filtrate.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="filtrate-box">
  3. <view :style="{ position: 'absolute', zIndex: index }">
  4. <u-transition :show="show">
  5. <view class="shade" catchtouchmove="true" @touchmove.stop.prevent="() => { }" @click="changeShow">
  6. <view @click.stop="">
  7. <scroll-view :style="{ maxHeight: tovw(maxHeight) }" class="scroll-view" scroll-y>
  8. <group v-for="(item, index) in list" :ref="'group' + index" :key="item.key" :item="item"
  9. :rowIndex="index" @onChange="onChange" />
  10. </scroll-view>
  11. <view class="but-box">
  12. <view class="reset" hover-class="navigator-hover" @click="onReset">
  13. 重置
  14. </view>
  15. <view class="confirm" hover-class="navigator-hover" @click="onConfirm">
  16. 确定
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </u-transition>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import group from "./filtrate-group.vue"
  27. export default {
  28. components: { group },
  29. props: {
  30. zIndex: {
  31. type: [String, Number],
  32. default: 9
  33. },
  34. filtrateList: {
  35. type: Array,
  36. default: [{
  37. title: "",//组名称
  38. key: 'id',//提交时返回的Key
  39. showKey: "",//显示的key
  40. selected: "",//选择时选择的字段
  41. isAll: false,//true 返回整个对象 false 返回selected选中的value
  42. value: "",//提交时选中的value
  43. defaultVal: "",//默认值
  44. rang: "",//选择的范围
  45. }]
  46. },
  47. arrName: {
  48. type: String,
  49. default: "filtrateList"
  50. },
  51. onFiltration: {
  52. type: Function
  53. }
  54. },
  55. watch: {
  56. filtrateList: function (newVal) {
  57. if (newVal) {
  58. this.list = JSON.parse(JSON.stringify(newVal))
  59. } else {
  60. }
  61. }
  62. },
  63. data() {
  64. return {
  65. show: false,
  66. maxHeight: 0,
  67. index: -99,
  68. list: []
  69. }
  70. },
  71. methods: {
  72. changeShow() {
  73. this.show = !this.show;
  74. if (this.show) {
  75. this.index = this.zIndex
  76. setTimeout(this.setHeight, 10);
  77. } else {
  78. setTimeout(() => { this.index = -99 }, 150)
  79. }
  80. },
  81. setHeight() {
  82. this.getHeight(".filtrate-box", this).then(res => {
  83. this.maxHeight = res - 300;
  84. });
  85. },
  86. onChange(option, index) {
  87. console.log(option, index)
  88. let item = this.list[index];
  89. this.$set(item, 'value', option[item.selected]);
  90. try {
  91. if (item.isAll) item.selectObj = option;
  92. } catch (error) { }
  93. this.$set(this.list, index, item);
  94. },
  95. onReset() {
  96. let page = getCurrentPages()[getCurrentPages().length - 1];
  97. // #ifdef H5
  98. this.list = JSON.parse(JSON.stringify(page[this.arrName]))
  99. // #endif
  100. // #ifndef H5
  101. this.list = JSON.parse(JSON.stringify(page.data[this.arrName]))
  102. // #endif
  103. console.log("重置")
  104. },
  105. onConfirm() {
  106. let obj = {};
  107. this.list.forEach(v => {
  108. if (v.value || v.defaultVal) {
  109. if (v.isAll) {
  110. obj[v.key] = v.rang.find(s => s[v.selected] == v.value) || v.rang.find(s => s[v.selected] == v.defaultVal);
  111. } else {
  112. obj[v.key] = v.value || v.defaultVal;
  113. }
  114. } else {
  115. obj[v.key] = v.rang.find(s => s[v.selected] == v.value || s[v.selected] == v.defaultVal);
  116. }
  117. })
  118. this.$emit("onFiltration", obj)
  119. this.changeShow();
  120. },
  121. },
  122. }
  123. </script>
  124. <style lang="scss">
  125. .filtrate-box {
  126. position: relative;
  127. .scroll-view {
  128. width: 100vw;
  129. background: #fff;
  130. }
  131. .but-box {
  132. display: flex;
  133. justify-content: space-between;
  134. width: 100vw;
  135. padding: 10px;
  136. background: #fff;
  137. box-sizing: border-box;
  138. .reset {
  139. width: 82px;
  140. height: 45px;
  141. line-height: 45px;
  142. text-align: center;
  143. background: #FFFFFF;
  144. border-radius: 5px;
  145. border: 1px solid #999999;
  146. }
  147. .confirm {
  148. width: 263px;
  149. height: 45px;
  150. text-align: center;
  151. line-height: 45px;
  152. background: #C30D23;
  153. border-radius: 5px;
  154. font-size: 16px;
  155. color: #FFFFFF;
  156. }
  157. }
  158. .shade {
  159. position: absolute;
  160. top: 0;
  161. width: 100vw;
  162. height: 9999px;
  163. background: rgba($color: #000000, $alpha: .7);
  164. }
  165. }
  166. </style>