|
|
@@ -243,7 +243,7 @@
|
|
|
<view class="info-row">
|
|
|
<text class="info-label">优惠券</text>
|
|
|
<view class="coupon-selected" v-if="selectedCoupon">
|
|
|
- <text class="coupon-discount">-{{ formatPriceWithSymbol(selectedCoupon.value) }}</text>
|
|
|
+ <text class="coupon-discount">-{{ formatPriceWithSymbol(couponDiscount) }}</text>
|
|
|
<text class="coupon-name-tag">{{ selectedCoupon.name }}</text>
|
|
|
</view>
|
|
|
<view class="coupon-placeholder" v-else>
|
|
|
@@ -484,7 +484,7 @@
|
|
|
<script>
|
|
|
import { BrandColors } from '@/utils/brand-colors.js'
|
|
|
import config from '@/config.js'
|
|
|
-import { getCouponList, getCouponCheckoutList, addressList, getProductRequiredFields, getMyMembership, getGiftMembershipProgress, productDetail, getFamilyPlatformBalance, exchangeCouponByCf, shopDiscountCalculate, getSpecialPriceInfo } from '../../../utils/api.js'
|
|
|
+import { getCouponList, getCouponCheckoutList, addressList, getProductRequiredFields, getMyMembership, getGiftMembershipProgress, productDetail, getFamilyPlatformBalance, exchangeCouponByCf, shopDiscountCalculate, getSpecialPriceInfo, applyCoupon } from '../../../utils/api.js'
|
|
|
import { parseDate } from '@/utils/format.js'
|
|
|
import CountdownTag from '@/pages/shop/components/countdown-tag.vue'
|
|
|
import HandSignature from '@/components/hand-signature/hand-signature.vue'
|
|
|
@@ -513,6 +513,8 @@ export default {
|
|
|
exchangeableCoupons: [],
|
|
|
cfBalance: 0,
|
|
|
selectedCoupon: null,
|
|
|
+ couponDiscount: 0, // 服务端 /api/coupon/apply 返回的抵扣金额(分),前端只展示
|
|
|
+ couponApplying: false,
|
|
|
showCouponPicker: false,
|
|
|
pointsUsed: 0,
|
|
|
userTotalPoints: 0,
|
|
|
@@ -592,9 +594,7 @@ export default {
|
|
|
},
|
|
|
finalAmount() {
|
|
|
var total = (this.actualAmount || 0) + (this.freight || 0)
|
|
|
- if (this.selectedCoupon) {
|
|
|
- total = total - this.selectedCoupon.value
|
|
|
- }
|
|
|
+ total = total - (this.couponDiscount || 0)
|
|
|
total = total - (this.pointsUsed || 0)
|
|
|
total = total - this.giftPromoDiscount
|
|
|
if (total < 0) total = 0
|
|
|
@@ -602,9 +602,7 @@ export default {
|
|
|
},
|
|
|
maxPoints() {
|
|
|
var total = (this.actualAmount || 0) + (this.freight || 0)
|
|
|
- if (this.selectedCoupon) {
|
|
|
- total = total - this.selectedCoupon.value
|
|
|
- }
|
|
|
+ total = total - (this.couponDiscount || 0)
|
|
|
if (total < 0) total = 0
|
|
|
if (this.userTotalPoints < total) {
|
|
|
return this.userTotalPoints
|
|
|
@@ -789,11 +787,43 @@ export default {
|
|
|
selectCoupon(coupon) {
|
|
|
this.selectedCoupon = coupon
|
|
|
this.showCouponPicker = false
|
|
|
+ this.applyCouponDiscount()
|
|
|
},
|
|
|
removeCoupon() {
|
|
|
this.selectedCoupon = null
|
|
|
+ this.couponDiscount = 0
|
|
|
this.showCouponPicker = false
|
|
|
},
|
|
|
+ // 优惠券抵扣统一由服务端计算(券类型/满减门槛/会员范围/折扣千分比),
|
|
|
+ // 前端不再用 selectedCoupon.value 本地减额,保证展示与下单落库一致。
|
|
|
+ async applyCouponDiscount() {
|
|
|
+ if (!this.selectedCoupon) {
|
|
|
+ this.couponDiscount = 0
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var applyingCouponId = this.selectedCoupon.id
|
|
|
+ this.couponApplying = true
|
|
|
+ try {
|
|
|
+ var res = await applyCoupon({
|
|
|
+ userCouponId: this.selectedCoupon.id,
|
|
|
+ orderType: 'PRODUCT',
|
|
|
+ orderAmount: this.actualAmount || 0
|
|
|
+ })
|
|
|
+ // 期间用户可能已改选/取消券,丢弃过期响应
|
|
|
+ if (!this.selectedCoupon || this.selectedCoupon.id !== applyingCouponId) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ this.couponDiscount = (res && res.data && res.data.discount) || 0
|
|
|
+ } catch (e) {
|
|
|
+ if (this.selectedCoupon && this.selectedCoupon.id === applyingCouponId) {
|
|
|
+ // 服务端判定不可用(request 已提示 message),本地同步清空避免错误展示
|
|
|
+ this.selectedCoupon = null
|
|
|
+ this.couponDiscount = 0
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ this.couponApplying = false
|
|
|
+ }
|
|
|
+ },
|
|
|
onPointsInput(e) {
|
|
|
var val = parseInt(e.detail.value) || 0
|
|
|
if (val < 0) val = 0
|