功能(小程序):同步用户体验流程到小程序
This commit is contained in:
@@ -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}`
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user