index.vue
10.1 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<template>
<div>
<CardGroupIndex :data="cardData"></CardGroupIndex>
<div class="g-card" style="margin-top: 0">
<div class="g-card-title">数据趋势</div>
<search-title @search="getLineData"></search-title>
<chart-line style="height: 300px" :legend="legend" :xData="xdata" :series="series"></chart-line>
</div>
<div class="column flex mt20">
<div class="column-item g-card mr20">
<div class="g-card-title">商品订单top5</div>
<search-title @search="getGoodsTop5Fn"></search-title>
<el-table v-loading="goodsTableLoading" :data="goodsTableList" style="width: 100%">
<el-table-column label="商品" align="center" width="200" prop="xtime" show-overflow-tooltip>
<div slot-scope="{ row }">
<div style="display: flex">
<el-image
style="width: 50px; height: 50px; margin-right: 5px; flex-shrink: 0"
:src="row.picture"></el-image>
<span class="limit_span">{{ row.productDesc }}</span>
</div>
</div>
</el-table-column>
<el-table-column label="订单总数" align="center" prop="orderNum" show-overflow-tooltip />
<el-table-column
label="订单总额(元)"
align="center"
prop="totalFee"
show-overflow-tooltip></el-table-column>
<el-table-column label="净收入(元)" align="center" prop="netIncome" show-overflow-tooltip></el-table-column>
</el-table>
</div>
<div class="column-item">
<div class="g-card">
<div class="g-card-title">员工订单top5</div>
<search-title @search="getMemebersTop5Fn"></search-title>
<el-table v-loading="memberTableLoading" :data="memberTableList" style="width: 100%">
<el-table-column
label="员工"
align="center"
min-width="100"
prop="weUserName"
show-overflow-tooltip></el-table-column>
<el-table-column label="订单总数" align="center" prop="orderNum" show-overflow-tooltip />
<el-table-column
label="订单总额(元)"
align="center"
prop="totalFee"
show-overflow-tooltip></el-table-column>
</el-table>
</div>
</div>
</div>
<div class="g-card">
<div class="g-card-title">数据报表</div>
<div class="mid-action">
<search-title :showScene="true" @search="getTableFn"></search-title>
<el-button type="primary" @click="exportFn" v-loading="exportLoading">导出Excel</el-button>
</div>
<el-table v-loading="loading" :data="tableList" style="width: 100%">
<el-table-column label="日期" align="center" min-width="100" prop="dateStr" show-overflow-tooltip />
<el-table-column label="订单总数" align="center" min-width="100" prop="orderNum" show-overflow-tooltip />
<el-table-column
label="订单总额(元)"
align="center"
prop="totalFee"
min-width="100"
show-overflow-tooltip></el-table-column>
<el-table-column
label="退款总额(元)"
align="center"
prop="refundFee"
min-width="100"
show-overflow-tooltip></el-table-column>
<el-table-column
label="净收入(元)"
align="center"
prop="netIncome"
min-width="100"
show-overflow-tooltip></el-table-column>
</el-table>
<pagination
:total="total"
:page.sync="query.pageNum"
:limit.sync="query.pageSize"
@pagination="getTableChangeSize()" />
</div>
</div>
</template>
<script>
import ChartBar from '@/components/ChartBar.vue'
import ChartLine from '@/components/ChartLine.vue'
import SearchTitle from '@/components/common/TimeSearchTitle.vue'
import {
getTableExport,
getTableTotal,
getGoodsTop5,
getMembersTop5,
getLineChartTotal,
getGoodsTotal,
} from '@/api/commodityCenter/commodityManage'
import { dateFormat } from '@/utils/index'
export default {
name: 'commodity-statistics',
components: {
SearchTitle,
ChartLine,
ChartBar,
},
data() {
return {
exportLoading: false,
legend: ['订单总额(元)', '退款总额(元)', '净收入(元)'],
xdata: [],
series: [],
cardData: [
{
title: '订单总数',
tips: '所有商品全部的订单总数',
value: 0,
noArrow: true,
},
{
title: '订单总额(元)',
tips: '所有商品全部的订单总额,精确到两位小数点',
value: 0,
},
{
title: '退款总额(元)',
tips: '所有商品全部的退款总额,精确到两位小数点',
value: 0,
},
{
title: '净收入(元)',
tips: '订单总额-退款总额,精确到两位小数点',
value: 0,
},
{
title: '今日订单总数',
tips: '今日所有商品全部的订单总数',
value: 0,
title1: '较昨日',
value1: 0,
},
{
title: '今日订单总额(元)',
tips: '今日所有商品全部的订单总额,精确到两位小数点',
value: 0,
title1: '较昨日',
value1: 0,
},
{
title: '今日退款总额(元)',
tips: '今日所有商品全部的退款总额,精确到两位小数点',
value: 0,
title1: '较昨日',
value1: 0,
},
{
title: '今日净收入(元)',
tips: '今日订单总额-退款总额,精确到两位小数点',
value: 0,
title1: '较昨日',
value1: 0,
},
],
total: 0,
query: {
pageSize: 10,
pageNum: 1,
},
tableList: [],
loading: false,
goodsTableLoading: false,
goodsTableList: [],
memberTableLoading: false,
memberTableList: [],
tableSearch: {},
}
},
methods: {
exportFn() {
this.$confirm('确认导出吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
this.exportLoading = true
return getTableExport(Object.assign({}, this.tableSearch))
})
.then((res) => {
if (!res) return
const blob = new Blob([res], { type: 'application/vnd.ms-excel' }) // 构造一个blob对象来处理数据,并设置文件类型
if (window.navigator.msSaveOrOpenBlob) {
//兼容IE10
navigator.msSaveBlob(blob, '商品分析')
} else {
const href = URL.createObjectURL(blob) //创建新的URL表示指定的blob对象
const a = document.createElement('a') //创建a标签
a.style.display = 'none'
a.href = href // 指定下载链接
a.download = dateFormat(new Date(), 'yyyy-MM-dd') + '_商品分析.xlsx' //指定下载文件名
a.click() //触发下载
URL.revokeObjectURL(a.href) //释放URL对象
}
})
.catch((error) => {
console.error(error)
})
.finally(() => {
this.exportLoading = false
})
},
getSceneTotalFn() {
getGoodsTotal().then((res) => {
this.cardData[0].value = res.data.orderNum
this.cardData[1].value = res.data.totalFee
this.cardData[2].value = res.data.refundFee
this.cardData[3].value = res.data.netIncome
this.cardData[4].value = res.data.todayOrderNum
this.cardData[4].value1 = res.data.orderNumComparedToYes
this.cardData[5].value = res.data.todayTotalFee
this.cardData[5].value1 = res.data.totalFeeComparedToYes
this.cardData[6].value = res.data.todayRefundFee
this.cardData[6].value1 = res.data.refundFeeComparedToYes
this.cardData[7].value = res.data.todayNetIncome
this.cardData[7].value1 = res.data.netIncomeComparedToYes
})
},
getLineData(data) {
this.$forceUpdate()
getLineChartTotal({
type: 'customization',
startDate: data.beginTime,
endDate: data.endTime,
}).then((res) => {
this.xdata = []
this.series = []
let arr1 = []
let arr2 = []
let arr3 = []
this.xdata = res.data.xAxis.data
arr1 = res.data.series[0].data
arr2 = res.data.series[1].data
arr3 = res.data.series[2].data
this.series = [arr1, arr2, arr3]
})
},
getGoodsTop5Fn(data) {
this.goodsTableLoading = true
getGoodsTop5({
type: 'customization',
startDate: data.beginTime,
endDate: data.endTime,
}).then((res) => {
this.goodsTableList = res.data
this.goodsTableLoading = false
})
},
getMemebersTop5Fn(data) {
this.memberTableLoading = true
getMembersTop5({
type: 'customization',
startDate: data.beginTime,
endDate: data.endTime,
}).then((res) => {
this.memberTableList = res.data
this.memberTableLoading = false
})
},
getTableChangeSize() {
this.loading = true
getTableTotal(Object.assign({}, this.query, this.tableSearch)).then((res) => {
this.tableList = res.rows
this.total = Number(res.total)
this.loading = false
})
},
getTableFn(data) {
this.loading = true
let obj = {
type: 'customization',
startDate: data.beginTime,
endDate: data.endTime,
}
this.tableSearch = obj
getTableTotal(Object.assign({}, this.query, obj)).then((res) => {
this.tableList = res.rows
this.total = Number(res.total)
this.loading = false
})
},
},
created() {
this.$store.dispatch(
'app/setBusininessDesc',
`
<div>全部商品及订单数据总览与数据分析。</div>
`,
)
this.getSceneTotalFn()
},
}
</script>
<style lang="scss" scoped>
.column {
display: flex;
.column-item {
flex: 1;
}
}
</style>