mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 11:09:20 +08:00
refactor: 重构电商模块目录结构
This commit is contained in:
+192
@@ -0,0 +1,192 @@
|
||||
<script lang="ts" setup>
|
||||
import type {
|
||||
OrderStatusDTO,
|
||||
OrderStatusVO,
|
||||
} from '#/api/ecommerce/order-status/types';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Form, Input, InputNumber, message, Switch } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createOrderStatusApi,
|
||||
updateOrderStatusApi,
|
||||
} from '#/api/ecommerce/order-status';
|
||||
|
||||
const emit = defineEmits<{
|
||||
cancel: [];
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[500px]',
|
||||
onCancel() {
|
||||
close();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentRecord = ref<null | OrderStatusVO.Info>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<Partial<OrderStatusDTO.Create>>({
|
||||
statusName: '',
|
||||
description: '',
|
||||
isActive: 1,
|
||||
sortOrder: 0,
|
||||
});
|
||||
|
||||
// 表单验证规则
|
||||
const rules = {
|
||||
statusName: [{ required: true, message: '请输入状态名称', trigger: 'blur' }],
|
||||
sortOrder: [{ required: true, message: '请输入排序', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
// 表单引用
|
||||
const formRef = ref();
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: OrderStatusVO.Info) {
|
||||
isEdit.value = edit;
|
||||
currentRecord.value = record || null;
|
||||
modalApi.open();
|
||||
|
||||
// 根据模式填充表单数据
|
||||
formData.value =
|
||||
edit && record
|
||||
? {
|
||||
statusName: record.statusName,
|
||||
description: record.description || '',
|
||||
isActive: record.isActive,
|
||||
sortOrder: record.sortOrder || 0,
|
||||
}
|
||||
: {
|
||||
statusName: '',
|
||||
description: '',
|
||||
isActive: 1,
|
||||
sortOrder: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
modalApi.close();
|
||||
formRef.value?.resetFields();
|
||||
emit('cancel');
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentRecord.value) {
|
||||
// 更新订单状态
|
||||
const updateData: OrderStatusDTO.Update = {
|
||||
id: currentRecord.value.id,
|
||||
statusName: formData.value.statusName!,
|
||||
description: formData.value.description,
|
||||
isActive: formData.value.isActive,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
};
|
||||
await updateOrderStatusApi(updateData);
|
||||
message.success('更新订单状态成功');
|
||||
} else {
|
||||
// 创建订单状态
|
||||
const createData: OrderStatusDTO.Create = {
|
||||
statusName: formData.value.statusName!,
|
||||
description: formData.value.description,
|
||||
isActive: formData.value.isActive,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
};
|
||||
await createOrderStatusApi(createData);
|
||||
message.success('创建订单状态成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
close();
|
||||
} catch (error) {
|
||||
console.error('提交订单状态失败:', (error as any).message);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 监听 modal 关闭状态
|
||||
watch(
|
||||
() => modalApi.useStore()?.value?.isOpen,
|
||||
(newVal) => {
|
||||
if (!newVal) {
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:title="isEdit ? '编辑订单状态' : '添加订单状态'"
|
||||
:confirm-loading="loading"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules as any"
|
||||
layout="vertical"
|
||||
>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="状态名称" name="statusName">
|
||||
<Input
|
||||
v-model:value="formData.statusName"
|
||||
placeholder="请输入状态名称"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<Form.Item label="状态描述" name="description">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.description"
|
||||
placeholder="请输入状态描述(可选)"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="排序" name="sortOrder">
|
||||
<InputNumber
|
||||
v-model:value="formData.sortOrder"
|
||||
placeholder="请输入排序"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="启用状态" name="isActive">
|
||||
<Switch
|
||||
v-model:checked="formData.isActive"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
+232
@@ -0,0 +1,232 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteOrderStatusApi,
|
||||
getAllOrderStatusListApi,
|
||||
} from '#/api/ecommerce/order-status';
|
||||
|
||||
import OrderStatusFormModal from './components/OrderStatusFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'OrderStatusConfig' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const orderStatusFormModalRef = ref();
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
width: 80,
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'statusName',
|
||||
title: '状态名称',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'description',
|
||||
title: '状态描述',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'sortOrder',
|
||||
title: '排序',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 'auto',
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
highlightHoverRow: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const data = await getAllOrderStatusListApi();
|
||||
return {
|
||||
items: data,
|
||||
total: data.length,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
message.error('获取订单状态列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入状态名称',
|
||||
},
|
||||
fieldName: 'statusName',
|
||||
label: '状态名称',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'isActive',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '订单状态配置',
|
||||
});
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加订单状态
|
||||
function handleAdd() {
|
||||
orderStatusFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑订单状态
|
||||
function handleEdit(record: OrderStatusVO.Info) {
|
||||
orderStatusFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除订单状态
|
||||
async function handleDelete(record: OrderStatusVO.Info) {
|
||||
try {
|
||||
await deleteOrderStatusApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除订单状态失败:', error);
|
||||
message.error('删除订单状态失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="订单状态配置" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理订单状态类型,包括状态名称、描述和启用状态
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加状态
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }: { row: any }">
|
||||
<Tag :color="row.isActive === 1 ? 'green' : 'red'">
|
||||
{{ row.isActive === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 订单状态表单模态框 -->
|
||||
<OrderStatusFormModal
|
||||
ref="orderStatusFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
+221
@@ -0,0 +1,221 @@
|
||||
<script lang="ts" setup>
|
||||
import type {
|
||||
PromotionFeeTypeDTO,
|
||||
PromotionFeeTypeVO,
|
||||
} from '#/api/ecommerce/promotion-fee-type';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Select,
|
||||
Switch,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createPromotionFeeTypeApi,
|
||||
updatePromotionFeeTypeApi,
|
||||
} from '#/api/ecommerce/promotion-fee-type';
|
||||
|
||||
const emit = defineEmits<{
|
||||
cancel: [];
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[600px]',
|
||||
onCancel() {
|
||||
close();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const isEdit = ref(false);
|
||||
const currentRecord = ref<null | PromotionFeeTypeVO.Info>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<Partial<PromotionFeeTypeDTO.Create>>({
|
||||
typeName: '',
|
||||
description: '',
|
||||
calculationMethod: 1,
|
||||
sortOrder: 0,
|
||||
isActive: 1,
|
||||
});
|
||||
|
||||
// 计算方式选项
|
||||
const calculationMethodOptions = [
|
||||
{ label: '固定金额', value: 1 },
|
||||
{ label: '按比例', value: 2 },
|
||||
{ label: '按点击', value: 3 },
|
||||
{ label: '按展示', value: 4 },
|
||||
];
|
||||
|
||||
// 表单验证规则
|
||||
const rules = {
|
||||
typeCode: [{ required: true, message: '请输入类型编码', trigger: 'blur' }],
|
||||
typeName: [{ required: true, message: '请输入类型名称', trigger: 'blur' }],
|
||||
sortOrder: [{ required: true, message: '请输入排序', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
// 表单引用
|
||||
const formRef = ref();
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: PromotionFeeTypeVO.Info) {
|
||||
isEdit.value = edit;
|
||||
currentRecord.value = record || null;
|
||||
modalApi.open();
|
||||
|
||||
// 根据模式填充表单数据
|
||||
formData.value =
|
||||
edit && record
|
||||
? {
|
||||
typeName: record.typeName,
|
||||
description: record.description || '',
|
||||
calculationMethod: record.calculationMethod || 1,
|
||||
sortOrder: record.sortOrder || 0,
|
||||
isActive: record.isActive || 1,
|
||||
}
|
||||
: {
|
||||
typeName: '',
|
||||
description: '',
|
||||
calculationMethod: 1,
|
||||
sortOrder: 0,
|
||||
isActive: 1,
|
||||
};
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
modalApi.close();
|
||||
formRef.value?.resetFields();
|
||||
emit('cancel');
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
if (isEdit.value && currentRecord.value) {
|
||||
// 更新推广费类型
|
||||
const updateData: PromotionFeeTypeDTO.Update = {
|
||||
id: currentRecord.value.id,
|
||||
typeName: formData.value.typeName!,
|
||||
description: formData.value.description,
|
||||
calculationMethod: formData.value.calculationMethod,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
isActive: formData.value.isActive,
|
||||
};
|
||||
await updatePromotionFeeTypeApi(updateData);
|
||||
message.success('更新推广费类型成功');
|
||||
} else {
|
||||
// 创建推广费类型
|
||||
const createData: PromotionFeeTypeDTO.Create = {
|
||||
typeName: formData.value.typeName!,
|
||||
description: formData.value.description,
|
||||
calculationMethod: formData.value.calculationMethod,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
isActive: formData.value.isActive,
|
||||
};
|
||||
await createPromotionFeeTypeApi(createData);
|
||||
message.success('创建推广费类型成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
close();
|
||||
} catch (error) {
|
||||
console.error('提交推广费类型失败:', (error as any).message);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 监听 modal 关闭状态
|
||||
watch(
|
||||
() => modalApi.useStore()?.value?.isOpen,
|
||||
(newVal) => {
|
||||
if (!newVal) {
|
||||
formRef.value?.resetFields();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
:title="isEdit ? '编辑推广费类型' : '添加推广费类型'"
|
||||
:confirm-loading="loading"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules as any"
|
||||
layout="vertical"
|
||||
>
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="类型名称" name="typeName">
|
||||
<Input
|
||||
v-model:value="formData.typeName"
|
||||
placeholder="请输入类型名称"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<Form.Item label="类型描述" name="description">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.description"
|
||||
placeholder="请输入类型描述(可选)"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<Form.Item label="计算方式" name="calculationMethod">
|
||||
<Select
|
||||
v-model:value="formData.calculationMethod"
|
||||
placeholder="请选择计算方式"
|
||||
:options="calculationMethodOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="排序" name="sortOrder">
|
||||
<InputNumber
|
||||
v-model:value="formData.sortOrder"
|
||||
placeholder="请输入排序"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="启用状态" name="isActive">
|
||||
<Switch
|
||||
v-model:checked="formData.isActive"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="启用"
|
||||
un-checked-children="禁用"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
+256
@@ -0,0 +1,256 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { PromotionFeeTypeVO } from '#/api/ecommerce/promotion-fee-type';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deletePromotionFeeTypeApi,
|
||||
getAllPromotionFeeTypeListApi,
|
||||
} from '#/api/ecommerce/promotion-fee-type';
|
||||
|
||||
import PromotionFeeTypeFormModal from './components/PromotionFeeTypeFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'PromotionFeeTypeConfig' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const promotionFeeTypeFormModalRef = ref();
|
||||
|
||||
// 计算方式选项
|
||||
const calculationMethodOptions = [
|
||||
{ label: '固定金额', value: 1 },
|
||||
{ label: '按比例', value: 2 },
|
||||
{ label: '按点击', value: 3 },
|
||||
{ label: '按展示', value: 4 },
|
||||
];
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
width: 80,
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'typeName',
|
||||
title: '类型名称',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'description',
|
||||
title: '类型描述',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '计算方式',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'calculationMethod' },
|
||||
},
|
||||
{
|
||||
field: 'sortOrder',
|
||||
title: '排序',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'status' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 'auto',
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
highlightHoverRow: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const data = await getAllPromotionFeeTypeListApi();
|
||||
return {
|
||||
items: data,
|
||||
total: data.length,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取推广费类型列表失败:', error);
|
||||
message.error('获取推广费类型列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入类型名称',
|
||||
},
|
||||
fieldName: 'typeName',
|
||||
label: '类型名称',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: [
|
||||
{ label: '启用', value: 1 },
|
||||
{ label: '禁用', value: 0 },
|
||||
],
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'isActive',
|
||||
label: '状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '推广费用类型配置',
|
||||
});
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加推广费类型
|
||||
function handleAdd() {
|
||||
promotionFeeTypeFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑推广费类型
|
||||
function handleEdit(record: PromotionFeeTypeVO.Info) {
|
||||
promotionFeeTypeFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除推广费类型
|
||||
async function handleDelete(record: PromotionFeeTypeVO.Info) {
|
||||
try {
|
||||
await deletePromotionFeeTypeApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除推广费类型失败:', error);
|
||||
message.error('删除推广费类型失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="推广费用类型配置" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理推广费用类型,包括费用类型名称、描述、计算方式和启用状态
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加类型
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 计算方式列 -->
|
||||
<template #calculationMethod="{ row }: { row: any }">
|
||||
<Tag color="blue">
|
||||
{{
|
||||
calculationMethodOptions.find(
|
||||
(opt) => opt.value === row.calculationMethod,
|
||||
)?.label || '未设置'
|
||||
}}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 状态列 -->
|
||||
<template #status="{ row }: { row: any }">
|
||||
<Tag :color="row.isActive === 1 ? 'green' : 'red'">
|
||||
{{ row.isActive === 1 ? '启用' : '禁用' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 推广费类型表单模态框 -->
|
||||
<PromotionFeeTypeFormModal
|
||||
ref="promotionFeeTypeFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user