index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const getHeight = require("../../utils/GetRheRemainingHeight");
  2. Component({
  3. properties: {
  4. list: {
  5. type: Array,
  6. value: [{
  7. label: "筛选1",
  8. index: null,
  9. showName: "name", //显示字段
  10. valueKey: "name", //返回Key
  11. selectKey: "id", //传参 代表选着字段 不传参返回整个选择对象
  12. value: "", //选中值
  13. list: [{
  14. name: "a1",
  15. id: 0
  16. }, {
  17. name: "a2",
  18. id: 1
  19. }]
  20. }]
  21. },
  22. show: Boolean,
  23. handle: Function, //按钮回调函数
  24. dateRange: { //是否开启日期范围筛选
  25. type: Boolean,
  26. value: true
  27. },
  28. zIndex: {
  29. type: String,
  30. value: 99999,
  31. },
  32. interrupt: Function
  33. },
  34. data: {
  35. startdate: "", //开始时间
  36. enddate: "", //结束时间
  37. },
  38. lifetimes: {
  39. ready() {
  40. getHeight.getHeight('.head', this).then(res => this.setData({
  41. listHeight: res - 80
  42. }));
  43. }
  44. },
  45. methods: {
  46. /* 选择 */
  47. onSelect(e) {
  48. const {
  49. item, //被选项
  50. index, //列表下标
  51. i //被选项下标
  52. } = e.currentTarget.dataset;
  53. if (this.data.list[index].index == i) {
  54. this.setData({
  55. [`list[${index}].value`]: "",
  56. [`list[${index}].index`]: null
  57. });
  58. } else {
  59. this.setData({
  60. [`list[${index}].value`]: this.data.list[index].selectKey ? item[this.data.list[index].selectKey] : item,
  61. [`list[${index}].index`]: i
  62. });
  63. }
  64. if (this.data.list[index].interrupt) this.triggerEvent("interrupt", {
  65. item,
  66. index,
  67. name: this.data.list[index].selectKey,
  68. list: this.data.list
  69. })
  70. },
  71. /* 点击按钮 */
  72. onClick(e) {
  73. const {
  74. name
  75. } = e.target.dataset;
  76. if (name == 'reset') {
  77. this.setData({
  78. list: this.data.list.map(v => {
  79. v.value = "";
  80. v.index = null;
  81. return v;
  82. })
  83. })
  84. this.setData({
  85. startdate: '',
  86. enddate: ''
  87. })
  88. let MultilevelClass = this.selectComponent("#MultilevelClass");
  89. if (MultilevelClass) MultilevelClass.clearChild()
  90. this.triggerEvent("handle", {})
  91. } else if (name == 'confirm') {
  92. let obj = {};
  93. this.data.list.forEach(v => {
  94. obj[v.valueKey] = v.value;
  95. });
  96. if (this.data.dateRange) {
  97. obj.startdate = this.data.startdate;
  98. obj.enddate = this.data.enddate;
  99. };
  100. this.triggerEvent("handle", obj);
  101. }
  102. this.onClose();
  103. },
  104. /* 筛选日期范围 */
  105. changeDate(e) {
  106. const name = e.currentTarget.dataset.name,
  107. value = e.detail.value;
  108. this.setData({
  109. [name]: value
  110. })
  111. },
  112. onClose() {
  113. this.setData({
  114. show: false
  115. })
  116. }
  117. }
  118. })