dropdownPanel.vue 7.0 KB

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