問題描述:
分單時(shí)退款金額和退款商品數(shù)量的變化
解決方法:
手動(dòng)修改
- 文件路徑 src/pages/order/index.vue
- 在 template 中修改這段代碼
{{ row.productInfo.store_name }}
- 在 computed 中增加 productSelection
computed: {
refundProductNum() {
return this.refundProduct.reduce((total, { refundNum }) => (total + refundNum), 0);
},
// 退款商品選擇
productSelection() {
// 使用Map優(yōu)化性能
const productMap = new Map(this.refundProduct.map(item => [item.id, item]));
return this.refundSelection.filter(item => productMap.has(item.id)).map(item => productMap.get(item.id));
}
}
- 在 methods 中修改 submitRefund、selectionChange,增加 numChange、refundMoneyCompute
submitRefund() {
let data = {
refund_price: this.refundMoney,
is_split_order: this.isSplitOrder,
};
if (this.isSplitOrder) {
if (!this.refundSelection.length) {
return this.$Message.warning('請(qǐng)選擇需要退款的商品');
}
// 組裝退款商品
data.cart_ids = this.productSelection.map(({ id, refundNum }) => {
return { cart_id: id, cart_num: refundNum };
});
}
openRefund(this.selectOrderData.id, data).then(res => {
this.$Message.success(res.msg);
this.refundModal = false;
this.reloading = true;
this.limitTemp = this.orderData.limit;
this.pageTemp = this.orderData.page;
this.orderData.limit *= this.orderData.page;
this.orderData.page = 1;
this.getOrderList();
}).catch(res => {
this.$Message.error(res.msg);
});
},
// 選擇商品
selectionChange(selection) {
this.refundSelection = selection;
this.refundMoneyCompute();
},
// 改變商品數(shù)量
numChange() {
this.refundMoneyCompute();
},
// 計(jì)算退款金額
refundMoneyCompute() {
let refundMoney = 0;
for (const item of this.productSelection) {
try {
// 使用trycatch處理計(jì)算退款金額可能發(fā)生的錯(cuò)誤
refundMoney = this.$computes.Add(refundMoney, this.$computes.Mul(item.refundNum, item.refundPrice));
} catch (error) {
console.error('計(jì)算退款金額發(fā)生錯(cuò)誤', error);
break;
}
}
this.refundMoney = refundMoney;
}
替換修改
下載附件,解壓、替換對(duì)應(yīng)的文件,重新打包。打包文檔 https://doc.crmeb.com/pro/crmebprov2/2357