1
This commit is contained in:
@@ -318,7 +318,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listOrderrows, getOrderrows, delOrderrows, addOrderrows, updateOrderrows, getValidCodeSelectData, getOrderStatistics } from "@/api/system/orderrows";
|
||||
import { listOrderrows, getOrderrows, delOrderrows, addOrderrows, updateOrderrows, getValidCodeSelectData } from "@/api/system/orderrows";
|
||||
import { getAdminSelectData } from "@/api/system/superadmin";
|
||||
import { mapGetters } from 'vuex'
|
||||
import MobileSearchForm from '@/components/MobileSearchForm'
|
||||
@@ -436,31 +436,25 @@ export default {
|
||||
this.orderrowsList = response.rows;
|
||||
this.total = response.total;
|
||||
this.loading = false;
|
||||
// 调用后端统计接口计算统计数据
|
||||
this.loadStatistics();
|
||||
// 统计已合并到列表接口返回的 statistics,与列表同条件
|
||||
this.applyStatistics(response.statistics);
|
||||
}).catch(error => {
|
||||
console.error('获取订单列表失败:', error);
|
||||
this.loading = false;
|
||||
this.$message.error('获取订单列表失败');
|
||||
});
|
||||
},
|
||||
/** 加载统计数据(从后端获取) */
|
||||
loadStatistics() {
|
||||
// 构建统计查询参数,使用与列表查询相同的条件
|
||||
const statParams = {
|
||||
...this.queryParams,
|
||||
beginTime: this.dateRange && this.dateRange.length > 0 ? this.dateRange[0] : null,
|
||||
endTime: this.dateRange && this.dateRange.length > 1 ? this.dateRange[1] : null
|
||||
};
|
||||
|
||||
getOrderStatistics(statParams).then(response => {
|
||||
const data = response.data || {};
|
||||
/** 使用列表接口返回的 statistics 填充统计(与列表同一次请求、同条件) */
|
||||
applyStatistics(data) {
|
||||
if (!data) {
|
||||
if (this.orderrowsList.length > 0) this.calculateStatistics();
|
||||
else this.statistics = { totalOrders: 0, totalCosPrice: 0, totalEstimateFee: 0, totalActualFee: 0, statusStats: {}, accountStats: {} };
|
||||
return;
|
||||
}
|
||||
const groupStats = data.groupStats || {};
|
||||
|
||||
// 转换后端返回的统计格式为前端需要的格式
|
||||
this.statistics = {
|
||||
totalOrders: data.totalOrders || 0,
|
||||
totalCosPrice: 0, // 后端没有返回此字段,如果需要可以前端计算或后端添加
|
||||
totalCosPrice: data.totalCosPrice != null ? data.totalCosPrice : 0,
|
||||
totalEstimateFee: data.totalCommission || 0,
|
||||
totalActualFee: data.totalActualFee || 0,
|
||||
statusStats: {
|
||||
@@ -472,68 +466,35 @@ export default {
|
||||
deposit: this.convertGroupStat(groupStats.deposit),
|
||||
illegal: this.convertGroupStat(groupStats.illegal)
|
||||
},
|
||||
accountStats: {} // 后端没有按账号统计,保留为空或后续添加
|
||||
accountStats: {}
|
||||
};
|
||||
|
||||
// 如果有订单列表,计算总计佣金额和按账号统计(这些前端计算更快)
|
||||
// 按账号统计仅用当前页列表轻量汇总
|
||||
if (this.orderrowsList.length > 0) {
|
||||
let totalCosPrice = 0;
|
||||
const accountStats = {};
|
||||
|
||||
this.orderrowsList.forEach(order => {
|
||||
// 总计佣金额
|
||||
if (order.estimateCosPrice) {
|
||||
totalCosPrice += parseFloat(order.estimateCosPrice) || 0;
|
||||
}
|
||||
|
||||
// 按账号统计
|
||||
const unionId = order.unionId;
|
||||
if (!accountStats[unionId]) {
|
||||
accountStats[unionId] = {
|
||||
count: 0,
|
||||
amount: 0
|
||||
};
|
||||
}
|
||||
if (!accountStats[unionId]) accountStats[unionId] = { count: 0, amount: 0 };
|
||||
accountStats[unionId].count++;
|
||||
|
||||
// 计算账号佣金金额(使用与后端相同的逻辑)
|
||||
const validCode = String(order.validCode);
|
||||
const isCancel = validCode === '3';
|
||||
const isIllegal = ['25', '26', '27', '28'].includes(validCode);
|
||||
|
||||
let commissionAmount = parseFloat(order.actualFee) || 0;
|
||||
if (isIllegal && order.estimateCosPrice && order.commissionRate) {
|
||||
commissionAmount = parseFloat(order.estimateCosPrice) * parseFloat(order.commissionRate) / 100;
|
||||
} else if (isCancel && (!order.actualFee || parseFloat(order.actualFee) === 0)
|
||||
&& order.estimateCosPrice && order.commissionRate) {
|
||||
} else if (isCancel && (!order.actualFee || parseFloat(order.actualFee) === 0) && order.estimateCosPrice && order.commissionRate) {
|
||||
commissionAmount = parseFloat(order.estimateCosPrice) * parseFloat(order.commissionRate) / 100;
|
||||
}
|
||||
|
||||
accountStats[unionId].amount += commissionAmount;
|
||||
});
|
||||
|
||||
this.statistics.totalCosPrice = totalCosPrice;
|
||||
this.statistics.accountStats = accountStats;
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error('获取统计数据失败:', error);
|
||||
// 如果后端统计失败,回退到前端计算
|
||||
this.calculateStatistics();
|
||||
});
|
||||
},
|
||||
/** 转换后端分组统计格式 */
|
||||
convertGroupStat(groupStat) {
|
||||
if (!groupStat) {
|
||||
return {
|
||||
label: '',
|
||||
count: 0,
|
||||
amount: 0
|
||||
};
|
||||
}
|
||||
if (!groupStat) return { label: '', count: 0, amount: 0 };
|
||||
return {
|
||||
label: groupStat.label || '',
|
||||
count: groupStat.count || 0,
|
||||
amount: groupStat.actualFee || 0 // 使用actualFee作为金额
|
||||
amount: groupStat.actualFee ?? 0
|
||||
};
|
||||
},
|
||||
/** 获取管理员列表 */
|
||||
|
||||
Reference in New Issue
Block a user