功能:新增微信小程序界面
This commit is contained in:
@@ -0,0 +1,496 @@
|
||||
const cartApi = require('../../api/cart')
|
||||
const couponApi = require('../../api/coupon')
|
||||
const orderApi = require('../../api/order')
|
||||
const auth = require('../../utils/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { resolveLegacyImage } = require('../../utils/file')
|
||||
const { NO_COUPON_KEY } = require('../../utils/config')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
const {
|
||||
buildAppointmentValue,
|
||||
formatDateTime,
|
||||
formatPrice,
|
||||
getMinDateText,
|
||||
isPastAppointment,
|
||||
parseAppointmentParts
|
||||
} = require('../../utils/format')
|
||||
|
||||
function getCouponKey(coupon) {
|
||||
return `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
|
||||
}
|
||||
|
||||
function getCouponDisplay(coupon) {
|
||||
if (Number(coupon.couponType) === 1) {
|
||||
return `${coupon.couponName} ${coupon.discountValue} 折`
|
||||
}
|
||||
return `${coupon.couponName} 满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
|
||||
}
|
||||
|
||||
function calculateCouponDiscount(coupon, amount) {
|
||||
if (!coupon || amount <= 0) {
|
||||
return 0
|
||||
}
|
||||
|
||||
if (Number(coupon.couponType) === 1) {
|
||||
const discountValue = Number(coupon.discountValue || 0)
|
||||
return discountValue ? amount - amount * discountValue / 10 : 0
|
||||
}
|
||||
|
||||
if (Number(coupon.couponType) === 2) {
|
||||
return Number(coupon.reduceAmount || 0)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function buildCheckoutIssues(items) {
|
||||
const issues = []
|
||||
const selectedItems = items.filter(item => item.selected)
|
||||
|
||||
if (!selectedItems.length) {
|
||||
issues.push('请先勾选要结算的作品')
|
||||
return issues
|
||||
}
|
||||
|
||||
const missingArtist = selectedItems.find(item => !item.artistId)
|
||||
if (missingArtist) {
|
||||
issues.push(`请先为“${missingArtist.productTitle}”选择美甲师`)
|
||||
}
|
||||
|
||||
const missingTime = selectedItems.find(item => !item.appointmentValue)
|
||||
if (missingTime) {
|
||||
issues.push(`请先为“${missingTime.productTitle}”选择预约时间`)
|
||||
}
|
||||
|
||||
const expiredTime = selectedItems.find(item => item.appointmentValue && isPastAppointment(item.appointmentValue))
|
||||
if (expiredTime) {
|
||||
issues.push(`“${expiredTime.productTitle}”的预约时间已过,请重新选择`)
|
||||
}
|
||||
|
||||
const shopIds = Array.from(new Set(selectedItems.map(item => item.shopId).filter(Boolean)))
|
||||
if (shopIds.length > 1) {
|
||||
issues.push('跨门店作品请分开结算')
|
||||
}
|
||||
|
||||
const artistIds = Array.from(new Set(selectedItems.map(item => item.artistId).filter(Boolean)))
|
||||
if (artistIds.length > 1) {
|
||||
issues.push('不同美甲师的项目请分开结算')
|
||||
}
|
||||
|
||||
return issues
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
isLoggedIn: false,
|
||||
loading: false,
|
||||
minDate: getMinDateText(),
|
||||
cartItems: [],
|
||||
availableCoupons: [],
|
||||
selectedCouponKey: NO_COUPON_KEY,
|
||||
selectedCount: 0,
|
||||
totalQuantity: 0,
|
||||
subtotalAmount: 0,
|
||||
subtotalText: '¥0.00',
|
||||
discountAmountText: '¥0.00',
|
||||
totalAmountText: '¥0.00',
|
||||
checkoutIssues: []
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadCartItems()
|
||||
},
|
||||
|
||||
async onPullDownRefresh() {
|
||||
await this.loadCartItems()
|
||||
wx.stopPullDownRefresh()
|
||||
},
|
||||
|
||||
getSelectedItems() {
|
||||
return this.data.cartItems.filter(item => item.selected)
|
||||
},
|
||||
|
||||
getSelectedCoupon() {
|
||||
return this.data.availableCoupons.find(item => item.key === this.data.selectedCouponKey) || null
|
||||
},
|
||||
|
||||
refreshSummary() {
|
||||
const selectedItems = this.getSelectedItems()
|
||||
const selectedCoupon = this.getSelectedCoupon()
|
||||
const selectedCount = selectedItems.length
|
||||
const totalQuantity = selectedItems.reduce((sum, item) => sum + Number(item.quantity || 0), 0)
|
||||
const subtotalAmount = selectedItems.reduce((sum, item) => sum + Number(item.price || 0) * Number(item.quantity || 0), 0)
|
||||
const discountAmount = calculateCouponDiscount(selectedCoupon, subtotalAmount)
|
||||
const totalAmount = Math.max(0, subtotalAmount - discountAmount)
|
||||
const checkoutIssues = buildCheckoutIssues(this.data.cartItems)
|
||||
|
||||
this.setData({
|
||||
selectedCount,
|
||||
totalQuantity,
|
||||
subtotalAmount,
|
||||
subtotalText: `¥${formatPrice(subtotalAmount)}`,
|
||||
discountAmountText: `¥${formatPrice(discountAmount)}`,
|
||||
totalAmountText: `¥${formatPrice(totalAmount)}`,
|
||||
checkoutIssues
|
||||
})
|
||||
},
|
||||
|
||||
async loadCartItems() {
|
||||
const isLoggedIn = auth.isLoggedIn()
|
||||
this.setData({
|
||||
isLoggedIn,
|
||||
loading: isLoggedIn
|
||||
})
|
||||
|
||||
if (!isLoggedIn) {
|
||||
this.setData({
|
||||
cartItems: [],
|
||||
availableCoupons: [],
|
||||
selectedCouponKey: NO_COUPON_KEY,
|
||||
loading: false
|
||||
})
|
||||
this.refreshSummary()
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const cartItems = await cartApi.getCartList()
|
||||
const list = Array.isArray(cartItems) ? cartItems : []
|
||||
const formattedItems = await Promise.all(list.map(async item => {
|
||||
const appointmentParts = parseAppointmentParts(item.appointmentTime)
|
||||
const productImageUrl = await resolveLegacyImage(item.productImage)
|
||||
const availableArtists = Array.isArray(item.availableArtists) ? item.availableArtists.map(artist => ({
|
||||
id: artist.id,
|
||||
name: artist.name,
|
||||
avatar: artist.avatar
|
||||
})) : []
|
||||
const artist = availableArtists.find(current => String(current.id) === String(item.artistId || ''))
|
||||
|
||||
return {
|
||||
...item,
|
||||
productImageUrl,
|
||||
priceText: `¥${formatPrice(item.price)}`,
|
||||
selected: true,
|
||||
artistId: item.artistId || '',
|
||||
artistName: artist ? artist.name : '',
|
||||
availableArtists,
|
||||
appointmentDate: appointmentParts.date,
|
||||
appointmentClock: appointmentParts.clock,
|
||||
appointmentValue: buildAppointmentValue(appointmentParts.date, appointmentParts.clock)
|
||||
}
|
||||
}))
|
||||
|
||||
this.setData({
|
||||
cartItems: formattedItems,
|
||||
selectedCouponKey: NO_COUPON_KEY
|
||||
})
|
||||
await this.loadAvailableCoupons()
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
cartItems: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '购物车加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
this.refreshSummary()
|
||||
}
|
||||
},
|
||||
|
||||
async loadAvailableCoupons() {
|
||||
const selectedItems = this.getSelectedItems()
|
||||
if (!selectedItems.length) {
|
||||
this.setData({
|
||||
availableCoupons: [],
|
||||
selectedCouponKey: NO_COUPON_KEY
|
||||
})
|
||||
this.refreshSummary()
|
||||
return
|
||||
}
|
||||
|
||||
const tags = new Set()
|
||||
const subtotalAmount = selectedItems.reduce((sum, item) => sum + Number(item.price || 0) * Number(item.quantity || 0), 0)
|
||||
selectedItems.forEach(item => {
|
||||
String(item.tagNames || '')
|
||||
.split(',')
|
||||
.map(tag => tag.trim())
|
||||
.filter(Boolean)
|
||||
.forEach(tag => tags.add(tag))
|
||||
})
|
||||
|
||||
try {
|
||||
const coupons = await couponApi.getAvailableCoupons(
|
||||
Array.from(tags).join(','),
|
||||
subtotalAmount,
|
||||
selectedItems[0].shopId
|
||||
)
|
||||
|
||||
const list = Array.isArray(coupons) ? coupons.map(item => ({
|
||||
...item,
|
||||
key: getCouponKey(item),
|
||||
displayText: getCouponDisplay(item)
|
||||
})) : []
|
||||
|
||||
let selectedCouponKey = this.data.selectedCouponKey
|
||||
if (selectedCouponKey !== NO_COUPON_KEY && !list.find(item => item.key === selectedCouponKey)) {
|
||||
selectedCouponKey = NO_COUPON_KEY
|
||||
}
|
||||
|
||||
if (selectedCouponKey === NO_COUPON_KEY) {
|
||||
const vipCoupons = list
|
||||
.filter(item => item.sourceType === 'SYSTEM_VIP')
|
||||
.sort((left, right) => calculateCouponDiscount(right, subtotalAmount) - calculateCouponDiscount(left, subtotalAmount))
|
||||
if (vipCoupons.length) {
|
||||
selectedCouponKey = vipCoupons[0].key
|
||||
}
|
||||
}
|
||||
|
||||
this.setData({
|
||||
availableCoupons: list,
|
||||
selectedCouponKey
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
availableCoupons: [],
|
||||
selectedCouponKey: NO_COUPON_KEY
|
||||
})
|
||||
} finally {
|
||||
this.refreshSummary()
|
||||
}
|
||||
},
|
||||
|
||||
handleOpenAuth() {
|
||||
navigation.openAuth('/pages/cart/index')
|
||||
},
|
||||
|
||||
handleBrowseProducts() {
|
||||
navigation.switchTab('/pages/products/index')
|
||||
},
|
||||
|
||||
async handleToggleSelect(event) {
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
const cartItems = this.data.cartItems.slice()
|
||||
const item = cartItems[index]
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
item.selected = !item.selected
|
||||
this.setData({
|
||||
cartItems
|
||||
})
|
||||
|
||||
if (cartItems.some(current => current.selected)) {
|
||||
await runWithLoading(() => this.loadAvailableCoupons())
|
||||
return
|
||||
}
|
||||
|
||||
await this.loadAvailableCoupons()
|
||||
},
|
||||
|
||||
async handleChangeQuantity(event) {
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
const delta = Number(event.currentTarget.dataset.delta)
|
||||
const cartItems = this.data.cartItems.slice()
|
||||
const item = cartItems[index]
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
|
||||
const nextQuantity = Number(item.quantity || 0) + delta
|
||||
if (nextQuantity < 1 || nextQuantity > 99) {
|
||||
return
|
||||
}
|
||||
|
||||
item.quantity = nextQuantity
|
||||
this.setData({
|
||||
cartItems
|
||||
})
|
||||
this.refreshSummary()
|
||||
|
||||
try {
|
||||
await runWithLoading(async () => {
|
||||
await cartApi.updateCartQuantity({
|
||||
productId: item.productId,
|
||||
quantity: nextQuantity
|
||||
})
|
||||
await this.loadAvailableCoupons()
|
||||
})
|
||||
await getApp().updateCartBadge()
|
||||
} catch (error) {
|
||||
item.quantity -= delta
|
||||
this.setData({
|
||||
cartItems
|
||||
})
|
||||
this.refreshSummary()
|
||||
wx.showToast({
|
||||
title: error.message || '数量更新失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleRemoveItem(event) {
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
const cartItems = this.data.cartItems.slice()
|
||||
const item = cartItems[index]
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
|
||||
const confirmed = await new Promise(resolve => {
|
||||
wx.showModal({
|
||||
title: '移除作品',
|
||||
content: '确认从购物车移除这件作品吗?',
|
||||
success: res => resolve(Boolean(res.confirm))
|
||||
})
|
||||
})
|
||||
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => cartApi.removeFromCart(item.productId))
|
||||
wx.showToast({
|
||||
title: '已移出购物车',
|
||||
icon: 'none'
|
||||
})
|
||||
await getApp().updateCartBadge()
|
||||
this.loadCartItems()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '移除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleOpenProduct(event) {
|
||||
const productId = event.currentTarget.dataset.productId
|
||||
if (!productId) {
|
||||
return
|
||||
}
|
||||
|
||||
navigation.navigate('/pages/product-detail/index', {
|
||||
id: productId
|
||||
})
|
||||
},
|
||||
|
||||
async handleChooseArtist(event) {
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
const cartItems = this.data.cartItems.slice()
|
||||
const item = cartItems[index]
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!item.availableArtists.length) {
|
||||
wx.showToast({
|
||||
title: '当前作品暂时没有可预约美甲师',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const tapIndex = await new Promise(resolve => {
|
||||
wx.showActionSheet({
|
||||
itemList: item.availableArtists.map(artist => artist.name),
|
||||
success: res => resolve(res.tapIndex),
|
||||
fail: () => resolve(-1)
|
||||
})
|
||||
})
|
||||
|
||||
if (tapIndex < 0 || tapIndex >= item.availableArtists.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const artist = item.availableArtists[tapIndex]
|
||||
item.artistId = artist.id
|
||||
item.artistName = artist.name
|
||||
this.setData({
|
||||
cartItems
|
||||
})
|
||||
this.refreshSummary()
|
||||
},
|
||||
|
||||
handleDateChange(event) {
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
const cartItems = this.data.cartItems.slice()
|
||||
const item = cartItems[index]
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
|
||||
item.appointmentDate = event.detail.value
|
||||
item.appointmentValue = buildAppointmentValue(item.appointmentDate, item.appointmentClock)
|
||||
this.setData({
|
||||
cartItems
|
||||
})
|
||||
this.refreshSummary()
|
||||
},
|
||||
|
||||
handleTimeChange(event) {
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
const cartItems = this.data.cartItems.slice()
|
||||
const item = cartItems[index]
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
|
||||
item.appointmentClock = event.detail.value
|
||||
item.appointmentValue = buildAppointmentValue(item.appointmentDate, item.appointmentClock)
|
||||
this.setData({
|
||||
cartItems
|
||||
})
|
||||
this.refreshSummary()
|
||||
},
|
||||
|
||||
handleCouponChange(event) {
|
||||
this.setData({
|
||||
selectedCouponKey: event.detail.value
|
||||
})
|
||||
this.refreshSummary()
|
||||
},
|
||||
|
||||
async handleCheckout() {
|
||||
const selectedItems = this.getSelectedItems()
|
||||
const checkoutIssues = buildCheckoutIssues(this.data.cartItems)
|
||||
if (checkoutIssues.length) {
|
||||
wx.showToast({
|
||||
title: checkoutIssues[0],
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const selectedCoupon = this.getSelectedCoupon()
|
||||
await runWithLoading(() => orderApi.createOrder({
|
||||
couponId: selectedCoupon ? selectedCoupon.id : undefined,
|
||||
couponSourceType: selectedCoupon ? selectedCoupon.sourceType : (this.data.selectedCouponKey === NO_COUPON_KEY ? NO_COUPON_KEY : undefined),
|
||||
items: selectedItems.map(item => ({
|
||||
productId: item.productId,
|
||||
quantity: item.quantity,
|
||||
artistId: item.artistId,
|
||||
appointmentTime: item.appointmentValue
|
||||
}))
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '订单创建成功',
|
||||
icon: 'none'
|
||||
})
|
||||
await getApp().updateCartBadge()
|
||||
await this.loadCartItems()
|
||||
navigation.navigate('/pages/orders/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '订单创建失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
},
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<navigation-bar title="购物车" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
|
||||
|
||||
<view class="page-shell cart-page">
|
||||
<view class="page-content cart-content">
|
||||
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
|
||||
<text class="empty-title">登录后查看购物车</text>
|
||||
<text class="empty-desc">把喜欢的作品加进购物车后,就能补全预约信息并提交订单。</text>
|
||||
<view class="ghost-btn" bindtap="handleOpenAuth">去登录</view>
|
||||
</view>
|
||||
|
||||
<block wx:elif="{{cartItems.length}}">
|
||||
<view class="page-hero cart-hero">
|
||||
<text class="hero-kicker">结算准备</text>
|
||||
<text class="hero-title">已选 {{selectedCount}} 个预约项目</text>
|
||||
<text class="hero-desc">先确认美甲师和预约时间,再统一提交订单,避免来回修改。</text>
|
||||
|
||||
<view class="summary-strip">
|
||||
<view class="summary-metric">
|
||||
<text class="summary-label">选中项目</text>
|
||||
<text class="summary-value">{{selectedCount}} 项</text>
|
||||
<text class="summary-note">可分批勾选结算</text>
|
||||
</view>
|
||||
<view class="summary-metric">
|
||||
<text class="summary-label">数量合计</text>
|
||||
<text class="summary-value">{{totalQuantity}} 件</text>
|
||||
<text class="summary-note">支持直接增减数量</text>
|
||||
</view>
|
||||
<view class="summary-metric">
|
||||
<text class="summary-label">待支付</text>
|
||||
<text class="summary-value">{{totalAmountText}}</text>
|
||||
<text class="summary-note">已自动计算优惠</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{checkoutIssues.length}}" class="issue-card">
|
||||
<view class="issue-title">下单前还需要完善</view>
|
||||
<view wx:for="{{checkoutIssues}}" wx:key="*this" class="issue-item">{{index + 1}}. {{item}}</view>
|
||||
</view>
|
||||
|
||||
<view wx:for="{{cartItems}}" wx:key="id" class="page-card cart-item-card">
|
||||
<view class="cart-item-top">
|
||||
<view class="select-dot {{item.selected ? 'active' : ''}}" data-index="{{index}}" bindtap="handleToggleSelect"></view>
|
||||
<image class="cart-thumb" src="{{item.productImageUrl}}" mode="aspectFill" data-product-id="{{item.productId}}" bindtap="handleOpenProduct"></image>
|
||||
<view class="cart-main">
|
||||
<view class="cart-title-row">
|
||||
<view class="cart-title" data-product-id="{{item.productId}}" bindtap="handleOpenProduct">{{item.productTitle}}</view>
|
||||
<view class="cart-price">{{item.priceText}}</view>
|
||||
</view>
|
||||
<view class="cart-meta-row">
|
||||
<text class="meta-chip">{{item.selected ? '已选中' : '未选中'}}</text>
|
||||
<text wx:if="{{item.approximateDuration}}" class="cart-meta">预计时长 {{item.approximateDuration}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="selector-group">
|
||||
<view class="selector-row {{item.selected && !item.artistId ? 'issue' : ''}}" data-index="{{index}}" bindtap="handleChooseArtist">
|
||||
<text class="selector-label">美甲师</text>
|
||||
<text class="selector-value">{{item.artistName || '请选择美甲师'}}</text>
|
||||
</view>
|
||||
|
||||
<view class="time-grid">
|
||||
<picker mode="date" value="{{item.appointmentDate}}" start="{{minDate}}" data-index="{{index}}" bindchange="handleDateChange">
|
||||
<view class="selector-row compact {{item.selected && !item.appointmentDate ? 'issue' : ''}}">
|
||||
<text class="selector-label">日期</text>
|
||||
<text class="selector-value">{{item.appointmentDate || '选择日期'}}</text>
|
||||
</view>
|
||||
</picker>
|
||||
|
||||
<picker mode="time" value="{{item.appointmentClock}}" data-index="{{index}}" bindchange="handleTimeChange">
|
||||
<view class="selector-row compact {{item.selected && !item.appointmentClock ? 'issue' : ''}}">
|
||||
<text class="selector-label">时间</text>
|
||||
<text class="selector-value">{{item.appointmentClock || '选择时间'}}</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{item.appointmentValue}}" class="appointment-preview">
|
||||
当前预约:{{item.appointmentValue}}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="cart-item-foot">
|
||||
<view class="qty-box">
|
||||
<view class="qty-btn" data-index="{{index}}" data-delta="-1" bindtap="handleChangeQuantity">-</view>
|
||||
<text class="qty-value">{{item.quantity}}</text>
|
||||
<view class="qty-btn" data-index="{{index}}" data-delta="1" bindtap="handleChangeQuantity">+</view>
|
||||
</view>
|
||||
<view class="remove-btn" data-index="{{index}}" bindtap="handleRemoveItem">移除</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{selectedCount}}" class="page-card coupon-card">
|
||||
<view class="section-title">优惠方式</view>
|
||||
<view class="section-subtitle">系统会优先帮你匹配最合适的 VIP 自动折扣,普通优惠券仍可手动改选。</view>
|
||||
|
||||
<radio-group bindchange="handleCouponChange">
|
||||
<label class="coupon-option">
|
||||
<radio value="NONE" checked="{{selectedCouponKey === 'NONE'}}" color="#c6597d"></radio>
|
||||
<view class="coupon-texts">
|
||||
<view class="coupon-name">不使用优惠</view>
|
||||
</view>
|
||||
</label>
|
||||
|
||||
<label wx:for="{{availableCoupons}}" wx:key="key" wx:for-item="coupon" class="coupon-option {{selectedCouponKey === coupon.key ? 'active' : ''}}">
|
||||
<radio value="{{coupon.key}}" checked="{{selectedCouponKey === coupon.key}}" color="#c6597d"></radio>
|
||||
<view class="coupon-texts">
|
||||
<view class="coupon-name">{{coupon.displayText}}</view>
|
||||
<view class="coupon-desc">{{coupon.sourceType === 'SYSTEM_VIP' ? 'VIP 自动折扣' : '用户优惠券'}}</view>
|
||||
</view>
|
||||
<view class="coupon-tag">{{coupon.sourceType === 'SYSTEM_VIP' ? '推荐' : '手动选择'}}</view>
|
||||
</label>
|
||||
</radio-group>
|
||||
</view>
|
||||
|
||||
<view class="page-card summary-card">
|
||||
<view class="summary-row">
|
||||
<text>选中项目</text>
|
||||
<text>{{selectedCount}} 项</text>
|
||||
</view>
|
||||
<view class="summary-row">
|
||||
<text>作品数量</text>
|
||||
<text>{{totalQuantity}} 件</text>
|
||||
</view>
|
||||
<view class="summary-row">
|
||||
<text>小计</text>
|
||||
<text>{{subtotalText}}</text>
|
||||
</view>
|
||||
<view class="summary-row">
|
||||
<text>优惠</text>
|
||||
<text>-{{discountAmountText}}</text>
|
||||
</view>
|
||||
<view class="summary-row total">
|
||||
<text>合计</text>
|
||||
<text>{{totalAmountText}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<view wx:elif="{{loading}}" class="page-card empty-card">
|
||||
<text class="empty-title">正在加载购物车</text>
|
||||
</view>
|
||||
|
||||
<view wx:else class="page-card empty-card">
|
||||
<text class="empty-title">购物车还是空的</text>
|
||||
<text class="empty-desc">先把喜欢的作品加进来,再补充预约时间和美甲师。</text>
|
||||
<view class="ghost-btn" bindtap="handleBrowseProducts">去逛作品</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{isLoggedIn && cartItems.length}}" class="checkout-bar">
|
||||
<view class="checkout-copy">
|
||||
<view class="checkout-total">{{totalAmountText}}</view>
|
||||
<view class="checkout-meta">已选 {{selectedCount}} 项</view>
|
||||
</view>
|
||||
<view class="checkout-btn" bindtap="handleCheckout">提交订单</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,326 @@
|
||||
.cart-page {
|
||||
padding-bottom: calc(env(safe-area-inset-bottom) + 150rpx);
|
||||
}
|
||||
|
||||
.cart-content {
|
||||
padding-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.cart-hero {
|
||||
background:
|
||||
radial-gradient(circle at top right, rgba(255, 192, 210, 0.42), transparent 34%),
|
||||
linear-gradient(145deg, #fffdfd 0%, #fff2f6 56%, #ffe7ef 100%);
|
||||
}
|
||||
|
||||
.issue-card {
|
||||
margin-top: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
padding: 22rpx 24rpx;
|
||||
border-radius: 24rpx;
|
||||
background: #fff7e8;
|
||||
color: #9b6900;
|
||||
}
|
||||
|
||||
.issue-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.issue-item {
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.cart-item-card + .cart-item-card,
|
||||
.coupon-card,
|
||||
.summary-card {
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
|
||||
.cart-item-card {
|
||||
padding: 24rpx;
|
||||
}
|
||||
|
||||
.cart-item-top {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.select-dot {
|
||||
width: 34rpx;
|
||||
height: 34rpx;
|
||||
margin-top: 8rpx;
|
||||
border-radius: 50%;
|
||||
border: 4rpx solid #d8c4cc;
|
||||
}
|
||||
|
||||
.select-dot.active {
|
||||
border-color: #c6597d;
|
||||
background: #c6597d;
|
||||
}
|
||||
|
||||
.cart-thumb {
|
||||
width: 140rpx;
|
||||
height: 140rpx;
|
||||
border-radius: 22rpx;
|
||||
background: #f6edf1;
|
||||
}
|
||||
|
||||
.cart-main {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.cart-title-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.cart-title {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
line-height: 1.5;
|
||||
color: #2d2430;
|
||||
}
|
||||
|
||||
.cart-price {
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #d5536f;
|
||||
}
|
||||
|
||||
.cart-meta-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
margin-top: 12rpx;
|
||||
}
|
||||
|
||||
.meta-chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 42rpx;
|
||||
padding: 0 16rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #fff1f5;
|
||||
color: #c6597d;
|
||||
font-size: 20rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.cart-meta {
|
||||
font-size: 24rpx;
|
||||
color: #8d7a84;
|
||||
}
|
||||
|
||||
.selector-group {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.selector-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
min-height: 76rpx;
|
||||
padding: 0 22rpx;
|
||||
border-radius: 20rpx;
|
||||
background: #fbf5f7;
|
||||
}
|
||||
|
||||
.selector-row.compact {
|
||||
min-height: 72rpx;
|
||||
}
|
||||
|
||||
.selector-row.issue {
|
||||
background: #fff7e8;
|
||||
}
|
||||
|
||||
.selector-label {
|
||||
font-size: 24rpx;
|
||||
color: #8d7a84;
|
||||
}
|
||||
|
||||
.selector-value {
|
||||
font-size: 24rpx;
|
||||
color: #2d2430;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.time-grid {
|
||||
display: flex;
|
||||
gap: 14rpx;
|
||||
margin-top: 14rpx;
|
||||
}
|
||||
|
||||
.time-grid picker {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.appointment-preview {
|
||||
margin-top: 14rpx;
|
||||
font-size: 24rpx;
|
||||
color: #8d7a84;
|
||||
}
|
||||
|
||||
.cart-item-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.qty-box {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.qty-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 56rpx;
|
||||
height: 56rpx;
|
||||
border-radius: 50%;
|
||||
background: #fbf5f7;
|
||||
color: #7a5262;
|
||||
font-size: 34rpx;
|
||||
}
|
||||
|
||||
.qty-value {
|
||||
min-width: 48rpx;
|
||||
text-align: center;
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
color: #2d2430;
|
||||
}
|
||||
|
||||
.remove-btn {
|
||||
font-size: 24rpx;
|
||||
color: #d5536f;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.coupon-card,
|
||||
.summary-card {
|
||||
padding: 26rpx;
|
||||
}
|
||||
|
||||
.coupon-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 18rpx;
|
||||
margin-top: 20rpx;
|
||||
padding: 20rpx 0;
|
||||
border-top: 2rpx solid #f6eaee;
|
||||
}
|
||||
|
||||
.coupon-option:first-child {
|
||||
border-top: 0;
|
||||
padding-top: 10rpx;
|
||||
}
|
||||
|
||||
.coupon-option.active {
|
||||
color: #c6597d;
|
||||
}
|
||||
|
||||
.coupon-texts {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.coupon-name {
|
||||
font-size: 26rpx;
|
||||
font-weight: 700;
|
||||
color: #2d2430;
|
||||
}
|
||||
|
||||
.coupon-desc {
|
||||
margin-top: 8rpx;
|
||||
font-size: 22rpx;
|
||||
color: #8d7a84;
|
||||
}
|
||||
|
||||
.coupon-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 92rpx;
|
||||
height: 44rpx;
|
||||
padding: 0 14rpx;
|
||||
border-radius: 999rpx;
|
||||
background: #fff1f5;
|
||||
color: #c6597d;
|
||||
font-size: 20rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.summary-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10rpx 0;
|
||||
font-size: 26rpx;
|
||||
color: #5d4b55;
|
||||
}
|
||||
|
||||
.summary-row.total {
|
||||
margin-top: 10rpx;
|
||||
padding-top: 18rpx;
|
||||
border-top: 2rpx solid #f3e7eb;
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #2d2430;
|
||||
}
|
||||
|
||||
.checkout-bar {
|
||||
position: fixed;
|
||||
left: 24rpx;
|
||||
right: 24rpx;
|
||||
bottom: calc(env(safe-area-inset-bottom) + 20rpx);
|
||||
z-index: 20;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 20rpx;
|
||||
padding: 18rpx 20rpx;
|
||||
border-radius: 30rpx;
|
||||
background: rgba(255, 255, 255, 0.98);
|
||||
box-shadow: 0 18rpx 50rpx rgba(122, 67, 88, 0.12);
|
||||
}
|
||||
|
||||
.checkout-copy {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.checkout-total {
|
||||
font-size: 36rpx;
|
||||
font-weight: 800;
|
||||
color: #d5536f;
|
||||
}
|
||||
|
||||
.checkout-meta {
|
||||
margin-top: 8rpx;
|
||||
font-size: 22rpx;
|
||||
color: #8d7a84;
|
||||
}
|
||||
|
||||
.checkout-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 220rpx;
|
||||
height: 84rpx;
|
||||
padding: 0 26rpx;
|
||||
border-radius: 999rpx;
|
||||
background: linear-gradient(135deg, #ff8cb0 0%, #c6597d 100%);
|
||||
color: #ffffff;
|
||||
font-size: 28rpx;
|
||||
font-weight: 700;
|
||||
}
|
||||
Reference in New Issue
Block a user