index.js 1.4 KB

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