重构项目文件夹目录

This commit is contained in:
2026-06-15 15:53:55 +08:00
parent 8093e07190
commit 7cbe5b3de5
1098 changed files with 34 additions and 4441 deletions
+30
View File
@@ -0,0 +1,30 @@
/**
* Purpose: request sends authenticated admin mini-program calls through the shared request wrapper.
* Usage: keep after-sale endpoints aligned with /admin/after-sale on the backend.
*/
const request = require('../utils/request')
module.exports = {
listAfterSales(params) {
return request({
url: '/after-sale/list',
params
})
},
approveAfterSale(id, data) {
return request({
url: `/after-sale/${id}/approve`,
method: 'PUT',
data: data || {}
})
},
rejectAfterSale(id, data) {
return request({
url: `/after-sale/${id}/reject`,
method: 'PUT',
data: data || {}
})
}
}
@@ -0,0 +1,22 @@
/**
* Purpose: request sends authenticated admin mini-program calls through the shared request wrapper.
* Usage: keep schedule endpoints aligned with /admin/artist-schedule on the backend.
*/
const request = require('../utils/request')
module.exports = {
listSchedules(params) {
return request({
url: '/artist-schedule/list',
params
})
},
saveSchedule(data) {
return request({
url: '/artist-schedule/save',
method: 'POST',
data
})
}
}
+68
View File
@@ -0,0 +1,68 @@
/**
* Purpose: request supports auth.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: login supports auth.js by holding or executing the login page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
login(data) {
return request({
url: '/auth/login',
method: 'POST',
data
})
},
/**
* Purpose: getLoginShops supports auth.js by holding or executing the get login shops page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getLoginShops(account) {
return request({
url: `/auth/login-shops/${encodeURIComponent(account)}`
})
},
/**
* Purpose: switchShop supports auth.js by holding or executing the switch shop page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
switchShop(shopId) {
return request({
url: '/auth/switch-shop',
method: 'POST',
data: {
shopId: shopId || undefined
}
})
},
/**
* Purpose: refreshToken supports auth.js by holding or executing the refresh token page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
refreshToken(refreshToken) {
return request({
url: '/auth/refresh',
method: 'POST',
data: {
refreshToken
}
})
},
/**
* Purpose: logout supports auth.js by holding or executing the logout page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
logout() {
return request({
url: '/auth/logout',
method: 'POST'
})
}
}
+22
View File
@@ -0,0 +1,22 @@
/**
* Purpose: request sends authenticated admin mini-program calls through the shared request wrapper.
* Usage: keep campaign endpoints aligned with /admin/campaign on the backend.
*/
const request = require('../utils/request')
module.exports = {
listCampaigns(params) {
return request({
url: '/campaign/list',
params
})
},
saveCampaign(data) {
return request({
url: '/campaign/save',
method: 'POST',
data
})
}
}
+29
View File
@@ -0,0 +1,29 @@
/**
* Purpose: request supports comment.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listComments supports comment.js by holding or executing the list comments page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listComments(params) {
return request({
url: '/comment/list',
params
})
},
/**
* Purpose: deleteComment supports comment.js by holding or executing the delete comment page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
deleteComment(id) {
return request({
url: `/comment/delete/${id}`,
method: 'DELETE'
})
}
}
+100
View File
@@ -0,0 +1,100 @@
/**
* Purpose: request supports coupon.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listCoupons supports coupon.js by holding or executing the list coupons page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listCoupons(params) {
return request({
url: '/coupon/list',
params
})
},
/**
* Purpose: listAllCoupons supports coupon.js by holding or executing the list all coupons page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listAllCoupons(shopId) {
return request({
url: '/coupon/list/all',
params: shopId ? { shopId } : undefined
})
},
/**
* Purpose: getCouponDetail supports coupon.js by holding or executing the get coupon detail page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getCouponDetail(id) {
return request({
url: `/coupon/detail/${id}`
})
},
/**
* Purpose: createCoupon supports coupon.js by holding or executing the create coupon page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
createCoupon(data) {
return request({
url: '/coupon/create',
method: 'POST',
data
})
},
/**
* Purpose: updateCoupon supports coupon.js by holding or executing the update coupon page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updateCoupon(id, data) {
return request({
url: `/coupon/update/${id}`,
method: 'PUT',
data
})
},
/**
* Purpose: deleteCoupon supports coupon.js by holding or executing the delete coupon page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
deleteCoupon(id) {
return request({
url: `/coupon/delete/${id}`,
method: 'DELETE'
})
},
/**
* Purpose: assignCoupon supports coupon.js by holding or executing the assign coupon page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
assignCoupon(data) {
return request({
url: '/coupon/assign',
method: 'POST',
params: data,
data: {}
})
},
/**
* Purpose: distributeCoupon supports coupon.js by holding or executing the distribute coupon page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
distributeCoupon(data) {
return request({
url: '/coupon/distribute',
method: 'POST',
params: data,
data: {}
})
}
}
+23
View File
@@ -0,0 +1,23 @@
/**
* Purpose: request supports dashboard.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: getStats supports dashboard.js by holding or executing the get stats page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getStats() {
return request({
url: '/dashboard/stats'
})
},
getAnalytics() {
return request({
url: '/dashboard/analytics'
})
}
}
+148
View File
@@ -0,0 +1,148 @@
/**
* Purpose: request supports file.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
/**
* Purpose: actionGuard supports file.js by holding or executing the action guard page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const actionGuard = require('../utils/action-guard')
const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config')
/**
* Purpose: normalizeUploadResponse supports file.js by holding or executing the normalize upload response page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function normalizeUploadResponse(response) {
if (!response) {
throw new Error('上传失败')
}
if (response.statusCode === 401) {
throw new Error('登录已过期,请重新登录')
}
if (response.statusCode >= 400) {
throw new Error('上传失败')
}
let payload = response.data
if (typeof payload === 'string') {
try {
payload = JSON.parse(payload)
} catch (error) {}
}
if (payload && typeof payload === 'object' && Object.prototype.hasOwnProperty.call(payload, 'code')) {
if (payload.code === 200) {
return payload.data
}
throw new Error(payload.message || '上传失败')
}
return payload
}
module.exports = {
/**
* Purpose: initChunkUpload supports file.js by holding or executing the init chunk upload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
initChunkUpload(data) {
return request({
url: '/object-storage-file/upload/init',
method: 'POST',
data
})
},
/**
* Purpose: uploadChunkFile supports file.js by holding or executing the upload chunk file page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploadChunkFile(options) {
const signedHeaders = request.buildSignatureHeaders({
url: '/object-storage-file/upload/chunk',
method: 'POST',
formData: {
uploadId: String(options.uploadId),
chunkIndex: String(options.chunkIndex),
totalChunks: String(options.totalChunks)
}
})
return actionGuard.run(
null,
`POST:/object-storage-file/upload/chunk:${String(options.uploadId)}:${String(options.chunkIndex)}`,
() => new Promise((resolve, reject) => {
const task = wx.uploadFile({
url: `${ADMIN_API_BASE_URL}/object-storage-file/upload/chunk`,
filePath: options.filePath,
name: 'chunk',
timeout: REQUEST_TIMEOUT,
formData: {
uploadId: String(options.uploadId),
chunkIndex: String(options.chunkIndex),
totalChunks: String(options.totalChunks)
},
header: signedHeaders,
success: response => {
try {
resolve(normalizeUploadResponse(response))
} catch (error) {
reject(error)
}
},
fail: error => {
reject(new Error(error.errMsg || '上传分片失败'))
}
})
if (task && typeof task.onProgressUpdate === 'function' && typeof options.onProgress === 'function') {
task.onProgressUpdate(progress => {
options.onProgress(progress)
})
}
}),
{
message: '上传处理中,请勿重复操作'
}
)
},
/**
* Purpose: completeChunkUpload supports file.js by holding or executing the complete chunk upload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
completeChunkUpload(uploadId) {
return request({
url: '/object-storage-file/upload/complete',
method: 'POST',
data: {
uploadId
}
})
},
/**
* Purpose: cancelChunkUpload supports file.js by holding or executing the cancel chunk upload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
cancelChunkUpload(uploadId) {
return request({
url: `/object-storage-file/upload/${uploadId}`,
method: 'DELETE'
})
},
/**
* Purpose: getSignedUrl supports file.js by holding or executing the get signed url page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getSignedUrl(fileId) {
return request({
url: `/object-storage-file/get-signed-url/${fileId}`
})
}
}
+30
View File
@@ -0,0 +1,30 @@
/**
* Purpose: request sends authenticated admin mini-program calls through the shared request wrapper.
* Usage: keep inventory endpoints aligned with /admin/inventory on the backend.
*/
const request = require('../utils/request')
module.exports = {
listItems(params) {
return request({
url: '/inventory/list',
params
})
},
saveItem(data) {
return request({
url: '/inventory/save',
method: 'POST',
data
})
},
adjustStock(id, data) {
return request({
url: `/inventory/${id}/adjust`,
method: 'POST',
data
})
}
}
@@ -0,0 +1,39 @@
/**
* Purpose: request supports nail-artist.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listNailArtists supports nail-artist.js by holding or executing the list nail artists page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listNailArtists() {
return request({
url: '/nail-artist/list'
})
},
/**
* Purpose: getNailArtistInfo supports nail-artist.js by holding or executing the get nail artist info page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getNailArtistInfo(userId) {
return request({
url: `/nail-artist/get/${userId}`
})
},
/**
* Purpose: saveNailArtistInfo supports nail-artist.js by holding or executing the save nail artist info page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
saveNailArtistInfo(data) {
return request({
url: '/nail-artist/save',
method: 'POST',
data
})
}
}
+88
View File
@@ -0,0 +1,88 @@
/**
* Purpose: request supports order.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listOrders supports order.js by holding or executing the list orders page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listOrders(params) {
return request({
url: '/order/list',
params
})
},
/**
* Purpose: getOrderDetail loads an authoritative admin-scoped order detail row.
* Usage: call with the order id when opening the order detail page so direct page entry works.
*/
getOrderDetail(id) {
return request({
url: `/order/detail/${id}`
})
},
/**
* Purpose: listOrderReviews supports order.js by holding or executing the list order reviews page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listOrderReviews(orderId) {
return request({
url: `/order/${orderId}/reviews`
})
},
/**
* Purpose: getArtistChangeOptions supports order.js by holding or executing the get artist change options page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getArtistChangeOptions(orderId, orderItemId) {
return request({
url: `/order/${orderId}/artist-change/options`,
params: {
orderItemId
}
})
},
/**
* Purpose: requestArtistChange supports order.js by holding or executing the request artist change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
requestArtistChange(data) {
return request({
url: '/order/artist-change/request',
method: 'POST',
data
})
},
/**
* Purpose: listMyPendingArtistChangeRequests supports order.js by holding or executing the list my pending artist change requests page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listMyPendingArtistChangeRequests() {
return request({
url: '/order/artist-change/my-pending'
})
},
/**
* Purpose: updateOrderStatus supports order.js by holding or executing the update order status page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updateOrderStatus(id, status) {
return request({
url: `/order/update-status/${id}`,
method: 'PUT',
params: {
status
},
data: {}
})
}
}
+18
View File
@@ -0,0 +1,18 @@
/**
* Purpose: request sends authenticated admin mini-program calls through the shared request wrapper.
* Usage: call manual payment operations only after UI permission checks; backend remains authoritative.
*/
const request = require('../utils/request')
module.exports = {
manualConfirmOrder(orderId, remark) {
return request({
url: `/payment/order/${orderId}/manual-confirm`,
method: 'POST',
params: {
remark
},
data: {}
})
}
}
+96
View File
@@ -0,0 +1,96 @@
/**
* Purpose: request supports permission.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: getCurrentUserPermissions supports permission.js by holding or executing the get current user permissions page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getCurrentUserPermissions() {
return request({
url: '/permission/user/current'
})
},
/**
* Purpose: getUserPermissions supports permission.js by holding or executing the get user permissions page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getUserPermissions(userId) {
return request({
url: `/permission/user/${userId}`
})
},
/**
* Purpose: getAssignablePermissionIds supports permission.js by holding or executing the get assignable permission ids page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getAssignablePermissionIds(userId) {
return request({
url: `/permission/assignable/${userId}`
})
},
/**
* Purpose: listAllPermissions supports permission.js by holding or executing the list all permissions page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listAllPermissions() {
return request({
url: '/permission/list/all'
})
},
/**
* Purpose: createPermission supports permission.js by holding or executing the create permission page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
createPermission(data) {
return request({
url: '/permission/create',
method: 'POST',
data
})
},
/**
* Purpose: updatePermission supports permission.js by holding or executing the update permission page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updatePermission(id, data) {
return request({
url: `/permission/update/${id}`,
method: 'PUT',
data
})
},
/**
* Purpose: deletePermission supports permission.js by holding or executing the delete permission page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
deletePermission(id) {
return request({
url: `/permission/delete/${id}`,
method: 'DELETE'
})
},
/**
* Purpose: assignUserPermissions supports permission.js by holding or executing the assign user permissions page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
assignUserPermissions(userId, permissionIds) {
return request({
url: `/permission/assign/${userId}`,
method: 'POST',
data: {
permissionIds
}
})
}
}
+63
View File
@@ -0,0 +1,63 @@
/**
* Purpose: request supports product.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listProducts supports product.js by holding or executing the list products page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listProducts(params) {
return request({
url: '/product/list',
params
})
},
/**
* Purpose: listAllProducts supports product.js by holding or executing the list all products page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listAllProducts() {
return request({
url: '/product/list/all'
})
},
/**
* Purpose: createProduct supports product.js by holding or executing the create product page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
createProduct(data) {
return request({
url: '/product/create',
method: 'POST',
data
})
},
/**
* Purpose: updateProduct supports product.js by holding or executing the update product page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updateProduct(id, data) {
return request({
url: `/product/update/${id}`,
method: 'PUT',
data
})
},
/**
* Purpose: deleteProduct supports product.js by holding or executing the delete product page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
deleteProduct(id) {
return request({
url: `/product/delete/${id}`,
method: 'DELETE'
})
}
}
@@ -0,0 +1,18 @@
/**
* Purpose: request sends signed admin mini-program requests to the backend audit API.
* Usage: require this module from the audit page and call `listLogs` with filter params.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listLogs loads read-only security audit log rows for authorized administrators.
* Usage: pass account, action, result, time range, page, and size filters, then render the returned page result.
*/
listLogs(params) {
return request({
url: '/security-audit/logs',
params
})
}
}
+87
View File
@@ -0,0 +1,87 @@
/**
* Purpose: request supports shop.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listShops supports shop.js by holding or executing the list shops page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listShops(params) {
return request({
url: '/shops/list',
params
})
},
/**
* Purpose: listAllShops supports shop.js by holding or executing the list all shops page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listAllShops() {
return request({
url: '/shops/list/all'
})
},
/**
* Purpose: getShop supports shop.js by holding or executing the get shop page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getShop(id) {
return request({
url: `/shops/${id}`
})
},
/**
* Purpose: createShop supports shop.js by holding or executing the create shop page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
createShop(data) {
return request({
url: '/shops/create',
method: 'POST',
data
})
},
/**
* Purpose: updateShop supports shop.js by holding or executing the update shop page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updateShop(id, data) {
return request({
url: `/shops/update/${id}`,
method: 'PUT',
data
})
},
/**
* Purpose: updateShopStatus supports shop.js by holding or executing the update shop status page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updateShopStatus(id, status) {
return request({
url: `/shops/status/${id}`,
method: 'PUT',
data: {
status
}
})
},
/**
* Purpose: deleteShop supports shop.js by holding or executing the delete shop page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
deleteShop(id) {
return request({
url: `/shops/delete/${id}`,
method: 'DELETE'
})
}
}
@@ -0,0 +1,51 @@
/**
* Purpose: request sends signed admin mini-program calls to the backend system-message endpoints.
* Usage: keep all system-message API wrappers in this module so pages do not build URLs by hand.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listMessages loads admin-visible system messages including popup and business navigation metadata.
* Usage: call it from the system-message management page during initial load or refresh.
*/
listMessages() {
return request({
url: '/system-message/admin/list'
})
},
/**
* Purpose: createMessage publishes a new system message to the selected target users.
* Usage: pass validated form data with targetType, popupEnabled, and optional business fields.
*/
createMessage(data) {
return request({
url: '/system-message/admin/create',
method: 'POST',
data
})
},
/**
* Purpose: revokeMessage withdraws a previously published message when the operator has delete permission.
* Usage: call it with the message id after an explicit confirmation dialog.
*/
revokeMessage(id) {
return request({
url: `/system-message/admin/${id}/revoke`,
method: 'PUT',
data: {}
})
},
/**
* Purpose: getTargetOptions loads shops and users that the current operator may target.
* Usage: call it before showing the publish form so picker data is permission-scoped.
*/
getTargetOptions() {
return request({
url: '/system-message/admin/target-options'
})
}
}
+72
View File
@@ -0,0 +1,72 @@
/**
* Purpose: request supports tag.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listAllTags supports tag.js by holding or executing the list all tags page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listAllTags() {
return request({
url: '/tag/list/all'
})
},
/**
* Purpose: listTagsByShopId supports tag.js by holding or executing the list tags by shop id page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listTagsByShopId(shopId) {
return request({
url: `/tag/list/by-shop/${shopId}`
})
},
/**
* Purpose: getTagById supports tag.js by holding or executing the get tag by id page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getTagById(id) {
return request({
url: `/tag/get/${id}`
})
},
/**
* Purpose: createTag supports tag.js by holding or executing the create tag page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
createTag(data) {
return request({
url: '/tag/create',
method: 'POST',
data
})
},
/**
* Purpose: updateTag supports tag.js by holding or executing the update tag page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updateTag(id, data) {
return request({
url: `/tag/update/${id}`,
method: 'PUT',
data
})
},
/**
* Purpose: deleteTag supports tag.js by holding or executing the delete tag page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
deleteTag(id) {
return request({
url: `/tag/delete/${id}`,
method: 'DELETE'
})
}
}
+176
View File
@@ -0,0 +1,176 @@
/**
* Purpose: request supports user.js by holding or executing the request page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const request = require('../utils/request')
module.exports = {
/**
* Purpose: listUsers supports user.js by holding or executing the list users page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listUsers(params) {
return request({
url: '/user/list',
params
})
},
/**
* Purpose: listAllUsers supports user.js by holding or executing the list all users page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listAllUsers() {
return request({
url: '/user/list/all'
})
},
/**
* Purpose: listArtists supports user.js by holding or executing the list artists page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
listArtists(shopId) {
return request({
url: '/user/list/artists',
params: shopId ? { shopId } : undefined
})
},
/**
* Purpose: createUser supports user.js by holding or executing the create user page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
createUser(data) {
return request({
url: '/user/create',
method: 'POST',
data
})
},
/**
* Purpose: updateUser supports user.js by holding or executing the update user page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updateUser(id, data) {
return request({
url: `/user/update/${id}`,
method: 'PUT',
data
})
},
/**
* Purpose: updateUserStatus supports user.js by holding or executing the update user status page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
updateUserStatus(id, status) {
return request({
url: `/user/status/${id}`,
method: 'PUT',
data: {
status
}
})
},
/**
* Purpose: deleteUser supports user.js by holding or executing the delete user page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
deleteUser(id) {
return request({
url: `/user/delete/${id}`,
method: 'DELETE'
})
},
/**
* Purpose: unbindUser supports user.js by holding or executing the unbind user page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
unbindUser(id) {
return request({
url: `/user/unbind/${id}`,
method: 'PUT',
data: {}
})
},
/**
* Purpose: resetPassword supports user.js by holding or executing the reset password page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
resetPassword(id) {
return request({
url: `/user/reset-password/${id}`,
method: 'POST'
})
},
/**
* Purpose: getCurrentUserInfo supports user.js by holding or executing the get current user info page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getCurrentUserInfo() {
return request({
url: '/user/info'
})
},
/**
* Purpose: getUserAsset supports user.js by holding or executing the get user asset page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getUserAsset(id) {
return request({
url: `/user/${id}/asset`
})
},
/**
* Purpose: getUserBalanceHistory supports user.js by holding or executing the get user balance history page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
getUserBalanceHistory(id) {
return request({
url: `/user/${id}/balance/history`
})
},
/**
* Purpose: changeUserBalance supports user.js by holding or executing the change user balance page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
changeUserBalance(id, data) {
return request({
url: `/user/${id}/balance/change`,
method: 'POST',
data
})
},
/**
* Purpose: overrideUserVip supports user.js by holding or executing the override user vip page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
overrideUserVip(id, data) {
return request({
url: `/user/${id}/vip/override`,
method: 'POST',
data
})
},
/**
* Purpose: recalculateUserVip supports user.js by holding or executing the recalculate user vip page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
recalculateUserVip(id) {
return request({
url: `/user/${id}/vip/recalculate`,
method: 'POST'
})
}
}
+508
View File
@@ -0,0 +1,508 @@
page {
min-height: 100%;
background:
radial-gradient(circle at top left, rgba(240, 126, 87, 0.18), transparent 30%),
linear-gradient(180deg, #071417 0%, #0d2225 30%, #f5f0e8 30%, #f5f0e8 100%);
color: #132024;
font-size: 28rpx;
}
view,
text,
button,
input,
textarea,
scroll-view,
swiper,
swiper-item,
picker,
label,
image,
checkbox,
checkbox-group {
box-sizing: border-box;
}
image {
display: block;
}
button {
margin: 0;
padding: 0;
line-height: 1;
background: transparent;
}
button::after {
border: 0;
}
.page-shell {
min-height: 100vh;
padding-bottom: calc(env(safe-area-inset-bottom) + 36rpx);
}
.page-stack {
padding: 24rpx;
}
.hero-panel {
padding: 34rpx 30rpx;
border-radius: 36rpx;
background: linear-gradient(140deg, rgba(8, 21, 24, 0.96) 0%, rgba(20, 51, 52, 0.96) 100%);
color: #f6efe7;
box-shadow: 0 26rpx 64rpx rgba(7, 20, 23, 0.28);
}
.hero-kicker {
display: block;
font-size: 22rpx;
font-weight: 700;
letter-spacing: 3rpx;
color: #f7b296;
}
.hero-title {
display: block;
margin-top: 16rpx;
font-size: 48rpx;
line-height: 1.2;
font-weight: 800;
}
.hero-desc {
display: block;
margin-top: 16rpx;
font-size: 24rpx;
line-height: 1.8;
color: rgba(246, 239, 231, 0.78);
}
.surface-card {
margin-top: 24rpx;
padding: 28rpx;
border-radius: 30rpx;
background: rgba(255, 252, 247, 0.96);
border: 1rpx solid rgba(19, 32, 36, 0.08);
box-shadow: 0 18rpx 44rpx rgba(26, 39, 42, 0.08);
}
.section-title {
display: block;
font-size: 34rpx;
font-weight: 800;
color: #132024;
}
.section-desc {
display: block;
margin-top: 10rpx;
font-size: 24rpx;
line-height: 1.7;
color: #60706d;
}
.field-group {
margin-top: 24rpx;
}
.field-label {
display: block;
margin-bottom: 12rpx;
font-size: 24rpx;
font-weight: 700;
color: #294248;
}
.field-input,
.field-picker,
.field-textarea {
width: 100%;
min-height: 92rpx;
padding: 0 24rpx;
border-radius: 24rpx;
background: #eef1ea;
border: 1rpx solid rgba(19, 32, 36, 0.08);
color: #132024;
font-size: 28rpx;
}
.field-picker {
display: flex;
align-items: center;
}
.field-textarea {
min-height: 200rpx;
padding: 24rpx;
}
.placeholder {
color: #9eaaa5;
}
.status-text {
display: block;
margin-top: 10rpx;
font-size: 22rpx;
line-height: 1.6;
}
.status-text.success {
color: #2d8d60;
}
.status-text.error {
color: #be4f3b;
}
.status-text.warning {
color: #a66817;
}
.primary-btn,
.secondary-btn,
.danger-btn {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-height: 88rpx;
padding: 0 28rpx;
border-radius: 999rpx;
font-size: 28rpx;
font-weight: 700;
}
.primary-btn {
background: linear-gradient(135deg, #f8a37c 0%, #f07e57 100%);
color: #fffaf4;
}
.secondary-btn {
background: rgba(8, 21, 24, 0.04);
color: #173036;
border: 1rpx solid rgba(8, 21, 24, 0.1);
}
.danger-btn {
background: rgba(190, 79, 59, 0.12);
color: #b94432;
}
.action-row {
display: flex;
gap: 16rpx;
margin-top: 24rpx;
}
.action-row .primary-btn,
.action-row .secondary-btn,
.action-row .danger-btn {
flex: 1;
}
.badge-row {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
margin-top: 18rpx;
}
.badge,
.soft-badge,
.danger-badge,
.success-badge {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 48rpx;
padding: 0 18rpx;
border-radius: 999rpx;
font-size: 22rpx;
font-weight: 700;
}
.badge {
background: rgba(240, 126, 87, 0.14);
color: #d05f3d;
}
.soft-badge {
background: rgba(8, 21, 24, 0.06);
color: #50625f;
}
.danger-badge {
background: rgba(190, 79, 59, 0.12);
color: #b94432;
}
.success-badge {
background: rgba(45, 141, 96, 0.12);
color: #2d8d60;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16rpx;
margin-top: 22rpx;
}
.stat-card {
padding: 24rpx;
border-radius: 24rpx;
background: rgba(8, 21, 24, 0.04);
}
.stat-label {
display: block;
font-size: 22rpx;
color: #667774;
}
.stat-value {
display: block;
margin-top: 10rpx;
font-size: 34rpx;
font-weight: 800;
color: #132024;
}
.stat-note {
display: block;
margin-top: 8rpx;
font-size: 22rpx;
color: #7b8a87;
}
.list-card {
margin-top: 18rpx;
padding: 24rpx;
border-radius: 26rpx;
background: #ffffff;
border: 1rpx solid rgba(19, 32, 36, 0.08);
}
.list-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16rpx;
}
.list-title {
display: block;
font-size: 30rpx;
line-height: 1.5;
font-weight: 800;
color: #132024;
}
.list-subtitle {
display: block;
margin-top: 8rpx;
font-size: 22rpx;
color: #768582;
}
.meta-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 12rpx 20rpx;
margin-top: 22rpx;
}
.meta-item {
min-width: 0;
}
.meta-label {
display: block;
font-size: 21rpx;
color: #82918e;
}
.meta-value {
display: block;
margin-top: 6rpx;
font-size: 25rpx;
color: #1b3035;
word-break: break-all;
}
.list-actions {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
margin-top: 22rpx;
}
.admin-bottom-nav {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10rpx;
margin-top: 24rpx;
padding: 12rpx;
border-radius: 28rpx;
background: rgba(8, 21, 24, 0.08);
}
.admin-bottom-link {
display: flex;
align-items: center;
justify-content: center;
min-width: 0;
min-height: 68rpx;
border-radius: 999rpx;
color: #50625f;
font-size: 24rpx;
font-weight: 700;
}
.admin-bottom-link.active {
background: rgba(240, 126, 87, 0.18);
color: #c85b39;
}
.mini-btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 132rpx;
min-height: 62rpx;
padding: 0 20rpx;
border-radius: 999rpx;
background: rgba(8, 21, 24, 0.05);
color: #173036;
font-size: 24rpx;
font-weight: 700;
}
.mini-btn.primary {
background: rgba(240, 126, 87, 0.14);
color: #cf5e3c;
}
.mini-btn.danger {
background: rgba(190, 79, 59, 0.12);
color: #b94432;
}
.search-row,
.filter-row {
display: flex;
gap: 14rpx;
margin-top: 18rpx;
}
.search-input {
flex: 1;
}
.chip-row,
.checkbox-grid {
display: flex;
flex-wrap: wrap;
gap: 12rpx;
margin-top: 18rpx;
}
.chip-btn,
.checkbox-chip {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 60rpx;
padding: 0 20rpx;
border-radius: 999rpx;
background: rgba(8, 21, 24, 0.05);
color: #4d625f;
font-size: 24rpx;
font-weight: 700;
}
.chip-btn.active,
.checkbox-chip.active {
background: rgba(240, 126, 87, 0.16);
color: #c85b39;
}
.checkbox-chip.disabled {
opacity: 0.45;
}
.empty-state {
margin-top: 24rpx;
padding: 72rpx 36rpx;
border-radius: 30rpx;
background: rgba(255, 252, 247, 0.8);
text-align: center;
}
.empty-title {
display: block;
font-size: 34rpx;
font-weight: 800;
color: #132024;
}
.empty-desc {
display: block;
margin-top: 14rpx;
font-size: 24rpx;
line-height: 1.8;
color: #758582;
}
.fab {
position: fixed;
right: 28rpx;
bottom: calc(env(safe-area-inset-bottom) + 128rpx);
display: flex;
align-items: center;
justify-content: center;
width: 112rpx;
height: 112rpx;
border-radius: 999rpx;
background: linear-gradient(135deg, #f8a37c 0%, #f07e57 100%);
color: #fffaf4;
box-shadow: 0 22rpx 50rpx rgba(240, 126, 87, 0.3);
font-size: 38rpx;
font-weight: 800;
}
.hint-card {
margin-top: 18rpx;
padding: 20rpx 22rpx;
border-radius: 24rpx;
background: rgba(240, 126, 87, 0.12);
color: #8f4d33;
font-size: 24rpx;
line-height: 1.75;
}
.divider-line {
width: 100%;
height: 2rpx;
margin: 18rpx 0;
background: rgba(19, 32, 36, 0.08);
}
.image-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 14rpx;
margin-top: 18rpx;
}
.image-chip {
padding: 18rpx 14rpx;
border-radius: 24rpx;
background: rgba(8, 21, 24, 0.04);
font-size: 22rpx;
color: #50625f;
line-height: 1.6;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 688 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 979 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 780 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

@@ -0,0 +1,147 @@
Component({
options: {
multipleSlots: true // 在组件定义时的选项中启用多slot支持
},
/**
* 组件的属性列表
*/
properties: {
extClass: {
type: String,
value: ''
},
title: {
type: String,
value: ''
},
background: {
type: String,
value: ''
},
color: {
type: String,
value: ''
},
back: {
type: Boolean,
value: true
},
loading: {
type: Boolean,
value: false
},
homeButton: {
type: Boolean,
value: false,
},
animated: {
// 显示隐藏的时候opacity动画效果
type: Boolean,
value: true
},
show: {
// 显示隐藏导航,隐藏的时候navigation-bar的高度占位还在
type: Boolean,
value: true,
observer: '_showChange'
},
// back为true的时候,返回的页面深度
delta: {
type: Number,
value: 1
},
},
/**
* 组件的初始数据
*/
data: {
/**
* Purpose: displayStyle supports navigation-bar.js by holding or executing the display style page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayStyle: ''
},
/**
* Purpose: lifetimes supports navigation-bar.js by holding or executing the lifetimes page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
lifetimes: {
attached() {
const rect = wx.getMenuButtonBoundingClientRect()
const platform = (wx.getDeviceInfo() || wx.getSystemInfoSync()).platform
const isAndroid = platform === 'android'
const isDevtools = platform === 'devtools'
const { windowWidth, safeArea: { top = 0, bottom = 0 } = {} } = wx.getWindowInfo() || wx.getSystemInfoSync()
this.setData({
/**
* Purpose: ios supports navigation-bar.js by holding or executing the ios page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
ios: !isAndroid,
/**
* Purpose: innerPaddingRight supports navigation-bar.js by holding or executing the inner padding right page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
innerPaddingRight: `padding-right: ${windowWidth - rect.left}px`,
/**
* Purpose: leftWidth supports navigation-bar.js by holding or executing the left width page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
leftWidth: `width: ${windowWidth - rect.left}px`,
/**
* Purpose: safeAreaTop supports navigation-bar.js by holding or executing the safe area top page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
safeAreaTop: isDevtools || isAndroid ? `height: calc(var(--height) + ${top}px); padding-top: ${top}px` : ``
})
},
},
/**
* 组件的方法列表
*/
methods: {
_showChange(show) {
const animated = this.data.animated
let displayStyle = ''
if (animated) {
displayStyle = `opacity: ${show ? '1' : '0'
};transition:opacity 0.5s;`
} else {
displayStyle = `display: ${show ? '' : 'none'}`
}
this.setData({
displayStyle
})
},
back() {
const data = this.data
const pages = getCurrentPages()
if (data.delta && pages.length > data.delta) {
wx.navigateBack({
/**
* Purpose: delta supports navigation-bar.js by holding or executing the delta page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
delta: data.delta
})
return
}
this.triggerEvent('back', { delta: data.delta }, {})
},
home() {
wx.redirectTo({
/**
* Purpose: url supports navigation-bar.js by holding or executing the url page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
url: '/admin/pages/workbench/index',
fail() {
wx.reLaunch({
url: '/admin/pages/workbench/index'
})
}
})
this.triggerEvent('home', {}, {})
}
},
})
@@ -0,0 +1,5 @@
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {}
}
@@ -0,0 +1,64 @@
<view class="weui-navigation-bar {{extClass}}">
<view class="weui-navigation-bar__inner {{ios ? 'ios' : 'android'}}" style="color: {{color}}; background: {{background}}; {{displayStyle}}; {{innerPaddingRight}}; {{safeAreaTop}};">
<!-- 左侧按钮 -->
<view class='weui-navigation-bar__left' style="{{leftWidth}};">
<block wx:if="{{back || homeButton}}">
<!-- 返回上一页 -->
<block wx:if="{{back}}">
<view class="weui-navigation-bar__buttons weui-navigation-bar__buttons_goback">
<view
bindtap="back"
class="weui-navigation-bar__btn_goback_wrapper"
hover-class="weui-active"
hover-stay-time="100"
aria-role="button"
aria-label="返回"
>
<view class="weui-navigation-bar__button weui-navigation-bar__btn_goback"></view>
</view>
</view>
</block>
<!-- 返回首页 -->
<block wx:if="{{homeButton}}">
<view class="weui-navigation-bar__buttons weui-navigation-bar__buttons_home">
<view
bindtap="home"
class="weui-navigation-bar__btn_home_wrapper"
hover-class="weui-active"
aria-role="button"
aria-label="首页"
>
<view class="weui-navigation-bar__button weui-navigation-bar__btn_home"></view>
</view>
</view>
</block>
</block>
<block wx:else>
<slot name="left"></slot>
</block>
</view>
<!-- 标题 -->
<view class='weui-navigation-bar__center'>
<view wx:if="{{loading}}" class="weui-navigation-bar__loading" aria-role="alert">
<view
class="weui-loading"
aria-role="img"
aria-label="加载中"
></view>
</view>
<block wx:if="{{title}}">
<text>{{title}}</text>
</block>
<block wx:else>
<slot name="center"></slot>
</block>
</view>
<!-- 右侧留空 -->
<view class='weui-navigation-bar__right'>
<slot name="right"></slot>
</view>
</view>
</view>
@@ -0,0 +1,99 @@
.weui-navigation-bar {
--weui-FG-0:rgba(0,0,0,.9);
--height: 44px;
--left: 16px;
}
.weui-navigation-bar .android {
--height: 48px;
}
.weui-navigation-bar {
overflow: hidden;
color: var(--weui-FG-0);
flex: none;
position: relative;
z-index: 20;
}
.weui-navigation-bar__inner {
position: relative;
top: 0;
left: 0;
z-index: 1;
height: calc(var(--height) + env(safe-area-inset-top));
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
padding-top: env(safe-area-inset-top);
width: 100%;
box-sizing: border-box;
}
.weui-navigation-bar__left {
position: relative;
padding-left: var(--left);
display: flex;
flex-direction: row;
align-items: flex-start;
height: 100%;
box-sizing: border-box;
}
.weui-navigation-bar__btn_goback_wrapper {
padding: 11px 18px 11px 16px;
margin: -11px -18px -11px -16px;
}
.weui-navigation-bar__btn_goback_wrapper.weui-active {
opacity: 0.5;
}
.weui-navigation-bar__btn_goback {
font-size: 12px;
width: 12px;
height: 24px;
-webkit-mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%;
mask: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='24' viewBox='0 0 12 24'%3E %3Cpath fill-opacity='.9' fill-rule='evenodd' d='M10 19.438L8.955 20.5l-7.666-7.79a1.02 1.02 0 0 1 0-1.42L8.955 3.5 10 4.563 2.682 12 10 19.438z'/%3E%3C/svg%3E") no-repeat 50% 50%;
-webkit-mask-size: cover;
mask-size: cover;
background-color: currentColor;
}
.weui-navigation-bar__center {
font-size: 17px;
text-align: center;
position: relative;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
font-weight: bold;
flex: 1;
height: 100%;
}
.weui-navigation-bar__loading {
margin-right: 4px;
align-items: center;
}
.weui-loading {
font-size: 16px;
width: 16px;
height: 16px;
display: block;
background: transparent url("data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' viewBox='0 0 80 80' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Ctitle%3Eloading%3C/title%3E%3Cdefs%3E%3ClinearGradient x1='94.0869141%25' y1='0%25' x2='94.0869141%25' y2='90.559082%25' id='linearGradient-1'%3E%3Cstop stop-color='%23606060' stop-opacity='0' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3ClinearGradient x1='100%25' y1='8.67370605%25' x2='100%25' y2='90.6286621%25' id='linearGradient-2'%3E%3Cstop stop-color='%23606060' offset='0%25'%3E%3C/stop%3E%3Cstop stop-color='%23606060' stop-opacity='0.3' offset='100%25'%3E%3C/stop%3E%3C/linearGradient%3E%3C/defs%3E%3Cg stroke='none' stroke-width='1' fill='none' fill-rule='evenodd' opacity='0.9'%3E%3Cg%3E%3Cpath d='M40,0 C62.09139,0 80,17.90861 80,40 C80,62.09139 62.09139,80 40,80 L40,73 C58.2253967,73 73,58.2253967 73,40 C73,21.7746033 58.2253967,7 40,7 L40,0 Z' fill='url(%23linearGradient-1)'%3E%3C/path%3E%3Cpath d='M40,0 L40,7 C21.7746033,7 7,21.7746033 7,40 C7,58.2253967 21.7746033,73 40,73 L40,80 C17.90861,80 0,62.09139 0,40 C0,17.90861 17.90861,0 40,0 Z' fill='url(%23linearGradient-2)'%3E%3C/path%3E%3Ccircle id='Oval' fill='%23606060' cx='40.5' cy='3.5' r='3.5'%3E%3C/circle%3E%3C/g%3E%3C/g%3E%3C/svg%3E%0A") no-repeat;
background-size: 100%;
margin-left: 0;
animation: loading linear infinite 1s;
}
@keyframes loading {
from {
transform: rotate(0);
}
to {
transform: rotate(360deg);
}
}
@@ -0,0 +1,166 @@
const afterSaleApi = require('../../api/after-sale')
const navigation = require('../../utils/navigation')
const permission = require('../../utils/permission')
const format = require('../../utils/format')
const { markDirty } = require('../../utils/page-state')
const STATUS_OPTIONS = [
{ label: '全部', value: '' },
{ label: '待处理', value: 'PENDING' },
{ label: '已同意', value: 'APPROVED' },
{ label: '已驳回', value: 'REJECTED' }
]
function safeList(response) {
if (Array.isArray(response && response.list)) {
return response.list
}
if (Array.isArray(response && response.records)) {
return response.records
}
return []
}
function statusText(status) {
if (status === 'PENDING') {
return '待处理'
}
if (status === 'APPROVED') {
return '已同意'
}
if (status === 'REJECTED') {
return '已驳回'
}
return status || '--'
}
Page({
data: {
loading: false,
list: [],
total: 0,
status: 'PENDING',
statusOptions: STATUS_OPTIONS,
canAudit: false
},
onShow() {
if (!navigation.ensureLogin('进入售后处理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
canAudit: permission.hasPermission(permissionCodes, 'after_sale:audit')
})
this.loadAfterSales()
},
onPullDownRefresh() {
this.loadAfterSales().finally(() => {
wx.stopPullDownRefresh()
})
},
async loadAfterSales() {
this.setData({ loading: true })
try {
const response = await afterSaleApi.listAfterSales({
page: 1,
size: 20,
status: this.data.status || undefined
})
this.setData({
list: safeList(response).map(item => this.formatAfterSale(item)),
total: Number(response && response.total) || 0
})
} catch (error) {
wx.showToast({
title: error.message || '售后加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
formatAfterSale(item) {
return {
...item,
displayCreateTime: format.formatDateTime(item.createTime),
displayAuditTime: format.formatDateTime(item.auditTime),
displayRefundAmount: format.formatPrice(item.refundAmount),
statusText: statusText(item.status)
}
},
handleStatusChange(event) {
this.setData({
status: event.currentTarget.dataset.status || ''
})
this.loadAfterSales()
},
promptReason(title) {
return new Promise(resolve => {
wx.showModal({
title,
content: '可填写处理说明,留空也可以提交。',
editable: true,
placeholderText: '处理说明',
confirmText: '提交',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
},
async handleAudit(event) {
if (!this.data.canAudit) {
wx.showToast({
title: '当前账号没有处理售后权限',
icon: 'none'
})
return
}
const id = event.currentTarget.dataset.id
const action = event.currentTarget.dataset.action
if (!id || !action) {
return
}
const reason = await this.promptReason(action === 'approve' ? '同意售后' : '驳回售后')
if (reason === null) {
return
}
try {
const data = {
auditReason: reason
}
if (action === 'approve') {
await afterSaleApi.approveAfterSale(id, data)
} else {
await afterSaleApi.rejectAfterSale(id, data)
}
markDirty('admin-workbench')
wx.showToast({
title: '售后已处理',
icon: 'none'
})
this.loadAfterSales()
} catch (error) {
wx.showToast({
title: error.message || '售后处理失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,62 @@
<navigation-bar title="售后处理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">After Sale</text>
<text class="hero-title">售后处理</text>
<text class="hero-desc">查看待处理退款/售后申请,在手机端完成同意或驳回的最小闭环。</text>
</view>
<view class="surface-card">
<text class="section-title">状态筛选</text>
<view class="chip-row">
<block wx:for="{{statusOptions}}" wx:key="value">
<view class="chip-btn {{status === item.value ? 'active' : ''}}" data-status="{{item.value}}" bindtap="handleStatusChange">{{item.label}}</view>
</block>
</view>
<text class="section-desc">共 {{total}} 条记录</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.afterSaleNo || ('售后 #' + item.id)}}</text>
<text class="list-subtitle">订单 {{item.orderId || '--'}} · {{item.displayCreateTime || '--'}}</text>
</view>
<text class="{{item.status === 'PENDING' ? 'badge' : 'soft-badge'}}">{{item.statusText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">类型</text>
<text class="meta-value">{{item.type || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">退款金额</text>
<text class="meta-value">¥{{item.displayRefundAmount}}</text>
</view>
<view class="meta-item">
<text class="meta-label">用户 ID</text>
<text class="meta-value">{{item.userId || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">审核时间</text>
<text class="meta-value">{{item.displayAuditTime || '--'}}</text>
</view>
</view>
<view wx:if="{{item.reason}}" class="hint-card">{{item.reason}}</view>
<view wx:if="{{item.auditReason}}" class="hint-card">处理说明:{{item.auditReason}}</view>
<view wx:if="{{item.status === 'PENDING'}}" class="list-actions">
<view class="mini-btn primary" data-id="{{item.id}}" data-action="approve" bindtap="handleAudit">同意</view>
<view class="mini-btn danger" data-id="{{item.id}}" data-action="reject" bindtap="handleAudit">驳回</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无售后单</text>
<text class="empty-desc">当前状态下没有需要展示的售后记录。</text>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,728 @@
/**
* Purpose: artistApi supports index.js by holding or executing the artist api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const artistApi = require('../../api/nail-artist')
/**
* Purpose: userApi supports index.js by holding or executing the user api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userApi = require('../../api/user')
/**
* Purpose: tagApi supports index.js by holding or executing the tag api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const tagApi = require('../../api/tag')
/**
* Purpose: productApi supports index.js by holding or executing the product api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const productApi = require('../../api/product')
/**
* Purpose: shopApi supports index.js by holding or executing the shop api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopApi = require('../../api/shop')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: format supports index.js by holding or executing the format page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const format = require('../../utils/format')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
/**
* Purpose: normalizeId supports index.js by holding or executing the normalize id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
}
/**
* Purpose: buildCheckableList supports index.js by holding or executing the build checkable list page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildCheckableList(list, selectedIds, labelKey) {
return (Array.isArray(list) ? list : []).map(item => ({
...item,
valueId: normalizeId(item.id),
labelText: item[labelKey],
checked: selectedIds.includes(normalizeId(item.id))
}))
}
/**
* Purpose: syncSelectedIds supports index.js by holding or executing the sync selected ids page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function syncSelectedIds(selectedIds, list) {
const availableIds = new Set((Array.isArray(list) ? list : []).map(item => normalizeId(item.id)))
return (Array.isArray(selectedIds) ? selectedIds : []).filter(id => availableIds.has(normalizeId(id)))
}
/**
* Purpose: filterProductsByShop supports index.js by holding or executing the filter products by shop page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function filterProductsByShop(products, shopId) {
const targetShopId = normalizeId(shopId)
if (!targetShopId) {
return []
}
return (Array.isArray(products) ? products : []).filter(item => normalizeId(item.shopId) === targetShopId)
}
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'create',
/**
* Purpose: userId supports index.js by holding or executing the user id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userId: '',
/**
* Purpose: shops supports index.js by holding or executing the shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shops: [],
/**
* Purpose: shopIndex supports index.js by holding or executing the shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopIndex: 0,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: '',
/**
* Purpose: statusOptions supports index.js by holding or executing the status options page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusOptions: ['营业中', '休息中'],
/**
* Purpose: statusIndex supports index.js by holding or executing the status index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusIndex: 0,
/**
* Purpose: userForm supports index.js by holding or executing the user form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userForm: {
/**
* Purpose: nickname supports index.js by holding or executing the nickname page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
nickname: '',
/**
* Purpose: account supports index.js by holding or executing the account page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
account: '',
/**
* Purpose: phone supports index.js by holding or executing the phone page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
phone: '',
/**
* Purpose: password supports index.js by holding or executing the password page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
password: '',
/**
* Purpose: signature supports index.js by holding or executing the signature page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
signature: ''
},
/**
* Purpose: artistForm supports index.js by holding or executing the artist form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
artistForm: {
/**
* Purpose: identity supports index.js by holding or executing the identity page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
identity: '',
/**
* Purpose: experience supports index.js by holding or executing the experience page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
experience: '',
/**
* Purpose: rating supports index.js by holding or executing the rating page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
rating: '',
/**
* Purpose: portfolioText supports index.js by holding or executing the portfolio text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
portfolioText: ''
},
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: [],
/**
* Purpose: products supports index.js by holding or executing the products page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
products: []
},
/**
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLoad(options) {
const mode = options && options.mode ? options.mode : 'create'
const currentArtist = getTempRecord('currentArtist', null)
this.setData({
mode,
/**
* Purpose: userId supports index.js by holding or executing the user id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userId: options && options.userId ? options.userId : ''
})
this._selectedTagIds = []
this._selectedProductIds = []
this._allProducts = []
if (mode === 'edit' && currentArtist) {
this._selectedTagIds = format.splitCsv(currentArtist.skills)
this._selectedProductIds = format.splitCsv(currentArtist.portfolio)
this._initialShopId = currentArtist.shopId
this.setData({
/**
* Purpose: artistForm supports index.js by holding or executing the artist form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
artistForm: {
/**
* Purpose: identity supports index.js by holding or executing the identity page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
identity: currentArtist.identity || '',
/**
* Purpose: experience supports index.js by holding or executing the experience page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
experience: currentArtist.experience || '',
/**
* Purpose: rating supports index.js by holding or executing the rating page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
rating: currentArtist.rating || '',
/**
* Purpose: portfolioText supports index.js by holding or executing the portfolio text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
portfolioText: ''
},
/**
* Purpose: userForm supports index.js by holding or executing the user form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userForm: {
/**
* Purpose: nickname supports index.js by holding or executing the nickname page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
nickname: currentArtist.nickname || '',
/**
* Purpose: account supports index.js by holding or executing the account page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
account: '',
/**
* Purpose: phone supports index.js by holding or executing the phone page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
phone: '',
/**
* Purpose: password supports index.js by holding or executing the password page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
password: '',
/**
* Purpose: signature supports index.js by holding or executing the signature page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
signature: currentArtist.signature || ''
},
/**
* Purpose: statusIndex supports index.js by holding or executing the status index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusIndex: Number(currentArtist.status) === 0 ? 1 : 0
})
}
this.loadDependencies()
},
/**
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onUnload() {
clearTempRecord('currentArtist')
},
async loadDependencies() {
const app = getApp()
const currentShop = app.globalData.currentShop
const operator = app.globalData.userInfo || {}
try {
const [shops, products, users] = await Promise.all([
shopApi.listAllShops(),
productApi.listAllProducts(),
userApi.listAllUsers()
])
let availableShops = Array.isArray(shops) ? shops : []
if (Number(operator.type) !== 4 && currentShop) {
availableShops = availableShops.filter(item => normalizeId(item.id) === normalizeId(currentShop.id))
}
let shopIndex = 0
if (this._initialShopId) {
const index = availableShops.findIndex(item => normalizeId(item.id) === normalizeId(this._initialShopId))
if (index >= 0) {
shopIndex = index
}
}
const selectedShop = availableShops[shopIndex]
this._allProducts = Array.isArray(products) ? products : []
if (this.data.mode === 'edit') {
const userRecord = (Array.isArray(users) ? users : []).find(item => normalizeId(item.id) === normalizeId(this.data.userId))
if (userRecord) {
this.setData({
/**
* Purpose: userForm supports index.js by holding or executing the user form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userForm: {
/**
* Purpose: nickname supports index.js by holding or executing the nickname page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
nickname: userRecord.nickname || '',
/**
* Purpose: account supports index.js by holding or executing the account page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
account: userRecord.account || '',
/**
* Purpose: phone supports index.js by holding or executing the phone page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
phone: userRecord.phone || '',
/**
* Purpose: password supports index.js by holding or executing the password page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
password: '',
/**
* Purpose: signature supports index.js by holding or executing the signature page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
signature: userRecord.signature || ''
}
})
}
}
this.setData({
/**
* Purpose: shops supports index.js by holding or executing the shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shops: availableShops,
shopIndex,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: selectedShop ? selectedShop.shopName : ''
})
await this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '初始化美甲师表单失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
async loadShopScopedOptions(shopId) {
if (!normalizeId(shopId)) {
this._selectedTagIds = []
this._selectedProductIds = []
this.setData({
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: [],
/**
* Purpose: products supports index.js by holding or executing the products page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
products: []
})
return
}
try {
const tagList = await tagApi.listTagsByShopId(shopId)
const productList = filterProductsByShop(this._allProducts, shopId)
this._selectedTagIds = syncSelectedIds(this._selectedTagIds, tagList)
this._selectedProductIds = syncSelectedIds(this._selectedProductIds, productList)
this.setData({
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: buildCheckableList(tagList, this._selectedTagIds, 'tagName'),
/**
* Purpose: products supports index.js by holding or executing the products page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
products: buildCheckableList(productList, this._selectedProductIds, 'title')
})
} catch (error) {
this.setData({
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: [],
/**
* Purpose: products supports index.js by holding or executing the products page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
products: []
})
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '店铺关联数据加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
/**
* Purpose: handleUserInput supports index.js by holding or executing the handle user input page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleUserInput(event) {
const field = event.currentTarget.dataset.field
let value = event.detail.value
if (field === 'account') {
value = String(value || '').replace(/[^A-Za-z0-9]/g, '')
}
if (field === 'phone') {
value = String(value || '').replace(/[^\d]/g, '').slice(0, 11)
}
this.setData({
[`userForm.${field}`]: value
})
},
/**
* Purpose: handleArtistInput supports index.js by holding or executing the handle artist input page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleArtistInput(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`artistForm.${field}`]: event.detail.value
})
},
/**
* Purpose: handleShopChange supports index.js by holding or executing the handle shop change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleShopChange(event) {
const shopIndex = Number(event.detail.value)
const selectedShop = this.data.shops[shopIndex]
this.setData({
shopIndex,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: selectedShop ? selectedShop.shopName : ''
})
this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
},
/**
* Purpose: handleStatusChange supports index.js by holding or executing the handle status change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleStatusChange(event) {
this.setData({
/**
* Purpose: statusIndex supports index.js by holding or executing the status index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusIndex: Number(event.detail.value)
})
},
/**
* Purpose: handleTagChange supports index.js by holding or executing the handle tag change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleTagChange(event) {
this._selectedTagIds = event.detail.value || []
this.setData({
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: this.data.tags.map(item => ({
...item,
/**
* Purpose: checked supports index.js by holding or executing the checked page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
checked: this._selectedTagIds.includes(item.valueId)
}))
})
},
/**
* Purpose: handleProductChange supports index.js by holding or executing the handle product change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleProductChange(event) {
this._selectedProductIds = event.detail.value || []
this.setData({
/**
* Purpose: products supports index.js by holding or executing the products page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
products: this.data.products.map(item => ({
...item,
/**
* Purpose: checked supports index.js by holding or executing the checked page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
checked: this._selectedProductIds.includes(item.valueId)
}))
})
},
/**
* Purpose: validateForm supports index.js by holding or executing the validate form page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
validateForm() {
if (!this.data.userForm.nickname) {
return '请输入美甲师昵称'
}
if (!this.data.userForm.account) {
return '请输入账号'
}
if (!this.data.userForm.phone || this.data.userForm.phone.length !== 11) {
return '请输入 11 位手机号'
}
if (this.data.mode === 'create' && !this.data.userForm.password) {
return '新增美甲师时必须设置密码'
}
if (!this.data.shops[this.data.shopIndex]) {
return '请选择所属店铺'
}
return ''
},
async handleSubmit() {
const errorMessage = this.validateForm()
if (errorMessage) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: errorMessage,
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
const selectedShop = this.data.shops[this.data.shopIndex]
const userPayload = {
/**
* Purpose: nickname supports index.js by holding or executing the nickname page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
nickname: this.data.userForm.nickname,
/**
* Purpose: account supports index.js by holding or executing the account page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
account: this.data.userForm.account,
/**
* Purpose: phone supports index.js by holding or executing the phone page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
phone: this.data.userForm.phone,
/**
* Purpose: signature supports index.js by holding or executing the signature page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
signature: this.data.userForm.signature || undefined,
/**
* Purpose: type supports index.js by holding or executing the type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
type: 3,
/**
* Purpose: shopIds supports index.js by holding or executing the shop ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopIds: selectedShop ? [Number(selectedShop.id)] : []
}
if (this.data.userForm.password) {
userPayload.password = this.data.userForm.password
}
try {
let targetUserId = this.data.userId
if (this.data.mode === 'edit') {
await userApi.updateUser(targetUserId, userPayload)
} else {
targetUserId = await userApi.createUser(userPayload)
}
await artistApi.saveNailArtistInfo({
/**
* Purpose: userId supports index.js by holding or executing the user id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userId: Number(targetUserId),
/**
* Purpose: identity supports index.js by holding or executing the identity page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
identity: this.data.artistForm.identity || undefined,
/**
* Purpose: experience supports index.js by holding or executing the experience page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
experience: this.data.artistForm.experience ? Number(this.data.artistForm.experience) : 0,
/**
* Purpose: skills supports index.js by holding or executing the skills page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
skills: this._selectedTagIds.join(',') || undefined,
/**
* Purpose: rating supports index.js by holding or executing the rating page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
rating: this.data.artistForm.rating ? Number(this.data.artistForm.rating) : 0,
/**
* Purpose: status supports index.js by holding or executing the status page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
status: this.data.statusIndex === 1 ? 0 : 1,
/**
* Purpose: portfolio supports index.js by holding or executing the portfolio page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
portfolio: this._selectedProductIds.join(',') || undefined,
/**
* Purpose: nickname supports index.js by holding or executing the nickname page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
nickname: this.data.userForm.nickname,
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: selectedShop ? Number(selectedShop.id) : undefined,
/**
* Purpose: signature supports index.js by holding or executing the signature page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
signature: this.data.userForm.signature || undefined
})
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: this.data.mode === 'edit' ? '美甲师已更新' : '美甲师已创建',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
navigation.goBack('/pages/artists/index')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '保存失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,82 @@
<navigation-bar title="{{mode === 'edit' ? '编辑美甲师' : '新增美甲师'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">账号信息</text>
<view class="field-group">
<text class="field-label">昵称</text>
<input class="field-input" value="{{userForm.nickname}}" data-field="nickname" bindinput="handleUserInput"></input>
</view>
<view class="field-group">
<text class="field-label">账号</text>
<input class="field-input" value="{{userForm.account}}" data-field="account" bindinput="handleUserInput"></input>
</view>
<view class="field-group">
<text class="field-label">手机号</text>
<input class="field-input" type="number" value="{{userForm.phone}}" data-field="phone" bindinput="handleUserInput"></input>
</view>
<view class="field-group">
<text class="field-label">{{mode === 'edit' ? '密码(留空则不修改)' : '登录密码'}}</text>
<input class="field-input" password value="{{userForm.password}}" data-field="password" bindinput="handleUserInput"></input>
</view>
<view class="field-group">
<text class="field-label">签名</text>
<textarea class="field-textarea" value="{{userForm.signature}}" data-field="signature" bindinput="handleUserInput"></textarea>
</view>
<view class="field-group">
<text class="field-label">所属店铺</text>
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
</picker>
</view>
</view>
<view class="surface-card">
<text class="section-title">职业信息</text>
<view class="field-group">
<text class="field-label">身份标签</text>
<input class="field-input" value="{{artistForm.identity}}" data-field="identity" bindinput="handleArtistInput"></input>
</view>
<view class="field-group">
<text class="field-label">从业年限</text>
<input class="field-input" type="number" value="{{artistForm.experience}}" data-field="experience" bindinput="handleArtistInput"></input>
</view>
<view class="field-group">
<text class="field-label">评分</text>
<input class="field-input" type="digit" value="{{artistForm.rating}}" data-field="rating" bindinput="handleArtistInput"></input>
</view>
<view class="field-group">
<text class="field-label">营业状态</text>
<picker mode="selector" range="{{statusOptions}}" value="{{statusIndex}}" bindchange="handleStatusChange">
<view class="field-picker">{{statusOptions[statusIndex]}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">擅长标签</text>
<checkbox-group bindchange="handleTagChange">
<block wx:for="{{tags}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="field-group">
<text class="field-label">作品集</text>
<checkbox-group bindchange="handleProductChange">
<block wx:for="{{products}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存美甲师</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
@@ -0,0 +1,119 @@
/**
* Purpose: artistApi supports index.js by holding or executing the artist api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const artistApi = require('../../api/nail-artist')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: list supports index.js by holding or executing the list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
list: [],
/**
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canCreate: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
if (!navigation.ensureLogin('进入美甲师管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canCreate: permissionCodes.includes('user:create') || permissionCodes.includes('nail_artist:edit')
})
this.loadArtists()
},
async loadArtists() {
try {
const list = await artistApi.listNailArtists()
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
list: (Array.isArray(list) ? list : []).map(item => ({
...item,
/**
* Purpose: displayStatusText supports index.js by holding or executing the display status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayStatusText: Number(item.status) === 0 ? '休息中' : '营业中'
}))
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '美甲师列表加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleCreate() {
clearTempRecord('currentArtist')
navigation.navigate('/pages/artist-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'create'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleEdit(event) {
const artist = event.currentTarget.dataset.artist
setTempRecord('currentArtist', artist)
navigation.navigate('/pages/artist-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'edit',
/**
* Purpose: userId supports index.js by holding or executing the user id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userId: artist.userId
}).catch(() => undefined)
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,42 @@
<navigation-bar title="美甲师管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">美甲师列表</text>
<text class="section-desc">店长只能看到并管理自己门店的美甲师;平台管理员可跨店查看,移动端表单集中处理账号和档案两部分信息。</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.nickname}}</text>
<text class="list-subtitle">{{item.identity || '未设置身份'}} · {{item.shopName || '当前店铺'}}</text>
</view>
<text class="{{item.status === 0 ? 'soft-badge' : 'badge'}}">{{item.displayStatusText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">从业年限</text>
<text class="meta-value">{{item.experience || 0}} 年</text>
</view>
<view class="meta-item">
<text class="meta-label">评分</text>
<text class="meta-value">{{item.rating || 0}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn primary" data-artist="{{item}}" bindtap="handleEdit">编辑</view>
</view>
</view>
</block>
<view wx:if="{{!list.length}}" class="empty-state">
<text class="empty-title">还没有美甲师</text>
<text class="empty-desc">可以先新增一个美甲师账号,再补充技能、作品集和营业状态。</text>
</view>
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,154 @@
const campaignApi = require('../../api/campaign')
const navigation = require('../../utils/navigation')
const permission = require('../../utils/permission')
const format = require('../../utils/format')
const { markDirty } = require('../../utils/page-state')
const STATUS_OPTIONS = [
{ label: '全部', value: '' },
{ label: '启用', value: '1' },
{ label: '停用', value: '0' }
]
function safeList(response) {
if (Array.isArray(response && response.list)) {
return response.list
}
if (Array.isArray(response && response.records)) {
return response.records
}
return []
}
Page({
data: {
loading: false,
list: [],
total: 0,
status: '',
statusOptions: STATUS_OPTIONS,
canManage: false,
form: {
title: '',
scene: 'HOME',
description: '',
sortOrder: '0'
}
},
onShow() {
if (!navigation.ensureLogin('进入活动管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
canManage: permission.hasPermission(permissionCodes, 'campaign:manage')
})
this.loadCampaigns()
},
onPullDownRefresh() {
this.loadCampaigns().finally(() => {
wx.stopPullDownRefresh()
})
},
async loadCampaigns() {
this.setData({ loading: true })
try {
const response = await campaignApi.listCampaigns({
page: 1,
size: 20,
status: this.data.status === '' ? undefined : Number(this.data.status)
})
this.setData({
list: safeList(response).map(item => this.formatCampaign(item)),
total: Number(response && response.total) || 0
})
} catch (error) {
wx.showToast({
title: error.message || '活动加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
formatCampaign(item) {
return {
...item,
statusText: Number(item.status) === 0 ? '停用' : '启用',
displayStartTime: format.formatDateTime(item.startTime),
displayEndTime: format.formatDateTime(item.endTime)
}
},
handleStatusChange(event) {
this.setData({
status: event.currentTarget.dataset.status
})
this.loadCampaigns()
},
handleFormInput(event) {
const field = event.currentTarget.dataset.field
if (!field) {
return
}
this.setData({
[`form.${field}`]: event.detail.value
})
},
async handleSaveCampaign() {
if (!this.data.canManage) {
wx.showToast({
title: '当前账号没有活动管理权限',
icon: 'none'
})
return
}
const form = this.data.form
const title = String(form.title || '').trim()
if (!title) {
wx.showToast({
title: '请填写活动标题',
icon: 'none'
})
return
}
try {
await campaignApi.saveCampaign({
title,
scene: String(form.scene || '').trim() || 'HOME',
description: String(form.description || '').trim(),
sortOrder: Number(form.sortOrder) || 0,
status: 1
})
markDirty('admin-workbench')
wx.showToast({
title: '活动已创建',
icon: 'none'
})
this.setData({
form: {
title: '',
scene: 'HOME',
description: '',
sortOrder: '0'
}
})
this.loadCampaigns()
} catch (error) {
wx.showToast({
title: error.message || '活动保存失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,60 @@
<navigation-bar title="活动管理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">Campaign</text>
<text class="hero-title">活动管理</text>
<text class="hero-desc">查看营销活动和推荐位配置,支持在手机端快速创建启用活动。</text>
</view>
<view wx:if="{{canManage}}" class="surface-card">
<text class="section-title">快速创建</text>
<input class="field-input compact-field" placeholder="活动标题" placeholder-class="placeholder" value="{{form.title}}" data-field="title" bindinput="handleFormInput"></input>
<view class="form-grid">
<input class="field-input" placeholder="场景,如 HOME" placeholder-class="placeholder" value="{{form.scene}}" data-field="scene" bindinput="handleFormInput"></input>
<input class="field-input" type="number" placeholder="排序" placeholder-class="placeholder" value="{{form.sortOrder}}" data-field="sortOrder" bindinput="handleFormInput"></input>
</view>
<textarea class="field-textarea compact-textarea" placeholder="活动说明,可留空" placeholder-class="placeholder" value="{{form.description}}" data-field="description" bindinput="handleFormInput"></textarea>
<button class="primary-btn compact-btn" loading="{{loading}}" bindtap="handleSaveCampaign">创建活动</button>
</view>
<view class="surface-card">
<text class="section-title">活动列表</text>
<view class="chip-row">
<block wx:for="{{statusOptions}}" wx:key="value">
<view class="chip-btn {{status === item.value ? 'active' : ''}}" data-status="{{item.value}}" bindtap="handleStatusChange">{{item.label}}</view>
</block>
</view>
<text class="section-desc">共 {{total}} 条活动</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.title}}</text>
<text class="list-subtitle">{{item.scene || '未设置场景'}} · 排序 {{item.sortOrder || 0}}</text>
</view>
<text class="{{item.status === 0 ? 'soft-badge' : 'success-badge'}}">{{item.statusText}}</text>
</view>
<view wx:if="{{item.description}}" class="hint-card">{{item.description}}</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">开始</text>
<text class="meta-value">{{item.displayStartTime || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">结束</text>
<text class="meta-value">{{item.displayEndTime || '--'}}</text>
</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无活动</text>
<text class="empty-desc">当前筛选条件下没有营销活动。</text>
</view>
</view>
</view>
@@ -0,0 +1,21 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.compact-field,
.compact-btn,
.compact-textarea {
margin-top: 16rpx;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14rpx;
margin-top: 16rpx;
}
.compact-textarea {
min-height: 140rpx;
}
@@ -0,0 +1,143 @@
/**
* Purpose: commentApi supports index.js by holding or executing the comment api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const commentApi = require('../../api/comment')
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: '',
/**
* Purpose: comments supports index.js by holding or executing the comments page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
comments: []
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
this.loadComments()
},
async onPullDownRefresh() {
await this.loadComments()
wx.stopPullDownRefresh()
},
/**
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleKeywordInput(event) {
this.setData({
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: event.detail.value
})
},
async loadComments() {
this.setData({ loading: true })
try {
const comments = await commentApi.listComments({
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: this.data.keyword || undefined
})
this.setData({
/**
* Purpose: comments supports index.js by holding or executing the comments page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
comments: Array.isArray(comments) ? comments : []
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '评论加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
/**
* Purpose: handleSearch supports index.js by holding or executing the handle search page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleSearch() {
this.loadComments()
},
/**
* Purpose: handleDelete supports index.js by holding or executing the handle delete page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleDelete(event) {
const id = event.currentTarget.dataset.id
if (!id) {
return
}
wx.showModal({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '删除评论',
/**
* Purpose: content supports index.js by holding or executing the content page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
content: '确认删除这条评论?',
/**
* Purpose: confirmText supports index.js by holding or executing the confirm text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
confirmText: '删除',
/**
* Purpose: success supports index.js by holding or executing the success page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
success: async res => {
if (!res.confirm) {
return
}
try {
await commentApi.deleteComment(id)
wx.showToast({ title: '评论已删除', icon: 'none' })
this.loadComments()
} catch (error) {
wx.showToast({ title: error.message || '删除失败', icon: 'none' })
}
}
})
}
})
@@ -0,0 +1,21 @@
<navigation-bar title="评论管理" showBack="{{true}}" background="#081518" color="#ffffff"></navigation-bar>
<view class="page">
<view class="search-row">
<input class="search-input" placeholder="搜索评论内容" value="{{keyword}}" bindinput="handleKeywordInput" confirm-type="search" bindconfirm="handleSearch" />
<view class="search-btn" bindtap="handleSearch">搜索</view>
</view>
<view wx:if="{{!comments.length && !loading}}" class="empty">暂无评论</view>
<view wx:for="{{comments}}" wx:key="id" class="comment-card">
<view class="comment-head">
<text class="comment-user">{{item.userNickname || '用户'}}</text>
<text class="comment-time">{{item.createTime}}</text>
</view>
<view class="comment-content">{{item.commentContent}}</view>
<view wx:if="{{item.parentCommentContent}}" class="reply-content">回复:{{item.parentCommentContent}}</view>
<view class="comment-meta">{{item.productTitle || '作品'}} · {{item.shopName || '门店'}}</view>
<view class="delete-btn" data-id="{{item.id}}" bindtap="handleDelete">删除</view>
</view>
</view>
@@ -0,0 +1,95 @@
@import "../../app.wxss";
.page {
min-height: 100vh;
padding: 28rpx 24rpx 60rpx;
background: #0c181b;
}
.search-row {
display: flex;
gap: 16rpx;
margin-bottom: 24rpx;
}
.search-input {
flex: 1;
height: 76rpx;
padding: 0 24rpx;
border-radius: 18rpx;
background: #132529;
color: #ffffff;
font-size: 26rpx;
}
.search-btn {
width: 128rpx;
height: 76rpx;
line-height: 76rpx;
text-align: center;
border-radius: 18rpx;
background: #f07e57;
color: #ffffff;
font-weight: 700;
}
.empty {
padding: 80rpx 0;
text-align: center;
color: #7e8f8c;
}
.comment-card {
margin-bottom: 18rpx;
padding: 24rpx;
border-radius: 20rpx;
background: #132529;
color: #dce7e4;
}
.comment-head {
display: flex;
justify-content: space-between;
gap: 16rpx;
}
.comment-user {
font-size: 28rpx;
font-weight: 700;
color: #ffffff;
}
.comment-time,
.comment-meta {
font-size: 22rpx;
color: #7e8f8c;
}
.comment-content {
margin-top: 16rpx;
font-size: 26rpx;
line-height: 1.8;
}
.reply-content {
margin-top: 12rpx;
padding: 16rpx;
border-radius: 16rpx;
background: #0c181b;
color: #a9bbb6;
font-size: 24rpx;
}
.comment-meta {
margin-top: 14rpx;
}
.delete-btn {
margin-top: 18rpx;
width: 120rpx;
height: 56rpx;
line-height: 56rpx;
text-align: center;
border-radius: 999rpx;
color: #ffffff;
background: #d95f5f;
}
@@ -0,0 +1,87 @@
const couponApi = require('../../api/coupon')
const userApi = require('../../api/user')
const navigation = require('../../utils/navigation')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
Page({
data: {
coupon: null,
users: [],
quantity: 1
},
onLoad() {
const coupon = getTempRecord('currentCoupon', null)
this.setData({
coupon
})
this.loadUsers()
},
onUnload() {
clearTempRecord('currentCoupon')
},
async loadUsers() {
try {
const users = await userApi.listAllUsers()
this.setData({
users: (Array.isArray(users) ? users : []).map(item => ({
...item,
valueId: String(item.id),
checked: false
}))
})
} catch (error) {
wx.showToast({
title: error.message || '可发放用户加载失败',
icon: 'none'
})
}
},
handleUserCheck(event) {
const selected = event.detail.value || []
this.setData({
users: this.data.users.map(item => ({
...item,
checked: selected.includes(item.valueId)
}))
})
},
handleQuantityInput(event) {
this.setData({
quantity: event.detail.value
})
},
async handleSubmit() {
const selectedUserIds = this.data.users.filter(item => item.checked).map(item => Number(item.id))
if (!selectedUserIds.length) {
wx.showToast({
title: '请至少选择一个用户',
icon: 'none'
})
return
}
try {
await couponApi.distributeCoupon({
couponId: this.data.coupon.id,
userIds: selectedUserIds,
quantity: Number(this.data.quantity || 1)
})
wx.showToast({
title: '优惠券已发放',
icon: 'none'
})
navigation.goBack('/pages/coupons/index')
} catch (error) {
wx.showToast({
title: error.message || '发放失败',
icon: 'none'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,28 @@
<navigation-bar title="发放优惠券" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card" wx:if="{{coupon}}">
<text class="section-title">{{coupon.couponName}}</text>
<text class="section-desc">选择用户后批量发放,数量默认 1。移动端只保留高频发放能力,不把 Web 的宽表格搬过来。</text>
<view class="field-group">
<text class="field-label">发放数量</text>
<input class="field-input" type="number" value="{{quantity}}" bindinput="handleQuantityInput"></input>
</view>
<view class="field-group">
<text class="field-label">选择用户</text>
<checkbox-group bindchange="handleUserCheck">
<block wx:for="{{users}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.nickname || item.account}}
</label>
</block>
</checkbox-group>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">确认发放</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
@@ -0,0 +1,707 @@
/**
* Purpose: couponApi supports index.js by holding or executing the coupon api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const couponApi = require('../../api/coupon')
/**
* Purpose: tagApi supports index.js by holding or executing the tag api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const tagApi = require('../../api/tag')
/**
* Purpose: shopApi supports index.js by holding or executing the shop api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopApi = require('../../api/shop')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: format supports index.js by holding or executing the format page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const format = require('../../utils/format')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
/**
* Purpose: normalizeId supports index.js by holding or executing the normalize id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
}
/**
* Purpose: buildCheckableList supports index.js by holding or executing the build checkable list page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildCheckableList(list, selectedIds, labelKey) {
return (Array.isArray(list) ? list : []).map(item => ({
...item,
valueId: normalizeId(item.id),
labelText: item[labelKey],
checked: selectedIds.includes(normalizeId(item.id))
}))
}
/**
* Purpose: syncSelectedIds supports index.js by holding or executing the sync selected ids page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function syncSelectedIds(selectedIds, list) {
const availableIds = new Set((Array.isArray(list) ? list : []).map(item => normalizeId(item.id)))
return (Array.isArray(selectedIds) ? selectedIds : []).filter(id => availableIds.has(normalizeId(id)))
}
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'create',
/**
* Purpose: couponId supports index.js by holding or executing the coupon id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponId: '',
/**
* Purpose: shops supports index.js by holding or executing the shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shops: [],
/**
* Purpose: shopIndex supports index.js by holding or executing the shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopIndex: 0,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: '',
/**
* Purpose: couponTypeOptions supports index.js by holding or executing the coupon type options page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponTypeOptions: ['折扣券', '满减券'],
/**
* Purpose: couponTypeIndex supports index.js by holding or executing the coupon type index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponTypeIndex: 0,
/**
* Purpose: couponTypeLabel supports index.js by holding or executing the coupon type label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponTypeLabel: '折扣券',
/**
* Purpose: vipLevelOptions supports index.js by holding or executing the vip level options page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipLevelOptions: ['普通', '青铜', '白银', '黄金'],
/**
* Purpose: vipLevelIndex supports index.js by holding or executing the vip level index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipLevelIndex: 0,
/**
* Purpose: vipLevelLabel supports index.js by holding or executing the vip level label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipLevelLabel: '普通',
/**
* Purpose: startDate supports index.js by holding or executing the start date page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
startDate: '',
/**
* Purpose: startTime supports index.js by holding or executing the start time page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
startTime: '',
/**
* Purpose: endDate supports index.js by holding or executing the end date page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
endDate: '',
/**
* Purpose: endTime supports index.js by holding or executing the end time page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
endTime: '',
/**
* Purpose: availableTags supports index.js by holding or executing the available tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
availableTags: [],
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unavailableTags: [],
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: couponName supports index.js by holding or executing the coupon name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponName: '',
/**
* Purpose: couponCode supports index.js by holding or executing the coupon code page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponCode: '',
/**
* Purpose: discountValue supports index.js by holding or executing the discount value page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
discountValue: '',
/**
* Purpose: minAmount supports index.js by holding or executing the min amount page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
minAmount: '',
/**
* Purpose: reduceAmount supports index.js by holding or executing the reduce amount page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
reduceAmount: '',
/**
* Purpose: totalCount supports index.js by holding or executing the total count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
totalCount: '',
/**
* Purpose: couponScene supports index.js by holding or executing the coupon scene page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponScene: '',
/**
* Purpose: autoMatch supports index.js by holding or executing the auto match page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
autoMatch: false
}
},
/**
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLoad(options) {
const mode = options && options.mode ? options.mode : 'create'
const currentCoupon = getTempRecord('currentCoupon', null)
this.setData({
mode,
/**
* Purpose: couponId supports index.js by holding or executing the coupon id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponId: options && options.id ? options.id : ''
})
this._selectedAvailableTagIds = []
this._selectedUnavailableTagIds = []
if (mode === 'edit' && currentCoupon) {
const start = format.parseDateTimeToPicker(currentCoupon.startTime)
const end = format.parseDateTimeToPicker(currentCoupon.endTime)
this._selectedAvailableTagIds = Array.isArray(currentCoupon.availableTags) ? currentCoupon.availableTags.map(item => String(item.id)) : []
this._selectedUnavailableTagIds = Array.isArray(currentCoupon.unavailableTags) ? currentCoupon.unavailableTags.map(item => String(item.id)) : []
this._initialShopId = currentCoupon.shopId
this.setData({
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: couponName supports index.js by holding or executing the coupon name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponName: currentCoupon.couponName || '',
/**
* Purpose: couponCode supports index.js by holding or executing the coupon code page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponCode: currentCoupon.couponCode || '',
/**
* Purpose: discountValue supports index.js by holding or executing the discount value page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
discountValue: currentCoupon.discountValue || '',
/**
* Purpose: minAmount supports index.js by holding or executing the min amount page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
minAmount: currentCoupon.minAmount || '',
/**
* Purpose: reduceAmount supports index.js by holding or executing the reduce amount page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
reduceAmount: currentCoupon.reduceAmount || '',
/**
* Purpose: totalCount supports index.js by holding or executing the total count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
totalCount: currentCoupon.totalCount || '',
/**
* Purpose: couponScene supports index.js by holding or executing the coupon scene page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponScene: currentCoupon.couponScene || '',
/**
* Purpose: autoMatch supports index.js by holding or executing the auto match page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
autoMatch: Number(currentCoupon.autoMatch) === 1
},
/**
* Purpose: couponTypeIndex supports index.js by holding or executing the coupon type index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponTypeIndex: Number(currentCoupon.couponType) === 2 ? 1 : 0,
/**
* Purpose: couponTypeLabel supports index.js by holding or executing the coupon type label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponTypeLabel: Number(currentCoupon.couponType) === 2 ? '满减券' : '折扣券',
/**
* Purpose: vipLevelIndex supports index.js by holding or executing the vip level index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipLevelIndex: this.data.vipLevelOptions.findIndex(item => item === (currentCoupon.requiredVipLevel || '普通')),
/**
* Purpose: vipLevelLabel supports index.js by holding or executing the vip level label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipLevelLabel: currentCoupon.requiredVipLevel || '普通',
/**
* Purpose: startDate supports index.js by holding or executing the start date page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
startDate: start.date,
/**
* Purpose: startTime supports index.js by holding or executing the start time page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
startTime: start.time,
/**
* Purpose: endDate supports index.js by holding or executing the end date page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
endDate: end.date,
/**
* Purpose: endTime supports index.js by holding or executing the end time page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
endTime: end.time
})
}
this.loadDependencies()
},
/**
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onUnload() {
clearTempRecord('currentCoupon')
},
async loadDependencies() {
const app = getApp()
const currentShop = app.globalData.currentShop
const operator = app.globalData.userInfo || {}
try {
const shopList = await shopApi.listAllShops()
let shops = Array.isArray(shopList) ? shopList : []
if (Number(operator.type) !== 4 && currentShop) {
shops = shops.filter(item => normalizeId(item.id) === normalizeId(currentShop.id))
}
let shopIndex = 0
if (this._initialShopId) {
const index = shops.findIndex(item => normalizeId(item.id) === normalizeId(this._initialShopId))
if (index >= 0) {
shopIndex = index
}
}
const selectedShop = shops[shopIndex]
this.setData({
shops,
shopIndex,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: selectedShop ? selectedShop.shopName : ''
})
await this.loadTagOptions(selectedShop ? selectedShop.id : '')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '初始化优惠券表单失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
async loadTagOptions(shopId) {
if (!normalizeId(shopId)) {
this._selectedAvailableTagIds = []
this._selectedUnavailableTagIds = []
this.setData({
/**
* Purpose: availableTags supports index.js by holding or executing the available tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
availableTags: [],
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unavailableTags: []
})
return
}
try {
const tagList = await tagApi.listTagsByShopId(shopId)
this._selectedAvailableTagIds = syncSelectedIds(this._selectedAvailableTagIds, tagList)
this._selectedUnavailableTagIds = syncSelectedIds(this._selectedUnavailableTagIds, tagList)
this.setData({
/**
* Purpose: availableTags supports index.js by holding or executing the available tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
availableTags: buildCheckableList(tagList, this._selectedAvailableTagIds, 'tagName'),
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unavailableTags: buildCheckableList(tagList, this._selectedUnavailableTagIds, 'tagName')
})
} catch (error) {
this.setData({
/**
* Purpose: availableTags supports index.js by holding or executing the available tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
availableTags: [],
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unavailableTags: []
})
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '可用标签加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
/**
* Purpose: handleInputChange supports index.js by holding or executing the handle input change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleInputChange(event) {
const field = event.currentTarget.dataset.field
const value = event.detail.value
this.setData({
[`form.${field}`]: value
})
},
/**
* Purpose: handleShopChange supports index.js by holding or executing the handle shop change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleShopChange(event) {
const shopIndex = Number(event.detail.value)
const selectedShop = this.data.shops[shopIndex]
this.setData({
shopIndex,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: selectedShop ? selectedShop.shopName : ''
})
this.loadTagOptions(selectedShop ? selectedShop.id : '')
},
/**
* Purpose: handleCouponTypeChange supports index.js by holding or executing the handle coupon type change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleCouponTypeChange(event) {
const couponTypeIndex = Number(event.detail.value)
this.setData({
couponTypeIndex,
/**
* Purpose: couponTypeLabel supports index.js by holding or executing the coupon type label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponTypeLabel: this.data.couponTypeOptions[couponTypeIndex]
})
},
/**
* Purpose: handleVipLevelChange supports index.js by holding or executing the handle vip level change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleVipLevelChange(event) {
const vipLevelIndex = Number(event.detail.value)
this.setData({
vipLevelIndex,
/**
* Purpose: vipLevelLabel supports index.js by holding or executing the vip level label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
vipLevelLabel: this.data.vipLevelOptions[vipLevelIndex]
})
},
/**
* Purpose: handleDateTimeChange supports index.js by holding or executing the handle date time change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleDateTimeChange(event) {
const field = event.currentTarget.dataset.field
this.setData({
[field]: event.detail.value
})
},
/**
* Purpose: handleAutoMatchChange supports index.js by holding or executing the handle auto match change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleAutoMatchChange(event) {
this.setData({
'form.autoMatch': event.detail.value
})
},
/**
* Purpose: handleAvailableTagChange supports index.js by holding or executing the handle available tag change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleAvailableTagChange(event) {
this._selectedAvailableTagIds = event.detail.value || []
this.setData({
/**
* Purpose: availableTags supports index.js by holding or executing the available tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
availableTags: this.data.availableTags.map(item => ({
...item,
/**
* Purpose: checked supports index.js by holding or executing the checked page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
checked: this._selectedAvailableTagIds.includes(item.valueId)
}))
})
},
/**
* Purpose: handleUnavailableTagChange supports index.js by holding or executing the handle unavailable tag change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleUnavailableTagChange(event) {
this._selectedUnavailableTagIds = event.detail.value || []
this.setData({
/**
* Purpose: unavailableTags supports index.js by holding or executing the unavailable tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unavailableTags: this.data.unavailableTags.map(item => ({
...item,
/**
* Purpose: checked supports index.js by holding or executing the checked page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
checked: this._selectedUnavailableTagIds.includes(item.valueId)
}))
})
},
async handleSubmit() {
const selectedShop = this.data.shops[this.data.shopIndex]
if (!this.data.form.couponName) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '请输入优惠券名称',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
if (!selectedShop) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '请选择所属店铺',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
const payload = {
/**
* Purpose: couponCode supports index.js by holding or executing the coupon code page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponCode: this.data.form.couponCode || undefined,
/**
* Purpose: couponName supports index.js by holding or executing the coupon name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponName: this.data.form.couponName,
/**
* Purpose: couponType supports index.js by holding or executing the coupon type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponType: this.data.couponTypeIndex === 1 ? 2 : 1,
/**
* Purpose: discountValue supports index.js by holding or executing the discount value page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
discountValue: this.data.couponTypeIndex === 0 ? Number(this.data.form.discountValue || 0) : undefined,
/**
* Purpose: minAmount supports index.js by holding or executing the min amount page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
minAmount: this.data.couponTypeIndex === 1 ? Number(this.data.form.minAmount || 0) : undefined,
/**
* Purpose: reduceAmount supports index.js by holding or executing the reduce amount page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
reduceAmount: this.data.couponTypeIndex === 1 ? Number(this.data.form.reduceAmount || 0) : undefined,
/**
* Purpose: totalCount supports index.js by holding or executing the total count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
totalCount: this.data.form.totalCount ? Number(this.data.form.totalCount) : undefined,
/**
* Purpose: startTime supports index.js by holding or executing the start time page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
startTime: format.buildDateTime(this.data.startDate, this.data.startTime),
/**
* Purpose: endTime supports index.js by holding or executing the end time page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
endTime: format.buildDateTime(this.data.endDate, this.data.endTime),
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: selectedShop.id,
/**
* Purpose: couponScene supports index.js by holding or executing the coupon scene page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
couponScene: this.data.form.couponScene || undefined,
/**
* Purpose: requiredVipLevel supports index.js by holding or executing the required vip level page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
requiredVipLevel: this.data.vipLevelLabel || undefined,
/**
* Purpose: autoMatch supports index.js by holding or executing the auto match page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
autoMatch: this.data.form.autoMatch ? 1 : 0,
/**
* Purpose: availableTagIds supports index.js by holding or executing the available tag ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
availableTagIds: this._selectedAvailableTagIds.map(item => Number(item)),
/**
* Purpose: unavailableTagIds supports index.js by holding or executing the unavailable tag ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
unavailableTagIds: this._selectedUnavailableTagIds.map(item => Number(item))
}
try {
if (this.data.mode === 'edit') {
await couponApi.updateCoupon(this.data.couponId, payload)
} else {
await couponApi.createCoupon(payload)
}
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: this.data.mode === 'edit' ? '优惠券已更新' : '优惠券已创建',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
navigation.goBack('/pages/coupons/index')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '保存失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,111 @@
<navigation-bar title="{{mode === 'edit' ? '编辑优惠券' : '新增优惠券'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">优惠券信息</text>
<view class="field-group">
<text class="field-label">优惠券名称</text>
<input class="field-input" value="{{form.couponName}}" data-field="couponName" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">所属店铺</text>
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">券类型</text>
<picker mode="selector" range="{{couponTypeOptions}}" value="{{couponTypeIndex}}" bindchange="handleCouponTypeChange">
<view class="field-picker">{{couponTypeLabel}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">优惠编码</text>
<input class="field-input" value="{{form.couponCode}}" data-field="couponCode" bindinput="handleInputChange"></input>
</view>
<view wx:if="{{couponTypeIndex === 0}}" class="field-group">
<text class="field-label">折扣值</text>
<input class="field-input" type="digit" value="{{form.discountValue}}" data-field="discountValue" bindinput="handleInputChange"></input>
</view>
<block wx:if="{{couponTypeIndex === 1}}">
<view class="field-group">
<text class="field-label">满多少可用</text>
<input class="field-input" type="digit" value="{{form.minAmount}}" data-field="minAmount" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">减免金额</text>
<input class="field-input" type="digit" value="{{form.reduceAmount}}" data-field="reduceAmount" bindinput="handleInputChange"></input>
</view>
</block>
<view class="field-group">
<text class="field-label">总数量</text>
<input class="field-input" type="number" value="{{form.totalCount}}" data-field="totalCount" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">优惠场景</text>
<input class="field-input" value="{{form.couponScene}}" data-field="couponScene" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">VIP 等级限制</text>
<picker mode="selector" range="{{vipLevelOptions}}" value="{{vipLevelIndex}}" bindchange="handleVipLevelChange">
<view class="field-picker">{{vipLevelLabel}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">开始日期 / 时间</text>
<view class="action-row">
<picker mode="date" value="{{startDate}}" data-field="startDate" bindchange="handleDateTimeChange">
<view class="field-picker">{{startDate || '开始日期'}}</view>
</picker>
<picker mode="time" value="{{startTime}}" data-field="startTime" bindchange="handleDateTimeChange">
<view class="field-picker">{{startTime || '开始时间'}}</view>
</picker>
</view>
</view>
<view class="field-group">
<text class="field-label">结束日期 / 时间</text>
<view class="action-row">
<picker mode="date" value="{{endDate}}" data-field="endDate" bindchange="handleDateTimeChange">
<view class="field-picker">{{endDate || '结束日期'}}</view>
</picker>
<picker mode="time" value="{{endTime}}" data-field="endTime" bindchange="handleDateTimeChange">
<view class="field-picker">{{endTime || '结束时间'}}</view>
</picker>
</view>
</view>
<view class="field-group">
<text class="field-label">自动匹配</text>
<switch checked="{{form.autoMatch}}" bindchange="handleAutoMatchChange"></switch>
</view>
<view class="field-group">
<text class="field-label">可用标签</text>
<checkbox-group bindchange="handleAvailableTagChange">
<block wx:for="{{availableTags}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="field-group">
<text class="field-label">不可用标签</text>
<checkbox-group bindchange="handleUnavailableTagChange">
<block wx:for="{{unavailableTags}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存优惠券</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
@@ -0,0 +1,219 @@
/**
* Purpose: couponApi supports index.js by holding or executing the coupon api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const couponApi = require('../../api/coupon')
/**
* Purpose: format supports index.js by holding or executing the format page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const format = require('../../utils/format')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: list supports index.js by holding or executing the list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
list: [],
/**
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canCreate: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
if (!navigation.ensureLogin('进入优惠券管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canCreate: permissionCodes.includes('coupon:create')
})
this.loadCoupons()
},
async loadCoupons() {
try {
const result = await couponApi.listCoupons({
/**
* Purpose: page supports index.js by holding or executing the page page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
size: 20
})
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
...item,
/**
* Purpose: displayTypeText supports index.js by holding or executing the display type text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayTypeText: format.getCouponTypeText(item.couponType),
/**
* Purpose: displayValueText supports index.js by holding or executing the display value text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayValueText: format.getCouponValueText(item),
/**
* Purpose: displayShopName supports index.js by holding or executing the display shop name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayShopName: item.shopName || '当前店铺'
}))
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '优惠券加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleCreate() {
clearTempRecord('currentCoupon')
navigation.navigate('/pages/coupon-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'create'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleEdit(event) {
const coupon = event.currentTarget.dataset.coupon
setTempRecord('currentCoupon', coupon)
navigation.navigate('/pages/coupon-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'edit',
/**
* Purpose: id supports index.js by holding or executing the id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
id: coupon.id
}).catch(() => undefined)
},
/**
* Purpose: handleDistribute supports index.js by holding or executing the handle distribute page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleDistribute(event) {
const coupon = event.currentTarget.dataset.coupon
setTempRecord('currentCoupon', coupon)
navigation.navigate('/pages/coupon-distribute/index', {
/**
* Purpose: id supports index.js by holding or executing the id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
id: coupon.id
}).catch(() => undefined)
},
/**
* Purpose: handleDelete supports index.js by holding or executing the handle delete page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleDelete(event) {
const coupon = event.currentTarget.dataset.coupon
wx.showModal({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '删除优惠券',
/**
* Purpose: content supports index.js by holding or executing the content page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
content: `确认删除优惠券“${coupon.couponName}”吗?`,
/**
* Purpose: success supports index.js by holding or executing the success page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
success: async result => {
if (!result.confirm) {
return
}
try {
await couponApi.deleteCoupon(coupon.id)
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '优惠券已删除',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
this.loadCoupons()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '优惠券删除失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,44 @@
<navigation-bar title="优惠券管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">优惠券列表</text>
<text class="section-desc">普通券、VIP 自动券都在这里维护;发放动作单独收口到移动端发放页,避免一屏塞太多字段。</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.couponName}}</text>
<text class="list-subtitle">{{item.displayShopName}} · {{item.displayTypeText}}</text>
</view>
<text class="badge">{{item.displayValueText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">可用时间</text>
<text class="meta-value">{{item.startTime}} ~ {{item.endTime}}</text>
</view>
<view class="meta-item">
<text class="meta-label">剩余数量</text>
<text class="meta-value">{{item.remainingCount || item.totalCount || '--'}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn" data-coupon="{{item}}" bindtap="handleDistribute">发放</view>
<view class="mini-btn primary" data-coupon="{{item}}" bindtap="handleEdit">编辑</view>
<view class="mini-btn danger" data-coupon="{{item}}" bindtap="handleDelete">删除</view>
</view>
</view>
</block>
<view wx:if="{{!list.length}}" class="empty-state">
<text class="empty-title">暂无优惠券</text>
<text class="empty-desc">可以先创建普通券,也可以为每家店铺维护自己的 VIP 自动券模板。</text>
</view>
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,204 @@
const inventoryApi = require('../../api/inventory')
const navigation = require('../../utils/navigation')
const permission = require('../../utils/permission')
const format = require('../../utils/format')
const { markDirty } = require('../../utils/page-state')
function safeList(response) {
if (Array.isArray(response && response.list)) {
return response.list
}
if (Array.isArray(response && response.records)) {
return response.records
}
return []
}
Page({
data: {
loading: false,
list: [],
total: 0,
canManage: false,
form: {
itemName: '',
category: '',
unit: '件',
stockQuantity: '0',
warningThreshold: '1'
}
},
onShow() {
if (!navigation.ensureLogin('进入库存管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
canManage: permission.hasPermission(permissionCodes, 'inventory:manage')
})
this.loadItems()
},
onPullDownRefresh() {
this.loadItems().finally(() => {
wx.stopPullDownRefresh()
})
},
async loadItems() {
this.setData({ loading: true })
try {
const response = await inventoryApi.listItems({
page: 1,
size: 30
})
this.setData({
list: safeList(response).map(item => this.formatItem(item)),
total: Number(response && response.total) || 0
})
} catch (error) {
wx.showToast({
title: error.message || '库存加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
formatItem(item) {
return {
...item,
displayStock: format.formatPrice(item.stockQuantity),
displayWarning: format.formatPrice(item.warningThreshold),
statusText: Number(item.status) === 0 ? '停用' : '启用'
}
},
handleFormInput(event) {
const field = event.currentTarget.dataset.field
if (!field) {
return
}
this.setData({
[`form.${field}`]: event.detail.value
})
},
async handleSaveItem() {
if (!this.data.canManage) {
wx.showToast({
title: '当前账号没有库存维护权限',
icon: 'none'
})
return
}
const form = this.data.form
if (!String(form.itemName || '').trim()) {
wx.showToast({
title: '请填写物料名称',
icon: 'none'
})
return
}
try {
await inventoryApi.saveItem({
itemName: String(form.itemName || '').trim(),
category: String(form.category || '').trim(),
unit: String(form.unit || '').trim() || '件',
stockQuantity: Number(form.stockQuantity) || 0,
warningThreshold: Number(form.warningThreshold) || 0,
status: 1
})
markDirty('admin-workbench')
wx.showToast({
title: '物料已保存',
icon: 'none'
})
this.setData({
form: {
itemName: '',
category: '',
unit: '件',
stockQuantity: '0',
warningThreshold: '1'
}
})
this.loadItems()
} catch (error) {
wx.showToast({
title: error.message || '物料保存失败',
icon: 'none'
})
}
},
promptAdjust(item) {
return new Promise(resolve => {
wx.showModal({
title: `调整 ${item.itemName}`,
content: '填写正数入库,负数出库。',
editable: true,
placeholderText: '例如 5 或 -2',
confirmText: '调整',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
},
async handleAdjust(event) {
if (!this.data.canManage) {
wx.showToast({
title: '当前账号没有库存调整权限',
icon: 'none'
})
return
}
const item = event.currentTarget.dataset.item
if (!item) {
return
}
const value = await this.promptAdjust(item)
if (value === null) {
return
}
const quantity = Number(value)
if (!isFinite(quantity) || quantity === 0) {
wx.showToast({
title: '请输入非 0 数量',
icon: 'none'
})
return
}
try {
await inventoryApi.adjustStock(item.id, {
changeType: quantity > 0 ? 'IN' : 'OUT',
changeQuantity: quantity,
remark: '管理端小程序调整'
})
markDirty('admin-workbench')
wx.showToast({
title: '库存已调整',
icon: 'none'
})
this.loadItems()
} catch (error) {
wx.showToast({
title: error.message || '库存调整失败',
icon: 'none'
})
}
},
handleBack() {
navigation.goBack('/pages/manage/index')
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,58 @@
<navigation-bar title="库存管理" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">Inventory</text>
<text class="hero-title">耗材库存</text>
<text class="hero-desc">查看库存和预警项,支持手机端快速新增物料与正负数调整库存。</text>
</view>
<view wx:if="{{canManage}}" class="surface-card">
<text class="section-title">新增物料</text>
<view class="form-grid">
<input class="field-input" placeholder="物料名称" placeholder-class="placeholder" value="{{form.itemName}}" data-field="itemName" bindinput="handleFormInput"></input>
<input class="field-input" placeholder="分类" placeholder-class="placeholder" value="{{form.category}}" data-field="category" bindinput="handleFormInput"></input>
<input class="field-input" placeholder="单位" placeholder-class="placeholder" value="{{form.unit}}" data-field="unit" bindinput="handleFormInput"></input>
<input class="field-input" type="digit" placeholder="初始库存" placeholder-class="placeholder" value="{{form.stockQuantity}}" data-field="stockQuantity" bindinput="handleFormInput"></input>
<input class="field-input" type="digit" placeholder="预警阈值" placeholder-class="placeholder" value="{{form.warningThreshold}}" data-field="warningThreshold" bindinput="handleFormInput"></input>
</view>
<button class="primary-btn compact-btn" loading="{{loading}}" bindtap="handleSaveItem">保存物料</button>
</view>
<view class="surface-card">
<text class="section-title">库存列表</text>
<text class="section-desc">共 {{total}} 个物料,低于阈值会标记为预警。</text>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.itemName}}</text>
<text class="list-subtitle">{{item.category || '未分类'}} · {{item.statusText}}</text>
</view>
<text class="{{item.warning ? 'danger-badge' : 'success-badge'}}">{{item.warning ? '库存预警' : '正常'}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">当前库存</text>
<text class="meta-value">{{item.displayStock}} {{item.unit || ''}}</text>
</view>
<view class="meta-item">
<text class="meta-label">预警阈值</text>
<text class="meta-value">{{item.displayWarning}} {{item.unit || ''}}</text>
</view>
</view>
<view wx:if="{{canManage}}" class="list-actions">
<view class="mini-btn primary" data-item="{{item}}" bindtap="handleAdjust">调整库存</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无库存物料</text>
<text class="empty-desc">当前店铺还没有录入耗材库存。</text>
</view>
</view>
</view>
@@ -0,0 +1,15 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14rpx;
margin-top: 18rpx;
}
.compact-btn {
margin-top: 18rpx;
}
@@ -0,0 +1,447 @@
/**
* Purpose: authApi supports index.js by holding or executing the auth api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const authApi = require('../../api/auth')
/**
* Purpose: auth supports index.js by holding or executing the auth page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const auth = require('../../utils/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
const { runWithLoading } = require('../../utils/loading')
const sessionSwitch = require('../../../utils/session-switch')
/**
* Purpose: ACCOUNT_REGEX supports index.js by holding or executing the account regex page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const ACCOUNT_REGEX = /[^A-Za-z0-9]/g
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: redirect supports index.js by holding or executing the redirect page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
redirect: '',
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: account supports index.js by holding or executing the account page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
account: '',
/**
* Purpose: password supports index.js by holding or executing the password page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
password: '',
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: ''
},
/**
* Purpose: loginShops supports index.js by holding or executing the login shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopMessage: '',
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusText: '',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusType: '',
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false
},
/**
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLoad(options) {
this._lookupTicket = 0
this.setData({
/**
* Purpose: redirect supports index.js by holding or executing the redirect page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
redirect: options && options.redirect ? options.redirect : ''
})
if (auth.isLoggedIn()) {
navigation.redirectAfterLogin(this.data.redirect).catch(() => undefined)
}
},
/**
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onUnload() {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
}
},
/**
* Purpose: handleInputChange supports index.js by holding or executing the handle input change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleInputChange(event) {
const field = event.currentTarget.dataset.field
let value = event.detail.value
if (field === 'account') {
value = String(value || '').replace(ACCOUNT_REGEX, '')
this.resetAccountState()
if (value) {
this.scheduleAccountLookup(value)
}
}
this.setData({
[`form.${field}`]: value
})
},
/**
* Purpose: handleShopChange supports index.js by holding or executing the handle shop change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleShopChange(event) {
const index = Number(event.detail.value)
const shop = this.data.loginShops[index]
this.setData({
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopIndex: index,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopDisplayName: shop ? shop.shopName || '' : '',
'form.shopId': shop ? shop.id : ''
})
},
/**
* Purpose: resetAccountState supports index.js by holding or executing the reset account state page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
resetAccountState() {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
}
this._lookupTicket += 1
this.setData({
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusText: '',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusType: '',
/**
* Purpose: loginShops supports index.js by holding or executing the login shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopMessage: '',
'form.shopId': ''
})
},
/**
* Purpose: scheduleAccountLookup supports index.js by holding or executing the schedule account lookup page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
scheduleAccountLookup(account) {
if (this._accountTimer) {
clearTimeout(this._accountTimer)
}
const ticket = this._lookupTicket + 1
this._lookupTicket = ticket
this._accountTimer = setTimeout(() => {
this.loadLoginShops(account, ticket)
}, 420)
},
/**
* Purpose: applyLoginShopSelection supports index.js by holding or executing the apply login shop selection page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
applyLoginShopSelection(selection) {
const shops = Array.isArray(selection && selection.shops) ? selection.shops : []
const allowShoplessLogin = Boolean(selection && selection.allowShoplessLogin)
let loginShopIndex = -1
let loginShopDisplayName = ''
let shopId = ''
if (!allowShoplessLogin && shops.length === 1) {
loginShopIndex = 0
loginShopDisplayName = shops[0].shopName || ''
shopId = shops[0].id
}
this.setData({
/**
* Purpose: loginShops supports index.js by holding or executing the login shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShops: shops,
allowShoplessLogin,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopMessage: (selection && selection.message) || '',
loginShopIndex,
loginShopDisplayName,
'form.shopId': shopId,
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusText: shops.length || allowShoplessLogin ? '该账号可用于后台登录' : '当前账号暂时不可用于后台登录',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusType: shops.length || allowShoplessLogin ? 'success' : 'warning'
})
},
async loadLoginShops(account, ticket) {
if (!account) {
this.resetAccountState()
return
}
try {
const result = await authApi.getLoginShops(account)
if (ticket !== this._lookupTicket || this.data.form.account !== account) {
return
}
this.applyLoginShopSelection(result)
} catch (error) {
if (ticket !== this._lookupTicket || this.data.form.account !== account) {
return
}
this.setData({
/**
* Purpose: loginShops supports index.js by holding or executing the login shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShops: [],
/**
* Purpose: loginShopIndex supports index.js by holding or executing the login shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopIndex: -1,
/**
* Purpose: loginShopDisplayName supports index.js by holding or executing the login shop display name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopDisplayName: '',
/**
* Purpose: allowShoplessLogin supports index.js by holding or executing the allow shopless login page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
allowShoplessLogin: false,
/**
* Purpose: loginShopMessage supports index.js by holding or executing the login shop message page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loginShopMessage: '',
'form.shopId': '',
/**
* Purpose: accountStatusText supports index.js by holding or executing the account status text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusText: error.message || '该后台账号不存在或不可登录',
/**
* Purpose: accountStatusType supports index.js by holding or executing the account status type page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
accountStatusType: 'error'
})
}
},
/**
* Purpose: validateForm supports index.js by holding or executing the validate form page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
validateForm() {
const form = this.data.form
if (!form.account) {
return '请输入后台账号'
}
if (!form.password) {
return '请输入登录密码'
}
if (!this.data.allowShoplessLogin && this.data.loginShops.length && !form.shopId) {
return '请选择登录店铺'
}
return ''
},
async handleSubmit() {
const errorMessage = this.validateForm()
if (errorMessage) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: errorMessage,
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: true
})
try {
const payload = await runWithLoading(() => authApi.login({
/**
* Purpose: account supports index.js by holding or executing the account page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
account: this.data.form.account,
/**
* Purpose: password supports index.js by holding or executing the password page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
password: this.data.form.password,
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: this.data.form.shopId || undefined
}))
await getApp().setAdminSession(payload)
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '登录成功',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
await navigation.redirectAfterLogin(this.data.redirect)
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '登录失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false
})
}
},
handleOpenCustomerHome() {
sessionSwitch.openCustomerHome()
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,47 @@
<navigation-bar title="后台管理" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack login-stack">
<view class="hero-panel">
<text class="hero-kicker">YUMINAIL ADMIN</text>
<text class="hero-title">把日常经营带到手机上</text>
<text class="hero-desc">平台管理员、店长、美甲师共用一套后台能力。首版保持业务能力对齐,交互按移动端重构,不把网页表格硬搬到手机里。</text>
<view class="badge-row">
<text class="badge">平台管理员</text>
<text class="soft-badge">店长</text>
<text class="soft-badge">美甲师</text>
</view>
</view>
<view class="surface-card">
<text class="section-title">账号密码登录</text>
<text class="section-desc">输入后台账号后,会自动识别登录范围。平台管理员可直接进入总览,也可选择本次登录店铺。</text>
<view class="field-group">
<text class="field-label">后台账号</text>
<input class="field-input" placeholder="仅支持字母和数字" placeholder-class="placeholder" value="{{form.account}}" data-field="account" bindinput="handleInputChange"></input>
<text wx:if="{{accountStatusText}}" class="status-text {{accountStatusType}}">{{accountStatusText}}</text>
</view>
<view class="field-group">
<text class="field-label">登录密码</text>
<input class="field-input" password placeholder="请输入后台密码" placeholder-class="placeholder" value="{{form.password}}" data-field="password" bindinput="handleInputChange"></input>
</view>
<view wx:if="{{loginShops.length}}" class="field-group">
<text class="field-label">登录店铺</text>
<picker mode="selector" range="{{loginShops}}" range-key="shopName" value="{{loginShopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{loginShopDisplayName || '请选择本次登录店铺'}}</view>
</picker>
</view>
<view wx:if="{{allowShoplessLogin || loginShopMessage}}" class="hint-card">{{loginShopMessage || '平台管理员可直接进入总览,也可选择本次登录店铺。'}}</view>
<view class="action-row">
<button class="primary-btn" loading="{{loading}}" disabled="{{loading}}" bindtap="handleSubmit">进入管理台</button>
</view>
</view>
<view class="customer-switch-link" bindtap="handleOpenCustomerHome">返回前台</view>
</view>
</view>
@@ -0,0 +1,14 @@
@import "../../app.wxss";
.login-stack {
padding-top: 40rpx;
}
.customer-switch-link {
display: flex;
align-items: center;
justify-content: center;
min-height: 72rpx;
color: #f7dba7;
font-size: 26rpx;
font-weight: 700;
}
@@ -0,0 +1,100 @@
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: permission supports index.js by holding or executing the permission page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const permission = require('../../utils/permission')
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: userInfo supports index.js by holding or executing the user info page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userInfo: null,
/**
* Purpose: currentShop supports index.js by holding or executing the current shop page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentShop: null,
/**
* Purpose: modules supports index.js by holding or executing the modules page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
modules: []
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
if (!navigation.ensureLogin('进入经营模块')) {
return
}
const app = getApp()
const userInfo = app.globalData.userInfo
const currentShop = app.globalData.currentShop
const permissionCodes = app.globalData.permissionCodes || []
this.setData({
userInfo,
currentShop,
/**
* Purpose: modules supports index.js by holding or executing the modules page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
modules: permission.getManageModules(userInfo, permissionCodes, currentShop)
})
},
handleOpenWorkbench() {
navigation.switchTab('/pages/workbench/index').catch(() => undefined)
},
handleOpenOrders() {
navigation.switchTab('/pages/orders/index').catch(() => undefined)
},
handleOpenProfile() {
navigation.switchTab('/pages/profile/index').catch(() => undefined)
},
/**
* Purpose: handleOpenModule supports index.js by holding or executing the handle open module page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleOpenModule(event) {
const module = event.currentTarget.dataset.module
if (!module) {
return
}
if (!module.allowed) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: module.disabledReason || '当前账号没有进入该模块的权限',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
navigation.navigate(module.path).catch(() => undefined)
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,32 @@
<navigation-bar title="经营" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">按权限展示</text>
<text class="hero-title">{{currentShop ? currentShop.shopName : '平台级入口'}}</text>
<text class="hero-desc">这里不复刻网页后台的大表格首页,而是把可用模块拆成移动端更好点到的入口卡片。</text>
</view>
<view wx:if="{{!currentShop && userInfo && userInfo.type === 4}}" class="hint-card">当前是平台总览模式。用户、作品、订单、优惠券、标签、美甲师等店铺业务可以查看,编辑操作由服务端关闭。</view>
<block wx:for="{{modules}}" wx:key="key">
<view class="list-card" data-module="{{item}}" bindtap="handleOpenModule">
<view class="list-head">
<view>
<text class="list-title">{{item.title}}</text>
<text class="list-subtitle">{{item.description}}</text>
</view>
<text class="{{item.allowed ? 'badge' : 'soft-badge'}}">{{item.readonly ? '仅查看' : (item.allowed ? '可进入' : '待解锁')}}</text>
</view>
<view wx:if="{{!item.allowed}}" class="hint-card">{{item.disabledReason}}</view>
</view>
</block>
<view class="admin-bottom-nav">
<view class="admin-bottom-link" bindtap="handleOpenWorkbench">工作台</view>
<view class="admin-bottom-link" bindtap="handleOpenOrders">订单</view>
<view class="admin-bottom-link active">经营</view>
<view class="admin-bottom-link" bindtap="handleOpenProfile">我的</view>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,199 @@
/**
* Purpose: orderApi loads full backend order detail so direct entry and message navigation can render complete data.
* Usage: call getOrderDetail with the current route id before displaying the order detail page.
*/
const orderApi = require('../../api/order')
const paymentApi = require('../../api/payment')
const permission = require('../../utils/permission')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: format supports index.js by holding or executing the format page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const format = require('../../utils/format')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
const { markDirty } = require('../../utils/page-state')
function getPaymentStatusText(status) {
if (status === 'PAID') {
return '已支付'
}
if (status === 'PAYING') {
return '支付中'
}
if (status === 'REFUNDED') {
return '已退款'
}
return '未支付'
}
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: loading marks whether the detail endpoint is currently fetching order data.
* Usage: bind it to loading and retry states while preserving any cached order shown on screen.
*/
loading: false,
/**
* Purpose: orderId keeps the backend order id used by reload and direct-entry flows.
* Usage: set it from route options or cached list data before calling loadOrderDetail.
*/
orderId: '',
/**
* Purpose: order supports index.js by holding or executing the order page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
order: null,
canManualConfirmPay: false
},
/**
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLoad(options) {
const permissionCodes = getApp().globalData.permissionCodes || []
const cachedOrder = getTempRecord('currentOrder', null)
const orderId = (options && options.id) || (cachedOrder && cachedOrder.id) || ''
this.setData({
orderId,
order: cachedOrder ? this.formatOrder(cachedOrder) : null,
canManualConfirmPay: permission.hasPermission(permissionCodes, 'payment:manage')
})
if (orderId) {
this.loadOrderDetail(orderId)
}
},
/**
* Purpose: loadOrderDetail replaces list-row summary data with the authoritative admin order-detail response.
* Usage: call it from onLoad and retry buttons with the backend order id; failures leave cached data visible.
*/
async loadOrderDetail(orderId) {
this.setData({ loading: true })
try {
const detail = await orderApi.getOrderDetail(orderId)
this.setData({
order: this.formatOrder(detail)
})
} catch (error) {
wx.showToast({
title: error.message || '订单详情加载失败',
icon: 'none'
})
} finally {
this.setData({ loading: false })
}
},
/**
* Purpose: formatOrder prepares order and item fields for WXML, including review and change-request summaries.
* Usage: run every cached or fetched order object through this method before assigning it to data.order.
*/
formatOrder(order) {
const items = Array.isArray(order && order.items) ? order.items : []
const paymentStatus = order && order.paymentStatus ? order.paymentStatus : 'UNPAID'
return order ? {
...order,
displayStatusText: format.getOrderStatusText(order),
displayPaymentStatusText: getPaymentStatusText(paymentStatus),
displayCreateTime: format.formatDateTime(order.createTime),
displayPayAmount: format.formatPrice(order.payAmount || order.actualAmount),
displayPaidAmount: format.formatPrice(order.paidAmount),
displayPayTime: format.formatDateTime(order.payTime),
canManualConfirmPay: paymentStatus !== 'PAID' && paymentStatus !== 'REFUNDED',
items: items.map(item => ({
...item,
displayAppointmentTime: item.appointmentTime ? format.formatDateTime(item.appointmentTime) : '',
reviewStatusText: item.reviewStatusText || (item.reviewSummary ? '已评价' : '待评价'),
changeStatusText: item.pendingArtistChangeRequest ? item.pendingArtistChangeRequest.displayText : ''
}))
} : null
},
/**
* Purpose: handleRetry reloads backend detail when direct entry failed or no cached data exists.
* Usage: bind it to the empty state action so operators can recover without returning to the list.
*/
handleRetry() {
if (!this.data.orderId) {
navigation.goBack('/pages/orders/index')
return
}
this.loadOrderDetail(this.data.orderId)
},
async handleManualConfirmPay() {
if (!this.data.canManualConfirmPay) {
wx.showToast({
title: '当前账号没有确认支付权限',
icon: 'none'
})
return
}
const order = this.data.order
if (!order) {
return
}
const remark = await new Promise(resolve => {
wx.showModal({
title: '手动确认支付',
content: `确认将订单 ${order.orderNo || order.id} 标记为已支付?`,
editable: true,
placeholderText: '备注,可留空',
confirmText: '确认',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
if (remark === null) {
return
}
try {
await paymentApi.manualConfirmOrder(order.id, remark)
markDirty('admin-orders')
markDirty('admin-workbench')
wx.showToast({
title: '支付已确认',
icon: 'none'
})
this.loadOrderDetail(order.id)
} catch (error) {
wx.showToast({
title: error.message || '确认支付失败',
icon: 'none'
})
}
},
/**
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onUnload() {
clearTempRecord('currentOrder')
},
/**
* Purpose: handleBack supports index.js by holding or executing the handle back page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleBack() {
navigation.goBack('/pages/orders/index')
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,77 @@
<navigation-bar title="订单详情" back="{{true}}" bindback="handleBack" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view wx:if="{{order}}" class="surface-card">
<text class="section-title">{{order.orderNo}}</text>
<text class="section-desc">{{order.displayStatusText}} · {{order.displayCreateTime}}</text>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">用户昵称</text>
<text class="meta-value">{{order.customerNickname || order.userNickname || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">脱敏手机号</text>
<text class="meta-value">{{order.customerPhoneMasked || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">所属店铺</text>
<text class="meta-value">{{order.shopName || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">美甲师</text>
<text class="meta-value">{{order.artistName || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">应付金额</text>
<text class="meta-value">¥{{order.displayPayAmount || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">支付状态</text>
<text class="meta-value">{{order.displayPaymentStatusText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">已付金额</text>
<text class="meta-value">¥{{order.displayPaidAmount}}</text>
</view>
<view class="meta-item">
<text class="meta-label">支付时间</text>
<text class="meta-value">{{order.displayPayTime || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">备注</text>
<text class="meta-value">{{order.remark || '暂无备注'}}</text>
</view>
</view>
<view wx:if="{{canManualConfirmPay && order.canManualConfirmPay}}" class="action-row">
<button class="primary-btn" loading="{{loading}}" bindtap="handleManualConfirmPay">手动确认支付</button>
</view>
</view>
<view wx:if="{{order && order.items && order.items.length}}" class="surface-card">
<text class="section-title">服务项目</text>
<block wx:for="{{order.items}}" wx:key="id">
<view class="detail-item">
<view class="detail-item-head">
<text class="detail-item-title">{{item.productTitle || '订单项目'}}</text>
<text class="badge">{{item.reviewStatusText}}</text>
</view>
<text class="detail-item-line">美甲师:{{item.artistName || '--'}}</text>
<text wx:if="{{item.displayAppointmentTime}}" class="detail-item-line">预约时间:{{item.displayAppointmentTime}}</text>
<text wx:if="{{item.reviewSummary && item.reviewSummary.contentText}}" class="detail-item-line">评价内容:{{item.reviewSummary.contentText}}</text>
<view wx:if="{{item.pendingArtistChangeRequest}}" class="change-box">
<text class="change-title">改派申请</text>
<text class="change-line">{{item.pendingArtistChangeRequest.displayText}}</text>
<text wx:if="{{item.pendingArtistChangeRequest.reasonText}}" class="change-line">原因:{{item.pendingArtistChangeRequest.reasonText}}</text>
</view>
</view>
</block>
</view>
<view wx:if="{{!order}}" class="empty-state">
<text class="empty-title">订单详情暂不可用</text>
<text class="empty-desc">当前详情页可通过列表、消息或订单 id 打开;加载失败时可重试。</text>
<button class="primary-btn" loading="{{loading}}" bindtap="handleRetry">重新加载</button>
</view>
</view>
</view>
@@ -0,0 +1,56 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.detail-item {
display: flex;
flex-direction: column;
gap: 12rpx;
padding: 20rpx 0;
border-top: 1rpx solid rgba(255, 255, 255, 0.08);
}
.detail-item:first-of-type {
border-top: 0;
}
.detail-item-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16rpx;
}
.detail-item-title {
color: #f6efe7;
font-size: 30rpx;
font-weight: 700;
}
.detail-item-line {
color: #9fb3ad;
font-size: 24rpx;
line-height: 1.6;
}
.change-box {
display: flex;
flex-direction: column;
gap: 8rpx;
padding: 16rpx;
border-radius: 8rpx;
background: rgba(240, 126, 87, 0.1);
}
.change-title {
color: #f6efe7;
font-size: 24rpx;
font-weight: 700;
}
.change-line {
color: #f4c7b8;
font-size: 24rpx;
line-height: 1.5;
}
@@ -0,0 +1,753 @@
/**
* Purpose: orderApi supports index.js by holding or executing the order api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const orderApi = require('../../api/order')
const paymentApi = require('../../api/payment')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: permission supports index.js by holding or executing the permission page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const permission = require('../../utils/permission')
/**
* Purpose: format supports index.js by holding or executing the format page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const format = require('../../utils/format')
const { setTempRecord } = require('../../utils/storage')
const { consumeDirty, markDirty } = require('../../utils/page-state')
/**
* Purpose: STATUS_OPTIONS supports index.js by holding or executing the status options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const STATUS_OPTIONS = [
{ label: '全部', value: '' },
{ label: '待服务', value: 1 },
{ label: '已完成', value: 2 },
{ label: '已取消', value: 0 }
]
/**
* Purpose: toId supports index.js by holding or executing the to id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function toId(value) {
return value === undefined || value === null ? '' : String(value)
}
/**
* Purpose: sameId supports index.js by holding or executing the same id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function sameId(left, right) {
const leftId = toId(left)
const rightId = toId(right)
return leftId !== '' && leftId === rightId
}
/**
* Purpose: safeList supports index.js by holding or executing the safe list page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function safeList(value) {
return Array.isArray(value) ? value : []
}
/**
* Purpose: trimText supports index.js by holding or executing the trim text page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function trimText(value) {
return String(value || '').trim()
}
/**
* Purpose: formatRating supports index.js by holding or executing the format rating page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function formatRating(value) {
const rating = Number(value)
if (!isFinite(rating) || rating <= 0) {
return ''
}
return rating % 1 === 0 ? String(rating) : rating.toFixed(1)
}
function getPaymentStatusText(status) {
if (status === 'PAID') {
return '已支付'
}
if (status === 'PAYING') {
return '支付中'
}
if (status === 'REFUNDED') {
return '已退款'
}
return '未支付'
}
/**
* Purpose: isSubmittedReview supports index.js by holding or executing the is submitted review page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function isSubmittedReview(review) {
if (!review) {
return false
}
if (Number(review.status) === 1) {
return true
}
return Boolean(review.rating)
}
/**
* Purpose: resolveRelatedRecord supports index.js by holding or executing the resolve related record page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function resolveRelatedRecord(source, orderItemId) {
if (Array.isArray(source)) {
return source.find(item => sameId(item && item.orderItemId, orderItemId)) || null
}
if (source && typeof source === 'object') {
if (!source.orderItemId || sameId(source.orderItemId, orderItemId)) {
return source
}
}
return null
}
/**
* Purpose: buildReviewSummary supports index.js by holding or executing the build review summary page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildReviewSummary(review) {
if (!review || !isSubmittedReview(review)) {
return null
}
const ratingText = formatRating(review.rating)
return {
...review,
ratingText,
contentText: trimText(review.content),
displayText: ratingText ? `已评价:${ratingText} 分` : (review.statusText || '已评价')
}
}
/**
* Purpose: buildArtistChangeSummary supports index.js by holding or executing the build artist change summary page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildArtistChangeSummary(request) {
if (!request) {
return null
}
const originalName = request.originalArtistName || '原美甲师'
const requestedName = request.requestedArtistName || '新美甲师'
return {
...request,
displayText: `${originalName} → ${requestedName}`,
reasonText: trimText(request.reason)
}
}
/**
* Purpose: indexByOrderItemId supports index.js by holding or executing the index by order item id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function indexByOrderItemId(list) {
return safeList(list).reduce((result, item) => {
if (item && item.orderItemId) {
result[toId(item.orderItemId)] = item
}
return result
}, {})
}
/**
* Purpose: safeCall supports index.js by holding or executing the safe call page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
async function safeCall(factory, fallbackValue) {
try {
const result = await factory()
return result === undefined || result === null ? fallbackValue : result
} catch (error) {
return fallbackValue
}
}
/**
* Purpose: loadAssistData supports index.js by holding or executing the load assist data page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
async function loadAssistData(orders) {
const pendingChangesPromise = safeCall(() => orderApi.listMyPendingArtistChangeRequests(), [])
const orderReviewListsPromise = Promise.all(orders.map(order => (
safeCall(() => orderApi.listOrderReviews(order.id), [])
)))
const [pendingChanges, orderReviewLists] = await Promise.all([
pendingChangesPromise,
orderReviewListsPromise
])
const submittedReviews = []
safeList(orderReviewLists).forEach(list => {
safeList(list).forEach(review => {
if (isSubmittedReview(review)) {
submittedReviews.push(review)
}
})
})
return {
pendingChangeByItemId: indexByOrderItemId(pendingChanges),
submittedReviewByItemId: indexByOrderItemId(submittedReviews)
}
}
/**
* Purpose: hasProductionFlag supports index.js by holding or executing the has production flag page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function hasProductionFlag(userInfo) {
const sources = [
userInfo && userInfo.participateProduction,
userInfo && userInfo.participateProductionFlag,
userInfo && userInfo.artistParticipateProduction,
userInfo && userInfo.nailArtistInfo && userInfo.nailArtistInfo.participateProduction,
userInfo && userInfo.artistInfo && userInfo.artistInfo.participateProduction
]
return sources.some(value => value === true || Number(value) === 1)
}
/**
* Purpose: canRequestArtistChangeForItem supports index.js by holding or executing the can request artist change for item page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function canRequestArtistChangeForItem(userInfo, order, item, pendingChange) {
if (!userInfo || !order || !item || pendingChange || Number(order.status) !== 1) {
return false
}
if (permission.isNailArtist(userInfo)) {
return !item.artistId || sameId(item.artistId, userInfo.id)
}
if (sameId(item.artistId, userInfo.id)) {
return true
}
return permission.isShopManager(userInfo) && hasProductionFlag(userInfo)
}
/**
* Purpose: formatOrderItem supports index.js by holding or executing the format order item page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function formatOrderItem(order, item, userInfo, assistData) {
const itemId = toId(item.id)
const inlineReviewSummary = resolveRelatedRecord(item.reviewSummary || order.reviewSummary, item.id)
const inlinePendingChange = resolveRelatedRecord(item.pendingArtistChangeRequest || order.pendingArtistChangeRequest, item.id)
const reviewSummary = buildReviewSummary(inlineReviewSummary || assistData.submittedReviewByItemId[itemId])
const pendingArtistChangeRequest = buildArtistChangeSummary(inlinePendingChange || assistData.pendingChangeByItemId[itemId])
return {
...item,
displayPrice: format.formatPrice(item.price),
displayAppointmentTime: format.formatDateTime(item.appointmentTime),
reviewSummary,
reviewStatusText: reviewSummary ? reviewSummary.displayText : '待评价',
pendingArtistChangeRequest,
canRequestArtistChange: canRequestArtistChangeForItem(userInfo, order, item, pendingArtistChangeRequest)
}
}
/**
* Purpose: formatOrder supports index.js by holding or executing the format order page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function formatOrder(order, userInfo, assistData) {
const items = safeList(order.items).map(item => formatOrderItem(order, item, userInfo, assistData))
const orderReviewSummary = buildReviewSummary(order.reviewSummary)
const paymentStatus = order.paymentStatus || 'UNPAID'
return {
...order,
displayStatusText: format.getOrderStatusText(order),
displayPaymentStatusText: getPaymentStatusText(paymentStatus),
displayCreateTime: format.formatDateTime(order.createTime),
displayPayAmount: format.formatPrice(order.payAmount || order.actualAmount),
displayPaidAmount: format.formatPrice(order.paidAmount),
canManualConfirmPay: paymentStatus !== 'PAID' && paymentStatus !== 'REFUNDED',
items,
reviewSummary: orderReviewSummary,
reviewStatusText: orderReviewSummary ? orderReviewSummary.displayText : ''
}
}
/**
* Purpose: selectArtist supports index.js by holding or executing the select artist page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function selectArtist(artists) {
return new Promise(resolve => {
wx.showActionSheet({
itemList: artists.map(item => item.artistName || `美甲师 ${item.artistId}`),
success: result => resolve(artists[result.tapIndex] || null),
fail: () => resolve(null)
})
})
}
/**
* Purpose: promptChangeReason supports index.js by holding or executing the prompt change reason page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function promptChangeReason() {
return new Promise(resolve => {
wx.showModal({
title: '改派原因',
content: '可填写改派原因,留空也可以提交。',
editable: true,
placeholderText: '例如档期冲突、客户沟通调整',
confirmText: '提交',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(trimText(result.content))
},
fail: () => resolve(null)
})
})
}
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: '',
/**
* Purpose: status supports index.js by holding or executing the status page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
status: '',
/**
* Purpose: statusOptions supports index.js by holding or executing the status options page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
statusOptions: STATUS_OPTIONS,
/**
* Purpose: list supports index.js by holding or executing the list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
list: [],
/**
* Purpose: total supports index.js by holding or executing the total page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
total: 0,
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: userInfo supports index.js by holding or executing the user info page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userInfo: null,
canManualConfirmPay: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
if (!navigation.ensureLogin('进入订单管理')) {
return
}
const userInfo = getApp().globalData.userInfo
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
userInfo,
canManualConfirmPay: permission.hasPermission(permissionCodes, 'payment:manage')
})
if (!this.data.initialized || consumeDirty('admin-orders')) {
this.loadOrders()
}
},
async handleManualConfirmPay(event) {
if (!this.data.canManualConfirmPay) {
wx.showToast({
title: '当前账号没有确认支付权限',
icon: 'none'
})
return
}
const order = event.currentTarget.dataset.order
if (!order) {
return
}
const confirmed = await new Promise(resolve => {
wx.showModal({
title: '手动确认支付',
content: `确认将订单 ${order.orderNo || order.id} 标记为已支付?`,
editable: true,
placeholderText: '备注,可留空',
confirmText: '确认',
success: result => {
if (!result.confirm) {
resolve(null)
return
}
resolve(String(result.content || '').trim())
},
fail: () => resolve(null)
})
})
if (confirmed === null) {
return
}
try {
await paymentApi.manualConfirmOrder(order.id, confirmed)
markDirty('admin-workbench')
wx.showToast({
title: '支付已确认',
icon: 'none'
})
this.loadOrders()
} catch (error) {
wx.showToast({
title: error.message || '确认支付失败',
icon: 'none'
})
}
},
/**
* Purpose: onPullDownRefresh supports index.js by holding or executing the on pull down refresh page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onPullDownRefresh() {
this.loadOrders().finally(() => {
wx.stopPullDownRefresh()
})
},
/**
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleKeywordInput(event) {
this.setData({
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: event.detail.value
})
},
/**
* Purpose: handleStatusChange supports index.js by holding or executing the handle status change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleStatusChange(event) {
const status = event.currentTarget.dataset.status
this.setData({
status
})
this.loadOrders()
},
async loadOrders() {
const requestId = (this._loadRequestId || 0) + 1
this._loadRequestId = requestId
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: true
})
try {
const result = await orderApi.listOrders({
/**
* Purpose: page supports index.js by holding or executing the page page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
size: 20,
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: this.data.keyword || undefined,
/**
* Purpose: status supports index.js by holding or executing the status page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
status: this.data.status === '' ? undefined : this.data.status
})
const rawList = safeList(result && result.list)
const assistData = await loadAssistData(rawList)
if (requestId !== this._loadRequestId) {
return
}
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
list: rawList.map(item => formatOrder(item, this.data.userInfo, assistData)),
/**
* Purpose: total supports index.js by holding or executing the total page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
total: Number(result && result.total) || 0,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: true
})
} catch (error) {
if (requestId !== this._loadRequestId) {
return
}
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '订单加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false
})
}
}
},
/**
* Purpose: handleSearch supports index.js by holding or executing the handle search page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleSearch() {
this.loadOrders()
},
handleOpenWorkbench() {
navigation.switchTab('/pages/workbench/index').catch(() => undefined)
},
handleOpenManage() {
navigation.switchTab('/pages/manage/index').catch(() => undefined)
},
handleOpenProfile() {
navigation.switchTab('/pages/profile/index').catch(() => undefined)
},
/**
* Purpose: handleOpenOrder supports index.js by holding or executing the handle open order page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleOpenOrder(event) {
const order = event.currentTarget.dataset.order
if (!order) {
return
}
setTempRecord('currentOrder', order)
navigation.navigate('/pages/order-detail/index', {
/**
* Purpose: id supports index.js by holding or executing the id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
id: order.id
}).catch(() => undefined)
},
async handleRequestArtistChange(event) {
const orderId = event.currentTarget.dataset.orderId
const orderItemId = event.currentTarget.dataset.orderItemId
if (!orderId || !orderItemId) {
return
}
try {
const options = await orderApi.getArtistChangeOptions(orderId, orderItemId)
const artists = safeList(options && options.artists)
if (!artists.length) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '暂无可改派美甲师',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
const targetArtist = await selectArtist(artists)
if (!targetArtist) {
return
}
const reason = await promptChangeReason()
if (reason === null) {
return
}
await orderApi.requestArtistChange({
orderId,
orderItemId,
/**
* Purpose: requestedArtistId supports index.js by holding or executing the requested artist id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
requestedArtistId: targetArtist.artistId,
reason
})
markDirty('admin-workbench')
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '改派申请已提交',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
this.loadOrders()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '改派申请失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
async handleProcessOrder(event) {
const order = event.currentTarget.dataset.order
if (!order) {
return
}
const isArtist = permission.isNailArtist(this.data.userInfo)
const options = isArtist
? [{ label: '标记为已完成', status: 2 }]
: [
{ label: '调整为待服务', status: 1 },
{ label: '标记为已完成', status: 2 },
{ label: '标记为已取消', status: 0 }
]
wx.showActionSheet({
/**
* Purpose: itemList supports index.js by holding or executing the item list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
itemList: options.map(item => item.label),
/**
* Purpose: success supports index.js by holding or executing the success page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
success: async result => {
const target = options[result.tapIndex]
if (!target) {
return
}
try {
await orderApi.updateOrderStatus(order.id, target.status)
markDirty('admin-workbench')
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '订单状态已更新',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
this.loadOrders()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '订单处理失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
}
})
@@ -0,0 +1,6 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
},
"enablePullDownRefresh": true
}
@@ -0,0 +1,95 @@
<navigation-bar title="订单" back="{{false}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="hero-panel">
<text class="hero-kicker">预约履约</text>
<text class="hero-title">按当前角色范围查看订单</text>
<text class="hero-desc">店长和平台管理员看当前权限范围订单,美甲师仅看属于自己的预约单,并只能完成属于自己的订单。</text>
</view>
<view class="surface-card">
<text class="section-title">筛选条件</text>
<view class="search-row">
<input class="field-input search-input" placeholder="输入订单号搜索" placeholder-class="placeholder" value="{{keyword}}" bindinput="handleKeywordInput" confirm-type="search" bindconfirm="handleSearch"></input>
<button class="secondary-btn" bindtap="handleSearch">搜索</button>
</view>
<view class="chip-row">
<block wx:for="{{statusOptions}}" wx:key="label">
<view class="chip-btn {{status === item.value ? 'active' : ''}}" data-status="{{item.value}}" bindtap="handleStatusChange">{{item.label}}</view>
</block>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.orderNo}}</text>
<text class="list-subtitle">{{item.customerNickname || item.userNickname || '未命名用户'}} · {{item.customerPhoneMasked || '--'}}</text>
</view>
<text class="badge">{{item.displayStatusText}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">订单金额</text>
<text class="meta-value">¥{{item.displayPayAmount}}</text>
</view>
<view class="meta-item">
<text class="meta-label">支付状态</text>
<text class="meta-value">{{item.displayPaymentStatusText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">所属门店</text>
<text class="meta-value">{{item.shopName || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">美甲师</text>
<text class="meta-value">{{item.artistName || '--'}}</text>
</view>
<view class="meta-item">
<text class="meta-label">下单时间</text>
<text class="meta-value">{{item.displayCreateTime}}</text>
</view>
</view>
<view wx:if="{{item.items.length}}" class="order-items">
<view wx:for="{{item.items}}" wx:key="id" wx:for-item="orderItem" class="order-item-row">
<view class="order-item-main">
<text class="order-item-title">{{orderItem.productTitle || '订单项目'}}</text>
<text class="order-item-line">美甲师:{{orderItem.artistName || '--'}}</text>
<text wx:if="{{orderItem.displayAppointmentTime}}" class="order-item-line">预约时间:{{orderItem.displayAppointmentTime}}</text>
<text class="order-item-review">{{orderItem.reviewStatusText}}</text>
<text wx:if="{{orderItem.reviewSummary && orderItem.reviewSummary.contentText}}" class="order-item-line">评价内容:{{orderItem.reviewSummary.contentText}}</text>
<view wx:if="{{orderItem.pendingArtistChangeRequest}}" class="change-note">
<text class="change-note-title">改派申请待处理</text>
<text class="change-note-desc">{{orderItem.pendingArtistChangeRequest.displayText}}</text>
<text wx:if="{{orderItem.pendingArtistChangeRequest.reasonText}}" class="change-note-desc">原因:{{orderItem.pendingArtistChangeRequest.reasonText}}</text>
</view>
</view>
<view wx:if="{{orderItem.canRequestArtistChange}}" class="mini-btn soft" data-order-id="{{item.id}}" data-order-item-id="{{orderItem.id}}" bindtap="handleRequestArtistChange">申请改派</view>
</view>
</view>
<view wx:elif="{{item.reviewStatusText}}" class="order-review-line">{{item.reviewStatusText}}</view>
<view class="list-actions">
<view class="mini-btn" data-order="{{item}}" bindtap="handleOpenOrder">查看详情</view>
<view wx:if="{{canManualConfirmPay && item.canManualConfirmPay}}" class="mini-btn primary" data-order="{{item}}" bindtap="handleManualConfirmPay">确认支付</view>
<view wx:if="{{item.status !== 2}}" class="mini-btn primary" data-order="{{item}}" bindtap="handleProcessOrder">处理订单</view>
</view>
</view>
</block>
<view wx:if="{{!list.length && !loading}}" class="empty-state">
<text class="empty-title">暂无订单</text>
<text class="empty-desc">当前筛选条件下没有符合的订单记录,切换状态或清空关键字后再试一次。</text>
</view>
<view class="admin-bottom-nav">
<view class="admin-bottom-link" bindtap="handleOpenWorkbench">工作台</view>
<view class="admin-bottom-link active">订单</view>
<view class="admin-bottom-link" bindtap="handleOpenManage">经营</view>
<view class="admin-bottom-link" bindtap="handleOpenProfile">我的</view>
</view>
</view>
</view>
@@ -0,0 +1,83 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
.order-items {
margin-top: 22rpx;
border-top: 1rpx solid rgba(246, 239, 231, 0.12);
}
.order-item-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 18rpx;
padding: 18rpx 0;
border-bottom: 1rpx solid rgba(246, 239, 231, 0.1);
}
.order-item-row:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.order-item-main {
flex: 1;
min-width: 0;
}
.order-item-title,
.order-item-line,
.order-item-review,
.order-review-line,
.change-note-title,
.change-note-desc {
display: block;
}
.order-item-title {
color: #f6efe7;
font-size: 26rpx;
font-weight: 700;
line-height: 1.5;
}
.order-item-line,
.order-review-line,
.change-note-desc {
margin-top: 8rpx;
color: rgba(246, 239, 231, 0.68);
font-size: 23rpx;
line-height: 1.55;
}
.order-item-review {
margin-top: 10rpx;
color: #f0c987;
font-size: 23rpx;
font-weight: 700;
line-height: 1.5;
}
.change-note {
margin-top: 14rpx;
padding: 16rpx;
border-radius: 14rpx;
background: rgba(240, 201, 135, 0.1);
border: 1rpx solid rgba(240, 201, 135, 0.3);
}
.change-note-title {
color: #f0c987;
font-size: 23rpx;
font-weight: 700;
line-height: 1.5;
}
.mini-btn.soft {
color: #081518;
background: #f0c987;
border-color: #f0c987;
white-space: nowrap;
}
@@ -0,0 +1,333 @@
/**
* Purpose: permissionApi supports index.js by holding or executing the permission api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const permissionApi = require('../../api/permission')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: permissionUtils supports index.js by holding or executing the permission utils page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const permissionUtils = require('../../utils/permission')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
/**
* Purpose: buildPermissionGroups supports index.js by holding or executing the build permission groups page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildPermissionGroups(list, checkedIds, assignableIds) {
const groups = permissionUtils.groupPermissionsByGroup(list)
return Object.keys(groups).map(group => ({
group,
items: groups[group].map(item => ({
...item,
valueId: String(item.id),
checked: checkedIds.includes(String(item.id)),
disabled: assignableIds.length ? !assignableIds.includes(String(item.id)) : false
}))
}))
}
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'definition-create',
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '',
/**
* Purpose: userId supports index.js by holding or executing the user id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userId: '',
/**
* Purpose: currentUser supports index.js by holding or executing the current user page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentUser: null,
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionGroups: [],
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: permissionCode supports index.js by holding or executing the permission code page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionCode: '',
/**
* Purpose: permissionName supports index.js by holding or executing the permission name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionName: '',
/**
* Purpose: permissionGroup supports index.js by holding or executing the permission group page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionGroup: '',
/**
* Purpose: description supports index.js by holding or executing the description page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
description: ''
}
},
/**
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLoad(options) {
const mode = options && options.mode ? options.mode : 'definition-create'
this.setData({
mode,
/**
* Purpose: userId supports index.js by holding or executing the user id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userId: options && options.userId ? options.userId : '',
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: mode === 'assign' ? '分配权限' : (mode === 'definition-edit' ? '编辑权限' : '新增权限')
})
if (mode === 'assign') {
this.loadAssignData()
return
}
const currentPermission = getTempRecord('currentPermission', null)
if (mode === 'definition-edit' && currentPermission) {
this.setData({
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: permissionCode supports index.js by holding or executing the permission code page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionCode: currentPermission.permissionCode || '',
/**
* Purpose: permissionName supports index.js by holding or executing the permission name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionName: currentPermission.permissionName || '',
/**
* Purpose: permissionGroup supports index.js by holding or executing the permission group page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionGroup: currentPermission.permissionGroup || '',
/**
* Purpose: description supports index.js by holding or executing the description page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
description: currentPermission.description || ''
}
})
}
},
/**
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onUnload() {
clearTempRecord('currentPermission')
},
async loadAssignData() {
const currentUser = getTempRecord('currentUser', null)
this.setData({
currentUser
})
try {
const [allPermissions, currentPermissions, assignableIds] = await Promise.all([
permissionApi.listAllPermissions(),
permissionApi.getUserPermissions(this.data.userId),
permissionApi.getAssignablePermissionIds(this.data.userId)
])
const checkedIds = (Array.isArray(currentPermissions) ? currentPermissions : []).map(item => String(item.id))
const normalizedAssignableIds = (Array.isArray(assignableIds) ? assignableIds : []).map(item => String(item))
this.setData({
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionGroups: buildPermissionGroups(allPermissions, checkedIds, normalizedAssignableIds)
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '权限数据加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
/**
* Purpose: handleInputChange supports index.js by holding or executing the handle input change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleInputChange(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`form.${field}`]: event.detail.value
})
},
/**
* Purpose: handlePermissionCheck supports index.js by holding or executing the handle permission check page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handlePermissionCheck(event) {
const selected = event.detail.value || []
this.setData({
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionGroups: this.data.permissionGroups.map(group => ({
...group,
/**
* Purpose: items supports index.js by holding or executing the items page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
items: group.items.map(item => ({
...item,
/**
* Purpose: checked supports index.js by holding or executing the checked page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
checked: item.disabled ? item.checked : selected.includes(item.valueId)
}))
}))
})
},
async handleSubmit() {
if (this.data.mode === 'assign') {
const permissionIds = []
this.data.permissionGroups.forEach(group => {
group.items.forEach(item => {
if (item.checked) {
permissionIds.push(Number(item.id))
}
})
})
try {
await permissionApi.assignUserPermissions(this.data.userId, permissionIds)
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '权限已保存',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
navigation.goBack('/pages/permissions/index')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '权限保存失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
return
}
if (!this.data.form.permissionCode || !this.data.form.permissionName) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '请补全权限编码和名称',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
try {
if (this.data.mode === 'definition-edit') {
const currentPermission = getTempRecord('currentPermission', null)
await permissionApi.updatePermission(currentPermission.id, this.data.form)
} else {
await permissionApi.createPermission(this.data.form)
}
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '权限定义已保存',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
navigation.goBack('/pages/permissions/index')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '保存失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,51 @@
<navigation-bar title="{{title}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view wx:if="{{mode === 'assign'}}" class="surface-card">
<text class="section-title">{{currentUser.nickname || currentUser.account}}</text>
<text class="section-desc">只能勾选当前账号被允许拥有的权限。超出允许范围的权限会直接置灰,避免前端只给出“保存失败”的笼统提示。</text>
<checkbox-group bindchange="handlePermissionCheck">
<block wx:for="{{permissionGroups}}" wx:key="group">
<view class="list-card">
<text class="list-title">{{item.group}}</text>
<view class="checkbox-grid">
<block wx:for="{{item.items}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}} {{item.disabled ? 'disabled' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" disabled="{{item.disabled}}" />
{{item.permissionName}}
</label>
</block>
</view>
</view>
</block>
</checkbox-group>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存权限</button>
</view>
</view>
<view wx:else class="surface-card">
<text class="section-title">权限定义</text>
<view class="field-group">
<text class="field-label">权限编码</text>
<input class="field-input" value="{{form.permissionCode}}" data-field="permissionCode" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">权限名称</text>
<input class="field-input" value="{{form.permissionName}}" data-field="permissionName" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">权限分组</text>
<input class="field-input" value="{{form.permissionGroup}}" data-field="permissionGroup" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">描述</text>
<textarea class="field-textarea" value="{{form.description}}" data-field="description" bindinput="handleInputChange"></textarea>
</view>
<view class="action-row">
<button class="primary-btn" bindtap="handleSubmit">保存权限定义</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
@@ -0,0 +1,181 @@
/**
* Purpose: permissionApi supports index.js by holding or executing the permission api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const permissionApi = require('../../api/permission')
/**
* Purpose: userApi supports index.js by holding or executing the user api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userApi = require('../../api/user')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
/**
* Purpose: groupPermissions supports index.js by holding or executing the group permissions page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function groupPermissions(list) {
const map = {}
;(Array.isArray(list) ? list : []).forEach(item => {
const group = item.permissionGroup || '未分组'
if (!map[group]) {
map[group] = []
}
map[group].push(item)
})
return Object.keys(map).map(group => ({
group,
items: map[group]
}))
}
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionGroups: [],
/**
* Purpose: users supports index.js by holding or executing the users page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
users: [],
/**
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canCreate: false,
/**
* Purpose: canAssign supports index.js by holding or executing the can assign page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canAssign: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
if (!navigation.ensureLogin('进入权限管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canCreate: permissionCodes.includes('permission:create'),
/**
* Purpose: canAssign supports index.js by holding or executing the can assign page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canAssign: permissionCodes.includes('permission:assign')
})
this.loadPageData()
},
async loadPageData() {
try {
const [permissions, users] = await Promise.all([
permissionApi.listAllPermissions(),
userApi.listAllUsers().catch(() => [])
])
this.setData({
/**
* Purpose: permissionGroups supports index.js by holding or executing the permission groups page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionGroups: groupPermissions(permissions),
/**
* Purpose: users supports index.js by holding or executing the users page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
users: Array.isArray(users) ? users : []
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '权限数据加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
/**
* Purpose: handleCreatePermission supports index.js by holding or executing the handle create permission page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleCreatePermission() {
clearTempRecord('currentPermission')
navigation.navigate('/pages/permission-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'definition-create'
}).catch(() => undefined)
},
/**
* Purpose: handleEditPermission supports index.js by holding or executing the handle edit permission page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleEditPermission(event) {
const permission = event.currentTarget.dataset.permission
setTempRecord('currentPermission', permission)
navigation.navigate('/pages/permission-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'definition-edit',
/**
* Purpose: id supports index.js by holding or executing the id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
id: permission.id
}).catch(() => undefined)
},
/**
* Purpose: handleAssignUser supports index.js by holding or executing the handle assign user page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleAssignUser(event) {
const user = event.currentTarget.dataset.user
setTempRecord('currentUser', user)
navigation.navigate('/pages/permission-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'assign',
/**
* Purpose: userId supports index.js by holding or executing the user id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userId: user.id
}).catch(() => undefined)
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,50 @@
<navigation-bar title="权限管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">用户授权</text>
<text class="section-desc">移动端不再铺宽表格,先选用户,再进入分组权限页勾选保存。服务端会继续兜底拦截超范围授权。</text>
<block wx:for="{{users}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.nickname || item.account}}</text>
<text class="list-subtitle">{{item.account}} · {{item.shopName || '多店铺账号'}}</text>
</view>
<text class="soft-badge">{{item.type === 4 ? '管理员' : item.type === 2 ? '店长' : item.type === 3 ? '美甲师' : '用户'}}</text>
</view>
<view class="list-actions">
<view wx:if="{{canAssign}}" class="mini-btn primary" data-user="{{item}}" bindtap="handleAssignUser">配置权限</view>
</view>
</view>
</block>
</view>
<view class="surface-card">
<view class="list-head">
<view>
<text class="section-title">权限字典</text>
<text class="section-desc">当前代码真实使用的权限定义都集中在这里,便于在手机上快速检查分组和描述是否合理。</text>
</view>
<view wx:if="{{canCreate}}" class="mini-btn primary" bindtap="handleCreatePermission">新增</view>
</view>
<block wx:for="{{permissionGroups}}" wx:key="group">
<view class="list-card">
<text class="list-title">{{item.group}}</text>
<block wx:for="{{item.items}}" wx:key="id">
<view class="divider-line"></view>
<view class="list-head">
<view>
<text class="list-subtitle">{{item.permissionCode}}</text>
<text class="list-title">{{item.permissionName}}</text>
<text class="list-subtitle">{{item.description || '暂无描述'}}</text>
</view>
<view wx:if="{{canCreate}}" class="mini-btn" data-permission="{{item}}" bindtap="handleEditPermission">编辑</view>
</view>
</block>
</view>
</block>
</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,811 @@
/**
* Purpose: productApi supports index.js by holding or executing the product api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const productApi = require('../../api/product')
/**
* Purpose: tagApi supports index.js by holding or executing the tag api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const tagApi = require('../../api/tag')
/**
* Purpose: userApi supports index.js by holding or executing the user api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const userApi = require('../../api/user')
/**
* Purpose: couponApi supports index.js by holding or executing the coupon api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const couponApi = require('../../api/coupon')
/**
* Purpose: shopApi supports index.js by holding or executing the shop api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const shopApi = require('../../api/shop')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: format supports index.js by holding or executing the format page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const format = require('../../utils/format')
/**
* Purpose: cache supports index.js by holding or executing the cache page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const cache = require('../../utils/cache')
/**
* Purpose: upload supports index.js by holding or executing the upload page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const upload = require('../../utils/upload')
const { getTempRecord, clearTempRecord } = require('../../utils/storage')
const { getDraftValue, clearDraft, scheduleDraftSave, clearDraftTimer } = require('../../utils/form-draft')
const { markDirty } = require('../../utils/page-state')
const { CACHE_TTL } = require('../../utils/config')
/**
* Purpose: DRAFT_KEY supports index.js by holding or executing the draft key page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const DRAFT_KEY = 'admin-product-form'
/**
* Purpose: normalizeId supports index.js by holding or executing the normalize id page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function normalizeId(value) {
return value === undefined || value === null ? '' : String(value)
}
/**
* Purpose: buildCheckableList supports index.js by holding or executing the build checkable list page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function buildCheckableList(list, selectedIds, labelKey) {
return (Array.isArray(list) ? list : []).map(item => ({
...item,
valueId: normalizeId(item.id),
labelText: item[labelKey],
checked: selectedIds.includes(normalizeId(item.id))
}))
}
/**
* Purpose: syncSelectedIds supports index.js by holding or executing the sync selected ids page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function syncSelectedIds(selectedIds, list) {
const availableIds = new Set((Array.isArray(list) ? list : []).map(item => normalizeId(item.id)))
return (Array.isArray(selectedIds) ? selectedIds : []).filter(id => availableIds.has(normalizeId(id)))
}
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'create',
/**
* Purpose: productId supports index.js by holding or executing the product id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
productId: '',
/**
* Purpose: shops supports index.js by holding or executing the shops page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shops: [],
/**
* Purpose: shopIndex supports index.js by holding or executing the shop index page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopIndex: 0,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: '',
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: [],
/**
* Purpose: artists supports index.js by holding or executing the artists page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
artists: [],
/**
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
coupons: [],
/**
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploading: false,
/**
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploadProgress: 0,
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '',
/**
* Purpose: description supports index.js by holding or executing the description page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
description: '',
/**
* Purpose: targetAudience records who or which scene this product is suitable for.
* Usage: edit it in the product form and submit it with create/update payloads.
*/
targetAudience: '',
/**
* Purpose: precautions records service reminders for this product.
* Usage: edit it in the product form and submit it with create/update payloads.
*/
precautions: '',
/**
* Purpose: price supports index.js by holding or executing the price page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
price: '',
/**
* Purpose: approximateDuration supports index.js by holding or executing the approximate duration page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
approximateDuration: '',
/**
* Purpose: likeCount supports index.js by holding or executing the like count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
likeCount: '',
/**
* Purpose: collectCount supports index.js by holding or executing the collect count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
collectCount: '',
/**
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
imageFileIds: [],
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: ''
}
},
/**
* Purpose: onLoad supports index.js by holding or executing the on load page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onLoad(options) {
const mode = options && options.mode ? options.mode : 'create'
const currentProduct = getTempRecord('currentProduct', null)
const draft = getDraftValue(DRAFT_KEY, null)
this.setData({
mode,
/**
* Purpose: productId supports index.js by holding or executing the product id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
productId: options && options.id ? options.id : ''
})
this._selectedTagIds = []
this._selectedArtistIds = []
this._selectedCouponIds = []
if (mode === 'edit' && currentProduct) {
this._selectedTagIds = format.splitCsv(currentProduct.tags)
this._selectedArtistIds = format.splitCsv(currentProduct.bookableArtists)
this._selectedCouponIds = format.splitCsv(currentProduct.availableCoupons)
this._initialShopId = currentProduct.shopId
this.setData({
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: currentProduct.title || '',
/**
* Purpose: description supports index.js by holding or executing the description page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
description: currentProduct.description || '',
/**
* Purpose: targetAudience restores the existing product suitable-audience text in edit mode.
* Usage: bind this field to the form textarea and submit it unchanged unless the operator edits it.
*/
targetAudience: currentProduct.targetAudience || '',
/**
* Purpose: precautions restores the existing product reminder text in edit mode.
* Usage: bind this field to the form textarea and submit it unchanged unless the operator edits it.
*/
precautions: currentProduct.precautions || '',
/**
* Purpose: price supports index.js by holding or executing the price page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
price: currentProduct.price || '',
/**
* Purpose: approximateDuration supports index.js by holding or executing the approximate duration page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
approximateDuration: currentProduct.approximateDuration || '',
/**
* Purpose: likeCount supports index.js by holding or executing the like count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
likeCount: currentProduct.likeCount || '',
/**
* Purpose: collectCount supports index.js by holding or executing the collect count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
collectCount: currentProduct.collectCount || '',
/**
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
imageFileIds: format.splitCsv(currentProduct.imageFileIds),
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: currentProduct.shopId || ''
}
})
}
if (draft && draft.mode === mode) {
this._selectedTagIds = Array.isArray(draft.selectedTagIds) ? draft.selectedTagIds : this._selectedTagIds
this._selectedArtistIds = Array.isArray(draft.selectedArtistIds) ? draft.selectedArtistIds : this._selectedArtistIds
this._selectedCouponIds = Array.isArray(draft.selectedCouponIds) ? draft.selectedCouponIds : this._selectedCouponIds
this._initialShopId = draft.form && draft.form.shopId ? draft.form.shopId : this._initialShopId
this.setData({
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
...this.data.form,
...(draft.form || {})
}
})
}
this.loadDependencies()
},
/**
* Purpose: onUnload supports index.js by holding or executing the on unload page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onUnload() {
clearTempRecord('currentProduct')
clearDraftTimer(this)
},
/**
* Purpose: scheduleProductDraft supports index.js by holding or executing the schedule product draft page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
scheduleProductDraft() {
scheduleDraftSave(this, DRAFT_KEY, () => ({
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: this.data.mode,
/**
* Purpose: form supports index.js by holding or executing the form page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
form: {
...this.data.form,
/**
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
imageFileIds: this.data.form.imageFileIds.slice()
},
/**
* Purpose: selectedTagIds supports index.js by holding or executing the selected tag ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
selectedTagIds: this._selectedTagIds.slice(),
/**
* Purpose: selectedArtistIds supports index.js by holding or executing the selected artist ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
selectedArtistIds: this._selectedArtistIds.slice(),
/**
* Purpose: selectedCouponIds supports index.js by holding or executing the selected coupon ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
selectedCouponIds: this._selectedCouponIds.slice()
}))
},
async loadDependencies() {
const app = getApp()
const currentShop = app.globalData.currentShop
const operator = app.globalData.userInfo || {}
try {
const shopList = await cache.remember('admin:shops:all', CACHE_TTL.dict, () => shopApi.listAllShops())
let shops = Array.isArray(shopList) ? shopList : []
if (Number(operator.type) !== 4 && currentShop) {
shops = shops.filter(item => normalizeId(item.id) === normalizeId(currentShop.id))
}
let shopIndex = 0
if (this._initialShopId) {
const index = shops.findIndex(item => normalizeId(item.id) === normalizeId(this._initialShopId))
if (index >= 0) {
shopIndex = index
}
}
const selectedShop = shops[shopIndex]
this.setData({
shops,
shopIndex,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: selectedShop ? selectedShop.shopName : '',
'form.shopId': selectedShop ? selectedShop.id : ''
})
await this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '初始化作品表单失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
async loadShopScopedOptions(shopId) {
if (!normalizeId(shopId)) {
this._selectedTagIds = []
this._selectedArtistIds = []
this._selectedCouponIds = []
this.setData({
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: [],
/**
* Purpose: artists supports index.js by holding or executing the artists page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
artists: [],
/**
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
coupons: []
})
return
}
try {
const [tagList, artistList, couponList] = await Promise.all([
tagApi.listTagsByShopId(shopId),
userApi.listArtists(shopId),
couponApi.listAllCoupons(shopId)
])
this._selectedTagIds = syncSelectedIds(this._selectedTagIds, tagList)
this._selectedArtistIds = syncSelectedIds(this._selectedArtistIds, artistList)
this._selectedCouponIds = syncSelectedIds(this._selectedCouponIds, couponList)
this.setData({
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: buildCheckableList(tagList, this._selectedTagIds, 'tagName'),
/**
* Purpose: artists supports index.js by holding or executing the artists page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
artists: buildCheckableList(artistList, this._selectedArtistIds, 'nickname'),
/**
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
coupons: buildCheckableList(couponList, this._selectedCouponIds, 'couponName')
})
this.scheduleProductDraft()
} catch (error) {
this.setData({
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: [],
/**
* Purpose: artists supports index.js by holding or executing the artists page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
artists: [],
/**
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
coupons: []
})
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '店铺关联数据加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
/**
* Purpose: handleInputChange supports index.js by holding or executing the handle input change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleInputChange(event) {
const field = event.currentTarget.dataset.field
this.setData({
[`form.${field}`]: event.detail.value
})
this.scheduleProductDraft()
},
/**
* Purpose: handleShopChange supports index.js by holding or executing the handle shop change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleShopChange(event) {
const shopIndex = Number(event.detail.value)
const selectedShop = this.data.shops[shopIndex]
this.setData({
shopIndex,
/**
* Purpose: shopLabel supports index.js by holding or executing the shop label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopLabel: selectedShop ? selectedShop.shopName : '',
'form.shopId': selectedShop ? selectedShop.id : ''
})
this.loadShopScopedOptions(selectedShop ? selectedShop.id : '')
this.scheduleProductDraft()
},
/**
* Purpose: handleTagChange supports index.js by holding or executing the handle tag change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleTagChange(event) {
this._selectedTagIds = event.detail.value || []
this.setData({
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: this.data.tags.map(item => ({
...item,
/**
* Purpose: checked supports index.js by holding or executing the checked page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
checked: this._selectedTagIds.includes(item.valueId)
}))
})
this.scheduleProductDraft()
},
/**
* Purpose: handleArtistChange supports index.js by holding or executing the handle artist change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleArtistChange(event) {
this._selectedArtistIds = event.detail.value || []
this.setData({
/**
* Purpose: artists supports index.js by holding or executing the artists page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
artists: this.data.artists.map(item => ({
...item,
/**
* Purpose: checked supports index.js by holding or executing the checked page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
checked: this._selectedArtistIds.includes(item.valueId)
}))
})
this.scheduleProductDraft()
},
/**
* Purpose: handleCouponChange supports index.js by holding or executing the handle coupon change page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleCouponChange(event) {
this._selectedCouponIds = event.detail.value || []
this.setData({
/**
* Purpose: coupons supports index.js by holding or executing the coupons page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
coupons: this.data.coupons.map(item => ({
...item,
/**
* Purpose: checked supports index.js by holding or executing the checked page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
checked: this._selectedCouponIds.includes(item.valueId)
}))
})
this.scheduleProductDraft()
},
async handleUploadImages() {
try {
const files = await upload.chooseImageFiles({ count: 9 })
this.setData({
/**
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploading: true,
/**
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploadProgress: 0
})
const result = await upload.uploadImageFiles({
files,
/**
* Purpose: scene supports index.js by holding or executing the scene page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
scene: 'admin-product-image',
/**
* Purpose: onProgress supports index.js by holding or executing the on progress page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
onProgress: progress => {
this.setData({
/**
* Purpose: uploadProgress supports index.js by holding or executing the upload progress page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploadProgress: Math.round(progress)
})
}
})
this.setData({
'form.imageFileIds': this.data.form.imageFileIds.concat(result.map(item => String(item.id)))
})
this.scheduleProductDraft()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '图片上传失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
this.setData({
/**
* Purpose: uploading supports index.js by holding or executing the uploading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
uploading: false
})
}
},
async handleSubmit() {
if (!this.data.form.title) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '请输入作品标题',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
if (!this.data.form.shopId) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '请选择所属店铺',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
if (!this.data.form.price) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '请输入作品价格',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
const payload = {
/**
* Purpose: shopId supports index.js by holding or executing the shop id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopId: this.data.form.shopId || undefined,
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: this.data.form.title,
/**
* Purpose: description supports index.js by holding or executing the description page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
description: this.data.form.description || undefined,
/**
* Purpose: targetAudience sends the optional suitable-audience text to the backend.
* Usage: leave it undefined when empty so old products can hide the section on user detail pages.
*/
targetAudience: this.data.form.targetAudience || undefined,
/**
* Purpose: precautions sends the optional reminder text to the backend.
* Usage: leave it undefined when empty so old products can hide the section on user detail pages.
*/
precautions: this.data.form.precautions || undefined,
/**
* Purpose: imageFileIds supports index.js by holding or executing the image file ids page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
imageFileIds: this.data.form.imageFileIds.join(',') || undefined,
/**
* Purpose: price supports index.js by holding or executing the price page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
price: Number(this.data.form.price),
/**
* Purpose: tags supports index.js by holding or executing the tags page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
tags: this._selectedTagIds.join(',') || undefined,
/**
* Purpose: likeCount supports index.js by holding or executing the like count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
likeCount: this.data.form.likeCount ? Number(this.data.form.likeCount) : undefined,
/**
* Purpose: collectCount supports index.js by holding or executing the collect count page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
collectCount: this.data.form.collectCount ? Number(this.data.form.collectCount) : undefined,
/**
* Purpose: approximateDuration supports index.js by holding or executing the approximate duration page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
approximateDuration: this.data.form.approximateDuration || undefined,
/**
* Purpose: bookableArtists supports index.js by holding or executing the bookable artists page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
bookableArtists: this._selectedArtistIds.join(',') || undefined,
/**
* Purpose: availableCoupons supports index.js by holding or executing the available coupons page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
availableCoupons: this._selectedCouponIds.join(',') || undefined
}
try {
if (this.data.mode === 'edit') {
await productApi.updateProduct(this.data.productId, payload)
} else {
await productApi.createProduct(payload)
}
clearDraft(DRAFT_KEY)
markDirty('admin-products')
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: this.data.mode === 'edit' ? '作品已更新' : '作品已创建',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
navigation.goBack('/pages/products/index')
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '保存失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,100 @@
<navigation-bar title="{{mode === 'edit' ? '编辑作品' : '新增作品'}}" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">作品信息</text>
<view class="field-group">
<text class="field-label">作品标题</text>
<input class="field-input" value="{{form.title}}" data-field="title" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">所属店铺</text>
<picker mode="selector" range="{{shops}}" range-key="shopName" value="{{shopIndex}}" bindchange="handleShopChange">
<view class="field-picker">{{shopLabel || '请选择店铺'}}</view>
</picker>
</view>
<view class="field-group">
<text class="field-label">作品价格</text>
<input class="field-input" type="digit" value="{{form.price}}" data-field="price" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">大约耗时</text>
<input class="field-input" value="{{form.approximateDuration}}" data-field="approximateDuration" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">作品描述</text>
<textarea class="field-textarea" value="{{form.description}}" data-field="description" bindinput="handleInputChange"></textarea>
</view>
<view class="field-group">
<text class="field-label">适合人群</text>
<textarea class="field-textarea" value="{{form.targetAudience}}" data-field="targetAudience" bindinput="handleInputChange" placeholder="例如:短甲、通勤、婚礼跟妆"></textarea>
</view>
<view class="field-group">
<text class="field-label">注意事项</text>
<textarea class="field-textarea" value="{{form.precautions}}" data-field="precautions" bindinput="handleInputChange" placeholder="例如:完成后 24 小时内避免长时间热水浸泡"></textarea>
</view>
<view class="field-group">
<text class="field-label">点赞数量</text>
<input class="field-input" type="number" value="{{form.likeCount}}" data-field="likeCount" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">收藏数量</text>
<input class="field-input" type="number" value="{{form.collectCount}}" data-field="collectCount" bindinput="handleInputChange"></input>
</view>
<view class="field-group">
<text class="field-label">作品图片</text>
<view class="list-actions">
<view class="mini-btn primary" bindtap="handleUploadImages">上传图片</view>
</view>
<view wx:if="{{form.imageFileIds.length}}" class="image-grid">
<block wx:for="{{form.imageFileIds}}" wx:key="*this">
<view class="image-chip">{{item}}</view>
</block>
</view>
</view>
<view class="field-group">
<text class="field-label">绑定标签</text>
<checkbox-group bindchange="handleTagChange">
<block wx:for="{{tags}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="field-group">
<text class="field-label">可预约美甲师</text>
<checkbox-group bindchange="handleArtistChange">
<block wx:for="{{artists}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view class="field-group">
<text class="field-label">可用优惠券</text>
<checkbox-group bindchange="handleCouponChange">
<block wx:for="{{coupons}}" wx:key="id">
<label class="checkbox-chip {{item.checked ? 'active' : ''}}">
<checkbox value="{{item.valueId}}" checked="{{item.checked}}" />
{{item.labelText}}
</label>
</block>
</checkbox-group>
</view>
<view wx:if="{{uploading}}" class="hint-card">图片上传中,当前进度 {{uploadProgress}}%</view>
<view class="action-row">
<button class="primary-btn" disabled="{{uploading}}" bindtap="handleSubmit">保存作品</button>
</view>
</view>
</view>
</view>
@@ -0,0 +1,5 @@
@import "../../app.wxss";
checkbox {
transform: scale(0.75);
margin-right: 8rpx;
}
@@ -0,0 +1,292 @@
/**
* Purpose: productApi supports index.js by holding or executing the product api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const productApi = require('../../api/product')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: format supports index.js by holding or executing the format page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const format = require('../../utils/format')
const { setTempRecord, clearTempRecord } = require('../../utils/storage')
const { consumeDirty } = require('../../utils/page-state')
/**
* Purpose: PAGE_KEY supports index.js by holding or executing the page key page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const PAGE_KEY = 'admin-products'
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: '',
/**
* Purpose: list supports index.js by holding or executing the list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
list: [],
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false,
/**
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canCreate: false,
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: false
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
if (!navigation.ensureLogin('进入作品管理')) {
return
}
const permissionCodes = getApp().globalData.permissionCodes || []
this.setData({
/**
* Purpose: canCreate supports index.js by holding or executing the can create page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
canCreate: permissionCodes.includes('product:create')
})
if (!this.data.initialized || consumeDirty(PAGE_KEY)) {
this.loadProducts()
}
},
/**
* Purpose: handleKeywordInput supports index.js by holding or executing the handle keyword input page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleKeywordInput(event) {
this.setData({
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: event.detail.value
})
},
/**
* Purpose: handleSearch supports index.js by holding or executing the handle search page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleSearch() {
this.loadProducts()
},
async loadProducts() {
const requestId = (this._loadRequestId || 0) + 1
this._loadRequestId = requestId
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: true
})
try {
const result = await productApi.listProducts({
/**
* Purpose: page supports index.js by holding or executing the page page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
page: 1,
/**
* Purpose: size supports index.js by holding or executing the size page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
size: 20,
/**
* Purpose: keyword supports index.js by holding or executing the keyword page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
keyword: this.data.keyword || undefined
})
if (requestId !== this._loadRequestId) {
return
}
this.setData({
/**
* Purpose: list supports index.js by holding or executing the list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
list: (Array.isArray(result && result.list) ? result.list : []).map(item => ({
...item,
/**
* Purpose: displayPrice supports index.js by holding or executing the display price page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayPrice: format.formatPrice(item.price),
/**
* Purpose: displayShopName supports index.js by holding or executing the display shop name page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayShopName: item.shopName || '当前店铺',
/**
* Purpose: displayDuration supports index.js by holding or executing the display duration page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayDuration: item.approximateDuration || '未设置时长',
/**
* Purpose: displayTagText supports index.js by holding or executing the display tag text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
displayTagText: Array.isArray(item.tagList) ? item.tagList.join(' / ') : (item.tags || '未设置标签')
})),
/**
* Purpose: initialized supports index.js by holding or executing the initialized page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
initialized: true
})
} catch (error) {
if (requestId !== this._loadRequestId) {
return
}
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '作品列表加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
} finally {
if (requestId === this._loadRequestId) {
this.setData({
/**
* Purpose: loading supports index.js by holding or executing the loading page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
loading: false
})
}
}
},
/**
* Purpose: handleCreate supports index.js by holding or executing the handle create page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleCreate() {
clearTempRecord('currentProduct')
navigation.navigate('/pages/product-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'create'
}).catch(() => undefined)
},
/**
* Purpose: handleEdit supports index.js by holding or executing the handle edit page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleEdit(event) {
const product = event.currentTarget.dataset.product
setTempRecord('currentProduct', product)
navigation.navigate('/pages/product-form/index', {
/**
* Purpose: mode supports index.js by holding or executing the mode page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
mode: 'edit',
/**
* Purpose: id supports index.js by holding or executing the id page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
id: product.id
}).catch(() => undefined)
},
/**
* Purpose: handleDelete supports index.js by holding or executing the handle delete page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleDelete(event) {
const product = event.currentTarget.dataset.product
wx.showModal({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '删除作品',
/**
* Purpose: content supports index.js by holding or executing the content page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
content: `确认删除作品“${product.title}”吗?`,
/**
* Purpose: success supports index.js by holding or executing the success page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
success: async result => {
if (!result.confirm) {
return
}
try {
await productApi.deleteProduct(product.id)
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '作品已删除',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
this.loadProducts()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '作品删除失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
}
})
@@ -0,0 +1,5 @@
{
"usingComponents": {
"navigation-bar": "/admin/components/navigation-bar/navigation-bar"
}
}
@@ -0,0 +1,50 @@
<navigation-bar title="作品管理" back="{{true}}" color="#f6efe7" background="#081518"></navigation-bar>
<view class="page-shell">
<view class="page-stack">
<view class="surface-card">
<text class="section-title">作品列表</text>
<view class="search-row">
<input class="field-input search-input" placeholder="按标题搜索作品" placeholder-class="placeholder" value="{{keyword}}" bindinput="handleKeywordInput" confirm-type="search" bindconfirm="handleSearch"></input>
<button class="secondary-btn" bindtap="handleSearch">搜索</button>
</view>
</view>
<block wx:for="{{list}}" wx:key="id">
<view class="list-card">
<view class="list-head">
<view>
<text class="list-title">{{item.title}}</text>
<text class="list-subtitle">{{item.displayShopName}} · {{item.displayDuration}}</text>
</view>
<text class="badge">¥{{item.displayPrice}}</text>
</view>
<view class="meta-grid">
<view class="meta-item">
<text class="meta-label">标签</text>
<text class="meta-value">{{item.displayTagText}}</text>
</view>
<view class="meta-item">
<text class="meta-label">点赞 / 收藏</text>
<text class="meta-value">{{item.likeCount || 0}} / {{item.collectCount || 0}}</text>
</view>
</view>
<view class="list-actions">
<view class="mini-btn primary" data-product="{{item}}" bindtap="handleEdit">编辑</view>
<view class="mini-btn danger" data-product="{{item}}" bindtap="handleDelete">删除</view>
</view>
</view>
</block>
<view wx:if="{{loading && !list.length}}" class="empty-state">
<text class="empty-title">正在加载作品列表</text>
</view>
<view wx:elif="{{!list.length}}" class="empty-state">
<text class="empty-title">还没有作品</text>
<text class="empty-desc">先上传图片、绑定标签和美甲师后,就可以把完整作品发布到门店里。</text>
</view>
<view wx:if="{{canCreate}}" class="fab" bindtap="handleCreate">+</view>
</view>
</view>
@@ -0,0 +1,4 @@
@import "../../app.wxss";
.page-shell {
background: transparent;
}
@@ -0,0 +1,251 @@
/**
* Purpose: authApi supports index.js by holding or executing the auth api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const authApi = require('../../api/auth')
/**
* Purpose: navigation supports index.js by holding or executing the navigation page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const navigation = require('../../utils/navigation')
/**
* Purpose: permission supports index.js by holding or executing the permission page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const permission = require('../../utils/permission')
const sessionSwitch = require('../../../utils/session-switch')
Page({
/**
* Purpose: data supports index.js by holding or executing the data page or API role.
* Usage: import, call, read, or update this page-data from the owning page/module while preserving the surrounding loading and permission flow.
*/
data: {
/**
* Purpose: userInfo supports index.js by holding or executing the user info page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
userInfo: null,
/**
* Purpose: currentShop supports index.js by holding or executing the current shop page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentShop: null,
/**
* Purpose: permissionCodes supports index.js by holding or executing the permission codes page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionCodes: [],
/**
* Purpose: roleLabel supports index.js by holding or executing the role label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
roleLabel: '',
/**
* Purpose: shopScopeText supports index.js by holding or executing the shop scope text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
shopScopeText: '',
/**
* Purpose: currentShopText supports index.js by holding or executing the current shop text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentShopText: ''
},
/**
* Purpose: onShow supports index.js by holding or executing the on show page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
onShow() {
if (!navigation.ensureLogin('进入个人中心')) {
return
}
const app = getApp()
const userInfo = app.globalData.userInfo
const currentShop = app.globalData.currentShop
const shopScopeText = userInfo
? (Array.isArray(userInfo.shopNames) && userInfo.shopNames.length
? userInfo.shopNames.join(' / ')
: (userInfo.shopName || '--'))
: '--'
this.setData({
userInfo,
currentShop,
/**
* Purpose: permissionCodes supports index.js by holding or executing the permission codes page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
permissionCodes: app.globalData.permissionCodes || [],
/**
* Purpose: roleLabel supports index.js by holding or executing the role label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
roleLabel: userInfo ? permission.getRoleLabel(userInfo.type) : '--',
shopScopeText,
/**
* Purpose: currentShopText supports index.js by holding or executing the current shop text page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
currentShopText: currentShop ? `当前店铺:${currentShop.shopName}` : '当前为平台总览模式'
})
},
/**
* Purpose: handleOpenOrders supports index.js by holding or executing the handle open orders page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleOpenOrders() {
navigation.switchTab('/pages/orders/index').catch(() => undefined)
},
/**
* Purpose: handleOpenManage supports index.js by holding or executing the handle open manage page or API role.
* Usage: import, call, read, or update this method from the owning page/module while preserving the surrounding loading and permission flow.
*/
handleOpenManage() {
navigation.switchTab('/pages/manage/index').catch(() => undefined)
},
handleOpenWorkbench() {
navigation.switchTab('/pages/workbench/index').catch(() => undefined)
},
handleOpenCustomerHome() {
sessionSwitch.openCustomerHome()
},
async handleSwitchShop() {
const userInfo = this.data.userInfo
if (!userInfo || !userInfo.account) {
return
}
try {
const result = await authApi.getLoginShops(userInfo.account)
const shops = Array.isArray(result && result.shops) ? result.shops : []
const allowShoplessLogin = Boolean(result && result.allowShoplessLogin)
if (allowShoplessLogin && permission.isPlatformAdmin(userInfo)) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '平台管理员固定为总览模式',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
const items = shops.map(shop => ({
/**
* Purpose: label supports index.js by holding or executing the label page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
label: shop.shopName,
/**
* Purpose: value supports index.js by holding or executing the value page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
value: shop.id
}))
if (!items.length) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '当前账号没有可切换的店铺',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
return
}
wx.showActionSheet({
/**
* Purpose: itemList supports index.js by holding or executing the item list page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
itemList: items.map(item => item.label),
/**
* Purpose: success supports index.js by holding or executing the success page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
success: async action => {
const target = items[action.tapIndex]
if (!target) {
return
}
try {
await getApp().switchAdminShop(target.value || undefined)
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: '店铺已切换',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
this.onShow()
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '切换店铺失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
}
})
} catch (error) {
wx.showToast({
/**
* Purpose: title supports index.js by holding or executing the title page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
title: error.message || '店铺列表加载失败',
/**
* Purpose: icon supports index.js by holding or executing the icon page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
icon: 'none'
})
}
},
async handleLogout() {
try {
await authApi.logout().catch(() => undefined)
} finally {
getApp().clearAdminSession()
wx.reLaunch({
/**
* Purpose: url supports index.js by holding or executing the url page or API role.
* Usage: import, call, read, or update this page-data-field from the owning page/module while preserving the surrounding loading and permission flow.
*/
url: '/admin/pages/login/index'
})
}
}
})

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