功能:完善门店能力与用户安全配置
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user