CarBrands.vue
3.04 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
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
<template>
<view>
<MessageBox
ref="carBrandListVisible"
position="bottom"
:isFooter="false"
title="请选择车品牌"
@close="$emit('close')"
>
<view class="select-box">
<view
class="select-item"
:class="{ checked: carBrand == item.name }"
@click="selectCar(item)"
v-for="(item, index) in carBrandList"
:key="index"
>
{{ item.name }}
</view>
</view>
</MessageBox>
<MessageBox
ref="carBoxVisible"
position="bottom"
:isFooter="false"
title="请选择车型"
:maxHeight="1000"
back
>
<view class="select-box">
<view
class="select-item"
:class="{ checked: carModel == item.name }"
@click="handleSelect(item)"
v-for="(item, index) in carlist"
:key="index"
>
{{ item.name }}
</view>
</view>
</MessageBox>
</view>
</template>
<script type='text/ecmascript-6'>
export default {
name: 'CarBrands',
data () {
return {
carlist: [],
selectItem: {}
}
},
watch: {
watchStatus: {
immediate: true,
handler (newval) {
this.close()
}
},
},
computed: {
watchStatus () {
return this.$store.state.user.historyStatus
},
carModel () {
return this.$store.state.user.customerInfo.carModel
},
carBrandList () {
return this.$store.state.user.carBrands
},
carBrand () {
return this.$store.state.user.customerInfo.carBrand
}
},
mounted () {
},
methods: {
open () {
this.$refs.carBrandListVisible.open()
},
selectCar (e) {
uni.showLoading()
const customerInfo = this.$store.state.user.customerInfo
customerInfo.carBrand = e.name
this.$store.dispatch('setCustomerInfo', customerInfo)
this.selectItem = {
carBrand: e.brandName,
carBrandId: e.brandId,
carChildsBrandName: e.name,
carChildsBrandId: e.id
}
console.log(e)
uni.$api.commonApi.getCarBrandsList({
brandId: e.brandId,
childBrandId: e.id
}).then(res => {
uni.hideLoading()
this.carlist = res
this.$refs.carBoxVisible.open()
}).catch(() => uni.hideLoading())
},
handleSelect (item) {
this.$refs.carBoxVisible.close();
this.$emit('select', {
...item,
...this.selectItem
})
},
close () {
this.$refs?.carBoxVisible?.close();
this.$refs?.carBrandListVisible?.close()
}
}
}
</script>
<style scoped lang='scss'>
.select-box {
margin: 40rpx 0;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20rpx;
overflow-y: scroll;
max-height: 50vh;
padding-bottom: 60rpx;
.select-item {
text-align: center;
height: 68rpx;
line-height: 68rpx;
opacity: 1;
border: 2rpx solid #dce0e6;
color: #292d33;
font-size: 28rpx;
border-radius: 8rpx;
&.checked {
border: 2rpx solid #292d33;
}
}
}
</style>