OptionsComponent.vue
3.78 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
143
<template>
<view class="options-list">
<template v-for="(i, index) in listData">
<view :key="index" @click="choose(i)" :class="['item flex', { active: checkActive(i) }]">
<view class="sprite-icon icon-tag-checked"></view>
{{ i.label }}
</view>
</template>
</view>
</template>
<script type="text/ecmascript-6">
import popupmixin from './popupmixin'
export default {
mixins: [popupmixin],
name: 'OptionsComponent',
inject: ['userInfo'],
data() {
return {
}
},
computed: {
},
mounted() {
},
methods: {
async getList() {
const hasCommonElement = (arrA, arrB) => {
return arrA.some(item => arrB.includes(item))
}
const isSubset = (arrA, arrB) => {
// 检查arrB的每个元素是否都在arrA中
const setA = new Set(arrA)
return arrB.every(item => setA.has(item))
}
let { params, data: { options }, STORE_BASE_SCENE_CODE, CAR_BRAND_ID } = this
this.currentId = ''
this.currentIds = []
this.chooseList = []
this.componentLoading(params)
options = options.filter(item => {
// 品牌过滤
let filterBrand = true,
filterScene = true,
brandId = true,
flag = true
if (item.filterBrandId && item.filterBrandId.length) {
filterBrand = !isSubset(item.filterBrandId, CAR_BRAND_ID)
} else {
brandId = item.brandId && item.brandId.length ? hasCommonElement(item.brandId, CAR_BRAND_ID) : true
}
filterScene = item.baseSceneCode&& item.baseSceneCode?.length ? hasCommonElement(item.baseSceneCode, STORE_BASE_SCENE_CODE) : true
flag = filterBrand && brandId && filterScene
if(item.matchEffect ) {
flag = !flag
}
return flag
})
this.updateParams(params, options || [])
},
initData(list) {
const { data, data: { key }, params: { multiple } } = this
if (data[key]) {
if (!multiple) {
this.currentId = data[key]
let item = list.find(i => i.value == this.currentId)
this.$emit('choose', item)
} else {
let arr = data[key]
if (typeof arr == 'string') arr = arr.split(',')
this.chooseList = arr.map(i => list.find(e => e.value == i))
this.currentIds = arr
this.$emit('choose', this.chooseList)
}
}
this.list = list
this.$emit('onComplete')
},
choose(i) {
let { params: { multiple }, currentIds } = this
if (!multiple) {
this.currentId = i.value
this.$emit('choose', i)
} else {
let index = currentIds.indexOf(i.value)
if (index == -1) {
this.currentIds.push(i.value)
this.chooseList.push(i)
} else {
this.currentIds.splice(index, 1)
this.chooseList.splice(index, 1)
}
this.$emit('choose', this.chooseList)
}
},
checkActive(i) {
let { currentId, currentIds, data: { key }, data } = this
if (currentIds && currentIds.length) return currentIds.includes(i.value)
return currentId ? i.value == currentId : i.value == data[key]
}
}
}
</script>
<style scoped lang="scss">
.options-list {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: toRpx(32);
margin: 0 toRpx(48);
.item {
justify-content: center;
height: toRpx(72);
border-radius: toRpx(8);
border: toRpx(2) solid #dce0e6;
box-sizing: border-box;
position: relative;
color: #333333;
font-size: toRpx(32);
.sprite-icon {
display: none;
position: absolute;
top: 0;
right: 0;
}
}
.active {
border-color: #2c66f7;
background: #ecf1ff;
color: #2c66f7;
.sprite-icon {
display: block;
}
}
}
</style>