功能:同步小程序流程
This commit is contained in:
@@ -1,7 +1,24 @@
|
||||
/**
|
||||
* 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 } = require('../../utils/file')
|
||||
const { getSignedUrl, resolveImageList, previewImagesSafely } = require('../../utils/file')
|
||||
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
|
||||
|
||||
/**
|
||||
@@ -15,6 +32,11 @@ Page({
|
||||
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: '',
|
||||
shopImages: []
|
||||
}),
|
||||
@@ -106,10 +128,47 @@ Page({
|
||||
return
|
||||
}
|
||||
|
||||
wx.previewImage({
|
||||
current: url,
|
||||
urls: this.data.shopImages
|
||||
})
|
||||
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) {
|
||||
wx.showToast({
|
||||
title: error.message || '联系方式获取失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -150,6 +209,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
@@ -169,6 +232,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -190,6 +257,35 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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') {
|
||||
@@ -205,6 +301,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 ''
|
||||
|
||||
Reference in New Issue
Block a user