SelectComponent.vue
1.92 KB
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
<template>
<view class="select-box">
<view
class="select"
@click.stop="isSelect = !isSelect"
>
{{selectList[selectIndex].label}}
<view class="sprite-icon icon-arrow-bottom"></view>
</view>
<view
class="pop-box"
v-if="isSelect"
>
<view
v-for="(i,index) in selectList"
:key="index"
class="type-item flex"
:class="index == selectIndex ? 'active' : ''"
@click="chooseType(index, i)"
>{{i[labelKey]}}</view>
</view>
</view>
</template>
<script type='text/ecmascript-6'>
export default {
props: {
selectList: Array,
labelKey: {
type: String,
default: 'label'
}
},
name: '',
data () {
return {
selectIndex: 0,
isSelect: false
}
},
mounted () {
},
methods: {
hideSelect () {
this.isSelect = false
},
chooseType (index, item) {
this.selectIndex = index
this.isSelect = false
this.$emit('chooseType', { item, index })
},
}
}
</script>
<style scoped lang='scss'>
.select-box {
position: relative;
z-index: 5;
.select {
display: flex;
align-items: center;
justify-content: flex-end;
height: toRpx(84);
border-radius: toRpx(16);
opacity: 1;
background: #f2f2f2;
padding: 0 toRpx(24) 0 toRpx(40);
}
.arrow-bottom {
width: toRpx(48);
height: toRpx(48);
}
.pop-box {
position: absolute;
top: toRpx(100);
left: 0;
width: 100%;
background: #ffffff;
box-shadow: 0 0 toRpx(16) 0 #99999933;
border-radius: toRpx(16);
padding: toRpx(16) 0;
text-align: center;
animation: show-view-opacity 0.15s forwards;
.type-item {
padding: 0 toRpx(28);
margin-bottom: toRpx(8);
height: toRpx(84);
justify-content: center;
&:last-child {
margin-bottom: 0;
}
&.active {
background-color: #ecf1ff;
}
}
}
}
</style>