Blame view

admin-web-master/src/views/analysis/statistics/index.vue 10.9 KB
3f535f30   杨鑫   '初始'
1
2
  <template>
  
52fc03a8   杨鑫   '最新'
3
4
5
6
7
8
9
  	<div style="background-color:#f7f7f7;padding:10px 10px;">
  		<div class="history">
  			<div style="height:58px;line-height:58px;">
  				<div style="color:#0006"> <span>渠道售票统计分析</span> <span style="padding:0 5px;">></span> <span
  						style="color:#000000e6">票种销售数据统计</span></div>
  			</div>
  			<div>
3f535f30   杨鑫   '初始'
10
  
52fc03a8   杨鑫   '最新'
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  				<!-- 顶部搜索 -->
  				<div class="toolbar">
  					<el-form ref="formParams" :inline="true" :model="pageIndex">
  						<el-form-item label="渠道">
  							<el-select placeholder="全部" v-model="pageIndex.ticketChannel"
  								style="width: 120px;margin-right: 15px">
  								<el-option v-for="(item,index) in type" :label="item==1?'有赞':'其他'" :value="item" />
  							</el-select>
  						</el-form-item>
  						<el-form-item label="票种">
  							<el-select placeholder="全部" v-model="pageIndex.ticketType"
  								style="width: 120px;margin-right: 15px">
  								<el-option v-for="(item,index) in listType" :label="item" :value="item" />
  							</el-select>
  						</el-form-item>
  						<el-form-item label="日期">
  							<el-date-picker v-model="pageIndex.list" type="daterange" range-separator="至"
  								start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd" />
  						</el-form-item>
3f535f30   杨鑫   '初始'
30
  
52fc03a8   杨鑫   '最新'
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
  						<el-form-item label-width="0">
  							<el-button @click="search" style="background-color: #3F9B6A;color: #fff">查询</el-button>
  							<el-button @click="clear" class="buttonHover"
  								style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">重置</el-button>
  						</el-form-item>
  					</el-form>
  				</div>
  			</div>
  			<!-- 表格 -->
  			<div class="content_table" style="padding: 15px 10px 10px 10px;background-color:#F2F3F5">
  				<div style='padding:20px 10px;background-color:#fff;margin-bottom: 10px;'>
  					<div style="font-size:14px;justify-content: space-around;display:flex;">
  						<div style="display:flex;width:50%;justify-content: space-around;text-align: center;" v-for="(item,index) in titleList">
  							<div style="width:45%;border-right:1px solid #F2F3F5" >
  								<div style="margin-bottom: 10px;font-weight: 600;">{{item.ticketType}}销售数量(张)</div>
  								<div style="font-weight: 600;">{{item.sumNum}}</div>
  							</div>
  							<div style="width:45%;border-right:1px solid #F2F3F5">
  								<div style="margin-bottom: 10px;font-weight: 600;">{{item.ticketType}}销售总额(元)</div>
  								<div style="font-weight: 600;">{{item.moyeTwo}}</div>
  							</div>
  						</div>
  					<!-- 	<div style="width:15%;border-right:1px solid #F2F3F5">
  							<div style="margin-bottom: 10px;font-weight: 600;">演唱会票销售数量(张)</div>
  							<div style="font-weight: 600;">{{numOne}}</div>
  						</div>
  						<div style="width:15%;">
  							<div style="margin-bottom: 10px;font-weight: 600;">演唱会票销售总额(元)</div>
  							<div style="font-weight: 600;">{{moyeOne}}</div>
  						</div> -->
  					</div>
  				</div>
  				<div style="background-color: #fff;padding: 10px;margin-bottom: 20px;">
  					<div style="display: flex;margin-bottom: 20px;">
  						<div style="width: 100%;padding: 10px 0;">各渠道票种销售数据</div>
  						<!-- <el-select  placeholder="全部渠道"
