shuishen
2023-05-08 e24f70ababdee2b4fdce71c6b80a9bc928fa0331
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
<template>
    <div class="selects-container">
        <!-- 选择框 -->
        <div :class="{ 'selects-box-show': !optionsShow, 'selects-box-hide': optionsShow, 'select-choosable': selectAllClass }"
            class="selects-box" @click="selectClick">
            <div class="text" v-text="checkValue"></div>
            <i class="el-icon-arrow-down"></i>
        </div>
        <!-- 下拉框大盒子 -->
        <div :class="{ 'options-box-show': !optionsShow && options.length, 'options-box-hide': optionsShow, issel: options.length >= 4 }"
            class="select-options">
            <!-- 下拉框 -->
            <div @click="cutValue(item, index)" v-for="(item, index) in options" :key="index">{{ item[optionsName] }}</div>
        </div>
    </div>
</template>
 
<script>
export default {
    name: 'mapSelect',
    props: {
        //下拉框显示的数据
        options: {
            type: Array,
            required: true //必传
        },
 
        checkValue: {
            type: String,
            required: true //必传
        },
 
        optionsName: {
            type: String,
        },
 
        selectAllClass: {
            type: Boolean,
            required: false,
            default: false
        }
    },
 
    data () {
        return {
            optionsShow: true, //控制下拉框显示及隐藏
        }
    },
 
    mounted () {
 
    },
 
    methods: {
        //点击换文字的方法
        cutValue (item, index) {
            this.optionsShow = true
            this.$emit("selectCheck", item, index)
        },
        selectClick () {
            console.log(this.selectAllClass, this.options.length)
            if (this.selectAllClass == true) return
            this.optionsShow = !this.optionsShow
        }
    }
}
</script>
 
<style lang="scss" scoped>
//显示下拉框
.options-box-show {
    display: block !important;
}
 
//隐藏下拉框
.options-box-hide {
    display: none !important;
}
 
//点击时改变选择框的边框颜色
.selects-box-show {
    border: 1px solid rgba(0, 246, 255, 0.5);
    box-shadow: inset 0 0 6px rgba(0, 246, 255, 0.5);
}
 
//恢复边框颜色
.selects-box-hide {
    border: 1px solid rgba(20, 50, 123, 1);
}
 
.select-choosable {
    cursor: not-allowed !important;
}
 
.selects-container {
    width: 100%;
    height: 100%;
    background: $select-box-bg-color;
 
    .selects-box {
        padding: 0 10px;
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
 
        .text {
            flex: 1;
            text-align: left;
            line-height: 100%;
            color: #fff; //默认字体颜色
            font-size: 15px; //默认字体大小
        }
    }
 
    //当下拉框数量超过4个时 使用固定高度
    .issel {
        max-height: 140px !important;
    }
 
    .select-options {
        display: none;
        width: 100%;
        max-height: 140px;
        overflow: auto;
        border: 1px solid rgba(20, 50, 123, 1); //下拉框边框颜色
        border-top: none;
 
        div {
            padding: 0 10px;
            width: 100%;
            height: 35px; //下拉框高度
            display: flex;
            justify-content: flex-start;
            align-items: center;
            line-height: 35px;
            background: rgba(35, 50, 167, 0.7); //下拉框默认背景
            cursor: pointer;
        }
 
        //鼠标移到下拉框时的背景
        div:hover {
            background: rgba(45, 92, 200, 0.8);
            color: white;
        }
 
        .selects0:hover {
            background: white;
        }
    }
 
    //隐藏滚动条
    .select-options::-webkit-scrollbar {
        display: none;
    }
}
</style>