pie.vue
6.48 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
<template>
<div :id="echartId" class="chart-container"></div>
</template>
<script>
import * as echarts from 'echarts'
import { introConpute } from '../../api/modules/rules'
import util from '../../util/util'
export default {
name: '',
data() {
return {
optinTitle: {}
}
},
props: {
echartId: {
type: String,
default: ''
}
},
mounted() {
this.getParams()
},
methods: {
getOptions(res) {
var chartDom = document.getElementById(this.echartId)
var myChart = echarts.init(chartDom)
var option = {
tooltip: {
trigger: 'item',
formatter:(params)=>{
let str = params.data["name"]+':'+this.priceFormat(params.data['value'])
return str
}
},
series: [
{
type: 'pie',
radius: '50%',
center: ['40%', '50%'],
data: [
{
value: res.afterSaleUnitPrice || 0,
name: `售后代运营新增产值`,
color: '#FACD67',
label: {
show: true,
rich: {
color: {
color: '#666666'
}
},
formatter: () => {
let temp = this.priceFormat(res.afterSaleUnitPrice)
if(!temp){
return
}
return `售后代运营新增产值:约${temp || 0}/年\n\n {color|累计3年可触达用户-渗透率:${res.afterSalePermeabilityString}}`
}
}
},
{
value: res.onSaleUnitPrice || 0,
name: `售中新品新增产值`,
color: '#64C0A2',
label: {
show: true,
rich: {
color: {
color: '#666666'
}
},
formatter: () => {
let temp = this.priceFormat(res.onSaleUnitPrice)
if(!temp){
return
}
return `售中新品新增产值:约${temp || 0}/年\n\n {color|渗透率:${res.onSalePermeabilityString}}`
}
}
},
{
value: res.preSaleUnitPrice || 0,
name: `售前权益新增产值`,
color: '#5850FF',
label: {
show: true,
rich: {
color: {
color: '#666666'
}
},
formatter: () => {
let temp = this.priceFormat(res.preSaleUnitPrice)
if(!temp){
return
}
return `售前权益新增产值:约${temp || 0}/年\n\n {color|渗透率:${res.preSalePermeabilityString}}`
}
}
}
],
emphasis: {
itemStyle: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
}
option && myChart.setOption(option, true)
},
getParams(newval) {
introConpute({}).then(res => {
res.preSalePermeabilityString = `${res.preSalePermeability * 100}%`
res.onSalePermeabilityString = `${res.onSalePermeability * 100}%`
res.afterSalePermeabilityString = `${res.afterSalePermeability * 100}%`
this.computeValue = res
if (newval) {
res.preSaleUnitPrice = newval.preSaleUnitPrice
res.onSaleUnitPrice = newval.onSaleUnitPrice
res.afterSaleUnitPrice = newval.afterSaleUnitPrice
}
// this.getOptions(res)
this.computeProduct(0,1)
})
},
computeProduct(num1, num2) {
let { preSalePermeability, preSaleUnitPrice, onSalePermeability, onSaleUnitPrice, afterSalePermeability, afterSaleUnitPrice } = this.computeValue
// 售前产值
let beforeSale = num1 * 12 * preSalePermeability * preSaleUnitPrice
let inSale = num1 * 12 * onSalePermeability * onSaleUnitPrice
let afterSale = num1 * 12 * 3 * afterSalePermeability * afterSaleUnitPrice
let totalValue = beforeSale + inSale + afterSale
let singleStoreValue = totalValue / num2
let totalProduct = this.priceFormat(totalValue)
let singleProduct = this.priceFormat(singleStoreValue)
let options = {
preSaleUnitPrice: beforeSale,
onSaleUnitPrice: inSale,
afterSaleUnitPrice: afterSale,
preSalePermeabilityString: this.computeValue.preSalePermeabilityString,
onSalePermeabilityString: this.computeValue.onSalePermeabilityString,
afterSalePermeabilityString: this.computeValue.afterSalePermeabilityString
}
this.getOptions(options)
return { totalProduct, singleProduct }
},
// 价格格式化
priceFormat(num, point = 2) {
let numStr = num.toString().split('.')[0]
if (numStr.length < 6) {
return util.decimal(num,2)
} else if (numStr >= 6) {
let decimal = numStr.substring(numStr.length - 4, numStr.length - 4 + point)
return parseFloat(parseInt(num / 10000) + '.' + decimal) + '万'
}
return num
// return util.priceFormat(num)
// num = util.decimal(num,2)
// 将数字转换为字符串,然后通过split方法用.分隔,取到第0个
// let numStr = num.toString().split('.')[0]
// if (numStr.length < 5) {
// // 判断数字有多长,如果小于6,,表示10万以内的数字,让其直接显示
// return num
// } else if (numStr.length >= 5) {
// // 如果数字大于6位,小于8位,让其数字后面加单位万
// let decimal = numStr.substring(numStr.length - 3, numStr.length - 3 + point)
// // 由千位,百位组成的一个数字
// return parseFloat(parseInt(num / 10000) + '.' + decimal) + '万'
// }
// else if (numStr.length > 6) {
// // 如果数字大于8位,让其数字后面加单位亿
// let decimal = numStr.substring(numStr.length - 6, numStr.length - 6 + point)
// return parseFloat(parseInt(num / 100000000) + '.' + decimal) + '亿'
// }
}
}
}
</script>
<style lang="scss" scoped>
.chart-container {
height: 152px;
// overflow: hidden;
}
</style>