ren-dropdown-filter.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="filter-wrapper" :style="{ top: top,'border-top':border?'1rpx solid #f2f2f2':'none' }"
  3. @touchmove.stop.prevent="discard">
  4. <view class="inner-wrapper">
  5. <view class="mask" :class="showMask ? 'show' : 'hide'" @tap="tapMask"></view>
  6. <view class="navs">
  7. <view class="c-flex-align c-flex-center"
  8. :class="{ 'c-flex-center': index > 0, actNav: index === actNav }" v-for="(item, index) in navData"
  9. :key="index" @click="navClick(index)">
  10. <view v-for="(child, childx) in item" :key="childx" v-if="child.select">{{ child.label }}</view>
  11. <image src="https://i.loli.net/2020/07/15/QsHxlr1gbSImvWt.png" mode="" class="icon-triangle"
  12. v-if="index === actNav"></image>
  13. <image src="https://i.loli.net/2020/07/15/xjVSvzWcH9NO7al.png" mode="" class="icon-triangle" v-else>
  14. </image>
  15. </view>
  16. </view>
  17. <scroll-view scroll-y="true" class="popup" :class="popupShow ? 'popupShow' : ''">
  18. <view class="item-opt c-flex-align" :class="item.select ? 'actOpt' : ''"
  19. v-for="(item, index) in navData[actNav]" :key="index" @click="handleOpt(index)">
  20. {{ item.label }}
  21. </view>
  22. </scroll-view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. // import { getCurDateTime } from '@/libs/utils.js';
  28. export default {
  29. props: {
  30. height: {
  31. type: Number,
  32. default: 100
  33. },
  34. top: {
  35. type: String,
  36. default: 'calc(var(--window-statsu-bar) + 44px)'
  37. },
  38. border: {
  39. type: Boolean,
  40. default: false
  41. },
  42. filterData: {
  43. //必填
  44. type: Array,
  45. default: () => {
  46. return [];
  47. }
  48. // default: () => {
  49. // return [
  50. // [{ text: '全部状态', value: '' }, { text: '状态1', value: 1 }, { text: '状态2', value: 2 }, { text: '状态3', value: 3 }],
  51. // [{ text: '全部类型', value: '' }, { text: '类型1', value: 1 }, { text: '类型2', value: 2 }, { text: '类型3', value: 3 }]
  52. // ];
  53. // }
  54. },
  55. defaultIndex: {
  56. //默认选中条件索引,超出一类时必填
  57. type: Array,
  58. default: () => {
  59. return [0];
  60. }
  61. }
  62. },
  63. data() {
  64. return {
  65. navData: [],
  66. popupShow: false,
  67. showMask: false,
  68. actNav: null,
  69. selDate: '选择日期',
  70. selIndex: [] //选中条件索引
  71. };
  72. },
  73. created() {
  74. this.navData = this.filterData;
  75. this.selIndex = this.defaultIndex;
  76. this.keepStatus();
  77. },
  78. mounted() {
  79. // this.selDate = getCurDateTime().formatDate;
  80. },
  81. methods: {
  82. keepStatus() {
  83. this.navData.forEach(itemnavData => {
  84. itemnavData.map(child => {
  85. child.select = false;
  86. });
  87. return itemnavData;
  88. });
  89. for (let i = 0; i < this.selIndex.length; i++) {
  90. let selindex = this.selIndex[i];
  91. this.navData[i][selindex].select = true;
  92. }
  93. },
  94. navClick(index) {
  95. console.log(index)
  96. if (index === this.actNav) {
  97. this.tapMask();
  98. return;
  99. }
  100. this.popupShow = true;
  101. this.showMask = true;
  102. this.actNav = index;
  103. this.$emit('dateChange', index);
  104. // if (index == 0) {
  105. // this.popupShow = false;
  106. // this.showMask = false;
  107. // this.actNav = index;
  108. // this.$emit('dateChange', index);
  109. // } else {
  110. // if (index === this.actNav) {
  111. // this.tapMask();
  112. // return;
  113. // }
  114. // this.popupShow = true;
  115. // this.showMask = true;
  116. // this.actNav = index;
  117. // this.$emit('dateChange', index);
  118. // }
  119. },
  120. handleOpt(index) {
  121. this.selIndex[this.actNav] = index;
  122. this.keepStatus();
  123. setTimeout(() => {
  124. this.tapMask();
  125. }, 100);
  126. let data = [];
  127. let res = this.navData.forEach(item => {
  128. let sel = item.filter(child => child.select);
  129. data.push(sel);
  130. });
  131. console.log(data);
  132. this.$emit('onSelected', data);
  133. },
  134. dateClick() {
  135. this.tapMask();
  136. },
  137. tapMask() {
  138. this.showMask = false;
  139. this.popupShow = false;
  140. this.actNav = null;
  141. },
  142. handleDate(e) {
  143. let d = e.detail.value;
  144. this.selDate = d;
  145. this.$emit('dateChange', d);
  146. },
  147. discard() {}
  148. }
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. page {
  153. font-size: 28rpx;
  154. }
  155. .c-flex-align {
  156. display: flex;
  157. align-items: center;
  158. }
  159. .c-flex-center {
  160. display: flex;
  161. align-items: center;
  162. justify-content: center;
  163. flex-direction: column;
  164. }
  165. .filter-wrapper {
  166. position: relative;
  167. // left: 0;
  168. width: 750rpx;
  169. z-index: 99;
  170. // padding: 0 20rpx;
  171. .inner-wrapper {
  172. position: relative;
  173. .navs {
  174. position: relative;
  175. height: 80rpx;
  176. // padding: 0 40rpx;
  177. display: flex;
  178. align-items: center;
  179. justify-content: space-between;
  180. background-color: #f5f5f5;
  181. // background-color: #ffffff;
  182. // border-bottom: 2rpx solid #f5f6f9;
  183. // color: #8b9aae;
  184. z-index: 999;
  185. box-sizing: border-box;
  186. // border-radius: 10rpx;
  187. &>view {
  188. flex: 1;
  189. height: 100%;
  190. flex-direction: row;
  191. z-index: 999;
  192. }
  193. .date {
  194. justify-content: flex-end;
  195. }
  196. .actNav {
  197. color: #6696FF;
  198. font-weight: bold;
  199. }
  200. }
  201. .mask {
  202. z-index: 666;
  203. position: fixed;
  204. top: 0;
  205. left: 0;
  206. right: 0;
  207. bottom: 0;
  208. background-color: rgba(0, 0, 0, 0);
  209. transition: background-color 0.15s linear;
  210. &.show {
  211. background-color: rgba(0, 0, 0, 0.4);
  212. }
  213. &.hide {
  214. display: none;
  215. }
  216. }
  217. .popup {
  218. position: relative;
  219. max-height: 500rpx;
  220. background-color: #ffffff;
  221. border-bottom-left-radius: 20rpx;
  222. border-bottom-right-radius: 20rpx;
  223. overflow: scroll;
  224. z-index: 999;
  225. transition: all 2s linear;
  226. opacity: 0;
  227. display: none;
  228. .item-opt {
  229. height: 100rpx;
  230. padding: 0 40rpx;
  231. color: #000000;
  232. border-bottom: 2rpx solid #E5E5E5;
  233. }
  234. .actOpt {
  235. color: #6696FF;
  236. font-weight: bold;
  237. position: relative;
  238. &::after {
  239. content: '✓';
  240. font-weight: bold;
  241. font-size: 36rpx;
  242. position: absolute;
  243. right: 40rpx;
  244. }
  245. }
  246. }
  247. .popupShow {
  248. display: block;
  249. opacity: 1;
  250. }
  251. }
  252. .icon-triangle {
  253. width: 16rpx;
  254. height: 16rpx;
  255. margin-left: 10rpx;
  256. }
  257. }
  258. </style>