功能:重建指尖管理师规划系统

This commit is contained in:
xiaowang
2026-06-04 16:39:06 +08:00
parent 73483e7b0c
commit 677890f518
413 changed files with 9602 additions and 795 deletions
@@ -0,0 +1,166 @@
const afterSaleApi = require('../../api/after-sale')
const navigation = require('../../utils/navigation')
const permission = require('../../utils/permission')
const format = require('../../utils/format')
const { markDirty } = require('../../utils/page-state')
const STATUS_OPTIONS = [
{ label: '全部', value: '' },
{ label: '待处理', value: 'PENDING' },
{ label: '已同意', value: 'APPROVED' },
{ label: '已驳回', value: 'REJECTED' }
]
function safeList(response) {
if (Array.isArray(response && response.list)) {
return response.list
}
if (Array.isArray(response && response.records)) {
return response.records
}
return []
}
function statusText(status) {
if (status === 'PENDING') {
return '待处理'
}
if (status === 'APPROVED') {
return '已同意'
}
if (status === 'REJECTED') {
return '已驳回'
}
return status || '--'
}
Page({
data: {
loading: false,
list: [],
total: 0,
status: 'PENDING',
statusOptions: STATUS_OPTIONS,
canAudit: false
},
onShow() {
if (!navigation.ensureLogin('进入售后处理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
canAudit: permission.hasPermission(permissionCodes, 'after_sale:audit')
})
this.loadAfterSales()
},
onPullDownRefresh() {
this.loadAfterSales().finally(() => {
wx.stopPullDownRefresh()
})
},
async loadAfterSales() {
this.setData({ loading: true })
try {
const response = await afterSaleApi.listAfterSales({
page: 1,
size: 20,
status: this.data.status || undefined
})
this.setData({
list: safeList(response).map(item => this.formatAfterSale(item)),
total: Number(response && response.total) || 0
})
} catch (error) {
wx.showToast({
title: error.message || '售后加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
formatAfterSale(item) {
return {
...item,
displayCreateTime: format.formatDateTime(item.createTime),
displayAuditTime: format.formatDateTime(item.auditTime),
displayRefundAmount: format.formatPrice(item.refundAmount),
statusText: statusText(item.status)
}
},
handleStatusChange(event) {
this.setData({
status: event.currentTarget.dataset.status || ''
})
this.loadAfterSales()
},
promptReason(title) {
return new Promise(resolve => {
wx.showModal({
title,
content: '可填写处理说明,留空也可以提交。',
editable: true,
placeholderText: '处理说明',
confirmText: '提交',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
},
async handleAudit(event) {
if (!this.data.canAudit) {
wx.showToast({
title: '当前账号没有处理售后权限',
icon: 'none'
})
return
}
const id = event.currentTarget.dataset.id
const action = event.currentTarget.dataset.action
if (!id || !action) {
return
}
const reason = await this.promptReason(action === 'approve' ? '同意售后' : '驳回售后')
if (reason === null) {
return
}
try {
const data = {
auditReason: reason
}
if (action === 'approve') {
await afterSaleApi.approveAfterSale(id, data)
} else {
await afterSaleApi.rejectAfterSale(id, data)
}
markDirty('admin-workbench')
wx.showToast({
title: '售后已处理',
icon: 'none'
})
this.loadAfterSales()
} catch (error) {
wx.showToast({
title: error.message || '售后处理失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,62 @@
<navigation-bar title="售后处理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">After Sale</text>
<text class="hero-title">售后处理</text>
<text class="hero-desc">查看待处理退款/售后申请,在手机端完成同意或驳回的最小闭环。</text>
</view>
<view class="surface-card">
<text class="section-title">状态筛选</text>
<view class="chip-row">
<block wx:for="{{statusOptions}}" wx:key="value">
<view class="chip-btn {{status === item.value ? 'active' : ''}}" data-status="{{item.value}}" bindtap="handleStatusChange">{{item.label}}</view>
</block>
</view>
<text class="section-desc">共 {{total}} 条记录</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.afterSaleNo || ('售后 #' + item.id)}}</text>
<text class="list-subtitle">订单 {{item.orderId || '--'}} · {{item.displayCreateTime || '--'}}</text>
</view>
<text class="{{item.status === 'PENDING' ? 'badge' : 'soft-badge'}}">{{item.statusText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">类型</text>
<text class="meta-value">{{item.type || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">退款金额</text>
<text class="meta-value">¥{{item.displayRefundAmount}}</text>
</view>
<view class="meta-item">
<text class="meta-label">用户 ID</text>
<text class="meta-value">{{item.userId || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">审核时间</text>
<text class="meta-value">{{item.displayAuditTime || '--'}}</text>
</view>
</view>
<view wx:if="{{item.reason}}" class="hint-card">{{item.reason}}</view>
<view wx:if="{{item.auditReason}}" class="hint-card">处理说明:{{item.auditReason}}</view>
<view wx:if="{{item.status === 'PENDING'}}" class="list-actions">
<view class="mini-btn primary" data-id="{{item.id}}" data-action="approve" bindtap="handleAudit">同意</view>
<view class="mini-btn danger" data-id="{{item.id}}" data-action="reject" bindtap="handleAudit">驳回</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无售后单</text>
<text class="empty-desc">当前状态下没有需要展示的售后记录。</text>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,728 @@
/**
* Purpose: artistApi supports index.js by holding or executing the artist 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 artistApi = require('../../api/nail-artist')
/**
* 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: 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: 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: 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)))
}
/**
* Purpose: filterProductsByShop supports index.js by holding or executing the filter products by shop 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 filterProductsByShop(products, shopId) {
const targetShopId = normalizeId(shopId)
if (!targetShopId) {
return []
}
return (Array.isArray(products) ? products : []).filter(item => normalizeId(item.shopId) === targetShopId)
}
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: userId supports index.js by holding or executing the user 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.
*/
userId: '',
/**
* 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: statusOptions supports index.js by holding or executing the status 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.
*/
statusOptions: ['营业中', '休息中'],
/**
* Purpose: statusIndex supports index.js by holding or executing the status 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.
*/
statusIndex: 0,
/**
* Purpose: userForm supports index.js by holding or executing the user 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.
*/
userForm: {
/**
* Purpose: nickname supports index.js by holding or executing the nickname 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.
*/
nickname: '',
/**
* Purpose: account supports index.js by holding or executing the account 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.
*/
account: '',
/**
* Purpose: phone supports index.js by holding or executing the phone 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.
*/
phone: '',
/**
* Purpose: password supports index.js by holding or executing the password 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.
*/
password: '',
/**
* Purpose: signature supports index.js by holding or executing the signature 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.
*/
signature: ''
},
/**
* Purpose: artistForm supports index.js by holding or executing the artist 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.
*/
artistForm: {
/**
* Purpose: identity supports index.js by holding or executing the identity 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.
*/
identity: '',
/**
* Purpose: experience supports index.js by holding or executing the experience 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.
*/
experience: '',
/**
* Purpose: rating supports index.js by holding or executing the rating 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.
*/
rating: '',
/**
* Purpose: portfolioText supports index.js by holding or executing the portfolio text 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.
*/
portfolioText: ''
},
/**
* 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: products supports index.js by holding or executing the products 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.
*/
products: []
},
/**
* 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 currentArtist = getTempRecord('currentArtist', null)
this.setData({
mode,
/**
* Purpose: userId supports index.js by holding or executing the user 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.
*/
userId: options && options.userId ? options.userId : ''
})
this._selectedTagIds = []
this._selectedProductIds = []
this._allProducts = []
if (mode === 'edit' && currentArtist) {
this._selectedTagIds = format.splitCsv(currentArtist.skills)
this._selectedProductIds = format.splitCsv(currentArtist.portfolio)
this._initialShopId = currentArtist.shopId
this.setData({
/**
* Purpose: artistForm supports index.js by holding or executing the artist 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.
*/
artistForm: {
/**
* Purpose: identity supports index.js by holding or executing the identity 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.
*/
identity: currentArtist.identity || '',
/**
* Purpose: experience supports index.js by holding or executing the experience 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.
*/
experience: currentArtist.experience || '',
/**
* Purpose: rating supports index.js by holding or executing the rating 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.
*/
rating: currentArtist.rating || '',
/**
* Purpose: portfolioText supports index.js by holding or executing the portfolio text 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.
*/
portfolioText: ''
},
/**
* Purpose: userForm supports index.js by holding or executing the user 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.
*/
userForm: {
/**
* Purpose: nickname supports index.js by holding or executing the nickname 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.
*/
nickname: currentArtist.nickname || '',
/**
* Purpose: account supports index.js by holding or executing the account 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.
*/
account: '',
/**
* Purpose: phone supports index.js by holding or executing the phone 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.
*/
phone: '',
/**
* Purpose: password supports index.js by holding or executing the password 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.
*/
password: '',
/**
* Purpose: signature supports index.js by holding or executing the signature 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.
*/
signature: currentArtist.signature || ''
},
/**
* Purpose: statusIndex supports index.js by holding or executing the status 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.
*/
statusIndex: Number(currentArtist.status) === 0 ? 1 : 0
})
}
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('currentArtist')
},
async loadDependencies() {
const app = getApp()
const currentShop = app.globalData.currentShop
const operator = app.globalData.userInfo || {}
try {
const [shops, products, users] = await Promise.all([
shopApi.listAllShops(),
productApi.listAllProducts(),
userApi.listAllUsers()
])
let availableShops = Array.isArray(shops) ? shops : []
if (Number(operator.type) !== 4 && currentShop) {
availableShops = availableShops.filter(item => normalizeId(item.id) === normalizeId(currentShop.id))
}
let shopIndex = 0
if (this._initialShopId) {
const index = availableShops.findIndex(item => normalizeId(item.id) === normalizeId(this._initialShopId))
if (index >= 0) {
shopIndex = index
}
}
const selectedShop = availableShops[shopIndex]
this._allProducts = Array.isArray(products) ? products : []
if (this.data.mode === 'edit') {
const userRecord = (Array.isArray(users) ? users : []).find(item => normalizeId(item.id) === normalizeId(this.data.userId))
if (userRecord) {
this.setData({
/**
* Purpose: userForm supports index.js by holding or executing the user 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.
*/
userForm: {
/**
* Purpose: nickname supports index.js by holding or executing the nickname 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.
*/
nickname: userRecord.nickname || '',
/**
* Purpose: account supports index.js by holding or executing the account 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.
*/
account: userRecord.account || '',
/**
* Purpose: phone supports index.js by holding or executing the phone 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.
*/
phone: userRecord.phone || '',
/**
* Purpose: password supports index.js by holding or executing the password 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.
*/
password: '',
/**
* Purpose: signature supports index.js by holding or executing the signature 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.
*/
signature: userRecord.signature || ''
}
})
}
}
this.setData({
/**
* 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: availableShops,
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.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._selectedProductIds = []
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: products supports index.js by holding or executing the products 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.
*/
products: []
})
return
}
try {
const tagList = await tagApi.listTagsByShopId(shopId)
const productList = filterProductsByShop(this._allProducts, shopId)
this._selectedTagIds = syncSelectedIds(this._selectedTagIds, tagList)
this._selectedProductIds = syncSelectedIds(this._selectedProductIds, productList)
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: products supports index.js by holding or executing the products 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.
*/
products: buildCheckableList(productList, this._selectedProductIds, 'title')
})
} 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: products supports index.js by holding or executing the products 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.
*/
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: 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: handleUserInput supports index.js by holding or executing the handle user input 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.
*/
handleUserInput(event) {
const field = event.currentTarget.dataset.field
let value = event.detail.value
if (field === 'account') {
value = String(value || '').replace(/[^A-Za-z0-9]/g, '')
}
if (field === 'phone') {
value = String(value || '').replace(/[^\d]/g, '').slice(0, 11)
}
this.setData({
[`userForm.${field}`]: value
})
},
/**
* Purpose: handleArtistInput supports index.js by holding or executing the handle artist input 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.
*/
handleArtistInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`artistForm.${field}`]: event.detail.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.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
},
/**
* Purpose: handleStatusChange supports index.js by holding or executing the handle status 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.
*/
handleStatusChange(event) {
this.setData({
/**
* Purpose: statusIndex supports index.js by holding or executing the status 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.
*/
statusIndex: Number(event.detail.value)
})
},
/**
* 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)
}))
})
},
/**
* Purpose: handleProductChange supports index.js by holding or executing the handle product 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.
*/
handleProductChange(event) {
this._selectedProductIds = event.detail.value || []
this.setData({
/**
* Purpose: products supports index.js by holding or executing the products 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.
*/
products: this.data.products.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._selectedProductIds.includes(item.valueId)
}))
})
},
/**
* Purpose: validateForm supports index.js by holding or executing the validate form 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.
*/
validateForm() {
if (!this.data.userForm.nickname) {
return '请输入美甲师昵称'
}
if (!this.data.userForm.account) {
return '请输入账号'
}
if (!this.data.userForm.phone || this.data.userForm.phone.length !== 11) {
return '请输入 11 位手机号'
}
if (this.data.mode === 'create' && !this.data.userForm.password) {
return '新增美甲师时必须设置密码'
}
if (!this.data.shops[this.data.shopIndex]) {
return '请选择所属店铺'
}
return ''
},
async handleSubmit() {
const errorMessage = this.validateForm()
if (errorMessage) {
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: errorMessage,
/**
* 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 selectedShop = this.data.shops[this.data.shopIndex]
const userPayload = {
/**
* Purpose: nickname supports index.js by holding or executing the nickname 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.
*/
nickname: this.data.userForm.nickname,
/**
* Purpose: account supports index.js by holding or executing the account 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.
*/
account: this.data.userForm.account,
/**
* Purpose: phone supports index.js by holding or executing the phone 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.
*/
phone: this.data.userForm.phone,
/**
* Purpose: signature supports index.js by holding or executing the signature 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.
*/
signature: this.data.userForm.signature || undefined,
/**
* Purpose: type supports index.js by holding or executing the 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.
*/
type: 3,
/**
* Purpose: shopIds supports index.js by holding or executing the shop 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.
*/
shopIds: selectedShop ? [Number(selectedShop.id)] : []
}
if (this.data.userForm.password) {
userPayload.password = this.data.userForm.password
}
try {
let targetUserId = this.data.userId
if (this.data.mode === 'edit') {
await userApi.updateUser(targetUserId, userPayload)
} else {
targetUserId = await userApi.createUser(userPayload)
}
await artistApi.saveNailArtistInfo({
/**
* Purpose: userId supports index.js by holding or executing the user 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.
*/
userId: Number(targetUserId),
/**
* Purpose: identity supports index.js by holding or executing the identity 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.
*/
identity: this.data.artistForm.identity || undefined,
/**
* Purpose: experience supports index.js by holding or executing the experience 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.
*/
experience: this.data.artistForm.experience ? Number(this.data.artistForm.experience) : 0,
/**
* Purpose: skills supports index.js by holding or executing the skills 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.
*/
skills: this._selectedTagIds.join(',') || undefined,
/**
* Purpose: rating supports index.js by holding or executing the rating 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.
*/
rating: this.data.artistForm.rating ? Number(this.data.artistForm.rating) : 0,
/**
* Purpose: status supports index.js by holding or executing the status 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.
*/
status: this.data.statusIndex === 1 ? 0 : 1,
/**
* Purpose: portfolio supports index.js by holding or executing the portfolio 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.
*/
portfolio: this._selectedProductIds.join(',') || undefined,
/**
* Purpose: nickname supports index.js by holding or executing the nickname 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.
*/
nickname: this.data.userForm.nickname,
/**
* 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 ? Number(selectedShop.id) : undefined,
/**
* Purpose: signature supports index.js by holding or executing the signature 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.
*/
signature: this.data.userForm.signature || undefined
})
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/artists/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'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,82 @@
<navigation-bar title="{{mode === 'edit' ? '编辑美甲师' : '新增美甲师'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">账号信息</text>
<view class="field-group">
<text class="field-label">昵称</text>
<input class="field-input" value="{{userForm.nickname}}" data-field="nickname" bindinput="handleUserInput"></input>
</view>
<view class="field-group">
<text class="field-label">账号</text>
<input class="field-input" value="{{userForm.account}}" data-field="account" bindinput="handleUserInput"></input>
</view>
<view class="field-group">
<text class="field-label">手机号</text>
<input class="field-input" type="number" value="{{userForm.phone}}" data-field="phone" bindinput="handleUserInput"></input>
</view>
<view class="field-group">
<text class="field-label">{{mode === 'edit' ? '密码(留空则不修改)' : '登录密码'}}</text>
<input class="field-input" password value="{{userForm.password}}" data-field="password" bindinput="handleUserInput"></input>
</view>
<view class="field-group">
<text class="field-label">签名</text>
<textarea class="field-textarea" value="{{userForm.signature}}" data-field="signature" bindinput="handleUserInput"></textarea>
</view>
<view class="field-group">
<text class="field-label">所属店铺</text>
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
</picker>
</view>
</view>
<view class="surface-card">
<text class="section-title">职业信息</text>
<view class="field-group">
<text class="field-label">身份标签</text>
<input class="field-input" value="{{artistForm.identity}}" data-field="identity" bindinput="handleArtistInput"></input>
</view>
<view class="field-group">
<text class="field-label">从业年限</text>
<input class="field-input" type="number" value="{{artistForm.experience}}" data-field="experience" bindinput="handleArtistInput"></input>
</view>
<view class="field-group">
<text class="field-label">评分</text>
<input class="field-input" type="digit" value="{{artistForm.rating}}" data-field="rating" bindinput="handleArtistInput"></input>
</view>
<view class="field-group">
<text class="field-label">营业状态</text>
<picker mode="selector" range="{{statusOptions}}" value="{{statusIndex}}" bindchange="handleStatusChange">
<view class="field-picker">{{statusOptions[statusIndex]}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">擅长标签</text>
<checkbox-group bindchange="handleTagChange">
<block wx:for="{{tags}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="field-group">
<text class="field-label">作品集</text>
<checkbox-group bindchange="handleProductChange">
<block wx:for="{{products}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存美甲师</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
+119
View File
@@ -0,0 +1,119 @@
/**
* Purpose: artistApi supports index.js by holding or executing the artist 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 artistApi = require('../../api/nail-artist')
/**
* 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')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
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: list supports index.js by holding or executing the list 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.
*/
list: [],
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入美甲师管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: permissionCodes.includes('user:create') || permissionCodes.includes('nail_artist:edit')
})
this.loadArtists()
},
async loadArtists() {
try {
const list = await artistApi.listNailArtists()
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: (Array.isArray(list) ? list : []).map(item => ({
...item,
/**
* Purpose: displayStatusText supports index.js by holding or executing the display status text 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.
*/
displayStatusText: Number(item.status) === 0 ? '休息中' : '营业中'
}))
})
} 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'
})
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create 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.
*/
handleCreate() {
clearTempRecord('currentArtist')
navigation.navigate('/pages/artist-form/index', {
/**
* 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'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit 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.
*/
handleEdit(event) {
const artist = event.currentTarget.dataset.artist
setTempRecord('currentArtist', artist)
navigation.navigate('/pages/artist-form/index', {
/**
* 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: 'edit',
/**
* Purpose: userId supports index.js by holding or executing the user 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.
*/
userId: artist.userId
}).catch(() => undefined)
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,42 @@
<navigation-bar title="美甲师管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">美甲师列表</text>
<text class="section-desc">店长只能看到并管理自己门店的美甲师;平台管理员可跨店查看,移动端表单集中处理账号和档案两部分信息。</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.nickname}}</text>
<text class="list-subtitle">{{item.identity || '未设置身份'}} · {{item.shopName || '当前店铺'}}</text>
</view>
<text class="{{item.status === 0 ? 'soft-badge' : 'badge'}}">{{item.displayStatusText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">从业年限</text>
<text class="meta-value">{{item.experience || 0}} 年</text>
</view>
<view class="meta-item">
<text class="meta-label">评分</text>
<text class="meta-value">{{item.rating || 0}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn primary" data-artist="{{item}}" bindtap="handleEdit">编辑</view>
</view>
</view>
</block>
<view wx:if="{{!list.length}}" class="empty-state">
<text class="empty-title">还没有美甲师</text>
<text class="empty-desc">可以先新增一个美甲师账号,再补充技能、作品集和营业状态。</text>
</view>
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,154 @@
const campaignApi = require('../../api/campaign')
const navigation = require('../../utils/navigation')
const permission = require('../../utils/permission')
const format = require('../../utils/format')
const { markDirty } = require('../../utils/page-state')
const STATUS_OPTIONS = [
{ label: '全部', value: '' },
{ label: '启用', value: '1' },
{ label: '停用', value: '0' }
]
function safeList(response) {
if (Array.isArray(response && response.list)) {
return response.list
}
if (Array.isArray(response && response.records)) {
return response.records
}
return []
}
Page({
data: {
loading: false,
list: [],
total: 0,
status: '',
statusOptions: STATUS_OPTIONS,
canManage: false,
form: {
title: '',
scene: 'HOME',
description: '',
sortOrder: '0'
}
},
onShow() {
if (!navigation.ensureLogin('进入活动管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
canManage: permission.hasPermission(permissionCodes, 'campaign:manage')
})
this.loadCampaigns()
},
onPullDownRefresh() {
this.loadCampaigns().finally(() => {
wx.stopPullDownRefresh()
})
},
async loadCampaigns() {
this.setData({ loading: true })
try {
const response = await campaignApi.listCampaigns({
page: 1,
size: 20,
status: this.data.status === '' ? undefined : Number(this.data.status)
})
this.setData({
list: safeList(response).map(item => this.formatCampaign(item)),
total: Number(response && response.total) || 0
})
} catch (error) {
wx.showToast({
title: error.message || '活动加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
formatCampaign(item) {
return {
...item,
statusText: Number(item.status) === 0 ? '停用' : '启用',
displayStartTime: format.formatDateTime(item.startTime),
displayEndTime: format.formatDateTime(item.endTime)
}
},
handleStatusChange(event) {
this.setData({
status: event.currentTarget.dataset.status
})
this.loadCampaigns()
},
handleFormInput(event) {
const field = event.currentTarget.dataset.field
if (!field) {
return
}
this.setData({
[`form.${field}`]: event.detail.value
})
},
async handleSaveCampaign() {
if (!this.data.canManage) {
wx.showToast({
title: '当前账号没有活动管理权限',
icon: 'none'
})
return
}
const form = this.data.form
const title = String(form.title || '').trim()
if (!title) {
wx.showToast({
title: '请填写活动标题',
icon: 'none'
})
return
}
try {
await campaignApi.saveCampaign({
title,
scene: String(form.scene || '').trim() || 'HOME',
description: String(form.description || '').trim(),
sortOrder: Number(form.sortOrder) || 0,
status: 1
})
markDirty('admin-workbench')
wx.showToast({
title: '活动已创建',
icon: 'none'
})
this.setData({
form: {
title: '',
scene: 'HOME',
description: '',
sortOrder: '0'
}
})
this.loadCampaigns()
} catch (error) {
wx.showToast({
title: error.message || '活动保存失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,60 @@
<navigation-bar title="活动管理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">Campaign</text>
<text class="hero-title">活动管理</text>
<text class="hero-desc">查看营销活动和推荐位配置,支持在手机端快速创建启用活动。</text>
</view>
<view wx:if="{{canManage}}" class="surface-card">
<text class="section-title">快速创建</text>
<input class="field-input compact-field" placeholder="活动标题" placeholder-class="placeholder" value="{{form.title}}" data-field="title" bindinput="handleFormInput"></input>
<view class="form-grid">
<input class="field-input" placeholder="场景,如 HOME" placeholder-class="placeholder" value="{{form.scene}}" data-field="scene" bindinput="handleFormInput"></input>
<input class="field-input" type="number" placeholder="排序" placeholder-class="placeholder" value="{{form.sortOrder}}" data-field="sortOrder" bindinput="handleFormInput"></input>
</view>
<textarea class="field-textarea compact-textarea" placeholder="活动说明,可留空" placeholder-class="placeholder" value="{{form.description}}" data-field="description" bindinput="handleFormInput"></textarea>
<button class="primary-btn compact-btn" loading="{{loading}}" bindtap="handleSaveCampaign">创建活动</button>
</view>
<view class="surface-card">
<text class="section-title">活动列表</text>
<view class="chip-row">
<block wx:for="{{statusOptions}}" wx:key="value">
<view class="chip-btn {{status === item.value ? 'active' : ''}}" data-status="{{item.value}}" bindtap="handleStatusChange">{{item.label}}</view>
</block>
</view>
<text class="section-desc">共 {{total}} 条活动</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.title}}</text>
<text class="list-subtitle">{{item.scene || '未设置场景'}} · 排序 {{item.sortOrder || 0}}</text>
</view>
<text class="{{item.status === 0 ? 'soft-badge' : 'success-badge'}}">{{item.statusText}}</text>
</view>
<view wx:if="{{item.description}}" class="hint-card">{{item.description}}</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">开始</text>
<text class="meta-value">{{item.displayStartTime || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">结束</text>
<text class="meta-value">{{item.displayEndTime || '--'}}</text>
</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无活动</text>
<text class="empty-desc">当前筛选条件下没有营销活动。</text>
</view>
</view>
</view>
@@ -0,0 +1,21 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.compact-field,
.compact-btn,
.compact-textarea {
margin-top: 16rpx;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14rpx;
margin-top: 16rpx;
}
.compact-textarea {
min-height: 140rpx;
}
+143
View File
@@ -0,0 +1,143 @@
/**
* Purpose: commentApi supports index.js by holding or executing the comment 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 commentApi = require('../../api/comment')
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: loading supports index.js by holding or executing the loading 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.
*/
loading: false,
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: '',
/**
* Purpose: comments supports index.js by holding or executing the comments 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.
*/
comments: []
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
this.loadComments()
},
async onPullDownRefresh() {
await this.loadComments()
wx.stopPullDownRefresh()
},
/**
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input 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.
*/
handleKeywordInput(event) {
this.setData({
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: event.detail.value
})
},
async loadComments() {
this.setData({ loading: true })
try {
const comments = await commentApi.listComments({
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: this.data.keyword || undefined
})
this.setData({
/**
* Purpose: comments supports index.js by holding or executing the comments 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.
*/
comments: Array.isArray(comments) ? comments : []
})
} 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({ loading: false })
}
},
/**
* Purpose: handleSearch supports index.js by holding or executing the handle search 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.
*/
handleSearch() {
this.loadComments()
},
/**
* Purpose: handleDelete supports index.js by holding or executing the handle delete 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.
*/
handleDelete(event) {
const id = event.currentTarget.dataset.id
if (!id) {
return
}
wx.showModal({
/**
* 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: content supports index.js by holding or executing the content 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.
*/
content: '确认删除这条评论?',
/**
* Purpose: confirmText supports index.js by holding or executing the confirm text 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.
*/
confirmText: '删除',
/**
* Purpose: success supports index.js by holding or executing the success 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.
*/
success: async res => {
if (!res.confirm) {
return
}
try {
await commentApi.deleteComment(id)
wx.showToast({ title: '评论已删除', icon: 'none' })
this.loadComments()
} catch (error) {
wx.showToast({ title: error.message || '删除失败', icon: 'none' })
}
}
})
}
})
@@ -0,0 +1,21 @@
<navigation-bar title="评论管理" showBack="{{true}}" background="#081518" color="#ffffff"></navigation-bar>
<view class="page">
<view class="search-row">
<input class="search-input" placeholder="搜索评论内容" value="{{keyword}}" bindinput="handleKeywordInput" confirm-type="search" bindconfirm="handleSearch" />
<view class="search-btn" bindtap="handleSearch">搜索</view>
</view>
<view wx:if="{{!comments.length && !loading}}" class="empty">暂无评论</view>
<view wx:for="{{comments}}" wx:key="id" class="comment-card">
<view class="comment-head">
<text class="comment-user">{{item.userNickname || '用户'}}</text>
<text class="comment-time">{{item.createTime}}</text>
</view>
<view class="comment-content">{{item.commentContent}}</view>
<view wx:if="{{item.parentCommentContent}}" class="reply-content">回复:{{item.parentCommentContent}}</view>
<view class="comment-meta">{{item.productTitle || '作品'}} · {{item.shopName || '门店'}}</view>
<view class="delete-btn" data-id="{{item.id}}" bindtap="handleDelete">删除</view>
</view>
</view>
@@ -0,0 +1,95 @@
@import "../../app.wxss";
.page {
min-height: 100vh;
padding: 28rpx 24rpx 60rpx;
background: #0c181b;
}
.search-row {
display: flex;
gap: 16rpx;
margin-bottom: 24rpx;
}
.search-input {
flex: 1;
height: 76rpx;
padding: 0 24rpx;
border-radius: 18rpx;
background: #132529;
color: #ffffff;
font-size: 26rpx;
}
.search-btn {
width: 128rpx;
height: 76rpx;
line-height: 76rpx;
text-align: center;
border-radius: 18rpx;
background: #f07e57;
color: #ffffff;
font-weight: 700;
}
.empty {
padding: 80rpx 0;
text-align: center;
color: #7e8f8c;
}
.comment-card {
margin-bottom: 18rpx;
padding: 24rpx;
border-radius: 20rpx;
background: #132529;
color: #dce7e4;
}
.comment-head {
display: flex;
justify-content: space-between;
gap: 16rpx;
}
.comment-user {
font-size: 28rpx;
font-weight: 700;
color: #ffffff;
}
.comment-time,
.comment-meta {
font-size: 22rpx;
color: #7e8f8c;
}
.comment-content {
margin-top: 16rpx;
font-size: 26rpx;
line-height: 1.8;
}
.reply-content {
margin-top: 12rpx;
padding: 16rpx;
border-radius: 16rpx;
background: #0c181b;
color: #a9bbb6;
font-size: 24rpx;
}
.comment-meta {
margin-top: 14rpx;
}
.delete-btn {
margin-top: 18rpx;
width: 120rpx;
height: 56rpx;
line-height: 56rpx;
text-align: center;
border-radius: 999rpx;
color: #ffffff;
background: #d95f5f;
}
@@ -0,0 +1,87 @@
const couponApi = require('../../api/coupon')
const userApi = require('../../api/user')
const navigation = require('../../utils/navigation')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
Page({
data: {
coupon: null,
users: [],
quantity: 1
},
onLoad() {
const coupon = getTempRecord('currentCoupon', null)
this.setData({
coupon
})
this.loadUsers()
},
onUnload() {
clearTempRecord('currentCoupon')
},
async loadUsers() {
try {
const users = await userApi.listAllUsers()
this.setData({
users: (Array.isArray(users) ? users : []).map(item => ({
...item,
valueId: String(item.id),
checked: false
}))
})
} catch (error) {
wx.showToast({
title: error.message || '可发放用户加载失败',
icon: 'none'
})
}
},
handleUserCheck(event) {
const selected = event.detail.value || []
this.setData({
users: this.data.users.map(item => ({
...item,
checked: selected.includes(item.valueId)
}))
})
},
handleQuantityInput(event) {
this.setData({
quantity: event.detail.value
})
},
async handleSubmit() {
const selectedUserIds = this.data.users.filter(item => item.checked).map(item => Number(item.id))
if (!selectedUserIds.length) {
wx.showToast({
title: '请至少选择一个用户',
icon: 'none'
})
return
}
try {
await couponApi.distributeCoupon({
couponId: this.data.coupon.id,
userIds: selectedUserIds,
quantity: Number(this.data.quantity || 1)
})
wx.showToast({
title: '优惠券已发放',
icon: 'none'
})
navigation.goBack('/pages/coupons/index')
} catch (error) {
wx.showToast({
title: error.message || '发放失败',
icon: 'none'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,28 @@
<navigation-bar title="发放优惠券" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card" wx:if="{{coupon}}">
<text class="section-title">{{coupon.couponName}}</text>
<text class="section-desc">选择用户后批量发放,数量默认 1。移动端只保留高频发放能力,不把 Web 的宽表格搬过来。</text>
<view class="field-group">
<text class="field-label">发放数量</text>
<input class="field-input" type="number" value="{{quantity}}" bindinput="handleQuantityInput"></input>
</view>
<view class="field-group">
<text class="field-label">选择用户</text>
<checkbox-group bindchange="handleUserCheck">
<block wx:for="{{users}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.nickname || item.account}}
</label>
</block>
</checkbox-group>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">确认发放</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
@@ -0,0 +1,707 @@
/**
* 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'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,111 @@
<navigation-bar title="{{mode === 'edit' ? '编辑优惠券' : '新增优惠券'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">优惠券信息</text>
<view class="field-group">
<text class="field-label">优惠券名称</text>
<input class="field-input" value="{{form.couponName}}" data-field="couponName" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">所属店铺</text>
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">券类型</text>
<picker mode="selector" range="{{couponTypeOptions}}" value="{{couponTypeIndex}}" bindchange="handleCouponTypeChange">
<view class="field-picker">{{couponTypeLabel}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">优惠编码</text>
<input class="field-input" value="{{form.couponCode}}" data-field="couponCode" bindinput="handleInputChange"></input>
</view>
<view wx:if="{{couponTypeIndex === 0}}" class="field-group">
<text class="field-label">折扣值</text>
<input class="field-input" type="digit" value="{{form.discountValue}}" data-field="discountValue" bindinput="handleInputChange"></input>
</view>
<block wx:if="{{couponTypeIndex === 1}}">
<view class="field-group">
<text class="field-label">满多少可用</text>
<input class="field-input" type="digit" value="{{form.minAmount}}" data-field="minAmount" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">减免金额</text>
<input class="field-input" type="digit" value="{{form.reduceAmount}}" data-field="reduceAmount" bindinput="handleInputChange"></input>
</view>
</block>
<view class="field-group">
<text class="field-label">总数量</text>
<input class="field-input" type="number" value="{{form.totalCount}}" data-field="totalCount" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">优惠场景</text>
<input class="field-input" value="{{form.couponScene}}" data-field="couponScene" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">VIP 等级限制</text>
<picker mode="selector" range="{{vipLevelOptions}}" value="{{vipLevelIndex}}" bindchange="handleVipLevelChange">
<view class="field-picker">{{vipLevelLabel}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">开始日期 / 时间</text>
<view class="action-row">
<picker mode="date" value="{{startDate}}" data-field="startDate" bindchange="handleDateTimeChange">
<view class="field-picker">{{startDate || '开始日期'}}</view>
</picker>
<picker mode="time" value="{{startTime}}" data-field="startTime" bindchange="handleDateTimeChange">
<view class="field-picker">{{startTime || '开始时间'}}</view>
</picker>
</view>
</view>
<view class="field-group">
<text class="field-label">结束日期 / 时间</text>
<view class="action-row">
<picker mode="date" value="{{endDate}}" data-field="endDate" bindchange="handleDateTimeChange">
<view class="field-picker">{{endDate || '结束日期'}}</view>
</picker>
<picker mode="time" value="{{endTime}}" data-field="endTime" bindchange="handleDateTimeChange">
<view class="field-picker">{{endTime || '结束时间'}}</view>
</picker>
</view>
</view>
<view class="field-group">
<text class="field-label">自动匹配</text>
<switch checked="{{form.autoMatch}}" bindchange="handleAutoMatchChange"></switch>
</view>
<view class="field-group">
<text class="field-label">可用标签</text>
<checkbox-group bindchange="handleAvailableTagChange">
<block wx:for="{{availableTags}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="field-group">
<text class="field-label">不可用标签</text>
<checkbox-group bindchange="handleUnavailableTagChange">
<block wx:for="{{unavailableTags}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存优惠券</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
+219
View File
@@ -0,0 +1,219 @@
/**
* 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: 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: 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')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
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: list supports index.js by holding or executing the list 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.
*/
list: [],
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入优惠券管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: permissionCodes.includes('coupon:create')
})
this.loadCoupons()
},
async loadCoupons() {
try {
const result = await couponApi.listCoupons({
/**
* Purpose: page supports index.js by holding or executing the page 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.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size 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.
*/
size: 20
})
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
...item,
/**
* Purpose: displayTypeText supports index.js by holding or executing the display type text 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.
*/
displayTypeText: format.getCouponTypeText(item.couponType),
/**
* Purpose: displayValueText supports index.js by holding or executing the display value text 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.
*/
displayValueText: format.getCouponValueText(item),
/**
* Purpose: displayShopName supports index.js by holding or executing the display shop 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.
*/
displayShopName: item.shopName || '当前店铺'
}))
})
} 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'
})
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create 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.
*/
handleCreate() {
clearTempRecord('currentCoupon')
navigation.navigate('/pages/coupon-form/index', {
/**
* 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'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit 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.
*/
handleEdit(event) {
const coupon = event.currentTarget.dataset.coupon
setTempRecord('currentCoupon', coupon)
navigation.navigate('/pages/coupon-form/index', {
/**
* 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: 'edit',
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: coupon.id
}).catch(() => undefined)
},
/**
* Purpose: handleDistribute supports index.js by holding or executing the handle distribute 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.
*/
handleDistribute(event) {
const coupon = event.currentTarget.dataset.coupon
setTempRecord('currentCoupon', coupon)
navigation.navigate('/pages/coupon-distribute/index', {
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: coupon.id
}).catch(() => undefined)
},
/**
* Purpose: handleDelete supports index.js by holding or executing the handle delete 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.
*/
handleDelete(event) {
const coupon = event.currentTarget.dataset.coupon
wx.showModal({
/**
* 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: content supports index.js by holding or executing the content 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.
*/
content: `确认删除优惠券“${coupon.couponName}”吗?`,
/**
* Purpose: success supports index.js by holding or executing the success 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.
*/
success: async result => {
if (!result.confirm) {
return
}
try {
await couponApi.deleteCoupon(coupon.id)
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'
})
this.loadCoupons()
} 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'
})
}
}
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,44 @@
<navigation-bar title="优惠券管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">优惠券列表</text>
<text class="section-desc">普通券、VIP 自动券都在这里维护;发放动作单独收口到移动端发放页,避免一屏塞太多字段。</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.couponName}}</text>
<text class="list-subtitle">{{item.displayShopName}} · {{item.displayTypeText}}</text>
</view>
<text class="badge">{{item.displayValueText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">可用时间</text>
<text class="meta-value">{{item.startTime}} ~ {{item.endTime}}</text>
</view>
<view class="meta-item">
<text class="meta-label">剩余数量</text>
<text class="meta-value">{{item.remainingCount || item.totalCount || '--'}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn" data-coupon="{{item}}" bindtap="handleDistribute">发放</view>
<view class="mini-btn primary" data-coupon="{{item}}" bindtap="handleEdit">编辑</view>
<view class="mini-btn danger" data-coupon="{{item}}" bindtap="handleDelete">删除</view>
</view>
</view>
</block>
<view wx:if="{{!list.length}}" class="empty-state">
<text class="empty-title">暂无优惠券</text>
<text class="empty-desc">可以先创建普通券,也可以为每家店铺维护自己的 VIP 自动券模板。</text>
</view>
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,204 @@
const inventoryApi = require('../../api/inventory')
const navigation = require('../../utils/navigation')
const permission = require('../../utils/permission')
const format = require('../../utils/format')
const { markDirty } = require('../../utils/page-state')
function safeList(response) {
if (Array.isArray(response && response.list)) {
return response.list
}
if (Array.isArray(response && response.records)) {
return response.records
}
return []
}
Page({
data: {
loading: false,
list: [],
total: 0,
canManage: false,
form: {
itemName: '',
category: '',
unit: '件',
stockQuantity: '0',
warningThreshold: '1'
}
},
onShow() {
if (!navigation.ensureLogin('进入库存管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
canManage: permission.hasPermission(permissionCodes, 'inventory:manage')
})
this.loadItems()
},
onPullDownRefresh() {
this.loadItems().finally(() => {
wx.stopPullDownRefresh()
})
},
async loadItems() {
this.setData({ loading: true })
try {
const response = await inventoryApi.listItems({
page: 1,
size: 30
})
this.setData({
list: safeList(response).map(item => this.formatItem(item)),
total: Number(response && response.total) || 0
})
} catch (error) {
wx.showToast({
title: error.message || '库存加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
formatItem(item) {
return {
...item,
displayStock: format.formatPrice(item.stockQuantity),
displayWarning: format.formatPrice(item.warningThreshold),
statusText: Number(item.status) === 0 ? '停用' : '启用'
}
},
handleFormInput(event) {
const field = event.currentTarget.dataset.field
if (!field) {
return
}
this.setData({
[`form.${field}`]: event.detail.value
})
},
async handleSaveItem() {
if (!this.data.canManage) {
wx.showToast({
title: '当前账号没有库存维护权限',
icon: 'none'
})
return
}
const form = this.data.form
if (!String(form.itemName || '').trim()) {
wx.showToast({
title: '请填写物料名称',
icon: 'none'
})
return
}
try {
await inventoryApi.saveItem({
itemName: String(form.itemName || '').trim(),
category: String(form.category || '').trim(),
unit: String(form.unit || '').trim() || '件',
stockQuantity: Number(form.stockQuantity) || 0,
warningThreshold: Number(form.warningThreshold) || 0,
status: 1
})
markDirty('admin-workbench')
wx.showToast({
title: '物料已保存',
icon: 'none'
})
this.setData({
form: {
itemName: '',
category: '',
unit: '件',
stockQuantity: '0',
warningThreshold: '1'
}
})
this.loadItems()
} catch (error) {
wx.showToast({
title: error.message || '物料保存失败',
icon: 'none'
})
}
},
promptAdjust(item) {
return new Promise(resolve => {
wx.showModal({
title: `调整 ${item.itemName}`,
content: '填写正数入库,负数出库。',
editable: true,
placeholderText: '例如 5 或 -2',
confirmText: '调整',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
},
async handleAdjust(event) {
if (!this.data.canManage) {
wx.showToast({
title: '当前账号没有库存调整权限',
icon: 'none'
})
return
}
const item = event.currentTarget.dataset.item
if (!item) {
return
}
const value = await this.promptAdjust(item)
if (value === null) {
return
}
const quantity = Number(value)
if (!isFinite(quantity) || quantity === 0) {
wx.showToast({
title: '请输入非 0 数量',
icon: 'none'
})
return
}
try {
await inventoryApi.adjustStock(item.id, {
changeType: quantity > 0 ? 'IN' : 'OUT',
changeQuantity: quantity,
remark: '管理端小程序调整'
})
markDirty('admin-workbench')
wx.showToast({
title: '库存已调整',
icon: 'none'
})
this.loadItems()
} catch (error) {
wx.showToast({
title: error.message || '库存调整失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,58 @@
<navigation-bar title="库存管理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">Inventory</text>
<text class="hero-title">耗材库存</text>
<text class="hero-desc">查看库存和预警项,支持手机端快速新增物料与正负数调整库存。</text>
</view>
<view wx:if="{{canManage}}" class="surface-card">
<text class="section-title">新增物料</text>
<view class="form-grid">
<input class="field-input" placeholder="物料名称" placeholder-class="placeholder" value="{{form.itemName}}" data-field="itemName" bindinput="handleFormInput"></input>
<input class="field-input" placeholder="分类" placeholder-class="placeholder" value="{{form.category}}" data-field="category" bindinput="handleFormInput"></input>
<input class="field-input" placeholder="单位" placeholder-class="placeholder" value="{{form.unit}}" data-field="unit" bindinput="handleFormInput"></input>
<input class="field-input" type="digit" placeholder="初始库存" placeholder-class="placeholder" value="{{form.stockQuantity}}" data-field="stockQuantity" bindinput="handleFormInput"></input>
<input class="field-input" type="digit" placeholder="预警阈值" placeholder-class="placeholder" value="{{form.warningThreshold}}" data-field="warningThreshold" bindinput="handleFormInput"></input>
</view>
<button class="primary-btn compact-btn" loading="{{loading}}" bindtap="handleSaveItem">保存物料</button>
</view>
<view class="surface-card">
<text class="section-title">库存列表</text>
<text class="section-desc">共 {{total}} 个物料,低于阈值会标记为预警。</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.itemName}}</text>
<text class="list-subtitle">{{item.category || '未分类'}} · {{item.statusText}}</text>
</view>
<text class="{{item.warning ? 'danger-badge' : 'success-badge'}}">{{item.warning ? '库存预警' : '正常'}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">当前库存</text>
<text class="meta-value">{{item.displayStock}} {{item.unit || ''}}</text>
</view>
<view class="meta-item">
<text class="meta-label">预警阈值</text>
<text class="meta-value">{{item.displayWarning}} {{item.unit || ''}}</text>
</view>
</view>
<view wx:if="{{canManage}}" class="list-actions">
<view class="mini-btn primary" data-item="{{item}}" bindtap="handleAdjust">调整库存</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无库存物料</text>
<text class="empty-desc">当前店铺还没有录入耗材库存。</text>
</view>
</view>
</view>
@@ -0,0 +1,15 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14rpx;
margin-top: 18rpx;
}
.compact-btn {
margin-top: 18rpx;
}
+447
View File
@@ -0,0 +1,447 @@
/**
* Purpose: authApi supports index.js by holding or executing the auth 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 authApi = require('../../api/auth')
/**
* Purpose: auth supports index.js by holding or executing the auth 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 auth = require('../../utils/auth')
/**
* 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')
const { runWithLoading } = require('../../utils/loading')
const sessionSwitch = require('../../../utils/session-switch')
/**
* Purpose: ACCOUNT_REGEX supports index.js by holding or executing the account regex 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 ACCOUNT_REGEX = /[^A-Za-z0-9]/g
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: redirect supports index.js by holding or executing the redirect 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.
*/
redirect: '',
/**
* 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: account supports index.js by holding or executing the account 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.
*/
account: '',
/**
* Purpose: password supports index.js by holding or executing the password 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.
*/
password: '',
/**
* 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: loginShops supports index.js by holding or executing the login 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.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login 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.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display 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.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login 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.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message 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.
*/
loginShopMessage: '',
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text 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.
*/
accountStatusText: '',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status 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.
*/
accountStatusType: '',
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: 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) {
this._lookupTicket = 0
this.setData({
/**
* Purpose: redirect supports index.js by holding or executing the redirect 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.
*/
redirect: options && options.redirect ? options.redirect : ''
})
if (auth.isLoggedIn()) {
navigation.redirectAfterLogin(this.data.redirect).catch(() => undefined)
}
},
/**
* 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() {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
}
},
/**
* 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
let value = event.detail.value
if (field === 'account') {
value = String(value || '').replace(ACCOUNT_REGEX, '')
this.resetAccountState()
if (value) {
this.scheduleAccountLookup(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 index = Number(event.detail.value)
const shop = this.data.loginShops[index]
this.setData({
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login 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.
*/
loginShopIndex: index,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display 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.
*/
loginShopDisplayName: shop ? shop.shopName || '' : '',
'form.shopId': shop ? shop.id : ''
})
},
/**
* Purpose: resetAccountState supports index.js by holding or executing the reset account state 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.
*/
resetAccountState() {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
}
this._lookupTicket += 1
this.setData({
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text 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.
*/
accountStatusText: '',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status 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.
*/
accountStatusType: '',
/**
* Purpose: loginShops supports index.js by holding or executing the login 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.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login 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.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display 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.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login 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.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message 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.
*/
loginShopMessage: '',
'form.shopId': ''
})
},
/**
* Purpose: scheduleAccountLookup supports index.js by holding or executing the schedule account lookup 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.
*/
scheduleAccountLookup(account) {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
}
const ticket = this._lookupTicket + 1
this._lookupTicket = ticket
this._accountTimer = setTimeout(() => {
this.loadLoginShops(account, ticket)
}, 420)
},
/**
* Purpose: applyLoginShopSelection supports index.js by holding or executing the apply login shop selection 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.
*/
applyLoginShopSelection(selection) {
const shops = Array.isArray(selection && selection.shops) ? selection.shops : []
const allowShoplessLogin = Boolean(selection && selection.allowShoplessLogin)
let loginShopIndex = -1
let loginShopDisplayName = ''
let shopId = ''
if (!allowShoplessLogin && shops.length === 1) {
loginShopIndex = 0
loginShopDisplayName = shops[0].shopName || ''
shopId = shops[0].id
}
this.setData({
/**
* Purpose: loginShops supports index.js by holding or executing the login 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.
*/
loginShops: shops,
allowShoplessLogin,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message 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.
*/
loginShopMessage: (selection && selection.message) || '',
loginShopIndex,
loginShopDisplayName,
'form.shopId': shopId,
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text 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.
*/
accountStatusText: shops.length || allowShoplessLogin ? '该账号可用于后台登录' : '当前账号暂时不可用于后台登录',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status 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.
*/
accountStatusType: shops.length || allowShoplessLogin ? 'success' : 'warning'
})
},
async loadLoginShops(account, ticket) {
if (!account) {
this.resetAccountState()
return
}
try {
const result = await authApi.getLoginShops(account)
if (ticket !== this._lookupTicket || this.data.form.account !== account) {
return
}
this.applyLoginShopSelection(result)
} catch (error) {
if (ticket !== this._lookupTicket || this.data.form.account !== account) {
return
}
this.setData({
/**
* Purpose: loginShops supports index.js by holding or executing the login 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.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login 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.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display 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.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login 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.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message 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.
*/
loginShopMessage: '',
'form.shopId': '',
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text 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.
*/
accountStatusText: error.message || '该后台账号不存在或不可登录',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status 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.
*/
accountStatusType: 'error'
})
}
},
/**
* Purpose: validateForm supports index.js by holding or executing the validate form 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.
*/
validateForm() {
const form = this.data.form
if (!form.account) {
return '请输入后台账号'
}
if (!form.password) {
return '请输入登录密码'
}
if (!this.data.allowShoplessLogin && this.data.loginShops.length && !form.shopId) {
return '请选择登录店铺'
}
return ''
},
async handleSubmit() {
const errorMessage = this.validateForm()
if (errorMessage) {
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: errorMessage,
/**
* 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
}
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: true
})
try {
const payload = await runWithLoading(() => authApi.login({
/**
* Purpose: account supports index.js by holding or executing the account 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.
*/
account: this.data.form.account,
/**
* Purpose: password supports index.js by holding or executing the password 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.
*/
password: this.data.form.password,
/**
* 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
}))
await getApp().setAdminSession(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: '登录成功',
/**
* 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'
})
await navigation.redirectAfterLogin(this.data.redirect)
} 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: loading supports index.js by holding or executing the loading 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.
*/
loading: false
})
}
},
handleOpenCustomerHome() {
sessionSwitch.openCustomerHome()
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,47 @@
<navigation-bar title="后台管理" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack login-stack">
<view class="hero-panel">
<text class="hero-kicker">YUMINAIL ADMIN</text>
<text class="hero-title">把日常经营带到手机上</text>
<text class="hero-desc">平台管理员、店长、美甲师共用一套后台能力。首版保持业务能力对齐,交互按移动端重构,不把网页表格硬搬到手机里。</text>
<view class="badge-row">
<text class="badge">平台管理员</text>
<text class="soft-badge">店长</text>
<text class="soft-badge">美甲师</text>
</view>
</view>
<view class="surface-card">
<text class="section-title">账号密码登录</text>
<text class="section-desc">输入后台账号后,会自动识别登录范围。平台管理员可直接进入总览,也可选择本次登录店铺。</text>
<view class="field-group">
<text class="field-label">后台账号</text>
<input class="field-input" placeholder="仅支持字母和数字" placeholder-class="placeholder" value="{{form.account}}" data-field="account" bindinput="handleInputChange"></input>
<text wx:if="{{accountStatusText}}" class="status-text {{accountStatusType}}">{{accountStatusText}}</text>
</view>
<view class="field-group">
<text class="field-label">登录密码</text>
<input class="field-input" password placeholder="请输入后台密码" placeholder-class="placeholder" value="{{form.password}}" data-field="password" bindinput="handleInputChange"></input>
</view>
<view wx:if="{{loginShops.length}}" class="field-group">
<text class="field-label">登录店铺</text>
<picker mode="selector" range="{{loginShops}}" range-key="shopName" value="{{loginShopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{loginShopDisplayName || '请选择本次登录店铺'}}</view>
</picker>
</view>
<view wx:if="{{allowShoplessLogin || loginShopMessage}}" class="hint-card">{{loginShopMessage || '平台管理员可直接进入总览,也可选择本次登录店铺。'}}</view>
<view class="action-row">
<button class="primary-btn" loading="{{loading}}" disabled="{{loading}}" bindtap="handleSubmit">进入管理台</button>
</view>
</view>
<view class="customer-switch-link" bindtap="handleOpenCustomerHome">返回前台</view>
</view>
</view>
@@ -0,0 +1,14 @@
@import "../../app.wxss";
.login-stack {
padding-top: 40rpx;
}
.customer-switch-link {
display: flex;
align-items: center;
justify-content: center;
min-height: 72rpx;
color: #f7dba7;
font-size: 26rpx;
font-weight: 700;
}
+100
View File
@@ -0,0 +1,100 @@
/**
* 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: permission supports index.js by holding or executing the permission 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 permission = require('../../utils/permission')
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: userInfo supports index.js by holding or executing the user info 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.
*/
userInfo: null,
/**
* Purpose: currentShop supports index.js by holding or executing the current shop 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.
*/
currentShop: null,
/**
* Purpose: modules supports index.js by holding or executing the modules 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.
*/
modules: []
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入经营模块')) {
return
}
const app = getApp()
const userInfo = app.globalData.userInfo
const currentShop = app.globalData.currentShop
const permissionCodes = app.globalData.permissionCodes || []
this.setData({
userInfo,
currentShop,
/**
* Purpose: modules supports index.js by holding or executing the modules 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.
*/
modules: permission.getManageModules(userInfo, permissionCodes, currentShop)
})
},
handleOpenWorkbench() {
navigation.switchTab('/pages/workbench/index').catch(() => undefined)
},
handleOpenOrders() {
navigation.switchTab('/pages/orders/index').catch(() => undefined)
},
handleOpenProfile() {
navigation.switchTab('/pages/profile/index').catch(() => undefined)
},
/**
* Purpose: handleOpenModule supports index.js by holding or executing the handle open module 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.
*/
handleOpenModule(event) {
const module = event.currentTarget.dataset.module
if (!module) {
return
}
if (!module.allowed) {
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: module.disabledReason || '当前账号没有进入该模块的权限',
/**
* 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
}
navigation.navigate(module.path).catch(() => undefined)
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,32 @@
<navigation-bar title="经营" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">按权限展示</text>
<text class="hero-title">{{currentShop ? currentShop.shopName : '平台级入口'}}</text>
<text class="hero-desc">这里不复刻网页后台的大表格首页,而是把可用模块拆成移动端更好点到的入口卡片。</text>
</view>
<view wx:if="{{!currentShop && userInfo && userInfo.type === 4}}" class="hint-card">当前是平台总览模式。用户、作品、订单、优惠券、标签、美甲师等店铺业务可以查看,编辑操作由服务端关闭。</view>
<block wx:for="{{modules}}" wx:key="key">
<view class="list-card" data-module="{{item}}" bindtap="handleOpenModule">
<view class="list-head">
<view>
<text class="list-title">{{item.title}}</text>
<text class="list-subtitle">{{item.description}}</text>
</view>
<text class="{{item.allowed ? 'badge' : 'soft-badge'}}">{{item.readonly ? '仅查看' : (item.allowed ? '可进入' : '待解锁')}}</text>
</view>
<view wx:if="{{!item.allowed}}" class="hint-card">{{item.disabledReason}}</view>
</view>
</block>
<view class="admin-bottom-nav">
<view class="admin-bottom-link" bindtap="handleOpenWorkbench">工作台</view>
<view class="admin-bottom-link" bindtap="handleOpenOrders">订单</view>
<view class="admin-bottom-link active">经营</view>
<view class="admin-bottom-link" bindtap="handleOpenProfile">我的</view>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,199 @@
/**
* Purpose: orderApi loads full backend order detail so direct entry and message navigation can render complete data.
* Usage: call getOrderDetail with the current route id before displaying the order detail page.
*/
const orderApi = require('../../api/order')
const paymentApi = require('../../api/payment')
const permission = require('../../utils/permission')
/**
* 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')
const { markDirty } = require('../../utils/page-state')
function getPaymentStatusText(status) {
if (status === 'PAID') {
return '已支付'
}
if (status === 'PAYING') {
return '支付中'
}
if (status === 'REFUNDED') {
return '已退款'
}
return '未支付'
}
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: loading marks whether the detail endpoint is currently fetching order data.
* Usage: bind it to loading and retry states while preserving any cached order shown on screen.
*/
loading: false,
/**
* Purpose: orderId keeps the backend order id used by reload and direct-entry flows.
* Usage: set it from route options or cached list data before calling loadOrderDetail.
*/
orderId: '',
/**
* Purpose: order supports index.js by holding or executing the order 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.
*/
order: null,
canManualConfirmPay: 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 permissionCodes = getApp().globalData.permissionCodes || []
const cachedOrder = getTempRecord('currentOrder', null)
const orderId = (options && options.id) || (cachedOrder && cachedOrder.id) || ''
this.setData({
orderId,
order: cachedOrder ? this.formatOrder(cachedOrder) : null,
canManualConfirmPay: permission.hasPermission(permissionCodes, 'payment:manage')
})
if (orderId) {
this.loadOrderDetail(orderId)
}
},
/**
* Purpose: loadOrderDetail replaces list-row summary data with the authoritative admin order-detail response.
* Usage: call it from onLoad and retry buttons with the backend order id; failures leave cached data visible.
*/
async loadOrderDetail(orderId) {
this.setData({ loading: true })
try {
const detail = await orderApi.getOrderDetail(orderId)
this.setData({
order: this.formatOrder(detail)
})
} catch (error) {
wx.showToast({
title: error.message || '订单详情加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
/**
* Purpose: formatOrder prepares order and item fields for WXML, including review and change-request summaries.
* Usage: run every cached or fetched order object through this method before assigning it to data.order.
*/
formatOrder(order) {
const items = Array.isArray(order && order.items) ? order.items : []
const paymentStatus = order && order.paymentStatus ? order.paymentStatus : 'UNPAID'
return order ? {
...order,
displayStatusText: format.getOrderStatusText(order),
displayPaymentStatusText: getPaymentStatusText(paymentStatus),
displayCreateTime: format.formatDateTime(order.createTime),
displayPayAmount: format.formatPrice(order.payAmount || order.actualAmount),
displayPaidAmount: format.formatPrice(order.paidAmount),
displayPayTime: format.formatDateTime(order.payTime),
canManualConfirmPay: paymentStatus !== 'PAID' && paymentStatus !== 'REFUNDED',
items: items.map(item => ({
...item,
displayAppointmentTime: item.appointmentTime ? format.formatDateTime(item.appointmentTime) : '',
reviewStatusText: item.reviewStatusText || (item.reviewSummary ? '已评价' : '待评价'),
changeStatusText: item.pendingArtistChangeRequest ? item.pendingArtistChangeRequest.displayText : ''
}))
} : null
},
/**
* Purpose: handleRetry reloads backend detail when direct entry failed or no cached data exists.
* Usage: bind it to the empty state action so operators can recover without returning to the list.
*/
handleRetry() {
if (!this.data.orderId) {
navigation.goBack('/pages/orders/index')
return
}
this.loadOrderDetail(this.data.orderId)
},
async handleManualConfirmPay() {
if (!this.data.canManualConfirmPay) {
wx.showToast({
title: '当前账号没有确认支付权限',
icon: 'none'
})
return
}
const order = this.data.order
if (!order) {
return
}
const remark = await new Promise(resolve => {
wx.showModal({
title: '手动确认支付',
content: `确认将订单 ${order.orderNo || order.id} 标记为已支付?`,
editable: true,
placeholderText: '备注,可留空',
confirmText: '确认',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
if (remark === null) {
return
}
try {
await paymentApi.manualConfirmOrder(order.id, remark)
markDirty('admin-orders')
markDirty('admin-workbench')
wx.showToast({
title: '支付已确认',
icon: 'none'
})
this.loadOrderDetail(order.id)
} catch (error) {
wx.showToast({
title: error.message || '确认支付失败',
icon: 'none'
})
}
},
/**
* 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('currentOrder')
},
/**
* Purpose: handleBack supports index.js by holding or executing the handle back 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.
*/
handleBack() {
navigation.goBack('/pages/orders/index')
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,77 @@
<navigation-bar title="订单详情" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view wx:if="{{order}}" class="surface-card">
<text class="section-title">{{order.orderNo}}</text>
<text class="section-desc">{{order.displayStatusText}} · {{order.displayCreateTime}}</text>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">用户昵称</text>
<text class="meta-value">{{order.customerNickname || order.userNickname || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">脱敏手机号</text>
<text class="meta-value">{{order.customerPhoneMasked || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">所属店铺</text>
<text class="meta-value">{{order.shopName || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">美甲师</text>
<text class="meta-value">{{order.artistName || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">应付金额</text>
<text class="meta-value">¥{{order.displayPayAmount || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">支付状态</text>
<text class="meta-value">{{order.displayPaymentStatusText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">已付金额</text>
<text class="meta-value">¥{{order.displayPaidAmount}}</text>
</view>
<view class="meta-item">
<text class="meta-label">支付时间</text>
<text class="meta-value">{{order.displayPayTime || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">备注</text>
<text class="meta-value">{{order.remark || '暂无备注'}}</text>
</view>
</view>
<view wx:if="{{canManualConfirmPay && order.canManualConfirmPay}}" class="action-row">
<button class="primary-btn" loading="{{loading}}" bindtap="handleManualConfirmPay">手动确认支付</button>
</view>
</view>
<view wx:if="{{order && order.items && order.items.length}}" class="surface-card">
<text class="section-title">服务项目</text>
<block wx:for="{{order.items}}" wx:key="id">
<view class="detail-item">
<view class="detail-item-head">
<text class="detail-item-title">{{item.productTitle || '订单项目'}}</text>
<text class="badge">{{item.reviewStatusText}}</text>
</view>
<text class="detail-item-line">美甲师:{{item.artistName || '--'}}</text>
<text wx:if="{{item.displayAppointmentTime}}" class="detail-item-line">预约时间:{{item.displayAppointmentTime}}</text>
<text wx:if="{{item.reviewSummary && item.reviewSummary.contentText}}" class="detail-item-line">评价内容:{{item.reviewSummary.contentText}}</text>
<view wx:if="{{item.pendingArtistChangeRequest}}" class="change-box">
<text class="change-title">改派申请</text>
<text class="change-line">{{item.pendingArtistChangeRequest.displayText}}</text>
<text wx:if="{{item.pendingArtistChangeRequest.reasonText}}" class="change-line">原因:{{item.pendingArtistChangeRequest.reasonText}}</text>
</view>
</view>
</block>
</view>
<view wx:if="{{!order}}" class="empty-state">
<text class="empty-title">订单详情暂不可用</text>
<text class="empty-desc">当前详情页可通过列表、消息或订单 id 打开;加载失败时可重试。</text>
<button class="primary-btn" loading="{{loading}}" bindtap="handleRetry">重新加载</button>
</view>
</view>
</view>
@@ -0,0 +1,56 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.detail-item {
display: flex;
flex-direction: column;
gap: 12rpx;
padding: 20rpx 0;
border-top: 1rpx solid rgba(255, 255, 255, 0.08);
}
.detail-item:first-of-type {
border-top: 0;
}
.detail-item-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.detail-item-title {
color: #f6efe7;
font-size: 30rpx;
font-weight: 700;
}
.detail-item-line {
color: #9fb3ad;
font-size: 24rpx;
line-height: 1.6;
}
.change-box {
display: flex;
flex-direction: column;
gap: 8rpx;
padding: 16rpx;
border-radius: 8rpx;
background: rgba(240, 126, 87, 0.1);
}
.change-title {
color: #f6efe7;
font-size: 24rpx;
font-weight: 700;
}
.change-line {
color: #f4c7b8;
font-size: 24rpx;
line-height: 1.5;
}
+753
View File
@@ -0,0 +1,753 @@
/**
* Purpose: orderApi supports index.js by holding or executing the order 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 orderApi = require('../../api/order')
const paymentApi = require('../../api/payment')
/**
* 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: permission supports index.js by holding or executing the permission 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 permission = require('../../utils/permission')
/**
* 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 { setTempRecord } = require('../../utils/storage')
const { consumeDirty, markDirty } = require('../../utils/page-state')
/**
* Purpose: STATUS_OPTIONS supports index.js by holding or executing the status options 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 STATUS_OPTIONS = [
{ label: '全部', value: '' },
{ label: '待服务', value: 1 },
{ label: '已完成', value: 2 },
{ label: '已取消', value: 0 }
]
/**
* Purpose: toId supports index.js by holding or executing the to 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 toId(value) {
return value === undefined || value === null ? '' : String(value)
}
/**
* Purpose: sameId supports index.js by holding or executing the same 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 sameId(left, right) {
const leftId = toId(left)
const rightId = toId(right)
return leftId !== '' && leftId === rightId
}
/**
* Purpose: safeList supports index.js by holding or executing the safe 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 safeList(value) {
return Array.isArray(value) ? value : []
}
/**
* Purpose: trimText supports index.js by holding or executing the trim text 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 trimText(value) {
return String(value || '').trim()
}
/**
* Purpose: formatRating supports index.js by holding or executing the format rating 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 formatRating(value) {
const rating = Number(value)
if (!isFinite(rating) || rating <= 0) {
return ''
}
return rating % 1 === 0 ? String(rating) : rating.toFixed(1)
}
function getPaymentStatusText(status) {
if (status === 'PAID') {
return '已支付'
}
if (status === 'PAYING') {
return '支付中'
}
if (status === 'REFUNDED') {
return '已退款'
}
return '未支付'
}
/**
* Purpose: isSubmittedReview supports index.js by holding or executing the is submitted review 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 isSubmittedReview(review) {
if (!review) {
return false
}
if (Number(review.status) === 1) {
return true
}
return Boolean(review.rating)
}
/**
* Purpose: resolveRelatedRecord supports index.js by holding or executing the resolve related record 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 resolveRelatedRecord(source, orderItemId) {
if (Array.isArray(source)) {
return source.find(item => sameId(item && item.orderItemId, orderItemId)) || null
}
if (source && typeof source === 'object') {
if (!source.orderItemId || sameId(source.orderItemId, orderItemId)) {
return source
}
}
return null
}
/**
* Purpose: buildReviewSummary supports index.js by holding or executing the build review summary 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 buildReviewSummary(review) {
if (!review || !isSubmittedReview(review)) {
return null
}
const ratingText = formatRating(review.rating)
return {
...review,
ratingText,
contentText: trimText(review.content),
displayText: ratingText ? `已评价:${ratingText} 分` : (review.statusText || '已评价')
}
}
/**
* Purpose: buildArtistChangeSummary supports index.js by holding or executing the build artist change summary 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 buildArtistChangeSummary(request) {
if (!request) {
return null
}
const originalName = request.originalArtistName || '原美甲师'
const requestedName = request.requestedArtistName || '新美甲师'
return {
...request,
displayText: `${originalName} → ${requestedName}`,
reasonText: trimText(request.reason)
}
}
/**
* Purpose: indexByOrderItemId supports index.js by holding or executing the index by order item 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 indexByOrderItemId(list) {
return safeList(list).reduce((result, item) => {
if (item && item.orderItemId) {
result[toId(item.orderItemId)] = item
}
return result
}, {})
}
/**
* Purpose: safeCall supports index.js by holding or executing the safe call 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.
*/
async function safeCall(factory, fallbackValue) {
try {
const result = await factory()
return result === undefined || result === null ? fallbackValue : result
} catch (error) {
return fallbackValue
}
}
/**
* Purpose: loadAssistData supports index.js by holding or executing the load assist data 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.
*/
async function loadAssistData(orders) {
const pendingChangesPromise = safeCall(() => orderApi.listMyPendingArtistChangeRequests(), [])
const orderReviewListsPromise = Promise.all(orders.map(order => (
safeCall(() => orderApi.listOrderReviews(order.id), [])
)))
const [pendingChanges, orderReviewLists] = await Promise.all([
pendingChangesPromise,
orderReviewListsPromise
])
const submittedReviews = []
safeList(orderReviewLists).forEach(list => {
safeList(list).forEach(review => {
if (isSubmittedReview(review)) {
submittedReviews.push(review)
}
})
})
return {
pendingChangeByItemId: indexByOrderItemId(pendingChanges),
submittedReviewByItemId: indexByOrderItemId(submittedReviews)
}
}
/**
* Purpose: hasProductionFlag supports index.js by holding or executing the has production flag 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 hasProductionFlag(userInfo) {
const sources = [
userInfo && userInfo.participateProduction,
userInfo && userInfo.participateProductionFlag,
userInfo && userInfo.artistParticipateProduction,
userInfo && userInfo.nailArtistInfo && userInfo.nailArtistInfo.participateProduction,
userInfo && userInfo.artistInfo && userInfo.artistInfo.participateProduction
]
return sources.some(value => value === true || Number(value) === 1)
}
/**
* Purpose: canRequestArtistChangeForItem supports index.js by holding or executing the can request artist change for item 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 canRequestArtistChangeForItem(userInfo, order, item, pendingChange) {
if (!userInfo || !order || !item || pendingChange || Number(order.status) !== 1) {
return false
}
if (permission.isNailArtist(userInfo)) {
return !item.artistId || sameId(item.artistId, userInfo.id)
}
if (sameId(item.artistId, userInfo.id)) {
return true
}
return permission.isShopManager(userInfo) && hasProductionFlag(userInfo)
}
/**
* Purpose: formatOrderItem supports index.js by holding or executing the format order item 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 formatOrderItem(order, item, userInfo, assistData) {
const itemId = toId(item.id)
const inlineReviewSummary = resolveRelatedRecord(item.reviewSummary || order.reviewSummary, item.id)
const inlinePendingChange = resolveRelatedRecord(item.pendingArtistChangeRequest || order.pendingArtistChangeRequest, item.id)
const reviewSummary = buildReviewSummary(inlineReviewSummary || assistData.submittedReviewByItemId[itemId])
const pendingArtistChangeRequest = buildArtistChangeSummary(inlinePendingChange || assistData.pendingChangeByItemId[itemId])
return {
...item,
displayPrice: format.formatPrice(item.price),
displayAppointmentTime: format.formatDateTime(item.appointmentTime),
reviewSummary,
reviewStatusText: reviewSummary ? reviewSummary.displayText : '待评价',
pendingArtistChangeRequest,
canRequestArtistChange: canRequestArtistChangeForItem(userInfo, order, item, pendingArtistChangeRequest)
}
}
/**
* Purpose: formatOrder supports index.js by holding or executing the format order 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 formatOrder(order, userInfo, assistData) {
const items = safeList(order.items).map(item => formatOrderItem(order, item, userInfo, assistData))
const orderReviewSummary = buildReviewSummary(order.reviewSummary)
const paymentStatus = order.paymentStatus || 'UNPAID'
return {
...order,
displayStatusText: format.getOrderStatusText(order),
displayPaymentStatusText: getPaymentStatusText(paymentStatus),
displayCreateTime: format.formatDateTime(order.createTime),
displayPayAmount: format.formatPrice(order.payAmount || order.actualAmount),
displayPaidAmount: format.formatPrice(order.paidAmount),
canManualConfirmPay: paymentStatus !== 'PAID' && paymentStatus !== 'REFUNDED',
items,
reviewSummary: orderReviewSummary,
reviewStatusText: orderReviewSummary ? orderReviewSummary.displayText : ''
}
}
/**
* Purpose: selectArtist supports index.js by holding or executing the select artist 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 selectArtist(artists) {
return new Promise(resolve => {
wx.showActionSheet({
itemList: artists.map(item => item.artistName || `美甲师 ${item.artistId}`),
success: result => resolve(artists[result.tapIndex] || null),
fail: () => resolve(null)
})
})
}
/**
* Purpose: promptChangeReason supports index.js by holding or executing the prompt change reason 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 promptChangeReason() {
return new Promise(resolve => {
wx.showModal({
title: '改派原因',
content: '可填写改派原因,留空也可以提交。',
editable: true,
placeholderText: '例如档期冲突、客户沟通调整',
confirmText: '提交',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(trimText(result.content))
},
fail: () => resolve(null)
})
})
}
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: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: '',
/**
* Purpose: status supports index.js by holding or executing the status 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.
*/
status: '',
/**
* Purpose: statusOptions supports index.js by holding or executing the status 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.
*/
statusOptions: STATUS_OPTIONS,
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: [],
/**
* Purpose: total supports index.js by holding or executing the total 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.
*/
total: 0,
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: false,
/**
* Purpose: userInfo supports index.js by holding or executing the user info 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.
*/
userInfo: null,
canManualConfirmPay: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized 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.
*/
initialized: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入订单管理')) {
return
}
const userInfo = getApp().globalData.userInfo
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
userInfo,
canManualConfirmPay: permission.hasPermission(permissionCodes, 'payment:manage')
})
if (!this.data.initialized || consumeDirty('admin-orders')) {
this.loadOrders()
}
},
async handleManualConfirmPay(event) {
if (!this.data.canManualConfirmPay) {
wx.showToast({
title: '当前账号没有确认支付权限',
icon: 'none'
})
return
}
const order = event.currentTarget.dataset.order
if (!order) {
return
}
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '手动确认支付',
content: `确认将订单 ${order.orderNo || order.id} 标记为已支付?`,
editable: true,
placeholderText: '备注,可留空',
confirmText: '确认',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
if (confirmed === null) {
return
}
try {
await paymentApi.manualConfirmOrder(order.id, confirmed)
markDirty('admin-workbench')
wx.showToast({
title: '支付已确认',
icon: 'none'
})
this.loadOrders()
} catch (error) {
wx.showToast({
title: error.message || '确认支付失败',
icon: 'none'
})
}
},
/**
* Purpose: onPullDownRefresh supports index.js by holding or executing the on pull down refresh 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.
*/
onPullDownRefresh() {
this.loadOrders().finally(() => {
wx.stopPullDownRefresh()
})
},
/**
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input 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.
*/
handleKeywordInput(event) {
this.setData({
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: event.detail.value
})
},
/**
* Purpose: handleStatusChange supports index.js by holding or executing the handle status 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.
*/
handleStatusChange(event) {
const status = event.currentTarget.dataset.status
this.setData({
status
})
this.loadOrders()
},
async loadOrders() {
const requestId = (this._loadRequestId || 0) + 1
this._loadRequestId = requestId
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: true
})
try {
const result = await orderApi.listOrders({
/**
* Purpose: page supports index.js by holding or executing the page 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.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size 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.
*/
size: 20,
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: this.data.keyword || undefined,
/**
* Purpose: status supports index.js by holding or executing the status 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.
*/
status: this.data.status === '' ? undefined : this.data.status
})
const rawList = safeList(result && result.list)
const assistData = await loadAssistData(rawList)
if (requestId !== this._loadRequestId) {
return
}
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: rawList.map(item => formatOrder(item, this.data.userInfo, assistData)),
/**
* Purpose: total supports index.js by holding or executing the total 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.
*/
total: Number(result && result.total) || 0,
/**
* Purpose: initialized supports index.js by holding or executing the initialized 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.
*/
initialized: true
})
} catch (error) {
if (requestId !== this._loadRequestId) {
return
}
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 {
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: false
})
}
}
},
/**
* Purpose: handleSearch supports index.js by holding or executing the handle search 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.
*/
handleSearch() {
this.loadOrders()
},
handleOpenWorkbench() {
navigation.switchTab('/pages/workbench/index').catch(() => undefined)
},
handleOpenManage() {
navigation.switchTab('/pages/manage/index').catch(() => undefined)
},
handleOpenProfile() {
navigation.switchTab('/pages/profile/index').catch(() => undefined)
},
/**
* Purpose: handleOpenOrder supports index.js by holding or executing the handle open order 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.
*/
handleOpenOrder(event) {
const order = event.currentTarget.dataset.order
if (!order) {
return
}
setTempRecord('currentOrder', order)
navigation.navigate('/pages/order-detail/index', {
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: order.id
}).catch(() => undefined)
},
async handleRequestArtistChange(event) {
const orderId = event.currentTarget.dataset.orderId
const orderItemId = event.currentTarget.dataset.orderItemId
if (!orderId || !orderItemId) {
return
}
try {
const options = await orderApi.getArtistChangeOptions(orderId, orderItemId)
const artists = safeList(options && options.artists)
if (!artists.length) {
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 targetArtist = await selectArtist(artists)
if (!targetArtist) {
return
}
const reason = await promptChangeReason()
if (reason === null) {
return
}
await orderApi.requestArtistChange({
orderId,
orderItemId,
/**
* Purpose: requestedArtistId supports index.js by holding or executing the requested artist 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.
*/
requestedArtistId: targetArtist.artistId,
reason
})
markDirty('admin-workbench')
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'
})
this.loadOrders()
} 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 handleProcessOrder(event) {
const order = event.currentTarget.dataset.order
if (!order) {
return
}
const isArtist = permission.isNailArtist(this.data.userInfo)
const options = isArtist
? [{ label: '标记为已完成', status: 2 }]
: [
{ label: '调整为待服务', status: 1 },
{ label: '标记为已完成', status: 2 },
{ label: '标记为已取消', status: 0 }
]
wx.showActionSheet({
/**
* Purpose: itemList supports index.js by holding or executing the item list 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.
*/
itemList: options.map(item => item.label),
/**
* Purpose: success supports index.js by holding or executing the success 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.
*/
success: async result => {
const target = options[result.tapIndex]
if (!target) {
return
}
try {
await orderApi.updateOrderStatus(order.id, target.status)
markDirty('admin-workbench')
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'
})
this.loadOrders()
} 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'
})
}
}
})
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,95 @@
<navigation-bar title="订单" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">预约履约</text>
<text class="hero-title">按当前角色范围查看订单</text>
<text class="hero-desc">店长和平台管理员看当前权限范围订单,美甲师仅看属于自己的预约单,并只能完成属于自己的订单。</text>
</view>
<view class="surface-card">
<text class="section-title">筛选条件</text>
<view class="search-row">
<input class="field-input search-input" placeholder="输入订单号搜索" placeholder-class="placeholder" value="{{keyword}}" bindinput="handleKeywordInput" confirm-type="search" bindconfirm="handleSearch"></input>
<button class="secondary-btn" bindtap="handleSearch">搜索</button>
</view>
<view class="chip-row">
<block wx:for="{{statusOptions}}" wx:key="label">
<view class="chip-btn {{status === item.value ? 'active' : ''}}" data-status="{{item.value}}" bindtap="handleStatusChange">{{item.label}}</view>
</block>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.orderNo}}</text>
<text class="list-subtitle">{{item.customerNickname || item.userNickname || '未命名用户'}} · {{item.customerPhoneMasked || '--'}}</text>
</view>
<text class="badge">{{item.displayStatusText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">订单金额</text>
<text class="meta-value">¥{{item.displayPayAmount}}</text>
</view>
<view class="meta-item">
<text class="meta-label">支付状态</text>
<text class="meta-value">{{item.displayPaymentStatusText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">所属门店</text>
<text class="meta-value">{{item.shopName || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">美甲师</text>
<text class="meta-value">{{item.artistName || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">下单时间</text>
<text class="meta-value">{{item.displayCreateTime}}</text>
</view>
</view>
<view wx:if="{{item.items.length}}" class="order-items">
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="order-item-row">
<view class="order-item-main">
<text class="order-item-title">{{orderItem.productTitle || '订单项目'}}</text>
<text class="order-item-line">美甲师:{{orderItem.artistName || '--'}}</text>
<text wx:if="{{orderItem.displayAppointmentTime}}" class="order-item-line">预约时间:{{orderItem.displayAppointmentTime}}</text>
<text class="order-item-review">{{orderItem.reviewStatusText}}</text>
<text wx:if="{{orderItem.reviewSummary && orderItem.reviewSummary.contentText}}" class="order-item-line">评价内容:{{orderItem.reviewSummary.contentText}}</text>
<view wx:if="{{orderItem.pendingArtistChangeRequest}}" class="change-note">
<text class="change-note-title">改派申请待处理</text>
<text class="change-note-desc">{{orderItem.pendingArtistChangeRequest.displayText}}</text>
<text wx:if="{{orderItem.pendingArtistChangeRequest.reasonText}}" class="change-note-desc">原因:{{orderItem.pendingArtistChangeRequest.reasonText}}</text>
</view>
</view>
<view wx:if="{{orderItem.canRequestArtistChange}}" class="mini-btn soft" data-order-id="{{item.id}}" data-order-item-id="{{orderItem.id}}" bindtap="handleRequestArtistChange">申请改派</view>
</view>
</view>
<view wx:elif="{{item.reviewStatusText}}" class="order-review-line">{{item.reviewStatusText}}</view>
<view class="list-actions">
<view class="mini-btn" data-order="{{item}}" bindtap="handleOpenOrder">查看详情</view>
<view wx:if="{{canManualConfirmPay && item.canManualConfirmPay}}" class="mini-btn primary" data-order="{{item}}" bindtap="handleManualConfirmPay">确认支付</view>
<view wx:if="{{item.status !== 2}}" class="mini-btn primary" data-order="{{item}}" bindtap="handleProcessOrder">处理订单</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无订单</text>
<text class="empty-desc">当前筛选条件下没有符合的订单记录,切换状态或清空关键字后再试一次。</text>
</view>
<view class="admin-bottom-nav">
<view class="admin-bottom-link" bindtap="handleOpenWorkbench">工作台</view>
<view class="admin-bottom-link active">订单</view>
<view class="admin-bottom-link" bindtap="handleOpenManage">经营</view>
<view class="admin-bottom-link" bindtap="handleOpenProfile">我的</view>
</view>
</view>
</view>
@@ -0,0 +1,83 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.order-items {
margin-top: 22rpx;
border-top: 1rpx solid rgba(246, 239, 231, 0.12);
}
.order-item-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18rpx;
padding: 18rpx 0;
border-bottom: 1rpx solid rgba(246, 239, 231, 0.1);
}
.order-item-row:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.order-item-main {
flex: 1;
min-width: 0;
}
.order-item-title,
.order-item-line,
.order-item-review,
.order-review-line,
.change-note-title,
.change-note-desc {
display: block;
}
.order-item-title {
color: #f6efe7;
font-size: 26rpx;
font-weight: 700;
line-height: 1.5;
}
.order-item-line,
.order-review-line,
.change-note-desc {
margin-top: 8rpx;
color: rgba(246, 239, 231, 0.68);
font-size: 23rpx;
line-height: 1.55;
}
.order-item-review {
margin-top: 10rpx;
color: #f0c987;
font-size: 23rpx;
font-weight: 700;
line-height: 1.5;
}
.change-note {
margin-top: 14rpx;
padding: 16rpx;
border-radius: 14rpx;
background: rgba(240, 201, 135, 0.1);
border: 1rpx solid rgba(240, 201, 135, 0.3);
}
.change-note-title {
color: #f0c987;
font-size: 23rpx;
font-weight: 700;
line-height: 1.5;
}
.mini-btn.soft {
color: #081518;
background: #f0c987;
border-color: #f0c987;
white-space: nowrap;
}
@@ -0,0 +1,333 @@
/**
* Purpose: permissionApi supports index.js by holding or executing the permission 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 permissionApi = require('../../api/permission')
/**
* 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: permissionUtils supports index.js by holding or executing the permission utils 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 permissionUtils = require('../../utils/permission')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
/**
* Purpose: buildPermissionGroups supports index.js by holding or executing the build permission groups 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 buildPermissionGroups(list, checkedIds, assignableIds) {
const groups = permissionUtils.groupPermissionsByGroup(list)
return Object.keys(groups).map(group => ({
group,
items: groups[group].map(item => ({
...item,
valueId: String(item.id),
checked: checkedIds.includes(String(item.id)),
disabled: assignableIds.length ? !assignableIds.includes(String(item.id)) : false
}))
}))
}
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: 'definition-create',
/**
* 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: userId supports index.js by holding or executing the user 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.
*/
userId: '',
/**
* Purpose: currentUser supports index.js by holding or executing the current user 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.
*/
currentUser: null,
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups 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.
*/
permissionGroups: [],
/**
* 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: permissionCode supports index.js by holding or executing the permission 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.
*/
permissionCode: '',
/**
* Purpose: permissionName supports index.js by holding or executing the permission 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.
*/
permissionName: '',
/**
* Purpose: permissionGroup supports index.js by holding or executing the permission group 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.
*/
permissionGroup: '',
/**
* 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: 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 : 'definition-create'
this.setData({
mode,
/**
* Purpose: userId supports index.js by holding or executing the user 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.
*/
userId: options && options.userId ? options.userId : '',
/**
* 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: mode === 'assign' ? '分配权限' : (mode === 'definition-edit' ? '编辑权限' : '新增权限')
})
if (mode === 'assign') {
this.loadAssignData()
return
}
const currentPermission = getTempRecord('currentPermission', null)
if (mode === 'definition-edit' && currentPermission) {
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: permissionCode supports index.js by holding or executing the permission 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.
*/
permissionCode: currentPermission.permissionCode || '',
/**
* Purpose: permissionName supports index.js by holding or executing the permission 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.
*/
permissionName: currentPermission.permissionName || '',
/**
* Purpose: permissionGroup supports index.js by holding or executing the permission group 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.
*/
permissionGroup: currentPermission.permissionGroup || '',
/**
* 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: currentPermission.description || ''
}
})
}
},
/**
* 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('currentPermission')
},
async loadAssignData() {
const currentUser = getTempRecord('currentUser', null)
this.setData({
currentUser
})
try {
const [allPermissions, currentPermissions, assignableIds] = await Promise.all([
permissionApi.listAllPermissions(),
permissionApi.getUserPermissions(this.data.userId),
permissionApi.getAssignablePermissionIds(this.data.userId)
])
const checkedIds = (Array.isArray(currentPermissions) ? currentPermissions : []).map(item => String(item.id))
const normalizedAssignableIds = (Array.isArray(assignableIds) ? assignableIds : []).map(item => String(item))
this.setData({
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups 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.
*/
permissionGroups: buildPermissionGroups(allPermissions, checkedIds, normalizedAssignableIds)
})
} 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'
})
}
},
/**
* 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
})
},
/**
* Purpose: handlePermissionCheck supports index.js by holding or executing the handle permission check 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.
*/
handlePermissionCheck(event) {
const selected = event.detail.value || []
this.setData({
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups 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.
*/
permissionGroups: this.data.permissionGroups.map(group => ({
...group,
/**
* Purpose: items supports index.js by holding or executing the items 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.
*/
items: group.items.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: item.disabled ? item.checked : selected.includes(item.valueId)
}))
}))
})
},
async handleSubmit() {
if (this.data.mode === 'assign') {
const permissionIds = []
this.data.permissionGroups.forEach(group => {
group.items.forEach(item => {
if (item.checked) {
permissionIds.push(Number(item.id))
}
})
})
try {
await permissionApi.assignUserPermissions(this.data.userId, permissionIds)
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'
})
navigation.goBack('/pages/permissions/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'
})
}
return
}
if (!this.data.form.permissionCode || !this.data.form.permissionName) {
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
}
try {
if (this.data.mode === 'definition-edit') {
const currentPermission = getTempRecord('currentPermission', null)
await permissionApi.updatePermission(currentPermission.id, this.data.form)
} else {
await permissionApi.createPermission(this.data.form)
}
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'
})
navigation.goBack('/pages/permissions/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'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,51 @@
<navigation-bar title="{{title}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view wx:if="{{mode === 'assign'}}" class="surface-card">
<text class="section-title">{{currentUser.nickname || currentUser.account}}</text>
<text class="section-desc">只能勾选当前账号被允许拥有的权限。超出允许范围的权限会直接置灰,避免前端只给出“保存失败”的笼统提示。</text>
<checkbox-group bindchange="handlePermissionCheck">
<block wx:for="{{permissionGroups}}" wx:key="group">
<view class="list-card">
<text class="list-title">{{item.group}}</text>
<view class="checkbox-grid">
<block wx:for="{{item.items}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}} {{item.disabled ? 'disabled' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" disabled="{{item.disabled}}" />
{{item.permissionName}}
</label>
</block>
</view>
</view>
</block>
</checkbox-group>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存权限</button>
</view>
</view>
<view wx:else class="surface-card">
<text class="section-title">权限定义</text>
<view class="field-group">
<text class="field-label">权限编码</text>
<input class="field-input" value="{{form.permissionCode}}" data-field="permissionCode" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">权限名称</text>
<input class="field-input" value="{{form.permissionName}}" data-field="permissionName" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">权限分组</text>
<input class="field-input" value="{{form.permissionGroup}}" data-field="permissionGroup" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">描述</text>
<textarea class="field-textarea" value="{{form.description}}" data-field="description" bindinput="handleInputChange"></textarea>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存权限定义</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
@@ -0,0 +1,181 @@
/**
* Purpose: permissionApi supports index.js by holding or executing the permission 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 permissionApi = require('../../api/permission')
/**
* 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: 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')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
/**
* Purpose: groupPermissions supports index.js by holding or executing the group permissions 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 groupPermissions(list) {
const map = {}
;(Array.isArray(list) ? list : []).forEach(item => {
const group = item.permissionGroup || '未分组'
if (!map[group]) {
map[group] = []
}
map[group].push(item)
})
return Object.keys(map).map(group => ({
group,
items: map[group]
}))
}
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: permissionGroups supports index.js by holding or executing the permission groups 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.
*/
permissionGroups: [],
/**
* Purpose: users supports index.js by holding or executing the users 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.
*/
users: [],
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: false,
/**
* Purpose: canAssign supports index.js by holding or executing the can assign 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.
*/
canAssign: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入权限管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: permissionCodes.includes('permission:create'),
/**
* Purpose: canAssign supports index.js by holding or executing the can assign 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.
*/
canAssign: permissionCodes.includes('permission:assign')
})
this.loadPageData()
},
async loadPageData() {
try {
const [permissions, users] = await Promise.all([
permissionApi.listAllPermissions(),
userApi.listAllUsers().catch(() => [])
])
this.setData({
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups 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.
*/
permissionGroups: groupPermissions(permissions),
/**
* Purpose: users supports index.js by holding or executing the users 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.
*/
users: Array.isArray(users) ? users : []
})
} 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'
})
}
},
/**
* Purpose: handleCreatePermission supports index.js by holding or executing the handle create permission 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.
*/
handleCreatePermission() {
clearTempRecord('currentPermission')
navigation.navigate('/pages/permission-form/index', {
/**
* 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: 'definition-create'
}).catch(() => undefined)
},
/**
* Purpose: handleEditPermission supports index.js by holding or executing the handle edit permission 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.
*/
handleEditPermission(event) {
const permission = event.currentTarget.dataset.permission
setTempRecord('currentPermission', permission)
navigation.navigate('/pages/permission-form/index', {
/**
* 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: 'definition-edit',
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: permission.id
}).catch(() => undefined)
},
/**
* Purpose: handleAssignUser supports index.js by holding or executing the handle assign user 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.
*/
handleAssignUser(event) {
const user = event.currentTarget.dataset.user
setTempRecord('currentUser', user)
navigation.navigate('/pages/permission-form/index', {
/**
* 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: 'assign',
/**
* Purpose: userId supports index.js by holding or executing the user 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.
*/
userId: user.id
}).catch(() => undefined)
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,50 @@
<navigation-bar title="权限管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">用户授权</text>
<text class="section-desc">移动端不再铺宽表格,先选用户,再进入分组权限页勾选保存。服务端会继续兜底拦截超范围授权。</text>
<block wx:for="{{users}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.nickname || item.account}}</text>
<text class="list-subtitle">{{item.account}} · {{item.shopName || '多店铺账号'}}</text>
</view>
<text class="soft-badge">{{item.type === 4 ? '管理员' : item.type === 2 ? '店长' : item.type === 3 ? '美甲师' : '用户'}}</text>
</view>
<view class="list-actions">
<view wx:if="{{canAssign}}" class="mini-btn primary" data-user="{{item}}" bindtap="handleAssignUser">配置权限</view>
</view>
</view>
</block>
</view>
<view class="surface-card">
<view class="list-head">
<view>
<text class="section-title">权限字典</text>
<text class="section-desc">当前代码真实使用的权限定义都集中在这里,便于在手机上快速检查分组和描述是否合理。</text>
</view>
<view wx:if="{{canCreate}}" class="mini-btn primary" bindtap="handleCreatePermission">新增</view>
</view>
<block wx:for="{{permissionGroups}}" wx:key="group">
<view class="list-card">
<text class="list-title">{{item.group}}</text>
<block wx:for="{{item.items}}" wx:key="id">
<view class="divider-line"></view>
<view class="list-head">
<view>
<text class="list-subtitle">{{item.permissionCode}}</text>
<text class="list-title">{{item.permissionName}}</text>
<text class="list-subtitle">{{item.description || '暂无描述'}}</text>
</view>
<view wx:if="{{canCreate}}" class="mini-btn" data-permission="{{item}}" bindtap="handleEditPermission">编辑</view>
</view>
</block>
</view>
</block>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,811 @@
/**
* 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'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,100 @@
<navigation-bar title="{{mode === 'edit' ? '编辑作品' : '新增作品'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">作品信息</text>
<view class="field-group">
<text class="field-label">作品标题</text>
<input class="field-input" value="{{form.title}}" data-field="title" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">所属店铺</text>
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">作品价格</text>
<input class="field-input" type="digit" value="{{form.price}}" data-field="price" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">大约耗时</text>
<input class="field-input" value="{{form.approximateDuration}}" data-field="approximateDuration" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">作品描述</text>
<textarea class="field-textarea" value="{{form.description}}" data-field="description" bindinput="handleInputChange"></textarea>
</view>
<view class="field-group">
<text class="field-label">适合人群</text>
<textarea class="field-textarea" value="{{form.targetAudience}}" data-field="targetAudience" bindinput="handleInputChange" placeholder="例如:短甲、通勤、婚礼跟妆"></textarea>
</view>
<view class="field-group">
<text class="field-label">注意事项</text>
<textarea class="field-textarea" value="{{form.precautions}}" data-field="precautions" bindinput="handleInputChange" placeholder="例如:完成后 24 小时内避免长时间热水浸泡"></textarea>
</view>
<view class="field-group">
<text class="field-label">点赞数量</text>
<input class="field-input" type="number" value="{{form.likeCount}}" data-field="likeCount" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">收藏数量</text>
<input class="field-input" type="number" value="{{form.collectCount}}" data-field="collectCount" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">作品图片</text>
<view class="list-actions">
<view class="mini-btn primary" bindtap="handleUploadImages">上传图片</view>
</view>
<view wx:if="{{form.imageFileIds.length}}" class="image-grid">
<block wx:for="{{form.imageFileIds}}" wx:key="*this">
<view class="image-chip">{{item}}</view>
</block>
</view>
</view>
<view class="field-group">
<text class="field-label">绑定标签</text>
<checkbox-group bindchange="handleTagChange">
<block wx:for="{{tags}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="field-group">
<text class="field-label">可预约美甲师</text>
<checkbox-group bindchange="handleArtistChange">
<block wx:for="{{artists}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="field-group">
<text class="field-label">可用优惠券</text>
<checkbox-group bindchange="handleCouponChange">
<block wx:for="{{coupons}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view wx:if="{{uploading}}" class="hint-card">图片上传中,当前进度 {{uploadProgress}}%</view>
<view class="action-row">
<button class="primary-btn" disabled="{{uploading}}" bindtap="handleSubmit">保存作品</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
+292
View File
@@ -0,0 +1,292 @@
/**
* 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: 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 { setTempRecord, clearTempRecord } = require('../../utils/storage')
const { consumeDirty } = require('../../utils/page-state')
/**
* Purpose: PAGE_KEY supports index.js by holding or executing the page 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 PAGE_KEY = 'admin-products'
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: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: '',
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: [],
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: false,
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized 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.
*/
initialized: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入作品管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: permissionCodes.includes('product:create')
})
if (!this.data.initialized || consumeDirty(PAGE_KEY)) {
this.loadProducts()
}
},
/**
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input 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.
*/
handleKeywordInput(event) {
this.setData({
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: event.detail.value
})
},
/**
* Purpose: handleSearch supports index.js by holding or executing the handle search 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.
*/
handleSearch() {
this.loadProducts()
},
async loadProducts() {
const requestId = (this._loadRequestId || 0) + 1
this._loadRequestId = requestId
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: true
})
try {
const result = await productApi.listProducts({
/**
* Purpose: page supports index.js by holding or executing the page 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.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size 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.
*/
size: 20,
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: this.data.keyword || undefined
})
if (requestId !== this._loadRequestId) {
return
}
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
...item,
/**
* Purpose: displayPrice supports index.js by holding or executing the display 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.
*/
displayPrice: format.formatPrice(item.price),
/**
* Purpose: displayShopName supports index.js by holding or executing the display shop 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.
*/
displayShopName: item.shopName || '当前店铺',
/**
* Purpose: displayDuration supports index.js by holding or executing the display 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.
*/
displayDuration: item.approximateDuration || '未设置时长',
/**
* Purpose: displayTagText supports index.js by holding or executing the display tag text 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.
*/
displayTagText: Array.isArray(item.tagList) ? item.tagList.join(' / ') : (item.tags || '未设置标签')
})),
/**
* Purpose: initialized supports index.js by holding or executing the initialized 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.
*/
initialized: true
})
} catch (error) {
if (requestId !== this._loadRequestId) {
return
}
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 {
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: false
})
}
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create 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.
*/
handleCreate() {
clearTempRecord('currentProduct')
navigation.navigate('/pages/product-form/index', {
/**
* 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'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit 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.
*/
handleEdit(event) {
const product = event.currentTarget.dataset.product
setTempRecord('currentProduct', product)
navigation.navigate('/pages/product-form/index', {
/**
* 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: 'edit',
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: product.id
}).catch(() => undefined)
},
/**
* Purpose: handleDelete supports index.js by holding or executing the handle delete 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.
*/
handleDelete(event) {
const product = event.currentTarget.dataset.product
wx.showModal({
/**
* 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: content supports index.js by holding or executing the content 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.
*/
content: `确认删除作品“${product.title}”吗?`,
/**
* Purpose: success supports index.js by holding or executing the success 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.
*/
success: async result => {
if (!result.confirm) {
return
}
try {
await productApi.deleteProduct(product.id)
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'
})
this.loadProducts()
} 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'
})
}
}
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,50 @@
<navigation-bar title="作品管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">作品列表</text>
<view class="search-row">
<input class="field-input search-input" placeholder="按标题搜索作品" placeholder-class="placeholder" value="{{keyword}}" bindinput="handleKeywordInput" confirm-type="search" bindconfirm="handleSearch"></input>
<button class="secondary-btn" bindtap="handleSearch">搜索</button>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.title}}</text>
<text class="list-subtitle">{{item.displayShopName}} · {{item.displayDuration}}</text>
</view>
<text class="badge">¥{{item.displayPrice}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">标签</text>
<text class="meta-value">{{item.displayTagText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">点赞 / 收藏</text>
<text class="meta-value">{{item.likeCount || 0}} / {{item.collectCount || 0}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn primary" data-product="{{item}}" bindtap="handleEdit">编辑</view>
<view class="mini-btn danger" data-product="{{item}}" bindtap="handleDelete">删除</view>
</view>
</view>
</block>
<view wx:if="{{loading && !list.length}}" class="empty-state">
<text class="empty-title">正在加载作品列表</text>
</view>
<view wx:elif="{{!list.length}}" class="empty-state">
<text class="empty-title">还没有作品</text>
<text class="empty-desc">先上传图片、绑定标签和美甲师后,就可以把完整作品发布到门店里。</text>
</view>
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
+251
View File
@@ -0,0 +1,251 @@
/**
* Purpose: authApi supports index.js by holding or executing the auth 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 authApi = require('../../api/auth')
/**
* 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: permission supports index.js by holding or executing the permission 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 permission = require('../../utils/permission')
const sessionSwitch = require('../../../utils/session-switch')
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: userInfo supports index.js by holding or executing the user info 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.
*/
userInfo: null,
/**
* Purpose: currentShop supports index.js by holding or executing the current shop 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.
*/
currentShop: null,
/**
* Purpose: permissionCodes supports index.js by holding or executing the permission codes 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.
*/
permissionCodes: [],
/**
* Purpose: roleLabel supports index.js by holding or executing the role 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.
*/
roleLabel: '',
/**
* Purpose: shopScopeText supports index.js by holding or executing the shop scope text 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.
*/
shopScopeText: '',
/**
* Purpose: currentShopText supports index.js by holding or executing the current shop text 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.
*/
currentShopText: ''
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入个人中心')) {
return
}
const app = getApp()
const userInfo = app.globalData.userInfo
const currentShop = app.globalData.currentShop
const shopScopeText = userInfo
? (Array.isArray(userInfo.shopNames) && userInfo.shopNames.length
? userInfo.shopNames.join(' / ')
: (userInfo.shopName || '--'))
: '--'
this.setData({
userInfo,
currentShop,
/**
* Purpose: permissionCodes supports index.js by holding or executing the permission codes 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.
*/
permissionCodes: app.globalData.permissionCodes || [],
/**
* Purpose: roleLabel supports index.js by holding or executing the role 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.
*/
roleLabel: userInfo ? permission.getRoleLabel(userInfo.type) : '--',
shopScopeText,
/**
* Purpose: currentShopText supports index.js by holding or executing the current shop text 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.
*/
currentShopText: currentShop ? `当前店铺:${currentShop.shopName}` : '当前为平台总览模式'
})
},
/**
* Purpose: handleOpenOrders supports index.js by holding or executing the handle open orders 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.
*/
handleOpenOrders() {
navigation.switchTab('/pages/orders/index').catch(() => undefined)
},
/**
* Purpose: handleOpenManage supports index.js by holding or executing the handle open manage 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.
*/
handleOpenManage() {
navigation.switchTab('/pages/manage/index').catch(() => undefined)
},
handleOpenWorkbench() {
navigation.switchTab('/pages/workbench/index').catch(() => undefined)
},
handleOpenCustomerHome() {
sessionSwitch.openCustomerHome()
},
async handleSwitchShop() {
const userInfo = this.data.userInfo
if (!userInfo || !userInfo.account) {
return
}
try {
const result = await authApi.getLoginShops(userInfo.account)
const shops = Array.isArray(result && result.shops) ? result.shops : []
const allowShoplessLogin = Boolean(result && result.allowShoplessLogin)
if (allowShoplessLogin && permission.isPlatformAdmin(userInfo)) {
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 items = shops.map(shop => ({
/**
* Purpose: label supports index.js by holding or executing the 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.
*/
label: shop.shopName,
/**
* Purpose: value supports index.js by holding or executing the 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.
*/
value: shop.id
}))
if (!items.length) {
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
}
wx.showActionSheet({
/**
* Purpose: itemList supports index.js by holding or executing the item list 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.
*/
itemList: items.map(item => item.label),
/**
* Purpose: success supports index.js by holding or executing the success 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.
*/
success: async action => {
const target = items[action.tapIndex]
if (!target) {
return
}
try {
await getApp().switchAdminShop(target.value || undefined)
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'
})
this.onShow()
} 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'
})
}
}
})
} 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 handleLogout() {
try {
await authApi.logout().catch(() => undefined)
} finally {
getApp().clearAdminSession()
wx.reLaunch({
/**
* Purpose: url supports index.js by holding or executing the url 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.
*/
url: '/admin/pages/login/index'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,61 @@
<navigation-bar title="我的" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">{{userInfo.account || '后台账号'}}</text>
<text class="hero-title">{{userInfo.nickname || '未设置昵称'}}</text>
<text class="hero-desc">当前角色:{{roleLabel}}。{{currentShopText}}</text>
</view>
<view class="surface-card">
<text class="section-title">账号信息</text>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">账号</text>
<text class="meta-value">{{userInfo.account || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">权限数</text>
<text class="meta-value">{{permissionCodes.length}}</text>
</view>
<view class="meta-item">
<text class="meta-label">店铺状态</text>
<text class="meta-value">{{currentShop ? currentShop.shopName : '平台总览模式'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">可登录店铺</text>
<text class="meta-value">{{shopScopeText}}</text>
</view>
</view>
<view wx:if="{{currentShop}}" class="action-row">
<button class="secondary-btn" bindtap="handleSwitchShop">切换店铺</button>
</view>
</view>
<view class="surface-card">
<text class="section-title">常用入口</text>
<view class="list-actions">
<view class="mini-btn primary" bindtap="handleOpenOrders">查看订单</view>
<view class="mini-btn" bindtap="handleOpenManage">经营模块</view>
</view>
</view>
<view class="surface-card">
<text class="section-title">退出登录</text>
<text class="section-desc">退出后会清理管理端会话、当前店铺和权限快照;再次进入需要重新登录。</text>
<view class="action-row">
<button class="danger-btn" bindtap="handleLogout">退出当前账号</button>
</view>
</view>
<view class="admin-bottom-nav">
<view class="admin-bottom-link" bindtap="handleOpenWorkbench">工作台</view>
<view class="admin-bottom-link" bindtap="handleOpenOrders">订单</view>
<view class="admin-bottom-link" bindtap="handleOpenManage">经营</view>
<view class="admin-bottom-link active">我的</view>
</view>
<view class="customer-switch-link" bindtap="handleOpenCustomerHome">返回前台</view>
</view>
</view>
@@ -0,0 +1,14 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.customer-switch-link {
display: flex;
align-items: center;
justify-content: center;
min-height: 72rpx;
color: #f7dba7;
font-size: 26rpx;
font-weight: 700;
}
@@ -0,0 +1,187 @@
const scheduleApi = require('../../api/artist-schedule')
const navigation = require('../../utils/navigation')
const permission = require('../../utils/permission')
const format = require('../../utils/format')
const { markDirty } = require('../../utils/page-state')
function todayText(offset) {
const date = new Date()
date.setDate(date.getDate() + (offset || 0))
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
return `${date.getFullYear()}-${month}-${day}`
}
function safeList(value) {
return Array.isArray(value) ? value : []
}
Page({
data: {
loading: false,
list: [],
startDate: todayText(0),
endDate: todayText(6),
artistId: '',
canEdit: false,
form: {
artistId: '',
workDate: todayText(0),
startTime: '10:00',
endTime: '18:00',
slotMinutes: '60',
capacity: '1',
remark: ''
}
},
onShow() {
if (!navigation.ensureLogin('进入排班管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
canEdit: permission.hasPermission(permissionCodes, 'schedule:edit')
})
this.loadSchedules()
},
onPullDownRefresh() {
this.loadSchedules().finally(() => {
wx.stopPullDownRefresh()
})
},
buildQuery() {
const query = {}
;['artistId', 'startDate', 'endDate'].forEach(key => {
const value = String(this.data[key] || '').trim()
if (value) {
query[key] = value
}
})
return query
},
async loadSchedules() {
this.setData({ loading: true })
try {
const list = await scheduleApi.listSchedules(this.buildQuery())
this.setData({
list: safeList(list).map(item => this.formatSchedule(item))
})
} catch (error) {
wx.showToast({
title: error.message || '排班加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
formatSchedule(item) {
const startTime = String(item.startTime || '').slice(0, 5)
const endTime = String(item.endTime || '').slice(0, 5)
return {
...item,
displayDate: format.formatDate(item.workDate),
displayTime: `${startTime || '--'} - ${endTime || '--'}`,
statusText: Number(item.status) === 0 ? '停用' : '可预约'
}
},
handleArtistInput(event) {
this.setData({ artistId: event.detail.value })
},
handleStartDateChange(event) {
this.setData({ startDate: event.detail.value })
this.loadSchedules()
},
handleEndDateChange(event) {
this.setData({ endDate: event.detail.value })
this.loadSchedules()
},
handleSearch() {
this.loadSchedules()
},
handleFormInput(event) {
const field = event.currentTarget.dataset.field
if (!field) {
return
}
this.setData({
[`form.${field}`]: event.detail.value
})
},
handleFormDateChange(event) {
this.setData({
'form.workDate': event.detail.value
})
},
handleFormStartTimeChange(event) {
this.setData({
'form.startTime': event.detail.value
})
},
handleFormEndTimeChange(event) {
this.setData({
'form.endTime': event.detail.value
})
},
async handleSaveSchedule() {
if (!this.data.canEdit) {
wx.showToast({
title: '当前账号没有编辑排班权限',
icon: 'none'
})
return
}
const form = this.data.form
const artistId = String(form.artistId || '').trim()
if (!artistId) {
wx.showToast({
title: '请填写美甲师 ID',
icon: 'none'
})
return
}
try {
await scheduleApi.saveSchedule({
artistId,
workDate: form.workDate,
startTime: form.startTime,
endTime: form.endTime,
slotMinutes: Number(form.slotMinutes) || 60,
capacity: Number(form.capacity) || 1,
status: 1,
remark: String(form.remark || '').trim()
})
markDirty('admin-workbench')
wx.showToast({
title: '排班已保存',
icon: 'none'
})
this.loadSchedules()
} catch (error) {
wx.showToast({
title: error.message || '排班保存失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,63 @@
<navigation-bar title="排班管理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">Schedule</text>
<text class="hero-title">门店排班</text>
<text class="hero-desc">按日期和美甲师查看可约班次,支持店长和管理员快速补录当天班次。</text>
</view>
<view class="surface-card">
<text class="section-title">筛选</text>
<input class="field-input compact-field" placeholder="美甲师 ID,可留空" placeholder-class="placeholder" value="{{artistId}}" bindinput="handleArtistInput" confirm-type="search" bindconfirm="handleSearch"></input>
<view class="filter-row">
<picker mode="date" value="{{startDate}}" bindchange="handleStartDateChange">
<view class="field-picker">{{startDate || '开始日期'}}</view>
</picker>
<picker mode="date" value="{{endDate}}" bindchange="handleEndDateChange">
<view class="field-picker">{{endDate || '结束日期'}}</view>
</picker>
</view>
<button class="secondary-btn compact-btn" loading="{{loading}}" bindtap="handleSearch">查询排班</button>
</view>
<view wx:if="{{canEdit}}" class="surface-card">
<text class="section-title">快速补班</text>
<view class="form-grid">
<input class="field-input" placeholder="美甲师 ID" placeholder-class="placeholder" value="{{form.artistId}}" data-field="artistId" bindinput="handleFormInput"></input>
<picker mode="date" value="{{form.workDate}}" bindchange="handleFormDateChange">
<view class="field-picker">{{form.workDate}}</view>
</picker>
<picker mode="time" value="{{form.startTime}}" bindchange="handleFormStartTimeChange">
<view class="field-picker">{{form.startTime}}</view>
</picker>
<picker mode="time" value="{{form.endTime}}" bindchange="handleFormEndTimeChange">
<view class="field-picker">{{form.endTime}}</view>
</picker>
<input class="field-input" type="number" placeholder="时段分钟" placeholder-class="placeholder" value="{{form.slotMinutes}}" data-field="slotMinutes" bindinput="handleFormInput"></input>
<input class="field-input" type="number" placeholder="容量" placeholder-class="placeholder" value="{{form.capacity}}" data-field="capacity" bindinput="handleFormInput"></input>
</view>
<textarea class="field-textarea compact-textarea" placeholder="备注,可留空" placeholder-class="placeholder" value="{{form.remark}}" data-field="remark" bindinput="handleFormInput"></textarea>
<button class="primary-btn compact-btn" loading="{{loading}}" bindtap="handleSaveSchedule">保存排班</button>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.displayDate}} · 美甲师 {{item.artistId}}</text>
<text class="list-subtitle">{{item.displayTime}} · {{item.slotMinutes || 60}} 分钟/档 · 容量 {{item.capacity || 1}}</text>
</view>
<text class="{{item.status === 0 ? 'soft-badge' : 'success-badge'}}">{{item.statusText}}</text>
</view>
<view wx:if="{{item.remark}}" class="hint-card">{{item.remark}}</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无排班</text>
<text class="empty-desc">当前日期范围没有可展示班次。</text>
</view>
</view>
</view>
@@ -0,0 +1,27 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.compact-field,
.compact-btn,
.compact-textarea {
margin-top: 16rpx;
}
.filter-row picker,
.form-grid picker {
flex: 1;
min-width: 0;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14rpx;
margin-top: 18rpx;
}
.compact-textarea {
min-height: 140rpx;
}
@@ -0,0 +1,226 @@
/**
* Purpose: auditApi reads immutable high-risk operation audit logs for admin review.
* Usage: call listLogs with filter and pagination params from this page.
*/
const auditApi = require('../../api/security-audit')
/**
* Purpose: navigation centralizes page transitions and fallback back behavior.
* Usage: call goBack when the custom navigation bar back event fires.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: format prepares backend timestamps for compact mini-program display.
* Usage: call formatDateTime before assigning audit rows to page data.
*/
const format = require('../../utils/format')
/**
* Purpose: RESULT_OPTIONS drives the audit result segmented filter.
* Usage: keep values aligned with backend result strings accepted by /admin/security-audit/logs.
*/
const RESULT_OPTIONS = [
{ label: '全部', value: '' },
{ label: '成功', value: 'SUCCESS' },
{ label: '失败', value: 'FAIL' }
]
Page({
/**
* Purpose: data stores filter, pagination, and rendered audit rows for the read-only audit page.
* Usage: WXML binds these fields and page methods update them through setData.
*/
data: {
/**
* Purpose: loading indicates whether an audit-log query is currently in flight.
* Usage: bind it to the search button and bottom loader to prevent duplicate requests.
*/
loading: false,
/**
* Purpose: list holds formatted audit log rows returned by the backend.
* Usage: append or replace it after listLogs responses.
*/
list: [],
/**
* Purpose: page tracks the current backend page number.
* Usage: increment it only after a successful load-more response.
*/
page: 1,
/**
* Purpose: size controls how many audit rows each request asks for.
* Usage: pass it unchanged to listLogs so paging remains stable.
*/
size: 10,
/**
* Purpose: hasMore tells the page whether another backend page is available.
* Usage: set it from response totals and guard onReachBottom.
*/
hasMore: true,
/**
* Purpose: account filters audit logs by operator account.
* Usage: bind it to the search input and pass non-empty values to the API.
*/
account: '',
/**
* Purpose: action filters audit logs by action code or action keyword.
* Usage: bind it to the search input and pass non-empty values to the API.
*/
action: '',
/**
* Purpose: result filters audit logs by success or failure status.
* Usage: update it from result chips and pass it to the backend query.
*/
result: '',
/**
* Purpose: resultOptions renders available result filter chips.
* Usage: iterate it in WXML and compare each option value with data.result.
*/
resultOptions: RESULT_OPTIONS
},
/**
* Purpose: onLoad performs the initial audit-log query for authorized users.
* Usage: mini-program runtime calls it once when the page is opened from Manage.
*/
onLoad() {
this.loadLogs(true)
},
/**
* Purpose: onPullDownRefresh reloads the first audit-log page after manual refresh.
* Usage: mini-program runtime calls it and the method stops the refresh animation after completion.
*/
async onPullDownRefresh() {
await this.loadLogs(true)
wx.stopPullDownRefresh()
},
/**
* Purpose: onReachBottom loads the next page when the operator scrolls to the bottom.
* Usage: mini-program runtime calls it and the method respects loading and hasMore guards.
*/
onReachBottom() {
if (!this.data.loading && this.data.hasMore) {
this.loadLogs(false)
}
},
/**
* Purpose: buildQuery creates a clean backend query object from page filters and pagination.
* Usage: call it before listLogs so empty filters are not sent.
*/
buildQuery(page) {
const query = {
page,
size: this.data.size
}
;['account', 'action', 'result'].forEach(key => {
const value = String(this.data[key] || '').trim()
if (value) {
query[key] = value
}
})
return query
},
/**
* Purpose: loadLogs queries audit logs and updates list pagination state.
* Usage: pass true for a fresh search and false for infinite-scroll loading.
*/
async loadLogs(reset) {
if (this.data.loading) {
return
}
const nextPage = reset ? 1 : this.data.page + 1
this.setData({ loading: true })
try {
const response = await auditApi.listLogs(this.buildQuery(nextPage))
const records = Array.isArray(response && response.records)
? response.records
: (Array.isArray(response && response.list) ? response.list : [])
const total = Number(response && response.total) || 0
const currentList = reset ? [] : this.data.list
const list = currentList.concat(records.map(item => this.formatLog(item)))
this.setData({
list,
page: nextPage,
hasMore: total ? list.length < total : records.length >= this.data.size
})
} catch (error) {
wx.showToast({
title: error.message || '审计日志加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
/**
* Purpose: formatLog normalizes one backend audit row for compact display.
* Usage: call it on every record returned from listLogs before rendering.
*/
formatLog(item) {
return {
...item,
displayTime: format.formatDateTime(item.operateTime || item.createTime),
resultText: item.result === 'SUCCESS' ? '成功' : '失败',
resultClass: item.result === 'SUCCESS' ? 'success' : 'fail',
operatorText: item.account || item.operatorAccount || '--',
reasonText: item.reason || item.failureReason || item.errorMessage || item.remark || ''
}
},
/**
* Purpose: handleAccountInput updates the operator-account filter as the input changes.
* Usage: bind it to the account input field.
*/
handleAccountInput(event) {
this.setData({ account: event.detail.value })
},
/**
* Purpose: handleActionInput updates the action-code filter as the input changes.
* Usage: bind it to the action input field.
*/
handleActionInput(event) {
this.setData({ action: event.detail.value })
},
/**
* Purpose: handleResultChange switches between all, success, and fail filters.
* Usage: bind it to result chips with data-result.
*/
handleResultChange(event) {
this.setData({ result: event.currentTarget.dataset.result || '' })
this.loadLogs(true)
},
/**
* Purpose: handleSearch reloads logs using the current text filters.
* Usage: bind it to keyboard confirm and the search button.
*/
handleSearch() {
this.loadLogs(true)
},
/**
* Purpose: handleReset clears filters and reloads the first audit-log page.
* Usage: bind it to the reset button in the filter card.
*/
handleReset() {
this.setData({
account: '',
action: '',
result: ''
})
this.loadLogs(true)
},
/**
* Purpose: handleBack returns to Manage when this page is opened as a standalone stack page.
* Usage: bind it to the custom navigation bar back event.
*/
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,64 @@
<navigation-bar title="审计日志" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">Security Audit</text>
<text class="hero-title">高危操作留痕</text>
<text class="hero-desc">按账号、动作和结果查看后台关键操作记录,失败原因会保留在详情行中。</text>
</view>
<view class="surface-card">
<text class="section-title">筛选</text>
<input class="field-input" placeholder="操作者账号" placeholder-class="placeholder" value="{{account}}" bindinput="handleAccountInput" confirm-type="search" bindconfirm="handleSearch"></input>
<input class="field-input" placeholder="动作编码" placeholder-class="placeholder" value="{{action}}" bindinput="handleActionInput" confirm-type="search" bindconfirm="handleSearch"></input>
<view class="chip-row">
<block wx:for="{{resultOptions}}" wx:key="value">
<view class="chip-btn {{result === item.value ? 'active' : ''}}" data-result="{{item.value}}" bindtap="handleResultChange">{{item.label}}</view>
</block>
</view>
<view class="actions-row">
<button class="secondary-btn" bindtap="handleReset">重置</button>
<button class="primary-btn" loading="{{loading}}" bindtap="handleSearch">查询</button>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.action || '--'}}</text>
<text class="list-subtitle">{{item.operatorText}} · {{item.displayTime}}</text>
</view>
<text class="audit-badge {{item.resultClass}}">{{item.resultText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">业务类型</text>
<text class="meta-value">{{item.businessType || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">业务 ID</text>
<text class="meta-value">{{item.businessId || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">IP</text>
<text class="meta-value">{{item.ipAddress || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">原因</text>
<text class="meta-value">{{item.reasonText || '无'}}</text>
</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无审计日志</text>
<text class="empty-desc">当前筛选条件下没有高危操作记录。</text>
</view>
<view wx:if="{{loading}}" class="loading-line">加载中...</view>
<view wx:if="{{list.length && !hasMore}}" class="loading-line">已加载全部</view>
</view>
</view>
@@ -0,0 +1,36 @@
@import "../../app.wxss";
.field-input {
margin-top: 16rpx;
}
.actions-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16rpx;
margin-top: 20rpx;
}
.audit-badge {
flex-shrink: 0;
padding: 8rpx 14rpx;
border-radius: 8rpx;
font-size: 22rpx;
font-weight: 700;
}
.audit-badge.success {
color: #73d99f;
background: rgba(115, 217, 159, 0.12);
}
.audit-badge.fail {
color: #ff9b8b;
background: rgba(255, 155, 139, 0.14);
}
.loading-line {
color: #7e8f8c;
font-size: 24rpx;
text-align: center;
padding: 24rpx 0;
}
@@ -0,0 +1,423 @@
/**
* 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: 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')
/**
* 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-shop-form'
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: 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: 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: statusOptions supports index.js by holding or executing the status 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.
*/
statusOptions: ['启用', '停用'],
/**
* Purpose: statusIndex supports index.js by holding or executing the status 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.
*/
statusIndex: 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: shopName supports index.js by holding or executing the shop 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.
*/
shopName: '',
/**
* 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: address supports index.js by holding or executing the address 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.
*/
address: '',
/**
* Purpose: businessHours supports index.js by holding or executing the business hours 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.
*/
businessHours: '',
/**
* Purpose: coverImageFileId supports index.js by holding or executing the cover image file 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.
*/
coverImageFileId: '',
/**
* 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: 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 currentShop = getTempRecord('currentShopRecord', null)
const draft = getDraftValue(DRAFT_KEY, null)
this.setData({
mode,
/**
* 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: options && options.id ? options.id : ''
})
if (mode === 'edit' && currentShop) {
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: shopName supports index.js by holding or executing the shop 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.
*/
shopName: currentShop.shopName || '',
/**
* 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: currentShop.description || '',
/**
* Purpose: address supports index.js by holding or executing the address 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.
*/
address: currentShop.address || '',
/**
* Purpose: businessHours supports index.js by holding or executing the business hours 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.
*/
businessHours: currentShop.businessHours || '',
/**
* Purpose: coverImageFileId supports index.js by holding or executing the cover image file 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.
*/
coverImageFileId: currentShop.coverImageFileId || '',
/**
* 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: currentShop.imageFileIds ? String(currentShop.imageFileIds).split(',').filter(Boolean) : []
},
/**
* Purpose: statusIndex supports index.js by holding or executing the status 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.
*/
statusIndex: Number(currentShop.status) === 0 ? 1 : 0
})
}
if (draft && draft.mode === mode) {
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
},
/**
* Purpose: statusIndex supports index.js by holding or executing the status 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.
*/
statusIndex: draft.statusIndex === 1 ? 1 : this.data.statusIndex
})
}
},
/**
* 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('currentShopRecord')
clearDraftTimer(this)
},
/**
* Purpose: scheduleShopDraft supports index.js by holding or executing the schedule shop 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.
*/
scheduleShopDraft() {
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: statusIndex supports index.js by holding or executing the status 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.
*/
statusIndex: this.data.statusIndex,
/**
* 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: 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.scheduleShopDraft()
},
/**
* Purpose: handleStatusChange supports index.js by holding or executing the handle status 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.
*/
handleStatusChange(event) {
this.setData({
/**
* Purpose: statusIndex supports index.js by holding or executing the status 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.
*/
statusIndex: Number(event.detail.value)
})
this.scheduleShopDraft()
},
async handleUploadBanner() {
await this.handleUpload('admin-shop-banner', true)
},
async handleUploadImages() {
await this.handleUpload('admin-shop-image', false)
},
async handleUpload(scene, isBanner) {
try {
const files = await upload.chooseImageFiles({
/**
* Purpose: count supports index.js by holding or executing the 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.
*/
count: isBanner ? 1 : 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 results = await upload.uploadImageFiles({
files,
scene,
/**
* 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)
})
}
})
if (isBanner) {
this.setData({
'form.coverImageFileId': results[0] ? String(results[0].id) : ''
})
} else {
this.setData({
'form.imageFileIds': this.data.form.imageFileIds.concat(results.map(item => String(item.id)))
})
}
this.scheduleShopDraft()
} 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.shopName) {
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: shopName supports index.js by holding or executing the shop 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.
*/
shopName: this.data.form.shopName,
/**
* 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: address supports index.js by holding or executing the address 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.
*/
address: this.data.form.address || undefined,
/**
* Purpose: businessHours supports index.js by holding or executing the business hours 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.
*/
businessHours: this.data.form.businessHours || undefined,
/**
* Purpose: coverImageFileId supports index.js by holding or executing the cover image file 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.
*/
coverImageFileId: this.data.form.coverImageFileId || 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: status supports index.js by holding or executing the status 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.
*/
status: this.data.statusIndex === 1 ? 0 : 1
}
try {
if (this.data.mode === 'edit') {
await shopApi.updateShop(this.data.shopId, payload)
} else {
await shopApi.createShop(payload)
}
clearDraft(DRAFT_KEY)
markDirty('admin-shops')
markDirty('admin-workbench')
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/shops/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'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,55 @@
<navigation-bar title="{{mode === 'edit' ? '编辑店铺' : '新增店铺'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">店铺信息</text>
<view class="field-group">
<text class="field-label">店铺名称</text>
<input class="field-input" value="{{form.shopName}}" data-field="shopName" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">店铺地址</text>
<input class="field-input" value="{{form.address}}" data-field="address" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">营业时间</text>
<input class="field-input" value="{{form.businessHours}}" data-field="businessHours" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">店铺描述</text>
<textarea class="field-textarea" value="{{form.description}}" data-field="description" bindinput="handleInputChange"></textarea>
</view>
<view class="field-group">
<text class="field-label">状态</text>
<picker mode="selector" range="{{statusOptions}}" value="{{statusIndex}}" bindchange="handleStatusChange">
<view class="field-picker">{{statusOptions[statusIndex]}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">Banner 图</text>
<view class="list-actions">
<view class="mini-btn primary" bindtap="handleUploadBanner">上传 Banner</view>
</view>
<view wx:if="{{form.coverImageFileId}}" class="image-grid">
<view class="image-chip">{{form.coverImageFileId}}</view>
</view>
</view>
<view class="field-group">
<text class="field-label">店铺图片</text>
<view class="list-actions">
<view class="mini-btn primary" bindtap="handleUploadImages">上传图片</view>
</view>
<view wx:if="{{form.imageFileIds.length}}" class="image-grid">
<block wx:for="{{form.imageFileIds}}" wx:key="*this">
<view class="image-chip">{{item}}</view>
</block>
</view>
</view>
<view wx:if="{{uploading}}" class="hint-card">图片上传中,当前进度 {{uploadProgress}}%</view>
<view class="action-row">
<button class="primary-btn" disabled="{{uploading}}" bindtap="handleSubmit">保存店铺</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
+247
View File
@@ -0,0 +1,247 @@
/**
* 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')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
const { consumeDirty } = require('../../utils/page-state')
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: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: '',
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: [],
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: false,
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized 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.
*/
initialized: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入店铺管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create 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.
*/
canCreate: permissionCodes.includes('shop:create')
})
if (!this.data.initialized || consumeDirty('admin-shops')) {
this.loadShops()
}
},
/**
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input 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.
*/
handleKeywordInput(event) {
this.setData({
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: event.detail.value
})
},
/**
* Purpose: handleSearch supports index.js by holding or executing the handle search 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.
*/
handleSearch() {
this.loadShops()
},
async loadShops() {
const requestId = (this._loadRequestId || 0) + 1
this._loadRequestId = requestId
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: true
})
try {
const result = await shopApi.listShops({
/**
* Purpose: page supports index.js by holding or executing the page 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.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size 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.
*/
size: 20,
/**
* Purpose: keyword supports index.js by holding or executing the keyword 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.
*/
keyword: this.data.keyword || undefined
})
if (requestId !== this._loadRequestId) {
return
}
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
...item,
/**
* Purpose: displayStatusText supports index.js by holding or executing the display status text 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.
*/
displayStatusText: Number(item.status) === 0 ? '已停用' : '启用中'
})),
/**
* Purpose: initialized supports index.js by holding or executing the initialized 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.
*/
initialized: true
})
} catch (error) {
if (requestId !== this._loadRequestId) {
return
}
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 {
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading 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.
*/
loading: false
})
}
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create 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.
*/
handleCreate() {
clearTempRecord('currentShopRecord')
navigation.navigate('/pages/shop-form/index', {
/**
* 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'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit 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.
*/
handleEdit(event) {
const shop = event.currentTarget.dataset.shop
setTempRecord('currentShopRecord', shop)
navigation.navigate('/pages/shop-form/index', {
/**
* 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: 'edit',
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: shop.id
}).catch(() => undefined)
},
/**
* Purpose: handleStatus supports index.js by holding or executing the handle status 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.
*/
handleStatus(event) {
const shop = event.currentTarget.dataset.shop
const nextStatus = Number(shop.status) === 0 ? 1 : 0
shopApi.updateShopStatus(shop.id, nextStatus)
.then(() => {
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'
})
this.loadShops()
})
.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'
})
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,50 @@
<navigation-bar title="店铺管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">店铺列表</text>
<view class="search-row">
<input class="field-input search-input" placeholder="按店铺名搜索" placeholder-class="placeholder" value="{{keyword}}" bindinput="handleKeywordInput" confirm-type="search" bindconfirm="handleSearch"></input>
<button class="secondary-btn" bindtap="handleSearch">搜索</button>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.shopName}}</text>
<text class="list-subtitle">{{item.address || '暂无地址'}}</text>
</view>
<text class="{{item.status === 0 ? 'danger-badge' : 'badge'}}">{{item.displayStatusText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">营业时间</text>
<text class="meta-value">{{item.businessHours || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">描述</text>
<text class="meta-value">{{item.description || '暂无描述'}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn primary" data-shop="{{item}}" bindtap="handleEdit">编辑</view>
<view class="mini-btn" data-shop="{{item}}" bindtap="handleStatus">{{item.status === 0 ? '启用' : '停用'}}</view>
</view>
</view>
</block>
<view wx:if="{{loading && !list.length}}" class="empty-state">
<text class="empty-title">正在加载店铺列表</text>
</view>
<view wx:elif="{{!list.length}}" class="empty-state">
<text class="empty-title">暂无店铺</text>
<text class="empty-desc">如果这是首次部署后的无店铺管理员登录,可以直接在这里创建第一家店铺。</text>
</view>
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,422 @@
/**
* Purpose: messageApi wraps admin system-message endpoints for list, publish, revoke, and target options.
* Usage: call these methods from page event handlers instead of assembling backend URLs in the view layer.
*/
const messageApi = require('../../api/system-message')
/**
* Purpose: navigation handles custom navigation-bar back behavior.
* Usage: call goBack when returning to the management menu.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: permission checks button-level rights for create and revoke actions.
* Usage: pass stored permission codes into hasPermission before rendering or running guarded actions.
*/
const permission = require('../../utils/permission')
/**
* Purpose: auth exposes the current admin permission list stored after login.
* Usage: read user info and permissions when deciding which mobile controls are available.
*/
const auth = require('../../utils/auth')
/**
* Purpose: format converts backend times into mini-program friendly text.
* Usage: call formatDateTime before assigning message rows to data.list.
*/
const format = require('../../utils/format')
/**
* Purpose: actionGuard prevents duplicate publish and revoke submissions from rapid taps.
* Usage: wrap create and revoke requests with actionGuard.run.
*/
const actionGuard = require('../../utils/action-guard')
/**
* Purpose: TARGET_TYPE_OPTIONS defines publish target scopes supported by the backend contract.
* Usage: render it as chips and submit the selected value as targetType.
*/
const TARGET_TYPE_OPTIONS = [
{ label: '全平台', value: 'PLATFORM_ALL' },
{ label: '指定店铺', value: 'SELECTED_SHOPS' },
{ label: '指定用户', value: 'SELECTED_USERS' }
]
/**
* Purpose: BUSINESS_TYPE_OPTIONS lists common business navigation types used by order review and artist-change messages.
* Usage: render it as chips and store the selected value in the publish form.
*/
const BUSINESS_TYPE_OPTIONS = [
{ label: '无', value: '' },
{ label: '订单', value: 'ORDER' },
{ label: '评价提醒', value: 'ORDER_ARTIST_REVIEW' },
{ label: '改派申请', value: 'ORDER_ARTIST_CHANGE' }
]
/**
* Purpose: initialForm returns a clean publish form with popup enabled by default.
* Usage: call it when opening the form and after successful publish.
*/
function initialForm() {
return {
title: '',
content: '',
targetType: 'PLATFORM_ALL',
targetId: '',
popupEnabled: true,
businessType: '',
businessId: '',
actionPath: ''
}
}
Page({
/**
* Purpose: data stores system-message list, publish form state, permissions, and picker options.
* Usage: WXML binds these fields and event handlers update them through setData.
*/
data: {
/**
* Purpose: loading shows whether the message list is being refreshed.
* Usage: bind it to page loading lines and refresh controls.
*/
loading: false,
/**
* Purpose: submitting shows whether publish or revoke is currently running.
* Usage: disable action buttons while true.
*/
submitting: false,
/**
* Purpose: list contains formatted system messages visible to the current admin scope.
* Usage: render it in WXML list cards.
*/
list: [],
/**
* Purpose: targetOptions stores backend-provided shops and users for scoped publishing.
* Usage: resolve targetId names and validate selected target choices.
*/
targetOptions: { shops: [], users: [] },
/**
* Purpose: formVisible controls whether the mobile publish panel is shown.
* Usage: toggle it from header and cancel buttons.
*/
formVisible: false,
/**
* Purpose: form holds publish fields sent to createMessage after validation.
* Usage: update individual properties from inputs and chips.
*/
form: initialForm(),
/**
* Purpose: targetTypeOptions renders publish target scope choices.
* Usage: iterate it in WXML chips.
*/
targetTypeOptions: TARGET_TYPE_OPTIONS,
/**
* Purpose: businessTypeOptions renders common business navigation choices.
* Usage: iterate it in WXML chips.
*/
businessTypeOptions: BUSINESS_TYPE_OPTIONS,
/**
* Purpose: canCreate controls whether the publish action is visible for the current permission set.
* Usage: derive it from message:create permission during onLoad.
*/
canCreate: false,
/**
* Purpose: canRevoke controls whether revoke buttons are visible for the current permission set.
* Usage: derive it from message:delete permission during onLoad.
*/
canRevoke: false
},
/**
* Purpose: onLoad initializes permission flags and fetches message list data.
* Usage: mini-program runtime calls it when the operator opens the system-message page.
*/
onLoad() {
const userInfo = auth.getStoredUserInfo() || {}
const codes = userInfo.permissions || []
this.setData({
canCreate: permission.hasPermission(codes, 'message:create'),
canRevoke: permission.hasPermission(codes, 'message:delete')
})
this.loadMessages()
},
/**
* Purpose: onPullDownRefresh reloads system messages and target options.
* Usage: mini-program runtime calls it after a manual refresh gesture.
*/
async onPullDownRefresh() {
await this.loadMessages()
wx.stopPullDownRefresh()
},
/**
* Purpose: loadMessages refreshes list data and target options for the publish form.
* Usage: call it on page entry, pull refresh, publish success, and revoke success.
*/
async loadMessages() {
this.setData({ loading: true })
try {
const [messages, targetOptions] = await Promise.all([
messageApi.listMessages(),
this.data.canCreate ? messageApi.getTargetOptions() : Promise.resolve(this.data.targetOptions)
])
this.setData({
list: (Array.isArray(messages) ? messages : []).map(item => this.formatMessage(item)),
targetOptions: targetOptions || { shops: [], users: [] }
})
} catch (error) {
wx.showToast({
title: error.message || '系统消息加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
/**
* Purpose: formatMessage normalizes backend message metadata for compact card display.
* Usage: call it on every list item before assigning to data.list.
*/
formatMessage(item) {
return {
...item,
displayTime: format.formatDateTime(item.publishTime || item.createTime),
statusText: Number(item.status) === 1 ? '已发布' : '已撤回',
popupText: Number(item.popupEnabled) === 1 ? '弹窗' : '不弹窗',
businessText: item.businessType || '无业务跳转',
actionText: item.actionPath || (item.businessId ? `业务 ID:${item.businessId}` : '无')
}
},
/**
* Purpose: handleShowForm opens a clean publish panel for authorized operators.
* Usage: bind it to the publish button.
*/
handleShowForm() {
this.setData({
formVisible: true,
form: initialForm()
})
},
/**
* Purpose: handleHideForm closes the publish panel without submitting.
* Usage: bind it to cancel controls.
*/
handleHideForm() {
this.setData({ formVisible: false })
},
/**
* Purpose: patchForm updates one field in the publish form.
* Usage: call it from input and chip handlers with a partial form object.
*/
patchForm(patch) {
this.setData({
form: {
...this.data.form,
...patch
}
})
},
/**
* Purpose: handleTitleInput stores the publish title input value.
* Usage: bind it to the title input.
*/
handleTitleInput(event) {
this.patchForm({ title: event.detail.value })
},
/**
* Purpose: handleContentInput stores the publish content textarea value.
* Usage: bind it to the content textarea.
*/
handleContentInput(event) {
this.patchForm({ content: event.detail.value })
},
/**
* Purpose: handleTargetIdInput stores selected shop or user id values.
* Usage: bind it to the target id input when targetType is SHOP or USER.
*/
handleTargetIdInput(event) {
this.patchForm({ targetId: event.detail.value })
},
/**
* Purpose: handleBusinessIdInput stores the optional business id used for message navigation.
* Usage: bind it to the business id input.
*/
handleBusinessIdInput(event) {
this.patchForm({ businessId: event.detail.value })
},
/**
* Purpose: handleActionPathInput stores the optional frontend action path used by popup and list taps.
* Usage: bind it to the action path input.
*/
handleActionPathInput(event) {
this.patchForm({ actionPath: event.detail.value })
},
/**
* Purpose: handleTargetTypeChange changes publish target scope and clears stale target ids.
* Usage: bind it to target type chips with data-value.
*/
handleTargetTypeChange(event) {
this.patchForm({
targetType: event.currentTarget.dataset.value,
targetId: ''
})
},
/**
* Purpose: handleBusinessTypeChange changes the optional business navigation type.
* Usage: bind it to business type chips with data-value.
*/
handleBusinessTypeChange(event) {
this.patchForm({ businessType: event.currentTarget.dataset.value || '' })
},
/**
* Purpose: handlePopupToggle flips whether recipients should see a one-time popup.
* Usage: bind it to the popup switch control.
*/
handlePopupToggle(event) {
this.patchForm({ popupEnabled: Boolean(event.detail.value) })
},
/**
* Purpose: buildPublishPayload validates the form and converts it to backend DTO shape.
* Usage: call it inside handlePublish before createMessage; it returns null after showing validation errors.
*/
buildPublishPayload() {
const form = this.data.form
const title = String(form.title || '').trim()
const content = String(form.content || '').trim()
if (!title || !content) {
wx.showToast({
title: '请填写标题和内容',
icon: 'none'
})
return null
}
const payload = {
title,
content,
targetType: form.targetType,
popupEnabled: form.popupEnabled ? 1 : 0,
businessType: form.businessType || undefined,
businessId: form.businessId ? Number(form.businessId) : undefined,
actionPath: String(form.actionPath || '').trim() || undefined
}
if (form.targetType === 'SELECTED_SHOPS') {
if (!form.targetId) {
wx.showToast({ title: '请输入店铺 ID', icon: 'none' })
return null
}
payload.shopIds = [Number(form.targetId)]
}
if (form.targetType === 'SELECTED_USERS') {
if (!form.targetId) {
wx.showToast({ title: '请输入用户 ID', icon: 'none' })
return null
}
payload.userIds = [Number(form.targetId)]
}
return payload
},
/**
* Purpose: handlePublish submits the publish form with duplicate-tap protection.
* Usage: bind it to the primary publish button.
*/
async handlePublish() {
const payload = this.buildPublishPayload()
if (!payload) {
return
}
try {
await actionGuard.run(this, 'system-message:publish', async () => {
this.setData({ submitting: true })
await messageApi.createMessage(payload)
wx.showToast({
title: '消息已发布',
icon: 'none'
})
this.setData({
formVisible: false,
form: initialForm()
})
await this.loadMessages()
}, {
message: '消息发布中,请勿重复提交'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '消息发布失败',
icon: 'none'
})
} finally {
this.setData({ submitting: false })
}
},
/**
* Purpose: handleRevoke revokes one message after operator confirmation.
* Usage: bind it to list-row revoke buttons with data-id.
*/
async handleRevoke(event) {
const id = event.currentTarget.dataset.id
if (!id) {
return
}
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '撤回消息',
content: '确认撤回这条系统消息吗?',
confirmText: '撤回',
success: res => resolve(Boolean(res.confirm))
})
})
if (!confirmed) {
return
}
try {
await actionGuard.run(this, `system-message:revoke:${id}`, async () => {
await messageApi.revokeMessage(id)
wx.showToast({
title: '已撤回',
icon: 'none'
})
await this.loadMessages()
}, {
message: '消息撤回中,请勿重复操作'
})
} catch (error) {
if (actionGuard.isGuardError(error)) {
return
}
wx.showToast({
title: error.message || '撤回失败',
icon: 'none'
})
}
},
/**
* Purpose: handleBack returns to the management menu.
* Usage: bind it to the custom navigation bar back event.
*/
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,89 @@
<navigation-bar title="系统消息" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">Message Center</text>
<text class="hero-title">消息发布与弹窗配置</text>
<text class="hero-desc">查看消息列表、弹窗开关、业务跳转和发布状态。</text>
</view>
<view wx:if="{{canCreate && !formVisible}}" class="primary-btn" bindtap="handleShowForm">发布消息</view>
<view wx:if="{{formVisible}}" class="surface-card form-card">
<text class="section-title">发布系统消息</text>
<input class="field-input" placeholder="标题" placeholder-class="placeholder" value="{{form.title}}" bindinput="handleTitleInput"></input>
<textarea class="field-textarea" placeholder="消息内容" placeholder-class="placeholder" value="{{form.content}}" maxlength="2000" bindinput="handleContentInput"></textarea>
<text class="field-label">接收范围</text>
<view class="chip-row">
<block wx:for="{{targetTypeOptions}}" wx:key="value">
<view class="chip-btn {{form.targetType === item.value ? 'active' : ''}}" data-value="{{item.value}}" bindtap="handleTargetTypeChange">{{item.label}}</view>
</block>
</view>
<input wx:if="{{form.targetType !== 'PLATFORM_ALL'}}" class="field-input" placeholder="{{form.targetType === 'SELECTED_SHOPS' ? '店铺 ID' : '用户 ID'}}" placeholder-class="placeholder" value="{{form.targetId}}" bindinput="handleTargetIdInput"></input>
<view wx:if="{{form.targetType === 'SELECTED_SHOPS' && targetOptions.shops.length}}" class="option-hint">可选店铺:{{targetOptions.shops.length}} 个,输入对应 ID 发布</view>
<view wx:if="{{form.targetType === 'SELECTED_USERS' && targetOptions.users.length}}" class="option-hint">可选用户:{{targetOptions.users.length}} 个,输入对应 ID 发布</view>
<view class="switch-row">
<text class="field-label">弹窗显示一次</text>
<switch checked="{{form.popupEnabled}}" color="#f07e57" bindchange="handlePopupToggle"></switch>
</view>
<text class="field-label">业务跳转</text>
<view class="chip-row">
<block wx:for="{{businessTypeOptions}}" wx:key="value">
<view class="chip-btn {{form.businessType === item.value ? 'active' : ''}}" data-value="{{item.value}}" bindtap="handleBusinessTypeChange">{{item.label}}</view>
</block>
</view>
<input class="field-input" placeholder="业务 ID,可选" placeholder-class="placeholder" value="{{form.businessId}}" bindinput="handleBusinessIdInput"></input>
<input class="field-input" placeholder="跳转路径,如 /orders?orderId=123" placeholder-class="placeholder" value="{{form.actionPath}}" bindinput="handleActionPathInput"></input>
<view class="actions-row">
<button class="secondary-btn" bindtap="handleHideForm">取消</button>
<button class="primary-btn" loading="{{submitting}}" bindtap="handlePublish">发布</button>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.title}}</text>
<text class="list-subtitle">{{item.publisherName || '系统'}} · {{item.displayTime}}</text>
</view>
<text class="badge">{{item.popupText}}</text>
</view>
<text wx:if="{{item.content}}" class="message-content">{{item.content}}</text>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">状态</text>
<text class="meta-value">{{item.statusText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">目标</text>
<text class="meta-value">{{item.targetTypeName || item.targetType || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">业务类型</text>
<text class="meta-value">{{item.businessText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">跳转</text>
<text class="meta-value">{{item.actionText}}</text>
</view>
</view>
<view wx:if="{{canRevoke && item.status === 1}}" class="card-actions">
<view class="mini-btn" data-id="{{item.id}}" bindtap="handleRevoke">撤回</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无系统消息</text>
<text class="empty-desc">发布后的消息会显示弹窗配置和业务跳转信息。</text>
</view>
<view wx:if="{{loading}}" class="loading-line">加载中...</view>
</view>
</view>
@@ -0,0 +1,66 @@
@import "../../app.wxss";
.form-card {
display: flex;
flex-direction: column;
gap: 16rpx;
}
.field-label {
color: #f6efe7;
font-size: 24rpx;
font-weight: 700;
}
.field-textarea {
width: 100%;
min-height: 180rpx;
box-sizing: border-box;
padding: 18rpx 20rpx;
border-radius: 8rpx;
background: rgba(255, 255, 255, 0.08);
border: 1rpx solid rgba(255, 255, 255, 0.12);
color: #f6efe7;
font-size: 26rpx;
line-height: 1.6;
}
.switch-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20rpx;
}
.option-hint {
color: #9fb3ad;
font-size: 22rpx;
line-height: 1.5;
}
.actions-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16rpx;
margin-top: 8rpx;
}
.message-content {
display: block;
margin-top: 14rpx;
color: #9fb3ad;
font-size: 24rpx;
line-height: 1.6;
}
.card-actions {
display: flex;
justify-content: flex-end;
margin-top: 18rpx;
}
.loading-line {
color: #7e8f8c;
font-size: 24rpx;
text-align: center;
padding: 24rpx 0;
}
+287
View File
@@ -0,0 +1,287 @@
/**
* 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')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
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: tagId supports index.js by holding or executing the tag 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.
*/
tagId: '',
/**
* 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: -1,
/**
* 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: 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: tagName supports index.js by holding or executing the tag 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.
*/
tagName: '',
/**
* Purpose: textColor supports index.js by holding or executing the text color 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.
*/
textColor: '#2b2b2b',
/**
* Purpose: bgColor supports index.js by holding or executing the bg color 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.
*/
bgColor: '#f6e5df',
/**
* Purpose: borderColor supports index.js by holding or executing the border color 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.
*/
borderColor: '#ef9a79'
}
},
/**
* 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 currentTag = getTempRecord('currentTag', null)
this.setData({
mode,
/**
* Purpose: tagId supports index.js by holding or executing the tag 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.
*/
tagId: options && options.id ? options.id : ''
})
if (mode === 'edit' && currentTag) {
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: tagName supports index.js by holding or executing the tag 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.
*/
tagName: currentTag.tagName || '',
/**
* Purpose: textColor supports index.js by holding or executing the text color 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.
*/
textColor: currentTag.textColor || '#2b2b2b',
/**
* Purpose: bgColor supports index.js by holding or executing the bg color 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.
*/
bgColor: currentTag.bgColor || '#f6e5df',
/**
* Purpose: borderColor supports index.js by holding or executing the border color 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.
*/
borderColor: currentTag.borderColor || '#ef9a79'
}
})
this._initialShopId = currentTag.shopId
}
this.loadShops()
},
/**
* 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('currentTag')
},
async loadShops() {
const app = getApp()
const operator = app.globalData.userInfo || {}
const currentShop = app.globalData.currentShop
try {
const list = await shopApi.listAllShops()
let shops = Array.isArray(list) ? list : []
if (Number(operator.type) !== 4 && currentShop) {
shops = shops.filter(item => String(item.id) === String(currentShop.id))
}
let shopIndex = 0
if (this._initialShopId) {
const targetIndex = shops.findIndex(item => String(item.id) === String(this._initialShopId))
if (targetIndex >= 0) {
shopIndex = targetIndex
}
}
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 : ''
})
} 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'
})
}
},
/**
* 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
})
},
/**
* 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 : ''
})
},
async handleSubmit() {
const selectedShop = this.data.shops[this.data.shopIndex]
if (!this.data.form.tagName) {
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 = {
...this.data.form,
/**
* 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
}
try {
if (this.data.mode === 'edit') {
await tagApi.updateTag(this.data.tagId, payload)
} else {
await tagApi.createTag(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/tags/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'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,34 @@
<navigation-bar title="{{mode === 'edit' ? '编辑标签' : '新增标签'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">标签信息</text>
<view class="field-group">
<text class="field-label">标签名称</text>
<input class="field-input" value="{{form.tagName}}" data-field="tagName" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">所属店铺</text>
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">文字颜色</text>
<input class="field-input" value="{{form.textColor}}" data-field="textColor" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">背景颜色</text>
<input class="field-input" value="{{form.bgColor}}" data-field="bgColor" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">边框颜色</text>
<input class="field-input" value="{{form.borderColor}}" data-field="borderColor" bindinput="handleInputChange"></input>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存标签</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
+163
View File
@@ -0,0 +1,163 @@
/**
* 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: 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')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
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: list supports index.js by holding or executing the list 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.
*/
list: []
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入标签管理')) {
return
}
this.loadTags()
},
async loadTags() {
try {
const list = await tagApi.listAllTags()
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list 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.
*/
list: (Array.isArray(list) ? list : []).map(item => ({
...item,
/**
* Purpose: displayShopName supports index.js by holding or executing the display shop 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.
*/
displayShopName: item.shopName || '当前店铺'
}))
})
} 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'
})
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create 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.
*/
handleCreate() {
clearTempRecord('currentTag')
navigation.navigate('/pages/tag-form/index', {
/**
* 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'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit 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.
*/
handleEdit(event) {
const tag = event.currentTarget.dataset.tag
setTempRecord('currentTag', tag)
navigation.navigate('/pages/tag-form/index', {
/**
* 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: 'edit',
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: tag.id
}).catch(() => undefined)
},
/**
* Purpose: handleDelete supports index.js by holding or executing the handle delete 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.
*/
handleDelete(event) {
const tag = event.currentTarget.dataset.tag
wx.showModal({
/**
* 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: content supports index.js by holding or executing the content 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.
*/
content: `确认删除标签“${tag.tagName}”吗?`,
/**
* Purpose: success supports index.js by holding or executing the success 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.
*/
success: async result => {
if (!result.confirm) {
return
}
try {
await tagApi.deleteTag(tag.id)
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'
})
this.loadTags()
} 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'
})
}
}
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
+38
View File
@@ -0,0 +1,38 @@
<navigation-bar title="标签管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">标签列表</text>
<text class="section-desc">标签按店铺绑定,同名标签可以在不同店铺重复存在,适合移动端用卡片方式快速维护。</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.tagName}}</text>
<text class="list-subtitle">{{item.displayShopName}}</text>
</view>
<text class="soft-badge">颜色标签</text>
</view>
<view class="badge-row">
<text class="soft-badge">{{item.textColor || '#333333'}}</text>
<text class="soft-badge">{{item.bgColor || '#f5f5f5'}}</text>
<text class="soft-badge">{{item.borderColor || '#dddddd'}}</text>
</view>
<view class="list-actions">
<view class="mini-btn primary" data-tag="{{item}}" bindtap="handleEdit">编辑</view>
<view class="mini-btn danger" data-tag="{{item}}" bindtap="handleDelete">删除</view>
</view>
</view>
</block>
<view wx:if="{{!list.length}}" class="empty-state">
<text class="empty-title">还没有标签</text>
<text class="empty-desc">先创建一组标签,后续作品和优惠券表单就可以直接复用它们。</text>
</view>
<view class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,644 @@
/**
* 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: 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, setTempRecord } = require('../../utils/storage')
/**
* Purpose: CHANGE_SCENE_OPTIONS supports index.js by holding or executing the change scene options 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 CHANGE_SCENE_OPTIONS = ['MANUAL_RECHARGE', 'MANUAL_INCREASE', 'MANUAL_DEDUCT']
/**
* Purpose: VIP_LEVEL_OPTIONS supports index.js by holding or executing the vip level options 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 VIP_LEVEL_OPTIONS = ['普通', '青铜', '白银', '黄金']
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: user supports index.js by holding or executing the user 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.
*/
user: null,
/**
* Purpose: asset supports index.js by holding or executing the asset 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.
*/
asset: null,
/**
* Purpose: balanceHistory supports index.js by holding or executing the balance history 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.
*/
balanceHistory: [],
/**
* Purpose: changeSceneIndex supports index.js by holding or executing the change scene 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.
*/
changeSceneIndex: 0,
/**
* 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: balanceForm supports index.js by holding or executing the balance 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.
*/
balanceForm: {
/**
* Purpose: amount supports index.js by holding or executing the 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.
*/
amount: '',
/**
* Purpose: externalOrderNo supports index.js by holding or executing the external order no 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.
*/
externalOrderNo: '',
/**
* Purpose: remark supports index.js by holding or executing the remark 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.
*/
remark: ''
},
/**
* Purpose: vipRemark supports index.js by holding or executing the vip remark 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.
*/
vipRemark: ''
},
/**
* 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 cached = getTempRecord('currentUser', null)
if (cached && (!options || !options.id || String(cached.id) === String(options.id))) {
this.setUser(cached)
}
},
/**
* Purpose: onShow supports index.js by holding or executing the on show 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.
*/
onShow() {
if (!navigation.ensureLogin('进入用户详情')) {
return
}
this.loadAssetData()
},
/**
* 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('currentUser')
},
async loadAssetData() {
if (!this.data.user) {
return
}
try {
const [asset, balanceHistory] = await Promise.all([
userApi.getUserAsset(this.data.user.id).catch(() => null),
userApi.getUserBalanceHistory(this.data.user.id).catch(() => [])
])
this.setData({
asset,
/**
* Purpose: balanceHistory supports index.js by holding or executing the balance history 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.
*/
balanceHistory: (Array.isArray(balanceHistory) ? balanceHistory : []).map(item => ({
...item,
/**
* Purpose: displayChangeTime supports index.js by holding or executing the display change 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.
*/
displayChangeTime: format.formatDateTime(item.changeTime),
/**
* Purpose: amountBadgeClass supports index.js by holding or executing the amount badge class 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.
*/
amountBadgeClass: Number(item.amount) >= 0 ? 'success-badge' : 'danger-badge'
}))
})
} 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'
})
}
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit 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.
*/
handleEdit() {
setTempRecord('currentUser', this.data.user)
navigation.navigate('/pages/user-form/index', {
/**
* 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: 'edit',
/**
* Purpose: id supports index.js by holding or executing the 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.
*/
id: this.data.user.id
}).catch(() => undefined)
},
/**
* Purpose: handlePermissionAssign supports index.js by holding or executing the handle permission assign 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.
*/
handlePermissionAssign() {
setTempRecord('currentUser', this.data.user)
navigation.navigate('/pages/permission-form/index', {
/**
* 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: 'assign',
/**
* Purpose: userId supports index.js by holding or executing the user 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.
*/
userId: this.data.user.id
}).catch(() => undefined)
},
/**
* Purpose: handleBalanceInput supports index.js by holding or executing the handle balance input 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.
*/
handleBalanceInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`balanceForm.${field}`]: event.detail.value
})
},
/**
* Purpose: handleVipRemarkInput supports index.js by holding or executing the handle vip remark input 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.
*/
handleVipRemarkInput(event) {
this.setData({
/**
* Purpose: vipRemark supports index.js by holding or executing the vip remark 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.
*/
vipRemark: event.detail.value
})
},
/**
* Purpose: handleSceneChange supports index.js by holding or executing the handle scene 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.
*/
handleSceneChange(event) {
this.setData({
/**
* Purpose: changeSceneIndex supports index.js by holding or executing the change scene 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.
*/
changeSceneIndex: Number(event.detail.value)
})
},
/**
* 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) {
this.setData({
/**
* 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: Number(event.detail.value)
})
},
async handleBalanceChange() {
try {
await userApi.changeUserBalance(this.data.user.id, {
/**
* Purpose: amount supports index.js by holding or executing the 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.
*/
amount: Number(this.data.balanceForm.amount),
/**
* Purpose: changeScene supports index.js by holding or executing the change 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.
*/
changeScene: CHANGE_SCENE_OPTIONS[this.data.changeSceneIndex],
/**
* Purpose: externalOrderNo supports index.js by holding or executing the external order no 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.
*/
externalOrderNo: this.data.balanceForm.externalOrderNo || undefined,
/**
* Purpose: remark supports index.js by holding or executing the remark 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.
*/
remark: this.data.balanceForm.remark || undefined
})
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'
})
this.setData({
/**
* Purpose: balanceForm supports index.js by holding or executing the balance 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.
*/
balanceForm: {
/**
* Purpose: amount supports index.js by holding or executing the 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.
*/
amount: '',
/**
* Purpose: externalOrderNo supports index.js by holding or executing the external order no 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.
*/
externalOrderNo: '',
/**
* Purpose: remark supports index.js by holding or executing the remark 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.
*/
remark: ''
}
})
this.loadAssetData()
} 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 handleVipOverride() {
try {
await userApi.overrideUserVip(this.data.user.id, {
/**
* Purpose: vipLevel supports index.js by holding or executing the 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.
*/
vipLevel: VIP_LEVEL_OPTIONS[this.data.vipLevelIndex],
/**
* Purpose: remark supports index.js by holding or executing the remark 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.
*/
remark: this.data.vipRemark || undefined
})
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: 'VIP 等级已更新',
/**
* 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'
})
this.loadAssetData()
} 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 || 'VIP 更新失败',
/**
* 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 handleVipRecalculate() {
try {
await userApi.recalculateUserVip(this.data.user.id)
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'
})
this.loadAssetData()
} 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 || 'VIP 重算失败',
/**
* 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 handleResetPassword() {
try {
await userApi.resetPassword(this.data.user.id)
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'
})
} 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'
})
}
},
/**
* Purpose: handleUserAction supports index.js by holding or executing the handle user action 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.
*/
handleUserAction(event) {
const action = event.currentTarget.dataset.action
if (action === 'disable') {
this.updateUserStatus(this.data.user.status === 0 ? 1 : 0)
return
}
if (action === 'delete') {
this.confirmDelete()
return
}
if (action === 'unbind') {
this.confirmUnbind()
}
},
async updateUserStatus(status) {
try {
await userApi.updateUserStatus(this.data.user.id, status)
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'
})
const user = {
...this.data.user,
status
}
this.setUser(user)
setTempRecord('currentUser', user)
} 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'
})
}
},
/**
* Purpose: confirmDelete supports index.js by holding or executing the confirm delete 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.
*/
confirmDelete() {
wx.showModal({
/**
* 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: content supports index.js by holding or executing the content 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.
*/
content: '删除后该账号将不再出现在前端可见列表中,确认继续吗?',
/**
* Purpose: success supports index.js by holding or executing the success 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.
*/
success: async result => {
if (!result.confirm) {
return
}
try {
await userApi.deleteUser(this.data.user.id)
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'
})
navigation.goBack('/pages/users/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'
})
}
}
})
},
/**
* Purpose: confirmUnbind supports index.js by holding or executing the confirm unbind 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.
*/
confirmUnbind() {
wx.showModal({
/**
* 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: content supports index.js by holding or executing the content 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.
*/
content: '解绑后,该用户将无法登录当前店铺,确认继续吗?',
/**
* Purpose: success supports index.js by holding or executing the success 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.
*/
success: async result => {
if (!result.confirm) {
return
}
try {
await userApi.unbindUser(this.data.user.id)
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'
})
} 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'
})
}
}
})
},
/**
* Purpose: setUser supports index.js by holding or executing the set user 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.
*/
setUser(user) {
this.setData({
/**
* Purpose: user supports index.js by holding or executing the user 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.
*/
user: user ? {
...user,
/**
* Purpose: displayTypeText supports index.js by holding or executing the display type text 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.
*/
displayTypeText: format.getUserTypeText(user.type),
/**
* Purpose: displayShopName supports index.js by holding or executing the display shop 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.
*/
displayShopName: format.buildShopName(user),
/**
* Purpose: displayStatusText supports index.js by holding or executing the display status text 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.
*/
displayStatusText: format.getUserStatusText(user.status),
/**
* Purpose: displayCreateTime supports index.js by holding or executing the display create 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.
*/
displayCreateTime: format.formatDateTime(user.createTime)
} : null
})
}
})

Some files were not shown because too many files have changed in this diff Show More