This commit is contained in:
2025-09-19 17:20:09 +08:00
parent 7fcb6e61ce
commit 9654a1cbbd
8 changed files with 1094 additions and 58 deletions

View File

@@ -1,11 +1,11 @@
<template>
<div class="calendar" style="min-width: 1000px;overflow-x: auto;min-height: 100%;">
<div @click="handleExportAll()" style="position: absolute;left: 280px;top:35px;cursor: pointer;color: #006699;font-size: 14px;"><i class="el-icon-download"></i>下载 {{year}} 年全部报表</div>
<div v-if="allMonthData.length>0" @click="handleExportAll()" style="position: absolute; left: 360px;top:30px;cursor: pointer;color: #006699;font-size: 14px;"><i class="el-icon-download"></i>下载 {{year}} 年全部VIP报表</div>
<el-card class="box-card" v-for="(month, mIndex) in months"
<el-card class="box-card" v-for="(month, mIndex) in allMonthData"
:key="mIndex" >
<div slot="header" class="clearfix" >
<div style="color: #888;font-weight: 700;text-align: center;position: relative;font-size: 20px;">{{ monthNames[mIndex] }} <el-button @click="handleExport(mIndex)" style="float: right; padding: 3px 0;position: absolute;right: 0px;top: -2px;" type="text"><i class="el-icon-download"></i>下载报表</el-button>
<div style="color: #888;font-weight: 700;text-align: center;position: relative;font-size: 20px;">{{ month.month}} <el-button @click="handleExport(Number(month.month))" style="float: right; padding: 3px 0;position: absolute;right: 0px;top: -2px;" type="text"><i class="el-icon-download"></i>下载报表</el-button>
</div>
</div>
<div class="days" style="margin-bottom: 15px;">
@@ -13,14 +13,12 @@
<!-- <div v-for="blank in month.startWeek" :key="'b'+blank" class="day"></div> -->
<div v-for="d in list" :key="d" class="day header" style="margin-bottom: 10px;">{{ d.title }}</div>
<template v-if=" allMonthData[mIndex]&&allMonthData[mIndex].total">
<div v-for="d in list" :key="d" class="day" :style="`${d.val=='currentTanxiao'?'background-color:#ffdddd;color:#d00':''}`">{{
allMonthData[mIndex].total[d.val]
<div v-for="d in list" :key="d" class="day" :style="`${d.val=='currentTanxiao'?'background-color:#11cdba30;color:#d00':''}`">{{
month.total[d.val]
}}</div>
</template>
<div v-else>
-
</div>
<!-- <div
v-for="day in month.days"
@@ -39,19 +37,19 @@
<script>
// 获取当年到当前月的所有月份数组
function getMonths(year) {
const now = new Date()
const currentYear = now.getFullYear()
const currentMonth = now.getMonth() + 1 // 月份从0开始
const now = new Date();
const currentYear = now.getFullYear();
const currentMonth = now.getMonth() + 1; // 月份从0开始
// 如果是今年只取到当前月否则取12个月
const endMonth = (year == currentYear) ? currentMonth-1 : 12
const endMonth = year == currentYear ? currentMonth - 1 : 12;
let months = []
let months = [];
for (let i = 1; i <= endMonth; i++) {
let monthStr = i < 10 ? "0" + i : i // 补零
months.push(`${monthStr}`)
let monthStr = i < 10 ? "0" + i : i; // 补零
months.push(`${monthStr}`);
}
return months
return months;
}
export default {
@@ -65,6 +63,10 @@
marks: {
type: Object,
default: () => ({})
},
urlList: {
type: Object,
default: () => ({})
}
},
data() {
@@ -118,7 +120,7 @@
},
methods: {
async handleExportAll() {
const months = getMonths(this.year) // 例如 ["01","02",...,"09"]
const months = this.allMonthData.map(m => m.month); // 例如 ["01","02",...,"09"]
this.$message({
message: "所有月份的VIP报表正在下载请耐心等待...",
@@ -130,7 +132,7 @@
// 构造请求数组
const requests = months.map(m => {
return this.$http({
url: this.$http.adornUrl("/master/userVip/exportUserVipLogInfo"),
url: this.$http.adornUrl(this.urlList.export),
method: "post",
data: this.$http.adornData({ date: `${this.year}-${m}` }),
responseType: "blob"
@@ -173,30 +175,30 @@
async handleExport(mIndex) {
console.log('mIndex at line 120:', mIndex)
var filename = `VIP报表_${this.year}${this.pad(mIndex + 1)}月下载文件.xlsx`;
var filename = `VIP报表_${this.year}${this.pad(mIndex)}月下载文件.xlsx`;
this.$message({
message: "请耐心等待...",
type: "info",
duration: 6000,
duration: 3000,
showClose: true
});
try {
this.$http({
url: this.$http.adornUrl(
"/master/userVip/exportUserVipLogInfo"
this.urlList.export,
),
method: "post",
data: this.$http.adornData({
date: `${this.year}-${this.pad(mIndex + 1)}`
date: `${this.year}-${this.pad(mIndex)}`
}),
responseType: "blob" // ⚡⚡⚡一定要加上
}).then(res => {
this.$message({
message: "VIP报表文件下载中下载完成后文件会自动下载请耐心等待...",
type: "info",
duration: 6000,
showClose: true
});
// this.$message({
// message: "VIP报表文件下载中下载完成后文件会自动下载请耐心等待...",
// type: "info",
// duration: 6000,
// showClose: true
// });
const blob = new Blob([res.data], {
type:
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
@@ -257,9 +259,9 @@
console.log('months', months)
// 构造请求数组
const requests = months.map(m => {
const monthNum = parseInt(m.split("-")[1]) // 拿到 1,2,3...
const monthNum = m // 拿到 1,2,3...
return this.$http({
url: this.$http.adornUrl("/master/userVip/getUserVipLogInfoTotal"),
url: this.$http.adornUrl(this.urlList.list),
method: "post",
data: this.$http.adornData({ date: `${year}-${m}` })
}).then(res => {
@@ -277,7 +279,17 @@
Promise.all(requests).then(resArr => {
console.log("所有月份结果:", resArr)
loading.close()
this.allMonthData = resArr
this.allMonthData = resArr.filter(
r => r.total !== null && r.total.length !== 0
);
if(this.allMonthData.length==0){
this.$message({
message: "该年无数据",
type: "warning",
duration: 3000,
showClose: true
});
}
if (this.year == new Date().getFullYear()) {
const now = new Date()
const year = now.getFullYear()