WeeklyConversionRate.vue
6.34 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
264
265
266
267
268
269
270
<template>
<view :class="['study-box2', !isHmzx || !isYb ? 'big-height' : '']">
<view class="tab-list">
<view @click="handleTabClick(index)" :class="['tab-item', tabIndex === index ? 'active' : '']"
v-for="(item, index) in tabList" :key="index">
<view class="tab-item-title">{{ item.title }}</view>
</view>
</view>
<view class="rank-title">周转化率排名</view>
<view class="rank-value">
<view class="rank-number">{{ currentConversionData.top || '-' }}</view>名
</view>
<view class="bar-box">
<view class="bar-item" v-for="(item, index) in barList" :key="index">
<view class="bar-label">{{ item.label }}</view>
<view class="bar-container">
<view
class="bar"
:class="item.class"
:style="{
width: `${Math.max(2, Number(currentConversionData[item.key]) || 0)}%`
}"
></view>
<view
class="bar-text"
:style="{ left: `calc(${currentConversionData[item.key]}%)` }"
>{{ (Number(currentConversionData[item.key]) || 0).toFixed(1) }}%</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'WeeklyConversionRate',
props: {
isFlag: {
type: Boolean,
default: false
},
dataInfo: {
type: Object,
default: () => {}
},
isHmzx: {
type: Boolean,
default: false
},
isYb: {
type: Boolean,
default: false
}
},
data() {
return {
barValue: 56,
barList: [
{
label: '我的',
value: '74.3',
key: 'myConversionRatio',
class: 'my'
},
{
label: 'Top1',
value: '94.5',
key: 'topOneConversionRatio',
class: 'top1'
}
],
tabIndex: 0,
}
},
computed: {
tabList() {
const weekConversionRatio = this.dataInfo && this.dataInfo.weekConversionRatio
// const weekConversionRatio = {
// 0: {
// top: 1,
// myConversionRatio: '0',
// topOneConversionRatio: '94.5'
// },
// 1: {
// top: 2,
// myConversionRatio: '74.3',
// topOneConversionRatio: '94.5'
// },
// 2: {
// top: 3,
// myConversionRatio: '55.7',
// topOneConversionRatio: '84.5'
// },
// }
if (!weekConversionRatio) return []
// 按顺序延保、权益、轻改生成tabList
const order = [0, 2, 1]
const tabArr = order
.filter(key => weekConversionRatio.hasOwnProperty(key))
.map(key => {
let title = '';
if (key == 0) title = '延保';
else if (key == 2) title = '权益';
else if (key == 1) title = '轻改';
else title = `类型${key}`;
return {
title,
value: key
}
});
// 默认展示延保,如果没有延保,tabIndex默认为第一个
this.$nextTick(() => {
if (tabArr.length > 0) {
const yanbaoIndex = tabArr.findIndex(item => item.value == 0);
if (yanbaoIndex !== -1) {
if (this.tabIndex !== yanbaoIndex) this.tabIndex = yanbaoIndex;
} else {
if (this.tabIndex !== 0) this.tabIndex = 0;
}
}
});
return tabArr;
},
currentConversionData() {
// 返回当前tabIndex对应的weekConversionRatio数据
const weekConversionRatio = this.dataInfo && this.dataInfo.weekConversionRatio
// const weekConversionRatio = {
// 0: {
// top: 1,
// myConversionRatio: '0',
// topOneConversionRatio: '94.5'
// },
// 1: {
// top: 2,
// myConversionRatio: '74.3',
// topOneConversionRatio: '94.5'
// },
// 2: {
// top: 3,
// myConversionRatio: '55.7',
// topOneConversionRatio: '84.5'
// },
// }
if (!weekConversionRatio) return {}
const key = this.tabList[this.tabIndex] && this.tabList[this.tabIndex].value
return weekConversionRatio[key] || {}
}
},
methods: {
handleTabClick(index) {
this.tabIndex = index
}
}
}
</script>
<style lang="scss" scoped>
.study-box2 {
width: calc(100% - #{toRpx(64)});
border-radius: toRpx(24);
background: #ffffff;
padding: toRpx(24);
margin: 0 toRpx(32) toRpx(16);
&.big-height {
height: toRpx(764);
}
.tab-list {
display: flex;
width: 100%;
height: toRpx(64);
background-color: #F5F6F7;
border-radius: toRpx(12);
color: #666666;
font-size: toRpx(24);
.tab-item {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
margin: toRpx(4);
&.active {
background-color: #fff;
color: #1A1A1A;
border-radius: toRpx(10);
}
}
}
.rank-title {
font-size: toRpx(28);
color: #1A1A1A;
margin-top: toRpx(32);
margin-left: toRpx(8);
}
.rank-value {
display: flex;
align-items: baseline;
color: #3B73FF;
font-size: toRpx(22);
font-weight: 500;
margin-top: toRpx(16);
margin-left: toRpx(8);
.rank-number {
font-size: toRpx(40);
font-weight: 700;
margin-right: toRpx(4);
}
}
/* 进度条整体项样式 */
.bar-box {
margin-top: toRpx(28);
}
.bar-item {
display: flex;
align-items: center;
margin-bottom: toRpx(20);
padding-right: toRpx(120);
&:last-child {
margin-bottom: toRpx(10);
}
.bar-label {
display: inline-block;
width: toRpx(60);
text-align: right;
margin-right: toRpx(10);
font-size: toRpx(22);
}
}
/* 进度条容器样式 */
.bar-container {
position: relative;
flex: 1;
// width: toRpx(380);
height: toRpx(12);
// overflow: hidden;
}
/* 进度条填充样式 */
.bar {
height: 100%;
border-radius: 0 4px 4px 0;
&.top1 {
background: linear-gradient(90deg, #708dff 0%, #6858f5 100%);
}
&.my {
background: linear-gradient(90deg, #389fff 0%, #2c66f7 100%);
}
}
/* 进度百分比文字样式 */
.bar-text {
margin-left: toRpx(20);
position: absolute;
top: 50%;
transform: translateY(-50%);
white-space: nowrap;
}
}
</style>