功能:完善门店能力与用户安全配置

This commit is contained in:
xiaowang
2026-05-18 10:04:57 +08:00
parent 4563dd2538
commit 3797938616
356 changed files with 24983 additions and 1858 deletions
+146 -3
View File
@@ -27,6 +27,10 @@ function getCouponDisplay(coupon) {
}
function calculateCouponDiscount(coupon, amount) {
/**
* `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 (!coupon || amount <= 0) {
return 0
}
@@ -47,32 +51,56 @@ function buildCheckoutIssues(items) {
const issues = []
const selectedItems = items.filter(item => item.selected)
/**
* `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 (!selectedItems.length) {
issues.push('请先勾选要结算的作品')
return issues
}
const missingArtist = selectedItems.find(item => !item.artistId)
/**
* `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 (missingArtist) {
issues.push(`请先为“${missingArtist.productTitle}”选择美甲师`)
}
const missingTime = selectedItems.find(item => !item.appointmentValue)
/**
* `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 (missingTime) {
issues.push(`请先为“${missingTime.productTitle}”选择预约时间`)
}
const expiredTime = selectedItems.find(item => item.appointmentValue && isPastAppointment(item.appointmentValue))
/**
* `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 (expiredTime) {
issues.push(`“${expiredTime.productTitle}”的预约时间已过,请重新选择`)
}
const shopIds = Array.from(new Set(selectedItems.map(item => item.shopId).filter(Boolean)))
/**
* `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 (shopIds.length > 1) {
issues.push('跨门店作品请分开结算')
}
const artistIds = Array.from(new Set(selectedItems.map(item => item.artistId).filter(Boolean)))
/**
* `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 (artistIds.length > 1) {
issues.push('不同美甲师的项目请分开结算')
}
@@ -80,6 +108,10 @@ function buildCheckoutIssues(items) {
return issues
}
/**
* cart page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: {
isLoggedIn: false,
@@ -98,6 +130,10 @@ Page({
submittingOrder: false
},
/**
* `onShow` 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.
*/
onShow() {
this.loadCartItems()
},
@@ -107,14 +143,26 @@ Page({
wx.stopPullDownRefresh()
},
/**
* `getSelectedItems` 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.
*/
getSelectedItems() {
return this.data.cartItems.filter(item => item.selected)
},
/**
* `getSelectedCoupon` 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.
*/
getSelectedCoupon() {
return this.data.availableCoupons.find(item => item.key === this.data.selectedCouponKey) || null
},
/**
* `refreshSummary` 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.
*/
refreshSummary() {
const selectedItems = this.getSelectedItems()
const selectedCoupon = this.getSelectedCoupon()
@@ -143,6 +191,10 @@ Page({
loading: isLoggedIn
})
/**
* `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 (!isLoggedIn) {
this.setData({
cartItems: [],
@@ -163,7 +215,10 @@ Page({
const availableArtists = Array.isArray(item.availableArtists) ? item.availableArtists.map(artist => ({
id: artist.id,
name: artist.name,
avatar: artist.avatar
avatar: artist.avatar,
userType: artist.userType,
roleLabel: artist.roleLabel,
participateProduction: artist.participateProduction
})) : []
const artist = availableArtists.find(current => String(current.id) === String(item.artistId || ''))
@@ -204,6 +259,10 @@ Page({
async loadAvailableCoupons() {
const selectedItems = this.getSelectedItems()
/**
* `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 (!selectedItems.length) {
this.setData({
availableCoupons: [],
@@ -241,9 +300,17 @@ Page({
selectedCouponKey = NO_COUPON_KEY
}
/**
* `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) {
const bestCoupons = list
.sort((left, right) => calculateCouponDiscount(right, subtotalAmount) - calculateCouponDiscount(left, subtotalAmount))
/**
* `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 (bestCoupons.length) {
selectedCouponKey = bestCoupons[0].key
}
@@ -263,10 +330,18 @@ Page({
}
},
/**
* `handleOpenAuth` 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.
*/
handleOpenAuth() {
navigation.openAuth('/pages/cart/index')
},
/**
* `handleBrowseProducts` 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.
*/
handleBrowseProducts() {
navigation.switchTab('/pages/products/index')
},
@@ -275,6 +350,10 @@ Page({
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
/**
* `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 (!item) {
return
}
@@ -296,11 +375,19 @@ Page({
const delta = Number(event.currentTarget.dataset.delta)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
/**
* `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 (!item) {
return
}
const nextQuantity = Number(item.quantity || 0) + delta
/**
* `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 (nextQuantity < 1 || nextQuantity > 99) {
return
}
@@ -337,6 +424,10 @@ Page({
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
/**
* `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 (!item) {
return
}
@@ -349,6 +440,10 @@ 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 (!confirmed) {
return
}
@@ -369,8 +464,16 @@ Page({
}
},
/**
* `handleOpenProduct` 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.
*/
handleOpenProduct(event) {
const productId = event.currentTarget.dataset.productId
/**
* `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 (!productId) {
return
}
@@ -384,10 +487,18 @@ Page({
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
/**
* `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 (!item) {
return
}
/**
* `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 (!item.availableArtists.length) {
wx.showToast({
title: '当前作品暂时没有可预约美甲师',
@@ -398,29 +509,41 @@ Page({
const tapIndex = await new Promise(resolve => {
wx.showActionSheet({
itemList: item.availableArtists.map(artist => artist.name),
itemList: item.availableArtists.map(artist => artist.roleLabel ? `${artist.name}(${artist.roleLabel})` : artist.name),
success: res => resolve(res.tapIndex),
fail: () => resolve(-1)
})
})
/**
* `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 (tapIndex < 0 || tapIndex >= item.availableArtists.length) {
return
}
const artist = item.availableArtists[tapIndex]
item.artistId = artist.id
item.artistName = artist.name
item.artistName = artist.roleLabel ? `${artist.name}(${artist.roleLabel})` : artist.name
this.setData({
cartItems
})
this.refreshSummary()
},
/**
* `handleDateChange` 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.
*/
handleDateChange(event) {
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
/**
* `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 (!item) {
return
}
@@ -433,10 +556,18 @@ Page({
this.refreshSummary()
},
/**
* `handleTimeChange` 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.
*/
handleTimeChange(event) {
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
/**
* `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 (!item) {
return
}
@@ -449,6 +580,10 @@ Page({
this.refreshSummary()
},
/**
* `handleCouponChange` 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.
*/
handleCouponChange(event) {
this.setData({
selectedCouponKey: event.detail.value
@@ -457,12 +592,20 @@ Page({
},
async handleCheckout() {
/**
* `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 (this.data.submittingOrder) {
return
}
const selectedItems = this.getSelectedItems()
const checkoutIssues = buildCheckoutIssues(this.data.cartItems)
/**
* `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 (checkoutIssues.length) {
wx.showToast({
title: checkoutIssues[0],