index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. },
  33. data: {
  34. startdate: "", //开始时间
  35. enddate: "", //结束时间
  36. },
  37. lifetimes: {
  38. ready() {
  39. getHeight.getHeight('.head', this).then(res => this.setData({
  40. listHeight: res - 80
  41. }));
  42. }
  43. },
  44. methods: {
  45. /* 选择 */
  46. onSelect(e) {
  47. const {
  48. item, //被选项
  49. index, //列表下标
  50. i //被选项下标
  51. } = e.currentTarget.dataset;
  52. if (this.data.list[index].index == i) {
  53. this.setData({
  54. [`list[${index}].value`]: "",
  55. [`list[${index}].index`]: null
  56. });
  57. } else {
  58. this.setData({
  59. [`list[${index}].value`]: this.data.list[index].selectKey ? item[this.data.list[index].selectKey] : item,
  60. [`list[${index}].index`]: i
  61. });
  62. }
  63. },
  64. /* 点击按钮 */
  65. onClick(e) {
  66. const {
  67. name
  68. } = e.target.dataset;
  69. if (name == 'reset') {
  70. this.setData({
  71. list: this.data.list.map(v => {
  72. v.value = "";
  73. v.index = null;
  74. return v;
  75. })
  76. })
  77. this.setData({
  78. startdate:'',
  79. enddate:''
  80. })
  81. this.triggerEvent("handle", {})
  82. } else if (name == 'confirm') {
  83. let obj = {};
  84. this.data.list.forEach(v => {
  85. obj[v.valueKey] = v.value;
  86. });
  87. if (this.data.dateRange) {
  88. obj.startdate = this.data.startdate;
  89. obj.enddate = this.data.enddate;
  90. };
  91. this.triggerEvent("handle", obj);
  92. }
  93. this.onClose();
  94. },
  95. /* 筛选日期范围 */
  96. changeDate(e) {
  97. const name = e.currentTarget.dataset.name,
  98. value = e.detail.value;
  99. this.setData({
  100. [name]: value
  101. })
  102. },
  103. onClose() {
  104. this.setData({
  105. show: false
  106. })
  107. }
  108. }
  109. })