ren-dropdown-filter.vue 6.3 KB

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