优化数据统计的传参以及部分展示字段以优化

This commit is contained in:
gyq
2025-11-24 16:37:49 +08:00
parent 7f76996829
commit 980f0357c1
5 changed files with 151 additions and 239 deletions

View File

@@ -11,7 +11,7 @@
<el-input placeholder="商品名称" v-model="query.productName" />
</el-form-item>
<el-form-item v-if="isHeadShop == 1&&loginType == 0">
<el-form-item v-if="isHeadShop == 1 && loginType == 0">
<el-select v-model="shopId" placeholder="选择分店" style="width: 200px; margin-right: 10px"
@change="getCategory">
<el-option v-for="item in branchList" :key="item.shopId" :label="item.shopName" :value="item.shopId" />
@@ -25,13 +25,13 @@
</template>
<el-form-item>
<el-radio-group v-model="timeValue" @change="timeChange">
<el-radio-button value="">全部</el-radio-button>
<el-radio-button value="0">今天</el-radio-button>
<el-radio-button value="-1">昨天</el-radio-button>
<el-radio-button value="-7">最近7天</el-radio-button>
<el-radio-button value="-30">最近30天</el-radio-button>
<el-radio-button value="week">本周</el-radio-button>
<el-radio-button value="month">本月</el-radio-button>
<!-- <el-radio-button value="">全部</el-radio-button> -->
<el-radio-button value="today">今天</el-radio-button>
<el-radio-button value="yesterday">昨天</el-radio-button>
<el-radio-button value="last_7_days">最近7天</el-radio-button>
<el-radio-button value="last_30_days">最近30天</el-radio-button>
<el-radio-button value="this_week">本周</el-radio-button>
<el-radio-button value="this_month">本月</el-radio-button>
<el-radio-button value="custom">自定义</el-radio-button>
</el-radio-group>
<el-date-picker class="u-m-l-10" v-model="query.createdAt" type="daterange" range-separator="至"
@@ -156,16 +156,18 @@
</template>
<script>
import _ from 'lodash'
import saleSummaryApi from "@/api/order/sale-summary";
import categoryApi from "@/api/product/productclassification";
import ShopApi from "@/api/account/shop";
import dayjs from "dayjs";
import { downloadFile } from "@/utils/index";
import { formatDateRange } from './utils/index.js'
export default {
data() {
return {
timeValue: "",
timeValue: "today",
resetQuery: null,
orderType: "2",
categorys: [],
@@ -175,6 +177,7 @@ export default {
prodCategoryId: "",
},
tableData: {
totalList: [],
data: [],
page: 1,
size: 10,
@@ -187,8 +190,8 @@ export default {
branchList: [],
shopId: null,
isHeadShop: JSON.parse(localStorage.getItem("userInfo")).isHeadShop,
loginType: localStorage.getItem("loginType")
loginType: localStorage.getItem("loginType"),
shopInfo: JSON.parse(localStorage.getItem("userInfo")),
};
},
filters: {
@@ -238,9 +241,10 @@ export default {
const res = await saleSummaryApi.count({
beginDate: this.query.createdAt[0],
endDate: this.query.createdAt[1],
rangeType: this.timeValue,
prodCategoryId: this.query.prodCategoryId,
productName: this.query.productName,
shopId: this.shopId,
shopId: this.shopInfo.id,
type: this.orderType,
});
this.payCount = res;
@@ -263,11 +267,10 @@ export default {
shopId: this.shopId
});
downloadFile(file, "数据", "xlsx");
this.downloadLoading = false;
} catch (error) {
this.downloadLoading = false;
console.log(error);
}
this.downloadLoading = false;
},
// 重置查询
resetHandle() {
@@ -284,7 +287,8 @@ export default {
// 分页回调
paginationChange(e) {
this.tableData.page = e;
this.getTableData();
this.tableData.data = this.tableData.totalList[this.tableData.page - 1] || [];
// this.getTableData();
},
async getTableData() {
this.tableData.loading = true;
@@ -299,71 +303,22 @@ export default {
type: this.orderType,
beginDate: this.query.createdAt[0],
endDate: this.query.createdAt[1],
rangeType: this.timeValue,
productName: this.query.productName,
prodCategoryId: this.query.prodCategoryId,
shopId: this.shopId
shopId: this.shopInfo.id,
});
this.tableData.loading = false;
this.tableData.data = res.records;
this.tableData.total = res.totalRow;
this.tableData.totalList = _.chunk(res, this.tableData.size);
this.tableData.data = this.tableData.totalList[this.tableData.page - 1] || [];
this.tableData.total = res.length;
} catch (error) {
console.log(error);
}
this.tableData.loading = false;
},
// 切换时间
timeChange(e) {
const format = ["YYYY-MM-DD 00:00:00", "YYYY-MM-DD 23:59:59"];
switch (e) {
case "":
// 全部
this.query.createdAt = [];
break;
case "0":
// 今天
this.query.createdAt = [dayjs().format(format[0]), dayjs().format(format[1])];
break;
case "-1":
// 昨天
this.query.createdAt = [
dayjs().add(-1, "d").format(format[0]),
dayjs().add(-1, "d").format(format[1]),
];
break;
case "-7":
// 最近7天
this.query.createdAt = [
dayjs().add(-7, "d").format(format[0]),
dayjs().format(format[1]),
];
break;
case "-30":
// 最近7天
this.query.createdAt = [
dayjs().add(-30, "d").format(format[0]),
dayjs().format(format[1]),
];
break;
case "week":
// 本周
this.query.createdAt = [
dayjs().startOf("week").format(format[0]),
dayjs().endOf("week").format(format[1]),
];
break;
case "month":
// 本周
this.query.createdAt = [
dayjs().startOf("month").format(format[0]),
dayjs().endOf("month").format(format[1]),
];
break;
case "custom":
// 自定义
this.query.createdAt = [];
break;
default:
break;
}
this.query.createdAt = formatDateRange(e)
},
},
};