dropdownPanel.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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="https://fbylive.obs.cn-southwest-2.myhuaweicloud.com:443/app/manergevip/icon-pullup.png" mode="" class="icon-triangle"
  15. v-if="index === actNav"></image>
  16. <image src="https://fbylive.obs.cn-southwest-2.myhuaweicloud.com:443/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. created() {
  92. this.navData = this.filterData;
  93. this.selIndex = this.defaultIndex;
  94. // this.keepStatus();
  95. },
  96. mounted() {
  97. const query = uni.createSelectorQuery().in(this);
  98. // query
  99. // .select(".filter-wrapper")
  100. // .boundingClientRect((data) => {
  101. // // console.log(data)
  102. // this.top = data.top + 'px'
  103. // })
  104. // .exec();
  105. },
  106. methods: {
  107. reset() {
  108. this.$emit('reset');
  109. this.showMask = false;
  110. this.popupShow = false;
  111. },
  112. confirm() {
  113. this.showMask = false;
  114. this.popupShow = false;
  115. this.$emit('confirm');
  116. },
  117. keepStatus() {
  118. // this.navData.forEach(itemnavData => {
  119. // itemnavData.map(child => {
  120. // child.select = false;
  121. // });
  122. // return itemnavData;
  123. // });
  124. // for (let i = 0; i < this.selIndex.length; i++) {
  125. // let selindex = this.selIndex[i];
  126. // this.navData[i][selindex].select = true;
  127. // }
  128. },
  129. navClick(item, index) {
  130. if (this.showMask && item.type == 'piliang') {
  131. this.popupShow = false
  132. this.showMask = false
  133. this.actNav = null
  134. return
  135. }
  136. this.titname = index
  137. this.$emit('onClick', item);
  138. if (index === this.actNav) return this.tapMask();
  139. this.actNav = index;
  140. if (item.stopPrevent) return
  141. this.popupShow = true;
  142. this.showMask = true;
  143. this.$emit('onChange', this.actNav);
  144. },
  145. handleOpt(index) {
  146. // this.selIndex[this.actNav] = index;
  147. // this.keepStatus();
  148. // setTimeout(() => {
  149. // this.tapMask();
  150. // }, 100);
  151. // let data = [];
  152. // let res = this.navData.forEach(item => {
  153. // let sel = item.filter(child => child.select);
  154. // data.push(sel);
  155. // });
  156. // console.log(data);
  157. // this.$emit('onSelected', data);
  158. },
  159. tapMask() {
  160. this.showMask = false;
  161. this.popupShow = false;
  162. this.actNav = null;
  163. },
  164. discard() {}
  165. }
  166. };
  167. </script>
  168. <style lang="scss" scoped>
  169. .c-flex-align {
  170. display: flex;
  171. align-items: center;
  172. }
  173. .c-flex-center {
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. flex-direction: column;
  178. }
  179. .footer {
  180. font-family: PingFang SC, PingFang SC;
  181. font-weight: 400;
  182. font-size: 14px;
  183. color: #222;
  184. padding: 10px;
  185. &-btn {
  186. flex: 1;
  187. text-align: center;
  188. background-color: #fff;
  189. border: 1px solid #999;
  190. border-radius: 50px;
  191. padding: 10px 0;
  192. }
  193. &-blue {
  194. background-color: #1677ff;
  195. border: 1px solid #1677ff;
  196. color: #fff;
  197. margin-left: 10px;
  198. }
  199. }
  200. .filter-wrapper {
  201. // position: fixed;
  202. // left: 0;
  203. // width: 750rpx;
  204. // z-index: 999;
  205. .inner-wrapper {
  206. // position: relative;
  207. .navs {
  208. position: relative;
  209. font-family: PingFang SC, PingFang SC;
  210. font-weight: 400;
  211. font-size: 14px;
  212. color: #222;
  213. padding: 10px;
  214. display: flex;
  215. align-items: center;
  216. justify-content: space-between;
  217. background-color: #fff;
  218. z-index: 999;
  219. box-sizing: border-box;
  220. &>view {
  221. flex: 1;
  222. height: 100%;
  223. flex-direction: row;
  224. z-index: 999;
  225. }
  226. .date {
  227. justify-content: flex-end;
  228. }
  229. .actNav {
  230. color: #1677ff;
  231. font-weight: bold;
  232. }
  233. }
  234. .mask {
  235. z-index: 666;
  236. position: fixed;
  237. top: 0;
  238. left: 0;
  239. right: 0;
  240. bottom: 0;
  241. background-color: rgba(0, 0, 0, 0);
  242. transition: background-color 0.15s linear;
  243. &.show {
  244. background-color: rgba(0, 0, 0, 0.4);
  245. }
  246. &.hide {
  247. display: none;
  248. }
  249. }
  250. .popup {
  251. position: relative;
  252. // max-height: 500rpx;
  253. background-color: #fff;
  254. border-bottom-left-radius: 20rpx;
  255. border-bottom-right-radius: 20rpx;
  256. overflow: scroll;
  257. z-index: 999;
  258. transition: all 1s linear;
  259. opacity: 0;
  260. display: none;
  261. .item-opt {
  262. height: 100rpx;
  263. padding: 0 40rpx;
  264. color: #8b9aae;
  265. border-bottom: 2rpx solid #f5f6f9;
  266. }
  267. .actOpt {
  268. color: #1677ff;
  269. font-weight: bold;
  270. position: relative;
  271. &::after {
  272. content: '✓';
  273. font-weight: bold;
  274. font-size: 36rpx;
  275. position: absolute;
  276. right: 40rpx;
  277. }
  278. }
  279. }
  280. .popupShow {
  281. display: block;
  282. opacity: 1;
  283. }
  284. }
  285. .icon-triangle {
  286. width: 16rpx;
  287. height: 16rpx;
  288. margin-left: 10rpx;
  289. }
  290. }
  291. </style>