重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
@@ -0,0 +1,76 @@
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { runWithLoading } = require('../../utils/loading')
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
saving: false,
isLoggedIn: false,
userInfo: null,
form: {
nickname: '',
signature: ''
}
}),
onShow() {
this.loadProfile()
},
handleBack() {
navigation.goBack('/pages/settings/index')
},
async loadProfile() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
this.setData({ loading: true })
try {
const userInfo = await userApi.getUserInfo()
this.setData({
userInfo,
'form.nickname': userInfo.nickname || '',
'form.signature': userInfo.signature || ''
})
} catch (error) {
wx.showToast({ title: error.message || '资料加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
handleInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`form.${field}`]: event.detail.value
})
},
async saveProfile() {
const nickname = String(this.data.form.nickname || '').trim()
if (!nickname) {
wx.showToast({ title: '请输入昵称', icon: 'none' })
return
}
this.setData({ saving: true })
try {
await runWithLoading(() => userApi.updateUserInfo({
nickname,
signature: String(this.data.form.signature || '').trim()
}))
wx.showToast({ title: '资料已更新', icon: 'none' })
await this.loadProfile()
} catch (error) {
wx.showToast({ title: error.message || '资料更新失败', icon: 'none' })
} finally {
this.setData({ saving: false })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,23 @@
<navigation-bar title="账号资料" showBack="{{true}}" fallbackPath="/pages/settings/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">Account</text>
<text class="hero-title">账号资料</text>
<text class="hero-desc">维护昵称、个性签名和基础资料�?/text>
</view>
<view class="page-card form-card">
<view class="field-block">
<text class="field-label">昵称</text>
<input class="field-input" value="{{form.nickname}}" data-field="nickname" bindinput="handleInput" placeholder="请输入昵�? placeholder-class="field-placeholder" />
</view>
<view class="field-block">
<text class="field-label">个��签�?/text>
<textarea class="field-textarea" maxlength="120" value="{{form.signature}}" data-field="signature" bindinput="handleInput" placeholder="写一句介绍自�? placeholder-class="field-placeholder"></textarea>
</view>
<button class="primary-btn" loading="{{saving}}" bindtap="saveProfile">保存资料</button>
</view>
</view>
</view>
@@ -0,0 +1,12 @@
.form-card {
margin-top: 22rpx;
padding: 28rpx;
}
.field-block + .field-block {
margin-top: 24rpx;
}
.primary-btn {
margin-top: 28rpx;
}
@@ -0,0 +1,132 @@
const orderApi = require('../../api/order')
const afterSaleApi = require('../../api/after-sale')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { formatPrice } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
function safeList(value) {
return Array.isArray(value) ? value : []
}
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
orderId: '',
loading: false,
submitting: false,
isLoggedIn: false,
order: null,
items: [],
typeOptions: ['退款', '售后服务'],
form: {
orderItemId: '',
type: 'REFUND',
typeIndex: 0,
reason: '',
refundAmount: ''
}
}),
onLoad(options) {
this.setData({
orderId: (options && options.orderId) || '',
'form.orderItemId': (options && options.orderItemId) || ''
})
},
onShow() {
this.loadOrder()
},
handleBack() {
navigation.goBack('/pages/orders/index')
},
async loadOrder() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
if (!this.data.orderId) return
this.setData({ loading: true })
try {
const order = await orderApi.getOrderDetail(this.data.orderId)
const items = safeList(order && order.items)
const selectedItem = items.find(item => String(item.id) === String(this.data.form.orderItemId)) || items[0]
this.setData({
order,
items,
'form.orderItemId': selectedItem ? selectedItem.id : '',
'form.refundAmount': String(order && (order.actualAmount || order.totalAmount || '')),
amountText: `¥${formatPrice(order && (order.actualAmount || order.totalAmount))}`
})
} catch (error) {
wx.showToast({
title: error.message || '订单信息加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
handleItemChange(event) {
const index = Number(event.detail.value)
const item = this.data.items[index]
this.setData({
'form.orderItemId': item ? item.id : ''
})
},
handleTypeChange(event) {
const index = Number(event.detail.value)
this.setData({
'form.typeIndex': index,
'form.type': index === 0 ? 'REFUND' : 'AFTER_SALE'
})
},
handleInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`form.${field}`]: event.detail.value
})
},
async submit() {
if (!this.data.orderId) {
wx.showToast({ title: '缺少订单信息', icon: 'none' })
return
}
const reason = String(this.data.form.reason || '').trim()
if (!reason) {
wx.showToast({ title: '请填写售后原因', icon: 'none' })
return
}
this.setData({ submitting: true })
try {
await runWithLoading(() => afterSaleApi.applyAfterSale({
orderId: this.data.orderId,
orderItemId: this.data.form.orderItemId || undefined,
type: this.data.form.type,
reason,
refundAmount: this.data.form.refundAmount ? Number(this.data.form.refundAmount) : undefined
}), { title: '提交售后' })
wx.showToast({ title: '售后申请已提交', icon: 'none' })
wx.redirectTo({
url: `/pages/after-sales/index?orderId=${encodeURIComponent(this.data.orderId)}`
})
} catch (error) {
wx.showToast({
title: error.message || '售后申请提交失败',
icon: 'none'
})
} finally {
this.setData({ submitting: false })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,41 @@
<navigation-bar title="申请售后" showBack="{{true}}" fallbackPath="/pages/orders/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">售后申请</text>
<text class="hero-title">{{order && order.orderNo || '选择订单'}}</text>
<text class="hero-desc">{{order ? '可申请金�?' + amountText : '从订单详情进入可自动带入订单信息'}}</text>
</view>
<view wx:if="{{!orderId}}" class="page-card empty-card">
<text class="empty-title">缺少订单信息</text>
<text class="empty-desc">请从订单详情或订单中心发起售后��?/text>
<view class="ghost-btn" bindtap="handleBack">返回订单</view>
</view>
<view wx:else class="page-card form-card">
<view class="field-block">
<text class="field-label">订单项目</text>
<picker mode="selector" range="{{items}}" range-key="productTitle" bindchange="handleItemChange">
<view class="field-picker">{{form.orderItemId ? '已��择项目' : '默认整单'}}</view>
</picker>
</view>
<view class="field-block">
<text class="field-label">售后类型</text>
<picker mode="selector" range="{{typeOptions}}" value="{{form.typeIndex}}" bindchange="handleTypeChange">
<view class="field-picker">{{typeOptions[form.typeIndex]}}</view>
</picker>
</view>
<view class="field-block">
<text class="field-label">逢�款金�?/text>
<input class="field-input" type="digit" value="{{form.refundAmount}}" data-field="refundAmount" bindinput="handleInput" placeholder="可��? placeholder-class="field-placeholder" />
</view>
<view class="field-block">
<text class="field-label">原因说明</text>
<textarea class="field-textarea" maxlength="300" value="{{form.reason}}" data-field="reason" bindinput="handleInput" placeholder="请说明���款或售后原因" placeholder-class="field-placeholder"></textarea>
</view>
<button class="primary-btn" loading="{{submitting}}" bindtap="submit">提交申请</button>
</view>
</view>
</view>
@@ -0,0 +1,12 @@
.form-card {
margin-top: 22rpx;
padding: 28rpx;
}
.field-block + .field-block {
margin-top: 24rpx;
}
.primary-btn {
margin-top: 28rpx;
}
@@ -0,0 +1,96 @@
const afterSaleApi = require('../../api/after-sale')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { formatDateTime, formatPrice } = require('../../utils/format')
function safeList(value) {
if (Array.isArray(value)) return value
if (value && Array.isArray(value.list)) return value.list
if (value && Array.isArray(value.records)) return value.records
return []
}
function statusText(status) {
const value = String(status || '').toUpperCase()
if (value === 'PENDING') return '审核中'
if (value === 'APPROVED') return '已通过'
if (value === 'REJECTED') return '已拒绝'
return status || '处理中'
}
function typeText(type) {
return type === 'REFUND' ? '退款' : (type || '售后')
}
function formatRecord(item) {
return {
...item,
typeText: typeText(item.type),
statusText: statusText(item.status),
amountText: item.refundAmount === undefined || item.refundAmount === null ? '--' : `¥${formatPrice(item.refundAmount)}`,
createdText: formatDateTime(item.createTime)
}
}
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
orderId: '',
loading: false,
isLoggedIn: false,
records: []
}),
onLoad(options) {
this.setData({
orderId: (options && options.orderId) || ''
})
},
onShow() {
this.loadRecords()
},
handleBack() {
navigation.goBack('/pages/profile/index')
},
async loadRecords() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
this.setData({ loading: true })
try {
const payload = await afterSaleApi.getMyAfterSales({ page: 1, size: 50 })
let records = safeList(payload)
if (this.data.orderId) {
records = records.filter(item => String(item.orderId) === String(this.data.orderId))
}
this.setData({
records: records.map(formatRecord)
})
} catch (error) {
wx.showToast({
title: error.message || '售后记录加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
openOrder(event) {
navigation.navigate('/pages/order-detail/index', {
id: event.currentTarget.dataset.orderId
})
},
openProgress(event) {
navigation.navigate('/pages/service-progress/index', {
orderId: event.currentTarget.dataset.orderId
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,49 @@
<navigation-bar title="售后记录" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">售后服务</text>
<text class="hero-title">{{records.length}} 条记�?/text>
<text class="hero-desc">{{orderId ? '当前订单的售后进�? : '逢�款��售后和审核记录集中查看'}}</text>
</view>
<view wx:if="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载售后记录</text>
</view>
<view wx:elif="{{records.length}}">
<view wx:for="{{records}}" wx:key="id" class="page-card record-card">
<view class="record-head">
<view>
<text class="record-label">{{item.typeText}}</text>
<text class="record-title">{{item.afterSaleNo || item.id}}</text>
</view>
<text class="chip">{{item.statusText}}</text>
</view>
<view class="record-grid">
<view>
<text class="summary-label">订单</text>
<text class="summary-value">{{item.orderId}}</text>
</view>
<view>
<text class="summary-label">金额</text>
<text class="summary-value">{{item.amountText}}</text>
</view>
</view>
<text wx:if="{{item.reason}}" class="record-line">原因:{{item.reason}}</text>
<text wx:if="{{item.auditReason}}" class="record-line">处理说明:{{item.auditReason}}</text>
<text class="record-line">提交时间:{{item.createdText}}</text>
<view class="record-actions">
<view class="ghost-btn" data-order-id="{{item.orderId}}" bindtap="openOrder">订单详情</view>
<view class="ghost-btn" data-order-id="{{item.orderId}}" bindtap="openProgress">服务进度</view>
</view>
</view>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">暂无售后记录</text>
<text class="empty-desc">订单完成或支付后可以发起售后申请�?/text>
</view>
</view>
</view>
@@ -0,0 +1,57 @@
.record-card {
margin-top: 22rpx;
padding: 26rpx;
}
.record-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18rpx;
}
.record-label,
.record-title,
.record-line {
display: block;
}
.record-label {
color: var(--theme-primary);
font-size: 22rpx;
font-weight: 800;
}
.record-title {
margin-top: 8rpx;
color: var(--text-primary);
font-size: 30rpx;
font-weight: 800;
}
.record-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14rpx;
margin-top: 22rpx;
}
.record-grid view {
padding: 18rpx;
border-radius: 22rpx;
background: var(--theme-primary-soft);
}
.record-line {
margin-top: 14rpx;
color: #504444;
font-size: 24rpx;
line-height: 1.6;
}
.record-actions {
display: flex;
flex-wrap: wrap;
gap: 14rpx;
margin-top: 20rpx;
}
@@ -0,0 +1,76 @@
const orderApi = require('../../api/order')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { formatDateTime, formatPrice } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
function safeList(value) {
return Array.isArray(value) ? value : []
}
function formatClock(value) {
return value ? String(value).replace('T', ' ').slice(11, 16) : '--'
}
function formatAppointment(item) {
return {
...item,
dayText: String(item.appointmentStartTime || '').slice(5, 10),
timeText: `${formatClock(item.appointmentStartTime)}-${formatClock(item.appointmentEndTime)}`,
amountText: `¥${formatPrice(item.actualAmount || item.totalAmount)}`,
dateTimeText: formatDateTime(item.appointmentStartTime)
}
}
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
isLoggedIn: false,
appointments: []
}),
onShow() {
this.loadAppointments()
},
handleBack() {
navigation.goBack('/pages/artist-orders/index')
},
async loadAppointments() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
this.setData({ loading: true })
try {
const list = safeList(await orderApi.getArtistCalendarRecent(7))
this.setData({
appointments: list.map(formatAppointment)
})
} catch (error) {
wx.showToast({ title: error.message || '预约日历加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
openArtistOrders() {
navigation.navigate('/pages/artist-orders/index')
},
async completeOrder(event) {
const orderId = event.currentTarget.dataset.orderId
if (!orderId) return
try {
await runWithLoading(() => orderApi.completeArtistOrder(orderId))
wx.showToast({ title: '服务已完成', icon: 'none' })
await this.loadAppointments()
} catch (error) {
wx.showToast({ title: error.message || '完成服务失败', icon: 'none' })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,37 @@
<navigation-bar title="预约日历" showBack="{{true}}" fallbackPath="/pages/artist-orders/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">未来 7 �?/text>
<text class="hero-title">{{appointments.length}} 个预�?/text>
<text class="hero-desc">按时间查看即将服务的客户与项目��?/text>
<view class="hero-action-row">
<view class="hero-action secondary" bindtap="openArtistOrders">订单列表</view>
</view>
</view>
<view wx:if="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载日历</text>
</view>
<view wx:elif="{{appointments.length}}">
<view wx:for="{{appointments}}" wx:key="orderItemId" class="page-card appointment-card">
<view class="day-box">
<text>{{item.dayText}}</text>
<text>{{item.timeText}}</text>
</view>
<view class="appointment-main">
<text class="appointment-title">{{item.customerNickname || '客户'}} · {{item.productTitle}}</text>
<text class="appointment-line">{{item.orderStatusText}} · {{item.shopName || '门店'}}</text>
<text class="appointment-line">{{item.amountText}}</text>
<view wx:if="{{item.orderStatus == 1}}" class="ghost-btn" data-order-id="{{item.orderId}}" bindtap="completeOrder">完成服务</view>
</view>
</view>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">未来 7 天暂无预�?/text>
</view>
</view>
</view>
@@ -0,0 +1,49 @@
.appointment-card {
display: flex;
gap: 18rpx;
margin-top: 22rpx;
padding: 24rpx;
}
.day-box {
width: 136rpx;
flex: 0 0 auto;
display: flex;
flex-direction: column;
justify-content: center;
gap: 8rpx;
padding: 20rpx 12rpx;
border-radius: 24rpx;
background: var(--theme-primary-soft);
color: var(--theme-primary);
text-align: center;
font-weight: 800;
}
.appointment-main {
flex: 1;
min-width: 0;
}
.appointment-title,
.appointment-line {
display: block;
}
.appointment-title {
color: var(--text-primary);
font-size: 29rpx;
font-weight: 800;
line-height: 1.45;
}
.appointment-line {
margin-top: 8rpx;
color: #504444;
font-size: 24rpx;
line-height: 1.6;
}
.ghost-btn {
margin-top: 16rpx;
}
@@ -0,0 +1,92 @@
const orderApi = require('../../api/order')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { resolveLegacyImage } = require('../../utils/file')
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
function safeList(value) {
return Array.isArray(value) ? value : []
}
async function formatOrder(order) {
return {
...order,
statusText: getOrderStatusText(order),
statusClass: getOrderStatusClass(order),
amountText: `¥${formatPrice(order && order.actualAmount)}`,
items: await Promise.all(safeList(order && order.items).map(async item => ({
...item,
productImageUrl: await resolveLegacyImage(item.productImage),
priceText: `¥${formatPrice(item.price)}`,
appointmentText: formatDateTime(item.appointmentTime)
})))
}
}
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
isLoggedIn: false,
orders: [],
focusOrderId: ''
}),
onLoad(options) {
this.setData({
focusOrderId: (options && options.orderId) || ''
})
},
onShow() {
this.loadOrders()
},
handleBack() {
navigation.goBack('/pages/profile/index')
},
async loadOrders() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
this.setData({ loading: true })
try {
const list = safeList(await orderApi.getArtistOrders())
const orders = await Promise.all(list.map(formatOrder))
this.setData({ orders })
} catch (error) {
wx.showToast({ title: error.message || '美甲师订单加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
openCalendar() {
navigation.navigate('/pages/artist-calendar/index')
},
async completeOrder(event) {
const orderId = event.currentTarget.dataset.orderId
if (!orderId) return
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '完成服务',
content: '确认这笔订单已经完成服务吗?',
success: res => resolve(Boolean(res.confirm))
})
})
if (!confirmed) return
try {
await runWithLoading(() => orderApi.completeArtistOrder(orderId))
wx.showToast({ title: '服务已完成', icon: 'none' })
await this.loadOrders()
} catch (error) {
wx.showToast({ title: error.message || '完成订单失败', icon: 'none' })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,47 @@
<navigation-bar title="美甲师订�? showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">服务订单</text>
<text class="hero-title">{{orders.length}} 笔相关订�?/text>
<text class="hero-desc">查看客户预约、项目和服务完成状����?/text>
<view class="hero-action-row">
<view class="hero-action secondary" bindtap="openCalendar">预约日历</view>
</view>
</view>
<view wx:if="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载订单</text>
</view>
<view wx:elif="{{orders.length}}">
<view wx:for="{{orders}}" wx:key="id" class="page-card order-card {{item.id == focusOrderId ? 'focus-target' : ''}}">
<view class="order-head">
<view>
<text class="order-no">{{item.orderNo}}</text>
<text class="order-line">{{item.customerNickname || '客户'}} {{item.customerPhoneMasked || ''}}</text>
</view>
<text class="chip">{{item.statusText}}</text>
</view>
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="item-row">
<image class="item-thumb" src="{{orderItem.productImageUrl}}" mode="aspectFill"></image>
<view class="item-main">
<text class="item-title">{{orderItem.productTitle}}</text>
<text class="item-line">{{orderItem.priceText}} x {{orderItem.quantity}}</text>
<text wx:if="{{orderItem.appointmentText}}" class="item-line">预约:{{orderItem.appointmentText}}</text>
</view>
</view>
<view class="order-foot">
<text class="order-amount">{{item.amountText}}</text>
<view wx:if="{{item.status == 1}}" class="ghost-btn" data-order-id="{{item.id}}" bindtap="completeOrder">完成服务</view>
</view>
</view>
</view>
<view wx:else class="page-card empty-card">
<text class="empty-title">暂无相关订单</text>
<text class="empty-desc">有客户预约你服务的项目后会出现在这里�?/text>
</view>
</view>
</view>
@@ -0,0 +1,70 @@
.order-card {
margin-top: 22rpx;
padding: 26rpx;
}
.order-card.focus-target {
border-color: var(--theme-primary);
}
.order-head,
.order-foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
}
.order-no,
.order-line,
.order-amount {
display: block;
}
.order-no {
color: var(--text-primary);
font-size: 28rpx;
font-weight: 800;
}
.order-line {
margin-top: 8rpx;
color: #504444;
font-size: 24rpx;
line-height: 1.6;
}
.item-row {
display: flex;
gap: 18rpx;
margin-top: 22rpx;
}
.item-thumb {
width: 116rpx;
height: 116rpx;
border-radius: 22rpx;
background: var(--theme-primary-soft);
}
.item-main {
flex: 1;
min-width: 0;
}
.item-title {
display: block;
color: var(--text-primary);
font-size: 28rpx;
font-weight: 800;
}
.order-foot {
margin-top: 24rpx;
}
.order-amount {
color: var(--text-primary);
font-size: 28rpx;
font-weight: 800;
}
@@ -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: var(--theme-primary-action);
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: var(--theme-primary-action);
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: var(--theme-primary-action);
font-weight: 800;
}
.review-content {
display: block;
margin-top: 18rpx;
color: #3f4a56;
line-height: 1.7;
white-space: pre-wrap;
}
File diff suppressed because it is too large Load Diff
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+355
View File
@@ -0,0 +1,355 @@
<view class="auth-page-root" style="{{themeVars}}">
<navigation-bar title="账号中心" showBack="{{true}}" fallbackPath="/pages/home/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<scroll-view class="auth-scroll" scroll-y="true" enhanced="true" show-scrollbar="false">
<view class="page-shell auth-page-shell auth-page">
<view class="page-content auth-content {{keyboardVisible ? 'keyboard-active' : ''}}">
<view class="page-card auth-panel">
<view class="tab-row">
<view class="tab-item {{activeTab === 'login' ? 'active' : ''}}" data-tab="login" bindtap="handleTabChange">登录</view>
<view class="tab-item {{activeTab === 'register' ? 'active' : ''}}" data-tab="register" bindtap="handleTabChange">注册</view>
</view>
<block wx:if="{{activeTab === 'login'}}">
<view wx:if="{{!traditionalLoginExpanded}}" class="wechat-login-panel">
<view class="wechat-login-copy">
<text class="wechat-login-title">微信手机号一键登录</text>
<text class="wechat-login-desc">更快登录</text>
</view>
<button
wx:if="{{wechatMiniSupported}}"
class="primary-btn wechat-login-btn"
open-type="getPhoneNumber"
bindgetphonenumber="handleWechatMiniPhoneLogin"
loading="{{wechatMiniLoading}}"
disabled="{{wechatMiniLoading || loading}}"
>
{{wechatMiniLoading ? '正在获取微信手机号...' : '微信手机号一键登录'}}
</button>
<button
wx:else
class="secondary-btn wechat-login-btn wechat-login-btn-disabled"
bindtap="handleWechatMiniUnavailableTap"
>
微信手机号一键登录
</button>
<text class="wechat-login-hint">{{wechatMiniSupported ? '单门店可直接登录' : wechatMiniDisabledReason}}</text>
<view class="agreement-row wechat-agreement" bindtap="handleAgreementToggle">
<view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view>
<view class="agreement-copy">
<text>我已阅读并同意</text>
<text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text>
<text>和</text>
<text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text>
</view>
</view>
</view>
<view wx:if="{{miniShopTicket && !showMiniShopSelector}}" class="hint-card mini-login-resume">
<text class="mini-login-resume-text">请选择登录门店</text>
<view class="ghost-btn mini-login-resume-btn" bindtap="handleResumeMiniShopSelector">继续选择门店</view>
</view>
<view wx:if="{{!traditionalLoginExpanded}}" class="traditional-entry">
<view class="secondary-btn traditional-entry-btn" bindtap="handleShowTraditionalLogin">其他登录方式</view>
</view>
<view wx:if="{{traditionalLoginExpanded}}" class="traditional-login-panel">
<view class="login-divider">
<view class="divider-line"></view>
<text class="login-divider-text">其他方式</text>
<view class="divider-line"></view>
</view>
<view class="toggle-row">
<view class="toggle-item {{loginType === 'password' ? 'active' : ''}}" data-type="password" bindtap="handleLoginTypeChange">账号密码登录</view>
<view class="toggle-item {{loginType === 'phone' ? 'active' : ''}}" data-type="phone" bindtap="handleLoginTypeChange">验证码登录</view>
</view>
</view>
</block>
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="auth-helper">{{authHelperText}}</view>
<block wx:if="{{activeTab === 'register'}}">
<view id="auth-register-nickname-anchor" class="field-block">
<text class="field-label">昵称</text>
<input
class="field-input"
placeholder="请输入昵称"
placeholder-class="field-placeholder"
value="{{form.nickname}}"
data-field="nickname"
data-keyboard-anchor="auth-register-nickname-anchor"
bindinput="handleInputChange"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
</block>
<view id="auth-account-anchor" wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="field-block">
<text class="field-label">账号</text>
<input
class="field-input"
placeholder="请输入账号"
placeholder-class="field-placeholder"
value="{{form.account}}"
data-field="account"
data-keyboard-anchor="auth-account-anchor"
bindinput="handleInputChange"
bindblur="handleAccountBlur"
bindfocus="handleKeyboardFocus"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
<text wx:if="{{activeTab === 'login' && loginAccountStatusText}}" class="status-text {{loginAccountStatusType}}">{{loginAccountStatusText}}</text>
<text wx:if="{{activeTab === 'register' && registerAccountStatusText}}" class="status-text {{registerAccountStatusType}}">{{registerAccountStatusText}}</text>
</view>
<view id="auth-phone-anchor" wx:if="{{activeTab === 'register' || (traditionalLoginExpanded && loginType === 'phone')}}" class="field-block">
<text class="field-label">手机号</text>
<input
class="field-input"
type="number"
placeholder="请输入手机号"
placeholder-class="field-placeholder"
value="{{form.phone}}"
data-field="phone"
data-keyboard-anchor="auth-phone-anchor"
bindinput="handleInputChange"
bindblur="handlePhoneBlur"
bindfocus="handleKeyboardFocus"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
<text wx:if="{{activeTab === 'register' && registerPhoneStatusText}}" class="status-text {{registerPhoneStatusType}}">{{registerPhoneStatusText}}</text>
</view>
<view id="auth-login-password-anchor" wx:if="{{activeTab === 'login' && traditionalLoginExpanded && loginType === 'password'}}" class="field-block">
<text class="field-label">密码</text>
<input
class="field-input"
password
placeholder="请输入密码"
placeholder-class="field-placeholder"
value="{{form.password}}"
data-field="password"
data-keyboard-anchor="auth-login-password-anchor"
bindinput="handleInputChange"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view id="auth-code-anchor" wx:if="{{activeTab === 'register' || (traditionalLoginExpanded && loginType === 'phone')}}" class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input
class="field-input code-input"
type="number"
placeholder="请输入验证码"
placeholder-class="field-placeholder"
value="{{form.verificationCode}}"
data-field="verificationCode"
data-keyboard-anchor="auth-code-anchor"
bindinput="handleInputChange"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view id="auth-register-password-anchor" wx:if="{{activeTab === 'register'}}" class="field-block">
<text class="field-label">密码</text>
<input
class="field-input"
password
placeholder="请输入密码"
placeholder-class="field-placeholder"
value="{{form.password}}"
data-field="password"
data-keyboard-anchor="auth-register-password-anchor"
bindinput="handleInputChange"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view id="auth-register-confirm-password-anchor" wx:if="{{activeTab === 'register'}}" class="field-block">
<text class="field-label">确认密码</text>
<input
class="field-input"
password
placeholder="请再次输入密码"
placeholder-class="field-placeholder"
value="{{form.confirmPassword}}"
data-field="confirmPassword"
data-keyboard-anchor="auth-register-confirm-password-anchor"
bindinput="handleInputChange"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view wx:if="{{activeTab === 'register'}}" class="field-block">
<text class="field-label">选择门店</text>
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{registerShopIndex}}" bindchange="handleRegisterShopChange">
<view class="field-picker">{{registerShopDisplayName || '请选择门店'}}</view>
</picker>
</view>
<view wx:if="{{activeTab === 'login' && traditionalLoginExpanded && loginShops.length}}" class="field-block">
<text class="field-label">选择登录门店</text>
<picker mode="selector" range="{{loginShops}}" range-key="shopName" value="{{loginShopIndex}}" bindchange="handleLoginShopChange">
<view class="field-picker">{{loginShopDisplayName || '请选择登录门店'}}</view>
</picker>
</view>
<view wx:if="{{activeTab === 'login' && traditionalLoginExpanded && loginShopMessage}}" class="hint-card login-shop-tip">{{loginShopMessage}}</view>
<view wx:if="{{activeTab === 'login' && traditionalLoginExpanded}}" class="aux-row">
<text class="aux-link" bindtap="handleToggleResetPanel">忘记密码?</text>
</view>
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="agreement-row" bindtap="handleAgreementToggle">
<view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view>
<view class="agreement-copy">
<text>我已阅读并同意</text>
<text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text>
<text>和</text>
<text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text>
</view>
</view>
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="primary-btn submit-btn {{agreementAccepted ? '' : 'disabled'}}" bindtap="handleSubmit">{{activeTab === 'login' ? '立即登录' : '完成注册'}}</view>
</view>
<view wx:if="{{showResetPanel}}" class="page-card reset-card">
<view class="section-title">重置密码</view>
<view class="section-subtitle">短信验证后重置密码</view>
<view id="auth-reset-phone-anchor" class="field-block">
<text class="field-label">手机号</text>
<input
class="field-input"
type="number"
placeholder="请输入绑定手机号"
placeholder-class="field-placeholder"
value="{{resetForm.phone}}"
data-field="phone"
data-keyboard-anchor="auth-reset-phone-anchor"
bindinput="handleResetInputChange"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view id="auth-reset-code-anchor" class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input
class="field-input code-input"
type="number"
placeholder="请输入验证码"
placeholder-class="field-placeholder"
value="{{resetForm.verificationCode}}"
data-field="verificationCode"
data-keyboard-anchor="auth-reset-code-anchor"
bindinput="handleResetInputChange"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
<view class="code-btn {{forgotCountdown > 0 ? 'disabled' : ''}}" bindtap="handleSendForgotCode">{{forgotCountdown > 0 ? forgotCountdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view id="auth-reset-password-anchor" class="field-block">
<text class="field-label">新密码</text>
<input
class="field-input"
password
placeholder="请输入新密码"
placeholder-class="field-placeholder"
value="{{resetForm.newPassword}}"
data-field="newPassword"
data-keyboard-anchor="auth-reset-password-anchor"
bindinput="handleResetInputChange"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view class="primary-btn submit-btn" bindtap="handleResetPassword">确认重置密码</view>
</view>
<view class="admin-switch-link" bindtap="handleOpenAdminLogin">管理后台登录</view>
</view>
<view wx:if="{{keyboardVisible}}" class="keyboard-spacer" style="height: {{keyboardInsetRpx}}rpx;"></view>
</view>
</scroll-view>
<view wx:if="{{showMiniShopSelector}}" class="mini-shop-mask" catchtouchmove="noop">
<view class="page-card mini-shop-modal">
<text class="mini-shop-kicker">{{miniShopNewUser ? '首次微信登录' : '确认本次登录门店'}}</text>
<text class="mini-shop-title">{{miniShopNewUser ? '先选门店' : '选择登录门店'}}</text>
<text class="mini-shop-desc">{{miniShopMessage || '选择后继续登录'}}</text>
<view class="field-block mini-shop-field">
<text class="field-label">登录门店</text>
<picker mode="selector" range="{{miniShops}}" range-key="shopName" value="{{miniShopIndex}}" bindchange="handleMiniShopChange">
<view class="field-picker">{{miniShopDisplayName || '请选择门店'}}</view>
</picker>
</view>
<view wx:if="{{miniShopNewUser}}" class="hint-card mini-shop-note">首次登录会自动注册并绑定手机号。</view>
<view class="agreement-row mini-shop-agreement" bindtap="handleAgreementToggle">
<view class="agreement-check {{agreementAccepted ? 'checked' : ''}}">{{agreementAccepted ? '✓' : ''}}</view>
<view class="agreement-copy">
<text>我已阅读并同意</text>
<text class="agreement-link" data-type="USER_TERMS" catchtap="openAgreement">《用户协议》</text>
<text>和</text>
<text class="agreement-link" data-type="PRIVACY_POLICY" catchtap="openAgreement">《隐私政策》</text>
</view>
</view>
<view class="mini-shop-actions">
<view class="secondary-btn mini-shop-action" bindtap="handleCloseMiniShopSelector">稍后再选</view>
<view class="primary-btn mini-shop-action" bindtap="handleConfirmMiniShopLogin">{{miniShopSubmitting ? '确认中...' : '确认登录'}}</view>
</view>
</view>
</view>
<view wx:if="{{agreementModalVisible}}" class="agreement-mask" catchtouchmove="noop">
<view class="agreement-modal">
<view class="agreement-modal-title">{{selectedAgreement.title || '协议详情'}}</view>
<view class="agreement-modal-meta">版本:{{selectedAgreement.version || '-'}}</view>
<scroll-view class="agreement-modal-body" scroll-y="true">
<text>{{selectedAgreement.content || '暂无协议内容'}}</text>
</scroll-view>
<view class="primary-btn agreement-modal-close" bindtap="closeAgreementModal">我知道了</view>
</view>
</view>
</view>
+421
View File
@@ -0,0 +1,421 @@
.auth-page-root {
min-height: 100vh;
overflow: visible;
}
.auth-scroll {
height: 100vh;
box-sizing: border-box;
}
.auth-page-shell {
min-height: 100%;
}
.auth-page {
background: var(--theme-page-bg);
}
.auth-content {
min-height: 100%;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
padding: 24rpx 24rpx calc(80rpx + env(safe-area-inset-bottom));
}
.auth-content.keyboard-active {
justify-content: flex-start;
align-items: stretch;
}
.auth-panel,
.reset-card {
width: 100%;
max-width: 680rpx;
padding: 30rpx 28rpx;
}
.auth-panel {
margin-top: 24rpx;
}
.reset-card {
margin-top: 18rpx;
margin-left: auto;
margin-right: auto;
}
.tab-row,
.toggle-row {
display: flex;
align-items: center;
gap: 12rpx;
}
.tab-row {
margin-bottom: 20rpx;
}
.toggle-row {
margin-bottom: 14rpx;
padding: 10rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
}
.tab-item,
.toggle-item {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
height: 76rpx;
border-radius: 999rpx;
color: var(--text-secondary);
font-size: 26rpx;
font-weight: 600;
}
.tab-item.active,
.toggle-item.active {
background: var(--theme-primary-soft);
color: var(--theme-primary);
}
.wechat-login-panel {
padding: 24rpx 22rpx;
border-radius: 28rpx;
background: var(--theme-gradient-soft);
border: 1rpx solid var(--theme-border);
box-shadow: 0 18rpx 38rpx rgba(74, 68, 63, 0.1);
}
.wechat-login-copy {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.wechat-login-title {
display: block;
font-size: 29rpx;
font-weight: 700;
color: var(--text-primary);
}
.wechat-login-desc {
display: block;
font-size: 24rpx;
line-height: 1.6;
color: var(--text-secondary);
}
.wechat-login-btn {
margin-top: 18rpx;
}
.wechat-login-btn.primary-btn {
background: var(--theme-gradient);
box-shadow: 0 16rpx 36rpx rgba(74, 68, 63, 0.16);
}
.wechat-login-btn-disabled {
color: var(--theme-accent);
border-color: var(--theme-border);
background: var(--theme-card-bg);
}
.wechat-login-hint {
display: block;
margin-top: 14rpx;
font-size: 22rpx;
line-height: 1.6;
color: var(--theme-accent);
}
.mini-login-resume {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
margin-top: 18rpx;
}
.mini-login-resume-text {
flex: 1;
min-width: 0;
}
.mini-login-resume-btn {
flex-shrink: 0;
}
.traditional-entry {
margin-top: 18rpx;
}
.traditional-entry-btn {
color: var(--theme-primary-action);
background: var(--theme-card-bg);
}
.traditional-login-panel {
margin-top: 18rpx;
}
.login-divider {
display: flex;
align-items: center;
gap: 18rpx;
margin: 0 0 16rpx;
}
.login-divider-text {
flex-shrink: 0;
font-size: 22rpx;
color: var(--text-secondary);
}
.auth-helper {
margin-bottom: 4rpx;
font-size: 22rpx;
line-height: 1.6;
color: var(--text-secondary);
}
.field-block {
margin-top: 16rpx;
}
.code-row {
display: flex;
align-items: center;
gap: 14rpx;
}
.code-input {
flex: 1;
}
.code-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 180rpx;
height: 92rpx;
padding: 0 18rpx;
border-radius: 24rpx;
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 24rpx;
font-weight: 700;
}
.code-btn.disabled {
background: var(--theme-secondary-soft);
color: var(--text-secondary);
}
.aux-row {
display: flex;
justify-content: flex-end;
margin-top: 16rpx;
}
.aux-link {
font-size: 24rpx;
color: var(--theme-primary);
font-weight: 600;
}
.login-shop-tip {
margin-top: 16rpx;
}
.submit-btn {
margin-top: 24rpx;
}
.submit-btn.disabled {
opacity: 0.52;
}
.agreement-row {
display: flex;
align-items: flex-start;
gap: 14rpx;
margin-top: 22rpx;
color: var(--text-secondary);
font-size: 23rpx;
line-height: 1.6;
}
.agreement-check {
display: flex;
align-items: center;
justify-content: center;
width: 34rpx;
height: 34rpx;
margin-top: 2rpx;
border: 2rpx solid var(--theme-border);
border-radius: 10rpx;
color: var(--theme-card-bg);
font-size: 22rpx;
font-weight: 800;
flex-shrink: 0;
}
.agreement-check.checked {
border-color: var(--theme-primary);
background: var(--theme-primary);
}
.agreement-copy {
flex: 1;
min-width: 0;
}
.agreement-link {
color: var(--theme-primary);
font-weight: 700;
}
.mini-shop-agreement {
margin-top: 22rpx;
}
.wechat-agreement {
width: 100%;
margin-top: 18rpx;
text-align: left;
}
.agreement-mask {
position: fixed;
inset: 0;
z-index: 80;
display: flex;
align-items: center;
justify-content: center;
padding: 28rpx;
background: rgba(74, 68, 63, 0.42);
}
.agreement-modal {
width: 100%;
max-width: 690rpx;
max-height: 82vh;
padding: 30rpx 28rpx;
border-radius: 32rpx;
background: var(--theme-card-bg);
}
.agreement-modal-title {
font-size: 32rpx;
line-height: 1.35;
font-weight: 800;
color: var(--text-primary);
}
.agreement-modal-meta {
margin-top: 10rpx;
font-size: 22rpx;
color: var(--text-secondary);
}
.agreement-modal-body {
height: 640rpx;
max-height: 56vh;
margin-top: 22rpx;
padding: 20rpx;
border-radius: 22rpx;
background: var(--theme-primary-soft);
color: var(--text-primary);
font-size: 24rpx;
line-height: 1.85;
box-sizing: border-box;
}
.agreement-modal-close {
margin-top: 22rpx;
}
.mini-shop-mask {
position: fixed;
inset: 0;
z-index: 60;
display: flex;
align-items: center;
justify-content: center;
padding: 24rpx;
background: rgba(74, 68, 63, 0.34);
}
.mini-shop-modal {
width: 100%;
max-width: 680rpx;
padding: 30rpx 28rpx;
border-radius: 36rpx;
background: var(--theme-card-bg);
}
.mini-shop-kicker {
display: block;
font-size: 22rpx;
font-weight: 700;
letter-spacing: 2rpx;
color: var(--theme-primary);
}
.mini-shop-title {
display: block;
margin-top: 16rpx;
font-size: 34rpx;
line-height: 1.35;
font-weight: 700;
color: var(--text-primary);
}
.mini-shop-desc {
display: block;
margin-top: 14rpx;
font-size: 24rpx;
line-height: 1.75;
color: var(--text-secondary);
}
.mini-shop-field {
margin-top: 26rpx;
}
.mini-shop-note {
margin-top: 20rpx;
}
.mini-shop-actions {
display: flex;
gap: 16rpx;
margin-top: 24rpx;
}
.mini-shop-action {
flex: 1;
}
.keyboard-spacer {
width: 100%;
flex-shrink: 0;
}
.admin-switch-link {
display: flex;
align-items: center;
justify-content: center;
min-height: 72rpx;
margin-top: 24rpx;
color: var(--theme-primary-action);
font-size: 26rpx;
font-weight: 700;
}
+830
View File
@@ -0,0 +1,830 @@
/**
* Purpose: cartApi supports index.js by holding or executing the cart api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const cartApi = require('../../api/cart')
/**
* Purpose: orderApi supports index.js by holding or executing the order api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const orderApi = require('../../api/order')
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
const { resolveLegacyImage } = require('../../utils/file')
const { NO_COUPON_KEY } = require('../../utils/config')
const { runWithLoading } = require('../../utils/loading')
const { clearBuyNowContext, isBuyNowCartItem, readBuyNowContext } = require('../../utils/buy-now')
const { buildRecoveryState, clearRecoveryState } = require('../../utils/recovery')
const {
buildAppointmentValue,
formatDateTime,
formatPrice,
getMinDateText,
isPastAppointment,
parseAppointmentParts
} = require('../../utils/format')
function buildClientRequestId(prefix) {
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
}
/**
* Purpose: getCouponKey supports index.js by holding or executing the get coupon key page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function getCouponKey(coupon) {
return `${coupon.sourceType || 'USER_COUPON'}:${coupon.id}`
}
/**
* Purpose: getCouponDisplay supports index.js by holding or executing the get coupon display page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function getCouponDisplay(coupon) {
if (coupon && coupon.displayText) {
return coupon.displayText
}
if (Number(coupon.couponType) === 1) {
return `${coupon.couponName} ${coupon.discountValue} 折`
}
return `${coupon.couponName} 满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
}
/**
* Purpose: calculateCouponDiscount supports index.js by holding or executing the calculate coupon discount page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function calculateCouponDiscount(coupon, amount) {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
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)
return discountValue ? amount - amount * discountValue / 10 : 0
}
if (Number(coupon.couponType) === 2) {
return Number(coupon.reduceAmount || 0)
}
return 0
}
/**
* Purpose: buildCheckoutIssues supports index.js by holding or executing the build checkout issues page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildCheckoutIssues(items) {
const issues = []
const selectedItems = items.filter(item => item.selected)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!selectedItems.length) {
issues.push('请先勾选要结算的作品')
return issues
}
const missingArtist = selectedItems.find(item => !item.artistId)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (missingArtist) {
issues.push(`请先为“${missingArtist.productTitle}”选择美甲师`)
}
const missingTime = selectedItems.find(item => !item.appointmentValue)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (missingTime) {
issues.push(`请先为“${missingTime.productTitle}”选择预约时间`)
}
const expiredTime = selectedItems.find(item => item.appointmentValue && isPastAppointment(item.appointmentValue))
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (expiredTime) {
issues.push(`“${expiredTime.productTitle}”的预约时间已过,请重新选择`)
}
const shopIds = Array.from(new Set(selectedItems.map(item => item.shopId).filter(Boolean)))
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (shopIds.length > 1) {
issues.push('跨门店作品请分开结算')
}
const artistIds = Array.from(new Set(selectedItems.map(item => item.artistId).filter(Boolean)))
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (artistIds.length > 1) {
issues.push('不同美甲师的项目请分开结算')
}
return issues
}
/**
* cart page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
isLoggedIn: false,
loading: false,
minDate: getMinDateText(),
cartItems: [],
availableCoupons: [],
unavailableCoupons: [],
checkoutPreview: null,
vipTip: '',
selectedCouponKey: NO_COUPON_KEY,
/**
* Purpose: couponSelectionTouched records whether the user explicitly chose a coupon option.
* Usage: keep normal user coupons manual-only while still allowing VIP auto coupons as default.
*/
couponSelectionTouched: false,
selectedCount: 0,
isBuyNowMode: false,
heroKicker: '结算准备',
heroTitle: '已选 0 个预约项目',
heroDesc: '确认美甲师和时间后再下单。',
totalQuantity: 0,
subtotalAmount: 0,
subtotalText: '¥0.00',
discountAmountText: '¥0.00',
totalAmountText: '¥0.00',
checkoutIssues: [],
submittingOrder: false,
recoveryState: clearRecoveryState()
}),
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.loadCartItems()
},
async onPullDownRefresh() {
await this.loadCartItems()
wx.stopPullDownRefresh()
},
/**
* `getSelectedItems` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
getSelectedItems() {
return this.data.cartItems.filter(item => item.selected)
},
/**
* `getSelectedCoupon` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
getSelectedCoupon() {
return this.data.availableCoupons.find(item => item.key === this.data.selectedCouponKey) || null
},
/**
* `refreshSummary` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
refreshSummary() {
const selectedItems = this.getSelectedItems()
const selectedCoupon = this.getSelectedCoupon()
const selectedCount = selectedItems.length
const totalQuantity = selectedItems.reduce((sum, item) => sum + Number(item.quantity || 0), 0)
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)}`,
discountAmountText: `¥${formatPrice(discountAmount)}`,
totalAmountText: `¥${formatPrice(totalAmount)}`,
checkoutIssues
})
},
async loadCartItems() {
const isLoggedIn = auth.isLoggedIn()
const buyNowContext = isLoggedIn ? readBuyNowContext() : null
const buyNowProductId = buyNowContext && buyNowContext.productId ? String(buyNowContext.productId) : ''
this.setData({
isLoggedIn,
isBuyNowMode: Boolean(buyNowProductId),
loading: isLoggedIn,
recoveryState: clearRecoveryState()
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!isLoggedIn) {
this.setData({
cartItems: [],
availableCoupons: [],
unavailableCoupons: [],
checkoutPreview: null,
vipTip: '',
selectedCouponKey: NO_COUPON_KEY,
couponSelectionTouched: false,
loading: false,
recoveryState: clearRecoveryState()
})
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,
userType: artist.userType,
roleLabel: artist.roleLabel,
participateProduction: artist.participateProduction
})) : []
const artist = availableArtists.find(current => String(current.id) === String(item.artistId || ''))
return {
...item,
productImageUrl,
priceText: `¥${formatPrice(item.price)}`,
selected: buyNowProductId ? isBuyNowCartItem(item, buyNowProductId) : 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,
couponSelectionTouched: false,
recoveryState: clearRecoveryState()
})
if (buyNowProductId) {
clearBuyNowContext()
}
await this.loadAvailableCoupons()
} catch (error) {
this.setData({
cartItems: [],
recoveryState: buildRecoveryState({
title: '购物车加载失败',
message: error,
fallbackMessage: '购物车暂时没有加载出来,请重试或先去逛作品。',
actions: [
{ key: 'retryCartLoad', text: '重试' },
{ key: 'products', text: '去逛作品' },
{ key: 'contact', text: '联系客服' }
]
})
})
} finally {
this.setData({
loading: false
})
this.refreshSummary()
}
},
async loadAvailableCoupons() {
const selectedItems = this.getSelectedItems()
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!selectedItems.length) {
this.setData({
availableCoupons: [],
unavailableCoupons: [],
checkoutPreview: null,
vipTip: '',
selectedCouponKey: NO_COUPON_KEY,
couponSelectionTouched: false
})
this.refreshSummary()
return
}
try {
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(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)
})) : []
let selectedCouponKey = this.data.selectedCouponKey
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.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (selectedCouponKey === NO_COUPON_KEY && !this.data.couponSelectionTouched) {
const bestCoupons = list
.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.
*/
if (bestCoupons.length) {
selectedCouponKey = bestCoupons[0].key
}
}
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
})
} finally {
this.refreshSummary()
}
},
/**
* `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleOpenAuth() {
navigation.openAuth('/pages/cart/index')
},
/**
* `handleBrowseProducts` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleBrowseProducts() {
navigation.switchTab('/pages/products/index')
},
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()
const item = cartItems[index]
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item) {
return
}
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` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item) {
return
}
const nextQuantity = Number(item.quantity || 0) + delta
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (nextQuantity < 1 || nextQuantity > 99) {
return
}
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` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item) {
return
}
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '移除作品',
content: '确认从购物车移除这件作品吗?',
success: res => resolve(Boolean(res.confirm))
})
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!confirmed) {
return
}
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` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleOpenProduct(event) {
const productId = event.currentTarget.dataset.productId
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!productId) {
return
}
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` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item) {
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item.availableArtists.length) {
wx.showToast({
title: '当前作品暂时没有可预约美甲师',
icon: 'none'
})
return
}
const tapIndex = await new Promise(resolve => {
wx.showActionSheet({
itemList: item.availableArtists.map(artist => artist.roleLabel ? `${artist.name}(${artist.roleLabel})` : artist.name),
success: res => resolve(res.tapIndex),
fail: () => resolve(-1)
})
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (tapIndex < 0 || tapIndex >= item.availableArtists.length) {
return
}
const artist = item.availableArtists[tapIndex]
item.artistId = artist.id
item.artistName = artist.roleLabel ? `${artist.name}(${artist.roleLabel})` : artist.name
this.setData({
cartItems
})
this.refreshSummary()
},
/**
* `handleDateChange` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleDateChange(event) {
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item) {
return
}
item.appointmentDate = event.detail.value
item.appointmentValue = buildAppointmentValue(item.appointmentDate, item.appointmentClock)
this.setData({
cartItems
})
this.refreshSummary()
},
/**
* `handleTimeChange` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleTimeChange(event) {
const index = Number(event.currentTarget.dataset.index)
const cartItems = this.data.cartItems.slice()
const item = cartItems[index]
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item) {
return
}
item.appointmentClock = event.detail.value
item.appointmentValue = buildAppointmentValue(item.appointmentDate, item.appointmentClock)
this.setData({
cartItems
})
this.refreshSummary()
},
/**
* `handleCouponChange` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleCouponChange(event) {
this.setData({
selectedCouponKey: event.detail.value,
couponSelectionTouched: true
})
this.loadAvailableCoupons()
},
async handleCheckout() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.submittingOrder) {
return
}
const selectedItems = this.getSelectedItems()
const checkoutIssues = buildCheckoutIssues(this.data.cartItems)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (checkoutIssues.length) {
wx.showToast({
title: checkoutIssues[0],
icon: 'none'
})
return
}
this.setData({
submittingOrder: true
})
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),
clientRequestId: buildClientRequestId('mini-order'),
items: selectedItems.map(item => ({
productId: item.productId,
quantity: item.quantity,
artistId: item.artistId,
appointmentTime: item.appointmentValue
}))
}))
let successToast = '订单创建成功'
try {
await getApp().updateCartBadge()
await this.loadCartItems()
} catch (followupError) {
console.error('订单创建后刷新页面失败:', followupError)
successToast = '订单已创建,但页面刷新失败,请前往订单页查看'
}
try {
await navigation.navigate('/pages/orders/index')
} catch (navigationError) {
console.error('订单创建后跳转订单页失败:', navigationError)
successToast = '订单已创建,但跳转订单页失败,请手动前往订单页查看'
}
wx.showToast({
title: successToast,
icon: 'none'
})
} catch (error) {
this.setData({
recoveryState: buildRecoveryState({
title: '下单失败',
message: error,
fallbackMessage: '订单创建失败,请重试;如果担心重复下单,请先查看订单。',
actions: [
{ key: 'retryCheckout', text: '重试下单' },
{ key: 'orders', text: '查看订单' },
{ key: 'contact', text: '联系客服' },
{ key: 'cart', text: '返回购物车' }
]
})
})
} finally {
this.setData({
submittingOrder: false
})
}
}
})
+6
View File
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
+197
View File
@@ -0,0 +1,197 @@
<navigation-bar title="购物车" showBack="{{false}}" isTabPage="{{true}}" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell cart-page" style="{{themeVars}}">
<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 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">{{heroKicker}}</text>
<text class="hero-title">{{heroTitle}}</text>
<text class="hero-desc">{{heroDesc}}</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" lazy-load="{{true}}"></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">{{vipTip || '系统会优先匹配 VIP 优惠。'}}</view>
<radio-group bindchange="handleCouponChange">
<label class="coupon-option">
<radio value="NONE" checked="{{selectedCouponKey === 'NONE'}}" color="{{navThemeColor || '#E8B4B8'}}"></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="{{navThemeColor || '#E8B4B8'}}"></radio>
<view class="coupon-texts">
<view class="coupon-name">{{coupon.displayText}}</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>
</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: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>
<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>
+422
View File
@@ -0,0 +1,422 @@
.cart-page {
padding-bottom: calc(env(safe-area-inset-bottom) + 150rpx);
background: var(--theme-page-bg);
}
.cart-content {
padding-bottom: 20rpx;
}
.cart-hero {
background: var(--theme-gradient-soft);
}
.issue-card {
margin-top: 20rpx;
margin-bottom: 20rpx;
padding: 22rpx 24rpx;
border-radius: 24rpx;
background: var(--theme-primary-soft);
color: var(--theme-neutral);
}
.issue-title {
font-size: 28rpx;
font-weight: 700;
}
.issue-item {
margin-top: 10rpx;
font-size: 24rpx;
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: var(--text-primary);
}
.recovery-desc {
font-size: 24rpx;
line-height: 1.6;
color: var(--text-secondary);
}
.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: var(--theme-card-bg);
border: 2rpx solid var(--theme-border);
color: var(--theme-neutral);
font-size: 24rpx;
font-weight: 700;
}
.recovery-btn.primary {
background: var(--theme-primary);
border-color: var(--theme-primary);
color: var(--theme-tertiary);
}
.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 var(--theme-border);
}
.select-dot.active {
border-color: var(--theme-primary);
background: var(--theme-primary);
}
.cart-thumb {
width: 140rpx;
height: 140rpx;
border-radius: 22rpx;
background: var(--theme-primary-soft);
}
.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: var(--text-primary);
}
.cart-price {
font-size: 30rpx;
font-weight: 700;
color: var(--theme-primary-action);
}
.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: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 20rpx;
font-weight: 700;
}
.cart-meta {
font-size: 24rpx;
color: var(--text-secondary);
}
.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: var(--theme-primary-soft);
}
.selector-row.compact {
min-height: 72rpx;
}
.selector-row.issue {
background: var(--theme-secondary-soft);
}
.selector-label {
font-size: 24rpx;
color: var(--text-secondary);
}
.selector-value {
font-size: 24rpx;
color: var(--text-primary);
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: var(--text-secondary);
}
.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: var(--theme-primary-soft);
color: var(--theme-primary-action);
font-size: 34rpx;
}
.qty-value {
min-width: 48rpx;
text-align: center;
font-size: 28rpx;
font-weight: 700;
color: var(--text-primary);
}
.remove-btn {
font-size: 24rpx;
color: var(--theme-primary-action);
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 var(--theme-border);
}
.coupon-option:first-child {
border-top: 0;
padding-top: 10rpx;
}
.coupon-option.active {
color: var(--theme-primary);
}
.coupon-texts {
flex: 1;
}
.coupon-name {
font-size: 26rpx;
font-weight: 700;
color: var(--text-primary);
}
.coupon-desc {
margin-top: 8rpx;
font-size: 22rpx;
color: var(--text-secondary);
}
.coupon-tag {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 92rpx;
height: 44rpx;
padding: 0 14rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 20rpx;
font-weight: 700;
}
.unavailable-coupon-list {
margin-top: 22rpx;
padding-top: 18rpx;
border-top: 2rpx solid var(--theme-border);
}
.unavailable-title {
font-size: 24rpx;
font-weight: 700;
color: var(--text-secondary);
}
.unavailable-coupon {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18rpx;
margin-top: 14rpx;
font-size: 22rpx;
color: var(--text-secondary);
}
.unavailable-coupon text:first-child {
flex: 1;
min-width: 0;
color: var(--theme-neutral);
}
.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: var(--theme-neutral);
font-size: 24rpx;
line-height: 1.6;
}
.summary-vip {
color: var(--theme-primary);
font-weight: 700;
}
.summary-row {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10rpx 0;
font-size: 26rpx;
color: var(--theme-neutral);
}
.summary-row.total {
margin-top: 10rpx;
padding-top: 18rpx;
border-top: 2rpx solid var(--theme-border);
font-size: 30rpx;
font-weight: 700;
color: var(--text-primary);
}
.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: var(--theme-primary-action);
}
.checkout-meta {
margin-top: 8rpx;
font-size: 22rpx;
color: var(--text-secondary);
}
.checkout-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 220rpx;
height: 84rpx;
padding: 0 26rpx;
border-radius: 999rpx;
background: var(--theme-gradient);
color: var(--theme-tertiary);
font-size: 28rpx;
font-weight: 700;
}
+168
View File
@@ -0,0 +1,168 @@
/**
* 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: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
/**
* Purpose: getBenefitText supports index.js by holding or executing the get benefit text 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 getBenefitText(coupon) {
if (Number(coupon.couponType) === 1) {
return `${coupon.discountValue} 折`
}
return `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
}
/**
* coupons page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
isLoggedIn: false,
coupons: [],
filteredCoupons: [],
activeFilter: 'all',
filterOptions: [
{ value: 'all', label: '全部' },
{ value: 'available', label: '未使用' },
{ value: 'used', label: '已使用' },
{ value: 'expired', label: '已过期' }
]
}),
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.loadCoupons()
},
async loadCoupons() {
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
loading: isLoggedIn
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!isLoggedIn) {
this.setData({
coupons: [],
filteredCoupons: [],
activeFilter: 'all',
loading: false
})
return
}
try {
const coupons = await couponApi.listUserCoupons()
const list = Array.isArray(coupons) ? coupons.map(item => ({
...item,
benefitText: getBenefitText(item),
periodText: `${String(item.startTime || '').slice(0, 10)} - ${String(item.endTime || '').slice(0, 10)}`,
sourceText: item.sourceType === 'SYSTEM_VIP' ? 'VIP 自动匹配' : '用户优惠券'
})) : []
this.setData({
coupons: list
})
this.applyFilter(this.data.activeFilter, list)
} catch (error) {
this.setData({
coupons: [],
filteredCoupons: []
})
wx.showToast({
title: error.message || '优惠券加载失败',
icon: 'none'
})
} finally {
this.setData({
loading: false
})
}
},
/**
* `applyFilter` 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.
*/
applyFilter(filterValue, sourceCoupons) {
const activeFilter = filterValue || 'all'
const coupons = Array.isArray(sourceCoupons) ? sourceCoupons : this.data.coupons
let filteredCoupons = coupons
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (activeFilter === 'available') {
filteredCoupons = coupons.filter(item => Number(item.status) === 1)
} else if (activeFilter === 'used') {
filteredCoupons = coupons.filter(item => Number(item.status) === 2)
} else if (activeFilter === 'expired') {
filteredCoupons = coupons.filter(item => Number(item.status) === 3)
}
this.setData({
activeFilter,
filteredCoupons
})
},
/**
* `handleFilterChange` 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.
*/
handleFilterChange(event) {
const value = event.currentTarget.dataset.value
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!value || value === this.data.activeFilter) {
return
}
this.applyFilter(value)
},
/**
* `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleOpenAuth() {
navigation.openAuth('/pages/coupons/index')
},
/**
* `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.
*/
handleBack() {
navigation.goBack('/pages/profile/index')
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,59 @@
<navigation-bar title="我的优惠券" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell coupons-page" style="{{themeVars}}">
<view class="page-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="{{coupons.length}}">
<view class="page-hero coupons-hero">
<text class="hero-kicker">优惠资产</text>
<text class="hero-title">当前有 {{coupons.length}} 张</text>
<text class="hero-desc">下单前可查看可用优惠。</text>
</view>
<view class="coupon-filter-row">
<view
wx:for="{{filterOptions}}"
wx:key="value"
class="coupon-filter-chip {{activeFilter === item.value ? 'active' : ''}}"
data-value="{{item.value}}"
bindtap="handleFilterChange"
>
{{item.label}}
</view>
</view>
<block wx:if="{{filteredCoupons.length}}">
<view wx:for="{{filteredCoupons}}" wx:key="id" class="page-card coupon-card">
<view class="coupon-top">
<view>
<view class="coupon-title">{{item.couponName}}</view>
<view class="coupon-source">{{item.sourceText}}</view>
</view>
<view class="coupon-status">{{item.statusName || '待使用'}}</view>
</view>
<view class="coupon-benefit">{{item.benefitText}}</view>
<view class="coupon-period">{{item.periodText}}</view>
</view>
</block>
<view wx:else class="page-card empty-card">
<text class="empty-title">当前筛选下暂无优惠券</text>
<text class="empty-desc">换个筛选试试。</text>
</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>
</view>
</view>
@@ -0,0 +1,86 @@
.coupons-hero {
margin-bottom: 20rpx;
}
.coupon-filter-row {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
margin-bottom: 20rpx;
}
.coupon-filter-chip {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 120rpx;
height: 60rpx;
padding: 0 24rpx;
border-radius: 999rpx;
background: var(--theme-card-bg);
border: 1rpx solid var(--theme-border);
color: var(--text-secondary);
font-size: 24rpx;
font-weight: 600;
}
.coupon-filter-chip.active {
background: var(--theme-gradient);
border-color: transparent;
color: #ffffff;
}
.coupon-card + .coupon-card {
margin-top: 20rpx;
}
.coupon-card {
padding: 26rpx 28rpx;
background: var(--theme-gradient-soft);
}
.coupon-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20rpx;
}
.coupon-title {
font-size: 30rpx;
font-weight: 700;
color: var(--text-primary);
}
.coupon-source {
margin-top: 10rpx;
font-size: 22rpx;
color: var(--text-secondary);
}
.coupon-status {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 140rpx;
height: 52rpx;
padding: 0 18rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.8);
color: var(--theme-primary);
font-size: 22rpx;
font-weight: 700;
}
.coupon-benefit {
margin-top: 26rpx;
font-size: 42rpx;
font-weight: 800;
color: var(--theme-primary);
}
.coupon-period {
margin-top: 18rpx;
font-size: 24rpx;
color: var(--text-secondary);
}
+40
View File
@@ -0,0 +1,40 @@
const userApi = require('../../api/user')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
contact: null
}),
onShow() {
this.loadContact()
},
handleBack() {
navigation.goBack('/pages/profile/index')
},
async loadContact() {
this.setData({ loading: true })
try {
const contact = await userApi.getPlatformContact()
this.setData({ contact })
} catch (error) {
this.setData({ contact: null })
} finally {
this.setData({ loading: false })
}
},
openRoute(event) {
const route = event.currentTarget.dataset.route
const pureRoute = String(route || '').split('?')[0]
if (navigation.isTabPage(pureRoute)) {
navigation.switchTab(pureRoute)
return
}
navigation.navigate(route)
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+41
View File
@@ -0,0 +1,41 @@
<navigation-bar title="帮助与客�? showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">Fingertip Designer Support</text>
<text class="hero-title">帮助与客�?/text>
<text class="hero-desc">订单、预约��售后和账号问题都可以从这里继续处理�?/text>
</view>
<view class="page-card contact-card">
<text class="section-title">平台联系信息</text>
<block wx:if="{{contact}}">
<text wx:if="{{contact.contactName}}" class="contact-line">{{contact.contactName}} {{contact.roleLabel || ''}}</text>
<text wx:if="{{contact.phoneAvailable && contact.phone}}" class="contact-line">电话:{{contact.phone}}</text>
<text wx:if="{{contact.wechatAvailable && contact.wechatId}}" class="contact-line">微信:{{contact.wechatId}}</text>
<text wx:if="{{contact.platformContactText}}" class="contact-line">{{contact.platformContactText}}</text>
</block>
<text wx:else class="contact-line">暂无可展示的客服信息,请稍后重试或从订单详情联系服务人员�?/text>
</view>
<view class="quick-grid">
<view class="page-card quick-card" data-route="/pages/orders/index" bindtap="openRoute">
<text class="quick-title">订单中心</text>
<text class="quick-desc">查看预约、支付��评�?/text>
</view>
<view class="page-card quick-card" data-route="/pages/after-sales/index" bindtap="openRoute">
<text class="quick-title">售后记录</text>
<text class="quick-desc">查看逢�款和处理进度</text>
</view>
<view class="page-card quick-card" data-route="/pages/notifications/index" bindtap="openRoute">
<text class="quick-title">消息中心</text>
<text class="quick-desc">查看系统通知</text>
</view>
<view class="page-card quick-card" data-route="/pages/settings/index" bindtap="openRoute">
<text class="quick-title">账号设置</text>
<text class="quick-desc">修改资料、手机号和密�?/text>
</view>
</view>
</view>
</view>
+42
View File
@@ -0,0 +1,42 @@
.contact-card {
margin-top: 22rpx;
padding: 26rpx;
}
.contact-line,
.quick-title,
.quick-desc {
display: block;
}
.contact-line {
margin-top: 12rpx;
color: #504444;
font-size: 25rpx;
line-height: 1.6;
}
.quick-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18rpx;
margin-top: 22rpx;
}
.quick-card {
min-height: 180rpx;
padding: 24rpx;
}
.quick-title {
color: var(--text-primary);
font-size: 29rpx;
font-weight: 800;
}
.quick-desc {
margin-top: 12rpx;
color: #504444;
font-size: 23rpx;
line-height: 1.6;
}
+469
View File
@@ -0,0 +1,469 @@
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: cache supports index.js by holding or executing the cache 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 cache = require('../../utils/cache')
const { buildProductCards } = require('../../utils/product')
const { resolveImageList } = require('../../utils/file')
const { DEFAULT_SHOP_IMAGE, CACHE_TTL } = require('../../utils/config')
const {
createKeyboardSafeData,
attachKeyboardSafe,
detachKeyboardSafe,
handleKeyboardFocus,
handleKeyboardBlur,
resetKeyboardSafe
} = require('../../utils/keyboard-safe')
/**
* Purpose: productApi supports index.js by holding or executing the product 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 productApi = require('../../api/product')
/**
* Purpose: shopApi supports index.js by holding or executing the shop 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 shopApi = require('../../api/shop')
/**
* Purpose: userApi supports index.js by holding or executing the user 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 userApi = require('../../api/user')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
/**
* home page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 96
}), theme.pageThemeData(getApp().globalData.shopTheme), {
initialized: false,
loading: false,
loadingMore: false,
isLoggedIn: false,
userInfo: null,
navTitle: '游客模式',
greeting: '欢迎来到 Fingertip Designer 指尖设计师',
displayName: '先看看门店和作品',
searchKeyword: '',
bannerImages: [],
featuredItems: [],
popularItems: [],
announcements: [],
popularPage: 1,
pageSize: 6,
hasMore: false,
popularTotal: 0
}),
/**
* `onLoad` 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.
*/
onLoad() {
this.homeRequestId = 0
this.ensureKeyboardSafe()
this.loadHomeData()
},
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.ensureKeyboardSafe()
this.syncUserState()
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.initialized && this.data.isLoggedIn) {
this.loadUserProfile()
}
},
/**
* `onHide` 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.
*/
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
/**
* `onUnload` 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.
*/
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
async onPullDownRefresh() {
cache.removeByPrefix('home:')
await this.loadHomeData()
wx.stopPullDownRefresh()
},
/**
* `onReachBottom` 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.
*/
onReachBottom() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!this.data.hasMore || this.data.loadingMore) {
return
}
this.loadPopularProducts(false)
},
/**
* `ensureKeyboardSafe` 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.
*/
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 96,
spacerExtraRpx: 24
})
},
/**
* `syncUserState` 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.
*/
syncUserState() {
const app = getApp()
const userInfo = auth.getStoredUserInfo()
const isLoggedIn = auth.isLoggedIn()
const navTitle = userInfo && String(userInfo.shopName || '').trim()
? String(userInfo.shopName).trim()
: '游客模式'
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (app) {
app.globalData.userInfo = userInfo
app.globalData.isLoggedIn = isLoggedIn
}
this.setData({
isLoggedIn,
userInfo,
navTitle,
greeting: isLoggedIn ? '欢迎回来' : '游客模式',
displayName: isLoggedIn
? ((userInfo && userInfo.nickname) || 'Yumi 用户')
: '先逛逛喜欢的款式和门店',
bannerImages: isLoggedIn ? [] : this.data.bannerImages
})
},
async loadUserProfile() {
if (!auth.isLoggedIn()) {
this.syncUserState()
return
}
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
this.syncUserState()
} catch (error) {}
},
async loadAnnouncements() {
if (!auth.isLoggedIn()) {
this.setData({ announcements: [] })
return
}
try {
const list = await userApi.listMyAnnouncements()
this.setData({
announcements: Array.isArray(list) ? list.map(item => ({
...item,
displayText: `${item.publisherName || '平台'}:${item.content || ''}`
})) : []
})
} catch (error) {
this.setData({ announcements: [] })
}
},
async loadHomeData() {
const requestId = ++this.homeRequestId
this.setData({ loading: true })
this.syncUserState()
try {
const loggedIn = auth.isLoggedIn()
await Promise.all([
this.loadUserProfile(),
this.loadAnnouncements(),
loggedIn ? Promise.resolve() : this.loadBannerImages(requestId),
this.loadFeaturedProducts(requestId),
this.loadPopularProducts(true, requestId)
])
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.homeRequestId) {
this.setData({
initialized: true
})
}
} catch (error) {
wx.showToast({
title: error.message || '首页加载失败',
icon: 'none'
})
} finally {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.homeRequestId) {
this.setData({ loading: false })
}
}
},
async loadBannerImages(requestId) {
const banners = await cache.remember('home:banners', CACHE_TTL.banner, async () => {
const shops = await shopApi.getPublicShops()
const list = Array.isArray(shops) ? shops : []
const resolved = await Promise.all(list.slice(0, 6).map(async (shop, index) => {
const imageIds = shop.coverImageFileId || shop.imageFileIds
const urls = await resolveImageList(imageIds, DEFAULT_SHOP_IMAGE)
return {
id: `${shop.id}-${index}`,
shopId: shop.id,
shopName: shop.shopName,
businessHours: shop.businessHours || '欢迎到店体验',
imageUrl: urls[0]
}
}))
return resolved.filter(item => item.imageUrl)
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.homeRequestId) {
this.setData({
bannerImages: Array.isArray(banners) ? banners : []
})
}
},
async loadFeaturedProducts(requestId) {
const items = await cache.remember('home:featured', CACHE_TTL.homeList, async () => {
const result = await productApi.getProductPage({
page: 1,
size: 6,
tag: '精选'
})
return buildProductCards(result && result.list ? result.list : [])
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.homeRequestId) {
this.setData({
featuredItems: Array.isArray(items) ? items : []
})
}
},
async loadPopularProducts(reset, requestId) {
const currentRequestId = requestId || this.homeRequestId
const nextPage = reset ? 1 : this.data.popularPage + 1
const loadingState = reset ? { loading: true } : { loadingMore: true }
this.setData(loadingState)
try {
const result = await productApi.getProductPage({
page: nextPage,
size: this.data.pageSize,
tag: '热门'
})
const cards = await buildProductCards(result && result.list ? result.list : [])
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (currentRequestId !== this.homeRequestId) {
return
}
const mergedItems = reset ? cards : this.data.popularItems.concat(cards)
const total = Number(result && result.total) || 0
this.setData({
popularItems: mergedItems,
popularPage: nextPage,
popularTotal: total,
hasMore: mergedItems.length < total
})
} catch (error) {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (currentRequestId !== this.homeRequestId) {
return
}
wx.showToast({
title: error.message || '热门作品加载失败',
icon: 'none'
})
} finally {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (currentRequestId === this.homeRequestId) {
this.setData({
loadingMore: false
})
}
}
},
/**
* `handleSearchInput` 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.
*/
handleSearchInput(event) {
this.setData({
searchKeyword: event.detail.value
})
},
/**
* `handleSearchFocus` 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.
*/
handleSearchFocus(event) {
handleKeyboardFocus(this, event)
},
/**
* `handleSearchBlur` 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.
*/
handleSearchBlur() {
handleKeyboardBlur(this)
},
/**
* `handleSearchConfirm` 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.
*/
handleSearchConfirm() {
resetKeyboardSafe(this)
navigation.openProducts({
keyword: this.data.searchKeyword.trim()
})
},
/**
* `handleBannerTap` 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.
*/
handleBannerTap(event) {
const shopId = event.currentTarget.dataset.shopId
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopId) {
return
}
navigation.navigate('/pages/shop-detail/index', {
id: shopId,
returnTo: navigation.getCurrentPageUrl()
})
},
/**
* `handleProfileTap` 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.
*/
handleProfileTap() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.isLoggedIn) {
navigation.switchTab('/pages/profile/index')
return
}
navigation.openAuth()
},
/**
* `handleProductSelect` 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.
*/
handleProductSelect(event) {
const product = event.detail || {}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!product.id) {
return
}
navigation.navigate('/pages/product-detail/index', {
id: product.id
})
},
/**
* `handleSeeAllFeatured` 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.
*/
handleSeeAllFeatured() {
navigation.openProducts({
tag: '精选'
})
},
/**
* `handleSeeAllPopular` 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.
*/
handleSeeAllPopular() {
navigation.openProducts({
tag: '热门'
})
}
})
+7
View File
@@ -0,0 +1,7 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar",
"product-card": "/components/product-card/product-card"
},
"enablePullDownRefresh": true
}
+152
View File
@@ -0,0 +1,152 @@
<view class="home-page-root yumi-page" style="{{themeVars}}">
<navigation-bar title="{{navTitle}}" showBack="{{false}}" isTabPage="{{true}}" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="home-scroll">
<view class="page-shell home-page {{keyboardVisible ? 'keyboard-active' : ''}}">
<view class="page-content">
<view class="page-hero home-hero">
<text class="hero-kicker">{{isLoggedIn ? greeting : 'YUMI NAIL 小程序'}}</text>
<text class="hero-title">{{displayName}}</text>
<text class="hero-desc">先选喜欢的作品。</text>
<view class="hero-action-row">
<view class="hero-action primary" bindtap="handleProfileTap">{{isLoggedIn ? '进入个人中心' : '立即登录'}}</view>
<view class="hero-action secondary" bindtap="handleSeeAllPopular">看看热门作品</view>
</view>
<view id="home-search-anchor" class="search-box">
<input
class="search-input"
placeholder="搜索作品、风格或门店"
placeholder-class="field-placeholder"
value="{{searchKeyword}}"
bindinput="handleSearchInput"
bindconfirm="handleSearchConfirm"
bindfocus="handleSearchFocus"
bindblur="handleSearchBlur"
data-keyboard-anchor="home-search-anchor"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
confirm-type="search"
/>
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>
</view>
<swiper wx:if="{{announcements.length}}" class="announcement-strip" autoplay circular vertical interval="2600">
<swiper-item wx:for="{{announcements}}" wx:key="id">
<view class="announcement-item">{{item.displayText}}</view>
</swiper-item>
</swiper>
<view class="summary-strip">
<view wx:if="{{!isLoggedIn}}" class="summary-metric">
<text class="summary-label">门店橱窗</text>
<text class="summary-value">{{bannerImages.length ? bannerImages.length : 0}} 家</text>
<text class="summary-note">看环境</text>
</view>
<view class="summary-metric">
<text class="summary-label">精选作品</text>
<text class="summary-value">{{featuredItems.length ? featuredItems.length : 0}} 款</text>
<text class="summary-note">找灵感</text>
</view>
<view class="summary-metric">
<text class="summary-label">热门推荐</text>
<text class="summary-value">{{popularItems.length ? popularItems.length : 0}} 条</text>
<text class="summary-note">热门款</text>
</view>
</view>
<view wx:if="{{!isLoggedIn}}" class="guest-tip">
登录后可同步收藏和预约记录。
</view>
</view>
<view wx:if="{{!isLoggedIn}}" 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">看店铺环境</text>
</view>
</view>
<view wx:if="{{bannerImages.length}}" class="banner-box page-card yumi-glass-card">
<swiper class="banner-swiper" indicator-dots autoplay circular interval="3200">
<swiper-item wx:for="{{bannerImages}}" wx:key="id">
<view class="banner-item" data-shop-id="{{item.shopId}}" bindtap="handleBannerTap">
<image class="banner-image" src="{{item.imageUrl}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="banner-mask">
<view class="banner-badge">门店实拍</view>
<view class="banner-title">{{item.shopName}}</view>
<view class="banner-desc">{{item.businessHours}}</view>
</view>
</view>
</swiper-item>
</swiper>
</view>
<view wx:else class="page-card yumi-glass-card empty-card">
<text class="empty-title">门店内容正在补充中</text>
<text class="empty-desc">先看看作品。</text>
</view>
</view>
<view 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">先看热门款</text>
</view>
<view class="section-link" bindtap="handleSeeAllFeatured">查看全部</view>
</view>
<view wx:if="{{featuredItems.length}}" class="featured-panel">
<scroll-view class="featured-scroll" scroll-x enable-flex>
<view class="featured-list">
<view wx:for="{{featuredItems}}" wx:key="id" class="featured-card">
<product-card item="{{item}}" bindselect="handleProductSelect"></product-card>
</view>
</view>
</scroll-view>
</view>
<view wx:else class="page-card yumi-glass-card empty-card">
<text class="empty-title">精选作品正在整理中</text>
<text class="empty-desc">稍后再来看看。</text>
</view>
</view>
<view 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">热门款式</text>
</view>
<view class="section-link" bindtap="handleSeeAllPopular">查看全部</view>
</view>
<view wx:if="{{popularItems.length}}" class="popular-grid">
<view wx:for="{{popularItems}}" wx:key="id" class="popular-card">
<product-card item="{{item}}" show-stats="{{true}}" bindselect="handleProductSelect"></product-card>
</view>
</view>
<view wx:if="{{popularItems.length && (loadingMore || !hasMore)}}" class="section-load-state">
<text class="section-load-text">{{loadingMore ? '正在加载更多热门作品...' : '已经到底了'}}</text>
</view>
<view wx:elif="{{loading}}" class="page-card yumi-glass-card empty-card">
<text class="empty-title">正在加载首页内容</text>
</view>
<view wx:else class="page-card yumi-glass-card empty-card">
<text class="empty-title">还没有热门作品</text>
<text class="empty-desc">稍后再来看看。</text>
</view>
</view>
</view>
<view wx:if="{{keyboardVisible}}" class="keyboard-light-spacer" style="height: {{keyboardInsetRpx}}rpx;"></view>
</view>
</view>
</view>
+218
View File
@@ -0,0 +1,218 @@
.home-page-root {
min-height: 100vh;
padding: 0;
color: var(--text-primary);
background: var(--theme-page-bg);
}
.home-scroll {
min-height: 100%;
}
.home-page {
min-height: 100%;
background: var(--theme-page-bg);
}
.home-page.keyboard-active {
padding-bottom: 0;
}
.home-hero {
background: var(--theme-gradient-soft);
box-shadow: 0 28rpx 64rpx rgba(74, 68, 63, 0.1);
}
.home-hero .hero-kicker,
.section-kicker {
color: var(--theme-secondary);
}
.home-hero .hero-title,
.section-title,
.summary-value,
.empty-title {
color: var(--text-primary);
}
.home-hero .hero-desc,
.section-subtitle,
.summary-label,
.summary-note,
.empty-desc,
.field-placeholder {
color: var(--text-secondary);
}
.home-hero .hero-action.secondary {
border: 1rpx solid var(--theme-border);
background: rgba(255, 255, 255, 0.9);
color: var(--theme-primary-action);
}
.search-box {
display: flex;
align-items: center;
gap: 16rpx;
margin-top: 30rpx;
padding: 10rpx;
border: 1rpx solid var(--theme-border);
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.92);
box-shadow: 0 18rpx 42rpx rgba(74, 68, 63, 0.08);
}
.search-input {
flex: 1;
height: 72rpx;
padding: 0 24rpx;
font-size: 28rpx;
color: var(--text-primary);
}
.search-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 150rpx;
height: 72rpx;
border-radius: 999rpx;
background: var(--theme-gradient);
color: #ffffff;
font-size: 26rpx;
font-weight: 700;
}
.guest-tip {
margin-top: 24rpx;
padding: 20rpx 24rpx;
border-radius: 22rpx;
background: rgba(255, 255, 255, 0.86);
border: 1rpx solid var(--theme-border);
color: var(--text-secondary);
font-size: 24rpx;
line-height: 1.7;
}
.banner-box {
overflow: hidden;
border-radius: 34rpx;
}
.banner-swiper,
.banner-item {
width: 100%;
height: 396rpx;
}
.banner-item {
position: relative;
}
.banner-image {
width: 100%;
height: 100%;
}
.banner-mask {
position: absolute;
left: 24rpx;
right: 24rpx;
bottom: 24rpx;
padding: 22rpx 24rpx;
border-radius: 24rpx;
border: 1rpx solid rgba(255, 255, 255, 0.92);
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 18rpx 42rpx rgba(74, 68, 63, 0.1);
}
.announcement-strip {
height: 58rpx;
margin-top: 18rpx;
border-radius: 16rpx;
background: var(--theme-primary-soft);
border: 1rpx solid var(--theme-border);
overflow: hidden;
}
.announcement-item {
height: 58rpx;
line-height: 58rpx;
padding: 0 22rpx;
font-size: 24rpx;
color: var(--theme-neutral);
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.banner-badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 8rpx 18rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 22rpx;
font-weight: 700;
}
.banner-title {
margin-top: 14rpx;
font-size: 34rpx;
font-weight: 700;
color: var(--text-primary);
}
.banner-desc {
margin-top: 8rpx;
font-size: 24rpx;
color: var(--text-secondary);
}
.featured-panel {
padding: 2rpx 0 4rpx;
}
.featured-scroll {
width: 100%;
white-space: nowrap;
}
.featured-list {
display: inline-flex;
gap: 18rpx;
padding: 4rpx 2rpx 12rpx;
}
.featured-card {
width: 332rpx;
}
.popular-grid {
display: flex;
flex-wrap: wrap;
gap: 18rpx;
padding-top: 2rpx;
}
.popular-card {
width: calc(50% - 9rpx);
}
.section-load-state {
display: flex;
justify-content: center;
padding-top: 18rpx;
}
.section-load-text {
font-size: 22rpx;
color: var(--text-secondary);
}
.keyboard-light-spacer {
width: 100%;
flex-shrink: 0;
}
+60
View File
@@ -0,0 +1,60 @@
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* index page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: navTitle supports index.js by holding or executing the nav title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
navTitle: '游客模式'
},
/**
* `onLoad` 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.
*/
onLoad() {
this.syncNavTitle()
wx.switchTab({
/**
* Purpose: url supports index.js by holding or executing the url page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
url: '/pages/home/index'
})
},
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.syncNavTitle()
},
/**
* `syncNavTitle` 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.
*/
syncNavTitle() {
const userInfo = auth.getStoredUserInfo()
const navTitle = userInfo && String(userInfo.shopName || '').trim()
? String(userInfo.shopName).trim()
: '游客模式'
this.setData({
navTitle
})
}
})
+5
View File
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+7
View File
@@ -0,0 +1,7 @@
<navigation-bar title="{{navTitle}}" showBack="{{false}}" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="redirect-page">
<view class="redirect-card">
<view class="redirect-title">正在进入首页</view>
<view class="redirect-desc">即将进入首页</view>
</view>
</view>
+33
View File
@@ -0,0 +1,33 @@
page {
min-height: 100vh;
background: var(--theme-page-bg);
}
.redirect-page {
min-height: calc(100vh - 88rpx);
display: flex;
align-items: center;
justify-content: center;
padding: 32rpx;
}
.redirect-card {
width: 100%;
padding: 40rpx 32rpx;
border-radius: 28rpx;
background: #ffffff;
box-shadow: 0 18rpx 50rpx rgba(122, 67, 88, 0.08);
}
.redirect-title {
font-size: 34rpx;
font-weight: 700;
color: var(--text-primary);
}
.redirect-desc {
margin-top: 18rpx;
font-size: 24rpx;
line-height: 1.7;
color: var(--text-secondary);
}
@@ -0,0 +1,218 @@
/**
* Purpose: userApi supports index.js by holding or executing the user 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 userApi = require('../../api/user')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
const { previewImagesSafely } = require('../../utils/file')
/**
* notifications page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: messages supports index.js by holding or executing the messages page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
messages: [],
/**
* Purpose: unreadCount supports index.js by holding or executing the unread count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unreadCount: 0,
/**
* Purpose: detailVisible supports index.js by holding or executing the detail visible page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
detailVisible: false,
/**
* Purpose: currentMessage supports index.js by holding or executing the current message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentMessage: null
},
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.loadMessages()
},
async loadMessages() {
if (!navigation.ensureLogin('查看消息通知')) {
return
}
this.setData({ loading: true })
try {
const messages = await userApi.listMyMessages()
const list = Array.isArray(messages) ? messages : []
this.setData({
/**
* Purpose: messages supports index.js by holding or executing the messages page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
messages: list,
/**
* Purpose: unreadCount supports index.js by holding or executing the unread count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unreadCount: list.filter(item => item.readStatus !== 1).length
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '消息加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
async handleOpenMessage(event) {
const id = event.currentTarget.dataset.id
const item = this.data.messages.find(message => String(message.id) === String(id))
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!item) {
return
}
const actionTarget = navigation.buildMessageActionPath(item)
if (actionTarget) {
try {
if (item.readStatus !== 1) {
await userApi.markMessageRead(item.id)
}
const opened = await navigation.openActionPath(actionTarget)
await this.loadMessages()
if (opened) {
return
}
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '打开消息失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
}
this.setData({
/**
* Purpose: currentMessage supports index.js by holding or executing the current message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentMessage: item,
/**
* Purpose: detailVisible supports index.js by holding or executing the detail visible page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
detailVisible: true
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (item.readStatus !== 1) {
try {
await userApi.markMessageRead(item.id)
await this.loadMessages()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '标记已读失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
},
/**
* `handleCloseDetail` 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.
*/
handleCloseDetail() {
this.setData({
/**
* Purpose: detailVisible supports index.js by holding or executing the detail visible page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
detailVisible: false,
/**
* Purpose: currentMessage supports index.js by holding or executing the current message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentMessage: null
})
},
/**
* `handlePreviewImage` 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.
*/
handlePreviewImage() {
const imageUrl = this.data.currentMessage && this.data.currentMessage.imageUrl
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!imageUrl) {
return
}
previewImagesSafely(imageUrl, [imageUrl])
},
/**
* Purpose: noop supports index.js by holding or executing the noop 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.
*/
noop() {},
/**
* `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.
*/
handleBack() {
navigation.goBack('/pages/profile/index')
}
})
@@ -0,0 +1,6 @@
{
"navigationStyle": "custom",
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,50 @@
<navigation-bar title="消息通知" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="notifications-page">
<view class="summary-card">
<view class="summary-title">消息通知</view>
<view class="summary-desc">{{unreadCount}} 条未读消息</view>
</view>
<view wx:if="{{messages.length}}" class="message-list">
<view
wx:for="{{messages}}"
wx:key="id"
class="message-item {{item.readStatus === 1 ? '' : 'unread'}}"
data-id="{{item.id}}"
bindtap="handleOpenMessage"
>
<view class="message-dot"></view>
<view class="message-copy">
<view class="message-title">{{item.title}}</view>
<view class="message-meta">{{item.publisherName || '系统消息'}} · {{item.publishTime || item.createTime}}</view>
<view wx:if="{{item.imageUrl}}" class="message-badge">含图片</view>
</view>
<view class="message-arrow">></view>
</view>
</view>
<view wx:else class="empty-card">
暂无消息
</view>
<view wx:if="{{detailVisible && currentMessage}}" class="detail-mask" bindtap="handleCloseDetail">
<view class="detail-panel" catchtap="noop">
<view class="detail-header">
<view>
<view class="detail-title">{{currentMessage.title}}</view>
<view class="detail-meta">{{currentMessage.publisherName || '系统消息'}} · {{currentMessage.publishTime || currentMessage.createTime}}</view>
</view>
<button class="detail-close" size="mini" bindtap="handleCloseDetail">关闭</button>
</view>
<view wx:if="{{currentMessage.content}}" class="detail-content">{{currentMessage.content}}</view>
<image
wx:if="{{currentMessage.imageUrl}}"
class="detail-image"
src="{{currentMessage.imageUrl}}"
mode="aspectFit"
bindtap="handlePreviewImage"
/>
</view>
</view>
</view>
@@ -0,0 +1,152 @@
.notifications-page {
min-height: 100vh;
padding: 176rpx 28rpx 40rpx;
background: var(--theme-page-bg);
box-sizing: border-box;
}
.summary-card,
.message-item,
.empty-card {
border-radius: 18rpx;
background: #ffffff;
box-shadow: 0 16rpx 40rpx rgba(150, 82, 105, 0.08);
}
.summary-card {
padding: 34rpx;
margin-bottom: 22rpx;
}
.summary-title {
color: var(--text-primary);
font-size: 38rpx;
font-weight: 800;
}
.summary-desc {
margin-top: 8rpx;
color: #927f88;
font-size: 26rpx;
}
.message-list {
display: flex;
flex-direction: column;
gap: 18rpx;
}
.message-item {
display: flex;
align-items: center;
gap: 18rpx;
padding: 28rpx;
}
.message-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background: #d7c9cf;
}
.message-item.unread .message-dot {
background: #ff5c8a;
}
.message-copy {
flex: 1;
min-width: 0;
}
.message-title {
color: var(--text-primary);
font-size: 30rpx;
font-weight: 700;
}
.message-meta {
margin-top: 8rpx;
color: #9b8d94;
font-size: 24rpx;
}
.message-badge {
display: inline-block;
margin-top: 10rpx;
padding: 4rpx 16rpx;
border-radius: 999rpx;
background: #fff0f4;
color: #d74270;
font-size: 22rpx;
}
.message-arrow {
color: #c3aab4;
}
.empty-card {
padding: 60rpx;
color: #9b8d94;
text-align: center;
}
.detail-mask {
position: fixed;
inset: 0;
z-index: 1000;
display: flex;
align-items: flex-end;
background: rgba(26, 18, 24, 0.45);
}
.detail-panel {
width: 100%;
max-height: 82vh;
padding: 34rpx 30rpx 46rpx;
border-radius: 28rpx 28rpx 0 0;
background: #fff;
box-sizing: border-box;
overflow-y: auto;
}
.detail-header {
display: flex;
gap: 20rpx;
align-items: flex-start;
justify-content: space-between;
}
.detail-title {
color: var(--text-primary);
font-size: 34rpx;
font-weight: 800;
}
.detail-meta {
margin-top: 8rpx;
color: #9b8d94;
font-size: 24rpx;
}
.detail-close {
margin: 0;
border-radius: 999rpx;
}
.detail-content {
margin-top: 28rpx;
color: #4b4048;
font-size: 28rpx;
line-height: 1.8;
white-space: pre-wrap;
}
.detail-image {
width: 100%;
min-height: 320rpx;
max-height: 760rpx;
margin-top: 24rpx;
border-radius: 18rpx;
background: var(--theme-page-bg);
}
@@ -0,0 +1,151 @@
const orderApi = require('../../api/order')
const afterSaleApi = require('../../api/after-sale')
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { resolveLegacyImage } = require('../../utils/file')
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
const { runWithLoading } = require('../../utils/loading')
function safeList(value) {
return Array.isArray(value) ? value : []
}
function sameId(left, right) {
return left !== undefined && left !== null && right !== undefined && right !== null && String(left) === String(right)
}
function formatMoney(value) {
return `¥${formatPrice(value)}`
}
function buildTimeline(order, reviews, changes, afterSales) {
const items = safeList(order && order.items)
const firstAppointment = items.map(item => item && item.appointmentTime).find(Boolean)
const status = Number(order && order.status)
return [
{ key: 'created', title: '已创建', text: formatDateTime(order && order.createTime) || '已提交', done: true, active: false },
{ key: 'appointment', title: '预约时间', text: formatDateTime(firstAppointment) || '待确认', done: Boolean(firstAppointment), active: status === 1 },
{ key: 'service', title: status === 3 ? '已取消' : '服务完成', text: formatDateTime(order && (order.completeTime || order.cancelTime || order.updateTime)) || '等待服务', done: status === 2 || status === 3, active: status === 2 || status === 3 },
{ key: 'change', title: '改派记录', text: changes.length ? `${changes.length} 条记录` : '暂无改派', done: changes.length > 0, active: changes.some(item => String(item.status || '').toUpperCase() === 'PENDING') },
{ key: 'after-sale', title: '售后/评价', text: afterSales.length ? `${afterSales.length} 条售后` : (reviews.length ? `${reviews.length} 条评价` : '暂无记录'), done: afterSales.length > 0 || reviews.length > 0, active: afterSales.some(item => String(item.status || '').toUpperCase() === 'PENDING') }
]
}
async function formatOrder(order, reviews, changes, afterSales) {
const items = await Promise.all(safeList(order && order.items).map(async item => ({
...item,
productImageUrl: await resolveLegacyImage(item.productImage),
priceText: formatMoney(item.price),
appointmentText: formatDateTime(item.appointmentTime)
})))
return {
...order,
items,
statusText: getOrderStatusText(order),
statusClass: getOrderStatusClass(order),
amountText: formatMoney(order && (order.actualAmount || order.totalAmount)),
canApplyAfterSale: Number(order && order.status) === 2 || String(order && order.paymentStatus || '').toUpperCase() === 'PAID',
timeline: buildTimeline(order, reviews, changes, afterSales)
}
}
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
id: '',
loading: false,
order: null,
reviews: [],
changes: [],
afterSales: [],
contact: null,
isLoggedIn: false
}),
onLoad(options) {
this.setData({
id: (options && (options.id || options.orderId)) || ''
})
},
onShow() {
this.loadOrder()
},
handleBack() {
navigation.goBack('/pages/orders/index')
},
async loadOrder() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
if (!this.data.id) {
return
}
this.setData({ loading: true })
try {
const [order, reviews, changes, afterSalePage, contact] = await Promise.all([
orderApi.getOrderDetail(this.data.id),
orderApi.listOrderReviews(this.data.id).catch(() => []),
orderApi.listOrderArtistChangeRequests(this.data.id).catch(() => []),
afterSaleApi.getMyAfterSales({ page: 1, size: 50 }).catch(() => ({ list: [] })),
userApi.getOrderArtistContact(this.data.id).catch(() => null)
])
const afterSales = safeList(afterSalePage && afterSalePage.list).filter(item => sameId(item.orderId, this.data.id))
this.setData({
order: await formatOrder(order, reviews || [], changes || [], afterSales),
reviews: reviews || [],
changes: changes || [],
afterSales,
contact
})
} catch (error) {
wx.showToast({
title: error.message || '订单详情加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
openProgress() {
navigation.navigate('/pages/service-progress/index', { orderId: this.data.id })
},
openAfterSaleApply(event) {
const orderItemId = event.currentTarget.dataset.itemId || ''
navigation.navigate('/pages/after-sale-apply/index', {
orderId: this.data.id,
orderItemId
})
},
openAfterSales() {
navigation.navigate('/pages/after-sales/index', { orderId: this.data.id })
},
async handleCancelOrder() {
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '取消订单',
content: '确认取消这笔订单吗?',
success: res => resolve(Boolean(res.confirm))
})
})
if (!confirmed) return
try {
await runWithLoading(() => orderApi.cancelOrder(this.data.id))
wx.showToast({ title: '订单已取消', icon: 'none' })
await this.loadOrder()
} catch (error) {
wx.showToast({ title: error.message || '取消订单失败', icon: 'none' })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,71 @@
<navigation-bar title="订单详情" showBack="{{true}}" fallbackPath="/pages/orders/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell detail-page" style="{{themeVars}}">
<view class="page-content">
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
<text class="empty-title">登录后查看订�?/text>
<text class="empty-desc">订单详情霢�要先登录�?/text>
</view>
<view wx:elif="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载订单</text>
</view>
<block wx:elif="{{order}}">
<view class="page-hero">
<text class="hero-kicker">预约订单</text>
<text class="hero-title">{{order.orderNo}}</text>
<text class="hero-desc">{{order.shopName || '当前门店'}} · {{order.statusText}}</text>
<view class="summary-strip">
<view class="summary-metric">
<text class="summary-label">订单金额</text>
<text class="summary-value">{{order.amountText}}</text>
</view>
<view class="summary-metric">
<text class="summary-label">项目�?/text>
<text class="summary-value">{{order.items.length}}</text>
</view>
</view>
</view>
<view class="page-card timeline-card">
<view wx:for="{{order.timeline}}" wx:key="key" class="timeline-node {{item.done ? 'done' : ''}} {{item.active ? 'active' : ''}}">
<text class="timeline-title">{{item.title}}</text>
<text class="timeline-text">{{item.text}}</text>
</view>
</view>
<view class="page-card detail-card">
<view wx:for="{{order.items}}" wx:key="id" class="item-row">
<image class="item-thumb" src="{{item.productImageUrl}}" mode="aspectFill"></image>
<view class="item-main">
<text class="item-title">{{item.productTitle}}</text>
<text class="item-line">{{item.priceText}} x {{item.quantity}}</text>
<text wx:if="{{item.artistName}}" class="item-line">美甲师:{{item.artistName}}</text>
<text wx:if="{{item.appointmentText}}" class="item-line">预约:{{item.appointmentText}}</text>
<view wx:if="{{order.canApplyAfterSale}}" class="soft-chip" data-item-id="{{item.id}}" bindtap="openAfterSaleApply">申请售后</view>
</view>
</view>
</view>
<view wx:if="{{contact}}" class="page-card contact-card">
<text class="section-title">联系信息</text>
<text class="contact-line">{{contact.contactName || contact.roleLabel || '服务联系�?}}</text>
<text wx:if="{{contact.phoneAvailable && contact.phone}}" class="contact-line">电话:{{contact.phone}}</text>
<text wx:if="{{contact.wechatAvailable && contact.wechatId}}" class="contact-line">微信:{{contact.wechatId}}</text>
<text wx:if="{{contact.platformContactText}}" class="contact-line">{{contact.platformContactText}}</text>
</view>
<view class="action-row">
<view class="secondary-btn" bindtap="openProgress">服务进度</view>
<view class="secondary-btn" bindtap="openAfterSales">售后记录</view>
<view wx:if="{{order.status == 1}}" class="secondary-btn danger" bindtap="handleCancelOrder">取消订单</view>
</view>
</block>
<view wx:else class="page-card empty-card">
<text class="empty-title">未找到订�?/text>
<text class="empty-desc">请从订单中心重新进入�?/text>
</view>
</view>
</view>
@@ -0,0 +1,103 @@
.timeline-card,
.detail-card,
.contact-card {
margin-top: 22rpx;
padding: 24rpx;
}
.timeline-card {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 8rpx;
}
.timeline-node {
min-width: 0;
padding: 12rpx 8rpx;
border-radius: 14rpx;
background: var(--theme-primary-soft);
color: #504444;
}
.timeline-node.done,
.timeline-node.active {
color: var(--theme-primary);
}
.timeline-title,
.timeline-text,
.contact-line {
display: block;
}
.timeline-title,
.timeline-text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.timeline-title {
font-size: 21rpx;
font-weight: 800;
}
.timeline-text {
margin-top: 6rpx;
font-size: 20rpx;
}
.item-row {
display: flex;
gap: 18rpx;
padding: 20rpx 0;
border-top: 2rpx solid var(--theme-border);
}
.item-row:first-child {
padding-top: 0;
border-top: 0;
}
.item-thumb {
width: 132rpx;
height: 132rpx;
border-radius: 24rpx;
background: var(--theme-primary-soft);
}
.item-main {
flex: 1;
min-width: 0;
}
.item-title {
display: block;
color: var(--text-primary);
font-size: 29rpx;
font-weight: 800;
line-height: 1.45;
}
.item-line,
.contact-line {
display: block;
margin-top: 10rpx;
color: #504444;
font-size: 24rpx;
line-height: 1.6;
}
.soft-chip {
margin-top: 16rpx;
}
.action-row {
display: grid;
gap: 16rpx;
margin-top: 24rpx;
}
.secondary-btn.danger {
color: var(--theme-accent);
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+159
View File
@@ -0,0 +1,159 @@
<navigation-bar title="我的订单" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell orders-page" style="{{themeVars}}">
<view class="page-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="{{orders.length}}">
<view class="page-hero orders-hero">
<text class="hero-kicker">预约记录</text>
<text class="hero-title">共 {{orders.length}} 笔订单</text>
<text class="hero-desc">查看订单状态和预约时间。</text>
</view>
<view wx:for="{{orders}}" wx:key="id" class="page-card order-card {{item.focusTarget ? 'focus-target' : ''}}">
<view class="order-head">
<view class="order-head-copy">
<text class="order-label">订单号</text>
<text class="order-no">{{item.orderNo}}</text>
</view>
<text class="order-status {{item.statusClass}}">{{item.statusText}}</text>
</view>
<view wx:if="{{item.shopNameText}}" class="order-shop">{{item.shopNameText}}</view>
<view class="payment-panel">
<view class="payment-copy">
<text class="assist-label">支付状态</text>
<text class="assist-main">{{item.paymentInfo.statusText}}</text>
<text wx:if="{{item.paymentInfo.payNoText}}" class="assist-desc">支付单:{{item.paymentInfo.payNoText}}</text>
</view>
<view class="payment-amount">
<text>{{item.paymentInfo.amountText}}</text>
<text wx:if="{{item.paymentInfo.isPaid}}">实付 {{item.paymentInfo.paidAmountText}}</text>
</view>
</view>
<view wx:if="{{item.afterSaleSummary}}" class="after-sale-summary">
<text class="assist-label">售后进度</text>
<text class="assist-main">{{item.afterSaleSummary.typeText}} · {{item.afterSaleSummary.statusText}}</text>
<text wx:if="{{item.afterSaleSummary.amountText}}" class="assist-desc">申请金额:{{item.afterSaleSummary.amountText}}</text>
<text wx:if="{{item.afterSaleSummary.reasonText}}" class="assist-desc">原因:{{item.afterSaleSummary.reasonText}}</text>
<text wx:if="{{item.afterSaleSummary.auditReasonText}}" class="assist-desc">处理说明:{{item.afterSaleSummary.auditReasonText}}</text>
</view>
<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>
<view class="order-line">{{orderItem.priceText}} x {{orderItem.quantity}}</view>
<view wx:if="{{orderItem.artistName}}" class="order-line">美甲师:{{orderItem.artistName}}</view>
<view wx:if="{{orderItem.appointmentText}}" class="order-line">预约时间:{{orderItem.appointmentText}}</view>
<view wx:if="{{orderItem.reviewSummary}}" class="review-summary">
<text class="assist-label">评价状态</text>
<text class="assist-main">{{orderItem.reviewSummary.displayText}}</text>
<text wx:if="{{orderItem.reviewSummary.contentText}}" class="assist-desc">{{orderItem.reviewSummary.contentText}}</text>
</view>
<view wx:elif="{{orderItem.pendingReview}}" class="review-panel">
<view class="review-panel-head">
<text class="assist-label">评价美甲师</text>
<text class="assist-desc">评分必填,文字可选</text>
</view>
<view class="score-row">
<view
wx:for="{{reviewScoreOptions}}"
wx:key="*this"
wx:for-item="score"
class="score-chip {{orderItem.reviewDraft.rating == score ? 'active' : ''}}"
data-review-id="{{orderItem.pendingReview.id}}"
data-score="{{score}}"
bindtap="handleSelectReviewScore"
>{{score}}</view>
</view>
<textarea
class="review-textarea"
maxlength="200"
placeholder="写下这次服务体验,可不填"
placeholder-class="textarea-placeholder"
value="{{orderItem.reviewDraft.content}}"
data-review-id="{{orderItem.pendingReview.id}}"
bindinput="handleReviewContentInput"
></textarea>
<view class="review-submit-btn" data-review-id="{{orderItem.pendingReview.id}}" bindtap="handleSubmitReview">提交评价</view>
</view>
<view wx:if="{{orderItem.pendingArtistChangeRequest}}" class="change-panel">
<text class="assist-label">待确认改派</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}}" 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>
</view>
<view class="order-foot">
<text class="order-amount">总计:{{item.actualAmountText}}</text>
<view class="order-actions">
<view wx:if="{{item.paymentInfo.canPay}}" class="pay-btn" data-order-id="{{item.id}}" bindtap="handlePayOrder">去支付</view>
<view wx:if="{{item.canApplyAfterSale}}" class="after-sale-btn" data-order-id="{{item.id}}" bindtap="handleApplyAfterSale">申请售后</view>
<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>
<view wx:elif="{{loading}}" class="page-card empty-card">
<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>
</view>
</view>
</view>
+447
View File
@@ -0,0 +1,447 @@
.orders-hero {
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: var(--text-primary);
}
.recovery-desc {
font-size: 24rpx;
line-height: 1.6;
color: var(--text-secondary);
}
.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: var(--theme-card-bg);
border: 2rpx solid var(--theme-border);
color: var(--theme-primary-action);
font-size: 24rpx;
font-weight: 700;
}
.recovery-btn.primary {
background: var(--theme-primary);
border-color: var(--theme-primary);
color: var(--theme-neutral);
}
.order-card + .order-card {
margin-top: 20rpx;
}
.order-card {
padding: 26rpx;
}
.order-card.focus-target {
border-color: var(--theme-primary);
box-shadow: 0 18rpx 48rpx rgba(197, 160, 89, 0.18);
}
.order-head,
.order-foot {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18rpx;
}
.order-head {
padding-bottom: 18rpx;
border-bottom: 2rpx solid var(--theme-border);
}
.order-shop {
margin: 14rpx 0 0;
color: var(--text-secondary);
font-size: 24rpx;
line-height: 1.5;
}
.payment-panel {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
margin-top: 18rpx;
padding: 18rpx 20rpx;
border-radius: 18rpx;
background: var(--theme-primary-soft);
}
.payment-copy {
flex: 1;
min-width: 0;
}
.payment-amount {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 6rpx;
color: var(--text-primary);
font-size: 26rpx;
font-weight: 800;
}
.payment-amount text:last-child {
color: var(--text-secondary);
font-size: 22rpx;
font-weight: 600;
}
.after-sale-summary {
margin-top: 16rpx;
padding: 18rpx 20rpx;
border-radius: 18rpx;
background: var(--theme-secondary-soft);
border: 2rpx solid var(--theme-border);
}
.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: var(--text-secondary);
}
.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: var(--text-primary);
}
.timeline-text,
.timeline-sub {
margin-top: 4rpx;
font-size: 20rpx;
}
.order-head-copy {
flex: 1;
min-width: 0;
}
.order-label {
display: block;
font-size: 22rpx;
color: var(--text-secondary);
}
.order-no {
display: block;
margin-top: 10rpx;
font-size: 24rpx;
line-height: 1.6;
color: var(--theme-primary-action);
}
.order-status {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 120rpx;
height: 48rpx;
padding: 0 16rpx;
border-radius: 999rpx;
font-size: 22rpx;
font-weight: 700;
}
.order-status.pending {
background: var(--theme-primary-soft);
color: var(--theme-tertiary);
}
.order-status.completed {
background: var(--theme-primary-soft);
color: var(--theme-primary);
}
.order-status.cancelled {
background: var(--theme-primary-soft);
color: var(--theme-tertiary);
}
.order-item {
display: flex;
gap: 18rpx;
margin-top: 22rpx;
}
.order-item.focus-target {
padding: 12rpx;
border-radius: 18rpx;
background: var(--theme-primary-soft);
outline: 2rpx solid var(--theme-primary);
}
.order-thumb {
width: 132rpx;
height: 132rpx;
border-radius: 20rpx;
background: var(--theme-primary-soft);
}
.order-main {
flex: 1;
min-width: 0;
}
.order-title {
font-size: 28rpx;
font-weight: 700;
color: var(--text-primary);
line-height: 1.5;
}
.order-line {
margin-top: 10rpx;
font-size: 24rpx;
color: var(--text-secondary);
line-height: 1.6;
}
.order-foot {
margin-top: 24rpx;
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: var(--text-primary);
}
.pay-btn,
.after-sale-btn,
.cancel-btn,
.rebook-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 144rpx;
height: 60rpx;
padding: 0 18rpx;
border-radius: 999rpx;
font-size: 24rpx;
font-weight: 700;
}
.pay-btn {
background: var(--theme-primary);
color: var(--theme-neutral);
}
.after-sale-btn {
background: var(--theme-card-bg);
border: 2rpx solid var(--theme-border);
color: var(--theme-primary-action);
}
.rebook-btn {
background: var(--theme-primary);
color: var(--theme-neutral);
}
.cancel-btn {
background: var(--theme-primary-soft);
color: var(--theme-tertiary);
}
.review-summary,
.review-panel,
.change-panel {
margin-top: 18rpx;
padding: 20rpx;
border-radius: 18rpx;
background: var(--theme-secondary-soft);
border: 2rpx solid var(--theme-border);
}
.review-panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.assist-label,
.assist-main,
.assist-desc {
display: block;
}
.assist-label {
font-size: 22rpx;
color: var(--text-secondary);
line-height: 1.5;
}
.assist-main {
margin-top: 8rpx;
font-size: 26rpx;
font-weight: 700;
color: var(--text-primary);
line-height: 1.5;
}
.assist-desc {
margin-top: 8rpx;
font-size: 24rpx;
color: var(--text-secondary);
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;
gap: 12rpx;
margin-top: 16rpx;
}
.score-chip {
display: inline-flex;
align-items: center;
justify-content: center;
width: 72rpx;
height: 52rpx;
border-radius: 999rpx;
background: var(--theme-card-bg);
border: 2rpx solid var(--theme-border);
color: var(--theme-primary-action);
font-size: 24rpx;
font-weight: 700;
}
.score-chip.active {
background: var(--theme-primary);
border-color: var(--theme-primary);
color: var(--theme-neutral);
}
.review-textarea {
width: 100%;
min-height: 136rpx;
box-sizing: border-box;
margin-top: 16rpx;
padding: 16rpx;
border-radius: 16rpx;
background: var(--theme-card-bg);
border: 2rpx solid var(--theme-border);
color: var(--text-primary);
font-size: 24rpx;
line-height: 1.6;
}
.textarea-placeholder {
color: var(--text-secondary);
}
.review-submit-btn,
.change-btn {
display: inline-flex;
align-items: center;
justify-content: center;
height: 58rpx;
padding: 0 22rpx;
border-radius: 999rpx;
font-size: 24rpx;
font-weight: 700;
}
.review-submit-btn {
margin-top: 16rpx;
background: var(--theme-primary);
color: var(--theme-neutral);
}
.change-actions {
display: flex;
flex-wrap: wrap;
gap: 14rpx;
margin-top: 16rpx;
}
.change-btn {
background: var(--theme-card-bg);
border: 2rpx solid var(--theme-border);
color: var(--theme-primary-action);
}
.change-btn.primary {
background: var(--theme-primary);
border-color: var(--theme-primary);
color: var(--theme-neutral);
}
@@ -0,0 +1,104 @@
const userApi = require('../../api/user')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { runWithLoading } = require('../../utils/loading')
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
saving: false,
isLoggedIn: false,
userInfo: null,
form: {
verificationCode: '',
password: '',
confirmPassword: ''
}
}),
onShow() {
this.loadProfile()
},
handleBack() {
navigation.goBack('/pages/settings/index')
},
async loadProfile() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
this.setData({ loading: true })
try {
this.setData({
userInfo: await userApi.getUserInfo()
})
} catch (error) {
wx.showToast({ title: error.message || '账号信息加载失败', icon: 'none' })
} finally {
this.setData({ loading: false })
}
},
handleInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`form.${field}`]: event.detail.value
})
},
async sendCode() {
const phone = String(this.data.userInfo && this.data.userInfo.phone || '').trim()
if (!phone) {
wx.showToast({ title: '请先绑定手机号', icon: 'none' })
return
}
try {
await runWithLoading(() => userApi.sendVerificationCode({
phone,
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
}))
wx.showToast({ title: '验证码已发送', icon: 'none' })
} catch (error) {
wx.showToast({ title: error.message || '验证码发送失败', icon: 'none' })
}
},
async savePassword() {
const verificationCode = String(this.data.form.verificationCode || '').trim()
const password = String(this.data.form.password || '')
const confirmPassword = String(this.data.form.confirmPassword || '')
if (!verificationCode) {
wx.showToast({ title: '请输入验证码', icon: 'none' })
return
}
if (!passwordRegex.test(password)) {
wx.showToast({ title: '密码至少8位且包含字母和数字', icon: 'none' })
return
}
if (password !== confirmPassword) {
wx.showToast({ title: '两次密码不一致', icon: 'none' })
return
}
this.setData({ saving: true })
try {
await runWithLoading(() => userApi.updatePassword({
password,
verificationCode
}))
auth.setNeedSetPassword(false)
wx.showToast({ title: '密码已更新', icon: 'none' })
navigation.goBack('/pages/settings/index')
} catch (error) {
wx.showToast({ title: error.message || '密码更新失败', icon: 'none' })
} finally {
this.setData({ saving: false })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,30 @@
<navigation-bar title="修改密码" showBack="{{true}}" fallbackPath="/pages/settings/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">Security</text>
<text class="hero-title">修改密码</text>
<text class="hero-desc">使用绑定手机号验证码完成密码更新�?/text>
</view>
<view class="page-card form-card">
<view class="field-block">
<text class="field-label">验证�?/text>
<view class="code-row">
<input class="field-input" value="{{form.verificationCode}}" data-field="verificationCode" bindinput="handleInput" placeholder="请输入验证码" placeholder-class="field-placeholder" />
<view class="ghost-btn" bindtap="sendCode">发��?/view>
</view>
</view>
<view class="field-block">
<text class="field-label">新密�?/text>
<input class="field-input" password value="{{form.password}}" data-field="password" bindinput="handleInput" placeholder="至少8位,含字母和数字" placeholder-class="field-placeholder" />
</view>
<view class="field-block">
<text class="field-label">确认密码</text>
<input class="field-input" password value="{{form.confirmPassword}}" data-field="confirmPassword" bindinput="handleInput" placeholder="再次输入新密�? placeholder-class="field-placeholder" />
</view>
<button class="primary-btn" loading="{{saving}}" bindtap="savePassword">更新密码</button>
</view>
</view>
</view>
@@ -0,0 +1,22 @@
.form-card {
margin-top: 22rpx;
padding: 28rpx;
}
.field-block + .field-block {
margin-top: 24rpx;
}
.code-row {
display: flex;
align-items: center;
gap: 16rpx;
}
.code-row .field-input {
flex: 1;
}
.primary-btn {
margin-top: 28rpx;
}
@@ -0,0 +1,565 @@
/**
* Purpose: cartApi supports index.js by holding or executing the cart api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const cartApi = require('../../api/cart')
/**
* Purpose: productApi supports index.js by holding or executing the product 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 productApi = require('../../api/product')
/**
* Purpose: productLikeApi supports index.js by holding or executing the product like 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 productLikeApi = require('../../api/product-like')
/**
* Purpose: commentApi supports index.js by holding or executing the comment 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 commentApi = require('../../api/comment')
/**
* Purpose: shopApi supports index.js by holding or executing the shop 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 shopApi = require('../../api/shop')
/**
* Purpose: wishlistApi supports index.js by holding or executing the wishlist 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 wishlistApi = require('../../api/wishlist')
/**
* Purpose: actionGuard supports index.js by holding or executing the action guard 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 actionGuard = require('../../utils/action-guard')
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../utils/file')
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.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function parseTimeRange(businessHours) {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!businessHours) {
return null
}
const matched = String(businessHours).replace(/\s+/g, '').match(/(\d{1,2}:\d{2}).*?(\d{1,2}:\d{2})/)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!matched) {
return null
}
return {
start: matched[1],
end: matched[2]
}
}
/**
* Purpose: estimateEarliestBookable supports index.js by holding or executing the estimate earliest bookable 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 estimateEarliestBookable(businessHours) {
const range = parseTimeRange(businessHours)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!range) {
return businessHours || '以门店安排为准'
}
const next = new Date(Date.now() + 30 * 60 * 1000)
const openTime = new Date(next)
const closeTime = new Date(next)
const startParts = range.start.split(':').map(Number)
const endParts = range.end.split(':').map(Number)
openTime.setHours(startParts[0], startParts[1], 0, 0)
closeTime.setHours(endParts[0], endParts[1], 0, 0)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (next <= openTime) {
return `今天 ${range.start}`
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (next >= closeTime) {
return `明天 ${range.start}`
}
const month = String(next.getMonth() + 1).padStart(2, '0')
const date = String(next.getDate()).padStart(2, '0')
const hour = String(next.getHours()).padStart(2, '0')
const minute = String(next.getMinutes()).padStart(2, '0')
return `${month}-${date} ${hour}:${minute}`
}
/**
* product-detail page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: true,
loadError: '',
productId: '',
product: null,
productImages: [],
shopInfo: null,
comments: [],
commentText: '',
replyTarget: null,
isFavorite: false,
isLiked: false,
artistCountText: '门店安排',
earliestBookableText: '以门店安排为准'
}),
/**
* `onLoad` 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.
*/
onLoad(options) {
this.setData({
productId: options && options.id ? options.id : ''
})
this.loadProductDetail()
},
async onPullDownRefresh() {
await this.loadProductDetail()
wx.stopPullDownRefresh()
},
async loadProductDetail() {
const productId = this.data.productId
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!productId) {
this.setData({
loading: false,
loadError: '作品 ID 不存在'
})
return
}
this.setData({
loading: true,
loadError: ''
})
try {
const product = await productApi.getProductById(productId)
const productImages = await resolveImageList(product.imageFileIds, DEFAULT_PRODUCT_IMAGE)
const shopInfo = product.shopId ? await shopApi.getShopById(product.shopId) : null
if (shopInfo) {
const shopTheme = theme.resolveShopTheme(shopInfo)
this.setData(theme.pageThemeData(shopTheme))
if (shopTheme.backgroundImageFileId) {
try {
const backgroundImageUrl = await getSignedUrl(shopTheme.backgroundImageFileId)
if (backgroundImageUrl) {
this.setData(theme.pageThemeData(shopTheme, backgroundImageUrl))
}
} catch (error) {}
}
}
const artistCount = typeof product.availableBookableArtistCount === 'number'
? product.availableBookableArtistCount
: splitCsv(product.bookableArtists).length
const formattedProduct = {
...product,
displayTitle: getProductTitle(product),
priceText: `¥${formatPrice(product.price)}`,
descriptionText: product.description || '商家还没有补充作品说明。',
targetAudienceText: product.targetAudience || '',
precautionsText: product.precautions || ''
}
this.setData({
product: formattedProduct,
productImages,
shopInfo,
artistCountText: artistCount > 0 ? `${artistCount} 位可预约` : (product.bookableArtistRestricted ? '暂时没有' : '门店安排'),
earliestBookableText: estimateEarliestBookable(shopInfo && shopInfo.businessHours)
})
await this.loadComments()
if (auth.isLoggedIn()) {
await this.loadInteractionStatus()
} else {
this.setData({
isFavorite: false,
isLiked: false
})
}
} catch (error) {
this.setData({
loadError: error.message || '作品详情加载失败'
})
} finally {
this.setData({
loading: false
})
}
},
async loadInteractionStatus() {
const product = this.data.product
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!product || !product.id) {
return
}
try {
const [isFavorite, isLiked] = await Promise.all([
wishlistApi.checkWishlist(product.id),
productLikeApi.checkLikeStatus(product.id)
])
this.setData({
isFavorite: Boolean(isFavorite),
isLiked: Boolean(isLiked)
})
} catch (error) {}
},
async loadComments() {
const product = this.data.product
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!product || !product.id) {
this.setData({ comments: [] })
return
}
try {
const comments = await commentApi.listByProduct(product.id)
this.setData({
comments: Array.isArray(comments) ? comments : []
})
} catch (error) {
this.setData({ comments: [] })
}
},
/**
* `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.
*/
handleBack() {
navigation.goBack('/pages/products/index')
},
/**
* `handlePreviewImage` 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.
*/
handlePreviewImage(event) {
const current = event.currentTarget.dataset.url
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!current) {
return
}
previewImagesSafely(current, this.data.productImages, {
failMessage: '图片可能已过期,请重试;仍失败时可以返回作品列表重新进入。',
emptyMessage: '这件作品暂时没有可预览图片,可以返回作品列表查看其他款式。'
})
},
/**
* Purpose: onShareAppMessage exposes the product detail as a native mini-program share target.
* Usage: WeChat calls it from the share menu; keep title and path aligned with the current product id.
*/
onShareAppMessage() {
const product = this.data.product || {}
return {
title: product.displayTitle || 'Fingertip Designer 美甲款式',
path: `/pages/product-detail/index?id=${product.id || this.data.productId}`,
imageUrl: this.data.productImages[0] || DEFAULT_PRODUCT_IMAGE
}
},
/**
* Purpose: handleCopyShareLink copies a mini-program route for users who cannot invoke native share.
* Usage: bind it to the visible share action in the product info card.
*/
handleCopyShareLink() {
const product = this.data.product || {}
const path = `/pages/product-detail/index?id=${product.id || this.data.productId}`
wx.setClipboardData({
data: path,
success: () => {
wx.showToast({
title: '分享路径已复制',
icon: 'none'
})
}
})
},
/**
* `handleOpenShop` 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.
*/
handleOpenShop() {
const shopInfo = this.data.shopInfo
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopInfo || !shopInfo.id) {
return
}
navigation.navigate('/pages/shop-detail/index', {
id: shopInfo.id,
returnTo: navigation.getCurrentPageUrl()
})
},
async handleToggleFavorite() {
const product = this.data.product
if (!product || !product.id || !navigation.ensureLogin('收藏作品')) {
return
}
try {
await actionGuard.run(this, `wishlist:toggle:${product.id}`, async () => {
const nextFavorite = !this.data.isFavorite
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.isFavorite) {
await runWithLoading(() => wishlistApi.removeFromWishlist(product.id))
product.collectCount = Math.max(0, Number(product.collectCount || 0) - 1)
} else {
await runWithLoading(() => wishlistApi.addToWishlist(product.id))
product.collectCount = Number(product.collectCount || 0) + 1
}
this.setData({
isFavorite: nextFavorite,
product
})
wx.showToast({
title: nextFavorite ? '已加入收藏' : '已取消收藏',
icon: 'none'
})
}, {
message: '操作进行中,请勿重复点击'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '收藏操作失败',
icon: 'none'
})
}
},
async handleToggleLike() {
const product = this.data.product
if (!product || !product.id || !navigation.ensureLogin('点赞作品')) {
return
}
try {
await actionGuard.run(this, `like:toggle:${product.id}`, async () => {
const nextLiked = !this.data.isLiked
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.isLiked) {
await runWithLoading(() => productLikeApi.unlikeProduct(product.id))
product.likeCount = Math.max(0, Number(product.likeCount || 0) - 1)
} else {
await runWithLoading(() => productLikeApi.likeProduct(product.id))
product.likeCount = Number(product.likeCount || 0) + 1
}
this.setData({
isLiked: nextLiked,
product
})
wx.showToast({
title: nextLiked ? '已点赞' : '已取消点赞',
icon: 'none'
})
}, {
message: '操作进行中,请勿重复点击'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '点赞操作失败',
icon: 'none'
})
}
},
async handleAddToCart() {
const product = this.data.product
if (!product || !product.id || !navigation.ensureLogin('加购')) {
return
}
try {
await actionGuard.run(this, `cart:add:${product.id}`, () => runWithLoading(() => cartApi.addToCart({
productId: product.id,
quantity: 1
})), {
message: '购物车处理中,请勿重复操作'
})
await getApp().updateCartBadge()
wx.showToast({
title: '已加入购物车',
icon: 'none'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '加入购物车失败',
icon: 'none'
})
}
},
async handleBuyNow() {
const product = this.data.product
if (!product || !product.id || !navigation.ensureLogin('预约下单')) {
return
}
try {
await actionGuard.run(this, `cart:buy-now:${product.id}`, () => runWithLoading(() => cartApi.addToCart({
productId: product.id,
quantity: 1
})), {
message: '操作进行中,请勿重复点击'
})
await getApp().updateCartBadge()
saveBuyNowContext(product.id)
wx.switchTab({
url: '/pages/cart/index'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '操作失败',
icon: 'none'
})
}
}
,
/**
* `handleCommentInput` 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.
*/
handleCommentInput(event) {
this.setData({
commentText: event.detail.value
})
},
/**
* `handleReply` 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.
*/
handleReply(event) {
const comment = event.currentTarget.dataset.comment
this.setData({
replyTarget: comment || null
})
},
async handleSubmitComment() {
const product = this.data.product
const content = String(this.data.commentText || '').trim()
if (!product || !product.id || !navigation.ensureLogin('发表评论')) {
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!content) {
wx.showToast({ title: '请输入评论内容', icon: 'none' })
return
}
try {
await commentApi.create({
productId: product.id,
shopId: product.shopId,
parentCommentId: this.data.replyTarget ? this.data.replyTarget.id : null,
commentContent: content
})
this.setData({
commentText: '',
replyTarget: null
})
await this.loadComments()
wx.showToast({ title: '评论已发布', icon: 'none' })
} catch (error) {
wx.showToast({ title: error.message || '评论发布失败', icon: 'none' })
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,129 @@
<navigation-bar title="{{product ? product.displayTitle : '作品详情'}}" showBack="{{true}}" fallbackPath="/pages/products/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell detail-page" style="{{themeVars}}">
<view wx:if="{{loadError}}" class="page-content">
<view class="page-card empty-card">
<text class="empty-title">暂时无法查看作品详情</text>
<text class="empty-desc">{{loadError}}</text>
<view class="ghost-btn" bindtap="handleBack">返回上一页</view>
</view>
</view>
<block wx:elif="{{product}}">
<view class="media-box">
<swiper class="media-swiper" indicator-dots autoplay circular>
<swiper-item wx:for="{{productImages}}" wx:key="*this">
<image class="media-image" src="{{item}}" mode="aspectFill" data-url="{{item}}" bindtap="handlePreviewImage" lazy-load="{{true}}"></image>
</swiper-item>
</swiper>
<view class="media-mask">
<view class="media-badges">
<view class="chip">{{product.approximateDuration || '时长待确认'}}</view>
<view class="soft-chip">{{artistCountText}}</view>
</view>
</view>
</view>
<view class="page-content detail-content">
<view class="page-card info-card">
<view class="detail-head">
<text class="section-kicker">作品详情</text>
<view class="product-title">{{product.displayTitle}}</view>
<view class="product-price">{{product.priceText}}</view>
<view class="product-brief">查看作品、门店和可预约信息。</view>
</view>
<view class="summary-strip detail-summary">
<view class="summary-metric" bindtap="handleOpenShop">
<text class="summary-label">所属门店</text>
<text class="summary-value detail-summary-value">{{shopInfo ? shopInfo.shopName : '待绑定'}}</text>
<text class="summary-note">查看门店</text>
</view>
<view class="summary-metric">
<text class="summary-label">可约美甲师</text>
<text class="summary-value detail-summary-value">{{artistCountText}}</text>
<text class="summary-note">可继续选择</text>
</view>
<view class="summary-metric">
<text class="summary-label">最早可约</text>
<text class="summary-value detail-summary-value">{{earliestBookableText}}</text>
<text class="summary-note">以营业时间为准</text>
</view>
</view>
<view wx:if="{{shopInfo}}" class="shop-box" bindtap="handleOpenShop">
<view class="shop-box-head">
<view class="shop-name">{{shopInfo.shopName}}</view>
<view class="shop-link">查看门店</view>
</view>
<view class="shop-meta">{{shopInfo.address || '门店地址待补充'}}</view>
<view class="shop-meta">{{shopInfo.businessHours || '营业时间待补充'}}</view>
</view>
<view class="actions-row">
<view class="action-pill {{isLiked ? 'active' : ''}}" bindtap="handleToggleLike">
点赞 {{product.likeCount || 0}}
</view>
<view class="action-pill {{isFavorite ? 'active' : ''}}" bindtap="handleToggleFavorite">
收藏 {{product.collectCount || 0}}
</view>
<button class="action-pill share-pill" open-type="share">分享</button>
<view class="action-pill" bindtap="handleCopyShareLink">复制路径</view>
</view>
<view wx:if="{{product.tagInfos && product.tagInfos.length}}" class="tags-wrap">
<view wx:for="{{product.tagInfos}}" wx:key="id" class="tag-chip">{{item.tagName}}</view>
</view>
<view class="desc-block">
<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">
<view class="comment-head">
<view class="section-title">作品评论</view>
<text class="comment-count">{{comments.length}} 条</text>
</view>
<view class="comment-editor">
<textarea class="comment-input" maxlength="300" auto-height placeholder="{{replyTarget ? '回复 ' + (replyTarget.userNickname || '用户') : '说说你的看法'}}" value="{{commentText}}" bindinput="handleCommentInput"></textarea>
<view class="comment-actions">
<view wx:if="{{replyTarget}}" class="comment-cancel" bindtap="handleReply">取消回复</view>
<view class="comment-submit" bindtap="handleSubmitComment">发布</view>
</view>
</view>
<view wx:if="{{!comments.length}}" class="comment-empty">还没有评论,来写第一条吧</view>
<view wx:for="{{comments}}" wx:key="id" class="comment-item">
<view class="comment-main">
<text class="comment-name">{{item.userNickname || '用户'}}</text>
<text class="comment-time">{{item.createTime}}</text>
</view>
<view class="comment-text">{{item.commentContent}}</view>
<view class="comment-reply-btn" data-comment="{{item}}" bindtap="handleReply">回复</view>
<view wx:if="{{item.replies && item.replies.length}}" class="reply-list">
<view wx:for="{{item.replies}}" wx:for-item="reply" wx:key="id" class="reply-item">
<text class="reply-name">{{reply.userNickname || '用户'}}:</text>
<text>{{reply.commentContent}}</text>
</view>
</view>
</view>
</view>
</view>
<view class="footer-bar">
<view class="footer-btn secondary" bindtap="handleAddToCart">加入购物车</view>
<view class="footer-btn primary" bindtap="handleBuyNow">立即预约</view>
</view>
</block>
</view>
@@ -0,0 +1,325 @@
.detail-page {
padding-bottom: calc(env(safe-area-inset-bottom) + 160rpx);
background: var(--theme-page-bg);
}
.media-box {
position: relative;
overflow: hidden;
border-radius: 0 0 40rpx 40rpx;
background: var(--theme-primary-soft);
}
.media-swiper,
.media-image {
width: 100%;
height: 640rpx;
}
.media-mask {
position: absolute;
left: 24rpx;
right: 24rpx;
bottom: 28rpx;
}
.media-badges {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
}
.detail-content {
margin-top: -48rpx;
}
.info-card {
padding: 32rpx 30rpx;
}
.detail-head {
padding-bottom: 10rpx;
}
.product-title {
margin-top: 16rpx;
font-size: 42rpx;
font-weight: 700;
line-height: 1.4;
color: var(--text-primary);
}
.product-price {
margin-top: 12rpx;
font-size: 38rpx;
font-weight: 700;
color: var(--theme-accent);
}
.product-brief {
margin-top: 14rpx;
font-size: 24rpx;
line-height: 1.8;
color: var(--text-secondary);
}
.detail-summary {
margin-top: 24rpx;
}
.detail-summary-value {
font-size: 26rpx;
line-height: 1.5;
}
.shop-box {
margin-top: 28rpx;
padding: 24rpx;
border-radius: 24rpx;
background: var(--theme-gradient-soft);
}
.shop-box-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.shop-name {
font-size: 30rpx;
font-weight: 700;
color: var(--text-primary);
}
.shop-link {
font-size: 24rpx;
color: var(--theme-primary);
font-weight: 700;
}
.shop-meta {
margin-top: 10rpx;
font-size: 24rpx;
color: var(--text-secondary);
line-height: 1.7;
}
.actions-row {
display: flex;
flex-wrap: wrap;
gap: 16rpx;
margin-top: 28rpx;
}
.action-pill {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 180rpx;
height: 68rpx;
padding: 0 24rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
color: var(--theme-accent);
font-size: 24rpx;
font-weight: 600;
border: 0;
line-height: 68rpx;
}
.share-pill::after {
border: 0;
}
.action-pill.active {
background: var(--theme-primary-soft);
color: var(--theme-primary);
}
.tags-wrap {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
margin-top: 24rpx;
}
.tag-chip {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 10rpx 18rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 22rpx;
}
.desc-block {
margin-top: 28rpx;
}
.desc-text {
margin-top: 16rpx;
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 {
margin-top: 24rpx;
padding: 30rpx;
}
.comment-head,
.comment-main,
.comment-actions {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.comment-count,
.comment-time {
font-size: 22rpx;
color: #9b8d94;
}
.comment-editor {
margin-top: 20rpx;
padding: 20rpx;
border-radius: 20rpx;
background: var(--theme-primary-soft);
}
.comment-input {
width: 100%;
min-height: 120rpx;
font-size: 26rpx;
line-height: 1.7;
color: var(--text-primary);
}
.comment-actions {
margin-top: 16rpx;
justify-content: flex-end;
}
.comment-cancel,
.comment-submit,
.comment-reply-btn {
font-size: 24rpx;
color: var(--theme-primary);
font-weight: 700;
}
.comment-submit {
min-width: 116rpx;
height: 56rpx;
line-height: 56rpx;
text-align: center;
border-radius: 999rpx;
color: #ffffff;
background: var(--theme-primary);
}
.comment-empty {
padding: 28rpx 0 8rpx;
font-size: 24rpx;
color: #9b8d94;
text-align: center;
}
.comment-item {
padding: 24rpx 0;
border-bottom: 1rpx solid #f2e7eb;
}
.comment-item:last-child {
border-bottom: 0;
}
.comment-name {
font-size: 26rpx;
font-weight: 700;
color: var(--text-primary);
}
.comment-text {
margin-top: 12rpx;
font-size: 26rpx;
line-height: 1.8;
color: #5d4b55;
}
.comment-reply-btn {
margin-top: 10rpx;
}
.reply-list {
margin-top: 14rpx;
padding: 16rpx;
border-radius: 18rpx;
background: var(--theme-primary-soft);
}
.reply-item {
padding: 6rpx 0;
font-size: 24rpx;
line-height: 1.7;
color: #5d4b55;
}
.reply-name {
color: var(--text-primary);
font-weight: 700;
}
.footer-bar {
position: fixed;
left: 24rpx;
right: 24rpx;
bottom: calc(env(safe-area-inset-bottom) + 20rpx);
z-index: 20;
display: flex;
gap: 16rpx;
padding: 18rpx;
border-radius: 30rpx;
background: rgba(255, 255, 255, 0.96);
box-shadow: 0 18rpx 50rpx rgba(122, 67, 88, 0.12);
}
.footer-btn {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
height: 88rpx;
border-radius: 999rpx;
font-size: 28rpx;
font-weight: 700;
}
.footer-btn.secondary {
background: var(--theme-primary-soft);
color: var(--theme-accent);
}
.footer-btn.primary {
background: var(--theme-gradient);
color: #ffffff;
}
+625
View File
@@ -0,0 +1,625 @@
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: cache supports index.js by holding or executing the cache 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 cache = require('../../utils/cache')
/**
* Purpose: tagApi supports index.js by holding or executing the tag 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 tagApi = require('../../api/tag')
/**
* Purpose: productApi supports index.js by holding or executing the product 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 productApi = require('../../api/product')
/**
* Purpose: cartApi supports index.js by holding or executing the cart api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const cartApi = require('../../api/cart')
/**
* Purpose: actionGuard supports index.js by holding or executing the action guard 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 actionGuard = require('../../utils/action-guard')
const { buildProductCards } = require('../../utils/product')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
const { runWithLoading } = require('../../utils/loading')
const { CACHE_TTL } = require('../../utils/config')
const {
createKeyboardSafeData,
attachKeyboardSafe,
detachKeyboardSafe,
handleKeyboardFocus,
handleKeyboardBlur,
resetKeyboardSafe
} = require('../../utils/keyboard-safe')
/**
* Purpose: ALL_CATEGORY supports index.js by holding or executing the all category 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 ALL_CATEGORY = '\u5168\u90e8'
/**
* Purpose: FILTER_BUSY_MESSAGE supports index.js by holding or executing the filter busy message 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 FILTER_BUSY_MESSAGE = '\u7b5b\u9009\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
/**
* Purpose: CART_BUSY_MESSAGE supports index.js by holding or executing the cart busy message 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 CART_BUSY_MESSAGE = '\u8d2d\u7269\u8f66\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
/**
* products page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 96
}), theme.pageThemeData(getApp().globalData.shopTheme), {
initialized: false,
loading: false,
loadingMore: false,
categories: [ALL_CATEGORY],
filterGroups: [],
selectedTagId: '',
selectedCategory: ALL_CATEGORY,
searchKeyword: '',
products: [],
filterSummaryText: '',
page: 1,
pageSize: 10,
total: 0,
hasMore: false
}),
/**
* `onLoad` 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.
*/
onLoad(options) {
this.filterRequestId = 0
this.ensureKeyboardSafe()
this.bootstrapPage(options || {})
},
async onShow() {
this.ensureKeyboardSafe()
const app = getApp()
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
if (this.data.initialized && pendingFilter && (pendingFilter.keyword || pendingFilter.tag)) {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (app && app.globalData) {
app.globalData.pendingProductFilter = null
}
await this.applyFilter(pendingFilter)
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this.data.initialized) {
await this.syncProductCartState()
}
},
/**
* `onHide` 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.
*/
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
/**
* `onUnload` 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.
*/
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
async onPullDownRefresh() {
await this.loadProducts(true)
wx.stopPullDownRefresh()
},
/**
* `onReachBottom` 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.
*/
onReachBottom() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!this.data.hasMore || this.data.loadingMore) {
return
}
this.loadProducts(false)
},
/**
* `ensureKeyboardSafe` 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.
*/
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 96,
spacerExtraRpx: 16
})
},
async bootstrapPage(options) {
this.setData({
loading: true
})
try {
await this.loadTags()
await this.applyInitialFilter(options)
this.setData({
initialized: true
})
} catch (error) {
wx.showToast({
title: error.message || '\u4f5c\u54c1\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
this.setData({
loading: false
})
}
},
async loadTags() {
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({
filterGroups: normalizedGroups
})
},
async applyInitialFilter(options) {
const app = getApp()
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
if (pendingFilter && (pendingFilter.keyword || pendingFilter.tag)) {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (app && app.globalData) {
app.globalData.pendingProductFilter = null
}
await this.applyFilter(pendingFilter)
return
}
await this.applyFilter(options || {})
},
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,
selectedTagId: matchedTag ? String(matchedTag.id) : '',
selectedCategory: matchedTag ? (matchedTag.displayName || matchedTag.tagName) : ALL_CATEGORY,
page: 1,
total: 0,
hasMore: false
})
await this.loadProducts(true)
},
async loadProducts(reset) {
const requestId = ++this.filterRequestId
const nextPage = reset ? 1 : this.data.page + 1
this.setData(reset ? { loading: true } : { loadingMore: true })
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: tagIds ? undefined : (tag || undefined),
tagIds: tagIds || undefined
})
const cards = await buildProductCards(result && result.list ? result.list : [])
const displayCards = await this.attachCartState(cards)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId !== this.filterRequestId) {
return
}
const merged = reset ? displayCards : this.data.products.concat(displayCards)
const total = Number(result && result.total) || 0
this.setData({
products: merged,
page: nextPage,
total,
hasMore: merged.length < total,
filterSummaryText: this.buildFilterSummary(keyword, tag, total)
})
} catch (error) {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId !== this.filterRequestId) {
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (reset) {
this.setData({
products: [],
total: 0,
hasMore: false,
filterSummaryText: ''
})
}
wx.showToast({
title: error.message || '\u4f5c\u54c1\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (requestId === this.filterRequestId) {
this.setData({
loading: false,
loadingMore: false
})
}
}
},
/**
* `buildFilterSummary` 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.
*/
buildFilterSummary(keyword, tag, total) {
const chips = []
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (tag) {
chips.push(tag)
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (keyword) {
chips.push(`\u641c\u7d22\uff1a${keyword}`)
}
chips.push(`\u5171 ${Number(total || 0)} \u4e2a`)
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.
*/
normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
},
async fetchCartProductIdSet() {
if (!auth.isLoggedIn()) {
this.cartProductIdSet = new Set()
return this.cartProductIdSet
}
try {
const cartList = await cartApi.getCartList()
const idSet = new Set(
(Array.isArray(cartList) ? cartList : [])
.map(item => this.normalizeId(item && item.productId))
.filter(Boolean)
)
this.cartProductIdSet = idSet
return idSet
} catch (error) {
this.cartProductIdSet = new Set()
return this.cartProductIdSet
}
},
async attachCartState(cards) {
const idSet = await this.fetchCartProductIdSet()
return this.markCardsInCart(cards, idSet)
},
/**
* `markCardsInCart` 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.
*/
markCardsInCart(cards, idSet) {
const productIdSet = idSet || new Set()
return (Array.isArray(cards) ? cards : []).map(item => ({
...item,
inCart: productIdSet.has(this.normalizeId(item && item.id))
}))
},
async syncProductCartState() {
const idSet = await this.fetchCartProductIdSet()
this.setData({
products: this.markCardsInCart(this.data.products, idSet)
})
},
/**
* `markProductInCart` 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.
*/
markProductInCart(productId) {
const normalizedId = this.normalizeId(productId)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!normalizedId) {
return
}
this.cartProductIdSet = this.cartProductIdSet || new Set()
this.cartProductIdSet.add(normalizedId)
this.setData({
products: this.data.products.map(item => (
this.normalizeId(item && item.id) === normalizedId
? {
...item,
inCart: true
}
: item
))
})
},
/**
* `handleSearchInput` 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.
*/
handleSearchInput(event) {
this.setData({
searchKeyword: event.detail.value
})
},
/**
* `handleSearchFocus` 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.
*/
handleSearchFocus(event) {
handleKeyboardFocus(this, event)
},
/**
* `handleSearchBlur` 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.
*/
handleSearchBlur() {
handleKeyboardBlur(this)
},
async handleSearchConfirm() {
resetKeyboardSafe(this)
try {
await actionGuard.run(this, 'products:search', async () => {
this.setData({
selectedCategory: ALL_CATEGORY,
selectedTagId: '',
page: 1
})
await runWithLoading(() => this.loadProducts(true))
}, {
message: FILTER_BUSY_MESSAGE
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u7b5b\u9009\u5931\u8d25',
icon: 'none'
})
}
},
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}:${tagId}`, async () => {
this.setData({
selectedCategory: category,
selectedTagId: tagId,
searchKeyword: '',
page: 1
})
await runWithLoading(() => this.loadProducts(true))
}, {
message: FILTER_BUSY_MESSAGE
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u7b5b\u9009\u5931\u8d25',
icon: 'none'
})
}
},
async handleResetFilters() {
resetKeyboardSafe(this)
try {
await actionGuard.run(this, 'products:reset', async () => {
this.setData({
selectedCategory: ALL_CATEGORY,
selectedTagId: '',
searchKeyword: '',
page: 1
})
await runWithLoading(() => this.loadProducts(true))
}, {
message: FILTER_BUSY_MESSAGE
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u7b5b\u9009\u5931\u8d25',
icon: 'none'
})
}
},
/**
* `handleProductSelect` 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.
*/
handleProductSelect(event) {
const product = event.detail || {}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!product.id) {
return
}
navigation.navigate('/pages/product-detail/index', {
id: product.id
})
},
async handleQuickAdd(event) {
const product = event.detail || {}
const productId = this.normalizeId(product.id)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!productId) {
return
}
if (!navigation.ensureLogin('\u52a0\u5165\u8d2d\u7269\u8f66')) {
return
}
if (this.cartProductIdSet && this.cartProductIdSet.has(productId)) {
wx.showToast({
title: '\u8d2d\u7269\u8f66\u5df2\u6709',
icon: 'none'
})
return
}
try {
await actionGuard.run(this, `cart:add:${productId}`, () => runWithLoading(() => cartApi.addToCart({
productId,
quantity: 1
})), {
message: CART_BUSY_MESSAGE
})
this.markProductInCart(productId)
await getApp().updateCartBadge()
wx.showToast({
title: '\u5df2\u52a0\u5165\u8d2d\u7269\u8f66',
icon: 'none'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u52a0\u5165\u8d2d\u7269\u8f66\u5931\u8d25',
icon: 'none'
})
}
}
})
@@ -0,0 +1,7 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar",
"product-card": "/components/product-card/product-card"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,88 @@
<navigation-bar title="作品库" showBack="{{false}}" isTabPage="{{true}}" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell product-page {{keyboardVisible ? 'keyboard-active' : ''}}" style="{{themeVars}}">
<view class="page-content product-page-content" style="{{keyboardVisible ? 'padding-bottom: ' + keyboardInsetRpx + 'rpx;' : ''}}">
<view class="sticky-filter-bar">
<view class="filter-surface">
<view class="search-row">
<input
class="search-input"
placeholder="搜索标题、标签或描述"
placeholder-class="field-placeholder"
value="{{searchKeyword}}"
bindinput="handleSearchInput"
bindconfirm="handleSearchConfirm"
bindfocus="handleSearchFocus"
bindblur="handleSearchBlur"
data-keyboard-anchor="products-search-anchor"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
confirm-type="search"
/>
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>
</view>
<scroll-view class="category-scroll" scroll-x enable-flex show-scrollbar="false">
<view class="category-list">
<view
class="category-item {{selectedCategory === '全部' ? 'active' : ''}}"
data-category="全部"
data-tag-id=""
bindtap="handleSelectCategory"
>
全部
</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>
<view class="results-head">
<view class="results-meta">
<view class="results-count">{{products.length ? products.length : 0}} 个</view>
<view wx:if="{{filterSummaryText}}" class="filter-summary-chip">{{filterSummaryText}}</view>
</view>
<view wx:if="{{searchKeyword || selectedCategory !== '全部'}}" class="ghost-btn results-reset" bindtap="handleResetFilters">重置</view>
</view>
</view>
</view>
<view wx:if="{{products.length}}" class="product-grid">
<view wx:for="{{products}}" wx:key="id" class="product-grid-item">
<product-card
item="{{item}}"
show-stats="{{true}}"
show-quick-add="{{true}}"
in-cart="{{item.inCart}}"
bindselect="handleProductSelect"
bindquickadd="handleQuickAdd"
></product-card>
</view>
</view>
<view wx:if="{{products.length && (loadingMore || !hasMore)}}" class="load-state">
<text class="load-state-text">{{loadingMore ? '正在加载更多作品...' : '已经到底了'}}</text>
</view>
<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="handleResetFilters">查看全部</view>
</view>
</view>
</view>
+175
View File
@@ -0,0 +1,175 @@
.product-page {
background: var(--theme-page-bg);
}
.product-page-content {
padding-top: 10rpx;
}
.sticky-filter-bar {
position: sticky;
top: 0;
z-index: 12;
padding: 6rpx 0 16rpx;
background: var(--theme-page-bg);
}
.filter-surface {
padding: 16rpx 16rpx 14rpx;
border-radius: 24rpx;
border: 1rpx solid var(--theme-border);
background: var(--theme-card-bg);
box-shadow: 0 18rpx 40rpx rgba(74, 68, 63, 0.08);
}
.search-row {
display: flex;
align-items: center;
gap: 12rpx;
}
.search-input {
flex: 1;
height: 68rpx;
padding: 0 22rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
color: var(--text-primary);
font-size: 26rpx;
}
.search-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 112rpx;
height: 68rpx;
padding: 0 28rpx;
border-radius: 999rpx;
background: var(--theme-gradient);
color: #ffffff;
font-size: 24rpx;
font-weight: 700;
}
.category-scroll {
margin-top: 14rpx;
width: 100%;
height: 56rpx;
min-height: 56rpx;
white-space: nowrap;
}
.category-list {
display: inline-flex;
align-items: center;
gap: 12rpx;
min-height: 56rpx;
padding-right: 4rpx;
}
.category-item {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
min-width: 88rpx;
height: 50rpx;
padding: 0 20rpx;
border-radius: 999rpx;
border: 1rpx solid var(--theme-border);
background: var(--theme-primary-soft);
color: var(--text-secondary);
font-size: 22rpx;
font-weight: 600;
}
.filter-group {
display: inline-flex;
align-items: center;
gap: 12rpx;
flex-shrink: 0;
}
.filter-group-title {
color: var(--theme-primary-action);
font-size: 22rpx;
font-weight: 700;
}
.category-item.active {
border-color: var(--theme-secondary);
background: var(--theme-secondary-soft);
color: var(--theme-primary-action);
}
.results-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12rpx;
margin-top: 14rpx;
}
.results-meta {
display: flex;
align-items: center;
gap: 12rpx;
min-width: 0;
}
.results-count {
flex-shrink: 0;
font-size: 24rpx;
font-weight: 700;
color: var(--text-primary);
}
.filter-summary-chip {
display: inline-flex;
align-items: center;
min-width: 0;
max-width: 360rpx;
height: 46rpx;
padding: 0 18rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 22rpx;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.results-reset {
flex-shrink: 0;
height: 52rpx;
padding: 0 20rpx;
min-width: 0;
font-size: 22rpx;
}
.product-grid {
display: flex;
flex-wrap: wrap;
gap: 14rpx;
margin-top: 18rpx;
}
.product-grid-item {
min-width: 0;
width: calc(50% - 7rpx);
}
.load-state {
display: flex;
align-items: center;
justify-content: center;
padding: 20rpx 0 10rpx;
}
.load-state-text {
font-size: 22rpx;
color: var(--text-secondary);
}
+456
View File
@@ -0,0 +1,456 @@
/**
* Purpose: authApi supports index.js by holding or executing the auth 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 authApi = require('../../api/auth')
/**
* Purpose: couponApi supports index.js by holding or executing the coupon api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const couponApi = require('../../api/coupon')
/**
* Purpose: orderApi supports index.js by holding or executing the order api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const orderApi = require('../../api/order')
const growthApi = require('../../api/growth')
/**
* Purpose: userApi supports index.js by holding or executing the user 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 userApi = require('../../api/user')
/**
* Purpose: wishlistApi supports index.js by holding or executing the wishlist 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 wishlistApi = require('../../api/wishlist')
/**
* Purpose: actionGuard supports index.js by holding or executing the action guard 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 actionGuard = require('../../utils/action-guard')
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
const sessionSwitch = require('../../utils/session-switch')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
const { DEFAULT_AVATAR } = require('../../utils/config')
const { runWithLoading } = require('../../utils/loading')
function formatGrowthSummary(summary) {
if (!summary) {
return null
}
return {
levelName: summary.levelName || '成长新客',
growthValue: Number(summary.growthValue || 0),
appointmentCount: Number(summary.appointmentCount || 0),
reviewCount: Number(summary.reviewCount || 0)
}
}
/**
* profile page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
isLoggedIn: false,
loading: false,
needSetPassword: false,
userInfo: null,
orderCount: 0,
pendingReviewCount: 0,
couponCount: 0,
wishlistCount: 0,
unreadMessageCount: 0,
growthSummary: null,
defaultAvatar: DEFAULT_AVATAR
}),
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.loadProfile()
},
async loadProfile() {
this._avatarReloadSource = ''
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
needSetPassword: auth.getNeedSetPassword(),
loading: isLoggedIn
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!isLoggedIn) {
this.setData({
userInfo: null,
orderCount: 0,
couponCount: 0,
wishlistCount: 0,
growthSummary: null,
loading: false
})
return
}
try {
const [userInfo, orders, coupons, wishlist, unreadMessages, pendingReviews, growthSummary] = await Promise.all([
userApi.getUserInfo(),
orderApi.getOrderList(),
couponApi.listUserCoupons(),
wishlistApi.getWishlist(),
userApi.getMyUnreadMessageCount(),
orderApi.listMyPendingReviews().catch(() => []),
growthApi.getGrowthSummary().catch(() => null)
])
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),
growthSummary: formatGrowthSummary(growthSummary)
})
await this.checkPopupMessages()
} catch (error) {
wx.showToast({
title: error.message || '\u4e2a\u4eba\u4e2d\u5fc3\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
this.setData({
loading: false
})
}
},
/**
* `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleOpenAuth() {
navigation.openAuth('/pages/profile/index')
},
handleOpenAdminLogin() {
sessionSwitch.openAdminLogin()
},
/**
* `handleOpenSettings` 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.
*/
handleOpenSettings() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!this.data.isLoggedIn) {
this.handleOpenAuth()
return
}
navigation.navigate('/pages/settings/index')
},
/**
* `handleOpenOrders` 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.
*/
handleOpenOrders() {
if (!navigation.ensureLogin('\u67e5\u770b\u8ba2\u5355')) {
return
}
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.
*/
handleOpenWishlist() {
if (!navigation.ensureLogin('\u67e5\u770b\u6536\u85cf')) {
return
}
navigation.navigate('/pages/wishlist/index')
},
/**
* `handleOpenCoupons` 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.
*/
handleOpenCoupons() {
if (!navigation.ensureLogin('\u67e5\u770b\u4f18\u60e0\u5238')) {
return
}
navigation.navigate('/pages/coupons/index')
},
/**
* `handleOpenVipCenter` 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.
*/
handleOpenVipCenter() {
if (!navigation.ensureLogin('查看 VIP 中心')) {
return
}
navigation.navigate('/pages/vip-center/index')
},
/**
* `handleOpenNotifications` 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.
*/
handleOpenNotifications() {
if (!navigation.ensureLogin('查看消息通知')) {
return
}
navigation.navigate('/pages/notifications/index')
},
async checkPopupMessages() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this._checkingPopupMessages) {
return
}
this._checkingPopupMessages = true
try {
const globalApp = getApp()
if (globalApp && typeof globalApp.checkPopupMessages === 'function') {
await globalApp.checkPopupMessages()
return
}
const messages = await userApi.listMyPopupMessages()
/**
* `for` 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.
*/
for (const item of messages || []) {
await new Promise(resolve => {
wx.showModal({
title: item.title || '消息通知',
content: item.content || '',
showCancel: false,
confirmText: '我知道了',
complete: resolve
})
})
await userApi.markMessagePopupShown(item.id)
const opened = await navigation.openSystemMessage(item)
if (opened) {
break
}
}
} catch (error) {
console.error('加载待弹窗消息失败', error)
} finally {
this._checkingPopupMessages = false
}
},
async handleSwitchShop() {
if (!navigation.ensureLogin('\u5207\u6362\u95e8\u5e97')) {
return
}
const userInfo = this.data.userInfo
const shopIds = userInfo && Array.isArray(userInfo.shopIds) ? userInfo.shopIds : []
const shopNames = userInfo && Array.isArray(userInfo.shopNames) ? userInfo.shopNames : []
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopIds.length) {
wx.showToast({
title: '\u5f53\u524d\u8d26\u53f7\u8fd8\u6ca1\u6709\u53ef\u7528\u95e8\u5e97',
icon: 'none'
})
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (shopIds.length === 1) {
navigation.navigate('/pages/shop-detail/index', {
id: shopIds[0],
returnTo: navigation.getCurrentPageUrl()
})
return
}
try {
await actionGuard.run(this, 'user:switch-shop', async () => {
const selection = await new Promise(resolve => {
wx.showActionSheet({
itemList: shopNames.map((name, index) => name || `\u95e8\u5e97 ${shopIds[index]}`),
success: res => resolve(res.tapIndex),
fail: () => resolve(-1)
})
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (selection < 0 || selection >= shopIds.length) {
return
}
const payload = await runWithLoading(() => authApi.switchShop({
shopId: shopIds[selection]
}))
getApp().setUserSession(payload)
wx.showToast({
title: '\u95e8\u5e97\u5df2\u5207\u6362',
icon: 'none'
})
await this.loadProfile()
}, {
message: '\u95e8\u5e97\u5207\u6362\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u95e8\u5e97\u5207\u6362\u5931\u8d25',
icon: 'none'
})
}
},
async handleLogout() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!this.data.isLoggedIn) {
this.handleOpenAuth()
return
}
try {
await actionGuard.run(this, 'auth:logout', async () => {
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '\u9000\u51fa\u767b\u5f55',
content: '\u9000\u51fa\u540e\u9700\u8981\u91cd\u65b0\u767b\u5f55\u624d\u80fd\u67e5\u770b\u8ba2\u5355\u548c\u7ee7\u7eed\u4e0b\u5355\u3002',
success: res => resolve(Boolean(res.confirm))
})
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!confirmed) {
return
}
try {
await runWithLoading(() => authApi.logout())
} catch (error) {}
getApp().clearUserSession()
await this.loadProfile()
wx.showToast({
title: '\u5df2\u9000\u51fa\u767b\u5f55',
icon: 'none'
})
}, {
message: '\u9000\u51fa\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
})
} catch (error) {
if (!actionGuard.isGuardError(error)) {
throw error
}
}
},
async handleAvatarError() {
const currentAvatar = this.data.userInfo && this.data.userInfo.avatar
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!currentAvatar) {
return
}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (this._avatarReloadSource === currentAvatar) {
this.setData({
'userInfo.avatar': ''
})
return
}
this._avatarReloadSource = currentAvatar
try {
const userInfo = await userApi.getUserInfo()
getApp().refreshUserInfo(userInfo)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!userInfo || !userInfo.avatar || userInfo.avatar === currentAvatar) {
this.setData({
'userInfo.avatar': ''
})
return
}
this.setData({
userInfo
})
} catch (error) {
this.setData({
'userInfo.avatar': ''
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+122
View File
@@ -0,0 +1,122 @@
<view class="profile-page-root" style="{{themeVars}}">
<navigation-bar title="个人中心" showBack="{{false}}" isTabPage="{{true}}" color="#FDFBF9" background="transparent" safeAreaMode="overlay"></navigation-bar>
<view class="profile-bg"></view>
<view class="profile-scroll">
<view class="page-shell profile-page">
<view class="page-content profile-content">
<view wx:if="{{!isLoggedIn}}" class="page-card guest-card">
<image class="guest-avatar" src="{{defaultAvatar}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="guest-title">还没有登录账号</view>
<view class="guest-desc">登录后查看订单、收藏和优惠券。</view>
<view class="primary-btn" bindtap="handleOpenAuth">去登录</view>
</view>
<block wx:elif="{{userInfo}}">
<view class="page-card profile-card">
<view class="profile-top">
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill" lazy-load="{{true}}" binderror="handleAvatarError"></image>
<view class="profile-copy">
<view class="nickname">{{userInfo.nickname || 'Yumi 用户'}}</view>
<view class="account">{{userInfo.account}}</view>
<view wx:if="{{userInfo.signature}}" class="signature">{{userInfo.signature}}</view>
</view>
</view>
<view class="summary-strip profile-stats">
<view class="summary-metric" bindtap="handleOpenOrders">
<text class="summary-label">订单</text>
<text class="summary-value">{{orderCount}}</text>
</view>
<view class="summary-metric" bindtap="handleOpenWishlist">
<text class="summary-label">收藏</text>
<text class="summary-value">{{wishlistCount}}</text>
</view>
<view class="summary-metric" bindtap="handleOpenCoupons">
<text class="summary-label">优惠券</text>
<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 wx:if="{{growthSummary}}" class="growth-card">
<view class="growth-head">
<text class="growth-label">成长等级</text>
<text class="growth-level">{{growthSummary.levelName}}</text>
</view>
<view class="growth-metrics">
<view>
<text>{{growthSummary.growthValue}}</text>
<text>成长值</text>
</view>
<view>
<text>{{growthSummary.appointmentCount}}</text>
<text>预约</text>
</view>
<view>
<text>{{growthSummary.reviewCount}}</text>
<text>评价</text>
</view>
</view>
</view>
<view class="shop-box" bindtap="handleSwitchShop">
<view>
<view class="shop-label">当前登录门店</view>
<view class="shop-name">{{userInfo.shopName || '当前暂无可用门店'}}</view>
</view>
<view class="shop-link">{{(userInfo.shopIds && userInfo.shopIds.length > 1) ? '切换' : '查看'}}</view>
</view>
<view wx:if="{{needSetPassword}}" class="password-tip">
建议尽快设置登录密码。
</view>
<view class="secondary-btn edit-btn" bindtap="handleOpenSettings">资料与设置</view>
</view>
<view class="page-card menu-card">
<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">
<text>我的收藏</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item" bindtap="handleOpenCoupons">
<text>我的优惠券</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item" bindtap="handleOpenVipCenter">
<text>VIP 中心</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item" bindtap="handleOpenNotifications">
<text>消息通知</text>
<text wx:if="{{unreadMessageCount > 0}}" class="menu-badge">{{unreadMessageCount}}</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item" bindtap="handleOpenSettings">
<text>设置中心</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item admin-entry-item" bindtap="handleOpenAdminLogin">
<text>进入管理后台</text>
<text class="menu-arrow">></text>
</view>
<view class="menu-item logout-item" bindtap="handleLogout">
<text>退出登录</text>
<text class="menu-arrow">></text>
</view>
</view>
</block>
</view>
</view>
</view>
</view>
+267
View File
@@ -0,0 +1,267 @@
.profile-page-root {
min-height: 100vh;
background: var(--theme-page-bg);
}
.profile-scroll {
min-height: 100%;
background: var(--theme-page-bg);
}
.profile-page {
min-height: 100%;
background: var(--theme-page-bg);
}
.profile-bg {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 228rpx;
background: var(--theme-gradient);
}
.profile-content {
position: relative;
z-index: 1;
padding-top: 80rpx;
}
.guest-card,
.profile-card,
.menu-card {
padding: 28rpx;
}
.guest-card {
display: flex;
flex-direction: column;
align-items: center;
gap: 18rpx;
text-align: center;
}
.guest-avatar {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
}
.guest-title {
font-size: 34rpx;
font-weight: 700;
color: var(--text-primary);
}
.guest-desc {
font-size: 24rpx;
line-height: 1.7;
color: var(--text-secondary);
}
.profile-top {
display: flex;
gap: 20rpx;
}
.avatar {
width: 120rpx;
height: 120rpx;
border-radius: 50%;
background: var(--theme-primary-soft);
}
.profile-copy {
flex: 1;
}
.nickname {
font-size: 38rpx;
font-weight: 700;
color: var(--text-primary);
}
.account,
.signature {
margin-top: 10rpx;
font-size: 24rpx;
color: var(--text-secondary);
line-height: 1.6;
}
.profile-stats {
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: var(--text-secondary);
font-size: 24rpx;
}
.pending-review-card text:first-child {
color: var(--theme-primary);
font-size: 28rpx;
font-weight: 700;
}
.growth-card {
margin-top: 22rpx;
padding: 22rpx 24rpx;
border-radius: 20rpx;
background: var(--theme-card-bg);
border: 2rpx solid var(--theme-border);
}
.growth-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
}
.growth-label {
color: var(--text-secondary);
font-size: 24rpx;
}
.growth-level {
color: var(--theme-primary);
font-size: 28rpx;
font-weight: 800;
}
.growth-metrics {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12rpx;
margin-top: 18rpx;
}
.growth-metrics view {
display: flex;
flex-direction: column;
gap: 6rpx;
min-width: 0;
}
.growth-metrics text:first-child {
color: var(--text-primary);
font-size: 30rpx;
font-weight: 800;
}
.growth-metrics text:last-child {
color: var(--text-secondary);
font-size: 22rpx;
}
.shop-box {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
margin-top: 26rpx;
padding: 22rpx 24rpx;
border-radius: 24rpx;
background: var(--theme-primary-soft);
}
.shop-label {
font-size: 22rpx;
color: var(--text-secondary);
}
.shop-name {
margin-top: 10rpx;
font-size: 28rpx;
font-weight: 700;
color: var(--text-primary);
}
.shop-link {
font-size: 24rpx;
color: var(--theme-primary);
font-weight: 700;
}
.password-tip {
margin-top: 22rpx;
padding: 20rpx 24rpx;
border-radius: 20rpx;
background: var(--theme-secondary-soft);
color: var(--theme-neutral);
font-size: 24rpx;
line-height: 1.7;
}
.edit-btn {
margin-top: 24rpx;
}
.menu-card {
margin-top: 20rpx;
}
.menu-item {
display: flex;
align-items: center;
justify-content: space-between;
height: 92rpx;
border-bottom: 2rpx solid var(--theme-border);
font-size: 28rpx;
color: var(--text-primary);
}
.menu-item:first-of-type {
margin-top: 18rpx;
}
.menu-item:last-child {
border-bottom: 0;
}
.menu-arrow {
color: var(--text-secondary);
}
.menu-badge {
margin-left: auto;
min-width: 36rpx;
height: 36rpx;
padding: 0 10rpx;
border-radius: 18rpx;
background: var(--theme-primary);
color: var(--theme-tertiary);
font-size: 22rpx;
line-height: 36rpx;
text-align: center;
}
.menu-badge + .menu-arrow {
margin-left: 16rpx;
}
.logout-item {
color: var(--theme-neutral);
font-weight: 700;
}
.admin-entry-item {
color: var(--theme-primary-action);
font-weight: 700;
}
.admin-entry-item .menu-arrow {
color: var(--theme-primary-action);
}
.logout-item .menu-arrow {
color: var(--theme-primary);
}
@@ -0,0 +1,100 @@
const orderApi = require('../../api/order')
const afterSaleApi = require('../../api/after-sale')
const auth = require('../../utils/auth')
const navigation = require('../../utils/navigation')
const theme = require('../../utils/theme')
const { formatDateTime } = require('../../utils/format')
function safeList(value) {
if (Array.isArray(value)) return value
if (value && Array.isArray(value.list)) return value.list
return []
}
function buildNodes(order, reviews, changes, afterSales) {
const items = safeList(order && order.items)
const appointment = items.map(item => item && item.appointmentTime).find(Boolean)
const status = Number(order && order.status)
return [
{ key: 'created', title: '订单创建', text: formatDateTime(order && order.createTime) || '已提交', done: true, active: false },
{ key: 'appointment', title: '预约确认', text: formatDateTime(appointment) || '待确认', done: Boolean(appointment), active: status === 1 },
{ key: 'artist', title: '服务安排', text: changes.length ? `${changes.length} 条改派记录` : '按预约安排服务', done: changes.length > 0 || items.some(item => item.artistName), active: changes.some(item => String(item.status || '').toUpperCase() === 'PENDING') },
{ key: 'service', title: status === 3 ? '订单取消' : '服务完成', text: formatDateTime(order && (order.completeTime || order.cancelTime || order.updateTime)) || '等待服务', done: status === 2 || status === 3, active: status === 2 || status === 3 },
{ key: 'after-sale', title: '售后/评价', text: afterSales.length ? `${afterSales.length} 条售后` : (reviews.length ? `${reviews.length} 条评价` : '暂无记录'), done: afterSales.length > 0 || reviews.length > 0, active: afterSales.some(item => String(item.status || '').toUpperCase() === 'PENDING') }
]
}
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
orderId: '',
loading: false,
isLoggedIn: false,
order: null,
nodes: [],
items: [],
reviews: [],
changes: [],
afterSales: []
}),
onLoad(options) {
this.setData({
orderId: (options && (options.orderId || options.id)) || ''
})
},
onShow() {
this.loadProgress()
},
handleBack() {
navigation.goBack('/pages/orders/index')
},
async loadProgress() {
const isLoggedIn = auth.isLoggedIn()
this.setData({ isLoggedIn })
if (!isLoggedIn) {
navigation.openAuth(navigation.getCurrentPageUrl())
return
}
if (!this.data.orderId) return
this.setData({ loading: true })
try {
const [order, reviews, changes, afterSalePage] = await Promise.all([
orderApi.getOrderDetail(this.data.orderId),
orderApi.listOrderReviews(this.data.orderId).catch(() => []),
orderApi.listOrderArtistChangeRequests(this.data.orderId).catch(() => []),
afterSaleApi.getMyAfterSales({ page: 1, size: 50 }).catch(() => ({ list: [] }))
])
const afterSales = safeList(afterSalePage).filter(item => String(item.orderId) === String(this.data.orderId))
this.setData({
order,
items: safeList(order && order.items).map(item => ({
...item,
appointmentText: formatDateTime(item.appointmentTime)
})),
reviews,
changes,
afterSales,
nodes: buildNodes(order, reviews || [], changes || [], afterSales)
})
} catch (error) {
wx.showToast({
title: error.message || '服务进度加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
openOrder() {
navigation.navigate('/pages/order-detail/index', { id: this.data.orderId })
},
openAfterSaleApply() {
navigation.navigate('/pages/after-sale-apply/index', { orderId: this.data.orderId })
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,52 @@
<navigation-bar title="服务进度" showBack="{{true}}" fallbackPath="/pages/orders/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell" style="{{themeVars}}">
<view class="page-content">
<view class="page-hero">
<text class="hero-kicker">进度追踪</text>
<text class="hero-title">{{order && order.orderNo || '订单进度'}}</text>
<text class="hero-desc">{{order && order.shopName || '查看预约、服务��评价与售后节点'}}</text>
</view>
<view wx:if="{{loading}}" class="page-card empty-card">
<text class="empty-title">正在加载进度</text>
</view>
<block wx:elif="{{order}}">
<view class="page-card progress-card">
<view wx:for="{{nodes}}" wx:key="key" class="progress-node {{item.done ? 'done' : ''}} {{item.active ? 'active' : ''}}">
<view class="node-dot"></view>
<view class="node-copy">
<text class="node-title">{{item.title}}</text>
<text class="node-text">{{item.text}}</text>
</view>
</view>
</view>
<view wx:if="{{items.length}}" class="page-card record-card">
<text class="section-title">项目进度</text>
<text wx:for="{{items}}" wx:key="id" class="record-line">{{item.productTitle}}:{{item.artistName || '待安�?}} · {{item.appointmentText || '待确�?}}</text>
</view>
<view wx:if="{{changes.length}}" class="page-card record-card">
<text class="section-title">改派记录</text>
<text wx:for="{{changes}}" wx:key="id" class="record-line">{{item.statusText || item.status || '已记�?}}:{{item.reason || item.timeImpactText || ''}}</text>
</view>
<view wx:if="{{afterSales.length}}" class="page-card record-card">
<text class="section-title">售后记录</text>
<text wx:for="{{afterSales}}" wx:key="id" class="record-line">{{item.afterSaleNo || item.id}}:{{item.status}}</text>
</view>
<view class="action-row">
<view class="secondary-btn" bindtap="openOrder">订单详情</view>
<view class="primary-btn" bindtap="openAfterSaleApply">申请售后</view>
</view>
</block>
<view wx:else class="page-card empty-card">
<text class="empty-title">未找到订单进�?/text>
<text class="empty-desc">请从订单中心重新进入�?/text>
</view>
</view>
</view>
@@ -0,0 +1,61 @@
.progress-card,
.record-card {
margin-top: 22rpx;
padding: 26rpx;
}
.progress-node {
display: flex;
gap: 18rpx;
padding: 20rpx 0;
border-top: 2rpx solid var(--theme-border);
}
.progress-node:first-child {
padding-top: 0;
border-top: 0;
}
.node-dot {
width: 24rpx;
height: 24rpx;
margin-top: 6rpx;
border-radius: 999rpx;
background: var(--theme-border);
box-shadow: 0 0 0 10rpx var(--theme-primary-soft);
}
.progress-node.done .node-dot,
.progress-node.active .node-dot {
background: var(--theme-primary);
}
.node-copy {
flex: 1;
}
.node-title,
.node-text,
.record-line {
display: block;
}
.node-title {
color: var(--text-primary);
font-size: 29rpx;
font-weight: 800;
}
.node-text,
.record-line {
margin-top: 8rpx;
color: #504444;
font-size: 24rpx;
line-height: 1.6;
}
.action-row {
display: grid;
gap: 16rpx;
margin-top: 24rpx;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
+287
View File
@@ -0,0 +1,287 @@
<view class="settings-page-root" style="{{themeVars}}">
<navigation-bar title="设置中心" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="settings-scroll">
<view class="page-shell settings-page-shell {{keyboardVisible ? 'keyboard-active' : ''}}">
<view class="page-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="{{userInfo}}">
<view class="page-hero settings-hero">
<text class="hero-kicker">账号设置</text>
<text class="hero-title">资料与安全</text>
<text class="hero-desc">常用设置都在这里</text>
</view>
<view class="page-card settings-card">
<view class="section-title">个人资料</view>
<view class="profile-preview">
<image class="avatar" src="{{userInfo.avatar || defaultAvatar}}" mode="aspectFill" lazy-load="{{true}}" binderror="handleAvatarError"></image>
<view class="profile-preview-copy">
<view class="preview-name">{{userInfo.nickname || 'Yumi 用户'}}</view>
<view class="preview-account">{{userInfo.account}}</view>
<view class="preview-phone">{{userInfo.phone || '未绑定手机号'}}</view>
</view>
</view>
<view class="avatar-actions">
<view class="ghost-btn avatar-action" bindtap="handleChooseAvatar">{{uploadingAvatar ? '头像上传中...' : '更换头像'}}</view>
<view wx:if="{{userInfo.avatar}}" class="text-action" bindtap="handleDeleteAvatar">删除头像</view>
</view>
<view wx:if="{{needSetPassword}}" class="hint-card password-hint">
当前账号未设置登录密码。
</view>
<view id="settings-profile-nickname-anchor" class="field-block">
<text class="field-label">昵称</text>
<input
class="field-input"
placeholder="请输入昵称"
placeholder-class="field-placeholder"
value="{{form.nickname}}"
data-field="nickname"
data-keyboard-anchor="settings-profile-nickname-anchor"
bindinput="handleFormInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view id="settings-profile-signature-anchor" class="field-block">
<text class="field-label">个性签名</text>
<textarea
class="field-textarea"
placeholder="请输入个性签名"
placeholder-class="field-placeholder"
value="{{form.signature}}"
data-field="signature"
data-keyboard-anchor="settings-profile-signature-anchor"
bindinput="handleFormInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></textarea>
</view>
<view class="primary-btn save-btn" bindtap="handleSaveProfile">{{savingProfile ? '保存中...' : '保存资料'}}</view>
</view>
<view class="page-card settings-card security-card">
<view class="section-title">账号与安全</view>
<view class="setting-row" bindtap="handleSwitchShop">
<view class="setting-main">
<view class="setting-name">当前登录门店</view>
<view class="setting-desc">{{userInfo.shopName || '当前暂无可用门店'}}</view>
</view>
<view class="setting-action">{{(userInfo.shopIds && userInfo.shopIds.length > 1) ? '切换' : '查看'}}</view>
</view>
<view wx:if="{{!userInfo.phone}}" class="setting-row" data-panel="bindPhone" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">绑定手机号</view>
<view class="setting-desc">绑定后可设置密码</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'bindPhone' ? '收起' : '去绑定'}}</view>
</view>
<view wx:if="{{userInfo.phone}}" class="setting-row" data-panel="changePhone" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">修改手机号</view>
<view class="setting-desc">{{userInfo.phone}}</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'changePhone' ? '收起' : '修改'}}</view>
</view>
<view class="setting-row" data-panel="password" bindtap="handleToggleSecurityPanel">
<view class="setting-main">
<view class="setting-name">{{needSetPassword ? '设置登录密码' : '修改登录密码'}}</view>
<view class="setting-desc">{{userInfo.phone ? '短信验证后修改' : '请先绑定手机号'}}</view>
</view>
<view class="setting-action">{{activeSecurityPanel === 'password' ? '收起' : (needSetPassword ? '去设置' : '修改')}}</view>
</view>
<view wx:if="{{activeSecurityPanel === 'bindPhone'}}" class="security-panel">
<view class="section-subtitle">输入后完成绑定</view>
<view id="settings-bind-phone-anchor" class="field-block">
<text class="field-label">手机号</text>
<input
class="field-input"
type="number"
placeholder="请输入手机号"
placeholder-class="field-placeholder"
value="{{bindPhoneForm.phone}}"
data-field="phone"
data-keyboard-anchor="settings-bind-phone-anchor"
bindinput="handleBindPhoneInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view id="settings-bind-phone-code-anchor" class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input
class="field-input code-input"
type="number"
placeholder="请输入验证码"
placeholder-class="field-placeholder"
value="{{bindPhoneForm.verificationCode}}"
data-field="verificationCode"
data-keyboard-anchor="settings-bind-phone-code-anchor"
bindinput="handleBindPhoneInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendBindPhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleBindPhoneSubmit">{{updatingPhone ? '绑定中...' : '确认绑定'}}</view>
</view>
</view>
<view wx:if="{{activeSecurityPanel === 'changePhone'}}" class="security-panel">
<view class="section-subtitle">验证后更新手机号</view>
<view class="field-block">
<text class="field-label">当前手机号</text>
<view class="field-static">{{userInfo.phone}}</view>
</view>
<view id="settings-change-phone-anchor" class="field-block">
<text class="field-label">新手机号</text>
<input
class="field-input"
type="number"
placeholder="请输入新的手机号"
placeholder-class="field-placeholder"
value="{{changePhoneForm.newPhone}}"
data-field="newPhone"
data-keyboard-anchor="settings-change-phone-anchor"
bindinput="handleChangePhoneInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view id="settings-change-phone-code-anchor" class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input
class="field-input code-input"
type="number"
placeholder="请输入验证码"
placeholder-class="field-placeholder"
value="{{changePhoneForm.verificationCode}}"
data-field="verificationCode"
data-keyboard-anchor="settings-change-phone-code-anchor"
bindinput="handleChangePhoneInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendChangePhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleChangePhoneSubmit">{{updatingPhone ? '提交中...' : '确认修改'}}</view>
</view>
</view>
<view wx:if="{{activeSecurityPanel === 'password'}}" class="security-panel">
<view wx:if="{{!userInfo.phone}}" class="hint-card password-hint">请先绑定手机号,再通过验证码设置或修改登录密码。</view>
<block wx:else>
<view class="section-subtitle">密码需包含字母和数字</view>
<view id="settings-password-code-anchor" class="field-block">
<text class="field-label">验证码</text>
<view class="code-row">
<input
class="field-input code-input"
type="number"
placeholder="请输入验证码"
placeholder-class="field-placeholder"
value="{{passwordForm.verificationCode}}"
data-field="verificationCode"
data-keyboard-anchor="settings-password-code-anchor"
bindinput="handlePasswordInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendPasswordCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
</view>
</view>
<view id="settings-password-anchor" class="field-block">
<text class="field-label">新密码</text>
<input
class="field-input"
password
placeholder="请输入新密码"
placeholder-class="field-placeholder"
value="{{passwordForm.password}}"
data-field="password"
data-keyboard-anchor="settings-password-anchor"
bindinput="handlePasswordInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view id="settings-password-confirm-anchor" class="field-block">
<text class="field-label">确认密码</text>
<input
class="field-input"
password
placeholder="请再次输入新密码"
placeholder-class="field-placeholder"
value="{{passwordForm.confirmPassword}}"
data-field="confirmPassword"
data-keyboard-anchor="settings-password-confirm-anchor"
bindinput="handlePasswordInput"
bindfocus="handleKeyboardFocus"
bindblur="handleKeyboardBlur"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
></input>
</view>
<view class="panel-actions">
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
<view class="primary-btn panel-btn" bindtap="handleUpdatePassword">{{updatingPassword ? '提交中...' : '确认保存'}}</view>
</view>
</block>
</view>
<view class="setting-row danger-row" bindtap="handleDeactivateAccount">
<view class="setting-main">
<view class="setting-name">注销账号</view>
<view class="setting-desc">注销后不可继续登录</view>
</view>
<view class="setting-action danger-text">{{deactivating ? '处理中' : '注销'}}</view>
</view>
</view>
<view class="logout-btn" bindtap="handleLogout">退出登录</view>
</block>
</view>
<view wx:if="{{keyboardVisible}}" class="keyboard-spacer" style="height: {{keyboardInsetRpx}}rpx;"></view>
</view>
</view>
</view>
+224
View File
@@ -0,0 +1,224 @@
.settings-page-root {
min-height: 100vh;
background: var(--theme-page-bg);
}
.settings-scroll {
min-height: 100%;
}
.settings-page-shell {
min-height: 100%;
background: var(--theme-page-bg);
}
.settings-page-shell.keyboard-active {
padding-bottom: 0;
}
.settings-hero {
margin-bottom: 20rpx;
}
.settings-card + .settings-card {
margin-top: 20rpx;
}
.settings-card {
padding: 28rpx;
}
.profile-preview {
display: flex;
align-items: center;
gap: 20rpx;
margin-top: 22rpx;
}
.avatar {
width: 110rpx;
height: 110rpx;
border-radius: 50%;
background: var(--theme-primary-soft);
}
.profile-preview-copy {
flex: 1;
min-width: 0;
}
.preview-name {
font-size: 32rpx;
font-weight: 700;
color: var(--text-primary);
}
.preview-account,
.preview-phone {
margin-top: 10rpx;
font-size: 24rpx;
color: var(--text-secondary);
word-break: break-all;
}
.avatar-actions {
display: flex;
align-items: center;
gap: 18rpx;
margin-top: 22rpx;
}
.avatar-action {
width: auto;
min-width: 220rpx;
padding: 0 28rpx;
}
.text-action {
font-size: 24rpx;
font-weight: 600;
color: var(--theme-primary);
}
.field-block {
margin-top: 20rpx;
}
.save-btn {
margin-top: 26rpx;
}
.password-hint {
margin-top: 20rpx;
}
.security-card {
margin-top: 20rpx;
}
.setting-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18rpx;
padding: 24rpx 0;
border-bottom: 1rpx solid var(--theme-border);
}
.setting-row:first-of-type {
margin-top: 8rpx;
}
.setting-row:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.setting-main {
flex: 1;
min-width: 0;
}
.setting-name {
font-size: 28rpx;
font-weight: 700;
color: var(--text-primary);
}
.setting-desc {
margin-top: 10rpx;
font-size: 24rpx;
line-height: 1.7;
color: var(--text-secondary);
}
.setting-action {
flex-shrink: 0;
font-size: 24rpx;
font-weight: 700;
color: var(--theme-primary);
}
.security-panel {
margin-top: 6rpx;
padding: 26rpx 24rpx;
border-radius: 28rpx;
background: var(--theme-primary-soft);
}
.field-static {
display: flex;
align-items: center;
min-height: 92rpx;
padding: 0 28rpx;
border-radius: 24rpx;
background: var(--theme-card-bg);
border: 1rpx solid var(--theme-border);
color: #5d4b55;
font-size: 28rpx;
}
.code-row {
display: flex;
align-items: center;
gap: 14rpx;
}
.code-input {
flex: 1;
}
.code-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 180rpx;
height: 92rpx;
padding: 0 18rpx;
border-radius: 24rpx;
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 24rpx;
font-weight: 700;
}
.code-btn.disabled {
background: var(--theme-card-bg);
color: #a998a0;
}
.panel-actions {
display: flex;
gap: 14rpx;
margin-top: 24rpx;
}
.panel-btn {
flex: 1;
}
.danger-row {
margin-top: 8rpx;
}
.danger-text {
color: var(--theme-accent);
}
.logout-btn {
display: flex;
align-items: center;
justify-content: center;
height: 92rpx;
margin-top: 24rpx;
border-radius: 999rpx;
background: var(--theme-primary-soft);
color: var(--theme-accent);
font-size: 28rpx;
font-weight: 700;
}
.keyboard-spacer {
width: 100%;
flex-shrink: 0;
}
@@ -0,0 +1,380 @@
/**
* Purpose: shopApi supports index.js by holding or executing the shop 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 shopApi = require('../../api/shop')
/**
* Purpose: userApi loads contact information that is hidden until the customer explicitly asks for it.
* Usage: call getShopManagerContact from the contact button after login checks pass.
*/
const userApi = require('../../api/user')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../utils/file')
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
const { showRecoveryModal } = require('../../utils/recovery')
/**
* shop-detail page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: true,
loadError: '',
shopId: '',
returnTo: '/pages/home/index',
shopInfo: null,
/**
* Purpose: managerContact stores the shop manager contact returned after a customer requests it.
* Usage: bind it to the contact card and keep it null until the API succeeds.
*/
managerContact: null,
distanceText: '',
trustProfile: null,
shopImages: []
}),
/**
* `onLoad` 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.
*/
onLoad(options) {
this.setData({
shopId: options && options.id ? options.id : '',
returnTo: options && options.returnTo ? decodeURIComponent(options.returnTo) : '/pages/home/index'
})
this.loadShopDetail()
},
async onPullDownRefresh() {
await this.loadShopDetail()
wx.stopPullDownRefresh()
},
async loadShopDetail() {
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!this.data.shopId) {
this.setData({
loading: false,
loadError: '门店 ID 不存在'
})
return
}
this.setData({
loading: true,
loadError: ''
})
try {
const shopInfo = await shopApi.getShopById(this.data.shopId)
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) {
try {
const backgroundImageUrl = await getSignedUrl(shopTheme.backgroundImageFileId)
if (backgroundImageUrl) {
this.setData(theme.pageThemeData(shopTheme, backgroundImageUrl))
}
} catch (error) {}
}
this.setData({
shopInfo,
trustProfile: this.normalizeTrustProfile(trustProfile),
shopImages,
distanceText: ''
})
this.loadCurrentDistance()
} catch (error) {
this.setData({
loadError: error.message || '门店详情加载失败'
})
} finally {
this.setData({
loading: false
})
}
},
/**
* 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.
*/
handleBack() {
navigation.goBack(this.data.returnTo || '/pages/home/index')
},
/**
* `handlePreviewImage` 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.
*/
handlePreviewImage(event) {
const url = event.currentTarget.dataset.url
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!url) {
return
}
previewImagesSafely(url, this.data.shopImages)
},
/**
* Purpose: handleContactManager retrieves and shows the current shop manager contact.
* Usage: bind it to the contact button and require login before exposing phone data.
*/
async handleContactManager() {
const shopInfo = this.data.shopInfo
if (!shopInfo || !shopInfo.id || !navigation.ensureLogin('联系店长')) {
return
}
try {
const contact = await userApi.getShopManagerContact(shopInfo.id)
this.setData({ managerContact: contact })
if (contact && contact.phoneAvailable && contact.phone) {
wx.showModal({
title: contact.contactName || '店长联系方式',
content: `${contact.roleLabel || '店长'}:${contact.phone}`,
confirmText: '拨打',
cancelText: '复制',
success: res => {
if (res.confirm) {
wx.makePhoneCall({ phoneNumber: contact.phone })
} else {
wx.setClipboardData({ data: contact.phone })
}
}
})
return
}
wx.showToast({
title: (contact && contact.platformContactText) || '暂无可用联系方式',
icon: 'none'
})
} catch (error) {
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')
}
})
}
},
/**
* `handleCopyName` 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.
*/
handleCopyName() {
const shopInfo = this.data.shopInfo
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopInfo || !shopInfo.shopName) {
return
}
wx.setClipboardData({
data: shopInfo.shopName
})
},
/**
* `handleCopyAddress` 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.
*/
handleCopyAddress() {
const shopInfo = this.data.shopInfo
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!shopInfo || !shopInfo.address) {
return
}
wx.setClipboardData({
data: shopInfo.address
})
},
/**
* Purpose: handleOpenLocation supports index.js by holding or executing the handle open location 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.
*/
handleOpenLocation() {
const shopInfo = this.data.shopInfo
if (!shopInfo || !shopInfo.latitude || !shopInfo.longitude) {
wx.showToast({
title: '店铺暂未设置地图位置',
icon: 'none'
})
return
}
wx.openLocation({
latitude: Number(shopInfo.latitude),
longitude: Number(shopInfo.longitude),
name: shopInfo.shopName || '店铺位置',
address: shopInfo.address || '',
scale: 16
})
},
/**
* Purpose: handleOpenAmapNavigation supports index.js by holding or executing the handle open amap navigation 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.
*/
handleOpenAmapNavigation() {
const shopInfo = this.data.shopInfo
const amapUrl = shopInfo && shopInfo.navigationUrls && shopInfo.navigationUrls.AMAP
if (!amapUrl) {
wx.showToast({
title: '店铺暂未设置地图位置',
icon: 'none'
})
return
}
wx.setClipboardData({
data: amapUrl,
success: () => {
wx.showToast({
title: '高德导航链接已复制',
icon: 'none'
})
}
})
},
/**
* Purpose: handleCopyTencentNavigation copies a browser/Tencent-compatible navigation link when provided by the backend.
* Usage: bind it to the navigation row as a fallback for users who prefer another map app.
*/
handleCopyTencentNavigation() {
const shopInfo = this.data.shopInfo
const url = shopInfo && shopInfo.navigationUrls && (shopInfo.navigationUrls.TENCENT || shopInfo.navigationUrls.BROWSER)
if (!url) {
wx.showToast({
title: '店铺暂未设置备用导航链接',
icon: 'none'
})
return
}
wx.setClipboardData({
data: url,
success: () => {
wx.showToast({
title: '导航链接已复制',
icon: 'none'
})
}
})
},
/**
* Purpose: loadCurrentDistance supports index.js by holding or executing the load current distance 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.
*/
loadCurrentDistance() {
const shopInfo = this.data.shopInfo
if (!shopInfo || !shopInfo.latitude || !shopInfo.longitude || typeof wx.getLocation !== 'function') {
return
}
wx.getLocation({
type: 'gcj02',
success: (res) => {
this.setData({
distanceText: this.formatDistance(res.latitude, res.longitude, Number(shopInfo.latitude), Number(shopInfo.longitude))
})
}
})
},
/**
* Purpose: formatDistance supports index.js by holding or executing the format distance 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.
*/
formatDistance(currentLat, currentLng, shopLat, shopLng) {
if (![currentLat, currentLng, shopLat, shopLng].every(Number.isFinite)) {
return ''
}
const toRad = value => value * Math.PI / 180
const earthRadius = 6371000
const dLat = toRad(shopLat - currentLat)
const dLng = toRad(shopLng - currentLng)
const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(currentLat)) * Math.cos(toRad(shopLat)) * Math.sin(dLng / 2) ** 2
const meters = 2 * earthRadius * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
return meters >= 1000 ? `距你约 ${(meters / 1000).toFixed(1)} km` : `距你约 ${Math.round(meters)} m`
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,150 @@
<navigation-bar title="{{shopInfo ? shopInfo.shopName : '门店详情'}}" showBack="{{true}}" fallbackPath="{{returnTo || '/pages/home/index'}}" color="#ffffff" background="transparent" safeAreaMode="overlay"></navigation-bar>
<view class="page-shell shop-page" style="{{themeVars}}">
<view class="shop-hero">
<image wx:if="{{shopImages.length}}" class="shop-hero-image" src="{{shopImages[0]}}" mode="aspectFill" lazy-load="{{true}}"></image>
<view class="shop-hero-mask"></view>
</view>
<view wx:if="{{loadError}}" class="page-content shop-content">
<view class="page-card empty-card">
<text class="empty-title">暂时无法查看门店详情</text>
<text class="empty-desc">{{loadError}}</text>
<view class="ghost-btn" bindtap="handleBack">返回上一页</view>
</view>
</view>
<view wx:elif="{{shopInfo}}" class="page-content shop-content">
<view class="page-card shop-card">
<view class="section-kicker">门店详情</view>
<view class="shop-title">{{shopInfo.shopName}}</view>
<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">{{trustProfile.businessHoursText || shopInfo.businessHours || '待补充'}}</text>
<text class="summary-note">以到店服务时间为准</text>
</view>
<view class="summary-metric">
<text class="summary-label">环境图片</text>
<text class="summary-value shop-summary-value">{{shopImages.length ? shopImages.length : 0}} 张</text>
<text class="summary-note">支持点击放大查看</text>
</view>
</view>
<view class="detail-group">
<view class="detail-label">营业时间</view>
<view class="detail-value">{{trustProfile.businessHoursText || shopInfo.businessHours || '待补充'}}</view>
</view>
<view class="detail-group">
<view class="detail-label">门店介绍</view>
<view class="detail-value">{{shopInfo.description || '门店介绍待补充'}}</view>
</view>
<view class="copy-row">
<view class="ghost-btn" bindtap="handleCopyName">复制门店名</view>
<view class="ghost-btn" bindtap="handleCopyAddress">复制地址</view>
</view>
<view class="contact-row">
<view class="primary-btn contact-btn" bindtap="handleContactManager">联系店长</view>
<view wx:if="{{managerContact}}" class="contact-copy">
{{managerContact.contactName || '店长'}} · {{managerContact.phoneAvailable ? managerContact.phone : (managerContact.platformContactText || '暂无电话')}}
</view>
</view>
<view wx:if="{{shopInfo.longitude && shopInfo.latitude}}" class="map-row">
<view class="primary-btn map-btn" bindtap="handleOpenLocation">查看地图位置</view>
<view class="ghost-btn map-btn" bindtap="handleOpenAmapNavigation">复制高德导航链接</view>
<view class="ghost-btn map-btn" bindtap="handleCopyTencentNavigation">复制备用导航</view>
</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">
<text class="section-kicker">实景展示</text>
<text class="section-title">门店环境图</text>
<text class="section-subtitle">点击图片可以放大查看,更直观地感受门店氛围。</text>
</view>
</view>
<view class="gallery-list">
<image
wx:for="{{shopImages}}"
wx:key="*this"
class="gallery-image"
src="{{item}}"
mode="aspectFill"
data-url="{{item}}"
bindtap="handlePreviewImage"
lazy-load="{{true}}"
></image>
</view>
</view>
</view>
</view>
@@ -0,0 +1,236 @@
.shop-page {
background: var(--theme-page-bg);
}
.shop-hero {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 320rpx;
background: var(--theme-gradient);
}
.shop-hero-image {
width: 100%;
height: 100%;
}
.shop-hero-mask {
position: absolute;
inset: 0;
background: linear-gradient(180deg, rgba(34, 21, 27, 0.12), rgba(34, 21, 27, 0.42));
}
.shop-content {
position: relative;
z-index: 1;
padding-top: 160rpx;
}
.shop-card {
padding: 30rpx;
}
.shop-title {
font-size: 42rpx;
font-weight: 700;
line-height: 1.4;
color: var(--text-primary);
}
.shop-address {
margin-top: 16rpx;
font-size: 26rpx;
color: var(--text-secondary);
line-height: 1.7;
}
.shop-distance {
margin-top: 8rpx;
color: #8f6e7a;
font-size: 24rpx;
line-height: 1.5;
}
.shop-summary {
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: var(--text-secondary);
font-size: 22rpx;
line-height: 1.35;
}
.shop-summary-value {
font-size: 26rpx;
line-height: 1.6;
}
.detail-group {
margin-top: 24rpx;
}
.detail-label {
font-size: 24rpx;
color: var(--text-secondary);
}
.detail-value {
margin-top: 12rpx;
font-size: 28rpx;
color: var(--text-primary);
line-height: 1.8;
}
.copy-row {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16rpx;
margin-top: 26rpx;
}
.map-row {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 16rpx;
margin-top: 18rpx;
}
.contact-row {
display: grid;
gap: 12rpx;
margin-top: 18rpx;
}
.contact-btn {
width: 100%;
}
.contact-copy {
color: var(--text-secondary);
font-size: 24rpx;
line-height: 1.6;
}
.copy-row .ghost-btn,
.map-btn {
min-width: 0;
width: 100%;
}
.gallery-list {
display: flex;
flex-wrap: wrap;
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: var(--text-primary);
font-size: 28rpx;
font-weight: 700;
}
.featured-price {
color: var(--theme-primary);
font-size: 28rpx;
font-weight: 700;
}
.featured-hint,
.review-time {
color: var(--text-secondary);
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: var(--text-primary);
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;
border-radius: 24rpx;
background: var(--theme-primary-soft);
}
+230
View File
@@ -0,0 +1,230 @@
/**
* Purpose: userApi supports index.js by holding or executing the user 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 userApi = require('../../api/user')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: money supports index.js by holding or executing the money 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 money(value) {
return Number(value || 0).toFixed(2)
}
/**
* Purpose: formatTime supports index.js by holding or executing the format time 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 formatTime(value) {
return value ? String(value).replace('T', ' ').slice(0, 16) : '--'
}
/**
* Purpose: sceneText supports index.js by holding or executing the scene text 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 sceneText(scene) {
const map = {
MANUAL_RECHARGE: '手工充值',
MANUAL_DEDUCT: '手工扣减',
ORDER_PAY: '订单消费',
ORDER_REFUND: '订单退款',
RECHARGE: '充值',
CONSUME: '消费'
}
return map[scene] || scene || '余额变动'
}
/**
* vip-center page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: asset supports index.js by holding or executing the asset page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
asset: {
/**
* Purpose: vipLevel supports index.js by holding or executing the vip level page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipLevel: '普通',
/**
* Purpose: balanceText supports index.js by holding or executing the balance text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
balanceText: '0.00',
/**
* Purpose: totalRechargeText supports index.js by holding or executing the total recharge text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
totalRechargeText: '0.00',
/**
* Purpose: lastRechargeText supports index.js by holding or executing the last recharge text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
lastRechargeText: '--',
/**
* Purpose: vipStartText supports index.js by holding or executing the vip start text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipStartText: '--',
/**
* Purpose: manualOverride supports index.js by holding or executing the manual override page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
manualOverride: false
},
/**
* Purpose: history supports index.js by holding or executing the history page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
history: [],
/**
* Purpose: rechargePlans supports index.js by holding or executing the recharge plans page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
rechargePlans: [],
/**
* Purpose: rechargePanelVisible supports index.js by holding or executing the recharge panel visible page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
rechargePanelVisible: false
},
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
if (!navigation.ensureLogin('查看 VIP 中心')) {
return
}
this.loadData()
},
async loadData() {
try {
const [asset, history, plans] = await Promise.all([
userApi.getMyAsset(),
userApi.getMyBalanceHistory(),
userApi.listMyVipRechargePlans().catch(() => [])
])
this.setData({
/**
* Purpose: asset supports index.js by holding or executing the asset page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
asset: {
...asset,
/**
* Purpose: balanceText supports index.js by holding or executing the balance text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
balanceText: money(asset && asset.balance),
/**
* Purpose: totalRechargeText supports index.js by holding or executing the total recharge text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
totalRechargeText: money(asset && asset.totalRechargeAmount),
/**
* Purpose: lastRechargeText supports index.js by holding or executing the last recharge text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
lastRechargeText: formatTime(asset && asset.lastRechargeTime),
/**
* Purpose: vipStartText supports index.js by holding or executing the vip start text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipStartText: formatTime(asset && asset.vipStartTime)
},
/**
* Purpose: history supports index.js by holding or executing the history page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
history: (Array.isArray(history) ? history : []).map(item => {
const amountNumber = Number(item.amount || 0)
return {
...item,
amountNumber,
/**
* Purpose: amountText supports index.js by holding or executing the amount text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
amountText: `${amountNumber > 0 ? '+' : ''}¥${money(amountNumber)}`,
/**
* Purpose: sceneText supports index.js by holding or executing the scene text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
sceneText: sceneText(item.changeScene || item.type),
/**
* Purpose: changeTimeText supports index.js by holding or executing the change time text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
changeTimeText: formatTime(item.changeTime)
}
}),
/**
* Purpose: rechargePlans supports index.js by holding or executing the recharge plans page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
rechargePlans: (Array.isArray(plans) ? plans : []).map(item => ({
...item,
/**
* Purpose: amountText supports index.js by holding or executing the amount text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
amountText: `充 ${money(item.rechargeAmount)} 送 ${money(item.giftAmount)}`
}))
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || 'VIP 信息加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
/**
* `openRechargePanel` 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.
*/
openRechargePanel() {
this.setData({ rechargePanelVisible: true })
},
/**
* `closeRechargePanel` 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.
*/
closeRechargePanel() {
this.setData({ rechargePanelVisible: false })
},
/**
* `noop` 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.
*/
noop() {
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,61 @@
<navigation-bar title="VIP 中心" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="vip-page">
<view class="vip-hero">
<text class="vip-kicker">会员等级</text>
<text class="vip-level">{{asset.vipLevel || '普通'}}</text>
<text class="vip-benefit">{{asset.benefitInfo || '暂无额外权益说明'}}</text>
</view>
<view class="metric-grid">
<view class="metric">
<text>余额</text>
<text class="metric-value">¥{{asset.balanceText}}</text>
</view>
<view class="metric">
<text>累计充值</text>
<text class="metric-value">¥{{asset.totalRechargeText}}</text>
</view>
</view>
<view class="recharge-entry" bindtap="openRechargePanel">去充值 / 查看充值说明</view>
<view class="section">
<view class="section-title">会员信息</view>
<view class="info-row"><text>最近充值</text><text>{{asset.lastRechargeText}}</text></view>
<view class="info-row"><text>生效时间</text><text>{{asset.vipStartText}}</text></view>
<view class="info-row"><text>等级来源</text><text>{{asset.manualOverride ? '后台指定' : '自动计算'}}</text></view>
</view>
<view class="section">
<view class="section-title">余额变动</view>
<block wx:if="{{history.length}}">
<view wx:for="{{history}}" wx:key="id" class="history-row">
<view>
<text class="history-title">{{item.sceneText}}</text>
<text class="history-time">{{item.changeTimeText}}</text>
<text wx:if="{{item.remark}}" class="history-remark">{{item.remark}}</text>
</view>
<text class="history-amount {{item.amountNumber > 0 ? 'income' : ''}}">{{item.amountText}}</text>
</view>
</block>
<view wx:else class="empty">暂无余额变动</view>
</view>
<view wx:if="{{rechargePanelVisible}}" class="recharge-mask" bindtap="closeRechargePanel">
<view class="recharge-panel" catchtap="noop">
<view class="section-title">充值档位展示</view>
<block wx:if="{{rechargePlans.length}}">
<view wx:for="{{rechargePlans}}" wx:key="id" class="recharge-plan">
<view class="plan-head">
<text>{{item.title}}</text>
<text>{{item.vipLevel}}</text>
</view>
<text class="plan-amount">{{item.amountText}}</text>
<text class="plan-desc">{{item.description || '该档位仅展示,暂不发起支付。'}}</text>
</view>
</block>
<view wx:else class="empty">暂无可展示充值档位</view>
<view class="recharge-close" bindtap="closeRechargePanel">关闭</view>
</view>
</view>
</view>
@@ -0,0 +1,162 @@
.vip-page {
min-height: 100vh;
padding: 24rpx;
background: #f7f4f1;
box-sizing: border-box;
}
.vip-hero {
display: flex;
flex-direction: column;
gap: 10rpx;
padding: 36rpx;
border-radius: 16rpx;
color: #fff;
background: linear-gradient(135deg, #2b2522, #8a704e);
}
.vip-kicker, .vip-benefit {
color: rgba(255,255,255,.76);
font-size: 24rpx;
}
.vip-level {
font-size: 56rpx;
font-weight: 700;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16rpx;
margin-top: 20rpx;
}
.metric, .section {
padding: 28rpx;
border-radius: 16rpx;
background: #fff;
}
.metric {
display: flex;
flex-direction: column;
gap: 10rpx;
color: #7f7470;
}
.metric-value {
color: #2d2927;
font-size: 36rpx;
font-weight: 700;
}
.section {
margin-top: 20rpx;
}
.section-title {
margin-bottom: 20rpx;
color: #2d2927;
font-size: 32rpx;
font-weight: 700;
}
.info-row, .history-row {
display: flex;
justify-content: space-between;
gap: 20rpx;
padding: 18rpx 0;
border-bottom: 1rpx solid #f0ece8;
}
.info-row:last-child, .history-row:last-child {
border-bottom: 0;
}
.history-title, .history-time, .history-remark {
display: block;
}
.history-title {
color: #2d2927;
font-weight: 600;
}
.history-time, .history-remark, .empty {
margin-top: 6rpx;
color: #9a918d;
font-size: 24rpx;
}
.history-amount {
color: #2d2927;
font-weight: 700;
white-space: nowrap;
}
.history-amount.income {
color: #0f8f63;
}
.recharge-entry {
margin-top: 20rpx;
padding: 20rpx;
border-radius: 16rpx;
background: #fff7ed;
color: #9a5b2e;
font-weight: 700;
text-align: center;
}
.recharge-mask {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.4);
z-index: 30;
display: flex;
align-items: flex-end;
}
.recharge-panel {
width: 100%;
max-height: 75vh;
overflow: auto;
border-radius: 24rpx 24rpx 0 0;
background: #fff;
padding: 24rpx;
}
.recharge-plan {
padding: 18rpx 0;
border-bottom: 1rpx solid #f0ece8;
}
.plan-head {
display: flex;
justify-content: space-between;
gap: 18rpx;
color: #2d2927;
font-weight: 700;
}
.plan-amount {
display: block;
margin-top: 10rpx;
color: #9a5b2e;
}
.plan-desc {
display: block;
margin-top: 6rpx;
color: #9a918d;
font-size: 24rpx;
}
.recharge-close {
margin-top: 18rpx;
padding: 18rpx;
border-radius: 16rpx;
background: #f4f0eb;
text-align: center;
}
+329
View File
@@ -0,0 +1,329 @@
/**
* Purpose: wishlistApi supports index.js by holding or executing the wishlist 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 wishlistApi = require('../../api/wishlist')
/**
* Purpose: cartApi supports index.js by holding or executing the cart api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const cartApi = require('../../api/cart')
/**
* Purpose: actionGuard supports index.js by holding or executing the action guard 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 actionGuard = require('../../utils/action-guard')
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: theme supports index.js by holding or executing the theme page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const theme = require('../../utils/theme')
const { buildProductCard } = require('../../utils/product')
const { runWithLoading } = require('../../utils/loading')
/**
* wishlist page logic.
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
*/
Page({
data: Object.assign(theme.pageThemeData(getApp().globalData.shopTheme), {
loading: false,
isLoggedIn: false,
wishlist: [],
visibleWishlist: [],
groups: [],
activeGroupId: ''
}),
/**
* `onShow` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
onShow() {
this.loadWishlist()
},
async loadWishlist() {
const isLoggedIn = auth.isLoggedIn()
this.setData({
isLoggedIn,
loading: isLoggedIn
})
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!isLoggedIn) {
this.cartProductIdSet = new Set()
this.setData({
wishlist: [],
visibleWishlist: [],
groups: [],
activeGroupId: '',
loading: false
})
return
}
try {
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,
groups: this.buildGroupTabs(groupList, this.data.activeGroupId),
visibleWishlist: this.filterWishlist(cards, this.data.activeGroupId)
})
} catch (error) {
this.setData({
wishlist: [],
visibleWishlist: []
})
wx.showToast({
title: error.message || '\u6536\u85cf\u5217\u8868\u52a0\u8f7d\u5931\u8d25',
icon: 'none'
})
} finally {
this.setData({
loading: false
})
}
},
/**
* `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.
*/
normalizeId(value) {
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()
const idSet = new Set(
(Array.isArray(cartList) ? cartList : [])
.map(item => this.normalizeId(item && item.productId))
.filter(Boolean)
)
this.cartProductIdSet = idSet
return idSet
} catch (error) {
this.cartProductIdSet = new Set()
return this.cartProductIdSet
}
},
/**
* `markCardInCart` 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.
*/
markCardInCart(card, idSet) {
return {
...card,
inCart: (idSet || new Set()).has(this.normalizeId(card && card.id))
}
},
/**
* `markWishlistProductInCart` 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.
*/
markWishlistProductInCart(productId) {
const normalizedId = this.normalizeId(productId)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!normalizedId) {
return
}
this.cartProductIdSet = this.cartProductIdSet || new Set()
this.cartProductIdSet.add(normalizedId)
const nextWishlist = this.data.wishlist.map(item => (
this.normalizeId(item && item.productId) === normalizedId
? {
...item,
productCard: {
...item.productCard,
inCart: true
}
}
: item
))
this.setData({
wishlist: nextWishlist,
visibleWishlist: this.filterWishlist(nextWishlist, this.data.activeGroupId)
})
},
/**
* `handleOpenAuth` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
handleOpenAuth() {
navigation.openAuth('/pages/wishlist/index')
},
/**
* `handleProductSelect` 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.
*/
handleProductSelect(event) {
const product = event.detail || {}
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!product.id) {
return
}
navigation.navigate('/pages/product-detail/index', {
id: product.id
})
},
async handleQuickAdd(event) {
const product = event.detail || {}
const productId = this.normalizeId(product.id)
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!productId) {
return
}
if (!navigation.ensureLogin('\u52a0\u5165\u8d2d\u7269\u8f66')) {
return
}
if (this.cartProductIdSet && this.cartProductIdSet.has(productId)) {
wx.showToast({
title: '\u8d2d\u7269\u8f66\u5df2\u6709',
icon: 'none'
})
return
}
try {
await actionGuard.run(this, `cart:add:${productId}`, () => runWithLoading(() => cartApi.addToCart({
productId,
quantity: 1
})), {
message: '\u8d2d\u7269\u8f66\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
})
this.markWishlistProductInCart(productId)
await getApp().updateCartBadge()
wx.showToast({
title: '\u5df2\u52a0\u5165\u8d2d\u7269\u8f66',
icon: 'none'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u52a0\u5165\u8d2d\u7269\u8f66\u5931\u8d25',
icon: 'none'
})
}
},
async handleRemove(event) {
const productId = event.currentTarget.dataset.productId
/**
* `if` page method. Use this from WXML event bindings or lifecycle hooks.
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
*/
if (!productId) {
return
}
try {
await actionGuard.run(this, `wishlist:remove:${productId}`, () => runWithLoading(() => wishlistApi.removeFromWishlist(productId)), {
message: '\u64cd\u4f5c\u8fdb\u884c\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u70b9\u51fb'
})
wx.showToast({
title: '\u5df2\u53d6\u6d88\u6536\u85cf',
icon: 'none'
})
await this.loadWishlist()
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '\u53d6\u6d88\u6536\u85cf\u5931\u8d25',
icon: 'none'
})
}
},
/**
* `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.
*/
handleBack() {
navigation.goBack('/pages/profile/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/components/navigation-bar/navigation-bar",
"product-card": "/components/product-card/product-card"
}
}
@@ -0,0 +1,65 @@
<navigation-bar title="我的收藏" showBack="{{true}}" fallbackPath="/pages/profile/index" color="{{navThemeColor || '#4A443F'}}" background="{{navThemeBackground || '#FDFBF9'}}"></navigation-bar>
<view class="page-shell wishlist-page" style="{{themeVars}}">
<view class="page-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="{{wishlist.length}}">
<view class="page-hero wishlist-hero">
<text class="hero-kicker">收藏夹</text>
<text class="hero-title">已收藏 {{wishlist.length}} 个作品</text>
<text class="hero-desc">喜欢的款式先收藏。</text>
</view>
<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}}"
in-cart="{{item.productCard.inCart}}"
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">
<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="handleBack">去逛作品</view>
</view>
</view>
</view>
@@ -0,0 +1,83 @@
.wishlist-hero {
margin-bottom: 20rpx;
}
.wishlist-item + .wishlist-item {
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;
margin-top: 12rpx;
}
.wishlist-action {
display: flex;
align-items: center;
justify-content: center;
height: 74rpx;
flex: 1;
border-radius: 20rpx;
background: var(--theme-primary-soft);
color: var(--theme-primary);
font-size: 26rpx;
font-weight: 600;
}
.wishlist-action--secondary {
background: var(--theme-primary-soft);
color: var(--theme-accent);
}