store-statistics-dialog.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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<template>
<el-dialog
title="门店统计详情"
:visible="visible"
width="900px"
:close-on-click-modal="false"
@close="handleClose"
@update:visible="handleVisibleChange"
>
<div class="dialog-content">
<!-- 统计卡片 -->
<div class="statistics-cards" v-if="summaryData">
<el-row :gutter="16">
<el-col :span="6">
<div class="statistics-card">
<div class="card-icon">
<i class="el-icon-shop"></i>
</div>
<div class="card-content">
<div class="card-title">门店总数</div>
<div class="card-value">{{ summaryData.totalStores || 0 }}</div>
</div>
</div>
</el-col>
<el-col :span="6">
<div class="statistics-card">
<div class="card-icon">
<i class="el-icon-document"></i>
</div>
<div class="card-content">
<div class="card-title">开单数合计</div>
<div class="card-value">{{ summaryData.totalBillingCount || 0 }}</div>
</div>
</div>
</el-col>
<el-col :span="6">
<div class="statistics-card">
<div class="card-icon">
<i class="el-icon-menu"></i>
</div>
<div class="card-content">
<div class="card-title">项目数合计</div>
<div class="card-value">{{ summaryData.totalProjectCount || 0 }}</div>
</div>
</div>
</el-col>
<el-col :span="6">
<div class="statistics-card">
<div class="card-icon">
<i class="el-icon-money"></i>
</div>
<div class="card-content">
<div class="card-title">实付金额合计</div>
<div class="card-value">¥{{ formatMoney(summaryData.totalActualAmount) }}</div>
</div>
</div>
</el-col>
</el-row>
<el-row :gutter="16" style="margin-top: 16px;">
<el-col :span="6">
<div class="statistics-card">
<div class="card-icon">
<i class="el-icon-delete"></i>
</div>
<div class="card-content">
<div class="card-title">退款金额合计</div>
<div class="card-value">¥{{ formatMoney(summaryData.totalRefundAmount) }}</div>
</div>
</div>
</el-col>
</el-row>
</div>
<!-- 数据表格 -->
<div class="table-container">
<NCC-table v-loading="listLoading" :data="list" has-c>
<el-table-column prop="StoreName" label="门店名称">
<template slot-scope="scope">
<i class="el-icon-shop" style="margin-right: 4px; color: #409EFF;"></i>
<span>{{ scope.row.StoreName || '无' }}</span>
</template>
</el-table-column>
<el-table-column prop="BillingCount" label="开单数" align="right">
<template slot-scope="scope">
<i class="el-icon-document" style="margin-right: 4px; color: #409EFF;"></i>
<span>{{ scope.row.BillingCount || 0 }}</span>
</template>
</el-table-column>
<el-table-column prop="TotalProjectCount" label="总项目数" align="right">
<template slot-scope="scope">
<i class="el-icon-menu" style="margin-right: 4px; color: #67C23A;"></i>
<span>{{ formatProjectCount(scope.row.TotalProjectCount) }}</span>
</template>
</el-table-column>
<el-table-column prop="PurchaseProjectCount" label="购买项目数" align="right">
<template slot-scope="scope">
<i class="el-icon-menu" style="margin-right: 4px; color: #67C23A;"></i>
<span>{{ formatProjectCount(scope.row.PurchaseProjectCount) }}</span>
</template>
</el-table-column>
<el-table-column prop="ExperienceProjectCount" label="体验项目数" align="right">
<template slot-scope="scope">
<i class="el-icon-menu" style="margin-right: 4px; color: #67C23A;"></i>
<span>{{ formatProjectCount(scope.row.ExperienceProjectCount) }}</span>
</template>
</el-table-column>
<el-table-column prop="GiftProjectCount" label="赠送项目数" align="right">
<template slot-scope="scope">
<i class="el-icon-menu" style="margin-right: 4px; color: #67C23A;"></i>
<span>{{ formatProjectCount(scope.row.GiftProjectCount) }}</span>
</template>
</el-table-column>
<el-table-column prop="ActualAmount" label="实付金额" align="right">
<template slot-scope="scope">
<i class="el-icon-money" style="margin-right: 4px; color: #67C23A;"></i>
<span class="amount-paid">¥{{ formatMoney(scope.row.ActualAmount) }}</span>
</template>
</el-table-column>
<el-table-column prop="RefundAmount" label="退款金额" align="right">
<template slot-scope="scope">
<i class="el-icon-delete" style="margin-right: 4px; color: #F56C6C;"></i>
<span class="amount-debt">¥{{ formatMoney(scope.row.RefundAmount) }}</span>
</template>
</el-table-column>
</NCC-table>
</div>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="handleClose">关闭</el-button>
</div>
</el-dialog>
</template>
<script>
import request from '@/utils/request'
export default {
name: 'StoreStatisticsDialog',
props: {
visible: {
type: Boolean,
default: false
},
itemId: {
type: [String, Number],
default: null
},
startTime: {
type: String,
default: ''
},
endTime: {
type: String,
default: ''
}
},
data() {
return {
list: [],
listLoading: false,
summaryData: null
}
},
watch: {
visible: {
immediate: true,
handler(val) {
if (val && this.itemId && this.startTime && this.endTime) {
this.loadData()
}
}
}
},
methods: {
// 加载数据
loadData() {
if (!this.itemId || !this.startTime || !this.endTime) {
this.$message({
type: 'warning',
message: '缺少必要参数',
duration: 1500
})
return
}
this.listLoading = true
const params = {
itemId: this.itemId,
startTime: this.startTime,
endTime: this.endTime
}
request({
url: '/api/Extend/lqxmzl/get-item-store-statistics',
method: 'POST',
data: params
}).then(res => {
// 兼容不同的返回格式:可能是 res.data.data 或 res.data 直接是数组
let dataList = []
if (res.data) {
if (Array.isArray(res.data)) {
dataList = res.data
} else if (res.data.data && Array.isArray(res.data.data)) {
dataList = res.data.data
} else if (Array.isArray(res.data.list)) {
dataList = res.data.list
}
}
this.list = dataList
this.calculateSummary()
this.listLoading = false
}).catch(err => {
console.error('查询失败:', err)
this.$message({
type: 'error',
message: '查询失败,请重试',
duration: 1500
})
this.listLoading = false
})
},
// 计算汇总数据
calculateSummary() {
if (!this.list || this.list.length === 0) {
this.summaryData = null
return
}
const summary = {
totalStores: this.list.length,
totalBillingCount: this.list.reduce((sum, item) => sum + (item.BillingCount || 0), 0),
// 使用后端返回的 TotalProjectCount 字段进行汇总,保持与列表展示字段一致
totalProjectCount: this.list.reduce((sum, item) => sum + (item.TotalProjectCount || 0), 0),
totalActualAmount: this.list.reduce((sum, item) => sum + (item.ActualAmount || 0), 0),
totalRefundAmount: this.list.reduce((sum, item) => sum + (item.RefundAmount || 0), 0)
}
this.summaryData = summary
},
// 格式化金额
formatMoney(amount) {
if (!amount && amount !== 0) return '0.00'
return Number(amount).toFixed(2)
},
// 格式化项目数(如果是整数显示整数,有小数保留2位)
formatProjectCount(count) {
if (count === null || count === undefined) return '0'
const num = Number(count)
if (isNaN(num)) return '0'
// 如果是整数,直接返回整数
if (num % 1 === 0) {
return num.toString()
}
// 有小数保留2位
return num.toFixed(2)
},
// 处理可见性变化
handleVisibleChange(val) {
if (!val) {
this.$emit('close')
}
},
// 关闭弹窗
handleClose() {
this.$emit('close')
}
}
}
</script>
<style lang="scss" scoped>
.dialog-content {
padding: 10px 0;
}
.statistics-cards {
margin-bottom: 20px;
}
.statistics-card {
height: 100px;
padding: 12px;
border-radius: 12px;
background: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
.card-icon {
width: 60px;
height: 60px;
border-radius: 8px;
background: linear-gradient(135deg, #409EFF, #67C23A);
display: flex;
align-items: center;
justify-content: center;
margin-right: 16px;
i {
font-size: 24px;
color: #fff;
}
}
.card-content {
flex: 1;
.card-title {
font-size: 14px;
color: #909399;
margin-bottom: 8px;
}
.card-value {
font-size: 24px;
font-weight: bold;
color: #303133;
}
}
}
.table-container {
margin-top: 20px;
height: 300px;
overflow-y: auto;
}
.amount-paid {
color: #67C23A;
font-weight: 500;
}
.amount-debt {
color: #F56C6C;
font-weight: 500;
}
.dialog-footer {
text-align: right;
padding-top: 20px;
border-top: 1px solid #E4E7ED;
}
</style>