queenwuli
2021-01-13 6e54af776db885ad1a22ec582bdc97d7e1273c6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<template>
    <view :class="isShow?'dropdown-wrap-open':'dropdown-wrap-close'">
        <view class="mask" @touchmove.stop.prevent="moveHandle" @click.stop="hide">
            <view v-if="type===1" class="dropdown-wrap-con">
                <view v-for="(item, index) in list" class="flex justify-between" @click="_changeItem(item, index)">
                    <text :class="selectIndex==index?'blue':''">{{item.title}}</text>
                    <text v-if="selectIndex==index" class="iconfont icongouxuan blue font-18"></text>
                </view>
            </view>
            <view v-else class="all-screen-wrap">
                <view v-for="(item, index) in list" class="all-screen" @click.stop="show">
                    <text class="title">{{item.title}}</text>
                    <view>
                        <text class="name"
                            v-for="op in item.list" 
                            :class="_handleActiveClass(item, op)"
                            @click="_chooseItem(item, op)">
                            {{op.title}}
                        </text>
                    </view>
                </view>
                <view class="btn-group">
                    <text class="btn" @click="_reset">重置</text>
                    <text class="btn btn-blue" @click="_confirm">完成</text>
                </view>
            </view>
        </view>
    </view>
</template>
 
<script>
     export default {
        props:{
            list: {
                default: []
            },
            type: {
                default: 1 //0表示全部筛选
            },
            filterKey: {
                default: {}
            }
         },
        data(){
            return {
                isShow: false,
                selectItem: {},
                selectIndex: 0
            }
        },
        created() {
            this.init();
        },
        methods:{
            moveHandle(){
                
            },
            init(){
                this.selectItem = JSON.parse(JSON.stringify(this.filterKey));
            },
            show(){
                this.isShow = true;
            },
            hide(){
                this.isShow = false
            },
            // 普通下拉选择
            _changeItem(item, index){
                this.selectIndex = index;
                this.$emit('confirm', item);
            },
            
            // 处理选项选中/不选中状态class
            _handleActiveClass(item, option){
                return this.selectItem[item.key] == option.value?'active':'';
            },
            // 选中筛选条件
            _chooseItem(item, option){
                if(this.selectItem[item.key] === option.value){
                    this.selectItem[item.key] = ''
                } else {
                    this.selectItem[item.key] = option.value;
                }
            },
            _reset(){
                this.init();
                this.$emit('reset');
            },
            _confirm(){
                this.$emit('confirm', this.selectItem);
            }
        }
      }
</script>
 
<style>
    .mask{
        position: fixed;
        top: calc(92px + var(--status-bar-height));
        left: 0;
        right: 0;
        height: 100%;
        background: rgba(0,0,0,0.4);
        transition: all 0.2s;
        z-index: 999;
    }
    .dropdown-wrap-close .mask{
        display: none;
    }
    .dropdown-wrap-open .mask{
        display: block;
    }
    .dropdown-wrap-con{
        background: #FFFFFF;
        padding: 5px 10px 10px;
        font-size: 14px;
        line-height: 32px;
        color: #999999;
    }
    .all-screen-wrap{
        background: #FFFFFF;
    }
    .all-screen{
        padding: 5px 10px 0;
    }
    .all-screen .title{
        display: block;
        font-size: 14px;
        padding: 5px 0 10px;
        color: #666666;
    }
    .all-screen .name{
        font-size: 10px;
        background: #F2f2f2;
        color: #666666;
        padding: 5px 0;
        width: 160rpx;
        box-sizing: border-box;
        text-align: center;
        display: inline-block;
        margin-right: 10px;
        border-radius: 2px;
        margin-bottom: 8px;
    }
    .all-screen .name.active{
        background: #518EFF;
        color: #FFFFFF;
    }
    .btn-group{
        display: flex;
        border-top: 1px solid #EDEAF4;
        margin-top: 20px;
    }
    .btn-group .btn{
        flex: 1;
        line-height: 44px;
        text-align: center;
        font-size: 15px;
        color: #666666;
    }
    .btn-group .btn-blue{
        background: #518EFF;
        color: #FFFFFF;
    }
</style>