3f535f30   杨鑫   '初始'
67
68
                style="width: 120px;margin-right: 15px">
                <el-option label="1" value="1" />
60d9bf40   杨鑫   '1'
69
              </el-select> -->
52fc03a8   杨鑫   '最新'
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  						<el-button style="background-color: #3F9B6A;color: #fff;" @click="daochu">导出</el-button>
  					</div>
  					<div class="table">
  						<!-- :span-method="objectSpanMethod" -->
  						<el-table :summary-method="getSummaries"  show-summary
  							:data="tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
  							:header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}">
  							<el-table-column label="序号" min-width="50">
  								<template slot-scope="scope">
  									{{scope.$index +1}}
  								</template>
  							</el-table-column>
  							<el-table-column prop="ticketChannel" label="渠道" min-width="60">
  								<template slot-scope="scope">
  									{{scope.row.ticketChannel == '1'?'有赞':'其他'}}
  								</template>
  							</el-table-column>
  							<el-table-column prop="ticketType" label="票种" min-width="60"/>
  							<el-table-column prop="ticketName" label="票名" min-width="160" :show-overflow-tooltip="true"/>
  							<el-table-column prop="num" label="销售数量(张)" />
  							<el-table-column prop="ticketPrice" label="客单价(元)" />
  							<el-table-column prop="price" label="销售金额(元)" />
  							<!-- <el-table-column label="操作">
3f535f30   杨鑫   '初始'
93
94
95
96
97
                  <template slot-scope="scope">
                    <el-button type="text"   style="background-color: transparent;color: #3F9B6A;;border: none;">详情</el-button>
                    <el-button type="text"   style="background-color: transparent;color: #3F9B6A;;border: none;">删除</el-button>
                  </template>
                </el-table-column> -->
52fc03a8   杨鑫   '最新'
98
99
100
101
  						</el-table>
  					</div>
  					<!-- 分页 -->
  					<div class="fenye">
3f535f30   杨鑫   '初始'
102
  
52fc03a8   杨鑫   '最新'
103
104
105
106
107
108
109
110
111
  						<el-pagination class="pagination" :hide-on-single-page="flag" background 
  							:current-page="currentPage" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize"
  							layout="total,prev, pager,next" :total="total " @size-change="handleSizeChange"
  							@current-change="handleCurrentChange" />
  					</div>
  				</div>
  			</div>
  		</div>
  	</div>
3f535f30   杨鑫   '初始'
112
113
114
  </template>
  
  <script>
