功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
@@ -78,5 +82,12 @@ module.exports = {
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
getCurrentAgreements() {
|
||||
return request({
|
||||
url: '/legal-agreement/current',
|
||||
method: 'GET'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
const actionGuard = require('../utils/action-guard')
|
||||
const { API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config')
|
||||
@@ -39,6 +43,86 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
|
||||
// 我的页常用数据:
|
||||
// 资产、余额流水、消息、公告、VIP 充值档位和所属关系都从这里拿。
|
||||
getMyAsset() {
|
||||
return request({
|
||||
url: '/user/asset/me'
|
||||
})
|
||||
},
|
||||
|
||||
getMyBalanceHistory() {
|
||||
return request({
|
||||
url: '/user/balance/history/me'
|
||||
})
|
||||
},
|
||||
|
||||
listMyMessages() {
|
||||
return request({
|
||||
url: '/system-message/my/list'
|
||||
})
|
||||
},
|
||||
|
||||
listMyPopupMessages() {
|
||||
return request({
|
||||
url: '/system-message/my/popup'
|
||||
})
|
||||
},
|
||||
|
||||
getMyUnreadMessageCount() {
|
||||
return request({
|
||||
url: '/system-message/my/unread-count'
|
||||
})
|
||||
},
|
||||
|
||||
markMessagePopupShown(id) {
|
||||
return request({
|
||||
url: `/system-message/my/${id}/popup-shown`,
|
||||
method: 'PUT',
|
||||
data: {}
|
||||
})
|
||||
},
|
||||
|
||||
markMessageRead(id) {
|
||||
return request({
|
||||
url: `/system-message/my/${id}/read`,
|
||||
method: 'PUT',
|
||||
data: {}
|
||||
})
|
||||
},
|
||||
|
||||
listMyAnnouncements() {
|
||||
return request({
|
||||
url: '/announcement/my/list'
|
||||
})
|
||||
},
|
||||
|
||||
// 这里只是“展示型充值档位”,不发起支付、不改余额。
|
||||
listMyVipRechargePlans() {
|
||||
return request({
|
||||
url: '/vip-recharge-plan/my/list'
|
||||
})
|
||||
},
|
||||
|
||||
getShopManagerContact(shopId) {
|
||||
return request({
|
||||
url: `/contact-info/shop/${shopId}/manager`
|
||||
})
|
||||
},
|
||||
|
||||
getProductArtistContact(productId, artistId) {
|
||||
return request({
|
||||
url: `/contact-info/product/${productId}/artist/${artistId}`
|
||||
})
|
||||
},
|
||||
|
||||
getOrderArtistContact(orderId, artistId) {
|
||||
return request({
|
||||
url: `/contact-info/order/${orderId}/artist`,
|
||||
data: artistId ? { artistId } : {}
|
||||
})
|
||||
},
|
||||
|
||||
updateUserInfo(data) {
|
||||
return request({
|
||||
url: '/user/update',
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Mini program API wrapper for this module.
|
||||
* Call guide: require this module in a page, then invoke the matching method from page event handlers or lifecycle hooks.
|
||||
*/
|
||||
const request = require('../utils/request')
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
"pages/orders/index",
|
||||
"pages/wishlist/index",
|
||||
"pages/coupons/index",
|
||||
"pages/vip-center/index",
|
||||
"pages/notifications/index",
|
||||
"pages/settings/index"
|
||||
],
|
||||
"window": {
|
||||
|
||||
@@ -52,7 +52,9 @@ Component({
|
||||
show: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
observer: '_showChange',
|
||||
observer(show) {
|
||||
this._showChange(show)
|
||||
},
|
||||
},
|
||||
delta: {
|
||||
type: Number,
|
||||
@@ -64,7 +66,9 @@ Component({
|
||||
},
|
||||
},
|
||||
observers: {
|
||||
'back, showBack, isTabPage': 'updateResolvedBack',
|
||||
'back, showBack, isTabPage': function () {
|
||||
this.updateResolvedBack()
|
||||
},
|
||||
},
|
||||
data: {
|
||||
displayStyle: '',
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
</view>
|
||||
<view class="product-body">
|
||||
<view class="product-title">{{item.displayTitle}}</view>
|
||||
<view wx:if="{{item.shopNameText}}" class="product-shop">{{item.shopNameText}}</view>
|
||||
<view wx:if="{{!showMeta && item.metaText}}" class="product-meta">{{item.metaText}}</view>
|
||||
<view wx:if="{{item.tagsPreview && item.tagsPreview.length}}" class="product-tags">
|
||||
<text wx:for="{{item.tagsPreview}}" wx:key="*this" class="tag-item">{{item}}</text>
|
||||
|
||||
@@ -215,3 +215,13 @@
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.product-shop {
|
||||
margin-top: 6rpx;
|
||||
color: #8f6e7a;
|
||||
font-size: 22rpx;
|
||||
line-height: 1.45;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ const {
|
||||
|
||||
const phoneRegex = /^1[3-9]\d{9}$/
|
||||
|
||||
/**
|
||||
* auth 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: 108
|
||||
@@ -54,6 +58,10 @@ Page({
|
||||
miniShopDisplayName: '',
|
||||
miniShopNewUser: false,
|
||||
miniShopSubmitting: false,
|
||||
agreementAccepted: false,
|
||||
agreements: [],
|
||||
agreementModalVisible: false,
|
||||
selectedAgreement: null,
|
||||
form: {
|
||||
account: '',
|
||||
password: '',
|
||||
@@ -71,6 +79,10 @@ Page({
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* `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.ensureKeyboardSafe()
|
||||
this.setData({
|
||||
@@ -79,20 +91,33 @@ Page({
|
||||
})
|
||||
this.detectWechatMiniCapability()
|
||||
this.loadShopOptions()
|
||||
this.loadAgreements()
|
||||
this.consumePendingWechatMiniLogin()
|
||||
this.waitForPendingWechatMiniAutoLogin()
|
||||
},
|
||||
|
||||
/**
|
||||
* `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.consumePendingWechatMiniLogin()
|
||||
},
|
||||
|
||||
/**
|
||||
* `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)
|
||||
@@ -100,6 +125,10 @@ Page({
|
||||
|
||||
noop() {},
|
||||
|
||||
/**
|
||||
* `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: 108,
|
||||
@@ -107,14 +136,26 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleKeyboardFocus` 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.
|
||||
*/
|
||||
handleKeyboardFocus(event) {
|
||||
handleKeyboardFocus(this, event)
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleKeyboardBlur` 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.
|
||||
*/
|
||||
handleKeyboardBlur() {
|
||||
handleKeyboardBlur(this)
|
||||
},
|
||||
|
||||
/**
|
||||
* `detectWechatMiniCapability` 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.
|
||||
*/
|
||||
detectWechatMiniCapability() {
|
||||
let supported = false
|
||||
let disabledReason = ''
|
||||
@@ -122,6 +163,10 @@ Page({
|
||||
try {
|
||||
supported = wx.canIUse('button.open-type.getPhoneNumber')
|
||||
const systemInfo = wx.getSystemInfoSync()
|
||||
/**
|
||||
* `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 (systemInfo && systemInfo.platform === 'devtools') {
|
||||
supported = false
|
||||
disabledReason = '当前环境无法使用微信手机号登录,请使用账号密码或验证码登录'
|
||||
@@ -130,6 +175,10 @@ Page({
|
||||
supported = false
|
||||
}
|
||||
|
||||
/**
|
||||
* `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 (!supported && !disabledReason) {
|
||||
disabledReason = '当前环境无法使用微信手机号登录,请使用账号密码或验证码登录'
|
||||
}
|
||||
@@ -140,6 +189,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `waitForPendingWechatMiniAutoLogin` 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.
|
||||
*/
|
||||
waitForPendingWechatMiniAutoLogin() {
|
||||
const app = getApp()
|
||||
if (
|
||||
@@ -167,13 +220,25 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `consumePendingWechatMiniLogin` 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.
|
||||
*/
|
||||
consumePendingWechatMiniLogin() {
|
||||
const app = getApp()
|
||||
/**
|
||||
* `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 || typeof app.consumePendingWechatMiniLogin !== 'function') {
|
||||
return
|
||||
}
|
||||
|
||||
const pending = app.consumePendingWechatMiniLogin()
|
||||
/**
|
||||
* `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 (pending && pending.status === 'SELECT_SHOP') {
|
||||
this.openMiniShopSelector(pending)
|
||||
}
|
||||
@@ -193,6 +258,87 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
async loadAgreements() {
|
||||
try {
|
||||
const agreements = await authApi.getCurrentAgreements()
|
||||
this.setData({
|
||||
agreements: Array.isArray(agreements) ? agreements : []
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: '协议内容加载失败,请稍后重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
buildAgreementPayload() {
|
||||
const agreementVersions = {}
|
||||
;(this.data.agreements || []).forEach((item) => {
|
||||
if (item && item.agreementType && item.version) {
|
||||
agreementVersions[item.agreementType] = item.version
|
||||
}
|
||||
})
|
||||
return {
|
||||
agreementAccepted: !!this.data.agreementAccepted,
|
||||
agreementVersions,
|
||||
clientType: 'WECHAT_MINI'
|
||||
}
|
||||
},
|
||||
|
||||
ensureAgreementAccepted() {
|
||||
if (!this.data.agreementAccepted) {
|
||||
wx.showToast({
|
||||
title: '请先阅读并同意用户协议和隐私政策',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
const versions = this.buildAgreementPayload().agreementVersions
|
||||
if (!versions.USER_TERMS || !versions.PRIVACY_POLICY) {
|
||||
wx.showToast({
|
||||
title: '协议版本加载中,请稍后再试',
|
||||
icon: 'none'
|
||||
})
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
|
||||
handleAgreementToggle() {
|
||||
this.setData({
|
||||
agreementAccepted: !this.data.agreementAccepted
|
||||
})
|
||||
},
|
||||
|
||||
openAgreement(event) {
|
||||
const type = event.currentTarget.dataset.type
|
||||
const selectedAgreement = (this.data.agreements || []).find((item) => item.agreementType === type)
|
||||
if (!selectedAgreement) {
|
||||
wx.showToast({
|
||||
title: '协议内容暂不可用',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
selectedAgreement,
|
||||
agreementModalVisible: true
|
||||
})
|
||||
},
|
||||
|
||||
closeAgreementModal() {
|
||||
this.setData({
|
||||
agreementModalVisible: false,
|
||||
selectedAgreement: null
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleTabChange` 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.
|
||||
*/
|
||||
handleTabChange(event) {
|
||||
const tab = event.currentTarget.dataset.tab
|
||||
resetKeyboardSafe(this)
|
||||
@@ -210,6 +356,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleLoginTypeChange` 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.
|
||||
*/
|
||||
handleLoginTypeChange(event) {
|
||||
const type = event.currentTarget.dataset.type
|
||||
resetKeyboardSafe(this)
|
||||
@@ -227,6 +377,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleShowTraditionalLogin` 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.
|
||||
*/
|
||||
handleShowTraditionalLogin() {
|
||||
resetKeyboardSafe(this)
|
||||
this.setData({
|
||||
@@ -235,6 +389,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleToggleResetPanel` 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.
|
||||
*/
|
||||
handleToggleResetPanel() {
|
||||
resetKeyboardSafe(this)
|
||||
this.setData({
|
||||
@@ -242,6 +400,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleInputChange` 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.
|
||||
*/
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const value = event.detail.value
|
||||
@@ -249,7 +411,15 @@ Page({
|
||||
[`form.${field}`]: 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 (field === 'account') {
|
||||
/**
|
||||
* `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.activeTab === 'login') {
|
||||
patch.loginAccountStatusText = ''
|
||||
patch.loginAccountStatusType = ''
|
||||
@@ -267,7 +437,15 @@ Page({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* `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 (field === 'phone') {
|
||||
/**
|
||||
* `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.activeTab === 'register') {
|
||||
patch.registerPhoneStatusText = ''
|
||||
patch.registerPhoneStatusType = ''
|
||||
@@ -284,6 +462,10 @@ Page({
|
||||
this.setData(patch)
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleResetInputChange` 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.
|
||||
*/
|
||||
handleResetInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
@@ -291,6 +473,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleRegisterShopChange` 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.
|
||||
*/
|
||||
handleRegisterShopChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.shops[index]
|
||||
@@ -301,6 +487,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleLoginShopChange` 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.
|
||||
*/
|
||||
handleLoginShopChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.loginShops[index]
|
||||
@@ -311,6 +501,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleMiniShopChange` 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.
|
||||
*/
|
||||
handleMiniShopChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.miniShops[index]
|
||||
@@ -320,7 +514,15 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleCloseMiniShopSelector` 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.
|
||||
*/
|
||||
handleCloseMiniShopSelector() {
|
||||
/**
|
||||
* `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.miniShopSubmitting) {
|
||||
return
|
||||
}
|
||||
@@ -329,7 +531,15 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleResumeMiniShopSelector` 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.
|
||||
*/
|
||||
handleResumeMiniShopSelector() {
|
||||
/**
|
||||
* `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.miniShopTicket || !this.data.miniShops.length) {
|
||||
return
|
||||
}
|
||||
@@ -342,15 +552,27 @@ Page({
|
||||
async handleAccountBlur() {
|
||||
this.handleKeyboardBlur()
|
||||
const account = this.data.form.account.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 (!account) {
|
||||
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.activeTab === 'register') {
|
||||
await this.checkRegisterAccountAvailability()
|
||||
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.loginType !== 'password') {
|
||||
return
|
||||
}
|
||||
@@ -364,10 +586,18 @@ Page({
|
||||
async handlePhoneBlur() {
|
||||
this.handleKeyboardBlur()
|
||||
const phone = this.data.form.phone.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 (!phone) {
|
||||
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.activeTab === 'register') {
|
||||
if (phoneRegex.test(phone)) {
|
||||
await this.checkRegisterPhoneAvailability()
|
||||
@@ -382,6 +612,10 @@ Page({
|
||||
await this.loadLoginShopsByPhone()
|
||||
},
|
||||
|
||||
/**
|
||||
* `applyLoginShopSelection` 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.
|
||||
*/
|
||||
applyLoginShopSelection(selection) {
|
||||
const shops = Array.isArray(selection && selection.shops) ? selection.shops : []
|
||||
const allowLoginShopless = Boolean(selection && selection.allowShoplessLogin)
|
||||
@@ -389,6 +623,10 @@ Page({
|
||||
let loginShopDisplayName = ''
|
||||
let 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 (!allowLoginShopless && shops.length === 1) {
|
||||
loginShopIndex = 0
|
||||
loginShopDisplayName = shops[0].shopName || ''
|
||||
@@ -482,6 +720,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `startCountdown` 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.
|
||||
*/
|
||||
startCountdown(fieldName) {
|
||||
this.setData({
|
||||
[fieldName]: 60
|
||||
@@ -493,6 +735,10 @@ Page({
|
||||
[fieldName]: nextValue
|
||||
})
|
||||
|
||||
/**
|
||||
* `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 (nextValue <= 0) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
@@ -500,6 +746,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleSendCode() {
|
||||
/**
|
||||
* `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.countdown > 0) {
|
||||
return
|
||||
}
|
||||
@@ -513,8 +763,16 @@ Page({
|
||||
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.activeTab === 'register') {
|
||||
const phoneAvailable = await this.checkRegisterPhoneAvailability()
|
||||
/**
|
||||
* `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 (!phoneAvailable) {
|
||||
wx.showToast({
|
||||
title: this.data.registerPhoneStatusText || '该手机号已被注册',
|
||||
@@ -525,7 +783,10 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => userApi.sendVerificationCode({ phone }))
|
||||
await runWithLoading(() => userApi.sendVerificationCode({
|
||||
phone,
|
||||
sceneCode: this.data.activeTab === 'register' ? 'USER_REGISTER_SMS_CODE' : 'USER_LOGIN_SMS_CODE'
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
@@ -540,6 +801,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleSendForgotCode() {
|
||||
/**
|
||||
* `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.forgotCountdown > 0) {
|
||||
return
|
||||
}
|
||||
@@ -554,7 +819,10 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => authApi.sendVerificationCode({ phone }))
|
||||
await runWithLoading(() => authApi.sendVerificationCode({
|
||||
phone,
|
||||
sceneCode: 'USER_RESET_PASSWORD_SMS_CODE'
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
@@ -568,8 +836,16 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `validateLoginForm` 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.
|
||||
*/
|
||||
validateLoginForm() {
|
||||
const form = this.data.form
|
||||
/**
|
||||
* `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.loginType === 'password') {
|
||||
if (!form.account.trim() || !form.password) {
|
||||
return '请输入账号和密码'
|
||||
@@ -578,6 +854,10 @@ Page({
|
||||
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.allowLoginShopless && this.data.loginShops.length && !form.shopId) {
|
||||
return '请选择登录门店'
|
||||
}
|
||||
@@ -599,12 +879,24 @@ Page({
|
||||
if (!form.verificationCode.trim()) {
|
||||
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 (!form.password || form.password.length < 6) {
|
||||
return '密码至少 6 位'
|
||||
}
|
||||
/**
|
||||
* `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 (form.password !== form.confirmPassword) {
|
||||
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 (!form.shopId) {
|
||||
return '请选择门店'
|
||||
}
|
||||
@@ -614,6 +906,10 @@ Page({
|
||||
this.checkRegisterPhoneAvailability()
|
||||
])
|
||||
|
||||
/**
|
||||
* `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 (!accountAvailable || !phoneAvailable) {
|
||||
return '请先处理注册信息中的占用问题'
|
||||
}
|
||||
@@ -622,30 +918,45 @@ Page({
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
if (!this.ensureAgreementAccepted()) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
/**
|
||||
* `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.activeTab === 'login') {
|
||||
const loginError = this.validateLoginForm()
|
||||
/**
|
||||
* `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 (loginError) {
|
||||
throw new Error(loginError)
|
||||
}
|
||||
|
||||
let payload
|
||||
await runWithLoading(async () => {
|
||||
const agreementPayload = this.buildAgreementPayload()
|
||||
payload = this.data.loginType === 'phone'
|
||||
? await authApi.phoneLogin({
|
||||
phone: this.data.form.phone.trim(),
|
||||
verificationCode: this.data.form.verificationCode.trim(),
|
||||
shopId: this.data.form.shopId || undefined
|
||||
shopId: this.data.form.shopId || undefined,
|
||||
...agreementPayload
|
||||
})
|
||||
: await authApi.login({
|
||||
account: this.data.form.account.trim(),
|
||||
password: this.data.form.password,
|
||||
rememberMe: true,
|
||||
shopId: this.data.form.shopId || undefined
|
||||
shopId: this.data.form.shopId || undefined,
|
||||
...agreementPayload
|
||||
})
|
||||
})
|
||||
|
||||
@@ -654,6 +965,10 @@ Page({
|
||||
}
|
||||
|
||||
const registerError = await this.validateRegisterForm()
|
||||
/**
|
||||
* `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 (registerError) {
|
||||
throw new Error(registerError)
|
||||
}
|
||||
@@ -664,7 +979,8 @@ Page({
|
||||
nickname: this.data.form.nickname.trim(),
|
||||
phone: this.data.form.phone.trim(),
|
||||
verificationCode: this.data.form.verificationCode.trim(),
|
||||
shopId: this.data.form.shopId
|
||||
shopId: this.data.form.shopId,
|
||||
...this.buildAgreementPayload()
|
||||
}))
|
||||
|
||||
wx.showToast({
|
||||
@@ -708,6 +1024,10 @@ Page({
|
||||
})
|
||||
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 (!form.newPassword || form.newPassword.length < 6) {
|
||||
wx.showToast({
|
||||
title: '新密码至少 6 位',
|
||||
@@ -750,6 +1070,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleWechatMiniUnavailableTap` 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.
|
||||
*/
|
||||
handleWechatMiniUnavailableTap() {
|
||||
wx.showToast({
|
||||
title: this.data.wechatMiniDisabledReason || '请使用账号密码或验证码登录',
|
||||
@@ -758,12 +1082,24 @@ Page({
|
||||
},
|
||||
|
||||
async handleWechatMiniPhoneLogin(event) {
|
||||
if (!this.ensureAgreementAccepted()) {
|
||||
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.wechatMiniSupported || this.data.wechatMiniLoading) {
|
||||
this.handleWechatMiniUnavailableTap()
|
||||
return
|
||||
}
|
||||
|
||||
const detail = 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 (!detail.code) {
|
||||
wx.showToast({
|
||||
title: this.resolveWechatAuthorizeError(detail),
|
||||
@@ -781,7 +1117,8 @@ Page({
|
||||
const result = await runWithLoading(() => authApi.wechatMiniPhoneLogin({
|
||||
wxCode,
|
||||
phoneCode: detail.code,
|
||||
preferredShopId: authStore.getPreferredMiniLoginShopId() || undefined
|
||||
preferredShopId: authStore.getPreferredMiniLoginShopId() || undefined,
|
||||
...this.buildAgreementPayload()
|
||||
}))
|
||||
await this.handleWechatMiniResult(result)
|
||||
} catch (error) {
|
||||
@@ -797,7 +1134,15 @@ Page({
|
||||
},
|
||||
|
||||
async handleConfirmMiniShopLogin() {
|
||||
if (!this.ensureAgreementAccepted()) {
|
||||
return
|
||||
}
|
||||
|
||||
const shop = this.data.miniShops[this.data.miniShopIndex]
|
||||
/**
|
||||
* `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.miniShopTicket) {
|
||||
wx.showToast({
|
||||
title: '登录票据已失效,请重新发起微信登录',
|
||||
@@ -805,6 +1150,10 @@ Page({
|
||||
})
|
||||
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 (!shop || !shop.id) {
|
||||
wx.showToast({
|
||||
title: '请选择门店',
|
||||
@@ -820,8 +1169,13 @@ Page({
|
||||
try {
|
||||
const result = await runWithLoading(() => authApi.confirmWechatMiniLogin({
|
||||
ticket: this.data.miniShopTicket,
|
||||
shopId: shop.id
|
||||
shopId: shop.id,
|
||||
...this.buildAgreementPayload()
|
||||
}))
|
||||
/**
|
||||
* `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 (!result || result.status !== 'SUCCESS') {
|
||||
throw new Error((result && result.message) || '确认登录失败')
|
||||
}
|
||||
@@ -839,6 +1193,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `resolveWechatAuthorizeError` 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.
|
||||
*/
|
||||
resolveWechatAuthorizeError(detail) {
|
||||
const errMsg = String((detail && detail.errMsg) || '')
|
||||
if (errMsg.includes('user deny') || errMsg.includes('user cancel')) {
|
||||
@@ -850,8 +1208,16 @@ Page({
|
||||
return '未获取到微信手机号授权,请稍后重试。'
|
||||
},
|
||||
|
||||
/**
|
||||
* `requestWechatMiniCode` 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.
|
||||
*/
|
||||
requestWechatMiniCode() {
|
||||
const app = getApp()
|
||||
/**
|
||||
* `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 && typeof app.requestWechatMiniCode === 'function') {
|
||||
return app.requestWechatMiniCode()
|
||||
}
|
||||
@@ -859,6 +1225,10 @@ Page({
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
success: res => {
|
||||
/**
|
||||
* `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 (res && res.code) {
|
||||
resolve(res.code)
|
||||
return
|
||||
@@ -871,15 +1241,27 @@ Page({
|
||||
},
|
||||
|
||||
async handleWechatMiniResult(result) {
|
||||
/**
|
||||
* `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 (!result) {
|
||||
throw new 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 (result.status === 'SUCCESS') {
|
||||
await this.finishLogin(result, result.newUser ? '注册并登录成功' : '登录成功')
|
||||
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 (result.status === 'SELECT_SHOP') {
|
||||
this.openMiniShopSelector(result)
|
||||
return
|
||||
@@ -891,9 +1273,17 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `openMiniShopSelector` 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.
|
||||
*/
|
||||
openMiniShopSelector(result) {
|
||||
resetKeyboardSafe(this)
|
||||
const shops = Array.isArray(result && result.shops) ? result.shops : []
|
||||
/**
|
||||
* `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 (!shops.length) {
|
||||
wx.showToast({
|
||||
title: result && result.message ? result.message : '暂无可选门店,请稍后重试',
|
||||
@@ -917,6 +1307,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `clearMiniShopSelector` 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.
|
||||
*/
|
||||
clearMiniShopSelector() {
|
||||
this.setData({
|
||||
showMiniShopSelector: false,
|
||||
@@ -951,10 +1345,22 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `buildAuthHelperText` 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.
|
||||
*/
|
||||
buildAuthHelperText(activeTab, loginType) {
|
||||
/**
|
||||
* `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 (activeTab === 'register') {
|
||||
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 (loginType === 'phone') {
|
||||
return '未注册手机号会先选门店'
|
||||
}
|
||||
|
||||
@@ -37,6 +37,16 @@
|
||||
</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">
|
||||
@@ -216,7 +226,17 @@
|
||||
<text class="aux-link" bindtap="handleToggleResetPanel">忘记密码?</text>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="primary-btn submit-btn" bindtap="handleSubmit">{{activeTab === 'login' ? '立即登录' : '完成注册'}}</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">
|
||||
@@ -303,10 +323,31 @@
|
||||
|
||||
<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>
|
||||
|
||||
@@ -238,6 +238,110 @@
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.submit-btn.disabled {
|
||||
opacity: 0.52;
|
||||
}
|
||||
|
||||
.agreement-row {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 14rpx;
|
||||
margin-top: 22rpx;
|
||||
color: #7a6871;
|
||||
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 #d9b8c4;
|
||||
border-radius: 10rpx;
|
||||
color: #ffffff;
|
||||
font-size: 22rpx;
|
||||
font-weight: 800;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.agreement-check.checked {
|
||||
border-color: #c6597d;
|
||||
background: #c6597d;
|
||||
}
|
||||
|
||||
.agreement-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.agreement-link {
|
||||
color: #c6597d;
|
||||
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(45, 36, 48, 0.42);
|
||||
}
|
||||
|
||||
.agreement-modal {
|
||||
width: 100%;
|
||||
max-width: 690rpx;
|
||||
max-height: 82vh;
|
||||
padding: 30rpx 28rpx;
|
||||
border-radius: 32rpx;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.agreement-modal-title {
|
||||
font-size: 32rpx;
|
||||
line-height: 1.35;
|
||||
font-weight: 800;
|
||||
color: #2d2430;
|
||||
}
|
||||
|
||||
.agreement-modal-meta {
|
||||
margin-top: 10rpx;
|
||||
font-size: 22rpx;
|
||||
color: #9a8590;
|
||||
}
|
||||
|
||||
.agreement-modal-body {
|
||||
height: 640rpx;
|
||||
max-height: 56vh;
|
||||
margin-top: 22rpx;
|
||||
padding: 20rpx;
|
||||
border-radius: 22rpx;
|
||||
background: #fff7f8;
|
||||
color: #5a4a52;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.85;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.agreement-modal-close {
|
||||
margin-top: 22rpx;
|
||||
}
|
||||
|
||||
.mini-shop-mask {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
|
||||
@@ -27,6 +27,10 @@ function getCouponDisplay(coupon) {
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -47,32 +51,56 @@ 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('不同美甲师的项目请分开结算')
|
||||
}
|
||||
@@ -80,6 +108,10 @@ function buildCheckoutIssues(items) {
|
||||
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: {
|
||||
isLoggedIn: false,
|
||||
@@ -98,6 +130,10 @@ Page({
|
||||
submittingOrder: 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() {
|
||||
this.loadCartItems()
|
||||
},
|
||||
@@ -107,14 +143,26 @@ Page({
|
||||
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()
|
||||
@@ -143,6 +191,10 @@ Page({
|
||||
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({
|
||||
cartItems: [],
|
||||
@@ -163,7 +215,10 @@ Page({
|
||||
const availableArtists = Array.isArray(item.availableArtists) ? item.availableArtists.map(artist => ({
|
||||
id: artist.id,
|
||||
name: artist.name,
|
||||
avatar: artist.avatar
|
||||
avatar: artist.avatar,
|
||||
userType: artist.userType,
|
||||
roleLabel: artist.roleLabel,
|
||||
participateProduction: artist.participateProduction
|
||||
})) : []
|
||||
const artist = availableArtists.find(current => String(current.id) === String(item.artistId || ''))
|
||||
|
||||
@@ -204,6 +259,10 @@ Page({
|
||||
|
||||
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: [],
|
||||
@@ -241,9 +300,17 @@ Page({
|
||||
selectedCouponKey = NO_COUPON_KEY
|
||||
}
|
||||
|
||||
/**
|
||||
* `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) {
|
||||
const bestCoupons = list
|
||||
.sort((left, right) => calculateCouponDiscount(right, subtotalAmount) - calculateCouponDiscount(left, subtotalAmount))
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -263,10 +330,18 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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')
|
||||
},
|
||||
@@ -275,6 +350,10 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -296,11 +375,19 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -337,6 +424,10 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -349,6 +440,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -369,8 +464,16 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -384,10 +487,18 @@ Page({
|
||||
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: '当前作品暂时没有可预约美甲师',
|
||||
@@ -398,29 +509,41 @@ Page({
|
||||
|
||||
const tapIndex = await new Promise(resolve => {
|
||||
wx.showActionSheet({
|
||||
itemList: item.availableArtists.map(artist => artist.name),
|
||||
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.name
|
||||
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
|
||||
}
|
||||
@@ -433,10 +556,18 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -449,6 +580,10 @@ Page({
|
||||
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
|
||||
@@ -457,12 +592,20 @@ Page({
|
||||
},
|
||||
|
||||
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],
|
||||
|
||||
@@ -9,6 +9,10 @@ function getBenefitText(coupon) {
|
||||
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: {
|
||||
loading: false,
|
||||
@@ -24,6 +28,10 @@ Page({
|
||||
]
|
||||
},
|
||||
|
||||
/**
|
||||
* `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()
|
||||
},
|
||||
@@ -35,6 +43,10 @@ Page({
|
||||
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: [],
|
||||
@@ -74,11 +86,19 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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') {
|
||||
@@ -93,18 +113,34 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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')
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ const productApi = require('../../api/product')
|
||||
const shopApi = require('../../api/shop')
|
||||
const userApi = require('../../api/user')
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -32,31 +36,52 @@ Page({
|
||||
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)
|
||||
@@ -68,13 +93,25 @@ Page({
|
||||
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,
|
||||
@@ -82,6 +119,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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()
|
||||
@@ -89,6 +130,10 @@ Page({
|
||||
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
|
||||
@@ -118,6 +163,24 @@ Page({
|
||||
} 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 })
|
||||
@@ -126,11 +189,16 @@ Page({
|
||||
try {
|
||||
await Promise.all([
|
||||
this.loadUserProfile(),
|
||||
this.loadAnnouncements(),
|
||||
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
|
||||
@@ -142,6 +210,10 @@ Page({
|
||||
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 })
|
||||
}
|
||||
@@ -166,6 +238,10 @@ Page({
|
||||
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 : []
|
||||
@@ -183,6 +259,10 @@ Page({
|
||||
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 : []
|
||||
@@ -203,6 +283,10 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -215,6 +299,10 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -223,6 +311,10 @@ Page({
|
||||
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
|
||||
@@ -231,20 +323,36 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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({
|
||||
@@ -252,8 +360,16 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -264,7 +380,15 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
@@ -273,8 +397,16 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -284,12 +416,20 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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: '热门'
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
<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 class="summary-metric">
|
||||
<text class="summary-label">门店橱窗</text>
|
||||
|
||||
@@ -94,6 +94,26 @@
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
}
|
||||
|
||||
.announcement-strip {
|
||||
height: 58rpx;
|
||||
margin-top: 18rpx;
|
||||
border-radius: 16rpx;
|
||||
background: #fff7ed;
|
||||
border: 1rpx solid #fed7aa;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.announcement-item {
|
||||
height: 58rpx;
|
||||
line-height: 58rpx;
|
||||
padding: 0 22rpx;
|
||||
font-size: 24rpx;
|
||||
color: #7c2d12;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.banner-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
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({
|
||||
data: {
|
||||
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({
|
||||
@@ -12,10 +20,18 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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()
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
const userApi = require('../../api/user')
|
||||
const navigation = require('../../utils/navigation')
|
||||
|
||||
/**
|
||||
* notifications page logic.
|
||||
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
|
||||
*/
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
messages: [],
|
||||
unreadCount: 0,
|
||||
detailVisible: false,
|
||||
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({
|
||||
messages: list,
|
||||
unreadCount: list.filter(item => item.readStatus !== 1).length
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '消息加载失败',
|
||||
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
|
||||
}
|
||||
this.setData({
|
||||
currentMessage: item,
|
||||
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({
|
||||
title: error.message || '标记已读失败',
|
||||
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({
|
||||
detailVisible: false,
|
||||
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
|
||||
}
|
||||
wx.previewImage({
|
||||
current: imageUrl,
|
||||
urls: [imageUrl]
|
||||
})
|
||||
},
|
||||
|
||||
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="#2d2430" background="#fff7f8"></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: #fff7f8;
|
||||
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: #2d2430;
|
||||
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: #2d2430;
|
||||
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: #2d2430;
|
||||
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: #fff7f8;
|
||||
}
|
||||
@@ -6,6 +6,10 @@ const { resolveLegacyImage } = require('../../utils/file')
|
||||
const { formatDateTime, formatPrice, getOrderStatusClass, getOrderStatusText } = require('../../utils/format')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
/**
|
||||
* orders page logic.
|
||||
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
|
||||
*/
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
@@ -13,6 +17,10 @@ Page({
|
||||
orders: []
|
||||
},
|
||||
|
||||
/**
|
||||
* `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.loadOrders()
|
||||
},
|
||||
@@ -24,6 +32,10 @@ Page({
|
||||
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({
|
||||
orders: [],
|
||||
@@ -39,6 +51,7 @@ Page({
|
||||
...order,
|
||||
statusText: getOrderStatusText(order),
|
||||
statusClass: getOrderStatusClass(order),
|
||||
shopNameText: order.shopName ? `所属店铺:${order.shopName}` : '',
|
||||
actualAmountText: `\u00a5${formatPrice(order.actualAmount)}`,
|
||||
items: await Promise.all((order.items || []).map(async item => ({
|
||||
...item,
|
||||
@@ -66,16 +79,28 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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/orders/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')
|
||||
},
|
||||
|
||||
async handleCancelOrder(event) {
|
||||
const orderId = event.currentTarget.dataset.orderId
|
||||
/**
|
||||
* `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 (!orderId) {
|
||||
return
|
||||
}
|
||||
@@ -90,6 +115,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
</view>
|
||||
<text class="order-status {{item.statusClass}}">{{item.statusText}}</text>
|
||||
</view>
|
||||
<view wx:if="{{item.shopNameText}}" class="order-shop">{{item.shopNameText}}</view>
|
||||
|
||||
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="order-item">
|
||||
<image class="order-thumb" src="{{orderItem.productImageUrl}}" mode="aspectFill" lazy-load="{{true}}"></image>
|
||||
|
||||
@@ -23,6 +23,13 @@
|
||||
border-bottom: 2rpx solid #f3e7eb;
|
||||
}
|
||||
|
||||
.order-shop {
|
||||
margin: 14rpx 0 0;
|
||||
color: #8f6e7a;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.order-head-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
@@ -13,11 +13,19 @@ const { formatPrice, getProductTitle, splitCsv } = require('../../utils/format')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
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
|
||||
}
|
||||
@@ -30,6 +38,10 @@ function parseTimeRange(businessHours) {
|
||||
|
||||
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 || '以门店安排为准'
|
||||
}
|
||||
@@ -43,10 +55,18 @@ function estimateEarliestBookable(businessHours) {
|
||||
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}`
|
||||
}
|
||||
@@ -58,6 +78,10 @@ function estimateEarliestBookable(businessHours) {
|
||||
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: {
|
||||
loading: true,
|
||||
@@ -75,6 +99,10 @@ Page({
|
||||
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 : ''
|
||||
@@ -90,6 +118,10 @@ Page({
|
||||
|
||||
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,
|
||||
@@ -148,6 +180,10 @@ Page({
|
||||
|
||||
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
|
||||
}
|
||||
@@ -166,6 +202,10 @@ Page({
|
||||
|
||||
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
|
||||
@@ -180,12 +220,24 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -196,8 +248,16 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -217,6 +277,10 @@ Page({
|
||||
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)
|
||||
@@ -257,6 +321,10 @@ Page({
|
||||
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)
|
||||
@@ -346,12 +414,20 @@ Page({
|
||||
}
|
||||
,
|
||||
|
||||
/**
|
||||
* `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({
|
||||
@@ -365,6 +441,10 @@ Page({
|
||||
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
|
||||
|
||||
@@ -21,6 +21,10 @@ const ALL_CATEGORY = '\u5168\u90e8'
|
||||
const FILTER_BUSY_MESSAGE = '\u7b5b\u9009\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
|
||||
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
|
||||
@@ -39,6 +43,10 @@ Page({
|
||||
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()
|
||||
@@ -51,6 +59,10 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -58,16 +70,28 @@ Page({
|
||||
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)
|
||||
@@ -78,13 +102,25 @@ Page({
|
||||
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,
|
||||
@@ -127,6 +163,10 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -169,6 +209,10 @@ Page({
|
||||
})
|
||||
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
|
||||
}
|
||||
@@ -183,9 +227,17 @@ Page({
|
||||
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: [],
|
||||
@@ -199,6 +251,10 @@ Page({
|
||||
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,
|
||||
@@ -208,11 +264,23 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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}`)
|
||||
}
|
||||
@@ -220,6 +288,10 @@ Page({
|
||||
return chips.join(' \u00b7 ')
|
||||
},
|
||||
|
||||
/**
|
||||
* `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)
|
||||
},
|
||||
@@ -250,6 +322,10 @@ Page({
|
||||
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 => ({
|
||||
@@ -265,8 +341,16 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -286,16 +370,28 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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)
|
||||
},
|
||||
@@ -372,8 +468,16 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -386,6 +490,10 @@ Page({
|
||||
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
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ const navigation = require('../../utils/navigation')
|
||||
const { DEFAULT_AVATAR } = require('../../utils/config')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
/**
|
||||
* profile page logic.
|
||||
* Call guide: page data drives the WXML template, and each method is called by user events or lifecycle callbacks.
|
||||
*/
|
||||
Page({
|
||||
data: {
|
||||
isLoggedIn: false,
|
||||
@@ -18,9 +22,14 @@ Page({
|
||||
orderCount: 0,
|
||||
couponCount: 0,
|
||||
wishlistCount: 0,
|
||||
unreadMessageCount: 0,
|
||||
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()
|
||||
},
|
||||
@@ -34,6 +43,10 @@ Page({
|
||||
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,
|
||||
@@ -46,11 +59,12 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
const [userInfo, orders, coupons, wishlist] = await Promise.all([
|
||||
const [userInfo, orders, coupons, wishlist, unreadMessages] = await Promise.all([
|
||||
userApi.getUserInfo(),
|
||||
orderApi.getOrderList(),
|
||||
couponApi.listUserCoupons(),
|
||||
wishlistApi.getWishlist()
|
||||
wishlistApi.getWishlist(),
|
||||
userApi.getMyUnreadMessageCount()
|
||||
])
|
||||
|
||||
getApp().refreshUserInfo(userInfo)
|
||||
@@ -58,8 +72,10 @@ Page({
|
||||
userInfo,
|
||||
orderCount: Array.isArray(orders) ? orders.length : 0,
|
||||
couponCount: Array.isArray(coupons) ? coupons.length : 0,
|
||||
wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0
|
||||
wishlistCount: Array.isArray(wishlist) ? wishlist.length : 0,
|
||||
unreadMessageCount: Number((unreadMessages && unreadMessages.unreadCount) || 0)
|
||||
})
|
||||
await this.checkPopupMessages()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '\u4e2a\u4eba\u4e2d\u5fc3\u52a0\u8f7d\u5931\u8d25',
|
||||
@@ -72,11 +88,23 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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')
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
@@ -84,6 +112,10 @@ Page({
|
||||
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
|
||||
@@ -91,6 +123,10 @@ Page({
|
||||
navigation.navigate('/pages/orders/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
@@ -98,6 +134,10 @@ Page({
|
||||
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
|
||||
@@ -105,6 +145,62 @@ Page({
|
||||
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 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)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载待弹窗消息失败', error)
|
||||
} finally {
|
||||
this._checkingPopupMessages = false
|
||||
}
|
||||
},
|
||||
|
||||
async handleSwitchShop() {
|
||||
if (!navigation.ensureLogin('\u5207\u6362\u95e8\u5e97')) {
|
||||
return
|
||||
@@ -114,6 +210,10 @@ Page({
|
||||
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',
|
||||
@@ -122,6 +222,10 @@ Page({
|
||||
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],
|
||||
@@ -140,6 +244,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -168,6 +276,10 @@ Page({
|
||||
},
|
||||
|
||||
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
|
||||
@@ -183,6 +295,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -209,10 +325,18 @@ Page({
|
||||
|
||||
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': ''
|
||||
@@ -225,6 +349,10 @@ Page({
|
||||
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': ''
|
||||
|
||||
@@ -67,6 +67,15 @@
|
||||
<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>
|
||||
|
||||
@@ -161,6 +161,23 @@
|
||||
color: #c3aab4;
|
||||
}
|
||||
|
||||
.menu-badge {
|
||||
margin-left: auto;
|
||||
min-width: 36rpx;
|
||||
height: 36rpx;
|
||||
padding: 0 10rpx;
|
||||
border-radius: 18rpx;
|
||||
background: #ff5c8a;
|
||||
color: #ffffff;
|
||||
font-size: 22rpx;
|
||||
line-height: 36rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.menu-badge + .menu-arrow {
|
||||
margin-left: 16rpx;
|
||||
}
|
||||
|
||||
.logout-item {
|
||||
color: #d5536f;
|
||||
font-weight: 700;
|
||||
|
||||
@@ -18,6 +18,10 @@ const phoneRegex = /^1[3-9]\d{9}$/
|
||||
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
|
||||
const SETTINGS_DRAFT_KEY = 'user-settings'
|
||||
|
||||
/**
|
||||
* settings 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: 108
|
||||
@@ -53,15 +57,27 @@ Page({
|
||||
}
|
||||
}),
|
||||
|
||||
/**
|
||||
* `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.ensureKeyboardSafe()
|
||||
},
|
||||
|
||||
/**
|
||||
* `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.loadSettings()
|
||||
},
|
||||
|
||||
/**
|
||||
* `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)
|
||||
@@ -69,6 +85,10 @@ Page({
|
||||
clearDraftTimer(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)
|
||||
@@ -76,6 +96,10 @@ Page({
|
||||
clearDraftTimer(this)
|
||||
},
|
||||
|
||||
/**
|
||||
* `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: 108,
|
||||
@@ -83,21 +107,41 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleKeyboardFocus` 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.
|
||||
*/
|
||||
handleKeyboardFocus(event) {
|
||||
handleKeyboardFocus(this, event)
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleKeyboardBlur` 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.
|
||||
*/
|
||||
handleKeyboardBlur() {
|
||||
handleKeyboardBlur(this)
|
||||
},
|
||||
|
||||
/**
|
||||
* `clearCountdown` 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.
|
||||
*/
|
||||
clearCountdown() {
|
||||
/**
|
||||
* `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.countdownTimer) {
|
||||
clearInterval(this.countdownTimer)
|
||||
this.countdownTimer = null
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `resetSecurityForms` 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.
|
||||
*/
|
||||
resetSecurityForms() {
|
||||
this.setData({
|
||||
bindPhoneForm: {
|
||||
@@ -116,8 +160,16 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `restoreDraftValues` 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.
|
||||
*/
|
||||
restoreDraftValues() {
|
||||
const draft = getDraftValue(SETTINGS_DRAFT_KEY, null)
|
||||
/**
|
||||
* `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 (!draft || typeof draft !== 'object') {
|
||||
return
|
||||
}
|
||||
@@ -131,6 +183,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `scheduleSettingsDraft` 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.
|
||||
*/
|
||||
scheduleSettingsDraft() {
|
||||
scheduleDraftSave(this, SETTINGS_DRAFT_KEY, () => ({
|
||||
activeSecurityPanel: this.data.activeSecurityPanel,
|
||||
@@ -147,6 +203,10 @@ Page({
|
||||
}))
|
||||
},
|
||||
|
||||
/**
|
||||
* `startCountdown` 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.
|
||||
*/
|
||||
startCountdown() {
|
||||
this.clearCountdown()
|
||||
this.setData({
|
||||
@@ -155,6 +215,10 @@ Page({
|
||||
|
||||
this.countdownTimer = setInterval(() => {
|
||||
const next = this.data.countdown - 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 (next <= 0) {
|
||||
this.clearCountdown()
|
||||
this.setData({
|
||||
@@ -177,6 +241,10 @@ Page({
|
||||
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.clearCountdown()
|
||||
this.setData({
|
||||
@@ -209,14 +277,26 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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')
|
||||
},
|
||||
|
||||
/**
|
||||
* `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/settings/index')
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleFormInput` 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.
|
||||
*/
|
||||
handleFormInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
@@ -225,26 +305,46 @@ Page({
|
||||
this.scheduleSettingsDraft()
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleBindPhoneInput` 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.
|
||||
*/
|
||||
handleBindPhoneInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`bindPhoneForm.${field}`]: event.detail.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 (field === 'phone') {
|
||||
this.scheduleSettingsDraft()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleChangePhoneInput` 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.
|
||||
*/
|
||||
handleChangePhoneInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`changePhoneForm.${field}`]: event.detail.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 (field === 'newPhone') {
|
||||
this.scheduleSettingsDraft()
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `handlePasswordInput` 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.
|
||||
*/
|
||||
handlePasswordInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
@@ -252,6 +352,10 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleToggleSecurityPanel` 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.
|
||||
*/
|
||||
handleToggleSecurityPanel(event) {
|
||||
const panel = event.currentTarget.dataset.panel
|
||||
const nextPanel = this.data.activeSecurityPanel === panel ? '' : panel
|
||||
@@ -265,6 +369,10 @@ Page({
|
||||
this.scheduleSettingsDraft()
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleCloseSecurityPanel` 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.
|
||||
*/
|
||||
handleCloseSecurityPanel() {
|
||||
resetKeyboardSafe(this)
|
||||
this.resetSecurityForms()
|
||||
@@ -312,7 +420,15 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `handleChooseAvatar` 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.
|
||||
*/
|
||||
handleChooseAvatar() {
|
||||
/**
|
||||
* `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.uploadingAvatar) {
|
||||
return
|
||||
}
|
||||
@@ -323,6 +439,10 @@ Page({
|
||||
sourceType: ['album', 'camera'],
|
||||
success: async res => {
|
||||
const filePath = Array.isArray(res.tempFilePaths) ? res.tempFilePaths[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 (!filePath) {
|
||||
return
|
||||
}
|
||||
@@ -353,6 +473,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleDeleteAvatar() {
|
||||
/**
|
||||
* `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.userInfo || !this.data.userInfo.avatar) {
|
||||
return
|
||||
}
|
||||
@@ -365,6 +489,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -395,6 +523,10 @@ Page({
|
||||
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: '当前账号还没有可用门店',
|
||||
@@ -403,6 +535,10 @@ Page({
|
||||
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],
|
||||
@@ -419,6 +555,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -442,6 +582,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleSendBindPhoneCode() {
|
||||
/**
|
||||
* `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.countdown > 0) {
|
||||
return
|
||||
}
|
||||
@@ -456,7 +600,10 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => userApi.sendVerificationCode({ phone }))
|
||||
await runWithLoading(() => userApi.sendVerificationCode({
|
||||
phone,
|
||||
sceneCode: 'USER_BIND_PHONE_SMS_CODE'
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
@@ -482,6 +629,10 @@ Page({
|
||||
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 (!verificationCode) {
|
||||
wx.showToast({
|
||||
title: '请输入验证码',
|
||||
@@ -519,6 +670,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleSendChangePhoneCode() {
|
||||
/**
|
||||
* `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.countdown > 0) {
|
||||
return
|
||||
}
|
||||
@@ -533,7 +688,10 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => userApi.sendVerificationCode({ phone: newPhone }))
|
||||
await runWithLoading(() => userApi.sendVerificationCode({
|
||||
phone: newPhone,
|
||||
sceneCode: 'USER_CHANGE_PHONE_SMS_CODE'
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
@@ -553,6 +711,10 @@ Page({
|
||||
const newPhone = String(this.data.changePhoneForm.newPhone || '').trim()
|
||||
const verificationCode = String(this.data.changePhoneForm.verificationCode || '').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 (!oldPhone) {
|
||||
wx.showToast({
|
||||
title: '请先绑定手机号',
|
||||
@@ -569,6 +731,10 @@ Page({
|
||||
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 (!verificationCode) {
|
||||
wx.showToast({
|
||||
title: '请输入验证码',
|
||||
@@ -607,12 +773,20 @@ Page({
|
||||
},
|
||||
|
||||
async handleSendPasswordCode() {
|
||||
/**
|
||||
* `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.countdown > 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const userInfo = this.data.userInfo || {}
|
||||
const phone = String(userInfo.phone || '').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 (!phone) {
|
||||
wx.showToast({
|
||||
title: '请先绑定手机号',
|
||||
@@ -622,7 +796,10 @@ Page({
|
||||
}
|
||||
|
||||
try {
|
||||
await runWithLoading(() => authApi.sendVerificationCode({ phone }))
|
||||
await runWithLoading(() => authApi.sendVerificationCode({
|
||||
phone,
|
||||
sceneCode: 'USER_CHANGE_PASSWORD_SMS_CODE'
|
||||
}))
|
||||
wx.showToast({
|
||||
title: '验证码已发送',
|
||||
icon: 'none'
|
||||
@@ -642,6 +819,10 @@ Page({
|
||||
const confirmPassword = String(this.data.passwordForm.confirmPassword || '')
|
||||
const userInfo = this.data.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.phone) {
|
||||
wx.showToast({
|
||||
title: '请先绑定手机号',
|
||||
@@ -650,6 +831,10 @@ Page({
|
||||
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 (!verificationCode) {
|
||||
wx.showToast({
|
||||
title: '请输入验证码',
|
||||
@@ -666,6 +851,10 @@ Page({
|
||||
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 (password !== confirmPassword) {
|
||||
wx.showToast({
|
||||
title: '两次输入的密码不一致',
|
||||
@@ -704,6 +893,10 @@ Page({
|
||||
},
|
||||
|
||||
async handleDeactivateAccount() {
|
||||
/**
|
||||
* `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.deactivating) {
|
||||
return
|
||||
}
|
||||
@@ -717,6 +910,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -757,6 +954,10 @@ Page({
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -778,10 +979,18 @@ Page({
|
||||
|
||||
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': ''
|
||||
@@ -794,6 +1003,10 @@ Page({
|
||||
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': ''
|
||||
|
||||
@@ -3,6 +3,10 @@ const navigation = require('../../utils/navigation')
|
||||
const { resolveImageList } = require('../../utils/file')
|
||||
const { DEFAULT_SHOP_IMAGE } = require('../../utils/config')
|
||||
|
||||
/**
|
||||
* 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: {
|
||||
loading: true,
|
||||
@@ -10,9 +14,14 @@ Page({
|
||||
shopId: '',
|
||||
returnTo: '/pages/home/index',
|
||||
shopInfo: null,
|
||||
distanceText: '',
|
||||
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 : '',
|
||||
@@ -27,6 +36,10 @@ Page({
|
||||
},
|
||||
|
||||
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,
|
||||
@@ -45,8 +58,10 @@ Page({
|
||||
const shopImages = await resolveImageList(shopInfo.imageFileIds || shopInfo.coverImageFileId, DEFAULT_SHOP_IMAGE)
|
||||
this.setData({
|
||||
shopInfo,
|
||||
shopImages
|
||||
shopImages,
|
||||
distanceText: ''
|
||||
})
|
||||
this.loadCurrentDistance()
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
loadError: error.message || '门店详情加载失败'
|
||||
@@ -58,12 +73,24 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -74,8 +101,16 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -85,8 +120,16 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -94,5 +137,73 @@ Page({
|
||||
wx.setClipboardData({
|
||||
data: shopInfo.address
|
||||
})
|
||||
},
|
||||
|
||||
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
|
||||
})
|
||||
},
|
||||
|
||||
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'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
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))
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
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`
|
||||
}
|
||||
})
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<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 class="summary-strip shop-summary">
|
||||
<view class="summary-metric">
|
||||
@@ -47,6 +48,11 @@
|
||||
<view class="ghost-btn" bindtap="handleCopyName">复制门店名</view>
|
||||
<view class="ghost-btn" bindtap="handleCopyAddress">复制地址</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>
|
||||
</view>
|
||||
|
||||
<view class="section-block">
|
||||
|
||||
@@ -46,6 +46,13 @@
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.shop-distance {
|
||||
margin-top: 8rpx;
|
||||
color: #8f6e7a;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.shop-summary {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
@@ -77,6 +84,17 @@
|
||||
margin-top: 26rpx;
|
||||
}
|
||||
|
||||
.map-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
gap: 16rpx;
|
||||
margin-top: 18rpx;
|
||||
}
|
||||
|
||||
.map-btn {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.gallery-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
const userApi = require('../../api/user')
|
||||
const navigation = require('../../utils/navigation')
|
||||
|
||||
function money(value) {
|
||||
return Number(value || 0).toFixed(2)
|
||||
}
|
||||
|
||||
function formatTime(value) {
|
||||
return value ? String(value).replace('T', ' ').slice(0, 16) : '--'
|
||||
}
|
||||
|
||||
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({
|
||||
data: {
|
||||
asset: {
|
||||
vipLevel: '普通',
|
||||
balanceText: '0.00',
|
||||
totalRechargeText: '0.00',
|
||||
lastRechargeText: '--',
|
||||
vipStartText: '--',
|
||||
manualOverride: false
|
||||
},
|
||||
history: [],
|
||||
rechargePlans: [],
|
||||
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({
|
||||
asset: {
|
||||
...asset,
|
||||
balanceText: money(asset && asset.balance),
|
||||
totalRechargeText: money(asset && asset.totalRechargeAmount),
|
||||
lastRechargeText: formatTime(asset && asset.lastRechargeTime),
|
||||
vipStartText: formatTime(asset && asset.vipStartTime)
|
||||
},
|
||||
history: (Array.isArray(history) ? history : []).map(item => {
|
||||
const amountNumber = Number(item.amount || 0)
|
||||
return {
|
||||
...item,
|
||||
amountNumber,
|
||||
amountText: `${amountNumber > 0 ? '+' : ''}¥${money(amountNumber)}`,
|
||||
sceneText: sceneText(item.changeScene || item.type),
|
||||
changeTimeText: formatTime(item.changeTime)
|
||||
}
|
||||
}),
|
||||
rechargePlans: (Array.isArray(plans) ? plans : []).map(item => ({
|
||||
...item,
|
||||
amountText: `充 ${money(item.rechargeAmount)} 送 ${money(item.giftAmount)}`
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || 'VIP 信息加载失败',
|
||||
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="#2d2430" background="#fff7f8"></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;
|
||||
}
|
||||
@@ -6,6 +6,10 @@ const navigation = require('../../utils/navigation')
|
||||
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: {
|
||||
loading: false,
|
||||
@@ -13,6 +17,10 @@ Page({
|
||||
wishlist: []
|
||||
},
|
||||
|
||||
/**
|
||||
* `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()
|
||||
},
|
||||
@@ -24,6 +32,10 @@ Page({
|
||||
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({
|
||||
@@ -63,6 +75,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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)
|
||||
},
|
||||
@@ -83,6 +99,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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,
|
||||
@@ -90,8 +110,16 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -114,12 +142,24 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* `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
|
||||
}
|
||||
@@ -132,6 +172,10 @@ Page({
|
||||
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
|
||||
}
|
||||
@@ -174,6 +218,10 @@ Page({
|
||||
|
||||
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
|
||||
}
|
||||
@@ -198,6 +246,10 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* `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')
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ async function buildProductCard(product) {
|
||||
...product,
|
||||
displayTitle: getProductTitle(product),
|
||||
priceText: `¥${formatPrice(product && product.price)}`,
|
||||
metaText: (product && (product.approximateDuration || product.shopName)) || '支持预约',
|
||||
metaText: (product && product.approximateDuration) || '支持预约',
|
||||
shopNameText: product && product.shopName ? `所属店铺:${product.shopName}` : '',
|
||||
coverUrl: images[0],
|
||||
imageUrls: images,
|
||||
tagsPreview: getProductTags(product),
|
||||
|
||||
@@ -36,6 +36,7 @@ function isWhitelistedPath(url) {
|
||||
'/user/phone-login',
|
||||
'/user/wechat-mini/',
|
||||
'/user/reset-password-by-phone',
|
||||
'/legal-agreement/current',
|
||||
'/product/get/',
|
||||
'/product/list/',
|
||||
'/comment/list/product/',
|
||||
|
||||
Reference in New Issue
Block a user