dropdownPanel.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="filter-wrapper" :style="{ height: height + 'px'}" @touchmove.stop.prevent="discard">
  3. <view class="inner-wrapper">
  4. <view class="mask" :class="showMask ? 'show' : 'hide'" :style="{top: top}" @tap="tapMask"></view>
  5. <view class="navs">
  6. <view class="c-flex-center" :class="{ 'c-flex-center': index > 0, actNav: index === actNav }"
  7. v-for="(item, index) in navData" :key="index" @click="navClick(item,index)">
  8. <view v-if="item.special&&item.name=='批量'" class="x-f" style="align-items: end;">
  9. <u-icon name="file-text" :color="index === actNav ?'#2979ff':'#222'" size="20"></u-icon>
  10. {{index === actNav ? '取消':'批量'}}
  11. </view>
  12. <template v-else>
  13. <text style="width: max-content;">{{item.name}}</text>
  14. <image :src="imgPath+'/app/manergevip/icon-pullup.png'" mode="" class="icon-triangle"
  15. v-if="index === actNav"></image>
  16. <image :src="imgPath+'/app/manergevip/icon-down.png'" mode="" class="icon-triangle"
  17. v-else></image>
  18. </template>
  19. </view>
  20. </view>
  21. <view scroll-y="true" class="popup" :class="popupShow ? 'popupShow' : ''">
  22. <scroll-view scroll-y="true" style="height: 30vh;">
  23. <slot></slot>
  24. </scroll-view>
  25. <view class="footer x-bc">
  26. <view class="footer-btn" @click="reset">重置</view>
  27. <view class="footer-btn footer-blue" @click="confirm">确认</view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. // import { getCurDateTime } from '@/libs/utils.js';
  35. export default {
  36. props: {
  37. height: {
  38. type: Number,
  39. default: 40
  40. },
  41. top: {
  42. type: String,
  43. default: ''
  44. },
  45. border: {
  46. type: Boolean,
  47. default: false
  48. },
  49. filterData: {
  50. //必填
  51. type: Array,
  52. default: () => {
  53. return []
  54. }
  55. },
  56. ispopshow: {
  57. type: Boolean,
  58. default: false
  59. },
  60. itemname: {
  61. type: String,
  62. default: ''
  63. },
  64. defaultIndex: {
  65. //默认选中条件索引,超出一类时必填
  66. type: Array,
  67. default: () => {
  68. return [0];
  69. }
  70. }
  71. },
  72. data() {
  73. return {
  74. navData: [],
  75. popupShow: false,
  76. showMask: false,
  77. actNav: null,
  78. selIndex: [] ,//选中条件索引
  79. };
  80. },
  81. watch: {
  82. // titname(newVal,oldVal){
  83. // console.log(newVal,oldVal)
  84. // if(newVal==2){
  85. // console.log(newVal,oldVal)
  86. // this.popupShow=false
  87. // this.showMask=false
  88. // }
  89. // }
  90. },
  91. computed: {
  92. imgPath() {
  93. return this.$store.state.imgpath
  94. }
  95. },
  96. created() {
  97. this.navData = this.filterData;
  98. this.selIndex = this.defaultIndex;
  99. // this.keepStatus();
  100. },
  101. mounted() {
  102. const query = uni.createSelectorQuery().in(this);
  103. // query
  104. // .select(".filter-wrapper")
  105. // .boundingClientRect((data) => {
  106. // // console.log(data)
  107. // this.top = data.top + 'px'
  108. // })
  109. // .exec();
  110. },
  111. methods: {
  112. reset() {
  113. this.$emit('reset');
  114. this.showMask = false;
  115. this.popupShow = false;
  116. },
  117. confirm() {
  118. this.showMask = false;
  119. this.popupShow = false;
  120. this.$emit('confirm');
  121. },
  122. keepStatus() {
  123. // this.navData.forEach(itemnavData => {
  124. // itemnavData.map(child => {
  125. // child.select = false;
  126. // });
  127. // return itemnavData;
  128. // });
  129. // for (let i = 0; i < this.selIndex.length; i++) {
  130. // let selindex = this.selIndex[i];
  131. // this.navData[i][selindex].select = true;
  132. // }
  133. },
  134. navClick(item, index) {
  135. if (this.showMask && item.type == 'piliang') {
  136. this.popupShow = false
  137. this.showMask = false
  138. this.actNav = null
  139. return
  140. }
  141. this.titname = index
  142. this.$emit('onClick', item);
  143. if (index === this.actNav) return this.tapMask();
  144. this.actNav = index;
  145. if (item.stopPrevent) return
  146. this.popupShow = true;
  147. this.showMask = true;
  148. this.$emit('onChange', this.actNav);
  149. },
  150. handleOpt(index) {
  151. // this.selIndex[this.actNav] = index;
  152. // this.keepStatus();
  153. // setTimeout(() => {
  154. // this.tapMask();
  155. // }, 100);
  156. // let data = [];
  157. // let res = this.navData.forEach(item => {
  158. // let sel = item.filter(child => child.select);
  159. // data.push(sel);
  160. // });
  161. // console.log(data);
  162. // this.$emit('onSelected', data);
  163. },
  164. tapMask() {
  165. this.showMask = false;
  166. this.popupShow = false;
  167. this.actNav = null;
  168. },
  169. discard() {}
  170. }
  171. };
  172. </script>
  173. <style lang="scss" scoped>
  174. .c-flex-align {
  175. display: flex;
  176. align-items: center;
  177. }
  178. .c-flex-center {
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. flex-direction: column;
  183. }
  184. .footer {
  185. font-family: PingFang SC, PingFang SC;
  186. font-weight: 400;
  187. font-size: 14px;
  188. color: #222;
  189. padding: 10px;
  190. &-btn {
  191. flex: 1;
  192. text-align: center;
  193. background-color: #fff;
  194. border: 1px solid #999;
  195. border-radius: 50px;
  196. padding: 10px 0;
  197. }
  198. &-blue {
  199. background-color: #1677ff;
  200. border: 1px solid #1677ff;
  201. color: #fff;
  202. margin-left: 10px;
  203. }
  204. }
  205. .filter-wrapper {
  206. // position: fixed;
  207. // left: 0;
  208. // width: 750rpx;
  209. // z-index: 999;
  210. .inner-wrapper {
  211. // position: relative;
  212. .navs {
  213. position: relative;
  214. font-family: PingFang SC, PingFang SC;
  215. font-weight: 400;
  216. font-size: 14px;
  217. color: #222;
  218. padding: 10px;
  219. display: flex;
  220. align-items: center;
  221. justify-content: space-between;
  222. background-color: #fff;
  223. z-index: 999;
  224. box-sizing: border-box;
  225. &>view {
  226. flex: 1;
  227. height: 100%;
  228. flex-direction: row;
  229. z-index: 999;
  230. }
  231. .date {
  232. justify-content: flex-end;
  233. }
  234. .actNav {
  235. color: #1677ff;
  236. font-weight: bold;
  237. }
  238. }
  239. .mask {
  240. z-index: 666;
  241. position: fixed;
  242. top: 0;
  243. left: 0;
  244. right: 0;
  245. bottom: 0;
  246. background-color: rgba(0, 0, 0, 0);
  247. transition: background-color 0.15s linear;
  248. &.show {
  249. background-color: rgba(0, 0, 0, 0.4);
  250. }
  251. &.hide {
  252. display: none;
  253. }
  254. }
  255. .popup {
  256. position: relative;
  257. // max-height: 500rpx;
  258. background-color: #fff;
  259. border-bottom-left-radius: 20rpx;
  260. border-bottom-right-radius: 20rpx;
  261. overflow: scroll;
  262. z-index: 999;
  263. transition: all 1s linear;
  264. opacity: 0;
  265. display: none;
  266. .item-opt {
  267. height: 100rpx;
  268. padding: 0 40rpx;
  269. color: #8b9aae;
  270. border-bottom: 2rpx solid #f5f6f9;
  271. }
  272. .actOpt {
  273. color: #1677ff;
  274. font-weight: bold;
  275. position: relative;
  276. &::after {
  277. content: '✓';
  278. font-weight: bold;
  279. font-size: 36rpx;
  280. position: absolute;
  281. right: 40rpx;
  282. }
  283. }
  284. }
  285. .popupShow {
  286. display: block;
  287. opacity: 1;
  288. }
  289. }
  290. .icon-triangle {
  291. width: 16rpx;
  292. height: 16rpx;
  293. margin-left: 10rpx;
  294. }
  295. }
  296. </style>