52fc03a8   杨鑫   '最新'
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
  	import {
  		getTicketType,
  		excelToTicketTypeSalesSituation
  	} from '@/api/piaowu'
  	export default {
  		data() {
  			return {
  				flag: false,
  				total: 0,
  				pageSize: 10,
  				currentPage: 1,
  				tipsList: [],
  				tableData: [],
  				pageIndex: {
  					list: [],
  					page: 1,
  					pageSize: 10,
  					startTime: "",
  					endTime: "",
  					ticketChannel: "",
  					ticketType: ""
  				},
  				numOne: 0,
  				moyeOne: 0,
  				numTwo: 0,
  				moyeTwo: 0,
  				type: [],
  				listType: [],
  				titleList:[]
  			}
  		},
  		mounted() {
  			this.getAll()
  			getTicketType(this.pageIndex).then(res=>{
3c4666ce   杨鑫   '最新'
149
150
  				this.type = this.extractAndDeduplicateTicketChannels(res.data.content)
  				this.listType = this.listype(res.data.content)
52fc03a8   杨鑫   '最新'
151
152
153
154
155
156
  			})
  			
  		},
  		methods: {
  			async getAll() {
  				let res = await getTicketType(this.pageIndex)
3c4666ce   杨鑫   '最新'
157
158
159
  				this.tableData = res.data.content
  				this.total = res.data.numberOfElements
  				this.titleList = this.processTicketData(res.data.content)
52fc03a8   杨鑫   '最新'
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
  			},
  			processTicketData(data) {
  			    const result = {};	
  			    // 遍历原始数据
  			    data.forEach(item => {
  			        const ticketType = item.ticketType;
  			        if (!result[ticketType]) {
  			            // 如果该 ticketType 还未在结果对象中,初始化它
  			            result[ticketType] = {
  			                ticketType: ticketType,
  			                sumNum: 0,
  			                moyeTwo: 0
  			            };
  			        }
  			        // 累加 num 和 price
  			        result[ticketType].sumNum += item.num;
  			        result[ticketType].moyeTwo += item.price;
  			    });
  			
  			    // 将结果对象转换为数组
  			    return Object.values(result);
  			},
  			search() {
  				if (this.pageIndex.list.length != 0) {
  					this.pageIndex.startTime = this.pageIndex.list[0]
  					this.pageIndex.endTime = this.pageIndex.list[1]
  				}
0e7a57c2   杨鑫   '最新'
187
  				this.currentPage = 1
52fc03a8   杨鑫   '最新'
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
  				this.getAll()
  			},
  			extractAndDeduplicateTicketChannels(arr) {
  				const ticketChannels = [];
  				for (let i = 0; i < arr.length; i++) {
  					if (arr[i].hasOwnProperty('ticketChannel')) {
  						ticketChannels.push(arr[i].ticketChannel);
  					}
  				}
  				return [...new Set(ticketChannels)];
  			},
  			listype(arr) {
  				const ticketChannels = [];
  				for (let i = 0; i < arr.length; i++) {
  					if (arr[i].hasOwnProperty('ticketType')) {
  						ticketChannels.push(arr[i].ticketType);
  					}
  				}
  				return [...new Set(ticketChannels)];
  			},
  			clear() {
  				this.pageIndex = {
  					list: [],
  					page: 1,
  					pageSize: 10,
  					startTime: "",
  					endTime: "",
  					ticketChannel: "",
  					ticketType: ""
  				}
0e7a57c2   杨鑫   '最新'
218
  				this.currentPage = 1
52fc03a8   杨鑫   '最新'
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
  				this.getAll()
  			},
  			changepiao() {
  				this.getAll()
  			},
  			async daochu() {
  				let res = await excelToTicketTypeSalesSituation(this.pageIndex)
  				if (!res) {
  					return
  				}
  				const blob = new Blob([res], {
  					type: 'application/vnd.ms-excel'
  				})
  				const fileName = '票种销售表.xls'
  				if ('download' in document.createElement('a')) {
  					// 非IE下载
  					const elink = document.createElement('a')
  					elink.download = fileName
  					elink.style.display = 'none'
  					elink.href = URL.createObjectURL(blob)
  					document.body.appendChild(elink)
  					elink.click()
  					URL.revokeObjectURL(elink.href) // 释放URL 对象
  					document.body.removeChild(elink)
  				} else {
  					// IE10+下载
  					navigator.msSaveBlob(blob, fileName)
  				}
  				this.$message({
  					message: '导出成功',
  					type: 'success'
  				})
  			},
  			getSummaries(param) {
  				const {
  					columns,
  					data
  				} = param;
  				const sums = [];
  				columns.forEach((column, index) => {
  					if (index === 0) {
  						sums[index] = '总计';
  						return;
  					}
  					if (['销售数量(张)', '客单价(元)', '销售金额(元)'].includes(column.label)) {
  						const values = data.map(item => Number(item[column.property]))
60d9bf40   杨鑫   '1'
265
  
52fc03a8   杨鑫   '最新'
266
267
268
  						if (!values.every(value => isNaN(value))) {
  							sums[index] = values.reduce((prev, curr) => {
  								const value = Number(curr);
60d9bf40   杨鑫   '1'
269
  
52fc03a8   杨鑫   '最新'
270
  								if (!isNaN(value)) {
60d9bf40   杨鑫   '1'
271
  
3c4666ce   杨鑫   '最新'
272
  									return parseFloat((prev + value).toFixed(2));
60d9bf40   杨鑫   '1'
273
  
52fc03a8   杨鑫   '最新'
274
275
276
277
278
279
280
281
282
283
284
  								} else {
  									return prev;
  								}
  							}, 0);
  						} else {
  							sums[index] = '';
  						}
  					} else {
  						sums[index] = '';
  					}
  				});
60d9bf40   杨鑫   '1'
285
  
52fc03a8   杨鑫   '最新'
286
287
  				return sums;
  			},
3f535f30   杨鑫   '初始'
288
  
52fc03a8   杨鑫   '最新'
289
290
  			handleCurrentChange(val) {
  				this.currentPage = val
3c4666ce   杨鑫   '最新'
291
  		
52fc03a8   杨鑫   '最新'
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
  			},
  			handleSizeChange(val) {
  				this.pageSize = val
  			},
  			// objectSpanMethod({
  			// 	row,
  			// 	column,
  			// 	rowIndex,
  			// 	columnIndex
  			// }) {
  			// 	if (columnIndex === 0) {
  			// 		if (rowIndex % 2 === 0) {
  			// 			return {
  			// 				rowspan: 2,
  			// 				colspan: 1
  			// 			};
  			// 		} else {
  			// 			return {
  			// 				rowspan: 0,
  			// 				colspan: 0
  			// 			};
  			// 		}
  			// 	}
  			// },
  		},
  	}
