123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 |
- <template>
- <view class="filter-wrapper"
- :style="{top: top,'border-top':border?'1rpx solid #f2f2f2':'none' }"
- @touchmove.stop.prevent="discard">
- <view class="inner-wrapper">
- <view class="mask" :class="showMask ? 'show' : 'hide'" @tap="tapMask"></view>
- <view class="navs" :style="stylesData">
- <!-- <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)">
- <view v-for="(child, childx) in item" :key="childx" v-if="child.select">{{ child.text }}</view>
- <image src="https://i.loli.net/2020/07/15/QsHxlr1gbSImvWt.png" mode="" class="icon-triangle"
- v-if="index === actNav"></image>
- <image src="https://i.loli.net/2020/07/15/xjVSvzWcH9NO7al.png" mode="" class="icon-triangle" v-else>
- </image>
- </view> -->
- <view class="date-wrapper">
- <picker mode="date" @change="handleDate">
- <view class="date c-flex-align" :style="{ height: height + 'rpx' }" @click="dateClick">
- <view>{{ selDate }}</view>
- <image src="https://i.loli.net/2020/07/15/xjVSvzWcH9NO7al.png" mode="" class="icon-triangle"></image>
- </view>
- </picker>
- </view>
- </view>
- <scroll-view scroll-y="true" class="popup" :class="popupShow ? 'popupShow' : ''">
- <view class="item-opt c-flex-align" :class="item.select ? 'actOpt' : ''"
- v-for="(item, index) in navData[actNav]" :key="index" @click="handleOpt(index)">
- {{ item.text }}
- </view>
- </scroll-view>
- </view>
- </view>
- </template>
- <script>
- // import { getCurDateTime } from '@/libs/utils.js';
- export default {
- props: {
- height: {
- type: Number,
- default: 108
- },
- top: {
- type: String,
- default: 'calc(var(--window-statsu-bar) + 44px)'
- },
- border: {
- type: Boolean,
- default: false
- },
- stylesData:{
- type: Object,
- default: {}
- },
- filterData: {
- //必填
- type: Array,
- default: () => {
- return [];
- }
- // default: () => {
- // return [
- // [{ text: '全部状态', value: '' }, { text: '状态1', value: 1 }, { text: '状态2', value: 2 }, { text: '状态3', value: 3 }],
- // [{ text: '全部类型', value: '' }, { text: '类型1', value: 1 }, { text: '类型2', value: 2 }, { text: '类型3', value: 3 }]
- // ];
- // }
- },
- defaultIndex: {
- //默认选中条件索引,超出一类时必填
- type: Array,
- default: () => {
- return [0];
- }
- }
- },
- data() {
- return {
- navData: [],
- popupShow: false,
- showMask: false,
- actNav: null,
- selDate: '选择日期',
- selIndex: [] //选中条件索引
- };
- },
- created() {
-
- },
- mounted() {
- // this.selDate = getCurDateTime().formatDate;
- },
- methods: {
- keepStatus() {
- this.navData.forEach(itemnavData => {
- itemnavData.map(child => {
- child.select = false;
- });
- return itemnavData;
- });
- for (let i = 0; i < this.selIndex.length; i++) {
- let selindex = this.selIndex[i];
- this.navData[i][selindex].select = true;
- }
- },
- navClick(index) {
- if (index === this.actNav) {
- this.tapMask();
- return;
- }
- this.popupShow = true;
- this.showMask = true;
- this.actNav = index;
- },
- handleOpt(index) {
- this.selIndex[this.actNav] = index;
- this.keepStatus();
- setTimeout(() => {
- this.tapMask();
- }, 100);
- let data = [];
- let res = this.navData.forEach(item => {
- let sel = item.filter(child => child.select);
- data.push(sel);
- });
- console.log(data);
- this.$emit('onSelected', data);
- },
- dateClick() {
- this.tapMask();
- },
- tapMask() {
- this.showMask = false;
- this.popupShow = false;
- this.actNav = null;
- },
- handleDate(e) {
- let d = e.detail.value;
- this.selDate = d;
- this.$emit('dateChange', d);
- },
- discard() {}
- }
- };
- </script>
- <style lang="scss" scoped>
- page {
- font-size: 28rpx;
- }
- .c-flex-align {
- display: flex;
- align-items: center;
- color: rgba(16, 16, 16, 1);
- }
- .c-flex-center {
- display: flex;
- align-items: center;
- justify-content: center;
- flex-direction: column;
- }
- .filter-wrapper {
- position: absolute;
- left: 0;
- top:0;
- width: 100%;
- z-index: 50;
- height:100rpx;
- border-radius: 20rpx;
- .inner-wrapper {
- // position: relative;
- .navs {
- position: relative;
- height: 100rpx;
- padding: 0 0 0 580rpx;
- display: flex;
- align-items: center;
- justify-content: space-between;
- background-color: #fff;
- border-bottom: 2rpx solid #f5f6f9;
- color: #8b9aae;
- z-index: 999;
- box-sizing: border-box;
- &>view {
- flex: 1;
- height: 100%;
- flex-direction: row;
- z-index: 999;
- }
- .date {
- // justify-content: flex-end;
- width:220rpx;
- }
- .actNav {
- color: #4d7df9;
- font-weight: bold;
- }
- .date-wrapper{
- margin-right:30rpx;
- }
-
- }
- .mask {
- z-index: 666;
- position: fixed;
- top: calc(var(--status-bar-height) + 44px);
- left: 0;
- right: 0;
- bottom: 0;
- background-color: rgba(0, 0, 0, 0);
- transition: background-color 0.15s linear;
- &.show {
- background-color: rgba(0, 0, 0, 0.4);
- }
- &.hide {
- display: none;
- }
- }
- .popup {
- position: relative;
- max-height: 500rpx;
- background-color: #fff;
- border-bottom-left-radius: 20rpx;
- border-bottom-right-radius: 20rpx;
- overflow: scroll;
- z-index: 999;
- transition: all 1s linear;
- opacity: 0;
- display: none;
- .item-opt {
- height: 100rpx;
- padding: 0 40rpx;
- color: #8b9aae;
- border-bottom: 2rpx solid #f5f6f9;
- }
- .actOpt {
- color: #4d7df9;
- font-weight: bold;
- position: relative;
- &::after {
- content: '✓';
- font-weight: bold;
- font-size: 36rpx;
- position: absolute;
- right: 40rpx;
- }
- }
- }
- .popupShow {
- display: block;
- opacity: 1;
- }
- }
- .icon-triangle {
- width: 16rpx;
- height: 16rpx;
- margin-left: 10rpx;
- }
-
- }
- </style>
|