提交Salon旧接口清理与安全配置基线

This commit is contained in:
2026-11-01 14:43:04 +08:00
parent f30abbc26c
commit 203dac2370
49 changed files with 73 additions and 19388 deletions
@@ -1,312 +0,0 @@
<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-button type="primary" @click="openCreateModal">
<template #icon>
<PlusOutlined />
</template>
新增活动
</a-button>
</div>
</template>
<AdminFilterPanel :active-count="activeFilterCount">
<a-select
v-model:value="statusFilter"
:options="statusOptions"
style="width: 160px"
@change="reload"
/>
<a-button @click="resetFilters">重置筛选</a-button>
</AdminFilterPanel>
<a-table
v-if="!isMobile"
:columns="columns"
:data-source="campaigns"
:loading="loading"
:pagination="pagination"
row-key="id"
:scroll="{ x: 'max-content' }"
@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 { 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 { 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 AdminFilterPanel from '@/components/admin/AdminFilterPanel.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 activeFilterCount = computed(() => statusFilter.value === 'all' ? 0 : 1)
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 resetFilters = () => {
statusFilter.value = 'all'
reload()
}
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>
@@ -1,987 +0,0 @@
<template>
<div class="coupons">
<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">优惠券 {{ couponList.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-input-search
v-model:value="searchText"
placeholder="搜索优惠券名称"
:style="isMobile ? { width: '100%' } : { width: '260px' }"
@search="handleSearch"
/>
<a-button v-if="!isMobile && hasPermission('coupon:create')" type="primary" @click="showAddModal">
<template #icon>
<PlusOutlined />
</template>
新增优惠券
</a-button>
</div>
</template>
<a-table
v-if="!isMobile"
:columns="columns"
:data-source="couponList"
:loading="loading"
:pagination="pagination"
row-key="id"
:scroll="{ x: 'max-content' }"
@change="handleTableChange"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'shop'">
{{ record.shopName || '未指定店铺' }}
</template>
<template v-else-if="column.key === 'couponType'">
<a-tag :color="record.couponType === 1 ? 'blue' : 'green'">
{{ record.couponTypeName || (record.couponType === 1 ? '折扣券' : '满减券') }}
</a-tag>
</template>
<template v-else-if="column.key === 'couponScene'">
<a-tag :color="record.couponScene === 'VIP_AUTO' ? 'gold' : 'default'">
{{ getCouponSceneText(record.couponScene) }}
</a-tag>
</template>
<template v-else-if="column.key === 'requiredVipLevel'">
{{ record.requiredVipLevel || '-' }}
</template>
<template v-else-if="column.key === 'value'">
<template v-if="record.couponType === 1">
{{ record.discountValue }} 折
</template>
<template v-else>
满 {{ record.minAmount }} 减 {{ record.reduceAmount }}
</template>
</template>
<template v-else-if="column.key === 'status'">
<a-tag :color="getStatusColor(record.status || 1)">
{{ record.statusName || '未知' }}
</a-tag>
</template>
<template v-else-if="column.key === 'actions'">
<a-space wrap>
<a-button v-if="hasPermission('coupon:view')" type="link" size="small" @click="showViewModal(record)">
查看
</a-button>
<a-button v-if="hasPermission('coupon:edit')" type="link" size="small" @click="showEditModal(record)">
编辑
</a-button>
<a-button
v-if="hasPermission('coupon:assign') && !isVipAutoCoupon(record) && record.status === 1"
type="link"
size="small"
@click="showDistributeModal(record)"
>
发放
</a-button>
<a-button
v-if="hasPermission('coupon:delete') && record.status !== 2"
type="link"
size="small"
danger
@click="handleDelete(record)"
>
删除
</a-button>
</a-space>
</template>
</template>
</a-table>
<AdminMobileCardList v-else :items="couponList" 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.couponName }}</div>
<div class="admin-mobile-card__subtitle">{{ item.shopName || '未指定店铺' }}</div>
</div>
<a-tag :color="getStatusColor(item.status || 1)">
{{ item.statusName || '未知' }}
</a-tag>
</div>
<div class="admin-mobile-card__rows">
<div class="admin-mobile-card__row">
<span>类型</span>
<strong>{{ item.couponType === 1 ? '折扣券' : '满减券' }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>场景</span>
<strong>{{ getCouponSceneText(item.couponScene) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>优惠值</span>
<strong>{{ getCouponValueText(item) }}</strong>
</div>
<div class="admin-mobile-card__row">
<span>剩余数量</span>
<strong>{{ item.remainingCount ?? '-' }}</strong>
</div>
</div>
<div class="admin-mobile-card__actions">
<a-button v-if="hasPermission('coupon:view')" size="small" @click="showViewModal(item)">查看</a-button>
<a-button v-if="hasPermission('coupon:edit')" size="small" @click="showEditModal(item)">编辑</a-button>
<a-button
v-if="hasPermission('coupon:assign') && !isVipAutoCoupon(item) && item.status === 1"
size="small"
@click="showDistributeModal(item)"
>
发放
</a-button>
<a-button
v-if="hasPermission('coupon:delete') && item.status !== 2"
size="small"
danger
@click="handleDelete(item)"
>
删除
</a-button>
</div>
</article>
</template>
</AdminMobileCardList>
</a-card>
<AdminResponsiveModal
v-model:open="modalVisible"
:title="isEdit ? '编辑优惠券' : '新增优惠券'"
:desktop-width="820"
:confirm-loading="modalLoading"
@ok="handleModalOk"
@cancel="handleModalCancel"
>
<DraftActions
:saved-at="draftSavedAt"
@save="handleSaveDraft"
@clear="handleClearDraft"
/>
<a-form
ref="formRef"
:model="formState"
:rules="formRules"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 16 }"
>
<a-form-item label="优惠券名称" name="couponName">
<a-input v-model:value="formState.couponName" placeholder="请输入优惠券名称" />
</a-form-item>
<a-form-item label="所属店铺" name="shopId">
<a-select
v-model:value="formState.shopId"
placeholder="请选择所属店铺"
:loading="loadingShops"
:disabled="currentUserInfo?.type === 2"
>
<a-select-option v-for="shop in shops" :key="shop.id" :value="shop.id">
{{ shop.shopName }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="优惠券类型" name="couponType">
<a-select v-model:value="formState.couponType" placeholder="请选择优惠券类型">
<a-select-option :value="1">折扣券</a-select-option>
<a-select-option :value="2">满减券</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="优惠场景" name="couponScene">
<a-select v-model:value="formState.couponScene" placeholder="请选择优惠场景">
<a-select-option value="GENERAL">普通券</a-select-option>
<a-select-option value="VIP_AUTO">VIP 自动券</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="自动匹配">
<a-switch :checked="formState.autoMatch === 1" @change="(checked: any) => handleAutoMatchChange(checked === true)" />
</a-form-item>
<a-form-item v-if="isVipAutoForm" label="所需 VIP 等级" name="requiredVipLevel">
<a-select v-model:value="formState.requiredVipLevel" placeholder="请选择 VIP 等级">
<a-select-option v-for="level in vipLevelOptions" :key="level" :value="level">{{ level }}</a-select-option>
</a-select>
</a-form-item>
<a-form-item v-if="formState.couponType === 1" label="折扣值" name="discountValue">
<a-input-number v-model:value="formState.discountValue" :min="0.1" :max="9.9" :step="0.1" style="width: 100%" />
</a-form-item>
<a-form-item v-if="formState.couponType === 2" label="最低消费" name="minAmount">
<a-input-number v-model:value="formState.minAmount" :min="0" :step="0.01" style="width: 100%" />
</a-form-item>
<a-form-item v-if="formState.couponType === 2" label="减免金额" name="reduceAmount">
<a-input-number v-model:value="formState.reduceAmount" :min="0" :step="0.01" style="width: 100%" />
</a-form-item>
<a-form-item label="总数量" name="totalCount">
<a-input-number v-model:value="formState.totalCount" :min="1" style="width: 100%" />
</a-form-item>
<a-form-item label="开始时间" name="startTime">
<a-date-picker v-model:value="formState.startTime" show-time format="YYYY-MM-DD HH:mm:ss" popup-class-name="jayucloud-salon-date-picker-panel jayucloud-salon-date-time-panel" style="width: 100%" />
</a-form-item>
<a-form-item label="结束时间" name="endTime">
<a-date-picker v-model:value="formState.endTime" show-time format="YYYY-MM-DD HH:mm:ss" popup-class-name="jayucloud-salon-date-picker-panel jayucloud-salon-date-time-panel" style="width: 100%" />
</a-form-item>
<a-form-item label="可用标签" name="availableTagIds">
<a-select v-model:value="formState.availableTagIds" mode="multiple" placeholder="请选择可用标签">
<a-select-option v-for="tag in tagList" :key="tag.id" :value="tag.id" :disabled="formState.unavailableTagIds.includes(Number(tag.id))">
{{ tag.tagName }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="不可用标签" name="unavailableTagIds">
<a-select v-model:value="formState.unavailableTagIds" mode="multiple" placeholder="请选择不可用标签">
<a-select-option v-for="tag in tagList" :key="tag.id" :value="tag.id" :disabled="formState.availableTagIds.includes(Number(tag.id))">
{{ tag.tagName }}
</a-select-option>
</a-select>
</a-form-item>
</a-form>
</AdminResponsiveModal>
<AdminResponsiveModal
v-model:open="viewModalVisible"
title="查看优惠券详情"
:footer="null"
:desktop-width="760"
@cancel="viewModalVisible = false"
>
<a-descriptions bordered :column="1" size="small">
<a-descriptions-item label="优惠券名称">{{ currentCoupon?.couponName || '-' }}</a-descriptions-item>
<a-descriptions-item label="所属店铺">{{ currentCoupon?.shopName || '-' }}</a-descriptions-item>
<a-descriptions-item label="优惠券类型">{{ currentCoupon?.couponType === 1 ? '折扣券' : '满减券' }}</a-descriptions-item>
<a-descriptions-item label="优惠场景">{{ getCouponSceneText(currentCoupon?.couponScene) }}</a-descriptions-item>
<a-descriptions-item label="所需 VIP 等级">{{ currentCoupon?.requiredVipLevel || '-' }}</a-descriptions-item>
<a-descriptions-item label="自动匹配">{{ currentCoupon?.autoMatch === 1 ? '是' : '否' }}</a-descriptions-item>
<a-descriptions-item label="优惠信息">{{ getCouponValueText(currentCoupon) }}</a-descriptions-item>
<a-descriptions-item label="总数量">{{ currentCoupon?.totalCount ?? '-' }}</a-descriptions-item>
<a-descriptions-item label="已使用">{{ currentCoupon?.usedCount ?? '-' }}</a-descriptions-item>
<a-descriptions-item label="开始时间">{{ currentCoupon?.startTime || '-' }}</a-descriptions-item>
<a-descriptions-item label="结束时间">{{ currentCoupon?.endTime || '-' }}</a-descriptions-item>
</a-descriptions>
</AdminResponsiveModal>
<AdminResponsiveModal
v-model:open="distributeModalVisible"
title="发放优惠券"
:desktop-width="760"
:confirm-loading="distributeLoading"
@ok="handleDistributeOk"
@cancel="handleDistributeCancel"
>
<a-form
ref="distributeFormRef"
:model="distributeFormState"
:rules="distributeFormRules"
:label-col="{ span: 6 }"
:wrapper-col="{ span: 16 }"
>
<a-form-item label="优惠券">
<a-input v-model:value="distributeFormState.couponName" disabled />
</a-form-item>
<a-form-item label="选择用户" name="userIds">
<a-select
v-model:value="distributeFormState.userIds"
mode="multiple"
placeholder="请选择要发放的用户"
>
<a-select-option v-for="user in userList" :key="user.id" :value="user.id">
{{ user.nickname }}({{ user.account }})
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="发放数量" name="quantity">
<a-input-number v-model:value="distributeFormState.quantity" :min="1" style="width: 100%" />
</a-form-item>
</a-form>
</AdminResponsiveModal>
<AdminMobileFab
:visible="isMobile && hasPermission('coupon:create') && !modalVisible && !viewModalVisible && !distributeModalVisible"
label="新增优惠券"
@click="showAddModal"
/>
</div>
</template>
<script setup lang="ts">
/**
* CouponsView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { message, Modal } from 'ant-design-vue'
import type { FormInstance } from 'ant-design-vue'
import { PlusOutlined } from '@ant-design/icons-vue'
import DraftActions from '@/components/DraftActions.vue'
/**
* Purpose: Dayjs supports CouponsView.vue by holding or executing the dayjs 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 dayjs, { type Dayjs } from 'dayjs'
import {
adminCouponApi,
adminVipRechargePlanApi,
adminShopApi,
adminTagApi,
adminUserApi,
type Coupon,
type Shop,
type Tag,
type UserVO
} from '@/api/admin'
import { buildDraftStorageKey, clearDraftRecord, loadDraftRecord, saveDraftRecord } from '@/utils/form-draft'
import { usePermission } from '@/utils/permission'
import { runWithGlobalLoading } from '@/utils/action-loading'
import { useAdminViewport } from '@/composables/useAdminViewport'
import AdminMobileCardList from '@/components/admin/AdminMobileCardList.vue'
import AdminMobileFab from '@/components/admin/AdminMobileFab.vue'
import AdminResponsiveModal from '@/components/admin/AdminResponsiveModal.vue'
const { hasPermission, loadUserPermissions } = usePermission()
const { isMobile } = useAdminViewport()
/** currentUserInfo is a local helper used by this page script. */
const currentUserInfo = (() => {
try {
const userInfoStr = localStorage.getItem('adminUserInfo')
return userInfoStr ? JSON.parse(userInfoStr) : null
} catch (error) {
console.error('获取当前用户信息失败', error)
return null
}
})()
/**
* Purpose: CouponFormState supports CouponsView.vue by holding or executing the coupon form state page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
interface CouponFormState {
couponCode: string
couponName: string
couponType: number
discountValue?: number
minAmount?: number
reduceAmount?: number
totalCount: number
startTime?: Dayjs
endTime?: Dayjs
availableTagIds: number[]
unavailableTagIds: number[]
shopId?: number
couponScene: string
requiredVipLevel?: string
autoMatch: number
}
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/** loadingShops is a reactive state variable used by the template and event handlers. */
const loadingShops = ref(false)
/** modalVisible is a reactive state variable used by the template and event handlers. */
const modalVisible = ref(false)
/** viewModalVisible is a reactive state variable used by the template and event handlers. */
const viewModalVisible = ref(false)
/** modalLoading is a reactive state variable used by the template and event handlers. */
const modalLoading = ref(false)
/** isEdit is a reactive state variable used by the template and event handlers. */
const isEdit = ref(false)
/** searchText is a reactive state variable used by the template and event handlers. */
const searchText = ref('')
/**
* Purpose: formRef supports CouponsView.vue by holding or executing the form ref 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 formRef = ref<FormInstance>()
/**
* Purpose: distributeFormRef supports CouponsView.vue by holding or executing the distribute form ref 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 distributeFormRef = ref<FormInstance>()
/**
* Purpose: currentCoupon supports CouponsView.vue by holding or executing the current coupon 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 currentCoupon = ref<Coupon | null>(null)
/**
* Purpose: draftSavedAt supports CouponsView.vue by holding or executing the draft saved at 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 draftSavedAt = ref<number | null>(null)
/**
* Purpose: couponList supports CouponsView.vue by holding or executing the coupon list 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 couponList = ref<Coupon[]>([])
/**
* Purpose: tagList supports CouponsView.vue by holding or executing the tag list 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 tagList = ref<Tag[]>([])
/**
* Purpose: userList supports CouponsView.vue by holding or executing the user list 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 userList = ref<UserVO[]>([])
/**
* Purpose: shops supports CouponsView.vue by holding or executing the shops 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 shops = ref<Shop[]>([])
/**
* Purpose: vipLevelOptions supports CouponsView.vue by holding or executing the vip level options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const vipLevelOptions = ref<string[]>(['普通', '青铜', '白银', '黄金'])
/** distributeModalVisible is a reactive state variable used by the template and event handlers. */
const distributeModalVisible = ref(false)
/** distributeLoading is a reactive state variable used by the template and event handlers. */
const distributeLoading = ref(false)
/**
* Purpose: currentDistributeCoupon supports CouponsView.vue by holding or executing the current distribute coupon 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 currentDistributeCoupon = ref<Coupon | null>(null)
/**
* Purpose: pagination supports CouponsView.vue by holding or executing the pagination 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 pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (total: number) => `共 ${total} 条`
})
/**
* Purpose: formState supports CouponsView.vue by holding or executing the form state 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 formState = reactive<CouponFormState>({
couponCode: '',
couponName: '',
couponType: 1,
discountValue: 9.5,
minAmount: 100,
reduceAmount: 20,
totalCount: 100,
startTime: dayjs(),
endTime: dayjs().add(30, 'day'),
availableTagIds: [],
unavailableTagIds: [],
shopId: undefined,
couponScene: 'GENERAL',
requiredVipLevel: undefined,
autoMatch: 0
})
/**
* Purpose: distributeFormState supports CouponsView.vue by holding or executing the distribute form state 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 distributeFormState = reactive({
couponName: '',
userIds: [] as number[],
quantity: 1
})
/**
* Purpose: formRules supports CouponsView.vue by holding or executing the form rules 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 formRules = {
couponName: [{ required: true, message: '请输入优惠券名称', trigger: 'blur' }],
couponType: [{ required: true, message: '请选择优惠券类型', trigger: 'change' }],
couponScene: [{ required: true, message: '请选择优惠场景', trigger: 'change' }],
requiredVipLevel: [{ required: true, message: '请选择所需 VIP 等级', trigger: 'change' }],
totalCount: [{ required: true, message: '请输入优惠券总数量', trigger: 'blur' }],
startTime: [{ required: true, message: '请选择开始时间', trigger: 'change' }],
endTime: [{ required: true, message: '请选择结束时间', trigger: 'change' }],
shopId: [{ required: true, message: '请选择所属店铺', trigger: 'change' }]
} as any
/**
* Purpose: distributeFormRules supports CouponsView.vue by holding or executing the distribute form rules 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 distributeFormRules = {
userIds: [{ required: true, message: '请选择要发放的用户', trigger: 'change' }],
quantity: [{ required: true, message: '请输入发放数量', trigger: 'blur' }]
} as any
/**
* Purpose: columns supports CouponsView.vue by holding or executing the columns 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 columns = [
{ title: '优惠券名称', dataIndex: 'couponName', key: 'couponName' },
{ title: '所属店铺', key: 'shop', width: 140 },
{ title: '类型', key: 'couponType', width: 100 },
{ title: '场景', key: 'couponScene', width: 120 },
{ title: '所需 VIP', key: 'requiredVipLevel', width: 110 },
{ title: '优惠信息', key: 'value', width: 170 },
{ title: '总数量', dataIndex: 'totalCount', key: 'totalCount', width: 90 },
{ title: '已使用', dataIndex: 'usedCount', key: 'usedCount', width: 90 },
{ title: '剩余', dataIndex: 'remainingCount', key: 'remainingCount', width: 90 },
{ title: '状态', key: 'status', width: 100 },
{ title: '操作', key: 'actions', width: 180, fixed: 'right' as const }
]
/** isVipAutoForm is a reactive state variable used by the template and event handlers. */
const isVipAutoForm = computed(() => formState.couponScene === 'VIP_AUTO' || formState.autoMatch === 1)
/** getStatusColor is a local helper used by this page script. */
const getStatusColor = (status: number) => {
switch (status) {
case 1:
return 'green'
case 2:
return 'red'
case 3:
return 'orange'
default:
return 'default'
}
}
/** getCouponSceneText is a local helper used by this page script. */
const getCouponSceneText = (scene?: string) => {
if (scene === 'VIP_AUTO') {
return 'VIP 自动券'
}
return '普通券'
}
/** isVipAutoCoupon is a local helper used by this page script. */
const isVipAutoCoupon = (coupon: any) => coupon?.couponScene === 'VIP_AUTO' || coupon?.autoMatch === 1
/** getCouponValueText is a local helper used by this page script. */
const getCouponValueText = (coupon: Coupon | null) => {
if (!coupon) {
return '-'
}
return coupon.couponType === 1
? `${coupon.discountValue} 折`
: `满 ${coupon.minAmount} 减 ${coupon.reduceAmount}`
}
/** resetFormState is a local helper used by this page script. */
const resetFormState = () => {
Object.assign(formState, {
couponCode: '',
couponName: '',
couponType: 1,
discountValue: 9.5,
minAmount: 100,
reduceAmount: 20,
totalCount: 100,
startTime: dayjs(),
endTime: dayjs().add(30, 'day'),
availableTagIds: [],
unavailableTagIds: [],
shopId: currentUserInfo?.shopId || undefined,
couponScene: 'GENERAL',
requiredVipLevel: undefined,
autoMatch: 0
})
}
/** getDraftKey is a local helper used by this page script. */
const getDraftKey = () => buildDraftStorageKey('admin-coupons', isEdit.value ? 'edit' : 'create', currentCoupon.value?.id ?? 'new')
/** buildDraftPayload is a local helper used by this page script. */
const buildDraftPayload = () => ({
couponCode: formState.couponCode,
couponName: formState.couponName,
couponType: formState.couponType,
discountValue: formState.discountValue,
minAmount: formState.minAmount,
reduceAmount: formState.reduceAmount,
totalCount: formState.totalCount,
startTime: formState.startTime?.format('YYYY-MM-DDTHH:mm:ss'),
endTime: formState.endTime?.format('YYYY-MM-DDTHH:mm:ss'),
availableTagIds: [...formState.availableTagIds],
unavailableTagIds: [...formState.unavailableTagIds],
shopId: formState.shopId,
couponScene: formState.couponScene,
requiredVipLevel: formState.requiredVipLevel,
autoMatch: formState.autoMatch
})
/** restoreDraft is a local helper used by this page script. */
const restoreDraft = () => {
const draft = loadDraftRecord<ReturnType<typeof buildDraftPayload>>(getDraftKey())
if (!draft) {
draftSavedAt.value = null
return
}
Object.assign(formState, {
...draft.payload,
startTime: draft.payload.startTime ? dayjs(draft.payload.startTime) : undefined,
endTime: draft.payload.endTime ? dayjs(draft.payload.endTime) : undefined
})
draftSavedAt.value = draft.savedAt
message.success('已恢复暂存内容')
}
/** handleSaveDraft is a local helper used by this page script. */
const handleSaveDraft = () => {
const draft = saveDraftRecord(getDraftKey(), buildDraftPayload())
draftSavedAt.value = draft.savedAt
message.success('已暂存到本地')
}
/** handleClearDraft is a local helper used by this page script. */
const handleClearDraft = (showMessage = true) => {
clearDraftRecord(getDraftKey())
draftSavedAt.value = null
if (showMessage) {
message.success('已清除暂存')
}
}
/**
* Purpose: isSameTagSelection supports CouponsView.vue by holding or executing the is same tag selection 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 isSameTagSelection = (left: number[], right: number[]) =>
left.length === right.length && left.every((id, index) => Number(id) === Number(right[index]))
/**
* Purpose: removeSelectedTags supports CouponsView.vue by holding or executing the remove selected tags 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 removeSelectedTags = (target: number[], selected: number[]) => {
const selectedIds = new Set(selected.map(Number))
return target.filter(id => !selectedIds.has(Number(id)))
}
watch(
() => formState.couponScene,
value => {
if (value === 'VIP_AUTO') {
formState.autoMatch = 1
if (!formState.requiredVipLevel) {
formState.requiredVipLevel = vipLevelOptions.value.find(level => level !== '普通') || vipLevelOptions.value[0]
}
} else {
formState.autoMatch = 0
formState.requiredVipLevel = undefined
}
}
)
watch(
() => formState.availableTagIds.slice(),
value => {
const nextUnavailableTagIds = removeSelectedTags(formState.unavailableTagIds, value)
if (!isSameTagSelection(formState.unavailableTagIds, nextUnavailableTagIds)) {
formState.unavailableTagIds = nextUnavailableTagIds
}
}
)
watch(
() => formState.unavailableTagIds.slice(),
value => {
const nextAvailableTagIds = removeSelectedTags(formState.availableTagIds, value)
if (!isSameTagSelection(formState.availableTagIds, nextAvailableTagIds)) {
formState.availableTagIds = nextAvailableTagIds
}
}
)
/** handleAutoMatchChange is a local helper used by this page script. */
const handleAutoMatchChange = (checked: boolean) => {
formState.autoMatch = checked ? 1 : 0
formState.couponScene = checked ? 'VIP_AUTO' : 'GENERAL'
}
/** fetchCoupons is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchCoupons = async () => {
loading.value = true
try {
const shopId = currentUserInfo?.shopId || undefined
const coupons = await adminCouponApi.listAllCoupons(shopId) as unknown as Coupon[]
const list = Array.isArray(coupons) ? coupons : []
const keyword = searchText.value.trim()
couponList.value = keyword
? list.filter(item => (item.couponName || '').includes(keyword))
: list
pagination.total = couponList.value.length
} catch (error) {
console.error('获取优惠券列表失败:', error)
message.error('获取优惠券列表失败')
} finally {
loading.value = false
}
}
/** fetchTags is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchTags = async () => {
try {
const tags = await adminTagApi.listAllTags() as unknown as Tag[]
tagList.value = tags || []
} catch (error) {
console.error('获取标签列表失败:', error)
}
}
/** fetchShops is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchShops = async () => {
loadingShops.value = true
try {
const shopList = await adminShopApi.listAllShops() as unknown as Shop[]
shops.value = shopList || []
} catch (error) {
console.error('获取店铺列表失败:', error)
} finally {
loadingShops.value = false
}
}
/** fetchUsers is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const fetchUsers = async () => {
try {
const params: Record<string, unknown> = { page: 1, size: 200 }
if (currentUserInfo?.shopId) {
params.shopId = currentUserInfo.shopId
}
const result = await adminUserApi.listUsers(params as any)
userList.value = result.list || []
} catch (error) {
console.error('获取用户列表失败:', error)
userList.value = []
}
}
/** handleSearch is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleSearch = async () => {
pagination.current = 1
await runWithGlobalLoading(() => fetchCoupons())
}
/** handleTableChange is a local helper used by this page script. */
const handleTableChange = (pag: any) => {
pagination.current = pag.current || 1
pagination.pageSize = pag.pageSize || pagination.pageSize
}
/** showAddModal is a local helper used by this page script. */
const showAddModal = () => {
isEdit.value = false
currentCoupon.value = null
resetFormState()
restoreDraft()
modalVisible.value = true
}
/** showEditModal is a local helper used by this page script. */
const showEditModal = (record: any) => {
isEdit.value = true
currentCoupon.value = record
Object.assign(formState, {
couponCode: record.couponCode || '',
couponName: record.couponName || '',
couponType: record.couponType || 1,
discountValue: record.discountValue ? Number(record.discountValue) : 9.5,
minAmount: record.minAmount ? Number(record.minAmount) : 100,
reduceAmount: record.reduceAmount ? Number(record.reduceAmount) : 20,
totalCount: record.totalCount || 100,
startTime: record.startTime ? dayjs(record.startTime) : undefined,
endTime: record.endTime ? dayjs(record.endTime) : undefined,
availableTagIds: record.availableTags?.map((tag: Tag) => tag.id) || [],
unavailableTagIds: record.unavailableTags?.map((tag: Tag) => tag.id) || [],
shopId: record.shopId,
couponScene: record.couponScene || 'GENERAL',
requiredVipLevel: record.requiredVipLevel || undefined,
autoMatch: record.autoMatch || 0
})
restoreDraft()
modalVisible.value = true
}
/** showViewModal is a local helper used by this page script. */
const showViewModal = (record: any) => {
currentCoupon.value = record
viewModalVisible.value = true
}
/** buildCouponPayload is a local helper used by this page script. */
const buildCouponPayload = () => ({
couponCode: formState.couponCode,
couponName: formState.couponName,
couponType: formState.couponType,
discountValue: formState.couponType === 1 ? formState.discountValue : undefined,
minAmount: formState.couponType === 2 ? formState.minAmount : undefined,
reduceAmount: formState.couponType === 2 ? formState.reduceAmount : undefined,
totalCount: formState.totalCount,
startTime: formState.startTime?.format('YYYY-MM-DDTHH:mm:ss'),
endTime: formState.endTime?.format('YYYY-MM-DDTHH:mm:ss'),
availableTagIds: formState.availableTagIds,
unavailableTagIds: formState.unavailableTagIds,
shopId: formState.shopId,
couponScene: formState.couponScene,
requiredVipLevel: isVipAutoForm.value ? formState.requiredVipLevel : undefined,
autoMatch: isVipAutoForm.value ? 1 : 0
})
/** handleModalOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleModalOk = async () => {
try {
await formRef.value?.validate()
modalLoading.value = true
await runWithGlobalLoading(async () => {
const payload = buildCouponPayload()
if (isEdit.value && currentCoupon.value) {
await adminCouponApi.updateCoupon(currentCoupon.value.id, payload)
message.success('更新成功')
} else {
await adminCouponApi.createCoupon(payload)
message.success('创建成功')
}
handleClearDraft(false)
modalVisible.value = false
formRef.value?.resetFields()
await fetchCoupons()
})
} catch (error: any) {
console.error('保存优惠券失败:', error)
message.error(error.message || '操作失败')
} finally {
modalLoading.value = false
}
}
/** handleModalCancel is a local helper used by this page script. */
const handleModalCancel = () => {
modalVisible.value = false
formRef.value?.resetFields()
resetFormState()
}
/** handleDelete is a local helper used by this page script. */
const handleDelete = (record: any) => {
Modal.confirm({
title: '确认删除',
content: `确定要删除优惠券 ${record.couponName} 吗?`,
async onOk() {
try {
await runWithGlobalLoading(async () => {
await adminCouponApi.deleteCoupon(record.id)
message.success('删除成功')
await fetchCoupons()
})
} catch (error) {
console.error('删除优惠券失败:', error)
message.error('删除失败')
}
}
})
}
/** showDistributeModal is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const showDistributeModal = async (record: any) => {
currentDistributeCoupon.value = record
distributeFormState.couponName = record.couponName
distributeFormState.userIds = []
distributeFormState.quantity = 1
await runWithGlobalLoading(() => fetchUsers())
distributeModalVisible.value = true
}
/** handleDistributeOk is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const handleDistributeOk = async () => {
if (!currentDistributeCoupon.value) {
return
}
const couponId = currentDistributeCoupon.value.id
if (isVipAutoCoupon(currentDistributeCoupon.value)) {
message.warning('VIP 自动券为系统模板券,不能手动发放')
return
}
try {
await distributeFormRef.value?.validate()
distributeLoading.value = true
await runWithGlobalLoading(async () => {
await adminCouponApi.distributeCoupon({
couponId,
userIds: distributeFormState.userIds,
quantity: distributeFormState.quantity
})
message.success('发放成功')
distributeModalVisible.value = false
})
} catch (error: any) {
console.error('发放优惠券失败:', error)
message.error(error.message || '发放失败')
} finally {
distributeLoading.value = false
}
}
/** handleDistributeCancel is a local helper used by this page script. */
const handleDistributeCancel = () => {
distributeModalVisible.value = false
distributeFormRef.value?.resetFields()
}
/**
* Purpose: fetchVipLevelOptions supports CouponsView.vue by holding or executing the fetch vip level options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const fetchVipLevelOptions = async () => {
try {
const levels = await adminVipRechargePlanApi.listVipLevelOptions(currentUserInfo?.shopId)
if (Array.isArray(levels) && levels.length) {
vipLevelOptions.value = ['普通', ...levels.filter(level => level !== '普通')]
}
} catch (error) {
console.error('VIP 等级选项加载失败:', error)
}
}
onMounted(async () => {
await loadUserPermissions()
await Promise.all([fetchTags(), fetchShops(), fetchCoupons(), fetchVipLevelOptions()])
})
</script>
<style scoped>
.coupons {
padding: 0;
}
</style>
@@ -349,186 +349,6 @@
</AdminResponsiveModal>
<AdminResponsiveModal
v-model:open="assetModalVisible"
title="余额 / VIP 管理"
:desktop-width="960"
:footer="null"
@cancel="handleAssetModalCancel"
>
<a-spin :spinning="assetLoading">
<div v-if="assetTargetUser" class="asset-modal">
<a-alert
:message="`${assetTargetUser.nickname}(${assetTargetUser.account})`"
:description="getShopDisplay(assetTargetUser) ? `所属店铺:${getShopDisplay(assetTargetUser)}` : '未绑定店铺'"
type="info"
show-icon
style="margin-bottom: 16px"
/>
<a-row :gutter="16" class="asset-summary">
<a-col :span="8">
<a-card size="small" title="当前余额">
<div class="summary-value">¥{{ formatMoney(assetData?.balance) }}</div>
<div class="summary-sub">累计充值:¥{{ formatMoney(assetData?.totalRechargeAmount) }}</div>
</a-card>
</a-col>
<a-col :span="8">
<a-card size="small" title="VIP 状态">
<div class="summary-value">{{ assetData?.vipLevel || '普通' }}</div>
<div class="summary-sub">
{{ assetData?.manualOverride ? '当前为手工指定' : '当前按累计充值自动判级' }}
</div>
</a-card>
</a-col>
<a-col :span="8">
<a-card size="small" title="最近充值">
<div class="summary-value">{{ formatDate(assetData?.lastRechargeTime) }}</div>
<div class="summary-sub">权益说明:{{ assetData?.benefitInfo || '-' }}</div>
</a-card>
</a-col>
</a-row>
<a-row :gutter="16" class="asset-actions">
<a-col :span="12">
<a-card size="small" title="余额变动">
<DraftActions
:saved-at="balanceDraftSavedAt"
@save="handleSaveBalanceDraft"
@clear="handleClearBalanceDraft"
/>
<a-form layout="vertical">
<a-form-item label="变动场景">
<a-select v-model:value="balanceForm.changeScene">
<a-select-option value="RECHARGE">充值</a-select-option>
<a-select-option value="MANUAL_ADD">手工增加余额</a-select-option>
<a-select-option value="MANUAL_DEDUCT">手工扣减余额</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="变动金额">
<a-input-number
v-model:value="balanceForm.amount"
:min="0.01"
:precision="2"
style="width: 100%"
placeholder="请输入金额"
/>
</a-form-item>
<a-form-item label="关联系统订单 ID(可选)">
<a-input-number
v-model:value="balanceForm.relatedOrderId"
:min="1"
:precision="0"
style="width: 100%"
placeholder="如有系统订单可填写"
/>
</a-form-item>
<a-form-item label="外部单号(扣减时二选一)">
<a-input
v-model:value="balanceForm.externalOrderNo"
placeholder="没有系统订单时请填写外部单号"
/>
</a-form-item>
<a-form-item label="备注">
<a-textarea
v-model:value="balanceForm.remark"
:rows="3"
placeholder="请输入备注"
/>
</a-form-item>
<a-button
v-if="hasPermission('user:balance:manage')"
type="primary"
:loading="assetSaving"
@click="handleBalanceChange"
>
提交余额变动
</a-button>
<a-typography-text v-else type="secondary">
当前账号只有查看权限,不能调整余额。
</a-typography-text>
</a-form>
</a-card>
</a-col>
<a-col :span="12">
<a-card size="small" title="VIP 管理">
<DraftActions
:saved-at="vipDraftSavedAt"
@save="handleSaveVipDraft"
@clear="handleClearVipDraft"
/>
<a-form layout="vertical">
<a-form-item label="目标等级">
<a-select v-model:value="vipForm.vipLevel">
<a-select-option v-for="level in vipLevelOptions" :key="level" :value="level">{{ level }}</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="备注">
<a-textarea
v-model:value="vipForm.remark"
:rows="3"
placeholder="可填写手工调整原因"
/>
</a-form-item>
<a-space>
<a-button
v-if="hasPermission('user:vip:manage')"
type="primary"
:loading="assetSaving"
@click="handleVipOverride"
>
手工设置 VIP
</a-button>
<a-button
v-if="hasPermission('user:vip:manage')"
:loading="assetSaving"
@click="handleVipRecalculate"
>
恢复自动判级
</a-button>
</a-space>
<div class="vip-note">
{{ assetData?.manualOverride ? '当前处于手工指定状态。' : '当前按累计充值自动判级。' }}
</div>
</a-form>
</a-card>
</a-col>
</a-row>
<a-card size="small" title="余额流水" class="history-card">
<a-table
:columns="historyColumns"
:data-source="balanceHistory"
:pagination="false"
size="small"
row-key="id"
:scroll="{ x: 'max-content', y: 320 }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'amount'">
<span :class="Number(record.amount) >= 0 ? 'amount-plus' : 'amount-minus'">
{{ Number(record.amount) >= 0 ? '+' : '' }}{{ formatMoney(record.amount) }}
</span>
</template>
<template v-else-if="column.key === 'changeScene'">
{{ getSceneText(record.changeScene) }}
</template>
<template v-else-if="column.key === 'balanceRange'">
{{ formatMoney(record.beforeBalance) }} -> {{ formatMoney(record.afterBalance) }}
</template>
<template v-else-if="column.key === 'relatedOrder'">
{{ record.relatedOrderNo || record.externalOrderNo || '-' }}
</template>
<template v-else-if="column.key === 'changeTime'">
{{ formatDate(record.changeTime) }}
</template>
</template>
</a-table>
</a-card>
</div>
</a-spin>
</AdminResponsiveModal>
<AdminMobileFab
:visible="isMobile && canCreateUser && !modalVisible && !viewModalVisible && !assetModalVisible"
label="新增店长"
@@ -1,189 +0,0 @@
<template>
<div class="admin-page">
<div class="page-head">
<div>
<h2>VIP 充值配置</h2>
<p>这里只配置展示档位,不会创建支付订单或修改余额。</p>
</div>
<a-button type="primary" @click="openCreate">新增档位</a-button>
</div>
<a-table :columns="columns" :data-source="plans" :loading="loading" row-key="id" :scroll="{ x: 'max-content' }">
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'amount'">
充 {{ money(record.rechargeAmount) }} 送 {{ money(record.giftAmount) }}
</template>
<template v-else-if="column.key === 'status'">
<a-switch :checked="record.status === 1" @change="(checked: any) => toggleStatus(record as VipRechargePlanVO, Boolean(checked))" />
</template>
<template v-else-if="column.key === 'action'">
<a-button size="small" @click="openEdit(record as VipRechargePlanVO)">编辑</a-button>
</template>
</template>
</a-table>
<a-modal v-model:open="formOpen" :title="editingId ? '编辑档位' : '新增档位'" :mask-closable="false" @ok="submit" :confirm-loading="saving">
<a-form layout="vertical">
<a-form-item label="所属店铺">
<a-select v-model:value="form.shopId" :options="shopOptions" allow-clear placeholder="店长默认当前店铺" />
</a-form-item>
<a-form-item label="标题">
<a-input v-model:value="form.title" />
</a-form-item>
<a-form-item label="充值金额">
<a-input-number v-model:value="form.rechargeAmount" :min="0" :precision="2" style="width: 100%" />
</a-form-item>
<a-form-item label="赠送金额">
<a-input-number v-model:value="form.giftAmount" :min="0" :precision="2" style="width: 100%" />
</a-form-item>
<a-form-item label="对应 VIP 等级">
<a-input v-model:value="form.vipLevel" placeholder="如 青铜 / 白银 / 黄金,也可以输入自定义等级" />
<div class="level-shortcuts">
<a-tag v-for="level in vipLevelOptions" :key="level" @click="form.vipLevel = level">{{ level }}</a-tag>
</div>
</a-form-item>
<a-form-item label="展示说明">
<a-textarea v-model:value="form.description" :rows="3" />
</a-form-item>
<a-form-item label="排序">
<a-input-number v-model:value="form.sortOrder" style="width: 100%" />
</a-form-item>
</a-form>
</a-modal>
</div>
</template>
<script setup lang="ts">
/**
* VipRechargePlansView page script.
* Call guide: the template binds the reactive state below, and the methods are triggered by button clicks, lifecycle hooks, or router events.
*/
import { onMounted, reactive, ref } from 'vue'
import { message } from 'ant-design-vue'
/**
* Purpose: Shop supports VipRechargePlansView.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.
*/
import { adminShopApi, adminVipRechargePlanApi, type Shop, type VipRechargePlanVO } from '@/api/admin'
/** loading is a reactive state variable used by the template and event handlers. */
const loading = ref(false)
/** saving is a reactive state variable used by the template and event handlers. */
const saving = ref(false)
/** formOpen is a reactive state variable used by the template and event handlers. */
const formOpen = ref(false)
/**
* Purpose: editingId supports VipRechargePlansView.vue by holding or executing the editing id 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 editingId = ref<any>()
/**
* Purpose: plans supports VipRechargePlansView.vue by holding or executing the plans 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 plans = ref<VipRechargePlanVO[]>([])
/**
* Purpose: shops supports VipRechargePlansView.vue by holding or executing the shops 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 shops = ref<Shop[]>([])
/**
* Purpose: vipLevelOptions supports VipRechargePlansView.vue by holding or executing the vip level options page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const vipLevelOptions = ref<string[]>(['普通', '青铜', '白银', '黄金'])
/**
* Purpose: form supports VipRechargePlansView.vue by holding or executing the form 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 form = reactive<any>({ shopId: undefined, title: '', rechargeAmount: 0, giftAmount: 0, vipLevel: '', description: '', sortOrder: 0, status: 1 })
/**
* Purpose: columns supports VipRechargePlansView.vue by holding or executing the columns 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 columns = [
{ title: '标题', dataIndex: 'title', key: 'title' },
{ title: '店铺', dataIndex: 'shopName', key: 'shopName' },
{ title: '金额', key: 'amount' },
{ title: 'VIP 等级', dataIndex: 'vipLevel', key: 'vipLevel' },
{ title: '说明', dataIndex: 'description', key: 'description' },
{ title: '启用', key: 'status', width: 100 },
{ title: '操作', key: 'action', width: 100 }
]
/**
* Purpose: shopOptions supports VipRechargePlansView.vue by holding or executing the shop 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 shopOptions = ref<Array<{ label: string; value: any }>>([])
/** money is a local helper used by this page script. */
const money = (value: number | string) => Number(value || 0).toFixed(2)
/** load is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const load = async () => {
loading.value = true
try {
const [planList, shopList] = await Promise.all([
adminVipRechargePlanApi.listPlans(),
adminShopApi.listAllShops().catch(() => [])
])
plans.value = planList || []
const configuredLevels = Array.from(new Set(plans.value.map(item => item.vipLevel).filter(Boolean)))
vipLevelOptions.value = Array.from(new Set(['普通', '青铜', '白银', '黄金', ...configuredLevels]))
shops.value = shopList || []
shopOptions.value = shops.value.map(item => ({ label: item.shopName, value: item.id }))
} finally {
loading.value = false
}
}
/** resetForm is a local helper used by this page script. */
const resetForm = () => Object.assign(form, { shopId: undefined, title: '', rechargeAmount: 0, giftAmount: 0, vipLevel: '', description: '', sortOrder: 0, status: 1 })
/** openCreate is a local helper used by this page script. */
const openCreate = () => { editingId.value = undefined; resetForm(); formOpen.value = true }
/** openEdit is a local helper used by this page script. */
const openEdit = (record: VipRechargePlanVO) => {
editingId.value = record.id
Object.assign(form, record)
formOpen.value = true
}
/** submit is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const submit = async () => {
if (!form.title || !form.vipLevel || Number(form.rechargeAmount) <= 0) {
message.warning('请填写标题、充值金额和 VIP 等级')
return
}
saving.value = true
try {
if (editingId.value) {
await adminVipRechargePlanApi.updatePlan(editingId.value, form)
} else {
await adminVipRechargePlanApi.createPlan(form)
}
message.success('档位已保存')
formOpen.value = false
await load()
} finally {
saving.value = false
}
}
/** toggleStatus is an async page action. Trigger it from the template or lifecycle hook, then await the result. */
const toggleStatus = async (record: VipRechargePlanVO, checked: boolean) => {
await adminVipRechargePlanApi.updateStatus(record.id, checked ? 1 : 0)
record.status = checked ? 1 : 0
}
onMounted(load)
</script>
<style scoped>
.admin-page { display: grid; gap: 18px; }
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.page-head h2 { margin: 0 0 4px; }
.page-head p { margin: 0; color: var(--text-secondary); }
.level-shortcuts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.level-shortcuts :deep(.ant-tag) { cursor: pointer; }
</style>