index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Component({
  2. properties: {
  3. list: {
  4. type: {
  5. type: Array
  6. },
  7. value: [{
  8. label: "筛选1",
  9. index: null,
  10. showName: "name", //显示字段
  11. valueKey: "name", //返回Key
  12. selectKey: "id", //传参 代表选着字段 不传参返回整个选择对象
  13. value: "", //选中值
  14. list: [{
  15. name: "a1",
  16. id: 0
  17. }, {
  18. name: "a2",
  19. id: 1
  20. }]
  21. }]
  22. },
  23. handle: {
  24. type: Function
  25. }, //按钮回调函数
  26. zIndex: {
  27. type: String,
  28. value: 99999,
  29. }
  30. },
  31. data: {},
  32. methods: {
  33. /* 选择 */
  34. onSelect(e) {
  35. const {
  36. item, //被选项
  37. index, //列表下标
  38. i //被选项下标
  39. } = e.currentTarget.dataset;
  40. if (this.data.list[index].index == i) {
  41. this.setData({
  42. [`list[${index}].value`]: "",
  43. [`list[${index}].index`]: null
  44. });
  45. } else {
  46. this.setData({
  47. [`list[${index}].value`]: this.data.list[index].selectKey ? item[this.data.list[index].selectKey] : item,
  48. [`list[${index}].index`]: i
  49. });
  50. }
  51. let obj = {};
  52. this.data.list.forEach(v => {
  53. if (v.type == 'multilevelClass') {
  54. obj[v.valueKey] = getApp().globalData.temporaryId;
  55. delete(getApp().globalData.temporaryId);
  56. } else {
  57. obj[v.valueKey] = v.value;
  58. }
  59. });
  60. this.triggerEvent("handle", obj);
  61. },
  62. }
  63. })