ren-dropdown-filters.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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">
  8. <view class="c-flex-align c-flex-center" :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.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. console.log(this.navData)
  84. this.navData.forEach(itemnavData => {
  85. itemnavData.map(child => {
  86. child.select = false;
  87. });
  88. return itemnavData;
  89. });
  90. for (let i = 0; i < this.selIndex.length; i++) {
  91. let selindex = this.selIndex[i];
  92. this.navData[i][selindex].select = true;
  93. }
  94. },
  95. navClick(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. },
  104. handleOpt(index) {
  105. this.selIndex[this.actNav] = index;
  106. this.keepStatus();
  107. setTimeout(() => {
  108. this.tapMask();
  109. }, 100);
  110. let data = [];
  111. let res = this.navData.forEach(item => {
  112. let sel = item.filter(child => child.select);
  113. data.push(sel);
  114. });
  115. console.log(data);
  116. this.$emit('onSelected', data);
  117. },
  118. dateClick() {
  119. this.tapMask();
  120. },
  121. tapMask() {
  122. this.showMask = false;
  123. this.popupShow = false;
  124. this.actNav = null;
  125. },
  126. handleDate(e) {
  127. let d = e.detail.value;
  128. this.selDate = d;
  129. this.$emit('dateChange', d);
  130. },
  131. discard() {}
  132. }
  133. };
  134. </script>
  135. <style lang="scss" scoped>
  136. page {
  137. font-size: 28rpx;
  138. }
  139. .c-flex-align {
  140. display: flex;
  141. align-items: center;
  142. }
  143. .c-flex-center {
  144. display: flex;
  145. align-items: center;
  146. justify-content: center;
  147. flex-direction: column;
  148. }
  149. .filter-wrapper {
  150. position: relative;
  151. // left: 0;
  152. width: 750rpx;
  153. z-index: 99;
  154. // padding: 0 20rpx;
  155. .inner-wrapper {
  156. position: relative;
  157. .navs {
  158. position: relative;
  159. height: 80rpx;
  160. // padding: 0 40rpx;
  161. display: flex;
  162. align-items: center;
  163. justify-content: space-between;
  164. background-color: #ffffff;
  165. // border-bottom: 2rpx solid #f5f6f9;
  166. // color: #8b9aae;
  167. z-index: 999;
  168. box-sizing: border-box;
  169. // border-radius: 10rpx;
  170. &>view {
  171. flex: 1;
  172. height: 100%;
  173. flex-direction: row;
  174. z-index: 999;
  175. }
  176. .date {
  177. justify-content: flex-end;
  178. }
  179. .actNav {
  180. color: #6696FF;
  181. font-weight: bold;
  182. }
  183. }
  184. .mask {
  185. z-index: 666;
  186. position: fixed;
  187. top: 0;
  188. left: 0;
  189. right: 0;
  190. bottom: 0;
  191. background-color: rgba(0, 0, 0, 0);
  192. transition: background-color 0.15s linear;
  193. &.show {
  194. background-color: rgba(0, 0, 0, 0.4);
  195. }
  196. &.hide {
  197. display: none;
  198. }
  199. }
  200. .popup {
  201. position: relative;
  202. max-height: 500rpx;
  203. background-color: #ffffff;
  204. border-bottom-left-radius: 20rpx;
  205. border-bottom-right-radius: 20rpx;
  206. overflow: scroll;
  207. z-index: 999;
  208. transition: all 2s linear;
  209. opacity: 0;
  210. display: none;
  211. .item-opt {
  212. height: 100rpx;
  213. padding: 0 40rpx;
  214. color: #000000;
  215. border-bottom: 2rpx solid #E5E5E5;
  216. }
  217. .actOpt {
  218. color: #6696FF;
  219. font-weight: bold;
  220. position: relative;
  221. &::after {
  222. content: '✓';
  223. font-weight: bold;
  224. font-size: 36rpx;
  225. position: absolute;
  226. right: 40rpx;
  227. }
  228. }
  229. }
  230. .popupShow {
  231. display: block;
  232. opacity: 1;
  233. }
  234. }
  235. .icon-triangle {
  236. width: 16rpx;
  237. height: 16rpx;
  238. margin-left: 10rpx;
  239. }
  240. }
  241. </style>