功能:收口小程序前后台安全与防重复提交
This commit is contained in:
@@ -0,0 +1,328 @@
|
||||
const artistApi = require('../../api/nail-artist')
|
||||
const userApi = require('../../api/user')
|
||||
const tagApi = require('../../api/tag')
|
||||
const productApi = require('../../api/product')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
function normalizeId(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
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))
|
||||
}))
|
||||
}
|
||||
|
||||
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)))
|
||||
}
|
||||
|
||||
function filterProductsByShop(products, shopId) {
|
||||
const targetShopId = normalizeId(shopId)
|
||||
if (!targetShopId) {
|
||||
return []
|
||||
}
|
||||
|
||||
return (Array.isArray(products) ? products : []).filter(item => normalizeId(item.shopId) === targetShopId)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
userId: '',
|
||||
shops: [],
|
||||
shopIndex: 0,
|
||||
shopLabel: '',
|
||||
statusOptions: ['营业中', '休息中'],
|
||||
statusIndex: 0,
|
||||
userForm: {
|
||||
nickname: '',
|
||||
account: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
signature: ''
|
||||
},
|
||||
artistForm: {
|
||||
identity: '',
|
||||
experience: '',
|
||||
rating: '',
|
||||
portfolioText: ''
|
||||
},
|
||||
tags: [],
|
||||
products: []
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentArtist = getTempRecord('currentArtist', null)
|
||||
this.setData({
|
||||
mode,
|
||||
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({
|
||||
artistForm: {
|
||||
identity: currentArtist.identity || '',
|
||||
experience: currentArtist.experience || '',
|
||||
rating: currentArtist.rating || '',
|
||||
portfolioText: ''
|
||||
},
|
||||
userForm: {
|
||||
nickname: currentArtist.nickname || '',
|
||||
account: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
signature: currentArtist.signature || ''
|
||||
},
|
||||
statusIndex: Number(currentArtist.status) === 0 ? 1 : 0
|
||||
})
|
||||
}
|
||||
|
||||
this.loadDependencies()
|
||||
},
|
||||
|
||||
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({
|
||||
userForm: {
|
||||
nickname: userRecord.nickname || '',
|
||||
account: userRecord.account || '',
|
||||
phone: userRecord.phone || '',
|
||||
password: '',
|
||||
signature: userRecord.signature || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.setData({
|
||||
shops: availableShops,
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
|
||||
await this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '初始化美甲师表单失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async loadShopScopedOptions(shopId) {
|
||||
if (!normalizeId(shopId)) {
|
||||
this._selectedTagIds = []
|
||||
this._selectedProductIds = []
|
||||
this.setData({
|
||||
tags: [],
|
||||
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({
|
||||
tags: buildCheckableList(tagList, this._selectedTagIds, 'tagName'),
|
||||
products: buildCheckableList(productList, this._selectedProductIds, 'title')
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
tags: [],
|
||||
products: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '店铺关联数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
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
|
||||
})
|
||||
},
|
||||
|
||||
handleArtistInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`artistForm.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const shopIndex = Number(event.detail.value)
|
||||
const selectedShop = this.data.shops[shopIndex]
|
||||
this.setData({
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
||||
},
|
||||
|
||||
handleStatusChange(event) {
|
||||
this.setData({
|
||||
statusIndex: Number(event.detail.value)
|
||||
})
|
||||
},
|
||||
|
||||
handleTagChange(event) {
|
||||
this._selectedTagIds = event.detail.value || []
|
||||
this.setData({
|
||||
tags: this.data.tags.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedTagIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
handleProductChange(event) {
|
||||
this._selectedProductIds = event.detail.value || []
|
||||
this.setData({
|
||||
products: this.data.products.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedProductIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
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({
|
||||
title: errorMessage,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const selectedShop = this.data.shops[this.data.shopIndex]
|
||||
const userPayload = {
|
||||
nickname: this.data.userForm.nickname,
|
||||
account: this.data.userForm.account,
|
||||
phone: this.data.userForm.phone,
|
||||
signature: this.data.userForm.signature || undefined,
|
||||
type: 3,
|
||||
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({
|
||||
userId: Number(targetUserId),
|
||||
identity: this.data.artistForm.identity || undefined,
|
||||
experience: this.data.artistForm.experience ? Number(this.data.artistForm.experience) : 0,
|
||||
skills: this._selectedTagIds.join(',') || undefined,
|
||||
rating: this.data.artistForm.rating ? Number(this.data.artistForm.rating) : 0,
|
||||
status: this.data.statusIndex === 1 ? 0 : 1,
|
||||
portfolio: this._selectedProductIds.join(',') || undefined,
|
||||
nickname: this.data.userForm.nickname,
|
||||
shopId: selectedShop ? Number(selectedShop.id) : undefined,
|
||||
signature: this.data.userForm.signature || undefined
|
||||
})
|
||||
|
||||
wx.showToast({
|
||||
title: this.data.mode === 'edit' ? '美甲师已更新' : '美甲师已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/artists/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
const artistApi = require('../../api/nail-artist')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
list: [],
|
||||
canCreate: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入美甲师管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('user:create') || permissionCodes.includes('nail_artist:edit')
|
||||
})
|
||||
this.loadArtists()
|
||||
},
|
||||
|
||||
async loadArtists() {
|
||||
try {
|
||||
const list = await artistApi.listNailArtists()
|
||||
this.setData({
|
||||
list: (Array.isArray(list) ? list : []).map(item => ({
|
||||
...item,
|
||||
displayStatusText: Number(item.status) === 0 ? '休息中' : '营业中'
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '美甲师列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentArtist')
|
||||
navigation.navigate('/pages/artist-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const artist = event.currentTarget.dataset.artist
|
||||
setTempRecord('currentArtist', artist)
|
||||
navigation.navigate('/pages/artist-form/index', {
|
||||
mode: 'edit',
|
||||
userId: artist.userId
|
||||
}).catch(() => undefined)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -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": "/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,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,291 @@
|
||||
const couponApi = require('../../api/coupon')
|
||||
const tagApi = require('../../api/tag')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
function normalizeId(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
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))
|
||||
}))
|
||||
}
|
||||
|
||||
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({
|
||||
data: {
|
||||
mode: 'create',
|
||||
couponId: '',
|
||||
shops: [],
|
||||
shopIndex: 0,
|
||||
shopLabel: '',
|
||||
couponTypeOptions: ['折扣券', '满减券'],
|
||||
couponTypeIndex: 0,
|
||||
couponTypeLabel: '折扣券',
|
||||
vipLevelOptions: ['普通', '青铜', '白银', '黄金'],
|
||||
vipLevelIndex: 0,
|
||||
vipLevelLabel: '普通',
|
||||
startDate: '',
|
||||
startTime: '',
|
||||
endDate: '',
|
||||
endTime: '',
|
||||
availableTags: [],
|
||||
unavailableTags: [],
|
||||
form: {
|
||||
couponName: '',
|
||||
couponCode: '',
|
||||
discountValue: '',
|
||||
minAmount: '',
|
||||
reduceAmount: '',
|
||||
totalCount: '',
|
||||
couponScene: '',
|
||||
autoMatch: false
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentCoupon = getTempRecord('currentCoupon', null)
|
||||
this.setData({
|
||||
mode,
|
||||
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({
|
||||
form: {
|
||||
couponName: currentCoupon.couponName || '',
|
||||
couponCode: currentCoupon.couponCode || '',
|
||||
discountValue: currentCoupon.discountValue || '',
|
||||
minAmount: currentCoupon.minAmount || '',
|
||||
reduceAmount: currentCoupon.reduceAmount || '',
|
||||
totalCount: currentCoupon.totalCount || '',
|
||||
couponScene: currentCoupon.couponScene || '',
|
||||
autoMatch: Number(currentCoupon.autoMatch) === 1
|
||||
},
|
||||
couponTypeIndex: Number(currentCoupon.couponType) === 2 ? 1 : 0,
|
||||
couponTypeLabel: Number(currentCoupon.couponType) === 2 ? '满减券' : '折扣券',
|
||||
vipLevelIndex: this.data.vipLevelOptions.findIndex(item => item === (currentCoupon.requiredVipLevel || '普通')),
|
||||
vipLevelLabel: currentCoupon.requiredVipLevel || '普通',
|
||||
startDate: start.date,
|
||||
startTime: start.time,
|
||||
endDate: end.date,
|
||||
endTime: end.time
|
||||
})
|
||||
}
|
||||
|
||||
this.loadDependencies()
|
||||
},
|
||||
|
||||
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,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
|
||||
await this.loadTagOptions(selectedShop ? selectedShop.id : '')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '初始化优惠券表单失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async loadTagOptions(shopId) {
|
||||
if (!normalizeId(shopId)) {
|
||||
this._selectedAvailableTagIds = []
|
||||
this._selectedUnavailableTagIds = []
|
||||
this.setData({
|
||||
availableTags: [],
|
||||
unavailableTags: []
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const tagList = await tagApi.listTagsByShopId(shopId)
|
||||
this._selectedAvailableTagIds = syncSelectedIds(this._selectedAvailableTagIds, tagList)
|
||||
this._selectedUnavailableTagIds = syncSelectedIds(this._selectedUnavailableTagIds, tagList)
|
||||
this.setData({
|
||||
availableTags: buildCheckableList(tagList, this._selectedAvailableTagIds, 'tagName'),
|
||||
unavailableTags: buildCheckableList(tagList, this._selectedUnavailableTagIds, 'tagName')
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
availableTags: [],
|
||||
unavailableTags: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '可用标签加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
const value = event.detail.value
|
||||
this.setData({
|
||||
[`form.${field}`]: value
|
||||
})
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const shopIndex = Number(event.detail.value)
|
||||
const selectedShop = this.data.shops[shopIndex]
|
||||
this.setData({
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
this.loadTagOptions(selectedShop ? selectedShop.id : '')
|
||||
},
|
||||
|
||||
handleCouponTypeChange(event) {
|
||||
const couponTypeIndex = Number(event.detail.value)
|
||||
this.setData({
|
||||
couponTypeIndex,
|
||||
couponTypeLabel: this.data.couponTypeOptions[couponTypeIndex]
|
||||
})
|
||||
},
|
||||
|
||||
handleVipLevelChange(event) {
|
||||
const vipLevelIndex = Number(event.detail.value)
|
||||
this.setData({
|
||||
vipLevelIndex,
|
||||
vipLevelLabel: this.data.vipLevelOptions[vipLevelIndex]
|
||||
})
|
||||
},
|
||||
|
||||
handleDateTimeChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[field]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleAutoMatchChange(event) {
|
||||
this.setData({
|
||||
'form.autoMatch': event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleAvailableTagChange(event) {
|
||||
this._selectedAvailableTagIds = event.detail.value || []
|
||||
this.setData({
|
||||
availableTags: this.data.availableTags.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedAvailableTagIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
handleUnavailableTagChange(event) {
|
||||
this._selectedUnavailableTagIds = event.detail.value || []
|
||||
this.setData({
|
||||
unavailableTags: this.data.unavailableTags.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedUnavailableTagIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
const selectedShop = this.data.shops[this.data.shopIndex]
|
||||
if (!this.data.form.couponName) {
|
||||
wx.showToast({
|
||||
title: '请输入优惠券名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!selectedShop) {
|
||||
wx.showToast({
|
||||
title: '请选择所属店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
couponCode: this.data.form.couponCode || undefined,
|
||||
couponName: this.data.form.couponName,
|
||||
couponType: this.data.couponTypeIndex === 1 ? 2 : 1,
|
||||
discountValue: this.data.couponTypeIndex === 0 ? Number(this.data.form.discountValue || 0) : undefined,
|
||||
minAmount: this.data.couponTypeIndex === 1 ? Number(this.data.form.minAmount || 0) : undefined,
|
||||
reduceAmount: this.data.couponTypeIndex === 1 ? Number(this.data.form.reduceAmount || 0) : undefined,
|
||||
totalCount: this.data.form.totalCount ? Number(this.data.form.totalCount) : undefined,
|
||||
startTime: format.buildDateTime(this.data.startDate, this.data.startTime),
|
||||
endTime: format.buildDateTime(this.data.endDate, this.data.endTime),
|
||||
shopId: selectedShop.id,
|
||||
couponScene: this.data.form.couponScene || undefined,
|
||||
requiredVipLevel: this.data.vipLevelLabel || undefined,
|
||||
autoMatch: this.data.form.autoMatch ? 1 : 0,
|
||||
availableTagIds: this._selectedAvailableTagIds.map(item => Number(item)),
|
||||
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({
|
||||
title: this.data.mode === 'edit' ? '优惠券已更新' : '优惠券已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/coupons/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
const couponApi = require('../../api/coupon')
|
||||
const format = require('../../utils/format')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
list: [],
|
||||
canCreate: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入优惠券管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('coupon:create')
|
||||
})
|
||||
this.loadCoupons()
|
||||
},
|
||||
|
||||
async loadCoupons() {
|
||||
try {
|
||||
const result = await couponApi.listCoupons({
|
||||
page: 1,
|
||||
size: 20
|
||||
})
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayTypeText: format.getCouponTypeText(item.couponType),
|
||||
displayValueText: format.getCouponValueText(item),
|
||||
displayShopName: item.shopName || '当前店铺'
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '优惠券加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentCoupon')
|
||||
navigation.navigate('/pages/coupon-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const coupon = event.currentTarget.dataset.coupon
|
||||
setTempRecord('currentCoupon', coupon)
|
||||
navigation.navigate('/pages/coupon-form/index', {
|
||||
mode: 'edit',
|
||||
id: coupon.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleDistribute(event) {
|
||||
const coupon = event.currentTarget.dataset.coupon
|
||||
setTempRecord('currentCoupon', coupon)
|
||||
navigation.navigate('/pages/coupon-distribute/index', {
|
||||
id: coupon.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleDelete(event) {
|
||||
const coupon = event.currentTarget.dataset.coupon
|
||||
wx.showModal({
|
||||
title: '删除优惠券',
|
||||
content: `确认删除优惠券“${coupon.couponName}”吗?`,
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await couponApi.deleteCoupon(coupon.id)
|
||||
wx.showToast({
|
||||
title: '优惠券已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadCoupons()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '优惠券删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
const authApi = require('../../api/auth')
|
||||
const auth = require('../../utils/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { runWithLoading } = require('../../utils/loading')
|
||||
|
||||
const ACCOUNT_REGEX = /[^A-Za-z0-9]/g
|
||||
|
||||
Page({
|
||||
data: {
|
||||
redirect: '',
|
||||
form: {
|
||||
account: '',
|
||||
password: '',
|
||||
shopId: ''
|
||||
},
|
||||
loginShops: [],
|
||||
loginShopIndex: -1,
|
||||
loginShopDisplayName: '',
|
||||
allowShoplessLogin: false,
|
||||
loginShopMessage: '',
|
||||
accountStatusText: '',
|
||||
accountStatusType: '',
|
||||
loading: false
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this._lookupTicket = 0
|
||||
this.setData({
|
||||
redirect: options && options.redirect ? options.redirect : ''
|
||||
})
|
||||
|
||||
if (auth.isLoggedIn()) {
|
||||
navigation.redirectAfterLogin(this.data.redirect).catch(() => undefined)
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if (this._accountTimer) {
|
||||
clearTimeout(this._accountTimer)
|
||||
}
|
||||
},
|
||||
|
||||
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
|
||||
})
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const shop = this.data.loginShops[index]
|
||||
|
||||
this.setData({
|
||||
loginShopIndex: index,
|
||||
loginShopDisplayName: shop ? shop.shopName || '' : '',
|
||||
'form.shopId': shop ? shop.id : ''
|
||||
})
|
||||
},
|
||||
|
||||
resetAccountState() {
|
||||
if (this._accountTimer) {
|
||||
clearTimeout(this._accountTimer)
|
||||
}
|
||||
|
||||
this._lookupTicket += 1
|
||||
|
||||
this.setData({
|
||||
accountStatusText: '',
|
||||
accountStatusType: '',
|
||||
loginShops: [],
|
||||
loginShopIndex: -1,
|
||||
loginShopDisplayName: '',
|
||||
allowShoplessLogin: false,
|
||||
loginShopMessage: '',
|
||||
'form.shopId': ''
|
||||
})
|
||||
},
|
||||
|
||||
scheduleAccountLookup(account) {
|
||||
if (this._accountTimer) {
|
||||
clearTimeout(this._accountTimer)
|
||||
}
|
||||
|
||||
const ticket = this._lookupTicket + 1
|
||||
this._lookupTicket = ticket
|
||||
this._accountTimer = setTimeout(() => {
|
||||
this.loadLoginShops(account, ticket)
|
||||
}, 420)
|
||||
},
|
||||
|
||||
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({
|
||||
loginShops: shops,
|
||||
allowShoplessLogin,
|
||||
loginShopMessage: (selection && selection.message) || '',
|
||||
loginShopIndex,
|
||||
loginShopDisplayName,
|
||||
'form.shopId': shopId,
|
||||
accountStatusText: shops.length || allowShoplessLogin ? '该账号可用于后台登录' : '当前账号暂时不可用于后台登录',
|
||||
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({
|
||||
loginShops: [],
|
||||
loginShopIndex: -1,
|
||||
loginShopDisplayName: '',
|
||||
allowShoplessLogin: false,
|
||||
loginShopMessage: '',
|
||||
'form.shopId': '',
|
||||
accountStatusText: error.message || '该后台账号不存在或不可登录',
|
||||
accountStatusType: 'error'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
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({
|
||||
title: errorMessage,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const payload = await runWithLoading(() => authApi.login({
|
||||
account: this.data.form.account,
|
||||
password: this.data.form.password,
|
||||
shopId: this.data.form.shopId || undefined
|
||||
}))
|
||||
|
||||
await getApp().setAdminSession(payload)
|
||||
|
||||
wx.showToast({
|
||||
title: '登录成功',
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
await navigation.redirectAfterLogin(this.data.redirect)
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '登录失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<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>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.login-stack {
|
||||
padding-top: 40rpx;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
currentShop: null,
|
||||
modules: []
|
||||
},
|
||||
|
||||
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,
|
||||
modules: permission.getManageModules(userInfo, permissionCodes, currentShop)
|
||||
})
|
||||
},
|
||||
|
||||
handleOpenModule(event) {
|
||||
const module = event.currentTarget.dataset.module
|
||||
if (!module) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!module.allowed) {
|
||||
wx.showToast({
|
||||
title: module.disabledReason || '当前账号没有进入该模块的权限',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
navigation.navigate(module.path).catch(() => undefined)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<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.allowed ? '可进入' : '待解锁'}}</text>
|
||||
</view>
|
||||
<view wx:if="{{!item.allowed}}" class="hint-card">{{item.disabledReason}}</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
order: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const order = getTempRecord('currentOrder', null)
|
||||
this.setData({
|
||||
order: order ? {
|
||||
...order,
|
||||
displayStatusText: format.getOrderStatusText(order),
|
||||
displayCreateTime: format.formatDateTime(order.createTime)
|
||||
} : null
|
||||
})
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentOrder')
|
||||
},
|
||||
|
||||
handleBack() {
|
||||
navigation.goBack('/pages/orders/index')
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<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.payAmount || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">备注</text>
|
||||
<text class="meta-value">{{order.remark || '暂无备注'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="empty-state">
|
||||
<text class="empty-title">订单详情暂不可用</text>
|
||||
<text class="empty-desc">当前详情页优先复用列表页已拉取的数据。如果你是直接打开该页面,请先回到订单列表重新进入。</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
const orderApi = require('../../api/order')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
const format = require('../../utils/format')
|
||||
const { setTempRecord } = require('../../utils/storage')
|
||||
const { consumeDirty, markDirty } = require('../../utils/page-state')
|
||||
|
||||
const STATUS_OPTIONS = [
|
||||
{ label: '全部', value: '' },
|
||||
{ label: '待服务', value: 1 },
|
||||
{ label: '已完成', value: 2 },
|
||||
{ label: '已取消', value: 0 }
|
||||
]
|
||||
|
||||
Page({
|
||||
data: {
|
||||
keyword: '',
|
||||
status: '',
|
||||
statusOptions: STATUS_OPTIONS,
|
||||
list: [],
|
||||
total: 0,
|
||||
loading: false,
|
||||
userInfo: null,
|
||||
initialized: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入订单管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
userInfo: getApp().globalData.userInfo
|
||||
})
|
||||
|
||||
if (!this.data.initialized || consumeDirty('admin-orders')) {
|
||||
this.loadOrders()
|
||||
}
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
this.loadOrders().finally(() => {
|
||||
wx.stopPullDownRefresh()
|
||||
})
|
||||
},
|
||||
|
||||
handleKeywordInput(event) {
|
||||
this.setData({
|
||||
keyword: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
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({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await orderApi.listOrders({
|
||||
page: 1,
|
||||
size: 20,
|
||||
keyword: this.data.keyword || undefined,
|
||||
status: this.data.status === '' ? undefined : this.data.status
|
||||
})
|
||||
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayStatusText: format.getOrderStatusText(item),
|
||||
displayCreateTime: format.formatDateTime(item.createTime)
|
||||
})),
|
||||
total: Number(result && result.total) || 0,
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
wx.showToast({
|
||||
title: error.message || '订单加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleSearch() {
|
||||
this.loadOrders()
|
||||
},
|
||||
|
||||
handleOpenOrder(event) {
|
||||
const order = event.currentTarget.dataset.order
|
||||
if (!order) {
|
||||
return
|
||||
}
|
||||
|
||||
setTempRecord('currentOrder', order)
|
||||
navigation.navigate('/pages/order-detail/index', {
|
||||
id: order.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
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({
|
||||
itemList: options.map(item => item.label),
|
||||
success: async result => {
|
||||
const target = options[result.tapIndex]
|
||||
if (!target) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await orderApi.updateOrderStatus(order.id, target.status)
|
||||
markDirty('admin-workbench')
|
||||
wx.showToast({
|
||||
title: '订单状态已更新',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadOrders()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '订单处理失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
},
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<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.payAmount}}</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 class="list-actions">
|
||||
<view class="mini-btn" data-order="{{item}}" bindtap="handleOpenOrder">查看详情</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>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
const permissionApi = require('../../api/permission')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permissionUtils = require('../../utils/permission')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
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({
|
||||
data: {
|
||||
mode: 'definition-create',
|
||||
title: '',
|
||||
userId: '',
|
||||
currentUser: null,
|
||||
permissionGroups: [],
|
||||
form: {
|
||||
permissionCode: '',
|
||||
permissionName: '',
|
||||
permissionGroup: '',
|
||||
description: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'definition-create'
|
||||
this.setData({
|
||||
mode,
|
||||
userId: options && options.userId ? options.userId : '',
|
||||
title: mode === 'assign' ? '分配权限' : (mode === 'definition-edit' ? '编辑权限' : '新增权限')
|
||||
})
|
||||
|
||||
if (mode === 'assign') {
|
||||
this.loadAssignData()
|
||||
return
|
||||
}
|
||||
|
||||
const currentPermission = getTempRecord('currentPermission', null)
|
||||
if (mode === 'definition-edit' && currentPermission) {
|
||||
this.setData({
|
||||
form: {
|
||||
permissionCode: currentPermission.permissionCode || '',
|
||||
permissionName: currentPermission.permissionName || '',
|
||||
permissionGroup: currentPermission.permissionGroup || '',
|
||||
description: currentPermission.description || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
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({
|
||||
permissionGroups: buildPermissionGroups(allPermissions, checkedIds, normalizedAssignableIds)
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '权限数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handlePermissionCheck(event) {
|
||||
const selected = event.detail.value || []
|
||||
this.setData({
|
||||
permissionGroups: this.data.permissionGroups.map(group => ({
|
||||
...group,
|
||||
items: group.items.map(item => ({
|
||||
...item,
|
||||
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({
|
||||
title: '权限已保存',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/permissions/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '权限保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.data.form.permissionCode || !this.data.form.permissionName) {
|
||||
wx.showToast({
|
||||
title: '请补全权限编码和名称',
|
||||
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({
|
||||
title: '权限定义已保存',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/permissions/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
const permissionApi = require('../../api/permission')
|
||||
const userApi = require('../../api/user')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
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({
|
||||
data: {
|
||||
permissionGroups: [],
|
||||
users: [],
|
||||
canCreate: false,
|
||||
canAssign: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入权限管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('permission:create'),
|
||||
canAssign: permissionCodes.includes('permission:assign')
|
||||
})
|
||||
this.loadPageData()
|
||||
},
|
||||
|
||||
async loadPageData() {
|
||||
try {
|
||||
const [permissions, users] = await Promise.all([
|
||||
permissionApi.listAllPermissions(),
|
||||
userApi.listAllUsers().catch(() => [])
|
||||
])
|
||||
this.setData({
|
||||
permissionGroups: groupPermissions(permissions),
|
||||
users: Array.isArray(users) ? users : []
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '权限数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleCreatePermission() {
|
||||
clearTempRecord('currentPermission')
|
||||
navigation.navigate('/pages/permission-form/index', {
|
||||
mode: 'definition-create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEditPermission(event) {
|
||||
const permission = event.currentTarget.dataset.permission
|
||||
setTempRecord('currentPermission', permission)
|
||||
navigation.navigate('/pages/permission-form/index', {
|
||||
mode: 'definition-edit',
|
||||
id: permission.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleAssignUser(event) {
|
||||
const user = event.currentTarget.dataset.user
|
||||
setTempRecord('currentUser', user)
|
||||
navigation.navigate('/pages/permission-form/index', {
|
||||
mode: 'assign',
|
||||
userId: user.id
|
||||
}).catch(() => undefined)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,349 @@
|
||||
const productApi = require('../../api/product')
|
||||
const tagApi = require('../../api/tag')
|
||||
const userApi = require('../../api/user')
|
||||
const couponApi = require('../../api/coupon')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const cache = require('../../utils/cache')
|
||||
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')
|
||||
|
||||
const DRAFT_KEY = 'admin-product-form'
|
||||
|
||||
function normalizeId(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
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))
|
||||
}))
|
||||
}
|
||||
|
||||
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({
|
||||
data: {
|
||||
mode: 'create',
|
||||
productId: '',
|
||||
shops: [],
|
||||
shopIndex: 0,
|
||||
shopLabel: '',
|
||||
tags: [],
|
||||
artists: [],
|
||||
coupons: [],
|
||||
uploading: false,
|
||||
uploadProgress: 0,
|
||||
form: {
|
||||
title: '',
|
||||
description: '',
|
||||
price: '',
|
||||
approximateDuration: '',
|
||||
likeCount: '',
|
||||
collectCount: '',
|
||||
imageFileIds: [],
|
||||
shopId: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentProduct = getTempRecord('currentProduct', null)
|
||||
const draft = getDraftValue(DRAFT_KEY, null)
|
||||
this.setData({
|
||||
mode,
|
||||
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({
|
||||
form: {
|
||||
title: currentProduct.title || '',
|
||||
description: currentProduct.description || '',
|
||||
price: currentProduct.price || '',
|
||||
approximateDuration: currentProduct.approximateDuration || '',
|
||||
likeCount: currentProduct.likeCount || '',
|
||||
collectCount: currentProduct.collectCount || '',
|
||||
imageFileIds: format.splitCsv(currentProduct.imageFileIds),
|
||||
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({
|
||||
form: {
|
||||
...this.data.form,
|
||||
...(draft.form || {})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
this.loadDependencies()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentProduct')
|
||||
clearDraftTimer(this)
|
||||
},
|
||||
|
||||
scheduleProductDraft() {
|
||||
scheduleDraftSave(this, DRAFT_KEY, () => ({
|
||||
mode: this.data.mode,
|
||||
form: {
|
||||
...this.data.form,
|
||||
imageFileIds: this.data.form.imageFileIds.slice()
|
||||
},
|
||||
selectedTagIds: this._selectedTagIds.slice(),
|
||||
selectedArtistIds: this._selectedArtistIds.slice(),
|
||||
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,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : '',
|
||||
'form.shopId': selectedShop ? selectedShop.id : ''
|
||||
})
|
||||
|
||||
await this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '初始化作品表单失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async loadShopScopedOptions(shopId) {
|
||||
if (!normalizeId(shopId)) {
|
||||
this._selectedTagIds = []
|
||||
this._selectedArtistIds = []
|
||||
this._selectedCouponIds = []
|
||||
this.setData({
|
||||
tags: [],
|
||||
artists: [],
|
||||
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({
|
||||
tags: buildCheckableList(tagList, this._selectedTagIds, 'tagName'),
|
||||
artists: buildCheckableList(artistList, this._selectedArtistIds, 'nickname'),
|
||||
coupons: buildCheckableList(couponList, this._selectedCouponIds, 'couponName')
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
tags: [],
|
||||
artists: [],
|
||||
coupons: []
|
||||
})
|
||||
wx.showToast({
|
||||
title: error.message || '店铺关联数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const shopIndex = Number(event.detail.value)
|
||||
const selectedShop = this.data.shops[shopIndex]
|
||||
this.setData({
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : '',
|
||||
'form.shopId': selectedShop ? selectedShop.id : ''
|
||||
})
|
||||
this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
handleTagChange(event) {
|
||||
this._selectedTagIds = event.detail.value || []
|
||||
this.setData({
|
||||
tags: this.data.tags.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedTagIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
handleArtistChange(event) {
|
||||
this._selectedArtistIds = event.detail.value || []
|
||||
this.setData({
|
||||
artists: this.data.artists.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedArtistIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
handleCouponChange(event) {
|
||||
this._selectedCouponIds = event.detail.value || []
|
||||
this.setData({
|
||||
coupons: this.data.coupons.map(item => ({
|
||||
...item,
|
||||
checked: this._selectedCouponIds.includes(item.valueId)
|
||||
}))
|
||||
})
|
||||
this.scheduleProductDraft()
|
||||
},
|
||||
|
||||
async handleUploadImages() {
|
||||
try {
|
||||
const files = await upload.chooseImageFiles({ count: 9 })
|
||||
this.setData({
|
||||
uploading: true,
|
||||
uploadProgress: 0
|
||||
})
|
||||
const result = await upload.uploadImageFiles({
|
||||
files,
|
||||
scene: 'admin-product-image',
|
||||
onProgress: progress => {
|
||||
this.setData({
|
||||
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({
|
||||
title: error.message || '图片上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
uploading: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
if (!this.data.form.title) {
|
||||
wx.showToast({
|
||||
title: '请输入作品标题',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.data.form.shopId) {
|
||||
wx.showToast({
|
||||
title: '请选择所属店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.data.form.price) {
|
||||
wx.showToast({
|
||||
title: '请输入作品价格',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
shopId: this.data.form.shopId || undefined,
|
||||
title: this.data.form.title,
|
||||
description: this.data.form.description || undefined,
|
||||
imageFileIds: this.data.form.imageFileIds.join(',') || undefined,
|
||||
price: Number(this.data.form.price),
|
||||
tags: this._selectedTagIds.join(',') || undefined,
|
||||
likeCount: this.data.form.likeCount ? Number(this.data.form.likeCount) : undefined,
|
||||
collectCount: this.data.form.collectCount ? Number(this.data.form.collectCount) : undefined,
|
||||
approximateDuration: this.data.form.approximateDuration || undefined,
|
||||
bookableArtists: this._selectedArtistIds.join(',') || undefined,
|
||||
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({
|
||||
title: this.data.mode === 'edit' ? '作品已更新' : '作品已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/products/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<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>
|
||||
<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,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
const productApi = require('../../api/product')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
const { consumeDirty } = require('../../utils/page-state')
|
||||
|
||||
const PAGE_KEY = 'admin-products'
|
||||
|
||||
Page({
|
||||
data: {
|
||||
keyword: '',
|
||||
list: [],
|
||||
loading: false,
|
||||
canCreate: false,
|
||||
initialized: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入作品管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('product:create')
|
||||
})
|
||||
|
||||
if (!this.data.initialized || consumeDirty(PAGE_KEY)) {
|
||||
this.loadProducts()
|
||||
}
|
||||
},
|
||||
|
||||
handleKeywordInput(event) {
|
||||
this.setData({
|
||||
keyword: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleSearch() {
|
||||
this.loadProducts()
|
||||
},
|
||||
|
||||
async loadProducts() {
|
||||
const requestId = (this._loadRequestId || 0) + 1
|
||||
this._loadRequestId = requestId
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await productApi.listProducts({
|
||||
page: 1,
|
||||
size: 20,
|
||||
keyword: this.data.keyword || undefined
|
||||
})
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayPrice: format.formatPrice(item.price),
|
||||
displayShopName: item.shopName || '当前店铺',
|
||||
displayDuration: item.approximateDuration || '未设置时长',
|
||||
displayTagText: Array.isArray(item.tagList) ? item.tagList.join(' / ') : (item.tags || '未设置标签')
|
||||
})),
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
wx.showToast({
|
||||
title: error.message || '作品列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentProduct')
|
||||
navigation.navigate('/pages/product-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const product = event.currentTarget.dataset.product
|
||||
setTempRecord('currentProduct', product)
|
||||
navigation.navigate('/pages/product-form/index', {
|
||||
mode: 'edit',
|
||||
id: product.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleDelete(event) {
|
||||
const product = event.currentTarget.dataset.product
|
||||
wx.showModal({
|
||||
title: '删除作品',
|
||||
content: `确认删除作品“${product.title}”吗?`,
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await productApi.deleteProduct(product.id)
|
||||
wx.showToast({
|
||||
title: '作品已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadProducts()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '作品删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
const authApi = require('../../api/auth')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
currentShop: null,
|
||||
permissionCodes: [],
|
||||
roleLabel: '',
|
||||
shopScopeText: '',
|
||||
currentShopText: ''
|
||||
},
|
||||
|
||||
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,
|
||||
permissionCodes: app.globalData.permissionCodes || [],
|
||||
roleLabel: userInfo ? permission.getRoleLabel(userInfo.type) : '--',
|
||||
shopScopeText,
|
||||
currentShopText: currentShop ? `当前店铺:${currentShop.shopName}` : '当前为无店铺登录'
|
||||
})
|
||||
},
|
||||
|
||||
handleOpenOrders() {
|
||||
navigation.switchTab('/pages/orders/index').catch(() => undefined)
|
||||
},
|
||||
|
||||
handleOpenManage() {
|
||||
navigation.switchTab('/pages/manage/index').catch(() => undefined)
|
||||
},
|
||||
|
||||
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)
|
||||
const items = shops.map(shop => ({
|
||||
label: shop.shopName,
|
||||
value: shop.id
|
||||
}))
|
||||
|
||||
if (allowShoplessLogin && permission.isPlatformAdmin(userInfo)) {
|
||||
items.unshift({
|
||||
label: '无店铺登录',
|
||||
value: ''
|
||||
})
|
||||
}
|
||||
|
||||
if (!items.length) {
|
||||
wx.showToast({
|
||||
title: '当前账号没有可切换的店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
wx.showActionSheet({
|
||||
itemList: items.map(item => item.label),
|
||||
success: async action => {
|
||||
const target = items[action.tapIndex]
|
||||
if (!target) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await getApp().switchAdminShop(target.value || undefined)
|
||||
wx.showToast({
|
||||
title: '店铺已切换',
|
||||
icon: 'none'
|
||||
})
|
||||
this.onShow()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '切换店铺失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '店铺列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleLogout() {
|
||||
try {
|
||||
await authApi.logout().catch(() => undefined)
|
||||
} finally {
|
||||
getApp().clearAdminSession()
|
||||
wx.reLaunch({
|
||||
url: '/pages/login/index'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<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 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>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
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 DRAFT_KEY = 'admin-shop-form'
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
shopId: '',
|
||||
uploading: false,
|
||||
uploadProgress: 0,
|
||||
statusOptions: ['启用', '停用'],
|
||||
statusIndex: 0,
|
||||
form: {
|
||||
shopName: '',
|
||||
description: '',
|
||||
address: '',
|
||||
businessHours: '',
|
||||
coverImageFileId: '',
|
||||
imageFileIds: []
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentShop = getTempRecord('currentShopRecord', null)
|
||||
const draft = getDraftValue(DRAFT_KEY, null)
|
||||
|
||||
this.setData({
|
||||
mode,
|
||||
shopId: options && options.id ? options.id : ''
|
||||
})
|
||||
|
||||
if (mode === 'edit' && currentShop) {
|
||||
this.setData({
|
||||
form: {
|
||||
shopName: currentShop.shopName || '',
|
||||
description: currentShop.description || '',
|
||||
address: currentShop.address || '',
|
||||
businessHours: currentShop.businessHours || '',
|
||||
coverImageFileId: currentShop.coverImageFileId || '',
|
||||
imageFileIds: currentShop.imageFileIds ? String(currentShop.imageFileIds).split(',').filter(Boolean) : []
|
||||
},
|
||||
statusIndex: Number(currentShop.status) === 0 ? 1 : 0
|
||||
})
|
||||
}
|
||||
|
||||
if (draft && draft.mode === mode) {
|
||||
this.setData({
|
||||
form: {
|
||||
...this.data.form,
|
||||
...draft.form
|
||||
},
|
||||
statusIndex: draft.statusIndex === 1 ? 1 : this.data.statusIndex
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentShopRecord')
|
||||
clearDraftTimer(this)
|
||||
},
|
||||
|
||||
scheduleShopDraft() {
|
||||
scheduleDraftSave(this, DRAFT_KEY, () => ({
|
||||
mode: this.data.mode,
|
||||
statusIndex: this.data.statusIndex,
|
||||
form: {
|
||||
...this.data.form,
|
||||
imageFileIds: this.data.form.imageFileIds.slice()
|
||||
}
|
||||
}))
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
this.scheduleShopDraft()
|
||||
},
|
||||
|
||||
handleStatusChange(event) {
|
||||
this.setData({
|
||||
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({
|
||||
count: isBanner ? 1 : 9
|
||||
})
|
||||
this.setData({
|
||||
uploading: true,
|
||||
uploadProgress: 0
|
||||
})
|
||||
const results = await upload.uploadImageFiles({
|
||||
files,
|
||||
scene,
|
||||
onProgress: progress => {
|
||||
this.setData({
|
||||
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({
|
||||
title: error.message || '图片上传失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.setData({
|
||||
uploading: false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
if (!this.data.form.shopName) {
|
||||
wx.showToast({
|
||||
title: '请输入店铺名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
shopName: this.data.form.shopName,
|
||||
description: this.data.form.description || undefined,
|
||||
address: this.data.form.address || undefined,
|
||||
businessHours: this.data.form.businessHours || undefined,
|
||||
coverImageFileId: this.data.form.coverImageFileId || undefined,
|
||||
imageFileIds: this.data.form.imageFileIds.join(',') || undefined,
|
||||
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({
|
||||
title: this.data.mode === 'edit' ? '店铺已更新' : '店铺已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/shops/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
const { consumeDirty } = require('../../utils/page-state')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
keyword: '',
|
||||
list: [],
|
||||
loading: false,
|
||||
canCreate: false,
|
||||
initialized: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入店铺管理')) {
|
||||
return
|
||||
}
|
||||
|
||||
const permissionCodes = getApp().globalData.permissionCodes || []
|
||||
this.setData({
|
||||
canCreate: permissionCodes.includes('shop:create')
|
||||
})
|
||||
|
||||
if (!this.data.initialized || consumeDirty('admin-shops')) {
|
||||
this.loadShops()
|
||||
}
|
||||
},
|
||||
|
||||
handleKeywordInput(event) {
|
||||
this.setData({
|
||||
keyword: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleSearch() {
|
||||
this.loadShops()
|
||||
},
|
||||
|
||||
async loadShops() {
|
||||
const requestId = (this._loadRequestId || 0) + 1
|
||||
this._loadRequestId = requestId
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await shopApi.listShops({
|
||||
page: 1,
|
||||
size: 20,
|
||||
keyword: this.data.keyword || undefined
|
||||
})
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayStatusText: Number(item.status) === 0 ? '已停用' : '启用中'
|
||||
})),
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
wx.showToast({
|
||||
title: error.message || '店铺加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentShopRecord')
|
||||
navigation.navigate('/pages/shop-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const shop = event.currentTarget.dataset.shop
|
||||
setTempRecord('currentShopRecord', shop)
|
||||
navigation.navigate('/pages/shop-form/index', {
|
||||
mode: 'edit',
|
||||
id: shop.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleStatus(event) {
|
||||
const shop = event.currentTarget.dataset.shop
|
||||
const nextStatus = Number(shop.status) === 0 ? 1 : 0
|
||||
shopApi.updateShopStatus(shop.id, nextStatus)
|
||||
.then(() => {
|
||||
wx.showToast({
|
||||
title: '店铺状态已更新',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadShops()
|
||||
})
|
||||
.catch(error => {
|
||||
wx.showToast({
|
||||
title: error.message || '状态更新失败',
|
||||
icon: 'none'
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
handleDelete(event) {
|
||||
const shop = event.currentTarget.dataset.shop
|
||||
wx.showModal({
|
||||
title: '删除店铺',
|
||||
content: `确认删除店铺“${shop.shopName}”吗?该操作会联动清理店铺下资源。`,
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await shopApi.deleteShop(shop.id)
|
||||
wx.showToast({
|
||||
title: '店铺已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadShops()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '店铺删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<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 class="mini-btn danger" data-shop="{{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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
const tagApi = require('../../api/tag')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
tagId: '',
|
||||
shops: [],
|
||||
shopIndex: -1,
|
||||
shopLabel: '',
|
||||
form: {
|
||||
tagName: '',
|
||||
textColor: '#2b2b2b',
|
||||
bgColor: '#f6e5df',
|
||||
borderColor: '#ef9a79'
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentTag = getTempRecord('currentTag', null)
|
||||
this.setData({
|
||||
mode,
|
||||
tagId: options && options.id ? options.id : ''
|
||||
})
|
||||
|
||||
if (mode === 'edit' && currentTag) {
|
||||
this.setData({
|
||||
form: {
|
||||
tagName: currentTag.tagName || '',
|
||||
textColor: currentTag.textColor || '#2b2b2b',
|
||||
bgColor: currentTag.bgColor || '#f6e5df',
|
||||
borderColor: currentTag.borderColor || '#ef9a79'
|
||||
}
|
||||
})
|
||||
this._initialShopId = currentTag.shopId
|
||||
}
|
||||
|
||||
this.loadShops()
|
||||
},
|
||||
|
||||
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,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '初始化标签页面失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`form.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleShopChange(event) {
|
||||
const shopIndex = Number(event.detail.value)
|
||||
const selectedShop = this.data.shops[shopIndex]
|
||||
this.setData({
|
||||
shopIndex,
|
||||
shopLabel: selectedShop ? selectedShop.shopName : ''
|
||||
})
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
const selectedShop = this.data.shops[this.data.shopIndex]
|
||||
if (!this.data.form.tagName) {
|
||||
wx.showToast({
|
||||
title: '请输入标签名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!selectedShop) {
|
||||
wx.showToast({
|
||||
title: '请选择所属店铺',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
...this.data.form,
|
||||
shopId: selectedShop.id
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.data.mode === 'edit') {
|
||||
await tagApi.updateTag(this.data.tagId, payload)
|
||||
} else {
|
||||
await tagApi.createTag(payload)
|
||||
}
|
||||
wx.showToast({
|
||||
title: this.data.mode === 'edit' ? '标签已更新' : '标签已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/tags/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
const tagApi = require('../../api/tag')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
list: []
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入标签管理')) {
|
||||
return
|
||||
}
|
||||
this.loadTags()
|
||||
},
|
||||
|
||||
async loadTags() {
|
||||
try {
|
||||
const list = await tagApi.listAllTags()
|
||||
this.setData({
|
||||
list: (Array.isArray(list) ? list : []).map(item => ({
|
||||
...item,
|
||||
displayShopName: item.shopName || '当前店铺'
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '标签加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentTag')
|
||||
navigation.navigate('/pages/tag-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const tag = event.currentTarget.dataset.tag
|
||||
setTempRecord('currentTag', tag)
|
||||
navigation.navigate('/pages/tag-form/index', {
|
||||
mode: 'edit',
|
||||
id: tag.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleDelete(event) {
|
||||
const tag = event.currentTarget.dataset.tag
|
||||
wx.showModal({
|
||||
title: '删除标签',
|
||||
content: `确认删除标签“${tag.tagName}”吗?`,
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await tagApi.deleteTag(tag.id)
|
||||
wx.showToast({
|
||||
title: '标签已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadTags()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '标签删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -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,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
const userApi = require('../../api/user')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { getTempRecord, clearTempRecord, setTempRecord } = require('../../utils/storage')
|
||||
|
||||
const CHANGE_SCENE_OPTIONS = ['MANUAL_RECHARGE', 'MANUAL_INCREASE', 'MANUAL_DEDUCT']
|
||||
const VIP_LEVEL_OPTIONS = ['普通', '青铜', '白银', '黄金']
|
||||
|
||||
Page({
|
||||
data: {
|
||||
user: null,
|
||||
asset: null,
|
||||
balanceHistory: [],
|
||||
changeSceneIndex: 0,
|
||||
vipLevelIndex: 0,
|
||||
balanceForm: {
|
||||
amount: '',
|
||||
externalOrderNo: '',
|
||||
remark: ''
|
||||
},
|
||||
vipRemark: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const cached = getTempRecord('currentUser', null)
|
||||
if (cached && (!options || !options.id || String(cached.id) === String(options.id))) {
|
||||
this.setUser(cached)
|
||||
}
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入用户详情')) {
|
||||
return
|
||||
}
|
||||
this.loadAssetData()
|
||||
},
|
||||
|
||||
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,
|
||||
balanceHistory: (Array.isArray(balanceHistory) ? balanceHistory : []).map(item => ({
|
||||
...item,
|
||||
displayChangeTime: format.formatDateTime(item.changeTime),
|
||||
amountBadgeClass: Number(item.amount) >= 0 ? 'success-badge' : 'danger-badge'
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '用户资产数据加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleEdit() {
|
||||
setTempRecord('currentUser', this.data.user)
|
||||
navigation.navigate('/pages/user-form/index', {
|
||||
mode: 'edit',
|
||||
id: this.data.user.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handlePermissionAssign() {
|
||||
setTempRecord('currentUser', this.data.user)
|
||||
navigation.navigate('/pages/permission-form/index', {
|
||||
mode: 'assign',
|
||||
userId: this.data.user.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleBalanceInput(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
this.setData({
|
||||
[`balanceForm.${field}`]: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleVipRemarkInput(event) {
|
||||
this.setData({
|
||||
vipRemark: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleSceneChange(event) {
|
||||
this.setData({
|
||||
changeSceneIndex: Number(event.detail.value)
|
||||
})
|
||||
},
|
||||
|
||||
handleVipLevelChange(event) {
|
||||
this.setData({
|
||||
vipLevelIndex: Number(event.detail.value)
|
||||
})
|
||||
},
|
||||
|
||||
async handleBalanceChange() {
|
||||
try {
|
||||
await userApi.changeUserBalance(this.data.user.id, {
|
||||
amount: Number(this.data.balanceForm.amount),
|
||||
changeScene: CHANGE_SCENE_OPTIONS[this.data.changeSceneIndex],
|
||||
externalOrderNo: this.data.balanceForm.externalOrderNo || undefined,
|
||||
remark: this.data.balanceForm.remark || undefined
|
||||
})
|
||||
wx.showToast({
|
||||
title: '余额已调整',
|
||||
icon: 'none'
|
||||
})
|
||||
this.setData({
|
||||
balanceForm: {
|
||||
amount: '',
|
||||
externalOrderNo: '',
|
||||
remark: ''
|
||||
}
|
||||
})
|
||||
this.loadAssetData()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '余额调整失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleVipOverride() {
|
||||
try {
|
||||
await userApi.overrideUserVip(this.data.user.id, {
|
||||
vipLevel: VIP_LEVEL_OPTIONS[this.data.vipLevelIndex],
|
||||
remark: this.data.vipRemark || undefined
|
||||
})
|
||||
wx.showToast({
|
||||
title: 'VIP 等级已更新',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadAssetData()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || 'VIP 更新失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleVipRecalculate() {
|
||||
try {
|
||||
await userApi.recalculateUserVip(this.data.user.id)
|
||||
wx.showToast({
|
||||
title: '已恢复自动判级',
|
||||
icon: 'none'
|
||||
})
|
||||
this.loadAssetData()
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || 'VIP 重算失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
async handleResetPassword() {
|
||||
try {
|
||||
await userApi.resetPassword(this.data.user.id)
|
||||
wx.showToast({
|
||||
title: '密码已重置',
|
||||
icon: 'none'
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '密码重置失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
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({
|
||||
title: '用户状态已更新',
|
||||
icon: 'none'
|
||||
})
|
||||
const user = {
|
||||
...this.data.user,
|
||||
status
|
||||
}
|
||||
this.setUser(user)
|
||||
setTempRecord('currentUser', user)
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '状态更新失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
confirmDelete() {
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
content: '删除后该账号将不再出现在前端可见列表中,确认继续吗?',
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await userApi.deleteUser(this.data.user.id)
|
||||
wx.showToast({
|
||||
title: '用户已删除',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/users/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '删除失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
confirmUnbind() {
|
||||
wx.showModal({
|
||||
title: '确认解绑',
|
||||
content: '解绑后,该用户将无法登录当前店铺,确认继续吗?',
|
||||
success: async result => {
|
||||
if (!result.confirm) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await userApi.unbindUser(this.data.user.id)
|
||||
wx.showToast({
|
||||
title: '已解除当前店铺绑定',
|
||||
icon: 'none'
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '解绑失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
setUser(user) {
|
||||
this.setData({
|
||||
user: user ? {
|
||||
...user,
|
||||
displayTypeText: format.getUserTypeText(user.type),
|
||||
displayShopName: format.buildShopName(user),
|
||||
displayStatusText: format.getUserStatusText(user.status),
|
||||
displayCreateTime: format.formatDateTime(user.createTime)
|
||||
} : null
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<navigation-bar title="用户详情" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
|
||||
|
||||
<view class="page-shell">
|
||||
<view class="page-stack">
|
||||
<view wx:if="{{user}}" class="surface-card">
|
||||
<text class="section-title">{{user.nickname || user.account}}</text>
|
||||
<text class="section-desc">{{user.displayTypeText}} · {{user.displayShopName}} · {{user.displayStatusText}}</text>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">账号</text>
|
||||
<text class="meta-value">{{user.account}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">手机号</text>
|
||||
<text class="meta-value">{{user.phone || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">签名</text>
|
||||
<text class="meta-value">{{user.signature || '暂无签名'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">创建时间</text>
|
||||
<text class="meta-value">{{user.displayCreateTime}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn primary" bindtap="handleEdit">编辑资料</view>
|
||||
<view class="mini-btn" bindtap="handlePermissionAssign">分配权限</view>
|
||||
<view class="mini-btn" bindtap="handleResetPassword">重置密码</view>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn" data-action="disable" bindtap="handleUserAction">{{user.status === 0 ? '恢复启用' : '停用账号'}}</view>
|
||||
<view class="mini-btn" data-action="unbind" bindtap="handleUserAction">解绑当前店铺</view>
|
||||
<view class="mini-btn danger" data-action="delete" bindtap="handleUserAction">删除账号</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{asset}}" class="surface-card">
|
||||
<text class="section-title">余额与 VIP</text>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">当前余额</text>
|
||||
<text class="meta-value">¥{{asset.balance}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">累计充值</text>
|
||||
<text class="meta-value">¥{{asset.totalRechargeAmount}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">VIP 等级</text>
|
||||
<text class="meta-value">{{asset.vipLevel || '普通'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">人工覆盖</text>
|
||||
<text class="meta-value">{{asset.manualOverride ? '是' : '否'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="divider-line"></view>
|
||||
|
||||
<text class="section-title">余额调整</text>
|
||||
<view class="field-group">
|
||||
<text class="field-label">金额(可填负数)</text>
|
||||
<input class="field-input" type="digit" value="{{balanceForm.amount}}" data-field="amount" bindinput="handleBalanceInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">变动场景</text>
|
||||
<picker mode="selector" range="{{['MANUAL_RECHARGE','MANUAL_INCREASE','MANUAL_DEDUCT']}}" value="{{changeSceneIndex}}" bindchange="handleSceneChange">
|
||||
<view class="field-picker">{{['MANUAL_RECHARGE','MANUAL_INCREASE','MANUAL_DEDUCT'][changeSceneIndex]}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">外部单号</text>
|
||||
<input class="field-input" value="{{balanceForm.externalOrderNo}}" data-field="externalOrderNo" bindinput="handleBalanceInput"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">备注</text>
|
||||
<textarea class="field-textarea" value="{{balanceForm.remark}}" data-field="remark" bindinput="handleBalanceInput"></textarea>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" bindtap="handleBalanceChange">提交余额变动</button>
|
||||
</view>
|
||||
|
||||
<view class="divider-line"></view>
|
||||
|
||||
<text class="section-title">VIP 管理</text>
|
||||
<view class="field-group">
|
||||
<text class="field-label">手工等级</text>
|
||||
<picker mode="selector" range="{{['普通','青铜','白银','黄金']}}" value="{{vipLevelIndex}}" bindchange="handleVipLevelChange">
|
||||
<view class="field-picker">{{['普通','青铜','白银','黄金'][vipLevelIndex]}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">备注</text>
|
||||
<textarea class="field-textarea" value="{{vipRemark}}" bindinput="handleVipRemarkInput"></textarea>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="secondary-btn" bindtap="handleVipOverride">手工覆盖 VIP</button>
|
||||
<button class="primary-btn" bindtap="handleVipRecalculate">恢复自动判级</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{balanceHistory.length}}" class="surface-card">
|
||||
<text class="section-title">余额流水</text>
|
||||
<block wx:for="{{balanceHistory}}" wx:key="id">
|
||||
<view class="list-card">
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="list-title">{{item.changeScene || item.type || '余额变动'}}</text>
|
||||
<text class="list-subtitle">{{item.remark || '无备注'}}</text>
|
||||
</view>
|
||||
<text class="{{item.amountBadgeClass}}">{{item.amount}}</text>
|
||||
</view>
|
||||
<view class="meta-grid">
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">变动后余额</text>
|
||||
<text class="meta-value">{{item.afterBalance || item.currentBalance || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">变动时间</text>
|
||||
<text class="meta-value">{{item.displayChangeTime}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
const userApi = require('../../api/user')
|
||||
const shopApi = require('../../api/shop')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const cache = require('../../utils/cache')
|
||||
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')
|
||||
|
||||
const ACCOUNT_REGEX = /[^A-Za-z0-9]/g
|
||||
const PHONE_REGEX = /[^\d]/g
|
||||
const DRAFT_KEY = 'admin-user-form'
|
||||
const TYPE_OPTIONS = [
|
||||
{ label: '普通用户', value: 0 },
|
||||
{ label: '店长', value: 2 },
|
||||
{ label: '美甲师', value: 3 },
|
||||
{ label: '平台管理员', value: 4 }
|
||||
]
|
||||
|
||||
function normalizeId(value) {
|
||||
return value === undefined || value === null ? '' : String(value)
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
mode: 'create',
|
||||
userId: '',
|
||||
typeOptions: TYPE_OPTIONS,
|
||||
currentTypeLabel: TYPE_OPTIONS[0].label,
|
||||
shops: [],
|
||||
selectedShopIds: [],
|
||||
form: {
|
||||
nickname: '',
|
||||
account: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
signature: '',
|
||||
type: 0
|
||||
}
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
const mode = options && options.mode ? options.mode : 'create'
|
||||
const currentUser = getTempRecord('currentUser', null)
|
||||
const draft = getDraftValue(DRAFT_KEY, null)
|
||||
const app = getApp()
|
||||
const operator = app.globalData.userInfo || {}
|
||||
|
||||
let availableTypes = TYPE_OPTIONS
|
||||
if (Number(operator.type) === 2) {
|
||||
availableTypes = TYPE_OPTIONS.filter(item => item.value === 0 || item.value === 3)
|
||||
}
|
||||
|
||||
const baseState = {
|
||||
mode,
|
||||
userId: options && options.id ? options.id : '',
|
||||
typeOptions: availableTypes,
|
||||
currentTypeLabel: availableTypes[0] ? availableTypes[0].label : ''
|
||||
}
|
||||
|
||||
if (mode === 'edit' && currentUser) {
|
||||
baseState.form = {
|
||||
nickname: currentUser.nickname || '',
|
||||
account: currentUser.account || '',
|
||||
phone: currentUser.phone || '',
|
||||
password: '',
|
||||
signature: currentUser.signature || '',
|
||||
type: Number(currentUser.type || 0)
|
||||
}
|
||||
baseState.selectedShopIds = Array.isArray(currentUser.shopIds) ? currentUser.shopIds.map(item => String(item)) : []
|
||||
}
|
||||
|
||||
this.setData(baseState)
|
||||
|
||||
if (draft && draft.mode === mode) {
|
||||
this.setData({
|
||||
form: {
|
||||
...this.data.form,
|
||||
...draft.form,
|
||||
password: ''
|
||||
},
|
||||
selectedShopIds: Array.isArray(draft.selectedShopIds) ? draft.selectedShopIds : this.data.selectedShopIds
|
||||
})
|
||||
}
|
||||
|
||||
this.syncTypeLabel(Number(this.data.form.type || 0))
|
||||
this.loadShops()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
clearTempRecord('currentUser')
|
||||
clearDraftTimer(this)
|
||||
},
|
||||
|
||||
scheduleUserDraft() {
|
||||
scheduleDraftSave(this, DRAFT_KEY, () => ({
|
||||
mode: this.data.mode,
|
||||
form: {
|
||||
nickname: this.data.form.nickname,
|
||||
account: this.data.form.account,
|
||||
phone: this.data.form.phone,
|
||||
signature: this.data.form.signature,
|
||||
type: Number(this.data.form.type)
|
||||
},
|
||||
selectedShopIds: this.data.selectedShopIds.slice()
|
||||
}))
|
||||
},
|
||||
|
||||
async loadShops() {
|
||||
try {
|
||||
const shops = await cache.remember('admin:shops:all', CACHE_TTL.dict, () => shopApi.listAllShops())
|
||||
const app = getApp()
|
||||
const operator = app.globalData.userInfo || {}
|
||||
const currentShop = app.globalData.currentShop
|
||||
|
||||
if (Number(operator.type) !== 4 && currentShop) {
|
||||
this.setData({
|
||||
shops: (Array.isArray(shops) ? shops : []).filter(item => normalizeId(item.id) === normalizeId(currentShop.id)).map(item => ({
|
||||
...item,
|
||||
valueId: normalizeId(item.id),
|
||||
checked: true
|
||||
})),
|
||||
selectedShopIds: [normalizeId(currentShop.id)]
|
||||
})
|
||||
this.scheduleUserDraft()
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
shops: (Array.isArray(shops) ? shops : []).map(item => ({
|
||||
...item,
|
||||
valueId: normalizeId(item.id),
|
||||
checked: this.data.selectedShopIds.includes(normalizeId(item.id))
|
||||
}))
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '店铺列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleInputChange(event) {
|
||||
const field = event.currentTarget.dataset.field
|
||||
let value = event.detail.value
|
||||
|
||||
if (field === 'account') {
|
||||
value = String(value || '').replace(ACCOUNT_REGEX, '')
|
||||
}
|
||||
|
||||
if (field === 'phone') {
|
||||
value = String(value || '').replace(PHONE_REGEX, '').slice(0, 11)
|
||||
}
|
||||
|
||||
this.setData({
|
||||
[`form.${field}`]: value
|
||||
})
|
||||
if (field !== 'password') {
|
||||
this.scheduleUserDraft()
|
||||
}
|
||||
},
|
||||
|
||||
handleTypeChange(event) {
|
||||
const index = Number(event.detail.value)
|
||||
const item = this.data.typeOptions[index]
|
||||
this.setData({
|
||||
'form.type': item ? item.value : 0,
|
||||
currentTypeLabel: item ? item.label : ''
|
||||
})
|
||||
this.scheduleUserDraft()
|
||||
},
|
||||
|
||||
handleShopCheck(event) {
|
||||
const selectedShopIds = event.detail.value || []
|
||||
this.setData({
|
||||
selectedShopIds,
|
||||
shops: this.data.shops.map(item => ({
|
||||
...item,
|
||||
checked: selectedShopIds.includes(String(item.id))
|
||||
}))
|
||||
})
|
||||
this.scheduleUserDraft()
|
||||
},
|
||||
|
||||
validateForm() {
|
||||
const form = this.data.form
|
||||
if (!form.nickname) {
|
||||
return '请输入用户昵称'
|
||||
}
|
||||
if (!form.account) {
|
||||
return '请输入账号'
|
||||
}
|
||||
if (!form.phone || form.phone.length !== 11) {
|
||||
return '请输入 11 位手机号'
|
||||
}
|
||||
if (this.data.mode === 'create' && !form.password) {
|
||||
return '新增用户时必须设置密码'
|
||||
}
|
||||
if (!this.data.selectedShopIds.length) {
|
||||
return '请至少绑定一个店铺'
|
||||
}
|
||||
return ''
|
||||
},
|
||||
|
||||
async handleSubmit() {
|
||||
const errorMessage = this.validateForm()
|
||||
if (errorMessage) {
|
||||
wx.showToast({
|
||||
title: errorMessage,
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const payload = {
|
||||
nickname: this.data.form.nickname,
|
||||
account: this.data.form.account,
|
||||
phone: this.data.form.phone,
|
||||
signature: this.data.form.signature || undefined,
|
||||
type: Number(this.data.form.type),
|
||||
shopIds: this.data.selectedShopIds.map(item => Number(item))
|
||||
}
|
||||
|
||||
if (this.data.form.password) {
|
||||
payload.password = this.data.form.password
|
||||
}
|
||||
|
||||
try {
|
||||
if (this.data.mode === 'edit') {
|
||||
await userApi.updateUser(this.data.userId, payload)
|
||||
} else {
|
||||
await userApi.createUser(payload)
|
||||
}
|
||||
clearDraft(DRAFT_KEY)
|
||||
markDirty('admin-users')
|
||||
wx.showToast({
|
||||
title: this.data.mode === 'edit' ? '用户已更新' : '用户已创建',
|
||||
icon: 'none'
|
||||
})
|
||||
navigation.goBack('/pages/users/index')
|
||||
} catch (error) {
|
||||
wx.showToast({
|
||||
title: error.message || '保存失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
syncTypeLabel(type) {
|
||||
const target = this.data.typeOptions.find(item => Number(item.value) === Number(type))
|
||||
this.setData({
|
||||
currentTypeLabel: target ? target.label : ''
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<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">{{mode === 'edit' ? '更新用户资料' : '创建后台账号'}}</text>
|
||||
<text class="section-desc">账号仅允许字母和数字,手机号保持全局唯一。店长创建美甲师时,这里会直接绑定当前店铺。</text>
|
||||
|
||||
<view class="field-group">
|
||||
<text class="field-label">昵称</text>
|
||||
<input class="field-input" value="{{form.nickname}}" data-field="nickname" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">账号</text>
|
||||
<input class="field-input" value="{{form.account}}" data-field="account" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">手机号</text>
|
||||
<input class="field-input" type="number" value="{{form.phone}}" data-field="phone" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">{{mode === 'edit' ? '密码(留空则不修改)' : '登录密码'}}</text>
|
||||
<input class="field-input" password value="{{form.password}}" data-field="password" bindinput="handleInputChange"></input>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">签名</text>
|
||||
<textarea class="field-textarea" value="{{form.signature}}" data-field="signature" bindinput="handleInputChange"></textarea>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">角色</text>
|
||||
<picker mode="selector" range="{{typeOptions}}" range-key="label" value="0" bindchange="handleTypeChange">
|
||||
<view class="field-picker">{{currentTypeLabel || '请选择角色'}}</view>
|
||||
</picker>
|
||||
</view>
|
||||
<view class="field-group">
|
||||
<text class="field-label">绑定店铺</text>
|
||||
<checkbox-group bindchange="handleShopCheck">
|
||||
<block wx:for="{{shops}}" wx:key="id">
|
||||
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
|
||||
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
|
||||
{{item.shopName}}
|
||||
</label>
|
||||
</block>
|
||||
</checkbox-group>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" bindtap="handleSubmit">保存用户</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,4 @@
|
||||
checkbox {
|
||||
transform: scale(0.75);
|
||||
margin-right: 8rpx;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
const userApi = require('../../api/user')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const format = require('../../utils/format')
|
||||
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
|
||||
const { consumeDirty } = require('../../utils/page-state')
|
||||
|
||||
const TYPE_OPTIONS = [
|
||||
{ label: '全部角色', value: '' },
|
||||
{ label: '普通用户', value: 0 },
|
||||
{ label: '店长', value: 2 },
|
||||
{ label: '美甲师', value: 3 },
|
||||
{ label: '管理员', value: 4 }
|
||||
]
|
||||
|
||||
Page({
|
||||
data: {
|
||||
keyword: '',
|
||||
type: '',
|
||||
typeOptions: TYPE_OPTIONS,
|
||||
list: [],
|
||||
loading: false,
|
||||
initialized: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入用户管理')) {
|
||||
return
|
||||
}
|
||||
if (!this.data.initialized || consumeDirty('admin-users')) {
|
||||
this.loadUsers()
|
||||
}
|
||||
},
|
||||
|
||||
handleKeywordInput(event) {
|
||||
this.setData({
|
||||
keyword: event.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
handleSearch() {
|
||||
this.loadUsers()
|
||||
},
|
||||
|
||||
handleTypeChange(event) {
|
||||
this.setData({
|
||||
type: event.currentTarget.dataset.type
|
||||
})
|
||||
this.loadUsers()
|
||||
},
|
||||
|
||||
async loadUsers() {
|
||||
const requestId = (this._loadRequestId || 0) + 1
|
||||
this._loadRequestId = requestId
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await userApi.listUsers({
|
||||
page: 1,
|
||||
size: 20,
|
||||
keyword: this.data.keyword || undefined,
|
||||
type: this.data.type === '' ? undefined : this.data.type
|
||||
})
|
||||
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({
|
||||
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
|
||||
...item,
|
||||
displayShopName: format.buildShopName(item),
|
||||
displayTypeText: format.getUserTypeText(item.type),
|
||||
displayStatusText: format.getUserStatusText(item.status)
|
||||
})),
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
wx.showToast({
|
||||
title: error.message || '用户列表加载失败',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
loading: false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
handleOpenDetail(event) {
|
||||
const user = event.currentTarget.dataset.user
|
||||
setTempRecord('currentUser', user)
|
||||
navigation.navigate('/pages/user-detail/index', {
|
||||
id: user.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleEdit(event) {
|
||||
const user = event.currentTarget.dataset.user
|
||||
setTempRecord('currentUser', user)
|
||||
navigation.navigate('/pages/user-form/index', {
|
||||
mode: 'edit',
|
||||
id: user.id
|
||||
}).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleCreate() {
|
||||
clearTempRecord('currentUser')
|
||||
navigation.navigate('/pages/user-form/index', {
|
||||
mode: 'create'
|
||||
}).catch(() => undefined)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<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 class="chip-row">
|
||||
<block wx:for="{{typeOptions}}" wx:key="label">
|
||||
<view class="chip-btn {{type === item.value ? 'active' : ''}}" data-type="{{item.value}}" bindtap="handleTypeChange">{{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.nickname || '未命名用户'}} · {{item.account}}</text>
|
||||
<text class="list-subtitle">{{item.displayShopName}}</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.displayTypeText}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">手机号</text>
|
||||
<text class="meta-value">{{item.phone || '--'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">VIP</text>
|
||||
<text class="meta-value">{{item.vipLevel || item.level || '普通'}}</text>
|
||||
</view>
|
||||
<view class="meta-item">
|
||||
<text class="meta-label">创建时间</text>
|
||||
<text class="meta-value">{{item.createTime}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="list-actions">
|
||||
<view class="mini-btn" data-user="{{item}}" bindtap="handleOpenDetail">详情</view>
|
||||
<view class="mini-btn primary" data-user="{{item}}" bindtap="handleEdit">编辑</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 class="fab" bindtap="handleCreate">+</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
const dashboardApi = require('../../api/dashboard')
|
||||
const orderApi = require('../../api/order')
|
||||
const navigation = require('../../utils/navigation')
|
||||
const permission = require('../../utils/permission')
|
||||
const cache = require('../../utils/cache')
|
||||
const { CACHE_TTL } = require('../../utils/config')
|
||||
const { consumeDirty } = require('../../utils/page-state')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
userInfo: null,
|
||||
currentShop: null,
|
||||
permissionCount: 0,
|
||||
shortcutModules: [],
|
||||
stats: null,
|
||||
pendingOrders: 0,
|
||||
shoplessAdmin: false,
|
||||
loading: false,
|
||||
initialized: false
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (!navigation.ensureLogin('进入工作台')) {
|
||||
return
|
||||
}
|
||||
|
||||
this.syncGlobalState()
|
||||
const dirty = consumeDirty('admin-workbench')
|
||||
if (!this.data.initialized || dirty) {
|
||||
this.loadDashboard({
|
||||
force: dirty
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
syncGlobalState() {
|
||||
const app = getApp()
|
||||
const userInfo = app.globalData.userInfo
|
||||
const currentShop = app.globalData.currentShop
|
||||
const permissionCodes = app.globalData.permissionCodes || []
|
||||
const modules = permission.getManageModules(userInfo, permissionCodes, currentShop)
|
||||
|
||||
this.setData({
|
||||
userInfo,
|
||||
currentShop,
|
||||
permissionCount: permissionCodes.length,
|
||||
shortcutModules: modules.filter(item => item.allowed).slice(0, 4),
|
||||
shoplessAdmin: permission.isPlatformAdmin(userInfo) && !currentShop
|
||||
})
|
||||
},
|
||||
|
||||
async loadDashboard(options) {
|
||||
const requestId = (this._loadRequestId || 0) + 1
|
||||
this._loadRequestId = requestId
|
||||
const force = Boolean(options && options.force)
|
||||
const app = getApp()
|
||||
const permissionCodes = app.globalData.permissionCodes || []
|
||||
const currentShopId = this.data.currentShop && this.data.currentShop.id ? String(this.data.currentShop.id) : 'none'
|
||||
const statsCacheKey = `workbench:stats:${currentShopId}`
|
||||
const pendingCacheKey = `workbench:pending:${currentShopId}`
|
||||
|
||||
this.setData({
|
||||
loading: true
|
||||
})
|
||||
|
||||
if (this.data.shoplessAdmin) {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
stats: null,
|
||||
pendingOrders: 0,
|
||||
loading: false,
|
||||
initialized: true
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (permission.hasPermission(permissionCodes, 'dashboard:view')) {
|
||||
try {
|
||||
if (force) {
|
||||
cache.removeCache(statsCacheKey)
|
||||
}
|
||||
const stats = force
|
||||
? await dashboardApi.getStats()
|
||||
: await cache.remember(statsCacheKey, CACHE_TTL.workbench, () => dashboardApi.getStats())
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
stats,
|
||||
pendingOrders: Number(stats && stats.todayOrders) || 0,
|
||||
loading: false,
|
||||
initialized: true
|
||||
})
|
||||
return
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
if (permission.hasPermission(permissionCodes, 'order:view')) {
|
||||
try {
|
||||
if (force) {
|
||||
cache.removeCache(pendingCacheKey)
|
||||
}
|
||||
const result = force
|
||||
? await orderApi.listOrders({
|
||||
page: 1,
|
||||
size: 20,
|
||||
status: 1
|
||||
})
|
||||
: await cache.remember(pendingCacheKey, CACHE_TTL.workbench, () => orderApi.listOrders({
|
||||
page: 1,
|
||||
size: 20,
|
||||
status: 1
|
||||
}))
|
||||
if (requestId !== this._loadRequestId) {
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
stats: null,
|
||||
pendingOrders: Number(result && result.total) || 0,
|
||||
loading: false,
|
||||
initialized: true
|
||||
})
|
||||
} catch (error) {
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
stats: null,
|
||||
pendingOrders: 0,
|
||||
loading: false,
|
||||
initialized: true
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (requestId === this._loadRequestId) {
|
||||
this.setData({
|
||||
stats: null,
|
||||
pendingOrders: 0,
|
||||
loading: false,
|
||||
initialized: true
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
handleOpenModule(event) {
|
||||
const path = event.currentTarget.dataset.path
|
||||
if (!path) {
|
||||
return
|
||||
}
|
||||
|
||||
if (path === '/pages/orders/index') {
|
||||
navigation.switchTab(path)
|
||||
return
|
||||
}
|
||||
|
||||
navigation.navigate(path).catch(() => undefined)
|
||||
},
|
||||
|
||||
handleOpenShops() {
|
||||
navigation.navigate('/pages/shops/index').catch(() => undefined)
|
||||
},
|
||||
|
||||
handleOpenOrders() {
|
||||
navigation.switchTab('/pages/orders/index').catch(() => undefined)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"usingComponents": {
|
||||
"navigation-bar": "/components/navigation-bar/navigation-bar"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<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.nickname || userInfo.account || '后台账号'}}</text>
|
||||
<text class="hero-title">{{currentShop ? currentShop.shopName : '无店铺登录工作台'}}</text>
|
||||
<text class="hero-desc">当前身份:{{userInfo ? userInfo.type === 4 ? '平台管理员' : userInfo.type === 2 ? '店长' : '美甲师' : '--'}}。已同步 {{permissionCount}} 项后台权限。</text>
|
||||
<view class="badge-row">
|
||||
<text class="badge">{{currentShop ? '当前店铺已锁定' : '当前无店铺上下文'}}</text>
|
||||
<text class="soft-badge">{{shoplessAdmin ? '先完成门店初始化' : '移动端工作流已就绪'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{shoplessAdmin}}" class="surface-card">
|
||||
<text class="section-title">先创建第一家店铺</text>
|
||||
<text class="section-desc">当前是无店铺管理员登录状态。为避免误进入强店铺范围页面,首版仅建议先完成店铺初始化,再继续订单、商品和用户管理。</text>
|
||||
<view class="action-row">
|
||||
<button class="primary-btn" bindtap="handleOpenShops">进入店铺管理</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:else class="surface-card">
|
||||
<text class="section-title">今日概览</text>
|
||||
<text class="section-desc">把高频动作和最关键的经营数字集中到一屏,方便在手机上快速判断接下来该处理什么。</text>
|
||||
<view class="stats-grid">
|
||||
<view class="stat-card">
|
||||
<text class="stat-label">待处理订单</text>
|
||||
<text class="stat-value">{{pendingOrders}}</text>
|
||||
<text class="stat-note">优先处理预约确认与履约</text>
|
||||
</view>
|
||||
<view class="stat-card">
|
||||
<text class="stat-label">当前权限</text>
|
||||
<text class="stat-value">{{permissionCount}}</text>
|
||||
<text class="stat-note">前端仅做显隐,服务端仍会兜底校验</text>
|
||||
</view>
|
||||
<view class="stat-card" wx:if="{{stats}}">
|
||||
<text class="stat-label">用户总量</text>
|
||||
<text class="stat-value">{{stats.totalUsers || 0}}</text>
|
||||
<text class="stat-note">按当前角色与店铺范围计算</text>
|
||||
</view>
|
||||
<view class="stat-card" wx:if="{{stats}}">
|
||||
<text class="stat-label">作品总量</text>
|
||||
<text class="stat-value">{{stats.totalProducts || 0}}</text>
|
||||
<text class="stat-note">支持后续直接跳去作品管理</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="action-row">
|
||||
<button class="secondary-btn" bindtap="handleOpenOrders">查看订单</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="surface-card">
|
||||
<text class="section-title">快捷入口</text>
|
||||
<text class="section-desc">只展示当前账号真实可进入的模块,避免手机端一屏堆太多无权限入口。</text>
|
||||
<block wx:for="{{shortcutModules}}" wx:key="key">
|
||||
<view class="list-card" data-path="{{item.path}}" bindtap="handleOpenModule">
|
||||
<view class="list-head">
|
||||
<view>
|
||||
<text class="list-title">{{item.title}}</text>
|
||||
<text class="list-subtitle">{{item.description}}</text>
|
||||
</view>
|
||||
<text class="badge">进入</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
<view wx:if="{{!shortcutModules.length}}" class="empty-state">
|
||||
<text class="empty-title">暂无可用快捷入口</text>
|
||||
<text class="empty-desc">当前账号没有可直接打开的后台模块,请先检查权限或切换店铺。</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-shell {
|
||||
background: transparent;
|
||||
}
|
||||
Reference in New Issue
Block a user