PriceSwitch.vue
2.36 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<template>
<div class="price-select">
<div class="type-plugin">
<div class="trend-type-box" @click.stop="switchType">
<div class="text">{{ selectType || priceList[0].label }}</div>
<div class="trangle-icon"></div>
</div>
<SelectBox :isShow="isShow" :defaultValue.sync="priceList[0].value" @clickOutside="clickOutside" :dataList.sync="priceList" isObject :boxWidth="boxWidth" @selectVal="selectPrice"></SelectBox>
</div>
</div>
</template>
<script>
export default {
name: 'PriceSwitch',
props: {
selectList: {
type: Array,
default: () => []
},
boxWidth: {
type: String,
default: ''
},
unit: {
type: String,
default: '元'
}
},
data() {
return {
isShow: false,
selectType: '',
priceList: []
}
},
watch: {
selectList: {
handler(newVal) {
console.log(newVal)
// this.priceList = newVal
// this.priceList = []
// newVal.forEach(item => {
// this.priceList.push(item + this.unit)
// })
// if (!this.unit) return (this.priceList = newVal)
if (this.unit) {
this.priceList.unshift({
label: '全部',
value: ''
})
}
this.priceList = this.priceList.concat(newVal)
},
immediate: true
}
},
mounted() {},
methods: {
switchType() {
this.isShow = !this.isShow
},
clickOutside() {
this.isShow = false
},
selectPrice(val) {
this.selectType = val.label
this.$emit('selectPrice', val)
this.switchType()
}
}
}
</script>
<style lang="scss" scoped>
.price-select {
.type-plugin {
position: relative;
}
.trend-type-box {
display: flex;
width: fit-content;
height: 2.22vh;
line-height: 2.22vh;
padding: 0 0.83vw;
box-sizing: border-box;
.text {
font-weight: 600;
font-size: 10px;
color: #ffffff;
margin-right: 0.83vw;
}
.trangle-icon {
width: 0px;
height: 0px;
border: 4px solid transparent;
border-top: 4px solid #fff;
margin-top: 8%;
}
}
/deep/.select-box {
top: 2vh;
padding: 0.2vw 0;
.select-item {
padding: 0 0.5vw;
font-size: 10px;
margin-bottom: 0.5vh;
}
.select-item:last-child {
margin-bottom: 0;
}
}
}
</style>