feat(统计业务): 新增课程统计页面,支持按金额、课程和分类统计

- 添加课程统计主页面,包含三个统计维度的标签页切换
- 实现按金额统计功能,支持年份选择和月度详情查看
- 实现按课程统计功能,支持年份/月份切换和分页展示
- 实现按分类统计功能,支持年份/月份切换
- 各统计页面均支持数据导出为Excel报表
- 添加路由配置,将课程统计页面集成到导航系统中
This commit is contained in:
2026-03-13 16:17:50 +08:00
parent 5138937dd4
commit cc9fc9adde
5 changed files with 920 additions and 1 deletions

View File

@@ -0,0 +1,194 @@
<template>
<div class="course-label-statistics-container">
<el-form
:inline="true"
:model="dataForm"
@keyup.enter.native="getDataList()"
>
<el-form-item>
<el-radio-group v-model="timeType" size="small" @change="handleTimeTypeChange">
<el-radio-button label="year">按年份</el-radio-button>
<el-radio-button label="month">按月份</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item>
<el-date-picker
v-show="timeType === 'year'"
v-model="currentDate"
type="year"
format="yyyy"
placeholder="选择年份"
popper-append-to-body
@change="getDataList"
size="small"
/>
<el-date-picker
v-show="timeType === 'month'"
v-model="currentDate"
type="month"
format="yyyy-MM"
placeholder="选择月份"
popper-append-to-body
@change="getDataList"
size="small"
/>
</el-form-item>
<el-form-item>
<el-button
type="primary"
size="small"
@click="getDataList"
>刷新</el-button>
</el-form-item>
<el-form-item>
<el-button
type="success"
size="small"
@click="exportData"
>下载报表</el-button>
</el-form-item>
</el-form>
<div class="table-container" ref="tableContainer">
<el-table
:data="dataList"
border
:header-cell-style="{ textAlign: 'center' }"
:cell-style="{ textAlign: 'center' }"
:max-height="tableHeight"
>
<el-table-column prop="courseLabel" label="分类" min-width="150" />
<el-table-column prop="courseCount" label="总销售门数" min-width="120" />
<el-table-column prop="sales" label="总销量" min-width="100" />
<el-table-column
:label="timeType === 'year' ? '年销售额(微信+支付宝+银行+天医币)' : '月销售额(微信+支付宝+银行+天医币)'"
min-width="280"
>
<template slot-scope="scope">
{{ scope.row.salesFee }}
</template>
</el-table-column>
<el-table-column
:label="timeType === 'year' ? '年销售额(微信+支付宝+银行)' : '月销售额(微信+支付宝+银行)'"
min-width="250"
>
<template slot-scope="scope">
{{ scope.row.cashFee }}
</template>
</el-table-column>
</el-table>
</div>
</div>
</template>
<script>
import http from '@/utils/httpRequest'
export default {
data() {
return {
timeType: 'year',
currentDate: new Date(),
dataForm: {},
dataList: [],
tableHeight: null
}
},
activated() {
const now = new Date()
if (this.timeType === 'year') {
this.currentDate = new Date(now.getFullYear(), 0, 1)
} else {
this.currentDate = now
}
this.getDataList()
this.$nextTick(() => {
this.calculateTableHeight()
})
},
mounted() {
window.addEventListener('resize', this.handleResize)
this.$nextTick(() => {
this.calculateTableHeight()
})
},
beforeDestroy() {
window.removeEventListener('resize', this.handleResize)
},
methods: {
handleResize() {
this.calculateTableHeight()
},
calculateTableHeight() {
if (this.$refs.tableContainer) {
this.tableHeight = this.$refs.tableContainer.offsetHeight || 500
} else {
this.tableHeight = 500
}
},
handleTimeTypeChange() {
if (this.timeType === 'year') {
const now = new Date()
this.currentDate = new Date(now.getFullYear(), 0, 1)
} else {
this.currentDate = new Date()
}
this.getDataList()
},
getDataList() {
const dateStr = this.timeType === 'year'
? this.currentDate.getFullYear().toString()
: `${this.currentDate.getFullYear()}-${String(this.currentDate.getMonth() + 1).padStart(2, '0')}`
http({
url: http.adornUrl('/master/statisticsBusiness/getCourseSaleInfoByCourseLabel'),
method: 'post',
data: http.adornData({
date: dateStr
})
}).then(({ data }) => {
if (data && data.code === 0) {
this.dataList = data.courseSaleInfo || []
}
})
},
exportData() {
const dateStr = this.timeType === 'year'
? this.currentDate.getFullYear().toString()
: `${this.currentDate.getFullYear()}-${String(this.currentDate.getMonth() + 1).padStart(2, '0')}`
http({
url: http.adornUrl('/master/statisticsBusiness/exportCourseSaleInfoByCourseLabel'),
method: 'post',
data: http.adornData({
date: dateStr
}),
responseType: 'blob'
}).then((response) => {
const blob = new Blob([response.data])
const fileName = `按分类统计报表_${dateStr}.xlsx`
const link = document.createElement('a')
link.href = URL.createObjectURL(blob)
link.download = fileName
link.click()
URL.revokeObjectURL(link.href)
})
}
}
}
</script>
<style scoped lang="less">
.course-label-statistics-container {
display: flex;
flex-direction: column;
height: calc(100vh - 220px);
.table-container {
flex: 1;
overflow: hidden;
}
}
.el-form .el-form-item {
margin-bottom: 10px !important;
}
</style>