index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import {
  2. getHeight
  3. } from "../../utils/GetRheRemainingHeight";
  4. Component({
  5. options: {
  6. multipleSlots: true
  7. },
  8. properties: {
  9. list: {
  10. type: {
  11. type: Array
  12. },
  13. value: [{
  14. label: "筛选1",
  15. index: null,
  16. showName: "name", //显示字段
  17. valueKey: "name", //返回Key
  18. selectKey: "id", //传参 代表选着字段 不传参返回整个选择对象
  19. value: "", //选中值
  20. default: "", //默认索引
  21. list: [{
  22. name: "a1",
  23. id: 0
  24. }, {
  25. name: "a2",
  26. id: 1
  27. }]
  28. }]
  29. },
  30. show: {
  31. type: Boolean
  32. },
  33. handle: {
  34. type: Function
  35. }, //按钮回调函数
  36. dateRange: {
  37. type: Boolean
  38. }, //是否开启日期范围筛选
  39. dateRangeName: {
  40. type: String,
  41. value: "日期范围"
  42. },
  43. dateRange1: {
  44. type: Boolean
  45. }, //是否开启日期范围筛选
  46. zIndex: {
  47. type: String,
  48. value: 99999,
  49. },
  50. interrupt: {
  51. type: Function
  52. },
  53. isReset: {
  54. type: Boolean,
  55. value: true
  56. },
  57. minus: {
  58. type: [Number, String],
  59. value: 80
  60. }
  61. },
  62. data: {
  63. startdate: "", //开始时间
  64. enddate: "", //结束时间
  65. periodstart: "",
  66. periodend: "",
  67. },
  68. observers: {
  69. "show"(newVal) {
  70. if (newVal) getHeight('.head', this).then(res => this.setData({
  71. listHeight: res - this.data.minus
  72. }));
  73. }
  74. },
  75. methods: {
  76. /* 选择 */
  77. onSelect(e) {
  78. const {
  79. item, //被选项
  80. index, //列表下标
  81. i //被选项下标
  82. } = e.currentTarget.dataset;
  83. if (this.data.list[index].index == i) {
  84. this.setData({
  85. [`list[${index}].value`]: "",
  86. [`list[${index}].index`]: null
  87. });
  88. } else {
  89. this.setData({
  90. [`list[${index}].value`]: this.data.list[index].selectKey ? item[this.data.list[index].selectKey] : item,
  91. [`list[${index}].index`]: i
  92. });
  93. };
  94. if (this.data.list[index].interrupt) this.triggerEvent("interrupt", {
  95. item,
  96. index,
  97. name: this.data.list[index].selectKey,
  98. list: this.data.list
  99. })
  100. },
  101. onSelectCheckbox(e) {
  102. const {
  103. item, //被选项
  104. index, //列表下标
  105. i //被选项下标
  106. } = e.currentTarget.dataset,
  107. list = this.data.list;
  108. if (list[index].index == "" || list[index].index == null) {
  109. list[index].index = [];
  110. list[index].value = [];
  111. }
  112. let arrIndex = list[index].index.indexOf(i)
  113. if (arrIndex == -1) {
  114. list[index].index.push(i)
  115. list[index].value.push(list[index].selectKey ? item[list[index].selectKey] : item)
  116. } else {
  117. list[index].index.splice(arrIndex, 1)
  118. list[index].value.splice(arrIndex, 1)
  119. };
  120. this.setData({
  121. list
  122. })
  123. if (this.data.list[index].interrupt) this.triggerEvent("interrupt", {
  124. item,
  125. index,
  126. name: this.data.list[index].selectKey,
  127. list
  128. })
  129. },
  130. /* 点击按钮 */
  131. onClick(e) {
  132. const {
  133. name
  134. } = e.target.dataset;
  135. if (name == 'reset') {
  136. this.setData({
  137. list: this.data.list.map(v => {
  138. let value = "",
  139. index = null;
  140. try {
  141. if ((v.default+'').length) {
  142. index = v.default;
  143. value = v.selectKey ? v.list[v.default][v.selectKey] : v.list[v.default]
  144. }
  145. } catch (error) {
  146. }
  147. v.value = value;
  148. v.index = index;
  149. return v;
  150. })
  151. })
  152. this.setData({
  153. startdate: '',
  154. enddate: ''
  155. })
  156. let MultilevelClass = this.selectComponent("#MultilevelClass");
  157. if (MultilevelClass) MultilevelClass.clearChild()
  158. };
  159. let obj = {};
  160. this.data.list.forEach(v => {
  161. if (v.type == 'multilevelClass') {
  162. obj[v.valueKey] = getApp().globalData.temporaryId;
  163. delete(getApp().globalData.temporaryId);
  164. } else if (v.type == 'checkbox') {
  165. obj[v.valueKey] = v.value || [];
  166. } else {
  167. obj[v.valueKey] = v.value;
  168. }
  169. });
  170. if (this.data.dateRange) {
  171. obj.startdate = this.data.startdate;
  172. obj.enddate = this.data.enddate;
  173. };
  174. if (this.data.dateRange1) {
  175. obj.periodstart = this.data.periodstart;
  176. obj.periodend = this.data.periodend;
  177. };
  178. obj.name = name;
  179. this.triggerEvent("handle", obj);
  180. this.onClose();
  181. },
  182. /* 筛选日期范围 */
  183. changeDate(e) {
  184. const name = e.currentTarget.dataset.name,
  185. value = e.detail.value;
  186. this.setData({
  187. [name]: value
  188. })
  189. },
  190. onClose() {
  191. this.setData({
  192. show: false
  193. })
  194. }
  195. }
  196. })