812 lines
41 KiB
JavaScript
812 lines
41 KiB
JavaScript
/**
|
|
* Purpose: productApi supports index.js by holding or executing the product api page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const productApi = require('../../api/product')
|
|
/**
|
|
* Purpose: tagApi supports index.js by holding or executing the tag api page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const tagApi = require('../../api/tag')
|
|
/**
|
|
* Purpose: userApi supports index.js by holding or executing the user api page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const userApi = require('../../api/user')
|
|
/**
|
|
* Purpose: couponApi supports index.js by holding or executing the coupon api page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const couponApi = require('../../api/coupon')
|
|
/**
|
|
* Purpose: shopApi supports index.js by holding or executing the shop api page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const shopApi = require('../../api/shop')
|
|
/**
|
|
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const navigation = require('../../utils/navigation')
|
|
/**
|
|
* Purpose: format supports index.js by holding or executing the format page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const format = require('../../utils/format')
|
|
/**
|
|
* Purpose: cache supports index.js by holding or executing the cache page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const cache = require('../../utils/cache')
|
|
/**
|
|
* Purpose: upload supports index.js by holding or executing the upload page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const upload = require('../../utils/upload')
|
|
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
|
const { getDraftValue, clearDraft, scheduleDraftSave, clearDraftTimer } = require('../../utils/form-draft')
|
|
const { markDirty } = require('../../utils/page-state')
|
|
const { CACHE_TTL } = require('../../utils/config')
|
|
|
|
/**
|
|
* Purpose: DRAFT_KEY supports index.js by holding or executing the draft key page or API role.
|
|
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
const DRAFT_KEY = 'admin-product-form'
|
|
|
|
/**
|
|
* Purpose: normalizeId supports index.js by holding or executing the normalize id page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function normalizeId(value) {
|
|
return value === undefined || value === null ? '' : String(value)
|
|
}
|
|
|
|
/**
|
|
* Purpose: buildCheckableList supports index.js by holding or executing the build checkable list page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function buildCheckableList(list, selectedIds, labelKey) {
|
|
return (Array.isArray(list) ? list : []).map(item => ({
|
|
...item,
|
|
valueId: normalizeId(item.id),
|
|
labelText: item[labelKey],
|
|
checked: selectedIds.includes(normalizeId(item.id))
|
|
}))
|
|
}
|
|
|
|
/**
|
|
* Purpose: syncSelectedIds supports index.js by holding or executing the sync selected ids page or API role.
|
|
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
function syncSelectedIds(selectedIds, list) {
|
|
const availableIds = new Set((Array.isArray(list) ? list : []).map(item => normalizeId(item.id)))
|
|
return (Array.isArray(selectedIds) ? selectedIds : []).filter(id => availableIds.has(normalizeId(id)))
|
|
}
|
|
|
|
Page({
|
|
/**
|
|
* Purpose: data supports index.js by holding or executing the data page or API role.
|
|
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
data: {
|
|
/**
|
|
* Purpose: mode supports index.js by holding or executing the mode page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
mode: 'create',
|
|
/**
|
|
* Purpose: productId supports index.js by holding or executing the product id page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
productId: '',
|
|
/**
|
|
* Purpose: shops supports index.js by holding or executing the shops page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
shops: [],
|
|
/**
|
|
* Purpose: shopIndex supports index.js by holding or executing the shop index page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
shopIndex: 0,
|
|
/**
|
|
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
shopLabel: '',
|
|
/**
|
|
* Purpose: tags supports index.js by holding or executing the tags page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
tags: [],
|
|
/**
|
|
* Purpose: artists supports index.js by holding or executing the artists page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
artists: [],
|
|
/**
|
|
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
coupons: [],
|
|
/**
|
|
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
uploading: false,
|
|
/**
|
|
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
uploadProgress: 0,
|
|
/**
|
|
* Purpose: form supports index.js by holding or executing the form page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
form: {
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: '',
|
|
/**
|
|
* Purpose: description supports index.js by holding or executing the description page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
description: '',
|
|
/**
|
|
* Purpose: targetAudience records who or which scene this product is suitable for.
|
|
* Usage: edit it in the product form and submit it with create/update payloads.
|
|
*/
|
|
targetAudience: '',
|
|
/**
|
|
* Purpose: precautions records service reminders for this product.
|
|
* Usage: edit it in the product form and submit it with create/update payloads.
|
|
*/
|
|
precautions: '',
|
|
/**
|
|
* Purpose: price supports index.js by holding or executing the price page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
price: '',
|
|
/**
|
|
* Purpose: approximateDuration supports index.js by holding or executing the approximate duration page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
approximateDuration: '',
|
|
/**
|
|
* Purpose: likeCount supports index.js by holding or executing the like count page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
likeCount: '',
|
|
/**
|
|
* Purpose: collectCount supports index.js by holding or executing the collect count page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
collectCount: '',
|
|
/**
|
|
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
imageFileIds: [],
|
|
/**
|
|
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
shopId: ''
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
onLoad(options) {
|
|
const mode = options && options.mode ? options.mode : 'create'
|
|
const currentProduct = getTempRecord('currentProduct', null)
|
|
const draft = getDraftValue(DRAFT_KEY, null)
|
|
this.setData({
|
|
mode,
|
|
/**
|
|
* Purpose: productId supports index.js by holding or executing the product id page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
productId: options && options.id ? options.id : ''
|
|
})
|
|
|
|
this._selectedTagIds = []
|
|
this._selectedArtistIds = []
|
|
this._selectedCouponIds = []
|
|
|
|
if (mode === 'edit' && currentProduct) {
|
|
this._selectedTagIds = format.splitCsv(currentProduct.tags)
|
|
this._selectedArtistIds = format.splitCsv(currentProduct.bookableArtists)
|
|
this._selectedCouponIds = format.splitCsv(currentProduct.availableCoupons)
|
|
this._initialShopId = currentProduct.shopId
|
|
this.setData({
|
|
/**
|
|
* Purpose: form supports index.js by holding or executing the form page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
form: {
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: currentProduct.title || '',
|
|
/**
|
|
* Purpose: description supports index.js by holding or executing the description page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
description: currentProduct.description || '',
|
|
/**
|
|
* Purpose: targetAudience restores the existing product suitable-audience text in edit mode.
|
|
* Usage: bind this field to the form textarea and submit it unchanged unless the operator edits it.
|
|
*/
|
|
targetAudience: currentProduct.targetAudience || '',
|
|
/**
|
|
* Purpose: precautions restores the existing product reminder text in edit mode.
|
|
* Usage: bind this field to the form textarea and submit it unchanged unless the operator edits it.
|
|
*/
|
|
precautions: currentProduct.precautions || '',
|
|
/**
|
|
* Purpose: price supports index.js by holding or executing the price page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
price: currentProduct.price || '',
|
|
/**
|
|
* Purpose: approximateDuration supports index.js by holding or executing the approximate duration page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
approximateDuration: currentProduct.approximateDuration || '',
|
|
/**
|
|
* Purpose: likeCount supports index.js by holding or executing the like count page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
likeCount: currentProduct.likeCount || '',
|
|
/**
|
|
* Purpose: collectCount supports index.js by holding or executing the collect count page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
collectCount: currentProduct.collectCount || '',
|
|
/**
|
|
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
imageFileIds: format.splitCsv(currentProduct.imageFileIds),
|
|
/**
|
|
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
shopId: currentProduct.shopId || ''
|
|
}
|
|
})
|
|
}
|
|
|
|
if (draft && draft.mode === mode) {
|
|
this._selectedTagIds = Array.isArray(draft.selectedTagIds) ? draft.selectedTagIds : this._selectedTagIds
|
|
this._selectedArtistIds = Array.isArray(draft.selectedArtistIds) ? draft.selectedArtistIds : this._selectedArtistIds
|
|
this._selectedCouponIds = Array.isArray(draft.selectedCouponIds) ? draft.selectedCouponIds : this._selectedCouponIds
|
|
this._initialShopId = draft.form && draft.form.shopId ? draft.form.shopId : this._initialShopId
|
|
this.setData({
|
|
/**
|
|
* Purpose: form supports index.js by holding or executing the form page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
form: {
|
|
...this.data.form,
|
|
...(draft.form || {})
|
|
}
|
|
})
|
|
}
|
|
|
|
this.loadDependencies()
|
|
},
|
|
|
|
/**
|
|
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
onUnload() {
|
|
clearTempRecord('currentProduct')
|
|
clearDraftTimer(this)
|
|
},
|
|
|
|
/**
|
|
* Purpose: scheduleProductDraft supports index.js by holding or executing the schedule product draft page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
scheduleProductDraft() {
|
|
scheduleDraftSave(this, DRAFT_KEY, () => ({
|
|
/**
|
|
* Purpose: mode supports index.js by holding or executing the mode page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
mode: this.data.mode,
|
|
/**
|
|
* Purpose: form supports index.js by holding or executing the form page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
form: {
|
|
...this.data.form,
|
|
/**
|
|
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
imageFileIds: this.data.form.imageFileIds.slice()
|
|
},
|
|
/**
|
|
* Purpose: selectedTagIds supports index.js by holding or executing the selected tag ids page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
selectedTagIds: this._selectedTagIds.slice(),
|
|
/**
|
|
* Purpose: selectedArtistIds supports index.js by holding or executing the selected artist ids page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
selectedArtistIds: this._selectedArtistIds.slice(),
|
|
/**
|
|
* Purpose: selectedCouponIds supports index.js by holding or executing the selected coupon ids page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
selectedCouponIds: this._selectedCouponIds.slice()
|
|
}))
|
|
},
|
|
|
|
async loadDependencies() {
|
|
const app = getApp()
|
|
const currentShop = app.globalData.currentShop
|
|
const operator = app.globalData.userInfo || {}
|
|
|
|
try {
|
|
const shopList = await cache.remember('admin:shops:all', CACHE_TTL.dict, () => shopApi.listAllShops())
|
|
|
|
let shops = Array.isArray(shopList) ? shopList : []
|
|
if (Number(operator.type) !== 4 && currentShop) {
|
|
shops = shops.filter(item => normalizeId(item.id) === normalizeId(currentShop.id))
|
|
}
|
|
|
|
let shopIndex = 0
|
|
if (this._initialShopId) {
|
|
const index = shops.findIndex(item => normalizeId(item.id) === normalizeId(this._initialShopId))
|
|
if (index >= 0) {
|
|
shopIndex = index
|
|
}
|
|
}
|
|
const selectedShop = shops[shopIndex]
|
|
|
|
this.setData({
|
|
shops,
|
|
shopIndex,
|
|
/**
|
|
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
shopLabel: selectedShop ? selectedShop.shopName : '',
|
|
'form.shopId': selectedShop ? selectedShop.id : ''
|
|
})
|
|
|
|
await this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
|
} catch (error) {
|
|
wx.showToast({
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: error.message || '初始化作品表单失败',
|
|
/**
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
icon: 'none'
|
|
})
|
|
}
|
|
},
|
|
|
|
async loadShopScopedOptions(shopId) {
|
|
if (!normalizeId(shopId)) {
|
|
this._selectedTagIds = []
|
|
this._selectedArtistIds = []
|
|
this._selectedCouponIds = []
|
|
this.setData({
|
|
/**
|
|
* Purpose: tags supports index.js by holding or executing the tags page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
tags: [],
|
|
/**
|
|
* Purpose: artists supports index.js by holding or executing the artists page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
artists: [],
|
|
/**
|
|
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
coupons: []
|
|
})
|
|
return
|
|
}
|
|
|
|
try {
|
|
const [tagList, artistList, couponList] = await Promise.all([
|
|
tagApi.listTagsByShopId(shopId),
|
|
userApi.listArtists(shopId),
|
|
couponApi.listAllCoupons(shopId)
|
|
])
|
|
|
|
this._selectedTagIds = syncSelectedIds(this._selectedTagIds, tagList)
|
|
this._selectedArtistIds = syncSelectedIds(this._selectedArtistIds, artistList)
|
|
this._selectedCouponIds = syncSelectedIds(this._selectedCouponIds, couponList)
|
|
|
|
this.setData({
|
|
/**
|
|
* Purpose: tags supports index.js by holding or executing the tags page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
tags: buildCheckableList(tagList, this._selectedTagIds, 'tagName'),
|
|
/**
|
|
* Purpose: artists supports index.js by holding or executing the artists page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
artists: buildCheckableList(artistList, this._selectedArtistIds, 'nickname'),
|
|
/**
|
|
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
coupons: buildCheckableList(couponList, this._selectedCouponIds, 'couponName')
|
|
})
|
|
this.scheduleProductDraft()
|
|
} catch (error) {
|
|
this.setData({
|
|
/**
|
|
* Purpose: tags supports index.js by holding or executing the tags page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
tags: [],
|
|
/**
|
|
* Purpose: artists supports index.js by holding or executing the artists page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
artists: [],
|
|
/**
|
|
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
coupons: []
|
|
})
|
|
wx.showToast({
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: error.message || '店铺关联数据加载失败',
|
|
/**
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
icon: 'none'
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleInputChange supports index.js by holding or executing the handle input change page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
handleInputChange(event) {
|
|
const field = event.currentTarget.dataset.field
|
|
this.setData({
|
|
[`form.${field}`]: event.detail.value
|
|
})
|
|
this.scheduleProductDraft()
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleShopChange supports index.js by holding or executing the handle shop change page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
handleShopChange(event) {
|
|
const shopIndex = Number(event.detail.value)
|
|
const selectedShop = this.data.shops[shopIndex]
|
|
this.setData({
|
|
shopIndex,
|
|
/**
|
|
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
shopLabel: selectedShop ? selectedShop.shopName : '',
|
|
'form.shopId': selectedShop ? selectedShop.id : ''
|
|
})
|
|
this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
|
this.scheduleProductDraft()
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleTagChange supports index.js by holding or executing the handle tag change page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
handleTagChange(event) {
|
|
this._selectedTagIds = event.detail.value || []
|
|
this.setData({
|
|
/**
|
|
* Purpose: tags supports index.js by holding or executing the tags page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
tags: this.data.tags.map(item => ({
|
|
...item,
|
|
/**
|
|
* Purpose: checked supports index.js by holding or executing the checked page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
checked: this._selectedTagIds.includes(item.valueId)
|
|
}))
|
|
})
|
|
this.scheduleProductDraft()
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleArtistChange supports index.js by holding or executing the handle artist change page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
handleArtistChange(event) {
|
|
this._selectedArtistIds = event.detail.value || []
|
|
this.setData({
|
|
/**
|
|
* Purpose: artists supports index.js by holding or executing the artists page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
artists: this.data.artists.map(item => ({
|
|
...item,
|
|
/**
|
|
* Purpose: checked supports index.js by holding or executing the checked page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
checked: this._selectedArtistIds.includes(item.valueId)
|
|
}))
|
|
})
|
|
this.scheduleProductDraft()
|
|
},
|
|
|
|
/**
|
|
* Purpose: handleCouponChange supports index.js by holding or executing the handle coupon change page or API role.
|
|
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
handleCouponChange(event) {
|
|
this._selectedCouponIds = event.detail.value || []
|
|
this.setData({
|
|
/**
|
|
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
coupons: this.data.coupons.map(item => ({
|
|
...item,
|
|
/**
|
|
* Purpose: checked supports index.js by holding or executing the checked page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
checked: this._selectedCouponIds.includes(item.valueId)
|
|
}))
|
|
})
|
|
this.scheduleProductDraft()
|
|
},
|
|
|
|
async handleUploadImages() {
|
|
try {
|
|
const files = await upload.chooseImageFiles({ count: 9 })
|
|
this.setData({
|
|
/**
|
|
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
uploading: true,
|
|
/**
|
|
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
uploadProgress: 0
|
|
})
|
|
const result = await upload.uploadImageFiles({
|
|
files,
|
|
/**
|
|
* Purpose: scene supports index.js by holding or executing the scene page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
scene: 'admin-product-image',
|
|
/**
|
|
* Purpose: onProgress supports index.js by holding or executing the on progress page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
onProgress: progress => {
|
|
this.setData({
|
|
/**
|
|
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
uploadProgress: Math.round(progress)
|
|
})
|
|
}
|
|
})
|
|
|
|
this.setData({
|
|
'form.imageFileIds': this.data.form.imageFileIds.concat(result.map(item => String(item.id)))
|
|
})
|
|
this.scheduleProductDraft()
|
|
} catch (error) {
|
|
wx.showToast({
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: error.message || '图片上传失败',
|
|
/**
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
icon: 'none'
|
|
})
|
|
} finally {
|
|
this.setData({
|
|
/**
|
|
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
uploading: false
|
|
})
|
|
}
|
|
},
|
|
|
|
async handleSubmit() {
|
|
if (!this.data.form.title) {
|
|
wx.showToast({
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: '请输入作品标题',
|
|
/**
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
if (!this.data.form.shopId) {
|
|
wx.showToast({
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: '请选择所属店铺',
|
|
/**
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
if (!this.data.form.price) {
|
|
wx.showToast({
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: '请输入作品价格',
|
|
/**
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
icon: 'none'
|
|
})
|
|
return
|
|
}
|
|
|
|
const payload = {
|
|
/**
|
|
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
shopId: this.data.form.shopId || undefined,
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: this.data.form.title,
|
|
/**
|
|
* Purpose: description supports index.js by holding or executing the description page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
description: this.data.form.description || undefined,
|
|
/**
|
|
* Purpose: targetAudience sends the optional suitable-audience text to the backend.
|
|
* Usage: leave it undefined when empty so old products can hide the section on user detail pages.
|
|
*/
|
|
targetAudience: this.data.form.targetAudience || undefined,
|
|
/**
|
|
* Purpose: precautions sends the optional reminder text to the backend.
|
|
* Usage: leave it undefined when empty so old products can hide the section on user detail pages.
|
|
*/
|
|
precautions: this.data.form.precautions || undefined,
|
|
/**
|
|
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
imageFileIds: this.data.form.imageFileIds.join(',') || undefined,
|
|
/**
|
|
* Purpose: price supports index.js by holding or executing the price page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
price: Number(this.data.form.price),
|
|
/**
|
|
* Purpose: tags supports index.js by holding or executing the tags page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
tags: this._selectedTagIds.join(',') || undefined,
|
|
/**
|
|
* Purpose: likeCount supports index.js by holding or executing the like count page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
likeCount: this.data.form.likeCount ? Number(this.data.form.likeCount) : undefined,
|
|
/**
|
|
* Purpose: collectCount supports index.js by holding or executing the collect count page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
collectCount: this.data.form.collectCount ? Number(this.data.form.collectCount) : undefined,
|
|
/**
|
|
* Purpose: approximateDuration supports index.js by holding or executing the approximate duration page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
approximateDuration: this.data.form.approximateDuration || undefined,
|
|
/**
|
|
* Purpose: bookableArtists supports index.js by holding or executing the bookable artists page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
bookableArtists: this._selectedArtistIds.join(',') || undefined,
|
|
/**
|
|
* Purpose: availableCoupons supports index.js by holding or executing the available coupons page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
availableCoupons: this._selectedCouponIds.join(',') || undefined
|
|
}
|
|
|
|
try {
|
|
if (this.data.mode === 'edit') {
|
|
await productApi.updateProduct(this.data.productId, payload)
|
|
} else {
|
|
await productApi.createProduct(payload)
|
|
}
|
|
clearDraft(DRAFT_KEY)
|
|
markDirty('admin-products')
|
|
wx.showToast({
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: this.data.mode === 'edit' ? '作品已更新' : '作品已创建',
|
|
/**
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
icon: 'none'
|
|
})
|
|
navigation.goBack('/pages/products/index')
|
|
} catch (error) {
|
|
wx.showToast({
|
|
/**
|
|
* Purpose: title supports index.js by holding or executing the title page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
title: error.message || '保存失败',
|
|
/**
|
|
* Purpose: icon supports index.js by holding or executing the icon page or API role.
|
|
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
|
|
*/
|
|
icon: 'none'
|
|
})
|
|
}
|
|
}
|
|
})
|