3f535f30   杨鑫   '初始'
318
319
320
  </script>
  
  <style lang='scss' scoped>
52fc03a8   杨鑫   '最新'
321
322
323
324
325
326
327
328
329
  	.history {
  		padding: 0 20px 20px 20px;
  		min-height: calc(100vh - 50px - 20px);
  		background-color: #Fff;
  	}
  
  	::v-deep .el-form-item__label {
  		font-weight: normal;
  		font-size: 14px;
3f535f30   杨鑫   '初始'
330
  
52fc03a8   杨鑫   '最新'
331
  	}
3f535f30   杨鑫   '初始'
332
  
52fc03a8   杨鑫   '最新'
333
334
335
  	::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
  		background-color: #3F9B6A;
  	}
3f535f30   杨鑫   '初始'
336
337
  </style>
  <style scoped>
52fc03a8   杨鑫   '最新'
338
339
340
341
  	.history /deep/ .el-table .cell.el-tooltip img {
  		max-height: 100px;
  	}
  
3f535f30   杨鑫   '初始'
342
  
52fc03a8   杨鑫   '最新'
343
344
345
346
  	.pagination {
  		text-align: right;
  		line-height: 20px;
  	}
3f535f30   杨鑫   '初始'
347
  
52fc03a8   杨鑫   '最新'
348
349
350
  	.greens {
  		color: #3F9B6A;
  	}
3f535f30   杨鑫   '初始'
351
  
52fc03a8   杨鑫   '最新'
352
353
354
355
356
  	/deep/ .el-table__row {
  		font-size: 14px;
  		color: #000000e6;
  		height: 42px;
  	}
3f535f30   杨鑫   '初始'
357
  
52fc03a8   杨鑫   '最新'
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
  	.fenye {
  		margin-top: 20px;
  		display: flex;
  		justify-content: flex-end;
  	}
  
  	::v-deep .el-pagination__total {
  		position: absolute;
  		left: 60px;
  	}
  
  	::v-deep .buttonHover:hover {
  		color: #3f9b6a !important;
  		border-color: #c5e1d2 !important;
  		background-color: #ecf5f0 !important;
  		outline: none;
  	}
3f535f30   杨鑫   '初始'
375
376
  </style>
  <style>
52fc03a8   杨鑫   '最新'
377
378
379
380
  	.el-tooltip__popper {
  		max-width: 50%;
  	}
  </style>