index.js 4.0 KB

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