Commit 699613b5 by chenwq

```

feat(order): 添加优惠券核销功能

- 新增buildVehicleInfo方法用于构建车辆信息字符串
- 实现shouldVerifyCouponBeforeSubmit方法检查优惠券核销条件
- 添加confirmVerifyCouponBeforeSubmit方法显示核销确认弹窗
- 实现verifyCouponAndSubmitVoucher方法处理优惠券核销逻辑
- 在提交支付凭证前先进行优惠券核销验证
- 添加错误处理和加载状态管理
- 优化代码结构,将submitVoucher提取为独立方法
```
1 parent 2eccb4ba
......@@ -235,6 +235,15 @@ export default class OrderPaymentInfoPanel extends Vue {
];
}
buildVehicleInfo(): string {
const v = this.order?.vehicle;
if (!v) return "";
const city = v.ownership?.carCityName?.replace("市", "") ?? "";
const series = v.baseInfo?.carSeriesName ?? "";
const type = v.baseInfo?.carTypeName ?? "";
return `【${city}】${series} ${type}`.trim();
}
reloadOrderCoupons(): Promise<boolean> {
this.orderCouponsLoaded = false;
return CouponController.getOrderCoupons(this.axios, this.orderId)
......@@ -624,6 +633,84 @@ export default class OrderPaymentInfoPanel extends Vue {
uni.showToast({ title: "请上传支付凭证", icon: "none" });
return;
}
if (this.shouldVerifyCouponBeforeSubmit()) {
this.confirmVerifyCouponBeforeSubmit();
return;
}
this.submitVoucher();
}
shouldVerifyCouponBeforeSubmit(): boolean {
if (this.isCouponRowLocked || !this.hasSelectableCoupon) return false;
const couponId = this.selectedCouponId;
return couponId != null &&
couponId !== COUPON_SELECT_NONE &&
!!this.findCouponById(couponId);
}
confirmVerifyCouponBeforeSubmit(): void {
uni.showModal({
title: "提示",
content: "是否核销并使用优惠券?",
cancelText: "取消",
confirmText: "确认使用",
success: (res) => {
if (res.confirm) {
this.verifyCouponAndSubmitVoucher();
}
},
});
}
verifyCouponAndSubmitVoucher(): void {
if (this.couponVerifyLoading || !this.order) return;
const couponId = this.selectedCouponId;
if (!couponId || couponId === COUPON_SELECT_NONE) {
this.submitVoucher();
return;
}
this.couponVerifyLoading = true;
uni.showLoading({ title: "优惠券核销中...", mask: true });
CouponController.verifyCoupon(this.axios, {
couponId,
orderId: this.order.orderId,
orderCode: this.order.orderCode,
transactionAmount: this.order.orderPrice,
vehicleId: this.order.vehicle?.vehicleId,
vehicleInfo: this.buildVehicleInfo(),
})
.then((res) => {
const parsed = parseCouponVerifyResponse(res as AxiosResponse<unknown>);
if (!parsed.success) {
uni.hideLoading();
uni.showToast({ title: parsed.message || "核销失败", icon: "none" });
return Promise.resolve(false);
}
this.emitOrderPaySubmitOnVerifySuccess(couponId, parsed.data?.actualDeduction);
if (parsed.data?.actualDeduction != null && parsed.data.actualDeduction >= 0) {
const row = this.findCouponById(couponId);
if (row) row.actualDeduction = parsed.data.actualDeduction;
}
return this.reloadAfterCouponVerify();
})
.then((reloadOk: boolean | undefined) => {
if (reloadOk === true) {
this.submitVoucher();
return;
}
uni.hideLoading();
})
.catch(() => {
uni.hideLoading();
uni.showToast({ title: "核销失败", icon: "none" });
})
.finally(() => {
this.couponVerifyLoading = false;
});
}
submitVoucher(): void {
uni.hideLoading();
const transaction = new OrderTransaction();
transaction.auctionOrder = new AuctionOrder();
transaction.auctionOrder.orderId = this.orderId;
......@@ -644,6 +731,9 @@ export default class OrderPaymentInfoPanel extends Vue {
},
});
})
.catch(() => {
uni.showToast({ title: "提交失败,请稍后重试", icon: "none" });
})
.finally(() => {
this.voucherSubmitting = false;
uni.hideLoading();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!