ren-dropdown-filter.vue 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <view class="filter-wrapper" :style="{ height: height + 'rpx', top: top,'border-top':border?'1rpx solid #f2f2f2':'none' }" @touchmove.stop.prevent="discard">
  3. <view class="inner-wrapper">
  4. <view class="mask" :class="showMask ? 'show' : 'hide'" @tap="tapMask"></view>
  5. <view class="navs">
  6. <view class="c-flex-align" :class="{ 'c-flex-center': index > 0, actNav: index === actNav }" v-for="(item, index) in navData" :key="index" @click="navClick(index)">
  7. <view v-for="(child, childx) in item" :key="childx" v-if="child.select">{{ child.text }}</view>
  8. <image src="https://i.loli.net/2020/07/15/QsHxlr1gbSImvWt.png" mode="" class="icon-triangle" v-if="index === actNav"></image>
  9. <image src="https://i.loli.net/2020/07/15/xjVSvzWcH9NO7al.png" mode="" class="icon-triangle" v-else></image>
  10. </view>
  11. <view class="date-wrapper" v-if="Date=='true' ">
  12. <picker mode="date" @change="handleDate">
  13. <view class="date c-flex-align" :style="{ height: height + 'rpx' }" @click="dateClick">
  14. <view>{{ selDate }}</view>
  15. <image src="https://i.loli.net/2020/07/15/xjVSvzWcH9NO7al.png" mode="" class="icon-triangle"></image>
  16. </view>
  17. </picker>
  18. </view>
  19. </view>
  20. <scroll-view scroll-y="true" class="popup" :class="popupShow ? 'popupShow' : ''">
  21. <view class="item-opt c-flex-align" :class="item.select ? 'actOpt' : ''" v-for="(item, index) in navData[actNav]" :key="index" @click="handleOpt(index)">
  22. {{ item.text }}
  23. </view>
  24. </scroll-view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. // import { getCurDateTime } from '@/libs/utils.js';
  30. export default {
  31. props: {
  32. height: {
  33. type: Number,
  34. default: 108
  35. },
  36. top: {
  37. type: String,
  38. default: 'calc(var(--window-statsu-bar) + 44px)'
  39. },
  40. border: {
  41. type: Boolean,
  42. default: false
  43. },
  44. Date: {
  45. type: String,
  46. default: ''
  47. },
  48. filterData: {
  49. //必填
  50. type: Array,
  51. // default: () => {
  52. // return [];
  53. // }
  54. default: () => {
  55. return [
  56. [{ text: '全部状态', value: '' }, { text: '状态1', value: 1 }, { text: '状态2', value: 2 }, { text: '状态3', value: 3 }],
  57. [{ text: '全部类型', value: '' }, { text: '类型1', value: 1 }, { text: '类型2', value: 2 }, { text: '类型3', value: 3 }]
  58. ];
  59. }
  60. },
  61. defaultIndex: {
  62. //默认选中条件索引,超出一类时必填
  63. type: Array,
  64. default: () => {
  65. return [0];
  66. }
  67. }
  68. },
  69. data() {
  70. return {
  71. navData: [],
  72. popupShow: false,
  73. showMask: false,
  74. actNav: null,
  75. selDate: '选择日期',
  76. selIndex: [] //选中条件索引
  77. };
  78. },
  79. created() {
  80. this.navData = this.filterData;
  81. this.selIndex = this.defaultIndex;
  82. if(this.Date != ''){
  83. this.dateshow = true
  84. }else{
  85. this.dateshow = false
  86. }
  87. console.log(this.dateshow,'日期控件')
  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. // console.log(data);
  127. this.$emit('onSelected', data);
  128. },
  129. dateClick() {
  130. this.tapMask();
  131. },
  132. tapMask() {
  133. this.showMask = false;
  134. this.popupShow = false;
  135. this.actNav = null;
  136. },
  137. handleDate(e) {
  138. let d = e.detail.value;
  139. this.selDate = d;
  140. this.$emit('dateChange', d);
  141. },
  142. discard() {}
  143. }
  144. };
  145. </script>
  146. <style lang="scss" scoped>
  147. page {
  148. font-size: 28rpx;
  149. }
  150. .c-flex-align {
  151. display: flex;
  152. align-items: center;
  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: fixed;
  162. left: 0;
  163. width: 750rpx;
  164. z-index: 999;
  165. .inner-wrapper {
  166. // position: relative;
  167. .navs {
  168. position: relative;
  169. height: 110rpx;
  170. padding: 0 40rpx;
  171. display: flex;
  172. align-items: center;
  173. justify-content: space-between;
  174. background-color: #fff;
  175. border-bottom: 2rpx solid #f5f6f9;
  176. color: #8b9aae;
  177. z-index: 999;
  178. box-sizing: border-box;
  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: #4d7df9;
  190. font-weight: bold;
  191. }
  192. }
  193. .mask {
  194. z-index: 666;
  195. position: fixed;
  196. top: calc(var(--status-bar-height) + 44px);
  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: #fff;
  213. border-bottom-left-radius: 20rpx;
  214. border-bottom-right-radius: 20rpx;
  215. overflow: scroll;
  216. z-index: 999;
  217. transition: all 1s linear;
  218. opacity: 0;
  219. display: none;
  220. .item-opt {
  221. height: 100rpx;
  222. padding: 0 40rpx;
  223. color: #8b9aae;
  224. border-bottom: 2rpx solid #f5f6f9;
  225. }
  226. .actOpt {
  227. color: #4d7df9;
  228. font-weight: bold;
  229. position: relative;
  230. &::after {
  231. content: '✓';
  232. font-weight: bold;
  233. font-size: 36rpx;
  234. position: absolute;
  235. right: 40rpx;
  236. }
  237. }
  238. }
  239. .popupShow {
  240. display: block;
  241. opacity: 1;
  242. }
  243. }
  244. .icon-triangle {
  245. width: 16rpx;
  246. height: 16rpx;
  247. margin-left: 10rpx;
  248. }
  249. }
  250. </style>