杂务:整理文档并收口 YumiNail 修复
This commit is contained in:
@@ -24,16 +24,44 @@
|
||||
v-model:value="keyword"
|
||||
class="admin-toolbar__grow"
|
||||
placeholder="搜索订单号、用户 ID 或优惠券"
|
||||
@search="noop"
|
||||
@search="loadOrders"
|
||||
/>
|
||||
<a-select
|
||||
v-model:value="statusFilter"
|
||||
:options="statusOptions"
|
||||
:style="isMobile ? { width: '100%' } : { width: '160px' }"
|
||||
@change="loadOrders"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="admin-filter-bar">
|
||||
<a-select
|
||||
v-model:value="shopFilter"
|
||||
:allow-clear="currentUserType === 4"
|
||||
placeholder="所属店铺"
|
||||
style="width: 180px"
|
||||
:loading="shopLoading"
|
||||
:disabled="currentUserType !== 4 && !!currentUserInfo?.shopId"
|
||||
@change="loadOrders"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="shop in shopList"
|
||||
:key="shop.id"
|
||||
:value="getShopOptionValue(shop)"
|
||||
>
|
||||
{{ shop.shopName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
<a-input v-model:value="artistKeyword" allow-clear placeholder="美甲师" style="width: 160px" @pressEnter="noop" />
|
||||
<a-input v-model:value="userKeyword" allow-clear placeholder="用户ID/客户" style="width: 160px" @pressEnter="noop" />
|
||||
<a-range-picker v-model:value="createRange" value-format="YYYY-MM-DD HH:mm:ss" show-time />
|
||||
<a-range-picker v-model:value="appointmentRange" value-format="YYYY-MM-DD HH:mm:ss" show-time />
|
||||
<a-input-number v-model:value="minAmount" :min="0" placeholder="最低金额" style="width: 120px" />
|
||||
<a-input-number v-model:value="maxAmount" :min="0" placeholder="最高金额" style="width: 120px" />
|
||||
<a-button @click="resetFilters">重置筛选</a-button>
|
||||
</div>
|
||||
|
||||
<a-table v-if="!isMobile" :columns="columns" :data-source="filteredOrders" :loading="loading" row-key="id">
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'status'">
|
||||
@@ -191,7 +219,7 @@
|
||||
*/
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { orderApi } from '../../api/order'
|
||||
import { adminOrderApi, adminShopApi, type Shop } from '@/api/admin'
|
||||
import { usePermission } from '@/utils/permission'
|
||||
import type { IdType } from '@/utils/id'
|
||||
import { sameId } from '@/utils/id'
|
||||
@@ -204,11 +232,29 @@ const { isMobile } = useAdminViewport()
|
||||
const orders = ref<any[]>([])
|
||||
/** loading is a reactive state variable used by the template and event handlers. */
|
||||
const loading = ref(false)
|
||||
const shopLoading = ref(false)
|
||||
const currentOrder = ref<any | null>(null)
|
||||
const currentUserType = ref<number | null>(null)
|
||||
const currentUserInfo = (() => {
|
||||
try {
|
||||
const cached = localStorage.getItem('adminUserInfo') || sessionStorage.getItem('adminUserInfo')
|
||||
return cached ? JSON.parse(cached) : null
|
||||
} catch (error) {
|
||||
console.error('获取当前用户信息失败', error)
|
||||
return null
|
||||
}
|
||||
})()
|
||||
/** keyword is a reactive state variable used by the template and event handlers. */
|
||||
const keyword = ref('')
|
||||
const statusFilter = ref<'all' | string>('all')
|
||||
const shopList = ref<Shop[]>([])
|
||||
const shopFilter = ref<string | undefined>()
|
||||
const artistKeyword = ref('')
|
||||
const userKeyword = ref('')
|
||||
const createRange = ref<[string, string] | undefined>()
|
||||
const appointmentRange = ref<[string, string] | undefined>()
|
||||
const minAmount = ref<number | undefined>()
|
||||
const maxAmount = ref<number | undefined>()
|
||||
const { hasPermission, loadUserPermissions } = usePermission()
|
||||
|
||||
/** detailVisible is a reactive state variable used by the template and event handlers. */
|
||||
@@ -235,6 +281,13 @@ const filteredOrders = computed(() => {
|
||||
if (!matchStatus) {
|
||||
return false
|
||||
}
|
||||
const actualAmount = Number(order.actualAmount ?? order.totalAmount ?? 0)
|
||||
if (minAmount.value !== undefined && actualAmount < minAmount.value) return false
|
||||
if (maxAmount.value !== undefined && actualAmount > maxAmount.value) return false
|
||||
if (!matchText(userKeyword.value, [order.userId, order.userNickname, order.customerName, order.customerPhone])) return false
|
||||
if (!matchText(artistKeyword.value, (order.items || []).map((item: any) => item.artistName || item.artistId))) return false
|
||||
if (!matchRange(order.createTime, createRange.value)) return false
|
||||
if (!matchRange((order.items || [])[0]?.appointmentTime, appointmentRange.value, (order.items || []).map((item: any) => item.appointmentTime))) return false
|
||||
if (!keywordValue) {
|
||||
return true
|
||||
}
|
||||
@@ -248,6 +301,37 @@ const filteredOrders = computed(() => {
|
||||
})
|
||||
})
|
||||
|
||||
const matchText = (needle: string, values: any[]) => {
|
||||
const normalized = needle.trim().toLowerCase()
|
||||
if (!normalized) return true
|
||||
return values.some(value => String(value ?? '').toLowerCase().includes(normalized))
|
||||
}
|
||||
|
||||
const matchRange = (value: string | undefined, range?: [string, string], candidates?: string[]) => {
|
||||
if (!range?.length) return true
|
||||
const values = candidates?.length ? candidates : [value]
|
||||
const start = new Date(range[0]).getTime()
|
||||
const end = new Date(range[1]).getTime()
|
||||
return values.some(item => {
|
||||
if (!item) return false
|
||||
const time = new Date(item).getTime()
|
||||
return time >= start && time <= end
|
||||
})
|
||||
}
|
||||
|
||||
const resetFilters = () => {
|
||||
keyword.value = ''
|
||||
statusFilter.value = 'all'
|
||||
shopFilter.value = currentUserType.value !== 4 ? normalizeShopId(currentUserInfo?.shopId) : undefined
|
||||
artistKeyword.value = ''
|
||||
userKeyword.value = ''
|
||||
createRange.value = undefined
|
||||
appointmentRange.value = undefined
|
||||
minAmount.value = undefined
|
||||
maxAmount.value = undefined
|
||||
void loadOrders()
|
||||
}
|
||||
|
||||
const columns = [
|
||||
{ title: '订单编号', dataIndex: 'orderNo', key: 'orderNo' },
|
||||
{ title: '用户ID', dataIndex: 'userId', key: 'userId', width: 100 },
|
||||
@@ -277,17 +361,36 @@ const statusColor = (status: number) => {
|
||||
return 'default'
|
||||
}
|
||||
|
||||
const normalizeUserType = (value: unknown) => {
|
||||
const type = Number(value)
|
||||
return Number.isFinite(type) ? type : null
|
||||
}
|
||||
|
||||
/** resolveCurrentUserType is a local helper used by this page script. */
|
||||
const resolveCurrentUserType = () => {
|
||||
const cached = localStorage.getItem('adminUserInfo') || sessionStorage.getItem('adminUserInfo')
|
||||
if (!cached) {
|
||||
currentUserType.value = null
|
||||
return
|
||||
currentUserType.value = normalizeUserType(currentUserInfo?.type)
|
||||
}
|
||||
|
||||
const normalizeShopId = (value: unknown) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return undefined
|
||||
}
|
||||
return String(value)
|
||||
}
|
||||
|
||||
const getShopOptionValue = (shop: Shop) => normalizeShopId((shop as any).id) || ''
|
||||
|
||||
const loadShopOptions = async () => {
|
||||
shopLoading.value = true
|
||||
try {
|
||||
currentUserType.value = JSON.parse(cached)?.type ?? null
|
||||
} catch {
|
||||
currentUserType.value = null
|
||||
shopList.value = await adminShopApi.listAllShops() as unknown as Shop[]
|
||||
if (currentUserType.value !== 4 && currentUserInfo?.shopId) {
|
||||
shopFilter.value = normalizeShopId(currentUserInfo.shopId)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error)
|
||||
} finally {
|
||||
shopLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,7 +398,15 @@ const resolveCurrentUserType = () => {
|
||||
const loadOrders = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
orders.value = await orderApi.getAllOrders() as unknown as any[]
|
||||
const scopedShopId = shopFilter.value || (currentUserType.value !== 4 ? normalizeShopId(currentUserInfo?.shopId) : undefined)
|
||||
const result = await adminOrderApi.listOrders({
|
||||
page: 1,
|
||||
size: 1000,
|
||||
keyword: keyword.value || undefined,
|
||||
status: statusFilter.value === 'all' ? undefined : Number(statusFilter.value),
|
||||
shopId: scopedShopId
|
||||
}) as unknown as { list?: any[] }
|
||||
orders.value = result.list || []
|
||||
} catch {
|
||||
message.error('获取订单列表失败')
|
||||
} finally {
|
||||
@@ -307,7 +418,7 @@ const loadOrders = async () => {
|
||||
const process = async (orderId: IdType, status: number) => {
|
||||
try {
|
||||
await runWithGlobalLoading(async () => {
|
||||
await orderApi.processOrder(orderId, status)
|
||||
await adminOrderApi.updateOrderStatus(orderId, status)
|
||||
await loadOrders()
|
||||
})
|
||||
message.success('操作成功')
|
||||
@@ -325,6 +436,7 @@ const noop = () => {}
|
||||
onMounted(async () => {
|
||||
resolveCurrentUserType()
|
||||
await loadUserPermissions()
|
||||
await loadShopOptions()
|
||||
await loadOrders()
|
||||
})
|
||||
</script>
|
||||
@@ -338,4 +450,11 @@ onMounted(async () => {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.admin-filter-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user