Files
JayuCloud/WeChatProgram/admin/pages/coupon-form/index.js

708 lines
38 KiB
JavaScript

/**
* 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: 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: 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')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
/**
* 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: couponId supports index.js by holding or executing the coupon 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.
*/
couponId: '',
/**
* 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: couponTypeOptions supports index.js by holding or executing the coupon type options 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.
*/
couponTypeOptions: ['折扣券', '满减券'],
/**
* Purpose: couponTypeIndex supports index.js by holding or executing the coupon type 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.
*/
couponTypeIndex: 0,
/**
* Purpose: couponTypeLabel supports index.js by holding or executing the coupon type 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.
*/
couponTypeLabel: '折扣券',
/**
* Purpose: vipLevelOptions supports index.js by holding or executing the vip level options 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.
*/
vipLevelOptions: ['普通', '青铜', '白银', '黄金'],
/**
* Purpose: vipLevelIndex supports index.js by holding or executing the vip level 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.
*/
vipLevelIndex: 0,
/**
* Purpose: vipLevelLabel supports index.js by holding or executing the vip level 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.
*/
vipLevelLabel: '普通',
/**
* Purpose: startDate supports index.js by holding or executing the start date 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.
*/
startDate: '',
/**
* Purpose: startTime supports index.js by holding or executing the start time 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.
*/
startTime: '',
/**
* Purpose: endDate supports index.js by holding or executing the end date 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.
*/
endDate: '',
/**
* Purpose: endTime supports index.js by holding or executing the end time 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.
*/
endTime: '',
/**
* Purpose: availableTags supports index.js by holding or executing the available 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.
*/
availableTags: [],
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable 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.
*/
unavailableTags: [],
/**
* 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: couponName supports index.js by holding or executing the coupon name 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.
*/
couponName: '',
/**
* Purpose: couponCode supports index.js by holding or executing the coupon code 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.
*/
couponCode: '',
/**
* Purpose: discountValue supports index.js by holding or executing the discount value 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.
*/
discountValue: '',
/**
* Purpose: minAmount supports index.js by holding or executing the min amount 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.
*/
minAmount: '',
/**
* Purpose: reduceAmount supports index.js by holding or executing the reduce amount 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.
*/
reduceAmount: '',
/**
* Purpose: totalCount supports index.js by holding or executing the total 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.
*/
totalCount: '',
/**
* Purpose: couponScene supports index.js by holding or executing the coupon 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.
*/
couponScene: '',
/**
* Purpose: autoMatch supports index.js by holding or executing the auto match 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.
*/
autoMatch: false
}
},
/**
* 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 currentCoupon = getTempRecord('currentCoupon', null)
this.setData({
mode,
/**
* Purpose: couponId supports index.js by holding or executing the coupon 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.
*/
couponId: options && options.id ? options.id : ''
})
this._selectedAvailableTagIds = []
this._selectedUnavailableTagIds = []
if (mode === 'edit' && currentCoupon) {
const start = format.parseDateTimeToPicker(currentCoupon.startTime)
const end = format.parseDateTimeToPicker(currentCoupon.endTime)
this._selectedAvailableTagIds = Array.isArray(currentCoupon.availableTags) ? currentCoupon.availableTags.map(item => String(item.id)) : []
this._selectedUnavailableTagIds = Array.isArray(currentCoupon.unavailableTags) ? currentCoupon.unavailableTags.map(item => String(item.id)) : []
this._initialShopId = currentCoupon.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: couponName supports index.js by holding or executing the coupon name 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.
*/
couponName: currentCoupon.couponName || '',
/**
* Purpose: couponCode supports index.js by holding or executing the coupon code 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.
*/
couponCode: currentCoupon.couponCode || '',
/**
* Purpose: discountValue supports index.js by holding or executing the discount value 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.
*/
discountValue: currentCoupon.discountValue || '',
/**
* Purpose: minAmount supports index.js by holding or executing the min amount 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.
*/
minAmount: currentCoupon.minAmount || '',
/**
* Purpose: reduceAmount supports index.js by holding or executing the reduce amount 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.
*/
reduceAmount: currentCoupon.reduceAmount || '',
/**
* Purpose: totalCount supports index.js by holding or executing the total 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.
*/
totalCount: currentCoupon.totalCount || '',
/**
* Purpose: couponScene supports index.js by holding or executing the coupon 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.
*/
couponScene: currentCoupon.couponScene || '',
/**
* Purpose: autoMatch supports index.js by holding or executing the auto match 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.
*/
autoMatch: Number(currentCoupon.autoMatch) === 1
},
/**
* Purpose: couponTypeIndex supports index.js by holding or executing the coupon type 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.
*/
couponTypeIndex: Number(currentCoupon.couponType) === 2 ? 1 : 0,
/**
* Purpose: couponTypeLabel supports index.js by holding or executing the coupon type 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.
*/
couponTypeLabel: Number(currentCoupon.couponType) === 2 ? '满减券' : '折扣券',
/**
* Purpose: vipLevelIndex supports index.js by holding or executing the vip level 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.
*/
vipLevelIndex: this.data.vipLevelOptions.findIndex(item => item === (currentCoupon.requiredVipLevel || '普通')),
/**
* Purpose: vipLevelLabel supports index.js by holding or executing the vip level 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.
*/
vipLevelLabel: currentCoupon.requiredVipLevel || '普通',
/**
* Purpose: startDate supports index.js by holding or executing the start date 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.
*/
startDate: start.date,
/**
* Purpose: startTime supports index.js by holding or executing the start time 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.
*/
startTime: start.time,
/**
* Purpose: endDate supports index.js by holding or executing the end date 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.
*/
endDate: end.date,
/**
* Purpose: endTime supports index.js by holding or executing the end time 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.
*/
endTime: end.time
})
}
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('currentCoupon')
},
async loadDependencies() {
const app = getApp()
const currentShop = app.globalData.currentShop
const operator = app.globalData.userInfo || {}
try {
const shopList = await 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 : ''
})
await this.loadTagOptions(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 loadTagOptions(shopId) {
if (!normalizeId(shopId)) {
this._selectedAvailableTagIds = []
this._selectedUnavailableTagIds = []
this.setData({
/**
* Purpose: availableTags supports index.js by holding or executing the available 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.
*/
availableTags: [],
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable 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.
*/
unavailableTags: []
})
return
}
try {
const tagList = await tagApi.listTagsByShopId(shopId)
this._selectedAvailableTagIds = syncSelectedIds(this._selectedAvailableTagIds, tagList)
this._selectedUnavailableTagIds = syncSelectedIds(this._selectedUnavailableTagIds, tagList)
this.setData({
/**
* Purpose: availableTags supports index.js by holding or executing the available 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.
*/
availableTags: buildCheckableList(tagList, this._selectedAvailableTagIds, 'tagName'),
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable 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.
*/
unavailableTags: buildCheckableList(tagList, this._selectedUnavailableTagIds, 'tagName')
})
} catch (error) {
this.setData({
/**
* Purpose: availableTags supports index.js by holding or executing the available 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.
*/
availableTags: [],
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable 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.
*/
unavailableTags: []
})
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
const value = event.detail.value
this.setData({
[`form.${field}`]: value
})
},
/**
* 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 : ''
})
this.loadTagOptions(selectedShop ? selectedShop.id : '')
},
/**
* Purpose: handleCouponTypeChange supports index.js by holding or executing the handle coupon type 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.
*/
handleCouponTypeChange(event) {
const couponTypeIndex = Number(event.detail.value)
this.setData({
couponTypeIndex,
/**
* Purpose: couponTypeLabel supports index.js by holding or executing the coupon type 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.
*/
couponTypeLabel: this.data.couponTypeOptions[couponTypeIndex]
})
},
/**
* Purpose: handleVipLevelChange supports index.js by holding or executing the handle vip level 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.
*/
handleVipLevelChange(event) {
const vipLevelIndex = Number(event.detail.value)
this.setData({
vipLevelIndex,
/**
* Purpose: vipLevelLabel supports index.js by holding or executing the vip level 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.
*/
vipLevelLabel: this.data.vipLevelOptions[vipLevelIndex]
})
},
/**
* Purpose: handleDateTimeChange supports index.js by holding or executing the handle date time 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.
*/
handleDateTimeChange(event) {
const field = event.currentTarget.dataset.field
this.setData({
[field]: event.detail.value
})
},
/**
* Purpose: handleAutoMatchChange supports index.js by holding or executing the handle auto match 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.
*/
handleAutoMatchChange(event) {
this.setData({
'form.autoMatch': event.detail.value
})
},
/**
* Purpose: handleAvailableTagChange supports index.js by holding or executing the handle available 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.
*/
handleAvailableTagChange(event) {
this._selectedAvailableTagIds = event.detail.value || []
this.setData({
/**
* Purpose: availableTags supports index.js by holding or executing the available 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.
*/
availableTags: this.data.availableTags.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._selectedAvailableTagIds.includes(item.valueId)
}))
})
},
/**
* Purpose: handleUnavailableTagChange supports index.js by holding or executing the handle unavailable 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.
*/
handleUnavailableTagChange(event) {
this._selectedUnavailableTagIds = event.detail.value || []
this.setData({
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable 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.
*/
unavailableTags: this.data.unavailableTags.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._selectedUnavailableTagIds.includes(item.valueId)
}))
})
},
async handleSubmit() {
const selectedShop = this.data.shops[this.data.shopIndex]
if (!this.data.form.couponName) {
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 (!selectedShop) {
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: couponCode supports index.js by holding or executing the coupon code 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.
*/
couponCode: this.data.form.couponCode || undefined,
/**
* Purpose: couponName supports index.js by holding or executing the coupon name 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.
*/
couponName: this.data.form.couponName,
/**
* Purpose: couponType supports index.js by holding or executing the coupon type 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.
*/
couponType: this.data.couponTypeIndex === 1 ? 2 : 1,
/**
* Purpose: discountValue supports index.js by holding or executing the discount value 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.
*/
discountValue: this.data.couponTypeIndex === 0 ? Number(this.data.form.discountValue || 0) : undefined,
/**
* Purpose: minAmount supports index.js by holding or executing the min amount 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.
*/
minAmount: this.data.couponTypeIndex === 1 ? Number(this.data.form.minAmount || 0) : undefined,
/**
* Purpose: reduceAmount supports index.js by holding or executing the reduce amount 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.
*/
reduceAmount: this.data.couponTypeIndex === 1 ? Number(this.data.form.reduceAmount || 0) : undefined,
/**
* Purpose: totalCount supports index.js by holding or executing the total 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.
*/
totalCount: this.data.form.totalCount ? Number(this.data.form.totalCount) : undefined,
/**
* Purpose: startTime supports index.js by holding or executing the start time 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.
*/
startTime: format.buildDateTime(this.data.startDate, this.data.startTime),
/**
* Purpose: endTime supports index.js by holding or executing the end time 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.
*/
endTime: format.buildDateTime(this.data.endDate, this.data.endTime),
/**
* 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: selectedShop.id,
/**
* Purpose: couponScene supports index.js by holding or executing the coupon 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.
*/
couponScene: this.data.form.couponScene || undefined,
/**
* Purpose: requiredVipLevel supports index.js by holding or executing the required vip level 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.
*/
requiredVipLevel: this.data.vipLevelLabel || undefined,
/**
* Purpose: autoMatch supports index.js by holding or executing the auto match 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.
*/
autoMatch: this.data.form.autoMatch ? 1 : 0,
/**
* Purpose: availableTagIds supports index.js by holding or executing the available 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.
*/
availableTagIds: this._selectedAvailableTagIds.map(item => Number(item)),
/**
* Purpose: unavailableTagIds supports index.js by holding or executing the unavailable 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.
*/
unavailableTagIds: this._selectedUnavailableTagIds.map(item => Number(item))
}
try {
if (this.data.mode === 'edit') {
await couponApi.updateCoupon(this.data.couponId, payload)
} else {
await couponApi.createCoupon(payload)
}
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/coupons/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'
})
}
}
})