功能:同步小程序流程
This commit is contained in:
@@ -1,8 +1,32 @@
|
||||
/**
|
||||
* Purpose: cartApi supports index.js by holding or executing the cart api page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const cartApi = require('../../api/cart')
|
||||
/**
|
||||
* Purpose: couponApi supports index.js by holding or executing the coupon api page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const couponApi = require('../../api/coupon')
|
||||
/**
|
||||
* Purpose: orderApi supports index.js by holding or executing the order api page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const orderApi = require('../../api/order')
|
||||
/**
|
||||
* Purpose: auth supports index.js by holding or executing the auth page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const auth = require('../../utils/auth')
|
||||
/**
|
||||
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const navigation = require('../../utils/navigation')
|
||||
/**
|
||||
* Purpose: theme supports index.js by holding or executing the theme page or API role.
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
const theme = require('../../utils/theme')
|
||||
const { resolveLegacyImage } = require('../../utils/file')
|
||||
const { NO_COUPON_KEY } = require('../../utils/config')
|
||||
@@ -16,10 +40,18 @@ const {
|
||||
parseAppointmentParts
|
||||
} = require('../../utils/format')
|
||||
|
||||
/**
|
||||
* Purpose: getCouponKey supports index.js by holding or executing the get coupon key page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getCouponKey(coupon) {
|
||||
return `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getCouponDisplay supports index.js by holding or executing the get coupon display page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getCouponDisplay(coupon) {
|
||||
if (Number(coupon.couponType) === 1) {
|
||||
return `${coupon.couponName} ${coupon.discountValue} 折`
|
||||
@@ -27,6 +59,10 @@ function getCouponDisplay(coupon) {
|
||||
return `${coupon.couponName} 满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: calculateCouponDiscount supports index.js by holding or executing the calculate coupon discount page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function calculateCouponDiscount(coupon, amount) {
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
@@ -48,6 +84,10 @@ function calculateCouponDiscount(coupon, amount) {
|
||||
return 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: buildCheckoutIssues supports index.js by holding or executing the build checkout issues page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function buildCheckoutIssues(items) {
|
||||
const issues = []
|
||||
const selectedItems = items.filter(item => item.selected)
|
||||
@@ -121,6 +161,11 @@ Page({
|
||||
cartItems: [],
|
||||
availableCoupons: [],
|
||||
selectedCouponKey: NO_COUPON_KEY,
|
||||
/**
|
||||
* Purpose: couponSelectionTouched records whether the user explicitly chose a coupon option.
|
||||
* Usage: keep normal user coupons manual-only while still allowing VIP auto coupons as default.
|
||||
*/
|
||||
couponSelectionTouched: false,
|
||||
selectedCount: 0,
|
||||
totalQuantity: 0,
|
||||
subtotalAmount: 0,
|
||||
@@ -201,6 +246,7 @@ Page({
|
||||
cartItems: [],
|
||||
availableCoupons: [],
|
||||
selectedCouponKey: NO_COUPON_KEY,
|
||||
couponSelectionTouched: false,
|
||||
loading: false
|
||||
})
|
||||
this.refreshSummary()
|
||||
@@ -239,7 +285,8 @@ Page({
|
||||
|
||||
this.setData({
|
||||
cartItems: formattedItems,
|
||||
selectedCouponKey: NO_COUPON_KEY
|
||||
selectedCouponKey: NO_COUPON_KEY,
|
||||
couponSelectionTouched: false
|
||||
})
|
||||
await this.loadAvailableCoupons()
|
||||
} catch (error) {
|
||||
@@ -267,7 +314,8 @@ Page({
|
||||
if (!selectedItems.length) {
|
||||
this.setData({
|
||||
availableCoupons: [],
|
||||
selectedCouponKey: NO_COUPON_KEY
|
||||
selectedCouponKey: NO_COUPON_KEY,
|
||||
couponSelectionTouched: false
|
||||
})
|
||||
this.refreshSummary()
|
||||
return
|
||||
@@ -305,8 +353,9 @@ Page({
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
*/
|
||||
if (selectedCouponKey === NO_COUPON_KEY) {
|
||||
if (selectedCouponKey === NO_COUPON_KEY && !this.data.couponSelectionTouched) {
|
||||
const bestCoupons = list
|
||||
.filter(item => item.sourceType === 'SYSTEM_VIP')
|
||||
.sort((left, right) => calculateCouponDiscount(right, subtotalAmount) - calculateCouponDiscount(left, subtotalAmount))
|
||||
/**
|
||||
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
@@ -324,7 +373,8 @@ Page({
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
availableCoupons: [],
|
||||
selectedCouponKey: NO_COUPON_KEY
|
||||
selectedCouponKey: NO_COUPON_KEY,
|
||||
couponSelectionTouched: false
|
||||
})
|
||||
} finally {
|
||||
this.refreshSummary()
|
||||
@@ -587,7 +637,8 @@ Page({
|
||||
*/
|
||||
handleCouponChange(event) {
|
||||
this.setData({
|
||||
selectedCouponKey: event.detail.value
|
||||
selectedCouponKey: event.detail.value,
|
||||
couponSelectionTouched: true
|
||||
})
|
||||
this.refreshSummary()
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user