功能(小程序):同步用户体验流程到小程序
This commit is contained in:
@@ -20,6 +20,7 @@ const navigation = require('../../utils/navigation')
|
||||
const theme = require('../../utils/theme')
|
||||
const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../utils/file')
|
||||
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
|
||||
const { showRecoveryModal } = require('../../utils/recovery')
|
||||
|
||||
/**
|
||||
* shop-detail page logic.
|
||||
@@ -38,6 +39,7 @@ Page({
|
||||
*/
|
||||
managerContact: null,
|
||||
distanceText: '',
|
||||
trustProfile: null,
|
||||
shopImages: []
|
||||
}),
|
||||
|
||||
@@ -78,7 +80,11 @@ Page({
|
||||
|
||||
try {
|
||||
const shopInfo = await shopApi.getShopById(this.data.shopId)
|
||||
const shopImages = await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE)
|
||||
const trustProfile = await shopApi.getTrustProfile(this.data.shopId).catch(() => null)
|
||||
const trustImages = trustProfile && Array.isArray(trustProfile.environmentImages) ? trustProfile.environmentImages.filter(Boolean) : []
|
||||
const shopImages = trustImages.length
|
||||
? trustImages
|
||||
: await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE)
|
||||
const shopTheme = theme.resolveShopTheme(shopInfo)
|
||||
this.setData(theme.pageThemeData(shopTheme))
|
||||
if (shopTheme.backgroundImageFileId) {
|
||||
@@ -91,6 +97,7 @@ Page({
|
||||
}
|
||||
this.setData({
|
||||
shopInfo,
|
||||
trustProfile: this.normalizeTrustProfile(trustProfile),
|
||||
shopImages,
|
||||
distanceText: ''
|
||||
})
|
||||
@@ -106,6 +113,47 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: normalizeTrustProfile prepares backend trust fields for WXML display.
|
||||
* Usage: call after getTrustProfile so metrics and lists have safe defaults.
|
||||
*/
|
||||
normalizeTrustProfile(profile) {
|
||||
if (!profile) {
|
||||
return null
|
||||
}
|
||||
const stats = profile.stats || {}
|
||||
return {
|
||||
...profile,
|
||||
ratingText: Number(stats.averageRating || 0) > 0 ? Number(stats.averageRating).toFixed(1) : '暂无',
|
||||
reviewCount: Number(stats.reviewCount || 0),
|
||||
productCount: Number(stats.productCount || 0),
|
||||
availabilityText: profile.availabilitySummary && profile.availabilitySummary.summaryText
|
||||
? profile.availabilitySummary.summaryText
|
||||
: '预约前会再次确认档期',
|
||||
featuredProducts: (Array.isArray(profile.featuredProducts) ? profile.featuredProducts : []).map(item => ({
|
||||
...item,
|
||||
priceText: Number(item.price || 0).toFixed(2)
|
||||
})),
|
||||
recentReviews: (Array.isArray(profile.recentReviews) ? profile.recentReviews : []).map(item => ({
|
||||
...item,
|
||||
ratingText: Number(item.ratingScore || 0) > 0 ? Number(item.ratingScore).toFixed(1) : '暂无',
|
||||
submittedText: item.submittedAt ? String(item.submittedAt).replace('T', ' ').slice(0, 16) : ''
|
||||
}))
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Purpose: handleOpenProduct navigates from trust-profile cards to product details.
|
||||
* Usage: bind product cards to this method with data-id.
|
||||
*/
|
||||
handleOpenProduct(event) {
|
||||
const productId = event.currentTarget.dataset.id
|
||||
if (!productId) {
|
||||
return
|
||||
}
|
||||
navigation.navigate('/pages/product-detail/index', { id: productId })
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleBack` page method. Use this from WXML event bindings or lifecycle hooks.
|
||||
* Call guide: read or update page data with `this.setData(...)` inside the method when state changes.
|
||||
@@ -164,9 +212,21 @@ Page({
|
||||
icon: 'none'
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '联系方式获取失败',
|
||||
icon: 'none'
|
||||
showRecoveryModal({
|
||||
title: '联系方式获取失败',
|
||||
message: error.message || '暂时没有拿到联系方式,请重试;也可以先复制门店名,稍后从“我的”页联系客服。',
|
||||
actions: [
|
||||
{ key: 'retry', text: '重试联系' },
|
||||
{ key: 'profile', text: '去我的' }
|
||||
]
|
||||
}).then(action => {
|
||||
if (action && action.key === 'retry') {
|
||||
this.handleContactManager()
|
||||
return
|
||||
}
|
||||
if (action && action.key === 'profile') {
|
||||
navigation.switchTab('/pages/profile/index')
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user