1
This commit is contained in:
@@ -318,7 +318,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<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 { getAdminSelectData } from "@/api/system/superadmin";
|
||||||
import { mapGetters } from 'vuex'
|
import { mapGetters } from 'vuex'
|
||||||
import MobileSearchForm from '@/components/MobileSearchForm'
|
import MobileSearchForm from '@/components/MobileSearchForm'
|
||||||
@@ -436,104 +436,65 @@ export default {
|
|||||||
this.orderrowsList = response.rows;
|
this.orderrowsList = response.rows;
|
||||||
this.total = response.total;
|
this.total = response.total;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
// 调用后端统计接口计算统计数据
|
// 统计已合并到列表接口返回的 statistics,与列表同条件
|
||||||
this.loadStatistics();
|
this.applyStatistics(response.statistics);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.error('获取订单列表失败:', error);
|
console.error('获取订单列表失败:', error);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.$message.error('获取订单列表失败');
|
this.$message.error('获取订单列表失败');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
/** 加载统计数据(从后端获取) */
|
/** 使用列表接口返回的 statistics 填充统计(与列表同一次请求、同条件) */
|
||||||
loadStatistics() {
|
applyStatistics(data) {
|
||||||
// 构建统计查询参数,使用与列表查询相同的条件
|
if (!data) {
|
||||||
const statParams = {
|
if (this.orderrowsList.length > 0) this.calculateStatistics();
|
||||||
...this.queryParams,
|
else this.statistics = { totalOrders: 0, totalCosPrice: 0, totalEstimateFee: 0, totalActualFee: 0, statusStats: {}, accountStats: {} };
|
||||||
beginTime: this.dateRange && this.dateRange.length > 0 ? this.dateRange[0] : null,
|
return;
|
||||||
endTime: this.dateRange && this.dateRange.length > 1 ? this.dateRange[1] : null
|
|
||||||
};
|
|
||||||
|
|
||||||
getOrderStatistics(statParams).then(response => {
|
|
||||||
const data = response.data || {};
|
|
||||||
const groupStats = data.groupStats || {};
|
|
||||||
|
|
||||||
// 转换后端返回的统计格式为前端需要的格式
|
|
||||||
this.statistics = {
|
|
||||||
totalOrders: data.totalOrders || 0,
|
|
||||||
totalCosPrice: 0, // 后端没有返回此字段,如果需要可以前端计算或后端添加
|
|
||||||
totalEstimateFee: data.totalCommission || 0,
|
|
||||||
totalActualFee: data.totalActualFee || 0,
|
|
||||||
statusStats: {
|
|
||||||
cancel: this.convertGroupStat(groupStats.cancel),
|
|
||||||
invalid: this.convertGroupStat(groupStats.invalid),
|
|
||||||
pending: this.convertGroupStat(groupStats.pending),
|
|
||||||
paid: this.convertGroupStat(groupStats.paid),
|
|
||||||
finished: this.convertGroupStat(groupStats.finished),
|
|
||||||
deposit: this.convertGroupStat(groupStats.deposit),
|
|
||||||
illegal: this.convertGroupStat(groupStats.illegal)
|
|
||||||
},
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
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) {
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
const groupStats = data.groupStats || {};
|
||||||
|
this.statistics = {
|
||||||
|
totalOrders: data.totalOrders || 0,
|
||||||
|
totalCosPrice: data.totalCosPrice != null ? data.totalCosPrice : 0,
|
||||||
|
totalEstimateFee: data.totalCommission || 0,
|
||||||
|
totalActualFee: data.totalActualFee || 0,
|
||||||
|
statusStats: {
|
||||||
|
cancel: this.convertGroupStat(groupStats.cancel),
|
||||||
|
invalid: this.convertGroupStat(groupStats.invalid),
|
||||||
|
pending: this.convertGroupStat(groupStats.pending),
|
||||||
|
paid: this.convertGroupStat(groupStats.paid),
|
||||||
|
finished: this.convertGroupStat(groupStats.finished),
|
||||||
|
deposit: this.convertGroupStat(groupStats.deposit),
|
||||||
|
illegal: this.convertGroupStat(groupStats.illegal)
|
||||||
|
},
|
||||||
|
accountStats: {}
|
||||||
|
};
|
||||||
|
// 按账号统计仅用当前页列表轻量汇总
|
||||||
|
if (this.orderrowsList.length > 0) {
|
||||||
|
const accountStats = {};
|
||||||
|
this.orderrowsList.forEach(order => {
|
||||||
|
const unionId = order.unionId;
|
||||||
|
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) {
|
||||||
|
commissionAmount = parseFloat(order.estimateCosPrice) * parseFloat(order.commissionRate) / 100;
|
||||||
|
}
|
||||||
|
accountStats[unionId].amount += commissionAmount;
|
||||||
|
});
|
||||||
|
this.statistics.accountStats = accountStats;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
convertGroupStat(groupStat) {
|
||||||
|
if (!groupStat) return { label: '', count: 0, amount: 0 };
|
||||||
return {
|
return {
|
||||||
label: groupStat.label || '',
|
label: groupStat.label || '',
|
||||||
count: groupStat.count || 0,
|
count: groupStat.count || 0,
|
||||||
amount: groupStat.actualFee || 0 // 使用actualFee作为金额
|
amount: groupStat.actualFee ?? 0
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
/** 获取管理员列表 */
|
/** 获取管理员列表 */
|
||||||
|
|||||||
Reference in New Issue
Block a user