ren-dropdown-filter.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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,'00000')
  96. // if (index == 2) {
  97. // this.popupShow = false;
  98. // this.showMask = false;
  99. // this.actNav = index;
  100. // // console.log(index,'00000')
  101. // } else {
  102. if (index === this.actNav) {
  103. this.tapMask();
  104. return;
  105. }
  106. this.popupShow = true;
  107. this.showMask = true;
  108. this.actNav = index;
  109. this.$emit('dateChange', index);
  110. // }
  111. },
  112. handleOpt(index) {
  113. // console.log(index,'00000')
  114. this.selIndex[this.actNav] = index;
  115. this.keepStatus();
  116. setTimeout(() => {
  117. this.tapMask();
  118. }, 100);
  119. let data = [];
  120. let res = this.navData.forEach(item => {
  121. let sel = item.filter(child => child.select);
  122. data.push(sel);
  123. });
  124. // console.log(data,'ppppppppppp');
  125. this.$emit('onSelected', data);
  126. },
  127. dateClick() {
  128. this.tapMask();
  129. },
  130. tapMask() {
  131. this.showMask = false;
  132. this.popupShow = false;
  133. this.actNav = null;
  134. },
  135. handleDate(e) {
  136. // console.log(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. }
  153. .c-flex-center {
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. flex-direction: column;
  158. }
  159. .filter-wrapper {
  160. position: relative;
  161. // left: 0;
  162. width: 100%;
  163. z-index: 99;
  164. // padding: 0 20rpx;
  165. .inner-wrapper {
  166. position: relative;
  167. .navs {
  168. position: relative;
  169. height: 80rpx;
  170. // padding: 0 40rpx;
  171. display: flex;
  172. align-items: center;
  173. justify-content: space-between;
  174. background-color: #F2F2F7;
  175. color: #1E1F31; // border-bottom: 2rpx solid #f5f6f9;
  176. z-index: 999;
  177. box-sizing: border-box;
  178. // border-radius: 10rpx;
  179. &>view {
  180. flex: 1;
  181. height: 100%;
  182. flex-direction: row;
  183. z-index: 999;
  184. }
  185. .date {
  186. justify-content: flex-end;
  187. }
  188. .actNav {
  189. color: #2B7DE2;
  190. font-weight: bold;
  191. }
  192. }
  193. .mask {
  194. z-index: 666;
  195. position: fixed;
  196. top: 0;
  197. left: 0;
  198. right: 0;
  199. bottom: 0;
  200. background-color: rgba(0, 0, 0, 0);
  201. transition: background-color 0.15s linear;
  202. &.show {
  203. background-color: rgba(0, 0, 0, 0.4);
  204. }
  205. &.hide {
  206. display: none;
  207. }
  208. }
  209. .popup {
  210. position: relative;
  211. max-height: 500rpx;
  212. background-color: #F4F6F9;
  213. // background-color: #111224;
  214. border-bottom-left-radius: 20rpx;
  215. border-bottom-right-radius: 20rpx;
  216. overflow: scroll;
  217. z-index: 999;
  218. transition: all 2s linear;
  219. opacity: 0;
  220. display: none;
  221. .item-opt {
  222. height: 100rpx;
  223. padding: 0 40rpx;
  224. color: #8b9aae;
  225. border-bottom: 2rpx solid #f5f5f5
  226. }
  227. .actOpt {
  228. color: #557EFD;
  229. font-weight: bold;
  230. position: relative;
  231. &::after {
  232. content: '✓';
  233. font-weight: bold;
  234. font-size: 36rpx;
  235. position: absolute;
  236. right: 40rpx;
  237. }
  238. }
  239. }
  240. .popupShow {
  241. display: block;
  242. opacity: 1;
  243. }
  244. }
  245. .icon-triangle {
  246. width: 16rpx;
  247. height: 16rpx;
  248. margin-left: 10rpx;
  249. }
  250. }
  251. </style>