功能(小程序):同步用户体验流程到小程序

This commit is contained in:
xiaowang
2026-05-23 21:56:52 +08:00
parent 861eea933b
commit b67dae502f
38 changed files with 2163 additions and 126 deletions
+136
View File
@@ -0,0 +1,136 @@
const nailArtistApi = require('../../api/nail-artist')
const navigation = require('../../utils/navigation')
const { DEFAULT_PRODUCT_IMAGE } = require('../../utils/config')
function formatPrice(price) {
const value = Number(price || 0)
return value > 0 ? `¥${value.toFixed(2)}` : '到店确认'
}
function formatDateTime(value) {
if (!value) {
return ''
}
return String(value).replace('T', ' ').slice(0, 16)
}
Page({
data: {
loading: true,
loadError: '',
artistId: '',
profile: null,
works: [],
reviews: [],
availability: [],
heroImage: DEFAULT_PRODUCT_IMAGE,
artistName: '美甲师',
artistDesc: '专注细节与稳定出品',
shopName: '门店待确认',
styleTags: [],
ratingText: '0.0',
serviceCountText: '0',
workTimeText: '到店确认'
},
onLoad(options) {
this.setData({
artistId: options && options.id ? options.id : ''
})
this.loadArtistProfile()
},
async onPullDownRefresh() {
await this.loadArtistProfile()
wx.stopPullDownRefresh()
},
async loadArtistProfile() {
if (!this.data.artistId) {
this.setData({
loading: false,
loadError: '缺少美甲师信息'
})
return
}
this.setData({
loading: true,
loadError: ''
})
try {
const [profile, availability, reviews] = await Promise.all([
nailArtistApi.getPublicProfile(this.data.artistId),
nailArtistApi.getAvailability(this.data.artistId),
nailArtistApi.listReviews(this.data.artistId)
])
const works = (profile.works || []).map(work => ({
...work,
title: work.title || '美甲作品',
coverImageUrl: work.coverImageUrl || DEFAULT_PRODUCT_IMAGE,
priceText: formatPrice(work.price)
}))
const formattedReviews = (reviews || profile.reviews || []).map(review => ({
...review,
customerName: review.customerName || '匿名用户',
content: review.content || '这位用户没有填写文字评价',
submittedAtText: formatDateTime(review.submittedAt),
ratingText: Number(review.rating || 0).toFixed(1)
}))
const start = profile.workStartTime ? String(profile.workStartTime).slice(0, 5) : ''
const end = profile.workEndTime ? String(profile.workEndTime).slice(0, 5) : ''
this.setData({
profile,
works,
reviews: formattedReviews,
availability: availability || profile.availability || [],
heroImage: (works.find(work => work.coverImageUrl) || {}).coverImageUrl || DEFAULT_PRODUCT_IMAGE,
artistName: profile.artistName || '美甲师',
artistDesc: profile.identity || profile.signature || '专注细节与稳定出品',
shopName: profile.shopName || '门店待确认',
styleTags: (profile.styleTags || []).filter(Boolean),
ratingText: Number(profile.rating || 0).toFixed(1),
serviceCountText: String(profile.serviceCount || 0),
workTimeText: start && end ? `${start}-${end}` : '到店确认'
})
} catch (error) {
this.setData({
loadError: error.message || '美甲师个人页加载失败'
})
} finally {
this.setData({
loading: false
})
}
},
handleBack() {
navigation.goBack('/pages/home/index')
},
handleRetry() {
this.loadArtistProfile()
},
handleOpenShop() {
const profile = this.data.profile
if (!profile || !profile.shopId) {
return
}
wx.navigateTo({
url: `/pages/shop-detail/index?id=${profile.shopId}`
})
},
handleOpenWork(event) {
const id = event.currentTarget.dataset.id
if (!id) {
return
}
wx.navigateTo({
url: `/pages/product-detail/index?id=${id}`
})
}
})
@@ -0,0 +1,4 @@
{
"navigationStyle": "custom",
"usingComponents": {}
}
@@ -0,0 +1,98 @@
<view class="artist-page">
<view class="page-header">
<view class="back-btn" bindtap="handleBack">‹</view>
<text class="page-title">{{artistName}}</text>
<view class="header-spacer"></view>
</view>
<view wx:if="{{loading}}" class="state-box">
<text>加载中...</text>
</view>
<view wx:elif="{{loadError}}" class="state-box">
<text class="state-title">暂时无法查看个人页</text>
<text class="state-desc">{{loadError}}</text>
<view class="primary-btn" bindtap="handleRetry">重试</view>
</view>
<scroll-view wx:else scroll-y class="content-scroll">
<view class="hero">
<image class="hero-image" src="{{heroImage}}" mode="aspectFill"></image>
<view class="hero-mask"></view>
<view class="artist-card">
<image wx:if="{{profile.avatar}}" class="avatar" src="{{profile.avatar}}" mode="aspectFill"></image>
<view wx:else class="avatar placeholder">艺</view>
<view class="artist-main">
<text class="artist-name">{{artistName}}</text>
<text class="artist-desc">{{artistDesc}}</text>
<view class="shop-link" bindtap="handleOpenShop">{{shopName}}</view>
</view>
</view>
</view>
<view class="metrics">
<view class="metric-item">
<text>评分</text>
<text class="metric-value">{{ratingText}}</text>
</view>
<view class="metric-item">
<text>服务</text>
<text class="metric-value">{{serviceCountText}}</text>
</view>
<view class="metric-item">
<text>工时</text>
<text class="metric-value">{{workTimeText}}</text>
</view>
</view>
<view class="section">
<view class="section-head">擅长风格</view>
<view class="tag-list" wx:if="{{styleTags.length}}">
<text class="tag" wx:for="{{styleTags}}" wx:key="*this">{{item}}</text>
</view>
<text wx:else class="empty-text">暂未设置风格标签</text>
</view>
<view class="section">
<view class="section-head">近期可预约</view>
<view class="slot-grid" wx:if="{{availability.length}}">
<view class="slot" wx:for="{{availability}}" wx:key="startTime">
<text>{{item.dateText}}</text>
<text class="slot-time">{{item.timeText}}</text>
</view>
</view>
<text wx:else class="empty-text">近期暂未放出可预约时间</text>
</view>
<view class="section">
<view class="section-head">作品</view>
<view class="work-grid" wx:if="{{works.length}}">
<view class="work-card" wx:for="{{works}}" wx:key="id" data-id="{{item.id}}" bindtap="handleOpenWork">
<image src="{{item.coverImageUrl}}" mode="aspectFill"></image>
<text class="work-title">{{item.title}}</text>
<text class="work-price">{{item.priceText}}</text>
</view>
</view>
<text wx:else class="empty-text">作品正在整理中</text>
</view>
<view class="section">
<view class="section-head">评价 {{reviews.length}}</view>
<view class="review-list" wx:if="{{reviews.length}}">
<view class="review-card" wx:for="{{reviews}}" wx:key="id">
<view class="review-top">
<image wx:if="{{item.customerAvatar}}" class="review-avatar" src="{{item.customerAvatar}}" mode="aspectFill"></image>
<view wx:else class="review-avatar placeholder">客</view>
<view class="review-meta">
<text>{{item.customerName}}</text>
<text>{{item.submittedAtText}}</text>
</view>
<text class="review-score">{{item.ratingText}}</text>
</view>
<text class="review-content">{{item.content}}</text>
</view>
</view>
<text wx:else class="empty-text">还没有公开评价</text>
</view>
</scroll-view>
</view>
@@ -0,0 +1,336 @@
.artist-page {
min-height: 100vh;
background: #f6f7fb;
color: #1f2933;
}
.page-header {
position: sticky;
top: 0;
z-index: 5;
display: flex;
align-items: center;
justify-content: space-between;
height: 96rpx;
padding: 0 24rpx;
background: rgba(255, 255, 255, 0.95);
border-bottom: 1rpx solid #e6e9ef;
}
.back-btn,
.header-spacer {
width: 64rpx;
height: 64rpx;
line-height: 58rpx;
text-align: center;
font-size: 48rpx;
}
.page-title {
flex: 1;
overflow: hidden;
text-align: center;
font-size: 32rpx;
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
}
.content-scroll {
height: calc(100vh - 96rpx);
}
.state-box {
display: flex;
min-height: 60vh;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 20rpx;
padding: 40rpx;
color: #65717f;
}
.state-title {
color: #1f2933;
font-size: 34rpx;
font-weight: 700;
}
.state-desc {
text-align: center;
line-height: 1.6;
}
.primary-btn {
padding: 18rpx 36rpx;
color: #fff;
background: #c6597d;
border-radius: 12rpx;
}
.hero {
position: relative;
height: 520rpx;
margin: 20rpx;
overflow: hidden;
background: #222831;
border-radius: 16rpx;
}
.hero-image,
.hero-mask {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
}
.hero-mask {
background: linear-gradient(180deg, rgba(10, 14, 20, 0.08), rgba(10, 14, 20, 0.72));
}
.artist-card {
position: absolute;
right: 28rpx;
bottom: 28rpx;
left: 28rpx;
display: flex;
gap: 22rpx;
align-items: center;
color: #fff;
}
.avatar {
width: 112rpx;
height: 112rpx;
flex: 0 0 auto;
overflow: hidden;
border: 3rpx solid rgba(255, 255, 255, 0.8);
border-radius: 56rpx;
}
.placeholder {
display: flex;
align-items: center;
justify-content: center;
background: #d8dde6;
color: #5f6b7a;
font-weight: 700;
}
.artist-main {
min-width: 0;
}
.artist-name,
.artist-desc,
.shop-link {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.artist-name {
font-size: 44rpx;
font-weight: 800;
}
.artist-desc {
margin-top: 10rpx;
color: rgba(255, 255, 255, 0.88);
font-size: 26rpx;
}
.shop-link {
max-width: 440rpx;
margin-top: 16rpx;
padding: 12rpx 18rpx;
background: rgba(255, 255, 255, 0.18);
border: 1rpx solid rgba(255, 255, 255, 0.28);
border-radius: 12rpx;
}
.metrics {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16rpx;
margin: 0 20rpx 20rpx;
}
.metric-item {
display: flex;
min-height: 132rpx;
flex-direction: column;
justify-content: center;
gap: 10rpx;
padding: 20rpx;
background: #fff;
border: 1rpx solid #e6e9ef;
border-radius: 16rpx;
}
.metric-item text:first-child {
color: #65717f;
font-size: 24rpx;
}
.metric-value {
overflow-wrap: anywhere;
font-size: 34rpx;
font-weight: 800;
}
.section {
margin: 20rpx;
padding: 28rpx;
background: #fff;
border: 1rpx solid #e6e9ef;
border-radius: 16rpx;
}
.section-head {
margin-bottom: 20rpx;
font-size: 32rpx;
font-weight: 800;
}
.tag-list {
display: flex;
flex-wrap: wrap;
gap: 14rpx;
}
.tag {
padding: 10rpx 18rpx;
color: #394554;
background: #eef1f5;
border-radius: 999rpx;
}
.empty-text {
color: #7b8794;
line-height: 1.6;
}
.slot-grid,
.work-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16rpx;
}
.slot {
display: flex;
min-height: 104rpx;
flex-direction: column;
justify-content: center;
gap: 8rpx;
padding: 18rpx;
background: #f6f7fb;
border: 1rpx solid #dfe4ea;
border-radius: 14rpx;
}
.slot text:first-child {
color: #65717f;
font-size: 24rpx;
}
.slot-time {
font-size: 32rpx;
font-weight: 800;
}
.work-card {
overflow: hidden;
background: #fff;
border: 1rpx solid #e6e9ef;
border-radius: 14rpx;
}
.work-card image {
width: 100%;
height: 210rpx;
background: #eef1f5;
}
.work-title,
.work-price {
display: block;
overflow: hidden;
padding: 0 16rpx;
text-overflow: ellipsis;
white-space: nowrap;
}
.work-title {
margin-top: 14rpx;
font-weight: 700;
}
.work-price {
margin: 8rpx 0 16rpx;
color: #c6597d;
font-weight: 800;
}
.review-list {
display: flex;
flex-direction: column;
gap: 18rpx;
}
.review-card {
padding: 22rpx;
background: #f8fafc;
border: 1rpx solid #e6e9ef;
border-radius: 14rpx;
}
.review-top {
display: flex;
align-items: center;
gap: 16rpx;
}
.review-avatar {
width: 72rpx;
height: 72rpx;
border-radius: 36rpx;
}
.review-meta {
flex: 1;
min-width: 0;
}
.review-meta text {
display: block;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.review-meta text:last-child {
margin-top: 4rpx;
color: #7b8794;
font-size: 22rpx;
}
.review-score {
color: #c6597d;
font-weight: 800;
}
.review-content {
display: block;
margin-top: 18rpx;
color: #3f4a56;
line-height: 1.7;
white-space: pre-wrap;
}
+148 -40
View File
@@ -3,11 +3,6 @@
* 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.
@@ -31,6 +26,8 @@ const theme = require('../../utils/theme')
const { resolveLegacyImage } = require('../../utils/file')
const { NO_COUPON_KEY } = require('../../utils/config')
const { runWithLoading } = require('../../utils/loading')
const { clearBuyNowContext, isBuyNowCartItem, readBuyNowContext } = require('../../utils/buy-now')
const { buildRecoveryState, clearRecoveryState } = require('../../utils/recovery')
const {
buildAppointmentValue,
formatDateTime,
@@ -53,6 +50,9 @@ function getCouponKey(coupon) {
* 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 (coupon && coupon.displayText) {
return coupon.displayText
}
if (Number(coupon.couponType) === 1) {
return `${coupon.couponName} ${coupon.discountValue} 折`
}
@@ -71,6 +71,9 @@ function calculateCouponDiscount(coupon, amount) {
if (!coupon || amount <= 0) {
return 0
}
if (coupon.discountAmount !== undefined && coupon.discountAmount !== null) {
return Number(coupon.discountAmount || 0)
}
if (Number(coupon.couponType) === 1) {
const discountValue = Number(coupon.discountValue || 0)
@@ -160,6 +163,9 @@ Page({
minDate: getMinDateText(),
cartItems: [],
availableCoupons: [],
unavailableCoupons: [],
checkoutPreview: null,
vipTip: '',
selectedCouponKey: NO_COUPON_KEY,
/**
* Purpose: couponSelectionTouched records whether the user explicitly chose a coupon option.
@@ -167,13 +173,18 @@ Page({
*/
couponSelectionTouched: false,
selectedCount: 0,
isBuyNowMode: false,
heroKicker: '结算准备',
heroTitle: '已选 0 个预约项目',
heroDesc: '确认美甲师和时间后再下单。',
totalQuantity: 0,
subtotalAmount: 0,
subtotalText: '¥0.00',
discountAmountText: '¥0.00',
totalAmountText: '¥0.00',
checkoutIssues: [],
submittingOrder: false
submittingOrder: false,
recoveryState: clearRecoveryState()
}),
/**
@@ -214,13 +225,19 @@ Page({
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 localSubtotalAmount = selectedItems.reduce((sum, item) => sum + Number(item.price || 0) * Number(item.quantity || 0), 0)
const preview = this.data.checkoutPreview || {}
const subtotalAmount = preview.subtotalAmount !== undefined ? Number(preview.subtotalAmount || 0) : localSubtotalAmount
const discountAmount = preview.savedAmount !== undefined ? Number(preview.savedAmount || 0) : calculateCouponDiscount(selectedCoupon, subtotalAmount)
const totalAmount = preview.payableAmount !== undefined ? Number(preview.payableAmount || 0) : Math.max(0, subtotalAmount - discountAmount)
const checkoutIssues = buildCheckoutIssues(this.data.cartItems)
const isBuyNowMode = Boolean(this.data.isBuyNowMode)
this.setData({
selectedCount,
heroKicker: isBuyNowMode ? '确认订单' : '结算准备',
heroTitle: isBuyNowMode ? '确认本次预约' : `已选 ${selectedCount} 个预约项目`,
heroDesc: isBuyNowMode ? '本次只会提交刚刚选择的作品,不会混入购物车其他项目。' : '确认美甲师和时间后再下单。',
totalQuantity,
subtotalAmount,
subtotalText: `¥${formatPrice(subtotalAmount)}`,
@@ -232,9 +249,13 @@ Page({
async loadCartItems() {
const isLoggedIn = auth.isLoggedIn()
const buyNowContext = isLoggedIn ? readBuyNowContext() : null
const buyNowProductId = buyNowContext && buyNowContext.productId ? String(buyNowContext.productId) : ''
this.setData({
isLoggedIn,
loading: isLoggedIn
isBuyNowMode: Boolean(buyNowProductId),
loading: isLoggedIn,
recoveryState: clearRecoveryState()
})
/**
@@ -245,9 +266,13 @@ Page({
this.setData({
cartItems: [],
availableCoupons: [],
unavailableCoupons: [],
checkoutPreview: null,
vipTip: '',
selectedCouponKey: NO_COUPON_KEY,
couponSelectionTouched: false,
loading: false
loading: false,
recoveryState: clearRecoveryState()
})
this.refreshSummary()
return
@@ -273,7 +298,7 @@ Page({
...item,
productImageUrl,
priceText: `¥${formatPrice(item.price)}`,
selected: true,
selected: buyNowProductId ? isBuyNowCartItem(item, buyNowProductId) : true,
artistId: item.artistId || '',
artistName: artist ? artist.name : '',
availableArtists,
@@ -286,16 +311,26 @@ Page({
this.setData({
cartItems: formattedItems,
selectedCouponKey: NO_COUPON_KEY,
couponSelectionTouched: false
couponSelectionTouched: false,
recoveryState: clearRecoveryState()
})
if (buyNowProductId) {
clearBuyNowContext()
}
await this.loadAvailableCoupons()
} catch (error) {
this.setData({
cartItems: []
})
wx.showToast({
title: error.message || '购物车加载失败',
icon: 'none'
cartItems: [],
recoveryState: buildRecoveryState({
title: '购物车加载失败',
message: error,
fallbackMessage: '购物车暂时没有加载出来,请重试或先去逛作品。',
actions: [
{ key: 'retryCartLoad', text: '重试' },
{ key: 'products', text: '去逛作品' },
{ key: 'contact', text: '联系客服' }
]
})
})
} finally {
this.setData({
@@ -314,6 +349,9 @@ Page({
if (!selectedItems.length) {
this.setData({
availableCoupons: [],
unavailableCoupons: [],
checkoutPreview: null,
vipTip: '',
selectedCouponKey: NO_COUPON_KEY,
couponSelectionTouched: false
})
@@ -321,24 +359,25 @@ Page({
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 selectedCoupon = this.getSelectedCoupon()
const preview = await orderApi.checkoutPreview({
couponId: selectedCoupon ? selectedCoupon.id : undefined,
couponSourceType: selectedCoupon ? selectedCoupon.sourceType : (this.data.couponSelectionTouched && 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
}))
})
const list = Array.isArray(coupons) ? coupons.map(item => ({
const list = Array.isArray(preview && preview.availableCoupons) ? preview.availableCoupons.map(item => ({
...item,
key: getCouponKey(item),
displayText: getCouponDisplay(item)
})) : []
const unavailableCoupons = Array.isArray(preview && preview.unavailableCoupons) ? preview.unavailableCoupons.map(item => ({
...item,
key: getCouponKey(item),
displayText: getCouponDisplay(item)
@@ -348,6 +387,7 @@ Page({
if (selectedCouponKey !== NO_COUPON_KEY && !list.find(item => item.key === selectedCouponKey)) {
selectedCouponKey = NO_COUPON_KEY
}
const previewSubtotalAmount = Number((preview && preview.subtotalAmount) || this.data.subtotalAmount || 0)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
@@ -355,8 +395,7 @@ Page({
*/
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))
.sort((left, right) => calculateCouponDiscount(right, previewSubtotalAmount) - calculateCouponDiscount(left, previewSubtotalAmount))
/**
* `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.
@@ -368,11 +407,17 @@ Page({
this.setData({
availableCoupons: list,
unavailableCoupons,
checkoutPreview: preview || null,
vipTip: preview && preview.vipTip ? preview.vipTip : '',
selectedCouponKey
})
} catch (error) {
this.setData({
availableCoupons: [],
unavailableCoupons: [],
checkoutPreview: null,
vipTip: '',
selectedCouponKey: NO_COUPON_KEY,
couponSelectionTouched: false
})
@@ -397,6 +442,60 @@ Page({
navigation.switchTab('/pages/products/index')
},
handleRecoveryAction(event) {
const key = event.currentTarget.dataset.key
if (key === 'retryCartLoad') {
this.setData({ recoveryState: clearRecoveryState() })
this.loadCartItems()
return
}
if (key === 'retryCheckout') {
this.setData({ recoveryState: clearRecoveryState() })
this.handleCheckout()
return
}
if (key === 'contact') {
this.handleContactSupport()
return
}
if (key === 'cart') {
this.setData({ recoveryState: clearRecoveryState() })
return
}
const actions = this.data.recoveryState.actions || []
const action = actions.find(item => item.key === key)
if (action && action.route) {
this.openRecoveryRoute(action.route)
}
},
openRecoveryRoute(route) {
const pureRoute = String(route || '').split('?')[0]
if (!pureRoute) {
return
}
if (navigation.isTabPage(pureRoute)) {
navigation.switchTab(pureRoute)
return
}
navigation.navigate(route)
},
handleContactSupport() {
wx.showModal({
title: '联系客服',
content: '请截图保留失败提示;如果担心重复下单,请先查看订单。也可以前往“我的”页联系门店或平台客服。',
confirmText: '去我的',
cancelText: '留在本页',
success: res => {
if (res.confirm) {
navigation.switchTab('/pages/profile/index')
}
}
})
},
async handleToggleSelect(event) {
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
@@ -640,7 +739,7 @@ Page({
selectedCouponKey: event.detail.value,
couponSelectionTouched: true
})
this.refreshSummary()
this.loadAvailableCoupons()
},
async handleCheckout() {
@@ -704,9 +803,18 @@ Page({
icon: 'none'
})
} catch (error) {
wx.showToast({
title: error.message || '订单创建失败',
icon: 'none'
this.setData({
recoveryState: buildRecoveryState({
title: '下单失败',
message: error,
fallbackMessage: '订单创建失败,请重试;如果担心重复下单,请先查看订单。',
actions: [
{ key: 'retryCheckout', text: '重试下单' },
{ key: 'orders', text: '查看订单' },
{ key: 'contact', text: '联系客服' },
{ key: 'cart', text: '返回购物车' }
]
})
})
} finally {
this.setData({
+45 -7
View File
@@ -9,10 +9,24 @@
</view>
<block wx:elif="{{cartItems.length}}">
<view wx:if="{{recoveryState.visible}}" class="page-card recovery-card">
<text class="recovery-title">{{recoveryState.title}}</text>
<text class="recovery-desc">{{recoveryState.message}}</text>
<view class="recovery-actions">
<view
wx:for="{{recoveryState.actions}}"
wx:key="key"
class="recovery-btn {{item.primary ? 'primary' : ''}}"
data-key="{{item.key}}"
bindtap="handleRecoveryAction"
>{{item.text}}</view>
</view>
</view>
<view class="page-hero cart-hero">
<text class="hero-kicker">结算准备</text>
<text class="hero-title">已选 {{selectedCount}} 个预约项目</text>
<text class="hero-desc">确认美甲师和时间后再下单。</text>
<text class="hero-kicker">{{heroKicker}}</text>
<text class="hero-title">{{heroTitle}}</text>
<text class="hero-desc">{{heroDesc}}</text>
<view class="summary-strip">
<view class="summary-metric">
@@ -93,7 +107,7 @@
<view wx:if="{{selectedCount}}" class="page-card coupon-card">
<view class="section-title">优惠方式</view>
<view class="section-subtitle">系统会优先匹配 VIP 优惠。</view>
<view class="section-subtitle">{{vipTip || '系统会优先匹配 VIP 优惠。'}}</view>
<radio-group bindchange="handleCouponChange">
<label class="coupon-option">
@@ -107,14 +121,24 @@
<radio value="{{coupon.key}}" checked="{{selectedCouponKey === coupon.key}}" color="{{navThemeColor || '#C6597D'}}"></radio>
<view class="coupon-texts">
<view class="coupon-name">{{coupon.displayText}}</view>
<view class="coupon-desc">{{coupon.sourceType === 'SYSTEM_VIP' ? 'VIP 自动折扣' : '用户优惠券'}}</view>
<view class="coupon-desc">{{coupon.savingText || (coupon.sourceType === 'SYSTEM_VIP' ? 'VIP 自动折扣' : '用户优惠券')}}</view>
</view>
<view class="coupon-tag">{{coupon.sourceType === 'SYSTEM_VIP' ? '推荐' : '手动选择'}}</view>
</label>
</radio-group>
<view wx:if="{{unavailableCoupons.length}}" class="unavailable-coupon-list">
<view class="unavailable-title">本单暂不可用</view>
<view wx:for="{{unavailableCoupons}}" wx:key="key" wx:for-item="coupon" class="unavailable-coupon">
<text>{{coupon.displayText}}</text>
<text>{{coupon.unavailableReason || '本单暂不可用'}}</text>
</view>
</view>
</view>
<view class="page-card summary-card">
<view wx:if="{{checkoutPreview && checkoutPreview.summaryText}}" class="summary-preview">{{checkoutPreview.summaryText}}</view>
<view wx:if="{{vipTip}}" class="summary-vip">{{vipTip}}</view>
<view class="summary-row">
<text>选中项目</text>
<text>{{selectedCount}} 项</text>
@@ -124,11 +148,11 @@
<text>{{totalQuantity}} 件</text>
</view>
<view class="summary-row">
<text>小计</text>
<text>商品小计</text>
<text>{{subtotalText}}</text>
</view>
<view class="summary-row">
<text>优惠</text>
<text>已省</text>
<text>-{{discountAmountText}}</text>
</view>
<view class="summary-row total">
@@ -142,6 +166,20 @@
<text class="empty-title">正在加载购物车</text>
</view>
<view wx:elif="{{recoveryState.visible}}" class="page-card recovery-card">
<text class="recovery-title">{{recoveryState.title}}</text>
<text class="recovery-desc">{{recoveryState.message}}</text>
<view class="recovery-actions">
<view
wx:for="{{recoveryState.actions}}"
wx:key="key"
class="recovery-btn {{item.primary ? 'primary' : ''}}"
data-key="{{item.key}}"
bindtap="handleRecoveryAction"
>{{item.text}}</view>
</view>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">购物车还是空的</text>
<text class="empty-desc">先加购,再预约。</text>
+97
View File
@@ -31,6 +31,54 @@
line-height: 1.7;
}
.recovery-card {
display: flex;
flex-direction: column;
gap: 14rpx;
margin-bottom: 20rpx;
padding: 26rpx;
border: 2rpx solid var(--theme-border);
}
.recovery-title {
font-size: 30rpx;
font-weight: 800;
color: #2d2430;
}
.recovery-desc {
font-size: 24rpx;
line-height: 1.6;
color: #8d7a84;
}
.recovery-actions {
display: flex;
flex-wrap: wrap;
gap: 14rpx;
}
.recovery-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 136rpx;
height: 60rpx;
padding: 0 20rpx;
border-radius: 999rpx;
background: #ffffff;
border: 2rpx solid var(--theme-border);
color: #5d4b55;
font-size: 24rpx;
font-weight: 700;
}
.recovery-btn.primary {
background: var(--theme-primary);
border-color: var(--theme-primary);
color: #ffffff;
}
.cart-item-card + .cart-item-card,
.coupon-card,
.summary-card {
@@ -260,6 +308,55 @@
font-weight: 700;
}
.unavailable-coupon-list {
margin-top: 22rpx;
padding-top: 18rpx;
border-top: 2rpx solid #f6eaee;
}
.unavailable-title {
font-size: 24rpx;
font-weight: 700;
color: #8d7a84;
}
.unavailable-coupon {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18rpx;
margin-top: 14rpx;
font-size: 22rpx;
color: #8d7a84;
}
.unavailable-coupon text:first-child {
flex: 1;
min-width: 0;
color: #5d4b55;
}
.unavailable-coupon text:last-child {
max-width: 260rpx;
text-align: right;
}
.summary-preview,
.summary-vip {
margin-bottom: 14rpx;
padding: 16rpx 18rpx;
border-radius: 18rpx;
background: var(--theme-primary-soft);
color: #5d4b55;
font-size: 24rpx;
line-height: 1.6;
}
.summary-vip {
color: var(--theme-primary);
font-weight: 700;
}
.summary-row {
display: flex;
align-items: center;
+259 -21
View File
@@ -3,6 +3,7 @@
* 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')
const cartApi = require('../../api/cart')
/**
* 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.
@@ -26,6 +27,7 @@ const theme = require('../../utils/theme')
const { resolveLegacyImage } = require('../../utils/file')
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
const { buildRecoveryState, clearRecoveryState } = require('../../utils/recovery')
/**
* Purpose: REVIEW_SCORE_OPTIONS supports index.js by holding or executing the review score options page or API role.
@@ -137,20 +139,49 @@ function buildPendingReview(review) {
return review
}
/**
* Purpose: formatImpactTime supports index.js by normalizing backend or order item appointment values for change summaries.
* Usage: call it when building user-visible artist-change cards and confirmation modal copy.
*/
function formatImpactTime(value) {
return formatDateTime(value)
}
/**
* Purpose: buildArtistChangeSummary supports index.js by holding or executing the build artist change summary 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 buildArtistChangeSummary(request) {
function buildArtistChangeSummary(request, orderItem) {
if (!request) {
return null
}
const originalName = request.originalArtistName || '原美甲师'
const requestedName = request.requestedArtistName || '新美甲师'
const originalName = request.originalArtistName || request.fromArtistName || (orderItem && orderItem.artistName) || '原美甲师'
const requestedName = request.requestedArtistName || request.toArtistName || '新美甲师'
const appointmentTime = formatImpactTime(request.appointmentTime || (orderItem && orderItem.appointmentTime))
const timeImpactText = request.timeImpactText || (request.timeAffected ? '预约时间可能调整' : '预约时间不变')
const priceImpactText = request.priceImpactText || (request.priceAffected ? '订单价格可能调整' : '价格不变')
const priceValue = request.priceAffected ? request.newPrice : (request.newPrice || request.originalPrice || (orderItem && orderItem.price))
const priceText = priceValue !== undefined && priceValue !== null && priceValue !== '' ? `¥${formatPrice(priceValue)}` : ''
const impactLines = [
appointmentTime ? `${timeImpactText}:${appointmentTime}` : timeImpactText,
priceText ? `${priceImpactText}:${priceText}` : priceImpactText
].filter(Boolean)
const originalArtistText = `原美甲师:${originalName}`
const requestedArtistText = `新美甲师:${requestedName}`
return {
...request,
originalArtistText,
requestedArtistText,
artistLines: [originalArtistText, requestedArtistText],
displayText: `改派申请:${originalName} → ${requestedName}`,
reasonText: trimText(request.reason)
reasonText: trimText(request.reason),
impactLines,
confirmText: [
`原美甲师:${originalName}`,
`新美甲师:${requestedName}`,
request.reason ? `原因:${trimText(request.reason)}` : '',
...impactLines
].filter(Boolean).join('\n')
}
}
@@ -167,6 +198,77 @@ function indexByOrderItemId(list) {
}, {})
}
/**
* Purpose: formatTimelineTime keeps timeline timestamps short enough for mini-program cards.
* Usage: call it while building the order lifecycle timeline from backend date fields.
*/
function formatTimelineTime(value) {
return formatDateTime(value) || ''
}
/**
* Purpose: latestChangeTime picks the most meaningful time from a change request record.
* Usage: use it when summarizing historical artist-change requests on the timeline.
*/
function latestChangeTime(request) {
return (request && (request.approvedTime || request.rejectedTime || request.reviewTime || request.createTime)) || ''
}
/**
* Purpose: buildOrderTimeline creates a compact lifecycle timeline for one order.
* Usage: call it after pending reviews, submitted reviews, and change requests are loaded.
*/
function buildOrderTimeline(order, orderReviews, changeRequests, pendingReviews) {
const items = safeList(order && order.items)
const firstAppointment = items.map(item => item && item.appointmentTime).find(Boolean)
const changes = safeList(changeRequests)
const latestChange = changes
.slice()
.sort((left, right) => String(latestChangeTime(right)).localeCompare(String(latestChangeTime(left))))[0]
const submittedReviews = safeList(orderReviews).filter(isSubmittedReview)
const hasPendingReview = safeList(pendingReviews).some(review => sameId(review && review.orderId, order && order.id))
const status = Number(order && order.status)
return [
{
key: 'created',
title: '已创建',
text: formatTimelineTime(order && order.createTime) || '已提交',
done: true,
active: false
},
{
key: 'appointment',
title: '预约时间',
text: formatTimelineTime(firstAppointment) || '待确认',
done: Boolean(firstAppointment),
active: status === 1
},
changes.length ? {
key: 'artist-change',
title: '改派记录',
text: `${changes.length} 次申请`,
subText: formatTimelineTime(latestChangeTime(latestChange)),
done: changes.every(request => String((request && request.status) || '').toUpperCase() !== 'PENDING'),
active: changes.some(request => String((request && request.status) || '').toUpperCase() === 'PENDING')
} : null,
{
key: status === 3 ? 'cancelled' : 'completed',
title: status === 3 ? '已取消' : '已完成',
text: formatTimelineTime(order && (order.completeTime || order.cancelTime || order.updateTime)) || (status === 2 ? '服务完成' : (status === 3 ? '订单已取消' : '等待服务')),
done: status === 2 || status === 3,
active: status === 2 || status === 3
},
{
key: 'review',
title: '评价',
text: submittedReviews.length ? '已评价' : (hasPendingReview ? '待评价' : '完成后可评价'),
subText: formatTimelineTime((submittedReviews[0] && (submittedReviews[0].reviewTime || submittedReviews[0].submitTime)) || ''),
done: submittedReviews.length > 0,
active: hasPendingReview
}
].filter(Boolean)
}
/**
* Purpose: safeCall supports index.js by holding or executing the safe call 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.
@@ -190,10 +292,14 @@ async function loadAssistData(orders) {
const orderReviewListsPromise = Promise.all(orders.map(order => (
safeCall(() => orderApi.listOrderReviews(order.id), [])
)))
const [pendingReviews, pendingChanges, orderReviewLists] = await Promise.all([
const orderChangeListsPromise = Promise.all(orders.map(order => (
safeCall(() => orderApi.listOrderArtistChangeRequests(order.id), [])
)))
const [pendingReviews, pendingChanges, orderReviewLists, orderChangeLists] = await Promise.all([
pendingReviewsPromise,
pendingChangesPromise,
orderReviewListsPromise
orderReviewListsPromise,
orderChangeListsPromise
])
const submittedReviews = []
@@ -208,7 +314,16 @@ async function loadAssistData(orders) {
return {
pendingReviewByItemId: indexByOrderItemId(pendingReviews),
submittedReviewByItemId: indexByOrderItemId(submittedReviews),
pendingChangeByItemId: indexByOrderItemId(pendingChanges)
pendingChangeByItemId: indexByOrderItemId(pendingChanges),
pendingReviews,
reviewsByOrderId: safeList(orders).reduce((result, order, index) => {
result[toId(order && order.id)] = safeList(orderReviewLists[index])
return result
}, {}),
changesByOrderId: safeList(orders).reduce((result, order, index) => {
result[toId(order && order.id)] = safeList(orderChangeLists[index])
return result
}, {})
}
}
@@ -230,6 +345,20 @@ function findReviewDraft(orders, reviewId) {
return {}
}
function normalizeRebookQuantity(quantity) {
const value = Number(quantity)
return isFinite(value) && value > 0 ? Math.max(1, Math.floor(value)) : 1
}
function getRebookableOrderItems(order) {
return safeList(order && order.items).filter(item => item && item.productId !== undefined && item.productId !== null)
}
function findOrderById(orders, orderId) {
const orderIdText = toId(orderId)
return safeList(orders).find(order => toId(order.id) === orderIdText) || null
}
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
@@ -240,7 +369,8 @@ Page({
* Usage: set it from onLoad route options and compare it while formatting order cards.
*/
focusOrderId: '',
reviewScoreOptions: REVIEW_SCORE_OPTIONS
reviewScoreOptions: REVIEW_SCORE_OPTIONS,
recoveryState: clearRecoveryState()
}),
/**
@@ -249,7 +379,10 @@ Page({
*/
onLoad(options) {
this.setData({
focusOrderId: (options && options.orderId) || ''
focusOrderId: (options && options.orderId) || '',
focusOrderItemId: (options && options.orderItemId) || '',
focusReviewId: (options && options.reviewId) || '',
focusReviewMode: (options && options.review) || ''
})
},
@@ -265,13 +398,15 @@ Page({
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
loading: isLoggedIn
loading: isLoggedIn,
recoveryState: clearRecoveryState()
})
if (!isLoggedIn) {
this.setData({
orders: [],
loading: false
loading: false,
recoveryState: clearRecoveryState()
})
return
}
@@ -280,13 +415,27 @@ Page({
const orders = await orderApi.getOrderList()
const list = safeList(orders)
const assistData = await loadAssistData(list)
let resolvedFocusOrderId = this.data.focusOrderId
let resolvedFocusOrderItemId = this.data.focusOrderItemId
const targetReviewId = toId(this.data.focusReviewId)
if (!resolvedFocusOrderId && this.data.focusReviewMode === 'pending') {
const firstPending = safeList(assistData.pendingReviews)[0]
resolvedFocusOrderId = toId(firstPending && firstPending.orderId)
resolvedFocusOrderItemId = toId(firstPending && firstPending.orderItemId)
} else if (targetReviewId) {
const submittedReviews = Object.values(assistData.reviewsByOrderId || {}).reduce((all, reviews) => all.concat(safeList(reviews)), [])
const matchedReview = safeList(assistData.pendingReviews).concat(submittedReviews).find(review => sameId(review && review.id, targetReviewId))
resolvedFocusOrderId = toId(matchedReview && matchedReview.orderId) || resolvedFocusOrderId
resolvedFocusOrderItemId = toId(matchedReview && matchedReview.orderItemId) || resolvedFocusOrderItemId
}
const formattedOrders = await Promise.all(list.map(async order => ({
...order,
focusTarget: sameId(order.id, this.data.focusOrderId),
focusTarget: sameId(order.id, resolvedFocusOrderId),
statusText: getOrderStatusText(order),
statusClass: getOrderStatusClass(order),
shopNameText: order.shopName ? `所属店铺:${order.shopName}` : '',
actualAmountText: `\u00a5${formatPrice(order.actualAmount)}`,
timeline: buildOrderTimeline(order, assistData.reviewsByOrderId[toId(order.id)], assistData.changesByOrderId[toId(order.id)], assistData.pendingReviews),
items: await Promise.all(safeList(order.items).map(async item => {
const itemId = toId(item.id)
const inlinePendingReview = resolveRelatedRecord(item.pendingReview || order.pendingReview, item.id)
@@ -294,13 +443,14 @@ Page({
const inlinePendingChange = resolveRelatedRecord(item.pendingArtistChangeRequest || order.pendingArtistChangeRequest, item.id)
const pendingReview = buildPendingReview(inlinePendingReview || assistData.pendingReviewByItemId[itemId])
const reviewSummary = buildReviewSummary(inlineReviewSummary || assistData.submittedReviewByItemId[itemId])
const pendingArtistChangeRequest = buildArtistChangeSummary(inlinePendingChange || assistData.pendingChangeByItemId[itemId])
const pendingArtistChangeRequest = buildArtistChangeSummary(inlinePendingChange || assistData.pendingChangeByItemId[itemId], item)
return {
...item,
productImageUrl: await resolveLegacyImage(item.productImage),
priceText: `\u00a5${formatPrice(item.price)}`,
appointmentText: formatDateTime(item.appointmentTime),
focusTarget: sameId(order.id, resolvedFocusOrderId) && (!resolvedFocusOrderItemId || sameId(item.id, resolvedFocusOrderItemId)),
pendingReview,
reviewSummary,
reviewDraft: pendingReview ? { rating: 0, content: '' } : null,
@@ -309,16 +459,27 @@ Page({
}))
})))
formattedOrders.forEach(order => {
order.canRebook = Number(order.status) === 2 && getRebookableOrderItems(order).length > 0
})
this.setData({
orders: formattedOrders
orders: formattedOrders,
recoveryState: clearRecoveryState()
})
} catch (error) {
this.setData({
orders: []
})
wx.showToast({
title: error.message || '\u8ba2\u5355\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
orders: [],
recoveryState: buildRecoveryState({
title: '订单列表加载失败',
message: error,
fallbackMessage: '订单暂时没有加载出来,请重试或稍后再查看。',
actions: [
{ key: 'retryOrdersLoad', text: '重试' },
{ key: 'products', text: '去逛作品' },
{ key: 'profile', text: '返回我的' }
]
})
})
} finally {
this.setData({
@@ -343,6 +504,33 @@ Page({
navigation.goBack('/pages/profile/index')
},
handleRecoveryAction(event) {
const key = event.currentTarget.dataset.key
if (key === 'retryOrdersLoad') {
this.setData({ recoveryState: clearRecoveryState() })
this.loadOrders()
return
}
const actions = this.data.recoveryState.actions || []
const action = actions.find(item => item.key === key)
if (action && action.route) {
this.openRecoveryRoute(action.route)
}
},
openRecoveryRoute(route) {
const pureRoute = String(route || '').split('?')[0]
if (!pureRoute) {
return
}
if (navigation.isTabPage(pureRoute)) {
navigation.switchTab(pureRoute)
return
}
navigation.navigate(route)
},
/**
* Purpose: updateReviewDraft supports index.js by holding or executing the update review draft page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
@@ -437,6 +625,7 @@ Page({
async handleApproveArtistChange(event) {
const requestId = event.currentTarget.dataset.requestId
const confirmText = event.currentTarget.dataset.confirmText
if (!requestId) {
return
}
@@ -446,7 +635,7 @@ Page({
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '同意改派',
content: '确认同意这次美甲师改派申请吗?',
content: confirmText || '确认同意这次美甲师改派申请吗?',
success: modalRes => resolve(Boolean(modalRes.confirm))
})
})
@@ -476,6 +665,7 @@ Page({
async handleRejectArtistChange(event) {
const requestId = event.currentTarget.dataset.requestId
const confirmText = event.currentTarget.dataset.confirmText
if (!requestId) {
return
}
@@ -485,7 +675,7 @@ Page({
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '拒绝改派',
content: '确认拒绝这次美甲师改派申请吗?拒绝后可在下一步补充原因。',
content: confirmText ? `${confirmText}\n\n确认拒绝这次改派申请吗?拒绝后可在下一步补充原因。` : '确认拒绝这次美甲师改派申请吗?拒绝后可在下一步补充原因。',
confirmText: '拒绝',
success: modalRes => resolve(Boolean(modalRes.confirm))
})
@@ -541,6 +731,54 @@ Page({
})
},
async handleRebookOrder(event) {
const orderId = event.currentTarget.dataset.orderId
const order = findOrderById(this.data.orders, orderId)
if (!order || !order.canRebook) {
wx.showToast({
title: '这笔订单暂无可复刻作品',
icon: 'none'
})
return
}
const items = getRebookableOrderItems(order)
try {
await actionGuard.run(this, `order:rebook:${orderId}`, async () => {
await runWithLoading(async () => {
for (let i = 0; i < items.length; i += 1) {
await cartApi.addToCart({
productId: items[i].productId,
quantity: normalizeRebookQuantity(items[i].quantity)
})
}
await getApp().updateCartBadge()
})
await new Promise(resolve => {
wx.showModal({
title: '已加入购物车',
content: '请重新选择美甲师和预约时间后再提交订单。',
showCancel: false,
confirmText: '去选择',
success: () => resolve(),
fail: () => resolve()
})
})
await navigation.switchTab('/pages/cart/index')
}, {
message: '正在加入购物车,请勿重复点击'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '复刻同款失败',
icon: 'none'
})
}
},
async handleCancelOrder(event) {
const orderId = event.currentTarget.dataset.orderId
if (!orderId) {
+44 -5
View File
@@ -25,7 +25,20 @@
</view>
<view wx:if="{{item.shopNameText}}" class="order-shop">{{item.shopNameText}}</view>
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="order-item">
<view wx:if="{{item.timeline && item.timeline.length}}" class="order-timeline">
<view
wx:for="{{item.timeline}}"
wx:key="key"
wx:for-item="node"
class="timeline-node {{node.done ? 'done' : ''}} {{node.active ? 'active' : ''}}"
>
<text class="timeline-title">{{node.title}}</text>
<text class="timeline-text">{{node.text}}</text>
<text wx:if="{{node.subText}}" class="timeline-sub">{{node.subText}}</text>
</view>
</view>
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="order-item {{orderItem.focusTarget ? 'focus-target' : ''}}">
<image class="order-thumb" src="{{orderItem.productImageUrl}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="order-main">
<view class="order-title">{{orderItem.productTitle}}</view>
@@ -69,11 +82,20 @@
<view wx:if="{{orderItem.pendingArtistChangeRequest}}" class="change-panel">
<text class="assist-label">待确认改派</text>
<text class="assist-main">{{orderItem.pendingArtistChangeRequest.displayText}}</text>
<text class="assist-main">{{orderItem.pendingArtistChangeRequest.originalArtistText}}</text>
<text class="assist-main">{{orderItem.pendingArtistChangeRequest.requestedArtistText}}</text>
<text wx:if="{{orderItem.pendingArtistChangeRequest.reasonText}}" class="assist-desc">原因:{{orderItem.pendingArtistChangeRequest.reasonText}}</text>
<view class="impact-list">
<text
wx:for="{{orderItem.pendingArtistChangeRequest.impactLines}}"
wx:key="*this"
wx:for-item="impactLine"
class="impact-line"
>{{impactLine}}</text>
</view>
<view class="change-actions">
<view class="change-btn primary" data-request-id="{{orderItem.pendingArtistChangeRequest.id}}" bindtap="handleApproveArtistChange">同意改派</view>
<view class="change-btn" data-request-id="{{orderItem.pendingArtistChangeRequest.id}}" bindtap="handleRejectArtistChange">拒绝</view>
<view class="change-btn primary" data-request-id="{{orderItem.pendingArtistChangeRequest.id}}" data-confirm-text="{{orderItem.pendingArtistChangeRequest.confirmText}}" bindtap="handleApproveArtistChange">同意改派</view>
<view class="change-btn" data-request-id="{{orderItem.pendingArtistChangeRequest.id}}" data-confirm-text="{{orderItem.pendingArtistChangeRequest.confirmText}}" bindtap="handleRejectArtistChange">拒绝</view>
</view>
</view>
</view>
@@ -81,7 +103,10 @@
<view class="order-foot">
<text class="order-amount">总计:{{item.actualAmountText}}</text>
<view wx:if="{{item.status == 1}}" class="cancel-btn" data-order-id="{{item.id}}" bindtap="handleCancelOrder">取消订单</view>
<view class="order-actions">
<view wx:if="{{item.canRebook}}" class="rebook-btn" data-order-id="{{item.id}}" bindtap="handleRebookOrder">复刻同款</view>
<view wx:if="{{item.status == 1}}" class="cancel-btn" data-order-id="{{item.id}}" bindtap="handleCancelOrder">取消订单</view>
</view>
</view>
</view>
</block>
@@ -90,6 +115,20 @@
<text class="empty-title">正在加载订单</text>
</view>
<view wx:elif="{{recoveryState.visible}}" class="page-card recovery-card">
<text class="recovery-title">{{recoveryState.title}}</text>
<text class="recovery-desc">{{recoveryState.message}}</text>
<view class="recovery-actions">
<view
wx:for="{{recoveryState.actions}}"
wx:key="key"
class="recovery-btn {{item.primary ? 'primary' : ''}}"
data-key="{{item.key}}"
bindtap="handleRecoveryAction"
>{{item.text}}</view>
</view>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">你还没有订单</text>
<text class="empty-desc">先去预约喜欢的款式。</text>
+132 -3
View File
@@ -2,6 +2,53 @@
margin-bottom: 20rpx;
}
.recovery-card {
display: flex;
flex-direction: column;
gap: 14rpx;
padding: 26rpx;
border: 2rpx solid var(--theme-border);
}
.recovery-title {
font-size: 30rpx;
font-weight: 800;
color: #2d2430;
}
.recovery-desc {
font-size: 24rpx;
line-height: 1.6;
color: #8d7a84;
}
.recovery-actions {
display: flex;
flex-wrap: wrap;
gap: 14rpx;
}
.recovery-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 136rpx;
height: 60rpx;
padding: 0 20rpx;
border-radius: 999rpx;
background: #ffffff;
border: 2rpx solid var(--theme-border);
color: #5d4b55;
font-size: 24rpx;
font-weight: 700;
}
.recovery-btn.primary {
background: var(--theme-primary);
border-color: var(--theme-primary);
color: #ffffff;
}
.order-card + .order-card {
margin-top: 20rpx;
}
@@ -35,6 +82,51 @@
line-height: 1.5;
}
.order-timeline {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 10rpx;
margin-top: 18rpx;
}
.timeline-node {
min-width: 0;
padding: 12rpx 10rpx;
border-radius: 12rpx;
background: var(--theme-primary-soft);
color: #8d7a84;
}
.timeline-node.done {
color: var(--theme-primary);
}
.timeline-node.active {
outline: 2rpx solid var(--theme-primary);
}
.timeline-title,
.timeline-text,
.timeline-sub {
display: block;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.timeline-title {
font-size: 21rpx;
font-weight: 800;
color: #2d2430;
}
.timeline-text,
.timeline-sub {
margin-top: 4rpx;
font-size: 20rpx;
}
.order-head-copy {
flex: 1;
min-width: 0;
@@ -87,6 +179,13 @@
margin-top: 22rpx;
}
.order-item.focus-target {
padding: 12rpx;
border-radius: 18rpx;
background: rgba(255, 247, 249, 0.9);
outline: 2rpx solid var(--theme-primary);
}
.order-thumb {
width: 132rpx;
height: 132rpx;
@@ -118,13 +217,21 @@
align-items: center;
}
.order-actions {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 14rpx;
}
.order-amount {
font-size: 28rpx;
font-weight: 700;
color: #2d2430;
}
.cancel-btn {
.cancel-btn,
.rebook-btn {
display: inline-flex;
align-items: center;
justify-content: center;
@@ -132,12 +239,20 @@
height: 60rpx;
padding: 0 18rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
color: var(--theme-accent);
font-size: 24rpx;
font-weight: 700;
}
.rebook-btn {
background: var(--theme-primary);
color: #ffffff;
}
.cancel-btn {
background: var(--theme-primary-soft);
color: var(--theme-accent);
}
.review-summary,
.review-panel,
.change-panel {
@@ -182,6 +297,20 @@
line-height: 1.6;
}
.impact-list {
display: flex;
flex-direction: column;
gap: 8rpx;
margin-top: 12rpx;
}
.impact-line {
font-size: 24rpx;
font-weight: 700;
color: var(--theme-primary);
line-height: 1.5;
}
.score-row {
display: flex;
flex-wrap: wrap;
+9 -2
View File
@@ -52,6 +52,7 @@ const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../u
const { DEFAULT_PRODUCT_IMAGE } = require('../../utils/config')
const { formatPrice, getProductTitle, splitCsv } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
const { saveBuyNowContext } = require('../../utils/buy-now')
/**
* Purpose: parseTimeRange supports index.js by holding or executing the parse time range page or API role.
@@ -208,7 +209,9 @@ Page({
...product,
displayTitle: getProductTitle(product),
priceText: `¥${formatPrice(product.price)}`,
descriptionText: product.description || '商家还没有补充作品说明。'
descriptionText: product.description || '商家还没有补充作品说明。',
targetAudienceText: product.targetAudience || '',
precautionsText: product.precautions || ''
}
this.setData({
@@ -303,7 +306,10 @@ Page({
return
}
previewImagesSafely(current, this.data.productImages)
previewImagesSafely(current, this.data.productImages, {
failMessage: '图片可能已过期,请重试;仍失败时可以返回作品列表重新进入。',
emptyMessage: '这件作品暂时没有可预览图片,可以返回作品列表查看其他款式。'
})
},
/**
@@ -488,6 +494,7 @@ Page({
message: '操作进行中,请勿重复点击'
})
await getApp().updateCartBadge()
saveBuyNowContext(product.id)
wx.switchTab({
url: '/pages/cart/index'
})
@@ -79,6 +79,16 @@
<view class="section-title">款式说明</view>
<view class="desc-text">{{product.descriptionText}}</view>
</view>
<view wx:if="{{product.targetAudienceText || product.precautionsText}}" class="guidance-grid">
<view wx:if="{{product.targetAudienceText}}" class="guidance-block">
<view class="section-title">适合人群</view>
<view class="desc-text">{{product.targetAudienceText}}</view>
</view>
<view wx:if="{{product.precautionsText}}" class="guidance-block">
<view class="section-title">注意事项</view>
<view class="desc-text">{{product.precautionsText}}</view>
</view>
</view>
</view>
<view class="page-card comment-card">
@@ -164,6 +164,19 @@
font-size: 26rpx;
line-height: 1.8;
color: #5d4b55;
white-space: pre-wrap;
}
.guidance-grid {
display: grid;
gap: 18rpx;
margin-top: 22rpx;
}
.guidance-block {
padding: 22rpx;
border-radius: 22rpx;
background: var(--theme-primary-soft);
}
.comment-card {
+50 -6
View File
@@ -78,6 +78,8 @@ Page({
loading: false,
loadingMore: false,
categories: [ALL_CATEGORY],
filterGroups: [],
selectedTagId: '',
selectedCategory: ALL_CATEGORY,
searchKeyword: '',
products: [],
@@ -197,10 +199,16 @@ Page({
},
async loadTags() {
const tags = await cache.remember('tags:all', CACHE_TTL.tags, () => tagApi.getAllTags())
const names = Array.isArray(tags) ? tags.map(item => item.tagName).filter(Boolean) : []
const groups = await cache.remember('tags:filter-options', CACHE_TTL.tags, () => tagApi.getFilterOptions())
const normalizedGroups = (Array.isArray(groups) ? groups : []).map(group => ({
...group,
tags: (Array.isArray(group.tags) ? group.tags : []).map(tag => ({
...tag,
idText: String(tag.id)
}))
}))
this.setData({
categories: [ALL_CATEGORY].concat(names)
filterGroups: normalizedGroups
})
},
@@ -225,10 +233,13 @@ Page({
async applyFilter(filter) {
const keyword = String(filter.keyword || '').trim()
const tag = String(filter.tag || '').trim()
const tagId = String(filter.tagId || '').trim()
const matchedTag = this.resolveFilterTag(tagId, tag)
this.setData({
searchKeyword: keyword,
selectedCategory: tag && this.data.categories.includes(tag) ? tag : ALL_CATEGORY,
selectedTagId: matchedTag ? String(matchedTag.id) : '',
selectedCategory: matchedTag ? (matchedTag.displayName || matchedTag.tagName) : ALL_CATEGORY,
page: 1,
total: 0,
hasMore: false
@@ -246,11 +257,13 @@ Page({
try {
const keyword = String(this.data.searchKeyword || '').trim()
const tag = this.data.selectedCategory === ALL_CATEGORY ? '' : this.data.selectedCategory
const tagIds = this.data.selectedTagId || ''
const result = await productApi.getProductPage({
page: nextPage,
size: this.data.pageSize,
keyword: keyword || undefined,
tag: tag || undefined
tag: tagIds ? undefined : (tag || undefined),
tagIds: tagIds || undefined
})
const cards = await buildProductCards(result && result.list ? result.list : [])
const displayCards = await this.attachCartState(cards)
@@ -333,6 +346,33 @@ Page({
return chips.join(' \u00b7 ')
},
/**
* Purpose: flattenFilterTags returns all scene-filter tags for query matching.
* Usage: call before applying route or pending filters.
*/
flattenFilterTags() {
return (Array.isArray(this.data.filterGroups) ? this.data.filterGroups : [])
.reduce((list, group) => list.concat(Array.isArray(group.tags) ? group.tags : []), [])
},
/**
* Purpose: resolveFilterTag matches route filter text or id to a visible scene tag.
* Usage: call from applyFilter so old tag query links still select the right chip.
*/
resolveFilterTag(tagId, tagName) {
const tags = this.flattenFilterTags()
if (tagId) {
const byId = tags.find(item => String(item.id) === tagId)
if (byId) {
return byId
}
}
if (!tagName) {
return null
}
return tags.find(item => item.tagName === tagName || item.displayName === tagName) || null
},
/**
* `normalizeId` 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.
@@ -447,6 +487,7 @@ Page({
await actionGuard.run(this, 'products:search', async () => {
this.setData({
selectedCategory: ALL_CATEGORY,
selectedTagId: '',
page: 1
})
await runWithLoading(() => this.loadProducts(true))
@@ -466,11 +507,13 @@ Page({
async handleSelectCategory(event) {
const category = event.currentTarget.dataset.category
const tagId = event.currentTarget.dataset.tagId ? String(event.currentTarget.dataset.tagId) : ''
resetKeyboardSafe(this)
try {
await actionGuard.run(this, `products:category:${category}`, async () => {
await actionGuard.run(this, `products:category:${category}:${tagId}`, async () => {
this.setData({
selectedCategory: category,
selectedTagId: tagId,
searchKeyword: '',
page: 1
})
@@ -495,6 +538,7 @@ Page({
await actionGuard.run(this, 'products:reset', async () => {
this.setData({
selectedCategory: ALL_CATEGORY,
selectedTagId: '',
searchKeyword: '',
page: 1
})
+18 -5
View File
@@ -25,13 +25,26 @@
<scroll-view class="category-scroll" scroll-x enable-flex show-scrollbar="false">
<view class="category-list">
<view
wx:for="{{categories}}"
wx:key="*this"
class="category-item {{selectedCategory === item ? 'active' : ''}}"
data-category="{{item}}"
class="category-item {{selectedCategory === '全部' ? 'active' : ''}}"
data-category="全部"
data-tag-id=""
bindtap="handleSelectCategory"
>
{{item}}
全部
</view>
<view wx:for="{{filterGroups}}" wx:for-item="group" wx:key="groupName" class="filter-group">
<view class="filter-group-title">{{group.groupName}}</view>
<view
wx:for="{{group.tags}}"
wx:for-item="tag"
wx:key="id"
class="category-item {{selectedTagId === tag.idText ? 'active' : ''}}"
data-category="{{tag.displayName || tag.tagName}}"
data-tag-id="{{tag.idText}}"
bindtap="handleSelectCategory"
>
{{tag.displayName || tag.tagName}}
</view>
</view>
</view>
</scroll-view>
+13
View File
@@ -83,6 +83,19 @@
font-weight: 600;
}
.filter-group {
display: inline-flex;
align-items: center;
gap: 12rpx;
flex-shrink: 0;
}
.filter-group-title {
color: #a4939c;
font-size: 22rpx;
font-weight: 700;
}
.category-item.active {
background: var(--theme-primary-soft);
color: var(--theme-primary);
+19 -2
View File
@@ -57,6 +57,7 @@ Page({
needSetPassword: false,
userInfo: null,
orderCount: 0,
pendingReviewCount: 0,
couponCount: 0,
wishlistCount: 0,
unreadMessageCount: 0,
@@ -96,18 +97,20 @@ Page({
}
try {
const [userInfo, orders, coupons, wishlist, unreadMessages] = await Promise.all([
const [userInfo, orders, coupons, wishlist, unreadMessages, pendingReviews] = await Promise.all([
userApi.getUserInfo(),
orderApi.getOrderList(),
couponApi.listUserCoupons(),
wishlistApi.getWishlist(),
userApi.getMyUnreadMessageCount()
userApi.getMyUnreadMessageCount(),
orderApi.listMyPendingReviews().catch(() => [])
])
getApp().refreshUserInfo(userInfo)
this.setData({
userInfo,
orderCount: Array.isArray(orders) ? orders.length : 0,
pendingReviewCount: Array.isArray(pendingReviews) ? pendingReviews.length : 0,
couponCount: Array.isArray(coupons) ? coupons.length : 0,
wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0,
unreadMessageCount: Number((unreadMessages && unreadMessages.unreadCount) || 0)
@@ -160,6 +163,20 @@ Page({
navigation.navigate('/pages/orders/index')
},
/**
* Purpose: handleOpenPendingReviews jumps straight to the order-page pending review focus.
* Usage: bind the pending-review card in profile WXML.
*/
handleOpenPendingReviews() {
if (!navigation.ensureLogin('查看待评价')) {
return
}
navigation.navigate('/pages/orders/index', {
review: 'pending',
source: 'profile'
})
},
/**
* `handleOpenWishlist` 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.
+5
View File
@@ -37,6 +37,10 @@
<text class="summary-value">{{couponCount}}</text>
</view>
</view>
<view wx:if="{{pendingReviewCount > 0}}" class="pending-review-card" bindtap="handleOpenPendingReviews">
<text>待评价 {{pendingReviewCount}}</text>
<text>给服务过你的美甲师一点反馈</text>
</view>
<view class="shop-box" bindtap="handleSwitchShop">
<view>
@@ -57,6 +61,7 @@
<view class="section-title">常用入口</view>
<view class="menu-item" bindtap="handleOpenOrders">
<text>我的订单</text>
<text wx:if="{{pendingReviewCount > 0}}" class="menu-badge">待评价 {{pendingReviewCount}}</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item" bindtap="handleOpenWishlist">
+17
View File
@@ -94,6 +94,23 @@
margin-top: 26rpx;
}
.pending-review-card {
display: grid;
gap: 8rpx;
margin-top: 22rpx;
padding: 20rpx 24rpx;
border-radius: 20rpx;
background: var(--theme-primary-soft);
color: #8d7a84;
font-size: 24rpx;
}
.pending-review-card text:first-child {
color: var(--theme-primary);
font-size: 28rpx;
font-weight: 700;
}
.shop-box {
display: flex;
align-items: center;
+64 -4
View File
@@ -20,6 +20,7 @@ const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../utils/file')
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
const { showRecoveryModal } = require('../../utils/recovery')
/**
* shop-detail page logic.
@@ -38,6 +39,7 @@ Page({
*/
managerContact: null,
distanceText: '',
trustProfile: null,
shopImages: []
}),
@@ -78,7 +80,11 @@ Page({
try {
const shopInfo = await shopApi.getShopById(this.data.shopId)
const shopImages = await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE)
const trustProfile = await shopApi.getTrustProfile(this.data.shopId).catch(() => null)
const trustImages = trustProfile && Array.isArray(trustProfile.environmentImages) ? trustProfile.environmentImages.filter(Boolean) : []
const shopImages = trustImages.length
? trustImages
: await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE)
const shopTheme = theme.resolveShopTheme(shopInfo)
this.setData(theme.pageThemeData(shopTheme))
if (shopTheme.backgroundImageFileId) {
@@ -91,6 +97,7 @@ Page({
}
this.setData({
shopInfo,
trustProfile: this.normalizeTrustProfile(trustProfile),
shopImages,
distanceText: ''
})
@@ -106,6 +113,47 @@ Page({
}
},
/**
* Purpose: normalizeTrustProfile prepares backend trust fields for WXML display.
* Usage: call after getTrustProfile so metrics and lists have safe defaults.
*/
normalizeTrustProfile(profile) {
if (!profile) {
return null
}
const stats = profile.stats || {}
return {
...profile,
ratingText: Number(stats.averageRating || 0) > 0 ? Number(stats.averageRating).toFixed(1) : '暂无',
reviewCount: Number(stats.reviewCount || 0),
productCount: Number(stats.productCount || 0),
availabilityText: profile.availabilitySummary && profile.availabilitySummary.summaryText
? profile.availabilitySummary.summaryText
: '预约前会再次确认档期',
featuredProducts: (Array.isArray(profile.featuredProducts) ? profile.featuredProducts : []).map(item => ({
...item,
priceText: Number(item.price || 0).toFixed(2)
})),
recentReviews: (Array.isArray(profile.recentReviews) ? profile.recentReviews : []).map(item => ({
...item,
ratingText: Number(item.ratingScore || 0) > 0 ? Number(item.ratingScore).toFixed(1) : '暂无',
submittedText: item.submittedAt ? String(item.submittedAt).replace('T', ' ').slice(0, 16) : ''
}))
}
},
/**
* Purpose: handleOpenProduct navigates from trust-profile cards to product details.
* Usage: bind product cards to this method with data-id.
*/
handleOpenProduct(event) {
const productId = event.currentTarget.dataset.id
if (!productId) {
return
}
navigation.navigate('/pages/product-detail/index', { id: productId })
},
/**
* `handleBack` 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.
@@ -164,9 +212,21 @@ Page({
icon: 'none'
})
} catch (error) {
wx.showToast({
title: error.message || '联系方式获取失败',
icon: 'none'
showRecoveryModal({
title: '联系方式获取失败',
message: error.message || '暂时没有拿到联系方式,请重试;也可以先复制门店名,稍后从“我的”页联系客服。',
actions: [
{ key: 'retry', text: '重试联系' },
{ key: 'profile', text: '去我的' }
]
}).then(action => {
if (action && action.key === 'retry') {
this.handleContactManager()
return
}
if (action && action.key === 'profile') {
navigation.switchTab('/pages/profile/index')
}
})
}
},
+63 -2
View File
@@ -21,10 +21,25 @@
<view class="shop-address" bindtap="handleCopyAddress">{{shopInfo.address || '门店地址待补充'}}</view>
<view wx:if="{{distanceText}}" class="shop-distance">{{distanceText}}</view>
<view wx:if="{{trustProfile}}" class="trust-grid">
<view class="trust-card">
<text class="trust-value">{{trustProfile.ratingText}}</text>
<text class="trust-label">{{trustProfile.reviewCount}} 条评价</text>
</view>
<view class="trust-card">
<text class="trust-value">{{trustProfile.productCount}}</text>
<text class="trust-label">在售作品</text>
</view>
<view class="trust-card">
<text class="trust-value">{{trustProfile.businessStatusText || '可浏览'}}</text>
<text class="trust-label">{{trustProfile.availabilityText}}</text>
</view>
</view>
<view class="summary-strip shop-summary">
<view class="summary-metric">
<text class="summary-label">营业时间</text>
<text class="summary-value shop-summary-value">{{shopInfo.businessHours || '待补充'}}</text>
<text class="summary-value shop-summary-value">{{trustProfile.businessHoursText || shopInfo.businessHours || '待补充'}}</text>
<text class="summary-note">以到店服务时间为准</text>
</view>
<view class="summary-metric">
@@ -36,7 +51,7 @@
<view class="detail-group">
<view class="detail-label">营业时间</view>
<view class="detail-value">{{shopInfo.businessHours || '待补充'}}</view>
<view class="detail-value">{{trustProfile.businessHoursText || shopInfo.businessHours || '待补充'}}</view>
</view>
<view class="detail-group">
@@ -63,6 +78,52 @@
</view>
</view>
<view wx:if="{{trustProfile && trustProfile.featuredProducts.length}}" class="section-block">
<view class="section-head">
<view class="section-copy">
<text class="section-kicker">可预约作品</text>
<text class="section-title">先看看本店热门款</text>
<text class="section-subtitle">{{trustProfile.availabilityText}}</text>
</view>
</view>
<view class="featured-list">
<view
wx:for="{{trustProfile.featuredProducts}}"
wx:key="id"
class="featured-card"
data-id="{{item.id}}"
bindtap="handleOpenProduct"
>
<image wx:if="{{item.imageUrl}}" class="featured-cover" src="{{item.imageUrl}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view wx:else class="featured-cover placeholder">作</view>
<view class="featured-info">
<text class="featured-title">{{item.title || '美甲作品'}}</text>
<text class="featured-price">¥{{item.priceText}}</text>
<text class="featured-hint">{{item.bookingHint || '下单前选择美甲师和时间'}}</text>
</view>
</view>
</view>
</view>
<view wx:if="{{trustProfile && trustProfile.recentReviews.length}}" class="section-block">
<view class="section-head">
<view class="section-copy">
<text class="section-kicker">近期评价</text>
<text class="section-title">真实体验反馈</text>
</view>
</view>
<view class="review-list">
<view wx:for="{{trustProfile.recentReviews}}" wx:key="id" class="review-card">
<view class="review-head">
<text>{{item.productTitle || '订单评价'}}</text>
<text>{{item.ratingText}}</text>
</view>
<text class="review-content">{{item.content || '用户已完成评价'}}</text>
<text class="review-time">{{item.submittedText}}</text>
</view>
</view>
</view>
<view class="section-block">
<view class="section-head">
<view class="section-copy">
+108
View File
@@ -57,6 +57,34 @@
margin-top: 24rpx;
}
.trust-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 14rpx;
margin-top: 24rpx;
}
.trust-card {
display: grid;
gap: 8rpx;
min-height: 112rpx;
padding: 18rpx;
border-radius: 16rpx;
background: var(--theme-primary-soft);
}
.trust-value {
color: var(--theme-primary);
font-size: 28rpx;
font-weight: 700;
}
.trust-label {
color: #8d7a84;
font-size: 22rpx;
line-height: 1.35;
}
.shop-summary-value {
font-size: 26rpx;
line-height: 1.6;
@@ -120,6 +148,86 @@
gap: 18rpx;
}
.featured-list,
.review-list {
display: grid;
gap: 18rpx;
}
.featured-card {
display: grid;
grid-template-columns: 150rpx minmax(0, 1fr);
gap: 18rpx;
padding: 18rpx;
border-radius: 24rpx;
background: #fff;
}
.featured-cover {
width: 150rpx;
height: 150rpx;
border-radius: 20rpx;
background: var(--theme-primary-soft);
}
.featured-cover.placeholder {
display: flex;
align-items: center;
justify-content: center;
color: var(--theme-primary);
font-size: 40rpx;
font-weight: 700;
}
.featured-info {
display: grid;
align-content: center;
gap: 10rpx;
min-width: 0;
}
.featured-title {
color: #2d2430;
font-size: 28rpx;
font-weight: 700;
}
.featured-price {
color: var(--theme-primary);
font-size: 28rpx;
font-weight: 700;
}
.featured-hint,
.review-time {
color: #8d7a84;
font-size: 22rpx;
line-height: 1.5;
}
.review-card {
display: grid;
gap: 12rpx;
padding: 22rpx;
border-radius: 24rpx;
background: #fff;
}
.review-head {
display: flex;
justify-content: space-between;
gap: 16rpx;
color: #2d2430;
font-size: 26rpx;
font-weight: 700;
}
.review-content {
color: #5d4b55;
font-size: 25rpx;
line-height: 1.6;
}
.gallery-image {
width: calc(50% - 9rpx);
height: 240rpx;
+63 -15
View File
@@ -39,7 +39,10 @@ Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
isLoggedIn: false,
wishlist: []
wishlist: [],
visibleWishlist: [],
groups: [],
activeGroupId: ''
}),
/**
@@ -65,29 +68,42 @@ Page({
this.cartProductIdSet = new Set()
this.setData({
wishlist: [],
visibleWishlist: [],
groups: [],
activeGroupId: '',
loading: false
})
return
}
try {
const wishlist = await wishlistApi.getWishlist()
const [wishlist, groups] = await Promise.all([
wishlistApi.getWishlist(),
wishlistApi.getGroups()
])
const list = Array.isArray(wishlist) ? wishlist : []
const groupList = Array.isArray(groups) ? groups : []
const cartProductIdSet = await this.fetchCartProductIdSet()
const cards = await Promise.all(list.map(async item => ({
id: item.id,
productId: item.productId,
groupId: this.normalizeId(item.groupId),
groupName: item.groupName || '\u6700\u8fd1\u60f3\u505a',
note: item.note || '',
productCard: this.markCardInCart(
await buildProductCard(item.product || {}),
cartProductIdSet
)
})))
this.setData({
wishlist: cards
wishlist: cards,
groups: this.buildGroupTabs(groupList, this.data.activeGroupId),
visibleWishlist: this.filterWishlist(cards, this.data.activeGroupId)
})
} catch (error) {
this.setData({
wishlist: []
wishlist: [],
visibleWishlist: []
})
wx.showToast({
title: error.message || '\u6536\u85cf\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
@@ -108,6 +124,36 @@ Page({
return value === undefined || value === null ? '' : String(value)
},
filterWishlist(list, groupId) {
const normalizedGroupId = this.normalizeId(groupId)
if (!normalizedGroupId) {
return list
}
return list.filter(item => this.normalizeId(item && item.groupId) === normalizedGroupId)
},
buildGroupTabs(groups, activeGroupId) {
const normalizedActiveGroupId = this.normalizeId(activeGroupId)
return (Array.isArray(groups) ? groups : []).map(group => {
const id = this.normalizeId(group && group.id)
return {
id,
name: group.name,
itemCount: group.itemCount || 0,
active: id === normalizedActiveGroupId
}
})
},
handleGroupSelect(event) {
const groupId = this.normalizeId(event.currentTarget.dataset.groupId)
this.setData({
activeGroupId: groupId,
groups: this.buildGroupTabs(this.data.groups, groupId),
visibleWishlist: this.filterWishlist(this.data.wishlist, groupId)
})
},
async fetchCartProductIdSet() {
try {
const cartList = await cartApi.getCartList()
@@ -152,18 +198,20 @@ Page({
this.cartProductIdSet = this.cartProductIdSet || new Set()
this.cartProductIdSet.add(normalizedId)
this.setData({
wishlist: this.data.wishlist.map(item => (
this.normalizeId(item && item.productId) === normalizedId
? {
...item,
productCard: {
...item.productCard,
inCart: true
}
const nextWishlist = this.data.wishlist.map(item => (
this.normalizeId(item && item.productId) === normalizedId
? {
...item,
productCard: {
...item.productCard,
inCart: true
}
: item
))
}
: item
))
this.setData({
wishlist: nextWishlist,
visibleWishlist: this.filterWishlist(nextWishlist, this.data.activeGroupId)
})
},
+24 -1
View File
@@ -15,7 +15,22 @@
<text class="hero-desc">喜欢的款式先收藏。</text>
</view>
<view wx:for="{{wishlist}}" wx:key="id" class="wishlist-item">
<scroll-view wx:if="{{groups.length}}" class="wishlist-groups" scroll-x enhanced show-scrollbar="{{false}}">
<view
class="wishlist-group-chip {{!activeGroupId ? 'wishlist-group-chip--active' : ''}}"
data-group-id=""
bindtap="handleGroupSelect"
>全部</view>
<view
wx:for="{{groups}}"
wx:key="id"
class="wishlist-group-chip {{item.active ? 'wishlist-group-chip--active' : ''}}"
data-group-id="{{item.id}}"
bindtap="handleGroupSelect"
>{{item.name}}</view>
</scroll-view>
<view wx:for="{{visibleWishlist}}" wx:key="id" class="wishlist-item">
<product-card
item="{{item.productCard}}"
show-quick-add="{{true}}"
@@ -23,10 +38,18 @@
bindselect="handleProductSelect"
bindquickadd="handleQuickAdd"
></product-card>
<view class="wishlist-meta">
<text class="wishlist-group-name">{{item.groupName || '最近想做'}}</text>
<text wx:if="{{item.note}}" class="wishlist-note">{{item.note}}</text>
</view>
<view class="wishlist-actions">
<view class="wishlist-action wishlist-action--secondary" data-product-id="{{item.productId}}" bindtap="handleRemove">取消收藏</view>
</view>
</view>
<view wx:if="{{!visibleWishlist.length}}" class="page-card empty-card">
<text class="empty-title">当前分组还没有作品</text>
</view>
</block>
<view wx:elif="{{loading}}" class="page-card empty-card">
+52
View File
@@ -6,6 +6,58 @@
margin-top: 22rpx;
}
.wishlist-groups {
display: block;
white-space: nowrap;
margin-bottom: 20rpx;
}
.wishlist-group-chip {
display: inline-flex;
align-items: center;
justify-content: center;
height: 58rpx;
min-width: 92rpx;
margin-right: 14rpx;
padding: 0 24rpx;
border: 2rpx solid var(--theme-border);
border-radius: 16rpx;
background: var(--theme-card-bg);
color: var(--text-secondary);
font-size: 24rpx;
white-space: nowrap;
}
.wishlist-group-chip--active {
border-color: var(--theme-primary);
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-weight: 600;
}
.wishlist-meta {
display: flex;
flex-direction: column;
gap: 8rpx;
margin-top: 12rpx;
}
.wishlist-group-name {
align-self: flex-start;
padding: 4rpx 16rpx;
border-radius: 14rpx;
background: var(--theme-primary-soft);
color: var(--theme-accent);
font-size: 22rpx;
}
.wishlist-note {
color: var(--text-secondary);
font-size: 24rpx;
line-height: 34rpx;
word-break: break-word;
}
.wishlist-actions {
display: flex;
gap: 16rpx;