MyCollapse.vue
6.55 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<template>
<!-- 折叠框 -->
<view class="myCollapse">
<view class="head">
<view>{{title}}</view>
<view v-if="title==='折射率'" class="headMid">注:折射率越高,镜片越薄,看着更美观。</view>
<view class="headRighted" v-if="isOpen" @click="myCollapseChange(isOpen)"></view>
<view class="headRight" v-else @click="myCollapseChange(isOpen)" ></view>
</view>
<view class="body">
<block v-if="isOpen">
<view style="background-color: #FFFFFF;" class="funBox">
<block v-if="title==='镜片种类'">
<view class="noRange">
<block v-for="(item) in funList" :key="item.key">
<view v-bind:class="item.isChioce?'boxChoiced':'boxChoice'"
@click="choice(item.key-1,item.isChioce)">{{item.name}}</view>
</block>
</view>
<view class="noRange">
<block v-for="(item,index) in funList2" :key="item.key">
<view v-bind:class="item.isChioce?'boxChoiced-C':'boxChoice-C'"
:style="colorList[index]" @click="choice2(index,item.isChioce)"></view>
</block>
</view>
</block>
<block v-else>
<view class="range" v-for="(item) in funList" :key="item.key">{{item.range}}</view>
<view class="noRange">
<block v-for="(item) in funList" :key="item.key">
<view v-bind:class="item.isChioce?'boxChoiced':'boxChoice'"
@click="choice(item.key-1,item.isChioce)">{{item.name}}</view>
</block>
</view>
<view class="range" v-for="(item) in funList2" :key="item.key">{{item.range}}</view>
<view class="noRange" style="max-width: 624rpx">
<block v-for="(item,index) in funList2" :key="item.key">
<view v-bind:class="item.isChioce?'boxChoiced':'boxChoice'"
@click="choice2(index,item.isChioce)">{{item.name}}</view>
</block>
</view>
</block>
</view>
</block>
<block v-else>
*<block v-for="(item,index) in funContent" :key="index">
<text v-if="item!==null">{{item}}</text>
</block>
</block>
</view>
</view>
</template>
<script>
export default {
props:{
isOpenProps:{
// 是否展开,默认 true
type: Boolean,
default: true
},
funListProp:{
"name":String,
"isChioce": Number,
"key":Number
},
funList2Prop:{
type:Array,
}
,
funContentProp: {
type: Array
},
title:{
type: String,
default: ''
}
},
data() {
return {
isOpen:this.isOpenProps,
// 颜色数组要与传入的值手动相同
colorList:[
"background-image: linear-gradient(180deg, #ECEAEA 1%, #f2f2f2 100%);",
"background-image: linear-gradient(180deg, #ECEAEA 1%, #8D8C8C 100%);",
"background-image: linear-gradient(180deg, #AEA8A8 1%, #624B3F 100%);",
"background-image: linear-gradient(180deg, #AEA096 1%, #5E3521 100%);",
"background-image: linear-gradient(180deg, #6F6864 1%, #352B26 100%);"
],
funList: this.funListProp,
funList2: this.funList2Prop,
funContent: this.funContentProp
};
},
methods:{
myCollapseChange(isopen){
this.isOpen = !isopen
},
choice(index,isChoice){
if(this.funList[index].type==="fun"){
this.funList[index].isChioce = !isChoice
if(!isChoice){
this.funContent[index] = this.funList[index].name
}
else{
this.funContent[index] = ''
}
}
else if(this.funList[index].type==="kind"){
for(let i=0;i<this.funList.length;i++){
this.funList[i].isChioce = false
}
this.funList[index].isChioce = !isChoice
this.funContent[0]=this.funList[index].name
}else {
for(let i=0;i<this.funList.length;i++){
this.funList[i].isChioce = false
}
for(let i=0;i<this.funList2.length;i++){
this.funList2[i].isChioce = false
}
this.funList[index].isChioce = !isChoice
this.funContent[0]=this.funList[index].name
}
},
choice2(index,isChoice){
if(this.funList2[index].type==="kind"){
for(let i=0;i<this.funList2.length;i++){
this.funList2[i].isChioce = false
}
this.funList2[index].isChioce = !isChoice
this.funContent[1] = this.funList2[index].name
}
else{
for(let i=0;i<this.funList.length;i++){
this.funList[i].isChioce = false
}
for(let i=0;i<this.funList2.length;i++){
this.funList2[i].isChioce = false
}
this.funList2[index].isChioce = !isChoice
this.funContent[0]=this.funList2[index].name
}
}
}
}
</script>
<style lang="scss">
.myCollapse{
width: 100%;
padding-bottom: 28rpx;
margin-top: 7px;
border-bottom: 1px solid #E9E9E9;
.head{
display: flex;
justify-content: space-between;
height: 24px;
// font-family: PingFangSC-Medium;
font-size: 16px;
color: #333333;
letter-spacing: -0.3px;
text-align: justify;
line-height: 24px;
margin-bottom: 18rpx;
.headRighted{
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid #CFCFCF;
transform: scaleY(-1);
margin-top: 10px;
}
.headMid{
// font-family: PingFangSC-Regular;
font-size: 10px;
color: #999999;
letter-spacing: -0.19px;
margin-left: -120rpx;
}
.headRight{
width: 0;
height: 0;
border-left: 4px solid transparent;
border-right: 4px solid transparent;
border-bottom: 4px solid #CFCFCF;
margin-top: 10px;
}
}
.body{
// font-family: PingFangSC-Regular;
font-size: 12px;
color: #666666;
letter-spacing: 0;
display: flex;
flex-wrap: wrap;
text{
padding-left: 4px;
}
}
}
.funBox {
// display: flex;
width: 100%;
// flex-wrap: wrap;
// max-width: 624rpx;
.range{
// font-family: PingFangSC-Regular;
font-size: 10px;
color: #999999;
letter-spacing: -0.19px;
margin-bottom: 5px;
}
.noRange{
display: flex;
flex-wrap: wrap;
// max-width: 624rpx;
// margin-bottom: 28rpx;
.boxChoiced,.boxChoice{
height: 60rpx;
border-radius: 4rpx;
// font-family: PingFangSC-Regular;
font-size: 12px;
letter-spacing: 0;
line-height: 60rpx;
box-sizing: border-box;
padding: 0 20rpx;
margin-right: 20rpx;
margin-bottom: 13rpx;
}
.boxChoiced{
background: rgba(255,107,74,0.15);
color: #FF6B4A;
}
.boxChoice{
background: #F2F2F2;
color: #666666;
}
.boxChoiced-C,.boxChoice-C{
width: 64rpx;
height: 64rpx;
border-radius: 32rpx;
margin-right: 8px;
}
.boxChoiced-C{
opacity: 0.7;
border: 1px solid #FF6B4A;
}
.boxChoice-C{
opacity: 0.7;
border: 1px solid #FFFFFF;
}
}
}
</style>