功能:新增下一阶段运营能力和生产部署

This commit is contained in:
xiaowang
2026-05-24 18:09:11 +08:00
parent 8116abc9b5
commit 1d077d4089
157 changed files with 9206 additions and 74 deletions
@@ -218,6 +218,7 @@ import {
DownOutlined,
GiftOutlined,
HomeOutlined,
CalendarOutlined,
IdcardOutlined,
LogoutOutlined,
MessageOutlined,
@@ -228,6 +229,7 @@ import {
SafetyCertificateOutlined,
ShopOutlined,
ShoppingOutlined,
ToolOutlined,
TagOutlined,
TeamOutlined,
UserOutlined
@@ -307,6 +309,10 @@ const menuItems: AdminMenuItem[] = [
{ key: '/admin/permissions', icon: SafetyCertificateOutlined, label: '权限管理', permissionCode: 'permission:view' },
{ key: '/admin/tags', icon: TagOutlined, label: '标签管理', permissionCode: 'tag:view' },
{ key: '/admin/orders', icon: ShoppingOutlined, label: '订单管理', permissionCode: 'order:view' },
{ key: '/admin/schedules', icon: CalendarOutlined, label: '排班管理', permissionCode: 'schedule:view' },
{ key: '/admin/after-sales', icon: MessageOutlined, label: '售后处理', permissionCode: 'after_sale:view' },
{ key: '/admin/inventory', icon: ToolOutlined, label: '库存管理', permissionCode: 'inventory:view' },
{ key: '/admin/campaigns', icon: GiftOutlined, label: '活动管理', permissionCode: 'campaign:view' },
{ key: '/admin/nail-artists', icon: TeamOutlined, label: '美甲师管理', permissionCode: 'nail_artist:view' }
,
{ key: '/admin/messages', icon: MessageOutlined, label: '消息发布', permissionCode: 'message:view' },
@@ -385,7 +391,11 @@ const activeMobileTab = computed(() => {
route.path.startsWith('/admin/shops') ||
route.path.startsWith('/admin/permissions') ||
route.path.startsWith('/admin/tags') ||
route.path.startsWith('/admin/nail-artists')
route.path.startsWith('/admin/nail-artists') ||
route.path.startsWith('/admin/schedules') ||
route.path.startsWith('/admin/after-sales') ||
route.path.startsWith('/admin/inventory') ||
route.path.startsWith('/admin/campaigns')
) {
return 'manage'
}
@@ -0,0 +1,286 @@
<template>
<div class="after-sales">
<a-page-header v-if="!isMobile" title="售后处理" sub-title="处理客户退款与售后申请" />
<section v-else class="admin-page-intro">
<span class="admin-page-intro__eyebrow">售后</span>
<h1 class="admin-page-intro__title">售后处理</h1>
<div class="admin-page-intro__meta">
<span class="admin-page-chip">申请 {{ pagination.total }}</span>
</div>
</section>
<a-card :bordered="false">
<template #title v-if="isMobile">售后列表</template>
<template #extra>
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
<a-select
v-model:value="statusFilter"
:options="statusOptions"
:style="isMobile ? { width: '100%' } : { width: '160px' }"
@change="reload"
/>
</div>
</template>
<a-table
v-if="!isMobile"
:columns="columns"
:data-source="visibleAfterSales"
:loading="loading"
:pagination="pagination"
row-key="id"
@change="handleTableChange"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
<a-tag :color="statusColor(record.status)">{{ statusText(record.status) }}</a-tag>
</template>
<template v-else-if="column.key === 'amount'">¥{{ money(record.refundAmount) }}</template>
<template v-else-if="column.key === 'actions'">
<a-space>
<a-button type="link" size="small" @click="currentAfterSale = record as AfterSaleVO">查看</a-button>
<a-button v-if="record.status === 'PENDING'" type="primary" size="small" @click="openAudit(record as AfterSaleVO, 'approve')">通过</a-button>
<a-button v-if="record.status === 'PENDING'" danger size="small" @click="openAudit(record as AfterSaleVO, 'reject')">驳回</a-button>
</a-space>
</template>
</template>
</a-table>
<AdminMobileCardList v-else :items="visibleAfterSales" empty-description="暂无售后申请">
<template #item="{ item }">
<article class="admin-mobile-card">
<div class="admin-mobile-card__head">
<div class="admin-mobile-card__body">
<div class="admin-mobile-card__title">{{ item.afterSaleNo || `售后 ${item.id}` }}</div>
<div class="admin-mobile-card__subtitle">订单 {{ item.orderId }} · {{ item.createTime || '-' }}</div>
</div>
<a-tag :color="statusColor(item.status)">{{ statusText(item.status) }}</a-tag>
</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>类型</span>
<strong>{{ typeText(item.type) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>退款金额</span>
<strong>¥{{ money(item.refundAmount) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>原因</span>
<strong>{{ item.reason || '-' }}</strong>
</div>
</div>
<div class="admin-mobile-card__actions">
<a-button size="small" @click="currentAfterSale = item">查看</a-button>
<a-button v-if="item.status === 'PENDING'" type="primary" size="small" @click="openAudit(item, 'approve')">通过</a-button>
<a-button v-if="item.status === 'PENDING'" danger size="small" @click="openAudit(item, 'reject')">驳回</a-button>
</div>
</article>
</template>
</AdminMobileCardList>
</a-card>
<AdminResponsiveModal
v-model:open="detailOpen"
title="售后详情"
:desktop-width="760"
:footer="null"
@cancel="currentAfterSale = null"
>
<a-descriptions v-if="currentAfterSale" bordered :column="1" size="small">
<a-descriptions-item label="售后单号">{{ currentAfterSale.afterSaleNo || '-' }}</a-descriptions-item>
<a-descriptions-item label="订单ID">{{ currentAfterSale.orderId }}</a-descriptions-item>
<a-descriptions-item label="订单项ID">{{ currentAfterSale.orderItemId || '-' }}</a-descriptions-item>
<a-descriptions-item label="用户ID">{{ currentAfterSale.userId || '-' }}</a-descriptions-item>
<a-descriptions-item label="类型">{{ typeText(currentAfterSale.type) }}</a-descriptions-item>
<a-descriptions-item label="退款金额">¥{{ money(currentAfterSale.refundAmount) }}</a-descriptions-item>
<a-descriptions-item label="状态">{{ statusText(currentAfterSale.status) }}</a-descriptions-item>
<a-descriptions-item label="申请原因">{{ currentAfterSale.reason || '-' }}</a-descriptions-item>
<a-descriptions-item label="审核原因">{{ currentAfterSale.auditReason || '-' }}</a-descriptions-item>
<a-descriptions-item label="申请时间">{{ currentAfterSale.createTime || '-' }}</a-descriptions-item>
</a-descriptions>
</AdminResponsiveModal>
<AdminResponsiveModal
v-model:open="auditOpen"
:title="auditAction === 'approve' ? '通过售后' : '驳回售后'"
:desktop-width="620"
:confirm-loading="auditing"
@ok="submitAudit"
@cancel="closeAudit"
>
<a-form layout="vertical">
<a-alert
v-if="auditTarget"
class="audit-alert"
type="info"
show-icon
:message="`${auditTarget.afterSaleNo || auditTarget.id} · 退款 ¥${money(auditTarget.refundAmount)}`"
:description="auditTarget.reason || '暂无申请原因'"
/>
<a-form-item label="处理备注">
<a-textarea v-model:value="auditReason" :rows="4" :maxlength="300" placeholder="填写给客户和门店留痕的处理说明" />
</a-form-item>
</a-form>
</AdminResponsiveModal>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { useRoute } from 'vue-router'
import { message } from 'ant-design-vue'
import { adminAfterSaleApi, type AfterSaleVO } from '@/api/admin'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { useAdminViewport } from '@/composables/useAdminViewport'
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
const { isMobile } = useAdminViewport()
const route = useRoute()
const loading = ref(false)
const auditing = ref(false)
const statusFilter = ref('all')
const afterSales = ref<AfterSaleVO[]>([])
const currentAfterSale = ref<AfterSaleVO | null>(null)
const auditOpen = ref(false)
const auditTarget = ref<AfterSaleVO | null>(null)
const auditAction = ref<'approve' | 'reject'>('approve')
const auditReason = ref('')
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showTotal: (total: number) => `共 ${total} 条`
})
const detailOpen = computed({
get: () => !!currentAfterSale.value,
set: value => { if (!value) currentAfterSale.value = null }
})
const visibleAfterSales = computed(() => {
const orderId = route.query.orderId
if (!orderId) {
return afterSales.value
}
return afterSales.value.filter(item => String(item.orderId) === String(orderId))
})
const statusOptions = [
{ label: '全部状态', value: 'all' },
{ label: '待处理', value: 'PENDING' },
{ label: '已通过', value: 'APPROVED' },
{ label: '已驳回', value: 'REJECTED' }
]
const columns = [
{ title: '售后单号', dataIndex: 'afterSaleNo', key: 'afterSaleNo' },
{ title: '订单ID', dataIndex: 'orderId', key: 'orderId', width: 110 },
{ title: '用户ID', dataIndex: 'userId', key: 'userId', width: 110 },
{ title: '类型', dataIndex: 'type', key: 'type', width: 110 },
{ title: '退款金额', key: 'amount', width: 120 },
{ title: '状态', key: 'status', width: 110 },
{ title: '申请时间', dataIndex: 'createTime', key: 'createTime', width: 180 },
{ title: '操作', key: 'actions', width: 190 }
]
const money = (value?: number) => Number(value || 0).toFixed(2)
const typeText = (type?: string) => {
if (type === 'REFUND') return '退款'
if (type === 'AFTER_SALE') return '售后'
return type || '-'
}
const statusText = (status?: string) => {
if (status === 'PENDING') return '待处理'
if (status === 'APPROVED') return '已通过'
if (status === 'REJECTED') return '已驳回'
return status || '-'
}
const statusColor = (status?: string) => {
if (status === 'PENDING') return 'orange'
if (status === 'APPROVED') return 'green'
if (status === 'REJECTED') return 'red'
return 'default'
}
const loadAfterSales = async () => {
loading.value = true
try {
const result = await adminAfterSaleApi.listAfterSales({
status: statusFilter.value === 'all' ? undefined : statusFilter.value,
page: pagination.current,
size: pagination.pageSize
})
afterSales.value = result.list || []
pagination.total = result.total || 0
} catch (error) {
console.error('加载售后失败:', error)
message.error('加载售后失败')
} finally {
loading.value = false
}
}
const reload = () => {
pagination.current = 1
void loadAfterSales()
}
const handleTableChange = (pag: any) => {
pagination.current = pag.current || 1
pagination.pageSize = pag.pageSize || pagination.pageSize
void loadAfterSales()
}
const openAudit = (record: AfterSaleVO, action: 'approve' | 'reject') => {
auditTarget.value = record
auditAction.value = action
auditReason.value = ''
auditOpen.value = true
}
const closeAudit = () => {
auditOpen.value = false
auditTarget.value = null
auditReason.value = ''
}
const submitAudit = async () => {
if (!auditTarget.value) return
auditing.value = true
try {
await runWithGlobalLoading(async () => {
const payload = { auditReason: auditReason.value.trim() || undefined }
if (auditAction.value === 'approve') {
await adminAfterSaleApi.approveAfterSale(auditTarget.value!.id, payload)
} else {
await adminAfterSaleApi.rejectAfterSale(auditTarget.value!.id, payload)
}
await loadAfterSales()
})
message.success('售后已处理')
closeAudit()
} catch (error: any) {
console.error('处理售后失败:', error)
message.error(error?.message || '处理售后失败')
} finally {
auditing.value = false
}
}
onMounted(loadAfterSales)
</script>
<style scoped>
.after-sales {
padding: 0;
}
.audit-alert {
margin-bottom: 16px;
}
</style>
@@ -0,0 +1,299 @@
<template>
<div class="campaigns">
<a-page-header v-if="!isMobile" title="活动管理" sub-title="维护营销活动、推荐位和关联资源" />
<section v-else class="admin-page-intro">
<span class="admin-page-intro__eyebrow">活动</span>
<h1 class="admin-page-intro__title">活动管理</h1>
<div class="admin-page-intro__meta">
<span class="admin-page-chip">活动 {{ pagination.total }}</span>
</div>
</section>
<a-card :bordered="false">
<template #title v-if="isMobile">活动列表</template>
<template #extra>
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
<a-select
v-model:value="statusFilter"
:options="statusOptions"
:style="isMobile ? { width: '100%' } : { width: '160px' }"
@change="reload"
/>
<a-button type="primary" @click="openCreateModal">
<template #icon>
<PlusOutlined />
</template>
新增活动
</a-button>
</div>
</template>
<a-table
v-if="!isMobile"
:columns="columns"
:data-source="campaigns"
:loading="loading"
:pagination="pagination"
row-key="id"
@change="handleTableChange"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'status'">
<a-tag :color="record.status === 0 ? 'red' : 'green'">{{ campaignStatusText(record.status) }}</a-tag>
</template>
<template v-else-if="column.key === 'time'">
{{ record.startTime || '-' }} 至 {{ record.endTime || '-' }}
</template>
<template v-else-if="column.key === 'actions'">
<a-button type="link" size="small" @click="openEditModal(record as CampaignVO)">编辑</a-button>
</template>
</template>
</a-table>
<AdminMobileCardList v-else :items="campaigns" empty-description="暂无活动数据">
<template #item="{ item }">
<article class="admin-mobile-card">
<div class="admin-mobile-card__head">
<div class="admin-mobile-card__body">
<div class="admin-mobile-card__title">{{ item.title }}</div>
<div class="admin-mobile-card__subtitle">{{ item.scene || 'GENERAL' }} · 排序 {{ item.sortOrder ?? 0 }}</div>
</div>
<a-tag :color="item.status === 0 ? 'red' : 'green'">{{ campaignStatusText(item.status) }}</a-tag>
</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>时间</span>
<strong>{{ item.startTime || '-' }} 至 {{ item.endTime || '-' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>作品ID</span>
<strong>{{ item.productIds || '-' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>优惠券ID</span>
<strong>{{ item.couponIds || '-' }}</strong>
</div>
</div>
<div class="admin-mobile-card__actions">
<a-button size="small" @click="openEditModal(item)">编辑</a-button>
</div>
</article>
</template>
</AdminMobileCardList>
</a-card>
<AdminResponsiveModal
v-model:open="modalOpen"
:title="editingCampaign ? '编辑活动' : '新增活动'"
:desktop-width="760"
:confirm-loading="saving"
@ok="saveCampaign"
@cancel="closeModal"
>
<a-form ref="formRef" :model="formState" :rules="rules" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
<a-form-item label="活动标题" name="title">
<a-input v-model:value="formState.title" placeholder="请输入活动标题" />
</a-form-item>
<a-form-item label="活动场景">
<a-input v-model:value="formState.scene" placeholder="HOME / DETAIL / POPUP" />
</a-form-item>
<a-form-item label="活动说明">
<a-textarea v-model:value="formState.description" :rows="3" :maxlength="500" />
</a-form-item>
<a-form-item label="关联作品ID">
<a-input v-model:value="formState.productIds" placeholder="多个 ID 用英文逗号分隔" />
</a-form-item>
<a-form-item label="关联券ID">
<a-input v-model:value="formState.couponIds" placeholder="多个 ID 用英文逗号分隔" />
</a-form-item>
<a-form-item label="开始时间">
<a-date-picker
v-model:value="formState.startTime"
show-time
value-format="YYYY-MM-DDTHH:mm:ss"
format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
/>
</a-form-item>
<a-form-item label="结束时间">
<a-date-picker
v-model:value="formState.endTime"
show-time
value-format="YYYY-MM-DDTHH:mm:ss"
format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
/>
</a-form-item>
<a-form-item label="排序">
<a-input-number v-model:value="formState.sortOrder" :min="0" style="width: 100%" />
</a-form-item>
<a-form-item label="状态">
<a-select v-model:value="formState.status">
<a-select-option :value="1">启用</a-select-option>
<a-select-option :value="0">停用</a-select-option>
</a-select>
</a-form-item>
</a-form>
</AdminResponsiveModal>
</div>
</template>
<script setup lang="ts">
import { onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue'
import { PlusOutlined } from '@ant-design/icons-vue'
import { adminCampaignApi, type CampaignRequest, type CampaignVO } from '@/api/admin'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { useAdminViewport } from '@/composables/useAdminViewport'
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
const { isMobile } = useAdminViewport()
const loading = ref(false)
const saving = ref(false)
const statusFilter = ref<'all' | number>('all')
const campaigns = ref<CampaignVO[]>([])
const modalOpen = ref(false)
const editingCampaign = ref<CampaignVO | null>(null)
const formRef = ref<FormInstance>()
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showTotal: (total: number) => `共 ${total} 条`
})
const formState = reactive<CampaignRequest>({
title: '',
description: '',
scene: 'HOME',
productIds: '',
couponIds: '',
status: 1,
startTime: undefined,
endTime: undefined,
sortOrder: 0
})
const rules = {
title: [{ required: true, message: '请输入活动标题', trigger: 'blur' }]
} as any
const statusOptions = [
{ label: '全部状态', value: 'all' },
{ label: '启用', value: 1 },
{ label: '停用', value: 0 }
]
const columns = [
{ title: '标题', dataIndex: 'title', key: 'title' },
{ title: '场景', dataIndex: 'scene', key: 'scene', width: 120 },
{ title: '活动时间', key: 'time', width: 280 },
{ title: '排序', dataIndex: 'sortOrder', key: 'sortOrder', width: 90 },
{ title: '状态', key: 'status', width: 100 },
{ title: '操作', key: 'actions', width: 90 }
]
const campaignStatusText = (status?: number) => status === 0 ? '停用' : '启用'
const resetForm = () => {
Object.assign(formState, {
title: '',
description: '',
scene: 'HOME',
productIds: '',
couponIds: '',
status: 1,
startTime: undefined,
endTime: undefined,
sortOrder: 0
})
}
const loadCampaigns = async () => {
loading.value = true
try {
const result = await adminCampaignApi.listCampaigns({
status: statusFilter.value === 'all' ? undefined : Number(statusFilter.value),
page: pagination.current,
size: pagination.pageSize
})
campaigns.value = result.list || []
pagination.total = result.total || 0
} catch (error) {
console.error('加载活动失败:', error)
message.error('加载活动失败')
} finally {
loading.value = false
}
}
const reload = () => {
pagination.current = 1
void loadCampaigns()
}
const handleTableChange = (pag: any) => {
pagination.current = pag.current || 1
pagination.pageSize = pag.pageSize || pagination.pageSize
void loadCampaigns()
}
const openCreateModal = () => {
editingCampaign.value = null
resetForm()
modalOpen.value = true
}
const openEditModal = (record: CampaignVO) => {
editingCampaign.value = record
Object.assign(formState, {
title: record.title || '',
description: record.description || '',
scene: record.scene || 'HOME',
productIds: record.productIds || '',
couponIds: record.couponIds || '',
status: record.status ?? 1,
startTime: record.startTime,
endTime: record.endTime,
sortOrder: record.sortOrder ?? 0
})
modalOpen.value = true
}
const closeModal = () => {
modalOpen.value = false
formRef.value?.resetFields()
}
const saveCampaign = async () => {
try {
await formRef.value?.validate()
saving.value = true
await runWithGlobalLoading(async () => {
await adminCampaignApi.saveCampaign({ ...formState })
await loadCampaigns()
})
message.success('活动已保存')
closeModal()
} catch (error: any) {
if (error?.errorFields) return
console.error('保存活动失败:', error)
message.error(error?.message || '保存活动失败')
} finally {
saving.value = false
}
}
onMounted(loadCampaigns)
</script>
<style scoped>
.campaigns {
padding: 0;
}
</style>
@@ -20,11 +20,22 @@
<a-row :gutter="[16, 16]" class="stat-cards">
<a-col v-for="item in primaryStats" :key="item.key" :xs="24" :sm="12" :xl="6">
<a-card class="metric-card">
<a-statistic :title="item.title" :value="item.value" :precision="item.precision || 0" :loading="loading">
<a-statistic :title="item.title" :value="item.value" :precision="0" :loading="loading">
<template #prefix>
<component :is="item.icon" />
</template>
</a-statistic>
</a-card>
</a-col>
</a-row>
<a-row :gutter="[16, 16]" class="stat-cards">
<a-col v-for="item in analyticsStats" :key="item.key" :xs="24" :sm="12" :xl="6">
<a-card class="metric-card">
<a-statistic :title="item.title" :value="item.value" :precision="0" :loading="loading">
<template #prefix>
<component :is="item.icon" />
</template>
<template v-if="item.suffix" #suffix>{{ item.suffix }}</template>
</a-statistic>
</a-card>
</a-col>
@@ -99,15 +110,20 @@
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { computed, onMounted, reactive, ref, type Component } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import {
CheckCircleOutlined,
EyeOutlined,
GiftOutlined,
HeartOutlined,
HomeOutlined,
MessageOutlined,
ShopOutlined,
ShoppingCartOutlined,
ShoppingOutlined,
StarOutlined,
TeamOutlined,
UserOutlined
} from '@ant-design/icons-vue'
@@ -115,9 +131,18 @@ import {
* Purpose: DashboardStats supports DashboardView.vue by holding or executing the dashboard stats page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
*/
import { adminDashboardApi, type DashboardStats } from '@/api/admin'
import { adminDashboardApi, type DashboardStats, type OperationsAnalyticsVO } from '@/api/admin'
import { useAdminViewport } from '@/composables/useAdminViewport'
type StatCard = {
key: string
title: string
value: number
precision?: number
suffix?: string
icon: Component
}
/**
* Purpose: router supports DashboardView.vue by holding or executing the router 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.
@@ -153,6 +178,18 @@ const stats = reactive<DashboardStats>({
recentActivities: []
})
const analytics = reactive<OperationsAnalyticsVO>({
viewCount: 0,
favoriteCount: 0,
cartCount: 0,
orderCount: 0,
paidOrderCount: 0,
completedOrderCount: 0,
reviewCount: 0,
rebookCount: 0,
totalAmount: 0
})
/**
* Purpose: getCurrentUserInfo supports DashboardView.vue by holding or executing the get current user info 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.
@@ -203,13 +240,24 @@ const numberText = (value?: number) => String(Number(value || 0))
* Purpose: primaryStats supports DashboardView.vue by holding or executing the primary stats 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 primaryStats = computed(() => [
const primaryStats = computed<StatCard[]>(() => [
{ key: 'amount', title: '订单总额', value: money(stats.totalOrderAmount), precision: 2, suffix: '元', icon: ShoppingOutlined },
{ key: 'todayAmount', title: '今日订单额', value: money(stats.todayOrderAmount), precision: 2, suffix: '元', icon: ShoppingOutlined },
{ key: 'customers', title: '客户数量', value: stats.totalCustomers || stats.totalUsers || 0, icon: UserOutlined },
{ key: 'artists', title: '美甲师数量', value: stats.totalArtists || 0, icon: TeamOutlined }
])
const analyticsStats = computed<StatCard[]>(() => [
{ key: 'views', title: '浏览量', value: Number(analytics.viewCount || 0), icon: EyeOutlined },
{ key: 'favorites', title: '收藏量', value: Number(analytics.favoriteCount || 0), icon: HeartOutlined },
{ key: 'carts', title: '加购量', value: Number(analytics.cartCount || 0), icon: ShoppingCartOutlined },
{ key: 'orders', title: '下单量', value: Number(analytics.orderCount || 0), icon: ShoppingOutlined },
{ key: 'paid', title: '支付订单', value: Number(analytics.paidOrderCount || 0), icon: CheckCircleOutlined },
{ key: 'completed', title: '完成订单', value: Number(analytics.completedOrderCount || 0), icon: CheckCircleOutlined },
{ key: 'reviews', title: '评价数', value: Number(analytics.reviewCount || 0), icon: StarOutlined },
{ key: 'rebooks', title: '复购数', value: Number(analytics.rebookCount || 0), icon: ShoppingOutlined }
])
/**
* Purpose: overviewItems supports DashboardView.vue by holding or executing the overview items 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.
@@ -266,6 +314,12 @@ const fetchStats = async () => {
try {
const data = await adminDashboardApi.getStats()
Object.assign(stats, data)
try {
const analyticsData = await adminDashboardApi.getAnalytics()
Object.assign(analytics, analyticsData)
} catch (analyticsError) {
console.error('获取经营分析数据失败:', analyticsError)
}
} catch (error) {
console.error('获取统计数据失败:', error)
message.error('获取统计数据失败')
@@ -66,8 +66,8 @@
<template #title>
快捷操作
</template>
<a-grid :columns="3" :colGap="16" :rowGap="16">
<a-grid-item v-for="item in quickActions" :key="item.key">
<a-row :gutter="[16, 16]">
<a-col v-for="item in quickActions" :key="item.key" :span="8">
<a-card hoverable @click="navigateTo(item.path, item.permissionCode)">
<template #cover>
<div class="action-icon">
@@ -78,8 +78,8 @@
{{ item.title }}
</template>
</a-card>
</a-grid-item>
</a-grid>
</a-col>
</a-row>
</a-card>
</template>
@@ -0,0 +1,343 @@
<template>
<div class="inventory">
<a-page-header v-if="!isMobile" title="库存管理" sub-title="维护门店耗材库存和预警阈值" />
<section v-else class="admin-page-intro">
<span class="admin-page-intro__eyebrow">库存</span>
<h1 class="admin-page-intro__title">库存管理</h1>
<div class="admin-page-intro__meta">
<span class="admin-page-chip">物料 {{ pagination.total }}</span>
<span class="admin-page-chip">预警 {{ warningCount }}</span>
</div>
</section>
<a-card :bordered="false">
<template #title v-if="isMobile">库存列表</template>
<template #extra>
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
<a-input-search
v-model:value="keyword"
placeholder="搜索物料或分类"
:style="isMobile ? { width: '100%' } : { width: '220px' }"
/>
<a-button type="primary" @click="openCreateModal">
<template #icon>
<PlusOutlined />
</template>
新增物料
</a-button>
</div>
</template>
<a-alert
v-if="warningCount"
class="inventory-alert"
type="warning"
show-icon
:message="`当前有 ${warningCount} 个物料低于预警阈值`"
/>
<a-table
v-if="!isMobile"
:columns="columns"
:data-source="filteredItems"
:loading="loading"
:pagination="pagination"
row-key="id"
@change="handleTableChange"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'stock'">
<a-tag :color="record.warning ? 'red' : 'green'">{{ numberText(record.stockQuantity) }} {{ record.unit || '' }}</a-tag>
</template>
<template v-else-if="column.key === 'warning'">{{ numberText(record.warningThreshold) }} {{ record.unit || '' }}</template>
<template v-else-if="column.key === 'status'">
<a-tag :color="record.status === 0 ? 'red' : 'green'">{{ record.status === 0 ? '停用' : '启用' }}</a-tag>
</template>
<template v-else-if="column.key === 'actions'">
<a-space>
<a-button type="link" size="small" @click="openAdjustModal(record as InventoryItemVO, 'IN')">入库</a-button>
<a-button type="link" size="small" @click="openAdjustModal(record as InventoryItemVO, 'OUT')">出库</a-button>
</a-space>
</template>
</template>
</a-table>
<AdminMobileCardList v-else :items="filteredItems" empty-description="暂无库存物料">
<template #item="{ item }">
<article class="admin-mobile-card">
<div class="admin-mobile-card__head">
<div class="admin-mobile-card__body">
<div class="admin-mobile-card__title">{{ item.itemName }}</div>
<div class="admin-mobile-card__subtitle">{{ item.category || '未分类' }}</div>
</div>
<a-tag :color="item.warning ? 'red' : 'green'">{{ item.warning ? '预警' : '正常' }}</a-tag>
</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>库存</span>
<strong>{{ numberText(item.stockQuantity) }} {{ item.unit || '' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>预警阈值</span>
<strong>{{ numberText(item.warningThreshold) }} {{ item.unit || '' }}</strong>
</div>
</div>
<div class="admin-mobile-card__actions">
<a-button size="small" @click="openAdjustModal(item, 'IN')">入库</a-button>
<a-button size="small" @click="openAdjustModal(item, 'OUT')">出库</a-button>
</div>
</article>
</template>
</AdminMobileCardList>
</a-card>
<AdminResponsiveModal
v-model:open="itemModalOpen"
title="新增物料"
:desktop-width="680"
:confirm-loading="savingItem"
@ok="saveItem"
@cancel="closeItemModal"
>
<a-form ref="itemFormRef" :model="itemForm" :rules="itemRules" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
<a-form-item label="物料名称" name="itemName">
<a-input v-model:value="itemForm.itemName" placeholder="例如:底胶" />
</a-form-item>
<a-form-item label="分类">
<a-input v-model:value="itemForm.category" placeholder="例如:胶类/工具/耗材" />
</a-form-item>
<a-form-item label="单位">
<a-input v-model:value="itemForm.unit" placeholder="瓶、盒、个" />
</a-form-item>
<a-form-item label="初始库存">
<a-input-number v-model:value="itemForm.stockQuantity" :min="0" :step="1" style="width: 100%" />
</a-form-item>
<a-form-item label="预警阈值">
<a-input-number v-model:value="itemForm.warningThreshold" :min="0" :step="1" style="width: 100%" />
</a-form-item>
<a-form-item label="状态">
<a-select v-model:value="itemForm.status">
<a-select-option :value="1">启用</a-select-option>
<a-select-option :value="0">停用</a-select-option>
</a-select>
</a-form-item>
</a-form>
</AdminResponsiveModal>
<AdminResponsiveModal
v-model:open="adjustModalOpen"
:title="adjustForm.changeType === 'OUT' ? '出库调整' : '入库调整'"
:desktop-width="600"
:confirm-loading="adjusting"
@ok="submitAdjust"
@cancel="closeAdjustModal"
>
<a-form ref="adjustFormRef" :model="adjustForm" :rules="adjustRules" layout="vertical">
<a-alert
v-if="adjustTarget"
class="inventory-alert"
type="info"
show-icon
:message="adjustTarget.itemName"
:description="`当前库存:${numberText(adjustTarget.stockQuantity)} ${adjustTarget.unit || ''}`"
/>
<a-form-item label="调整数量" name="changeQuantity">
<a-input-number v-model:value="adjustForm.changeQuantity" :step="1" style="width: 100%" />
</a-form-item>
<a-form-item label="备注">
<a-textarea v-model:value="adjustForm.remark" :rows="3" :maxlength="200" />
</a-form-item>
</a-form>
</AdminResponsiveModal>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue'
import { PlusOutlined } from '@ant-design/icons-vue'
import { adminInventoryApi, type InventoryItemVO } from '@/api/admin'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { useAdminViewport } from '@/composables/useAdminViewport'
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
const { isMobile } = useAdminViewport()
const loading = ref(false)
const savingItem = ref(false)
const adjusting = ref(false)
const keyword = ref('')
const items = ref<InventoryItemVO[]>([])
const itemModalOpen = ref(false)
const adjustModalOpen = ref(false)
const adjustTarget = ref<InventoryItemVO | null>(null)
const itemFormRef = ref<FormInstance>()
const adjustFormRef = ref<FormInstance>()
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showTotal: (total: number) => `共 ${total} 条`
})
const itemForm = reactive({
itemName: '',
category: '',
unit: '',
stockQuantity: 0,
warningThreshold: 0,
status: 1
})
const adjustForm = reactive({
changeType: 'IN' as 'IN' | 'OUT',
changeQuantity: 1,
remark: ''
})
const itemRules = {
itemName: [{ required: true, message: '请输入物料名称', trigger: 'blur' }]
} as any
const adjustRules = {
changeQuantity: [{ required: true, message: '请输入调整数量', trigger: 'blur' }]
} as any
const columns = [
{ title: '物料名称', dataIndex: 'itemName', key: 'itemName' },
{ title: '分类', dataIndex: 'category', key: 'category', width: 140 },
{ title: '库存', key: 'stock', width: 140 },
{ title: '预警阈值', key: 'warning', width: 140 },
{ title: '状态', key: 'status', width: 100 },
{ title: '操作', key: 'actions', width: 130 }
]
const warningCount = computed(() => items.value.filter(item => item.warning).length)
const filteredItems = computed(() => {
const value = keyword.value.trim().toLowerCase()
if (!value) return items.value
return items.value.filter(item => [item.itemName, item.category, item.unit].join(' ').toLowerCase().includes(value))
})
const numberText = (value?: number) => Number(value || 0).toFixed(2).replace(/\.00$/, '')
const resetItemForm = () => {
Object.assign(itemForm, {
itemName: '',
category: '',
unit: '',
stockQuantity: 0,
warningThreshold: 0,
status: 1
})
}
const loadItems = async () => {
loading.value = true
try {
const result = await adminInventoryApi.listItems({
page: pagination.current,
size: pagination.pageSize
})
items.value = result.list || []
pagination.total = result.total || 0
} catch (error) {
console.error('加载库存失败:', error)
message.error('加载库存失败')
} finally {
loading.value = false
}
}
const handleTableChange = (pag: any) => {
pagination.current = pag.current || 1
pagination.pageSize = pag.pageSize || pagination.pageSize
void loadItems()
}
const openCreateModal = () => {
resetItemForm()
itemModalOpen.value = true
}
const closeItemModal = () => {
itemModalOpen.value = false
itemFormRef.value?.resetFields()
}
const saveItem = async () => {
try {
await itemFormRef.value?.validate()
savingItem.value = true
await runWithGlobalLoading(async () => {
await adminInventoryApi.saveItem({ ...itemForm })
await loadItems()
})
message.success('物料已保存')
closeItemModal()
} catch (error: any) {
if (error?.errorFields) return
console.error('保存物料失败:', error)
message.error(error?.message || '保存物料失败')
} finally {
savingItem.value = false
}
}
const openAdjustModal = (record: InventoryItemVO, changeType: 'IN' | 'OUT') => {
adjustTarget.value = record
adjustForm.changeType = changeType
adjustForm.changeQuantity = changeType === 'OUT' ? -1 : 1
adjustForm.remark = ''
adjustModalOpen.value = true
}
const closeAdjustModal = () => {
adjustModalOpen.value = false
adjustTarget.value = null
adjustFormRef.value?.resetFields()
}
const submitAdjust = async () => {
if (!adjustTarget.value) return
const quantity = Number(adjustForm.changeQuantity || 0)
if (quantity === 0) {
message.warning('调整数量不能为 0')
return
}
adjusting.value = true
try {
await runWithGlobalLoading(async () => {
await adminInventoryApi.adjustStock(adjustTarget.value!.id, {
changeType: adjustForm.changeType,
changeQuantity: quantity,
remark: adjustForm.remark.trim() || undefined
})
await loadItems()
})
message.success('库存已调整')
closeAdjustModal()
} catch (error: any) {
console.error('库存调整失败:', error)
message.error(error?.message || '库存调整失败')
} finally {
adjusting.value = false
}
}
onMounted(loadItems)
</script>
<style scoped>
.inventory {
padding: 0;
}
.inventory-alert {
margin-bottom: 16px;
}
</style>
@@ -76,6 +76,22 @@
<template v-else-if="column.key === 'actions'">
<a-space>
<a-button type="link" size="small" @click="currentOrder = record">查看</a-button>
<a-button
v-if="canManagePayments && record.paymentStatus !== 'PAID'"
type="link"
size="small"
@click="openManualPay(record)"
>
手动确认支付
</a-button>
<a-button
v-if="canViewAfterSales"
type="link"
size="small"
@click="openAfterSales(record)"
>
售后
</a-button>
<a-button
v-if="record.status === 1 && canProcessOrders"
type="primary"
@@ -129,6 +145,20 @@
</div>
<div class="admin-mobile-card__actions">
<a-button size="small" @click="currentOrder = item">查看详情</a-button>
<a-button
v-if="canManagePayments && item.paymentStatus !== 'PAID'"
size="small"
@click="openManualPay(item)"
>
确认支付
</a-button>
<a-button
v-if="canViewAfterSales"
size="small"
@click="openAfterSales(item)"
>
售后
</a-button>
<a-button
v-if="item.status === 1 && canProcessOrders"
size="small"
@@ -209,6 +239,29 @@
</div>
</template>
</AdminResponsiveModal>
<AdminResponsiveModal
v-model:open="manualPayOpen"
title="手动确认支付"
:desktop-width="560"
:confirm-loading="manualPayLoading"
@ok="submitManualPay"
@cancel="closeManualPay"
>
<a-form layout="vertical">
<a-alert
v-if="manualPayOrder"
class="order-action-alert"
type="warning"
show-icon
:message="manualPayOrder.orderNo"
:description="`将把订单标记为已支付,实付金额 ¥${moneyText(manualPayOrder.actualAmount || manualPayOrder.totalAmount)}`"
/>
<a-form-item label="确认备注">
<a-textarea v-model:value="manualPayRemark" :rows="3" :maxlength="200" placeholder="例如:线下现金已核验" />
</a-form-item>
</a-form>
</AdminResponsiveModal>
</div>
</template>
@@ -219,6 +272,7 @@
*/
import { computed, onMounted, ref } from 'vue'
import { message } from 'ant-design-vue'
import { useRouter } from 'vue-router'
/**
* Purpose: Shop supports OrdersView.vue by holding or executing the shop page or API role.
* Usage: import, call, read, or update this type from the owning page/module while preserving the surrounding loading and permission flow.
@@ -233,6 +287,7 @@ import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
const { isMobile } = useAdminViewport()
const router = useRouter()
/**
* Purpose: orders supports OrdersView.vue by holding or executing the orders 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.
@@ -250,6 +305,10 @@ const shopLoading = ref(false)
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const currentOrder = ref<any | null>(null)
const manualPayOpen = ref(false)
const manualPayLoading = ref(false)
const manualPayOrder = ref<any | null>(null)
const manualPayRemark = ref('')
/**
* Purpose: currentUserType supports OrdersView.vue by holding or executing the current user type 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.
@@ -324,6 +383,8 @@ const detailVisible = computed({
})
/** canProcessOrders is a reactive state variable used by the template and event handlers. */
const canProcessOrders = computed(() => hasPermission('order:process'))
const canManagePayments = computed(() => hasPermission('payment:manage'))
const canViewAfterSales = computed(() => hasPermission('after_sale:view'))
/** isArtist is a reactive state variable used by the template and event handlers. */
const isArtist = computed(() => currentUserType.value === 3)
/**
@@ -445,6 +506,8 @@ const statusColor = (status: number) => {
return 'default'
}
const moneyText = (value?: number) => Number(value || 0).toFixed(2)
/**
* Purpose: normalizeUserType supports OrdersView.vue by holding or executing the normalize user type 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.
@@ -530,6 +593,43 @@ const process = async (orderId: IdType, status: number) => {
}
}
const openManualPay = (order: any) => {
manualPayOrder.value = order
manualPayRemark.value = ''
manualPayOpen.value = true
}
const closeManualPay = () => {
manualPayOpen.value = false
manualPayOrder.value = null
manualPayRemark.value = ''
}
const submitManualPay = async () => {
if (!manualPayOrder.value) return
manualPayLoading.value = true
try {
await runWithGlobalLoading(async () => {
await adminOrderApi.manualConfirmPayment(manualPayOrder.value.id, manualPayRemark.value.trim() || undefined)
await loadOrders()
})
message.success('支付已确认')
closeManualPay()
} catch (error: any) {
console.error('手动确认支付失败:', error)
message.error(error?.message || '手动确认支付失败')
} finally {
manualPayLoading.value = false
}
}
const openAfterSales = (order: any) => {
router.push({
path: '/admin/after-sales',
query: { orderId: String(order.id) }
})
}
/** noop is a local helper used by this page script. */
const noop = () => {}
@@ -557,4 +657,8 @@ onMounted(async () => {
gap: 10px;
margin-bottom: 16px;
}
.order-action-alert {
margin-bottom: 16px;
}
</style>
@@ -1013,7 +1013,7 @@ const fetchProductList = async () => {
}
const nextProducts = response?.list || []
productList.value = nextProducts
pagination.total = response?.total || 0
pagination.total = Number(response?.total || 0)
const nextImageUrls = await loadImageUrls(nextProducts, requestToken)
if (nextImageUrls && isLatestRequestToken('products', requestToken)) {
@@ -0,0 +1,293 @@
<template>
<div class="schedules">
<a-page-header v-if="!isMobile" title="排班管理" sub-title="维护美甲师班次、容量和可约状态" />
<section v-else class="admin-page-intro">
<span class="admin-page-intro__eyebrow">排班</span>
<h1 class="admin-page-intro__title">排班管理</h1>
<div class="admin-page-intro__meta">
<span class="admin-page-chip">班次 {{ schedules.length }}</span>
</div>
</section>
<a-card :bordered="false">
<template #title v-if="isMobile">班次列表</template>
<template #extra>
<div class="admin-toolbar" :class="{ 'admin-toolbar--stacked': isMobile }">
<a-select
v-model:value="filters.artistId"
allow-clear
placeholder="选择美甲师"
:options="artistOptions"
:style="isMobile ? { width: '100%' } : { width: '180px' }"
@change="loadSchedules"
/>
<a-range-picker
v-model:value="filters.dateRange"
value-format="YYYY-MM-DD"
:style="isMobile ? { width: '100%' } : { width: '240px' }"
@change="loadSchedules"
/>
<a-button type="primary" @click="openCreateModal">
<template #icon>
<PlusOutlined />
</template>
新增排班
</a-button>
</div>
</template>
<a-table v-if="!isMobile" :columns="columns" :data-source="schedules" :loading="loading" row-key="id">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'artist'">{{ artistName(record.artistId) }}</template>
<template v-else-if="column.key === 'time'">{{ record.startTime }} - {{ record.endTime }}</template>
<template v-else-if="column.key === 'capacity'">{{ record.capacity ?? '-' }} / {{ record.slotMinutes ?? '-' }} 分钟</template>
<template v-else-if="column.key === 'status'">
<a-tag :color="record.status === 0 ? 'red' : 'green'">{{ scheduleStatusText(record.status) }}</a-tag>
</template>
<template v-else-if="column.key === 'actions'">
<a-button type="link" size="small" @click="openEditModal(record as ArtistScheduleVO)">编辑</a-button>
</template>
</template>
</a-table>
<AdminMobileCardList v-else :items="schedules" empty-description="暂无排班数据">
<template #item="{ item }">
<article class="admin-mobile-card">
<div class="admin-mobile-card__head">
<div class="admin-mobile-card__body">
<div class="admin-mobile-card__title">{{ artistName(item.artistId) }}</div>
<div class="admin-mobile-card__subtitle">{{ item.workDate }} {{ item.startTime }} - {{ item.endTime }}</div>
</div>
<a-tag :color="item.status === 0 ? 'red' : 'green'">{{ scheduleStatusText(item.status) }}</a-tag>
</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>容量</span>
<strong>{{ item.capacity ?? '-' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>间隔</span>
<strong>{{ item.slotMinutes ?? '-' }} 分钟</strong>
</div>
<div class="admin-mobile-card__row">
<span>备注</span>
<strong>{{ item.remark || '-' }}</strong>
</div>
</div>
<div class="admin-mobile-card__actions">
<a-button size="small" @click="openEditModal(item)">编辑</a-button>
</div>
</article>
</template>
</AdminMobileCardList>
</a-card>
<AdminResponsiveModal
v-model:open="modalOpen"
:title="editingSchedule ? '编辑排班' : '新增排班'"
:desktop-width="720"
:confirm-loading="saving"
@ok="saveSchedule"
@cancel="closeModal"
>
<a-form ref="formRef" :model="formState" :rules="rules" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
<a-form-item label="美甲师" name="artistId">
<a-select v-model:value="formState.artistId" placeholder="选择美甲师" :options="artistOptions" />
</a-form-item>
<a-form-item label="工作日期" name="workDate">
<a-date-picker v-model:value="formState.workDate" value-format="YYYY-MM-DD" style="width: 100%" />
</a-form-item>
<a-form-item label="开始时间" name="startTime">
<a-input v-model:value="formState.startTime" placeholder="09:00:00" />
</a-form-item>
<a-form-item label="结束时间" name="endTime">
<a-input v-model:value="formState.endTime" placeholder="18:00:00" />
</a-form-item>
<a-form-item label="预约间隔">
<a-input-number v-model:value="formState.slotMinutes" :min="5" :step="5" style="width: 100%" />
</a-form-item>
<a-form-item label="容量">
<a-input-number v-model:value="formState.capacity" :min="1" style="width: 100%" />
</a-form-item>
<a-form-item label="状态">
<a-select v-model:value="formState.status">
<a-select-option :value="1">可预约</a-select-option>
<a-select-option :value="0">停用</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="备注">
<a-textarea v-model:value="formState.remark" :rows="3" :maxlength="200" />
</a-form-item>
</a-form>
</AdminResponsiveModal>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue'
import { PlusOutlined } from '@ant-design/icons-vue'
import {
adminArtistScheduleApi,
adminNailArtistApi,
type ArtistScheduleRequest,
type ArtistScheduleVO,
type NailArtistInfoVO
} from '@/api/admin'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { useAdminViewport } from '@/composables/useAdminViewport'
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
const { isMobile } = useAdminViewport()
const loading = ref(false)
const saving = ref(false)
const modalOpen = ref(false)
const schedules = ref<ArtistScheduleVO[]>([])
const artists = ref<NailArtistInfoVO[]>([])
const editingSchedule = ref<ArtistScheduleVO | null>(null)
const formRef = ref<FormInstance>()
const filters = reactive({
artistId: undefined as string | undefined,
dateRange: undefined as [string, string] | undefined
})
const formState = reactive<ArtistScheduleRequest>({
artistId: undefined,
workDate: '',
startTime: '09:00:00',
endTime: '18:00:00',
slotMinutes: 30,
capacity: 1,
status: 1,
remark: ''
})
const rules = {
artistId: [{ required: true, message: '请选择美甲师', trigger: 'change' }],
workDate: [{ required: true, message: '请选择工作日期', trigger: 'change' }],
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }]
} as any
const columns = [
{ title: '美甲师', key: 'artist', width: 160 },
{ title: '工作日期', dataIndex: 'workDate', key: 'workDate', width: 140 },
{ title: '工作时段', key: 'time', width: 180 },
{ title: '容量 / 间隔', key: 'capacity', width: 140 },
{ title: '状态', key: 'status', width: 100 },
{ title: '备注', dataIndex: 'remark', key: 'remark' },
{ title: '操作', key: 'actions', width: 90 }
]
const artistOptions = computed(() => artists.value.map(artist => ({
label: artist.nickname || artist.identity || `美甲师 ${artist.userId}`,
value: String(artist.userId || artist.id)
})))
const artistName = (artistId?: unknown) => {
const artist = artists.value.find(item => String(item.userId || item.id) === String(artistId))
return artist?.nickname || artist?.identity || (artistId ? `美甲师 ${artistId}` : '-')
}
const scheduleStatusText = (status?: number) => status === 0 ? '停用' : '可预约'
const resetForm = () => {
Object.assign(formState, {
artistId: undefined,
workDate: '',
startTime: '09:00:00',
endTime: '18:00:00',
slotMinutes: 30,
capacity: 1,
status: 1,
remark: ''
})
}
const loadArtists = async () => {
try {
artists.value = await adminNailArtistApi.listNailArtists() as unknown as NailArtistInfoVO[]
} catch (error) {
console.error('加载美甲师失败:', error)
artists.value = []
}
}
const loadSchedules = async () => {
loading.value = true
try {
schedules.value = await adminArtistScheduleApi.listSchedules({
artistId: filters.artistId,
startDate: filters.dateRange?.[0],
endDate: filters.dateRange?.[1]
})
} catch (error) {
console.error('加载排班失败:', error)
message.error('加载排班失败')
} finally {
loading.value = false
}
}
const openCreateModal = () => {
editingSchedule.value = null
resetForm()
modalOpen.value = true
}
const openEditModal = (record: ArtistScheduleVO) => {
editingSchedule.value = record
Object.assign(formState, {
artistId: String(record.artistId),
workDate: record.workDate,
startTime: record.startTime,
endTime: record.endTime,
slotMinutes: record.slotMinutes ?? 30,
capacity: record.capacity ?? 1,
status: record.status ?? 1,
remark: record.remark || ''
})
modalOpen.value = true
}
const closeModal = () => {
modalOpen.value = false
formRef.value?.resetFields()
}
const saveSchedule = async () => {
try {
await formRef.value?.validate()
saving.value = true
await runWithGlobalLoading(async () => {
await adminArtistScheduleApi.saveSchedule({ ...formState })
await loadSchedules()
})
message.success('排班已保存')
closeModal()
} catch (error: any) {
if (error?.errorFields) {
return
}
console.error('保存排班失败:', error)
message.error(error?.message || '保存排班失败')
} finally {
saving.value = false
}
}
onMounted(async () => {
await loadArtists()
await loadSchedules()
})
</script>
<style scoped>
.schedules {
padding: 0;
}
</style>