mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 08:29: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>
|
||||
@@ -56,6 +56,7 @@ const gridOptions: VxeGridProps<any> = {
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
highlightHoverRow: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
data: [],
|
||||
@@ -83,18 +84,47 @@ const gridOptions: VxeGridProps<any> = {
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载,实现真正的分页
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
// 如果没有数据,返回空
|
||||
if (csvData.value.length === 0) {
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
}
|
||||
|
||||
// 计算分页参数
|
||||
const currentPage = page.currentPage || 1;
|
||||
const pageSize = page.pageSize || 50;
|
||||
const startIndex = (currentPage - 1) * pageSize;
|
||||
const endIndex = startIndex + pageSize;
|
||||
|
||||
// 从 csvData 中截取当前页的数据
|
||||
const pageData = csvData.value.slice(startIndex, endIndex);
|
||||
|
||||
return {
|
||||
items: pageData,
|
||||
total: csvData.value.length,
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
});
|
||||
|
||||
// 更新表格数据和列
|
||||
// 更新表格列配置(不再更新 data,data 由 proxyConfig 管理)
|
||||
const updateTable = () => {
|
||||
gridApi.setGridOptions({
|
||||
columns: gridColumns.value,
|
||||
data: csvData.value,
|
||||
});
|
||||
// 触发重新加载数据
|
||||
gridApi.reload();
|
||||
};
|
||||
|
||||
// 处理文件上传
|
||||
|
||||
+352
@@ -0,0 +1,352 @@
|
||||
<script lang="ts" setup>
|
||||
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
import type { ShopVO } from '#/api/shop/shop/types';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
DatePicker,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Select,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { createOrderApi, updateOrderApi } from '#/api/ecommerce/order';
|
||||
import { getActiveOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
import { getShopPageApi } from '#/api/shop/shop';
|
||||
|
||||
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 | OrderVO.Info>(null);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<Partial<OrderDTO.Create>>({
|
||||
shopId: undefined,
|
||||
platformOrderNo: '',
|
||||
statusId: undefined,
|
||||
receivedAmount: 0,
|
||||
orderDate: dayjs().format('YYYY-MM-DD'),
|
||||
productId: undefined,
|
||||
productSpecId: undefined,
|
||||
productName: '',
|
||||
specName: '',
|
||||
quantity: 1,
|
||||
unitPrice: 0,
|
||||
costPrice: 0,
|
||||
});
|
||||
|
||||
// 下拉选项数据
|
||||
const shopOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
// 表单验证规则
|
||||
const rules = {
|
||||
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
statusId: [{ required: true, message: '请选择订单状态', trigger: 'change' }],
|
||||
receivedAmount: [
|
||||
{ required: true, message: '请输入实收金额', trigger: 'blur' },
|
||||
],
|
||||
orderDate: [{ required: true, message: '请选择下单时间', trigger: 'change' }],
|
||||
productId: [{ required: true, message: '请输入商品ID', trigger: 'blur' }],
|
||||
productName: [{ required: true, message: '请输入商品名称', trigger: 'blur' }],
|
||||
quantity: [{ required: true, message: '请输入数量', trigger: 'blur' }],
|
||||
unitPrice: [{ required: true, message: '请输入销售单价', trigger: 'blur' }],
|
||||
costPrice: [{ required: true, message: '请输入成本价', trigger: 'blur' }],
|
||||
};
|
||||
|
||||
// 表单引用
|
||||
const formRef = ref();
|
||||
|
||||
// 获取店铺选项
|
||||
async function fetchShopOptions() {
|
||||
try {
|
||||
const params: any = {
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
filters: {},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
shopOptions.value = data.records.map((shop: ShopVO.Info) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单状态选项
|
||||
async function fetchOrderStatusOptions() {
|
||||
try {
|
||||
const data = await getActiveOrderStatusListApi();
|
||||
orderStatusOptions.value = data.map((status: OrderStatusVO.Info) => ({
|
||||
label: status.statusName,
|
||||
value: status.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: OrderVO.Info) {
|
||||
isEdit.value = edit;
|
||||
currentRecord.value = record || null;
|
||||
|
||||
// 加载下拉选项数据
|
||||
fetchShopOptions();
|
||||
fetchOrderStatusOptions();
|
||||
|
||||
modalApi.open();
|
||||
|
||||
// 根据模式填充表单数据
|
||||
formData.value =
|
||||
edit && record
|
||||
? {
|
||||
shopId: record.shopId,
|
||||
platformOrderNo: record.platformOrderNo || '',
|
||||
statusId: record.statusId,
|
||||
receivedAmount: record.receivedAmount,
|
||||
orderDate: record.orderDate
|
||||
? dayjs(record.orderDate).format('YYYY-MM-DD')
|
||||
: dayjs().format('YYYY-MM-DD'),
|
||||
productId: record.productId,
|
||||
productSpecId: record.productSpecId,
|
||||
productName: record.productName,
|
||||
specName: record.specName,
|
||||
quantity: record.quantity,
|
||||
unitPrice: record.unitPrice,
|
||||
costPrice: record.costPrice,
|
||||
}
|
||||
: {
|
||||
shopId: undefined,
|
||||
platformOrderNo: '',
|
||||
statusId: undefined,
|
||||
receivedAmount: 0,
|
||||
orderDate: dayjs().format('YYYY-MM-DD'),
|
||||
productId: undefined,
|
||||
productSpecId: undefined,
|
||||
productName: '',
|
||||
specName: '',
|
||||
quantity: 1,
|
||||
unitPrice: 0,
|
||||
costPrice: 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: OrderDTO.Update = {
|
||||
shopId: formData.value.shopId!,
|
||||
platformOrderNo: formData.value.platformOrderNo,
|
||||
statusId: formData.value.statusId,
|
||||
receivedAmount: formData.value.receivedAmount!,
|
||||
orderDate: formData.value.orderDate!,
|
||||
productId: formData.value.productId,
|
||||
productSpecId: formData.value.productSpecId,
|
||||
productName: formData.value.productName,
|
||||
specName: formData.value.specName,
|
||||
quantity: formData.value.quantity,
|
||||
unitPrice: formData.value.unitPrice,
|
||||
costPrice: formData.value.costPrice,
|
||||
};
|
||||
await updateOrderApi(currentRecord.value.id, updateData);
|
||||
message.success('更新订单成功');
|
||||
} else {
|
||||
// 创建订单
|
||||
const createData: OrderDTO.Create = {
|
||||
shopId: formData.value.shopId!,
|
||||
platformOrderNo: formData.value.platformOrderNo,
|
||||
statusId: formData.value.statusId!,
|
||||
receivedAmount: formData.value.receivedAmount!,
|
||||
orderDate: formData.value.orderDate!,
|
||||
productId: formData.value.productId!,
|
||||
productSpecId: formData.value.productSpecId,
|
||||
productName: formData.value.productName!,
|
||||
specName: formData.value.specName,
|
||||
quantity: formData.value.quantity!,
|
||||
unitPrice: formData.value.unitPrice!,
|
||||
costPrice: formData.value.costPrice!,
|
||||
};
|
||||
await createOrderApi(createData);
|
||||
message.success('创建订单成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
close();
|
||||
} catch (error) {
|
||||
console.error('提交订单失败:', error);
|
||||
message.error('提交订单失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露方法
|
||||
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="shopId">
|
||||
<Select
|
||||
v-model:value="formData.shopId"
|
||||
placeholder="请选择店铺"
|
||||
:options="shopOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="订单状态" name="statusId">
|
||||
<Select
|
||||
v-model:value="formData.statusId"
|
||||
placeholder="请选择订单状态"
|
||||
:options="orderStatusOptions"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="平台订单号" name="platformOrderNo">
|
||||
<Input
|
||||
v-model:value="formData.platformOrderNo"
|
||||
placeholder="请输入平台订单号(可选)"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="下单时间" name="orderDate">
|
||||
<DatePicker
|
||||
v-model:value="formData.orderDate"
|
||||
placeholder="请选择下单时间"
|
||||
style="width: 100%"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="商品ID" name="productId">
|
||||
<InputNumber
|
||||
v-model:value="formData.productId"
|
||||
placeholder="请输入商品ID"
|
||||
style="width: 100%"
|
||||
:min="1"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="商品规格ID" name="productSpecId">
|
||||
<InputNumber
|
||||
v-model:value="formData.productSpecId"
|
||||
placeholder="请输入商品规格ID(可选)"
|
||||
style="width: 100%"
|
||||
:min="1"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<Form.Item label="商品名称" name="productName">
|
||||
<Input
|
||||
v-model:value="formData.productName"
|
||||
placeholder="请输入商品名称"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="规格名称" name="specName">
|
||||
<Input
|
||||
v-model:value="formData.specName"
|
||||
placeholder="请输入规格名称(可选)"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-3 gap-4">
|
||||
<Form.Item label="数量" name="quantity">
|
||||
<InputNumber
|
||||
v-model:value="formData.quantity"
|
||||
placeholder="请输入数量"
|
||||
style="width: 100%"
|
||||
:min="1"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="销售单价" name="unitPrice">
|
||||
<InputNumber
|
||||
v-model:value="formData.unitPrice"
|
||||
placeholder="请输入销售单价"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="成本价" name="costPrice">
|
||||
<InputNumber
|
||||
v-model:value="formData.costPrice"
|
||||
placeholder="请输入成本价"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<Form.Item label="实收金额" name="receivedAmount">
|
||||
<InputNumber
|
||||
v-model:value="formData.receivedAmount"
|
||||
placeholder="请输入实收金额"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,361 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
import type { ShopVO } from '#/api/shop/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, 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 { deleteOrderApi, getOrderPageApi } from '#/api/ecommerce/order';
|
||||
import { getActiveOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
import { getShopPageApi } from '#/api/shop/shop';
|
||||
|
||||
import OrderFormModal from './components/OrderFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'OrderManagement' });
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const orderFormModalRef = ref();
|
||||
|
||||
// 下拉选项数据
|
||||
const shopOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
platformOrderNo: '',
|
||||
shopId: undefined as number | undefined,
|
||||
statusId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'platformOrderNo',
|
||||
title: '平台订单号',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'shopName',
|
||||
title: '店铺名称',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '商品信息',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'productInfo' },
|
||||
},
|
||||
{
|
||||
title: '数量',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'quantity' },
|
||||
},
|
||||
{
|
||||
title: '实收金额',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'receivedAmount' },
|
||||
},
|
||||
{
|
||||
title: '订单状态',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'orderStatus' },
|
||||
},
|
||||
{
|
||||
field: 'orderDate',
|
||||
title: '下单时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
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: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<OrderDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
platformOrderNo: searchForm.value.platformOrderNo || undefined,
|
||||
shopId: searchForm.value.shopId,
|
||||
statusId: searchForm.value.statusId,
|
||||
},
|
||||
};
|
||||
const data = await getOrderPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取订单列表失败:', error);
|
||||
message.error('获取订单列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入平台订单号',
|
||||
},
|
||||
fieldName: 'platformOrderNo',
|
||||
label: '平台订单号',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择店铺',
|
||||
options: shopOptions.value,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'shopId',
|
||||
label: '店铺',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: orderStatusOptions.value,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'statusId',
|
||||
label: '订单状态',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 获取店铺选项
|
||||
async function fetchShopOptions() {
|
||||
try {
|
||||
const params: PageQueryDTO<any> = {
|
||||
page: 1,
|
||||
pageSize: 1000, // 获取所有店铺
|
||||
filters: {},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
shopOptions.value = data.records.map((shop: ShopVO.Info) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取订单状态选项
|
||||
async function fetchOrderStatusOptions() {
|
||||
try {
|
||||
const data = await getActiveOrderStatusListApi();
|
||||
orderStatusOptions.value = data.map((status: OrderStatusVO.Info) => ({
|
||||
label: status.statusName,
|
||||
value: status.id,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '订单管理',
|
||||
});
|
||||
|
||||
// 处理添加订单
|
||||
function handleAdd() {
|
||||
orderFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑订单
|
||||
function handleEdit(record: OrderVO.Info) {
|
||||
orderFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除订单
|
||||
async function handleDelete(record: OrderVO.Info) {
|
||||
try {
|
||||
await deleteOrderApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除订单失败:', error);
|
||||
message.error('删除订单失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理批量导入
|
||||
function handleBatchImport() {
|
||||
// 跳转到数据导入页面
|
||||
window.open('/data-import', '_blank');
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(async () => {
|
||||
await Promise.all([fetchShopOptions(), fetchOrderStatusOptions()]);
|
||||
});
|
||||
</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 @click="handleBatchImport">
|
||||
<UploadIcon />
|
||||
批量导入
|
||||
</Button>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加订单
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 商品信息列 -->
|
||||
<template #productInfo="{ row }: { row: any }">
|
||||
<div v-if="row.productName">
|
||||
<div style="font-weight: bold">{{ row.productName }}</div>
|
||||
<div v-if="row.specName" style="color: #666; font-size: 12px">
|
||||
{{ row.specName }}
|
||||
</div>
|
||||
</div>
|
||||
<span v-else style="color: #999">暂无商品信息</span>
|
||||
</template>
|
||||
|
||||
<!-- 数量列 -->
|
||||
<template #quantity="{ row }: { row: any }">
|
||||
{{ row.quantity || 0 }}
|
||||
</template>
|
||||
|
||||
<!-- 实收金额列 -->
|
||||
<template #receivedAmount="{ row }: { row: any }">
|
||||
<span style="color: #52c41a; font-weight: bold">
|
||||
¥{{ (row.receivedAmount || 0).toFixed(2) }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<!-- 订单状态列 -->
|
||||
<template #orderStatus="{ row }: { row: any }">
|
||||
<Tag color="blue">
|
||||
{{
|
||||
orderStatusOptions.find((s) => s.value === row.statusId)?.label ||
|
||||
row.statusName ||
|
||||
'未知状态'
|
||||
}}
|
||||
</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>
|
||||
|
||||
<!-- 订单表单模态框 -->
|
||||
<OrderFormModal ref="orderFormModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductVO } from '#/api/shop/product/types';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Card, Image, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
// 创建图标组件
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
const SettingsIcon = createIconifyIcon('lucide:settings');
|
||||
|
||||
interface Props {
|
||||
product: ProductVO.Info;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'edit', product: ProductVO.Info): void;
|
||||
(e: 'delete', product: ProductVO.Info): void;
|
||||
(e: 'manageSpecs', product: ProductVO.Info): void;
|
||||
}
|
||||
|
||||
const handleEdit = (product: ProductVO.Info) => {
|
||||
emit('edit', product);
|
||||
};
|
||||
|
||||
const handleDelete = (product: ProductVO.Info) => {
|
||||
emit('delete', product);
|
||||
};
|
||||
|
||||
const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
emit('manageSpecs', product);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card
|
||||
hoverable
|
||||
:body-style="{ padding: 0 }"
|
||||
class="group h-full border border-gray-200 transition-all duration-300 ease-out hover:-translate-y-1 hover:border-blue-500 hover:shadow-lg dark:border-gray-700"
|
||||
>
|
||||
<!-- 图片区域 -->
|
||||
<div
|
||||
class="relative aspect-square cursor-pointer overflow-hidden rounded-t-lg bg-gray-100 dark:bg-neutral-800"
|
||||
>
|
||||
<Image
|
||||
v-if="product.mainImage"
|
||||
:src="product.mainImage"
|
||||
:alt="product.name"
|
||||
class="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
|
||||
:preview="true"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="flex h-full w-full items-center justify-center text-gray-400 dark:text-gray-500"
|
||||
>
|
||||
<div class="text-center">
|
||||
<div class="mb-2 text-4xl">📦</div>
|
||||
<div class="text-sm">暂无图片</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 规格数量标签 -->
|
||||
<div
|
||||
v-if="product.specs && product.specs.length > 0"
|
||||
class="absolute left-2 top-2"
|
||||
>
|
||||
<Tag color="blue" size="small"> {{ product.specs.length }} 个规格 </Tag>
|
||||
</div>
|
||||
|
||||
<!-- 如果有多个规格,显示更多标识 -->
|
||||
<div
|
||||
v-if="product.specs && product.specs.length > 3"
|
||||
class="absolute right-2 top-2"
|
||||
>
|
||||
<Tag color="orange" size="small"> +{{ product.specs.length - 3 }} </Tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 信息区域 -->
|
||||
<div class="p-3">
|
||||
<!-- 商品名称 -->
|
||||
<div
|
||||
class="mb-2 line-clamp-2 text-sm font-medium text-gray-900 dark:text-gray-100"
|
||||
:title="product.name"
|
||||
>
|
||||
{{ product.name }}
|
||||
</div>
|
||||
|
||||
<!-- 商品编码 -->
|
||||
<div
|
||||
v-if="product.productCode"
|
||||
class="mb-2 text-xs text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
编码: {{ product.productCode }}
|
||||
</div>
|
||||
|
||||
<!-- 规格信息预览 -->
|
||||
<div
|
||||
v-if="product.specs && product.specs.length > 0"
|
||||
class="mb-3 space-y-1"
|
||||
>
|
||||
<div
|
||||
v-for="spec in product.specs.slice(0, 2)"
|
||||
:key="spec.id"
|
||||
class="flex items-center justify-between rounded-md bg-gray-50 px-2 py-1 text-xs dark:bg-neutral-800"
|
||||
>
|
||||
<span class="font-medium text-gray-700 dark:text-gray-300">{{
|
||||
spec.name
|
||||
}}</span>
|
||||
<span class="ml-2 font-semibold text-red-500 dark:text-red-400">
|
||||
¥{{ spec.costPrice.toFixed(2) }}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
v-if="product.specs.length > 2"
|
||||
class="text-xs text-gray-400 dark:text-gray-500"
|
||||
>
|
||||
还有 {{ product.specs.length - 2 }} 个规格...
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 创建时间 -->
|
||||
<div class="mb-3 text-xs text-gray-500 dark:text-gray-400">
|
||||
{{ product.createTime }}
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex w-full items-center justify-between gap-1">
|
||||
<Space size="small">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(product)"
|
||||
title="编辑"
|
||||
class="min-w-0 flex-1"
|
||||
>
|
||||
<template #icon>
|
||||
<EditIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">编辑</span>
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleManageSpecs(product)"
|
||||
title="管理规格"
|
||||
class="min-w-0 flex-1"
|
||||
>
|
||||
<template #icon>
|
||||
<SettingsIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">规格</span>
|
||||
</Button>
|
||||
</Space>
|
||||
<Popconfirm
|
||||
title="确定要删除这个商品吗?"
|
||||
@confirm="handleDelete(product)"
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
danger
|
||||
title="删除"
|
||||
class="flex-shrink-0"
|
||||
>
|
||||
<template #icon>
|
||||
<TrashIcon class="h-4 w-4" />
|
||||
</template>
|
||||
<span class="hidden sm:inline">删除</span>
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.line-clamp-2 {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
+600
@@ -0,0 +1,600 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductDTO, ProductVO } from '#/api/shop/product/types';
|
||||
|
||||
import { computed, h, onUnmounted, ref, resolveComponent } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Space,
|
||||
Table,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { uploadImageApi } from '#/api/media/image';
|
||||
import { createProductApi, updateProductApi } from '#/api/shop/product';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
defineOptions({ name: 'ProductFormModal' });
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建Vben Modal实例
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
title: '添加商品',
|
||||
class: 'w-[800px]',
|
||||
draggable: true, // 开启拖拽
|
||||
contentClass: 'px-6 py-4',
|
||||
onConfirm: handleSubmit,
|
||||
onCancel: close,
|
||||
onOpenChange: (isOpen: boolean) => {
|
||||
if (isOpen) {
|
||||
// 打开时不做操作
|
||||
return;
|
||||
}
|
||||
resetForm();
|
||||
},
|
||||
});
|
||||
|
||||
// 创建图标组件
|
||||
const CameraIcon = createIconifyIcon('mdi:camera');
|
||||
const UpIcon = createIconifyIcon('lucide:chevron-up');
|
||||
const DownIcon = createIconifyIcon('lucide:chevron-down');
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
// 内部状态管理
|
||||
const isEdit = ref(false);
|
||||
const currentProductData = ref<null | Partial<ProductVO.Info> | ProductVO.Info>(
|
||||
null,
|
||||
);
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const newImageFile = ref<File | null>(null); // 新选择的图片文件
|
||||
const originalImageUrl = ref(''); // 原始图片 URL
|
||||
const imageLoadError = ref(false); // 图片加载错误状态
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
name: '',
|
||||
productCode: '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
mainImageId: undefined as number | undefined,
|
||||
costPrice: 0,
|
||||
});
|
||||
|
||||
// 规格数据
|
||||
const specs = ref<ProductDTO.Spec[]>([]);
|
||||
const showSpecs = ref(false);
|
||||
|
||||
// 当前显示的图片 URL(优先显示新选择的)
|
||||
const currentImageUrl = computed(() => {
|
||||
if (newImageFile.value) {
|
||||
return URL.createObjectURL(newImageFile.value);
|
||||
}
|
||||
return originalImageUrl.value;
|
||||
});
|
||||
|
||||
// 初始化表单数据
|
||||
function initFormData() {
|
||||
if (isEdit.value && currentProductData.value) {
|
||||
// 编辑模式
|
||||
// 注意:ProductVO.Info 中可能没有 specCode、skuCode、costPrice 字段
|
||||
// 这些字段可能需要在编辑时从其他地方获取或设置为空
|
||||
const productData = currentProductData.value as any;
|
||||
formData.value = {
|
||||
name: currentProductData.value.name || '',
|
||||
productCode: currentProductData.value.productCode || '',
|
||||
specCode: productData.specCode || '',
|
||||
skuCode: productData.skuCode || '',
|
||||
mainImageId: undefined,
|
||||
costPrice: productData.costPrice ?? 0,
|
||||
};
|
||||
|
||||
// 设置原始图片 URL
|
||||
originalImageUrl.value = currentProductData.value.mainImage || '';
|
||||
} else {
|
||||
// 创建模式 - 如果有传入的productData,则使用它来初始化表单
|
||||
formData.value = {
|
||||
name: currentProductData.value?.name || '',
|
||||
productCode: currentProductData.value?.productCode || '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
mainImageId: undefined,
|
||||
costPrice: 0,
|
||||
};
|
||||
originalImageUrl.value = currentProductData.value?.mainImage || '';
|
||||
}
|
||||
|
||||
// 重置新选择的图片和图片加载状态
|
||||
newImageFile.value = null;
|
||||
imageLoadError.value = false;
|
||||
|
||||
// 重置规格数据
|
||||
specs.value = [];
|
||||
showSpecs.value = false;
|
||||
|
||||
// 如果有传入的规格信息,则自动填入
|
||||
if (
|
||||
!isEdit.value &&
|
||||
currentProductData.value &&
|
||||
'specs' in currentProductData.value &&
|
||||
currentProductData.value.specs
|
||||
) {
|
||||
specs.value = currentProductData.value.specs.map((spec) => ({
|
||||
name: (spec as ProductVO.SpecInfo).name || spec.specCode || '',
|
||||
specCode: spec.specCode || '',
|
||||
costPrice: spec.costPrice || 0,
|
||||
}));
|
||||
showSpecs.value = specs.value.length > 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 重置表单(在open方法中调用)
|
||||
function resetForm() {
|
||||
formRef.value?.resetFields();
|
||||
newImageFile.value = null;
|
||||
originalImageUrl.value = '';
|
||||
imageLoadError.value = false;
|
||||
specs.value = [];
|
||||
showSpecs.value = false;
|
||||
}
|
||||
|
||||
// 处理提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
modalApi.setState({ confirmLoading: true });
|
||||
|
||||
// 准备提交数据
|
||||
const submitData = { ...formData.value };
|
||||
|
||||
// 如果有新选择的图片,先上传获取ID
|
||||
if (newImageFile.value) {
|
||||
const mainImageId = await uploadImageAndGetId();
|
||||
if (mainImageId) {
|
||||
submitData.mainImageId = mainImageId;
|
||||
}
|
||||
} else if (!isEdit.value) {
|
||||
// 创建模式且没有选择图片,移除mainImageId字段
|
||||
delete submitData.mainImageId;
|
||||
}
|
||||
|
||||
// 调用API
|
||||
if (
|
||||
isEdit.value &&
|
||||
currentProductData.value &&
|
||||
'id' in currentProductData.value &&
|
||||
currentProductData.value.id
|
||||
) {
|
||||
const updateData: ProductDTO.Update = {
|
||||
name: submitData.name,
|
||||
productCode: submitData.productCode || undefined,
|
||||
specCode: submitData.specCode || undefined,
|
||||
skuCode: submitData.skuCode || undefined,
|
||||
mainImageId: submitData.mainImageId,
|
||||
costPrice: submitData.costPrice,
|
||||
};
|
||||
await updateProductApi(currentProductData.value.id, updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
// 创建模式:统一使用创建接口,规格信息作为可选字段
|
||||
const createData: ProductDTO.Create = {
|
||||
name: submitData.name,
|
||||
productCode: submitData.productCode || undefined,
|
||||
mainImageId: submitData.mainImageId,
|
||||
...(specs.value.length > 0 && { specs: specs.value }),
|
||||
};
|
||||
await createProductApi(createData);
|
||||
if (specs.value.length > 0) {
|
||||
message.success('商品和规格创建成功');
|
||||
} else {
|
||||
message.success('创建成功');
|
||||
}
|
||||
}
|
||||
|
||||
close();
|
||||
emit('success');
|
||||
} catch (error) {
|
||||
console.error('保存商品失败:', error);
|
||||
message.error('保存商品失败');
|
||||
} finally {
|
||||
modalApi.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭模态框
|
||||
function close() {
|
||||
modalApi.close();
|
||||
resetForm();
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(
|
||||
editMode: boolean = false,
|
||||
productData?: null | Partial<ProductVO.Info> | ProductVO.Info,
|
||||
) {
|
||||
isEdit.value = editMode;
|
||||
currentProductData.value = productData || null;
|
||||
|
||||
// 更新模态框标题
|
||||
modalApi.setState({
|
||||
title: isEdit.value ? '编辑商品' : '添加商品',
|
||||
});
|
||||
|
||||
resetForm(); // 先重置表单
|
||||
initFormData(); // 再初始化数据
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
|
||||
// 选择图片文件
|
||||
function selectImageFile() {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/*';
|
||||
input.style.display = 'none';
|
||||
document.body.append(input);
|
||||
|
||||
input.addEventListener('change', (e) => {
|
||||
const file = (e.target as HTMLInputElement).files?.[0];
|
||||
if (file) {
|
||||
// 验证文件
|
||||
const isImage = file.type.startsWith('image/');
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件');
|
||||
input.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过 2MB');
|
||||
input.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置新选择的文件
|
||||
newImageFile.value = file;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('图片选择成功');
|
||||
}
|
||||
|
||||
input.remove();
|
||||
});
|
||||
|
||||
input.click();
|
||||
}
|
||||
|
||||
// 重置新选择的图片
|
||||
function removeNewImage() {
|
||||
newImageFile.value = null;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('已重置图片');
|
||||
}
|
||||
|
||||
// 添加规格
|
||||
function addSpec() {
|
||||
specs.value.push({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
});
|
||||
}
|
||||
|
||||
// 删除规格
|
||||
function removeSpec(index: number) {
|
||||
specs.value.splice(index, 1);
|
||||
}
|
||||
|
||||
// 表格列配置
|
||||
const specColumns = [
|
||||
{
|
||||
title: '规格名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: '30%',
|
||||
customRender: ({ record }: { record: ProductDTO.Spec }) => {
|
||||
return h(Input, {
|
||||
value: record.name,
|
||||
placeholder: '请输入规格名称',
|
||||
'onUpdate:value': (value: string) => {
|
||||
record.name = value;
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '规格编码',
|
||||
dataIndex: 'specCode',
|
||||
key: 'specCode',
|
||||
width: '30%',
|
||||
customRender: ({ record }: { record: ProductDTO.Spec }) => {
|
||||
return h(Input, {
|
||||
value: record.specCode,
|
||||
placeholder: '请输入规格编码',
|
||||
'onUpdate:value': (value: string) => {
|
||||
record.specCode = value;
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '成本价',
|
||||
dataIndex: 'costPrice',
|
||||
key: 'costPrice',
|
||||
width: '25%',
|
||||
customRender: ({ record }: { record: ProductDTO.Spec }) => {
|
||||
const InputNumberComponent = resolveComponent('InputNumber');
|
||||
return h(InputNumberComponent, {
|
||||
value: record.costPrice,
|
||||
placeholder: '请输入成本价',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record.costPrice = value ?? 0;
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: '15%',
|
||||
align: 'center' as const,
|
||||
customRender: ({ index }: { index: number }) => {
|
||||
return h(
|
||||
Button,
|
||||
{
|
||||
type: 'text',
|
||||
danger: true,
|
||||
size: 'small',
|
||||
onClick: () => removeSpec(index),
|
||||
},
|
||||
{
|
||||
default: () => '删除',
|
||||
icon: () => h(TrashIcon, { class: 'h-4 w-4' }),
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 上传图片并获取图片ID
|
||||
async function uploadImageAndGetId(): Promise<number | undefined> {
|
||||
if (!newImageFile.value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await uploadImageApi(newImageFile.value);
|
||||
return response.id;
|
||||
} catch (error) {
|
||||
console.error('图片上传失败:', error);
|
||||
message.error('图片上传失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 图片加载错误处理
|
||||
function handleImageError(event: Event) {
|
||||
console.error('图片加载失败:', event);
|
||||
imageLoadError.value = true;
|
||||
message.error('图片加载失败,请重新选择');
|
||||
}
|
||||
|
||||
// 组件卸载时清理
|
||||
onUnmounted(() => {
|
||||
if (newImageFile.value) {
|
||||
const url = URL.createObjectURL(newImageFile.value);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="商品主图" name="mainImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px">
|
||||
<!-- 主图预览区域 -->
|
||||
<div style="position: relative; display: inline-block">
|
||||
<!-- 有图片时显示图片 -->
|
||||
<img
|
||||
v-if="currentImageUrl && !imageLoadError"
|
||||
:src="currentImageUrl"
|
||||
alt="商品主图"
|
||||
style="
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #d9d9d9;
|
||||
background-color: #f5f5f5;
|
||||
"
|
||||
@error="handleImageError"
|
||||
/>
|
||||
<!-- 无图片或加载失败时显示空状态 -->
|
||||
<div
|
||||
v-else
|
||||
style="
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
border: 1px dashed #d9d9d9;
|
||||
border-radius: 8px;
|
||||
background-color: #fafafa;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
line-height: 1.2;
|
||||
"
|
||||
>
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
"
|
||||
>
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px" />
|
||||
<div>上传主图</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 点击更换遮罩 -->
|
||||
<div
|
||||
style="
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
cursor: pointer;
|
||||
"
|
||||
@mouseenter="($event.target as HTMLElement).style.opacity = '1'"
|
||||
@mouseleave="($event.target as HTMLElement).style.opacity = '0'"
|
||||
@click="selectImageFile"
|
||||
>
|
||||
<div
|
||||
style="
|
||||
color: white;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
"
|
||||
>
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px" />
|
||||
<div style="font-size: 12px">
|
||||
{{
|
||||
currentImageUrl && !imageLoadError ? '更换主图' : '上传主图'
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<div v-if="newImageFile">
|
||||
<Button size="small" @click="removeNewImage">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="商品名称"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: '请输入商品名称' }]"
|
||||
>
|
||||
<Input v-model:value="formData.name" placeholder="请输入商品名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="商品编码" name="productCode">
|
||||
<Input
|
||||
v-model:value="formData.productCode"
|
||||
placeholder="请输入商品编码"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="isEdit" label="规格编码" name="specCode">
|
||||
<Input v-model:value="formData.specCode" placeholder="请输入规格编码" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item v-if="isEdit" label="商品SKU" name="skuCode">
|
||||
<Input v-model:value="formData.skuCode" placeholder="请输入商品SKU" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
v-if="isEdit"
|
||||
label="成本价"
|
||||
name="costPrice"
|
||||
:rules="[{ required: true, message: '请输入成本价' }]"
|
||||
>
|
||||
<InputNumber
|
||||
v-model:value="formData.costPrice"
|
||||
placeholder="请输入成本价"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
:step="0.01"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<!-- 规格管理 -->
|
||||
<Form.Item v-if="!isEdit" label="商品规格">
|
||||
<div class="space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<Space>
|
||||
<Button type="dashed" @click="showSpecs = !showSpecs">
|
||||
<template #icon>
|
||||
<component
|
||||
:is="showSpecs ? UpIcon : DownIcon"
|
||||
class="h-4 w-4"
|
||||
/>
|
||||
</template>
|
||||
{{ showSpecs ? '收起规格' : '添加规格' }}
|
||||
</Button>
|
||||
</Space>
|
||||
<Button v-if="showSpecs" type="primary" @click="addSpec">
|
||||
<template #icon>
|
||||
<PlusIcon class="h-4 w-4" />
|
||||
</template>
|
||||
添加规格
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="showSpecs"
|
||||
class="rounded-lg border border-gray-200 bg-white p-4"
|
||||
>
|
||||
<Table
|
||||
:columns="specColumns"
|
||||
:data-source="specs"
|
||||
:pagination="false"
|
||||
row-key="index"
|
||||
size="small"
|
||||
>
|
||||
<template #emptyText>
|
||||
<div class="py-4 text-center text-gray-400">
|
||||
暂无规格,点击上方"添加规格"按钮添加
|
||||
</div>
|
||||
</template>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
+360
@@ -0,0 +1,360 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductDTO, ProductVO } from '#/api/shop/product/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { h, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Table,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createProductSpecApi,
|
||||
deleteProductSpecApi,
|
||||
getProductSpecPageApi,
|
||||
updateProductSpecApi,
|
||||
} from '#/api/shop/product';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 内部状态管理
|
||||
const currentProduct = ref<null | ProductVO.Info>(null);
|
||||
|
||||
// 响应式数据
|
||||
const specLoading = ref(false);
|
||||
const specList = ref<ProductVO.SpecInfo[]>([]);
|
||||
const specTotal = ref(0);
|
||||
const specCurrent = ref(1);
|
||||
const specPageSize = ref(10);
|
||||
|
||||
// 规格表单相关
|
||||
const specFormRef = ref();
|
||||
const isEditSpec = ref(false);
|
||||
const currentSpecId = ref<null | number>(null);
|
||||
|
||||
const specFormData = ref({
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
});
|
||||
|
||||
// 声明模态框 API(稍后赋值)
|
||||
let modalApi: ReturnType<typeof useVbenModal>[1];
|
||||
let specFormModalApi: ReturnType<typeof useVbenModal>[1];
|
||||
|
||||
// 处理取消
|
||||
function handleCancel() {
|
||||
modalApi?.close();
|
||||
}
|
||||
|
||||
// 处理规格表单取消
|
||||
function handleSpecCancel() {
|
||||
specFormModalApi?.close();
|
||||
}
|
||||
|
||||
// 处理规格表单提交
|
||||
async function handleSpecSubmit() {
|
||||
try {
|
||||
await specFormRef.value?.validate();
|
||||
specFormModalApi?.setState({ confirmLoading: true });
|
||||
|
||||
if (isEditSpec.value && currentSpecId.value) {
|
||||
await updateProductSpecApi(
|
||||
currentSpecId.value,
|
||||
specFormData.value as ProductDTO.UpdateSpec,
|
||||
);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
if (!currentProduct.value) {
|
||||
message.error('商品信息不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
const createData: ProductDTO.CreateSpec = {
|
||||
productId: currentProduct.value.id,
|
||||
...specFormData.value,
|
||||
};
|
||||
await createProductSpecApi(createData);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
specFormModalApi?.close();
|
||||
await fetchSpecList();
|
||||
} catch (error) {
|
||||
console.error('保存规格失败:', error);
|
||||
message.error('保存规格失败');
|
||||
} finally {
|
||||
specFormModalApi?.setState({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
|
||||
// 创建主模态框
|
||||
const [Modal, _modalApi] = useVbenModal({
|
||||
title: '管理规格',
|
||||
draggable: true,
|
||||
class: 'w-[800px]',
|
||||
contentClass: 'px-6 py-4',
|
||||
showConfirmButton: false,
|
||||
showCancelButton: false,
|
||||
onCancel: handleCancel,
|
||||
onOpenChange: (isOpen: boolean) => {
|
||||
if (!isOpen) {
|
||||
emit('success');
|
||||
}
|
||||
},
|
||||
});
|
||||
modalApi = _modalApi;
|
||||
|
||||
// 创建规格表单模态框
|
||||
const [SpecFormModal, _specFormModalApi] = useVbenModal({
|
||||
title: '添加规格',
|
||||
draggable: true,
|
||||
contentClass: 'px-6 py-4',
|
||||
onConfirm: handleSpecSubmit,
|
||||
onCancel: handleSpecCancel,
|
||||
});
|
||||
specFormModalApi = _specFormModalApi;
|
||||
|
||||
// 模态框标题(通过 modalApi 动态更新)
|
||||
// 规格表单标题(通过 specFormModalApi 动态更新)
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '规格名称',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
title: '规格编码',
|
||||
dataIndex: 'specCode',
|
||||
key: 'specCode',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
title: '成本价',
|
||||
dataIndex: 'costPrice',
|
||||
key: 'costPrice',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: ProductVO.SpecInfo }) => {
|
||||
return `¥${record.costPrice.toFixed(2)}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 150,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: ProductVO.SpecInfo }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(
|
||||
Button,
|
||||
{
|
||||
size: 'small',
|
||||
onClick: () => handleEditSpec(record),
|
||||
},
|
||||
{ default: () => '编辑' },
|
||||
),
|
||||
h(
|
||||
Button,
|
||||
{
|
||||
size: 'small',
|
||||
danger: true,
|
||||
onClick: () => handleDeleteSpec(record),
|
||||
},
|
||||
{ default: () => '删除' },
|
||||
),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// 获取规格列表
|
||||
async function fetchSpecList() {
|
||||
if (!currentProduct.value) return;
|
||||
|
||||
try {
|
||||
specLoading.value = true;
|
||||
const params: PageQueryDTO<ProductDTO.SpecFilters> = {
|
||||
page: specCurrent.value,
|
||||
pageSize: specPageSize.value,
|
||||
filters: {
|
||||
productId: currentProduct.value.id,
|
||||
},
|
||||
};
|
||||
const data = await getProductSpecPageApi(params);
|
||||
specList.value = data.records;
|
||||
specTotal.value = data.total;
|
||||
} catch (error) {
|
||||
console.error('获取规格列表失败:', error);
|
||||
message.error('获取规格列表失败');
|
||||
} finally {
|
||||
specLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理规格表格变化
|
||||
function handleSpecTableChange(pagination: any) {
|
||||
specCurrent.value = pagination.current;
|
||||
specPageSize.value = pagination.pageSize;
|
||||
fetchSpecList();
|
||||
}
|
||||
|
||||
// 处理添加规格
|
||||
function handleAddSpec() {
|
||||
isEditSpec.value = false;
|
||||
currentSpecId.value = null;
|
||||
specFormData.value = {
|
||||
name: '',
|
||||
specCode: '',
|
||||
costPrice: 0,
|
||||
};
|
||||
specFormModalApi.setState({ title: '添加规格' });
|
||||
specFormModalApi.open();
|
||||
}
|
||||
|
||||
// 处理编辑规格
|
||||
function handleEditSpec(record: ProductVO.SpecInfo) {
|
||||
isEditSpec.value = true;
|
||||
currentSpecId.value = record.id;
|
||||
specFormData.value = {
|
||||
name: record.name,
|
||||
specCode: record.specCode || '',
|
||||
costPrice: record.costPrice,
|
||||
};
|
||||
specFormModalApi.setState({ title: '编辑规格' });
|
||||
specFormModalApi.open();
|
||||
}
|
||||
|
||||
// 处理删除规格
|
||||
async function handleDeleteSpec(record: ProductVO.SpecInfo) {
|
||||
try {
|
||||
await deleteProductSpecApi(record.id);
|
||||
message.success('删除成功');
|
||||
await fetchSpecList();
|
||||
} catch (error) {
|
||||
console.error('删除规格失败:', error);
|
||||
message.error('删除规格失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(product: ProductVO.Info) {
|
||||
currentProduct.value = product;
|
||||
specCurrent.value = 1;
|
||||
specPageSize.value = 10;
|
||||
modalApi.setState({
|
||||
title: `管理规格 - ${product.name}`,
|
||||
});
|
||||
modalApi.open();
|
||||
fetchSpecList();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal>
|
||||
<div class="space-y-4">
|
||||
<!-- 商品信息 -->
|
||||
<div class="rounded-lg bg-gray-50 p-4">
|
||||
<h3 class="mb-2 font-medium text-gray-900">商品信息</h3>
|
||||
<div class="grid grid-cols-2 gap-4 text-sm">
|
||||
<div>
|
||||
<span class="text-gray-500">商品名称:</span>
|
||||
<span class="ml-2 font-medium">{{ currentProduct?.name }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-gray-500">商品ID:</span>
|
||||
<span class="ml-2 font-medium">{{ currentProduct?.id }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 规格列表 -->
|
||||
<div>
|
||||
<div class="mb-4 flex items-center justify-between">
|
||||
<h3 class="font-medium text-gray-900">商品规格</h3>
|
||||
<Button type="primary" @click="handleAddSpec"> 添加规格 </Button>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="specList"
|
||||
:loading="specLoading"
|
||||
:pagination="{
|
||||
current: specCurrent,
|
||||
pageSize: specPageSize,
|
||||
total: specTotal,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) =>
|
||||
`第 ${range[0]}-${range[1]} 条/共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
@change="handleSpecTableChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<!-- 规格表单模态框 -->
|
||||
<SpecFormModal>
|
||||
<Form
|
||||
ref="specFormRef"
|
||||
:model="specFormData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item
|
||||
label="规格名称"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: '请输入规格名称' }]"
|
||||
>
|
||||
<Input v-model:value="specFormData.name" placeholder="请输入规格名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="规格编码" name="specCode">
|
||||
<Input
|
||||
v-model:value="specFormData.specCode"
|
||||
placeholder="请输入规格编码"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="成本价"
|
||||
name="costPrice"
|
||||
:rules="[{ required: true, message: '请输入成本价' }]"
|
||||
>
|
||||
<InputNumber
|
||||
v-model:value="specFormData.costPrice"
|
||||
placeholder="请输入成本价"
|
||||
style="width: 100%"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</SpecFormModal>
|
||||
</template>
|
||||
@@ -0,0 +1,169 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductVO } from '#/api/shop/product/types';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Divider, Flex, Space } from 'ant-design-vue';
|
||||
|
||||
import { deleteProductApi } from '#/api/shop/product';
|
||||
|
||||
import ProductFormModal from './components/ProductFormModal.vue';
|
||||
import ProductSpecModal from './components/ProductSpecModal.vue';
|
||||
import ProductGridView from './views/ProductGridView/index.vue';
|
||||
import ProductListView from './views/ProductListView/index.vue';
|
||||
|
||||
defineOptions({ name: 'ProductManagement' });
|
||||
// 创建图标组件
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
const ListIcon = createIconifyIcon('lucide:list');
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const viewMode = ref<'grid' | 'table'>('grid');
|
||||
const productFormModalRef = ref();
|
||||
const productSpecModalRef = ref();
|
||||
const productListViewRef = ref<null | { refreshTable: () => void }>(null);
|
||||
const productGridViewRef = ref<null | { refreshTable: () => void }>(null);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
productCode: '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
minCostPrice: undefined as number | undefined,
|
||||
maxCostPrice: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (viewMode.value === 'table' && productListViewRef.value) {
|
||||
productListViewRef.value.refreshTable();
|
||||
} else if (viewMode.value === 'grid' && productGridViewRef.value) {
|
||||
productGridViewRef.value.refreshTable();
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加商品
|
||||
function handleAdd() {
|
||||
productFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑商品
|
||||
function handleEdit(record: ProductVO.Info) {
|
||||
productFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除商品
|
||||
async function handleDelete(record: ProductVO.Info) {
|
||||
try {
|
||||
await deleteProductApi(record.id);
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除商品失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理列表视图删除
|
||||
const handleListViewDelete = (product: ProductVO.Info) => {
|
||||
handleDelete(product);
|
||||
};
|
||||
|
||||
// 处理管理规格
|
||||
function handleManageSpecs(record: ProductVO.Info) {
|
||||
productSpecModalRef.value?.open(record);
|
||||
}
|
||||
|
||||
// 切换视图模式
|
||||
function toggleViewMode() {
|
||||
viewMode.value = viewMode.value === 'grid' ? 'table' : 'grid';
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
// 处理规格模态框成功
|
||||
function handleSpecModalSuccess() {
|
||||
// 规格管理成功后可能需要刷新商品列表
|
||||
refreshTable();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page :auto-content-height="true" content-class="flex-col">
|
||||
<!-- 工具栏区域 -->
|
||||
<template #extra>
|
||||
<Flex gap="small" align="center">
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="mr-2 h-4 w-4" />
|
||||
添加商品
|
||||
</Button>
|
||||
</Space>
|
||||
|
||||
<Divider type="vertical" />
|
||||
|
||||
<Space>
|
||||
<Button
|
||||
:type="viewMode === 'grid' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<GridIcon class="mr-2 h-4 w-4" />
|
||||
网格视图
|
||||
</Button>
|
||||
<Button
|
||||
:type="viewMode === 'table' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<ListIcon class="mr-2 h-4 w-4" />
|
||||
列表视图
|
||||
</Button>
|
||||
</Space>
|
||||
</Flex>
|
||||
</template>
|
||||
|
||||
<!-- 列表视图 -->
|
||||
<ProductListView
|
||||
v-if="viewMode === 'table'"
|
||||
ref="productListViewRef"
|
||||
v-model:search-form="searchForm"
|
||||
@edit="handleEdit"
|
||||
@delete="handleListViewDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
/>
|
||||
|
||||
<!-- 网格视图 -->
|
||||
<ProductGridView
|
||||
v-else
|
||||
ref="productGridViewRef"
|
||||
v-model:search-form="searchForm"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
/>
|
||||
|
||||
<!-- 商品表单模态框 -->
|
||||
<ProductFormModal ref="productFormModalRef" @success="handleModalSuccess" />
|
||||
|
||||
<!-- 商品规格管理模态框 -->
|
||||
<ProductSpecModal
|
||||
ref="productSpecModalRef"
|
||||
@success="handleSpecModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.line-clamp-2 {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
+365
@@ -0,0 +1,365 @@
|
||||
<script setup lang="ts">
|
||||
import type { ProductDTO, ProductVO } from '#/api/shop/product/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
import { Waterfall } from 'vue-waterfall-plugin-next';
|
||||
import 'vue-waterfall-plugin-next/dist/style.css';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Empty,
|
||||
Flex,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Space,
|
||||
Spin,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getProductPageApi } from '#/api/shop/product';
|
||||
|
||||
import ProductCard from '../../components/ProductCard.vue';
|
||||
|
||||
defineOptions({ name: 'ProductGridView' });
|
||||
|
||||
const props = defineProps<{
|
||||
searchForm: {
|
||||
maxCostPrice?: number;
|
||||
minCostPrice?: number;
|
||||
name: string;
|
||||
productCode: string;
|
||||
skuCode: string;
|
||||
specCode: string;
|
||||
};
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'edit', product: ProductVO.Info): void;
|
||||
(e: 'delete', product: ProductVO.Info): void;
|
||||
(e: 'manageSpecs', product: ProductVO.Info): void;
|
||||
(e: 'update:searchForm', value: typeof props.searchForm): void;
|
||||
}>();
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const productList = ref<ProductVO.Info[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(24); // 无限滚动默认每页24个
|
||||
const hasMore = ref(true); // 是否还有更多数据
|
||||
const scrollContainerRef = ref<HTMLElement | null>(null);
|
||||
|
||||
// 本地搜索表单副本(用于 v-model)
|
||||
const localSearchForm = ref({
|
||||
name: props.searchForm.name,
|
||||
productCode: props.searchForm.productCode,
|
||||
specCode: props.searchForm.specCode,
|
||||
skuCode: props.searchForm.skuCode,
|
||||
minCostPrice: props.searchForm.minCostPrice,
|
||||
maxCostPrice: props.searchForm.maxCostPrice,
|
||||
});
|
||||
|
||||
// 监听 props 变化,同步到本地
|
||||
watch(
|
||||
() => props.searchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
localSearchForm.value.name !== newForm.name ||
|
||||
localSearchForm.value.productCode !== newForm.productCode ||
|
||||
localSearchForm.value.specCode !== newForm.specCode ||
|
||||
localSearchForm.value.skuCode !== newForm.skuCode ||
|
||||
localSearchForm.value.minCostPrice !== newForm.minCostPrice ||
|
||||
localSearchForm.value.maxCostPrice !== newForm.maxCostPrice
|
||||
) {
|
||||
localSearchForm.value.name = newForm.name;
|
||||
localSearchForm.value.productCode = newForm.productCode;
|
||||
localSearchForm.value.specCode = newForm.specCode;
|
||||
localSearchForm.value.skuCode = newForm.skuCode;
|
||||
localSearchForm.value.minCostPrice = newForm.minCostPrice;
|
||||
localSearchForm.value.maxCostPrice = newForm.maxCostPrice;
|
||||
// 重置分页和列表
|
||||
current.value = 1;
|
||||
productList.value = [];
|
||||
hasMore.value = true;
|
||||
loadProductList(true);
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// 监听本地表单变化,同步到父组件
|
||||
watch(
|
||||
localSearchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
props.searchForm.name !== newForm.name ||
|
||||
props.searchForm.productCode !== newForm.productCode ||
|
||||
props.searchForm.specCode !== newForm.specCode ||
|
||||
props.searchForm.skuCode !== newForm.skuCode ||
|
||||
props.searchForm.minCostPrice !== newForm.minCostPrice ||
|
||||
props.searchForm.maxCostPrice !== newForm.maxCostPrice
|
||||
) {
|
||||
emit('update:searchForm', { ...newForm });
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// 加载商品列表
|
||||
const loadProductList = async (reset = false) => {
|
||||
if (loading.value || (!hasMore.value && !reset)) return;
|
||||
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<ProductDTO.Filters> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
name: localSearchForm.value.name || undefined,
|
||||
productCode: localSearchForm.value.productCode || undefined,
|
||||
specCode: localSearchForm.value.specCode || undefined,
|
||||
skuCode: localSearchForm.value.skuCode || undefined,
|
||||
minCostPrice: localSearchForm.value.minCostPrice,
|
||||
maxCostPrice: localSearchForm.value.maxCostPrice,
|
||||
},
|
||||
};
|
||||
|
||||
const response = await getProductPageApi(params);
|
||||
|
||||
if (reset) {
|
||||
productList.value = response.records;
|
||||
} else {
|
||||
productList.value.push(...response.records);
|
||||
}
|
||||
|
||||
total.value = response.total;
|
||||
|
||||
// 判断是否还有更多数据
|
||||
if (productList.value.length >= response.total) {
|
||||
hasMore.value = false;
|
||||
} else {
|
||||
current.value++;
|
||||
hasMore.value = true;
|
||||
}
|
||||
} catch {
|
||||
message.error('加载商品列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 搜索
|
||||
const handleSearch = () => {
|
||||
current.value = 1;
|
||||
productList.value = [];
|
||||
hasMore.value = true;
|
||||
loadProductList(true);
|
||||
};
|
||||
|
||||
// 重置
|
||||
const handleReset = () => {
|
||||
localSearchForm.value = {
|
||||
name: '',
|
||||
productCode: '',
|
||||
specCode: '',
|
||||
skuCode: '',
|
||||
minCostPrice: undefined,
|
||||
maxCostPrice: undefined,
|
||||
};
|
||||
handleSearch();
|
||||
};
|
||||
|
||||
// 滚动监听
|
||||
const handleScroll = () => {
|
||||
const container = scrollContainerRef.value;
|
||||
if (!container || loading.value || !hasMore.value) return;
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = container;
|
||||
// 当滚动到距离底部 200px 时加载更多
|
||||
if (scrollTop + clientHeight >= scrollHeight - 200) {
|
||||
loadProductList();
|
||||
}
|
||||
};
|
||||
|
||||
// 事件处理
|
||||
const handleEdit = (product: ProductVO.Info) => {
|
||||
emit('edit', product);
|
||||
};
|
||||
|
||||
const handleDelete = (product: ProductVO.Info) => {
|
||||
emit('delete', product);
|
||||
};
|
||||
|
||||
const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
emit('manageSpecs', product);
|
||||
};
|
||||
|
||||
// 刷新列表
|
||||
function refreshTable() {
|
||||
handleSearch();
|
||||
}
|
||||
|
||||
// 暴露方法
|
||||
defineExpose({
|
||||
refreshTable,
|
||||
});
|
||||
|
||||
// 滚动监听
|
||||
onMounted(() => {
|
||||
loadProductList(true);
|
||||
// 延迟绑定滚动事件,确保 DOM 已渲染
|
||||
setTimeout(() => {
|
||||
if (scrollContainerRef.value) {
|
||||
scrollContainerRef.value.addEventListener('scroll', handleScroll);
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
if (scrollContainerRef.value) {
|
||||
scrollContainerRef.value.removeEventListener('scroll', handleScroll);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex h-full flex-col">
|
||||
<!-- 搜索区域 -->
|
||||
<Card class="mb-4" :body-style="{ padding: '16px' }">
|
||||
<Form :model="localSearchForm" layout="inline" class="w-full">
|
||||
<Flex class="w-full" justify="end" align="center" gap="4">
|
||||
<Form.Item label="商品名称" class="mb-0">
|
||||
<Input
|
||||
v-model:value="localSearchForm.name"
|
||||
placeholder="请输入商品名称"
|
||||
style="width: 200px"
|
||||
allow-clear
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品编码" class="mb-0">
|
||||
<Input
|
||||
v-model:value="localSearchForm.productCode"
|
||||
placeholder="请输入商品编码"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="规格编码" class="mb-0">
|
||||
<Input
|
||||
v-model:value="localSearchForm.specCode"
|
||||
placeholder="请输入规格编码"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="商品SKU" class="mb-0">
|
||||
<Input
|
||||
v-model:value="localSearchForm.skuCode"
|
||||
placeholder="请输入商品SKU"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="成本价范围" class="mb-0">
|
||||
<div class="flex items-center gap-2">
|
||||
<InputNumber
|
||||
v-model:value="localSearchForm.minCostPrice"
|
||||
placeholder="最小值"
|
||||
style="width: 100px"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
<span class="text-gray-500">-</span>
|
||||
<InputNumber
|
||||
v-model:value="localSearchForm.maxCostPrice"
|
||||
placeholder="最大值"
|
||||
style="width: 100px"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
/>
|
||||
</div>
|
||||
</Form.Item>
|
||||
<Form.Item class="mb-0">
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
<div class="ml-auto text-sm text-gray-500 dark:text-gray-400">
|
||||
共 {{ total }} 个商品
|
||||
</div>
|
||||
</Flex>
|
||||
</Form>
|
||||
</Card>
|
||||
|
||||
<!-- 网格内容 -->
|
||||
<Card
|
||||
class="flex flex-1 flex-col overflow-y-auto"
|
||||
:body-style="{
|
||||
padding: '16px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
height: '100%',
|
||||
}"
|
||||
>
|
||||
<Spin :spinning="loading && productList.length === 0">
|
||||
<!-- 空状态 -->
|
||||
<div
|
||||
v-if="!loading && productList.length === 0"
|
||||
class="flex h-full items-center justify-center py-8"
|
||||
>
|
||||
<Empty />
|
||||
</div>
|
||||
|
||||
<!-- 瀑布流 -->
|
||||
<Waterfall
|
||||
v-else-if="productList.length > 0"
|
||||
:list="productList"
|
||||
row-key="id"
|
||||
:width="300"
|
||||
:breakpoints="{
|
||||
1600: { rowPerView: 4 },
|
||||
1400: { rowPerView: 3 },
|
||||
1200: { rowPerView: 3 },
|
||||
992: { rowPerView: 2 },
|
||||
768: { rowPerView: 2 },
|
||||
500: { rowPerView: 1 },
|
||||
}"
|
||||
:gutter="16"
|
||||
>
|
||||
<template #default="{ item }">
|
||||
<div class="w-full">
|
||||
<ProductCard
|
||||
:product="item"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@manage-specs="handleManageSpecs"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Waterfall>
|
||||
|
||||
<!-- 加载更多提示 -->
|
||||
<div
|
||||
v-if="productList.length > 0"
|
||||
class="mt-4 flex justify-center py-4"
|
||||
>
|
||||
<Spin v-if="loading" />
|
||||
<div
|
||||
v-else-if="!hasMore"
|
||||
class="text-sm text-gray-500 dark:text-gray-400"
|
||||
>
|
||||
没有更多商品了
|
||||
</div>
|
||||
</div>
|
||||
</Spin>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
<script setup lang="ts">
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { ProductDTO, ProductVO } from '#/api/shop/product/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { Button, Image, message, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { getProductPageApi } from '#/api/shop/product';
|
||||
|
||||
defineOptions({ name: 'ProductListView' });
|
||||
|
||||
const props = defineProps<{
|
||||
searchForm: {
|
||||
maxCostPrice?: number;
|
||||
minCostPrice?: number;
|
||||
name: string;
|
||||
productCode: string;
|
||||
skuCode: string;
|
||||
specCode: string;
|
||||
};
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'edit', product: ProductVO.Info): void;
|
||||
(e: 'delete', product: ProductVO.Info): void;
|
||||
(e: 'manageSpecs', product: ProductVO.Info): void;
|
||||
(e: 'update:searchForm', value: typeof props.searchForm): void;
|
||||
}>();
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
|
||||
// 本地搜索表单副本(用于 v-model)
|
||||
const localSearchForm = ref({
|
||||
name: props.searchForm.name,
|
||||
productCode: props.searchForm.productCode,
|
||||
specCode: props.searchForm.specCode,
|
||||
skuCode: props.searchForm.skuCode,
|
||||
minCostPrice: props.searchForm.minCostPrice,
|
||||
maxCostPrice: props.searchForm.maxCostPrice,
|
||||
});
|
||||
|
||||
// 监听 props 变化,同步到本地
|
||||
watch(
|
||||
() => props.searchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
localSearchForm.value.name !== newForm.name ||
|
||||
localSearchForm.value.productCode !== newForm.productCode ||
|
||||
localSearchForm.value.specCode !== newForm.specCode ||
|
||||
localSearchForm.value.skuCode !== newForm.skuCode ||
|
||||
localSearchForm.value.minCostPrice !== newForm.minCostPrice ||
|
||||
localSearchForm.value.maxCostPrice !== newForm.maxCostPrice
|
||||
) {
|
||||
localSearchForm.value.name = newForm.name;
|
||||
localSearchForm.value.productCode = newForm.productCode;
|
||||
localSearchForm.value.specCode = newForm.specCode;
|
||||
localSearchForm.value.skuCode = newForm.skuCode;
|
||||
localSearchForm.value.minCostPrice = newForm.minCostPrice;
|
||||
localSearchForm.value.maxCostPrice = newForm.maxCostPrice;
|
||||
refreshTable();
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// 监听本地表单变化,同步到父组件
|
||||
watch(
|
||||
localSearchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
props.searchForm.name !== newForm.name ||
|
||||
props.searchForm.productCode !== newForm.productCode ||
|
||||
props.searchForm.specCode !== newForm.specCode ||
|
||||
props.searchForm.skuCode !== newForm.skuCode ||
|
||||
props.searchForm.minCostPrice !== newForm.minCostPrice ||
|
||||
props.searchForm.maxCostPrice !== newForm.maxCostPrice
|
||||
) {
|
||||
emit('update:searchForm', { ...newForm });
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
title: '主图',
|
||||
width: 60,
|
||||
slots: { default: 'mainImage' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '商品名称',
|
||||
minWidth: 200,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'productCode',
|
||||
title: '商品编码',
|
||||
minWidth: 150,
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '规格数量',
|
||||
minWidth: 100,
|
||||
slots: { default: 'specs' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
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: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ProductDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
name: localSearchForm.value.name || undefined,
|
||||
productCode: localSearchForm.value.productCode || undefined,
|
||||
specCode: localSearchForm.value.specCode || undefined,
|
||||
skuCode: localSearchForm.value.skuCode || undefined,
|
||||
minCostPrice: localSearchForm.value.minCostPrice,
|
||||
maxCostPrice: localSearchForm.value.maxCostPrice,
|
||||
},
|
||||
};
|
||||
const data = await getProductPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取商品列表失败:', error);
|
||||
message.error('获取商品列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品名称',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '商品名称',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品编码',
|
||||
},
|
||||
fieldName: 'productCode',
|
||||
label: '商品编码',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入规格编码',
|
||||
},
|
||||
fieldName: 'specCode',
|
||||
label: '规格编码',
|
||||
},
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入商品SKU',
|
||||
},
|
||||
fieldName: 'skuCode',
|
||||
label: '商品SKU',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '最小值',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'minCostPrice',
|
||||
label: '成本价最小值',
|
||||
},
|
||||
{
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '最大值',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'maxCostPrice',
|
||||
label: '成本价最大值',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '商品管理',
|
||||
});
|
||||
|
||||
// 事件处理
|
||||
const handleEdit = (product: ProductVO.Info) => {
|
||||
emit('edit', product);
|
||||
};
|
||||
|
||||
const handleDelete = (product: ProductVO.Info) => {
|
||||
emit('delete', product);
|
||||
};
|
||||
|
||||
const handleManageSpecs = (product: ProductVO.Info) => {
|
||||
emit('manageSpecs', product);
|
||||
};
|
||||
|
||||
// 暴露刷新方法
|
||||
defineExpose({
|
||||
refreshTable,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Grid :loading="loading">
|
||||
<!-- 主图列 -->
|
||||
<template #mainImage="{ row }: { row: any }">
|
||||
<Image
|
||||
:src="row.mainImage"
|
||||
:alt="row.name"
|
||||
width="60"
|
||||
height="60"
|
||||
style="object-fit: cover; border-radius: 4px"
|
||||
:preview="true"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- 规格数量列 -->
|
||||
<template #specs="{ row }: { row: any }">
|
||||
<Tag :color="(row.specs?.length || 0) > 0 ? 'blue' : 'default'">
|
||||
{{ row.specs?.length || 0 }} 个规格
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Button size="small" @click="handleManageSpecs(row)"> 规格 </Button>
|
||||
<Button size="small" danger @click="handleDelete(row)"> 删除 </Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
</template>
|
||||
+384
@@ -0,0 +1,384 @@
|
||||
<script setup lang="ts">
|
||||
import type { PromotionFeeTypeVO } from '#/api/ecommerce/promotion-fee-type';
|
||||
import type {
|
||||
PromotionFeeDTO,
|
||||
PromotionFeeVO,
|
||||
} from '#/api/shop/promotion-fee/types';
|
||||
import type { ShopVO } from '#/api/shop/shop/types';
|
||||
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
DatePicker,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Select,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getActivePromotionFeeTypeListApi } from '#/api/ecommerce/promotion-fee-type';
|
||||
import {
|
||||
createPromotionFeeApi,
|
||||
updatePromotionFeeApi,
|
||||
} from '#/api/shop/promotion-fee';
|
||||
import { getShopPageApi } from '#/api/shop/shop';
|
||||
|
||||
defineOptions({ name: 'PromotionFeeFormModal' });
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
open: boolean;
|
||||
promotionFeeData?: null | PromotionFeeVO.Info;
|
||||
}
|
||||
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'update:open', value: boolean): void;
|
||||
(e: 'success'): void;
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[800px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleOk();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const isEdit = ref(false);
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<PromotionFeeDTO.Create>({
|
||||
shopId: undefined as any,
|
||||
feeTypeId: undefined as any,
|
||||
feeName: '',
|
||||
platform: undefined,
|
||||
campaignName: '',
|
||||
feeAmount: undefined as any,
|
||||
baseAmount: undefined,
|
||||
feeRate: undefined,
|
||||
clickCount: undefined,
|
||||
impressionCount: undefined,
|
||||
conversionCount: undefined,
|
||||
feeDate: undefined as any,
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 表单验证规则
|
||||
const rules = {
|
||||
shopId: [{ required: true, message: '请选择店铺', trigger: 'change' }],
|
||||
feeTypeId: [
|
||||
{ required: true, message: '请选择推广费类型', trigger: 'change' },
|
||||
],
|
||||
feeName: [{ required: true, message: '请输入推广费名称', trigger: 'blur' }],
|
||||
feeAmount: [{ required: true, message: '请输入推广费金额', trigger: 'blur' }],
|
||||
feeDate: [{ required: true, message: '请选择发生日期', trigger: 'change' }],
|
||||
} as any;
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
{ label: '抖音', value: '抖音' },
|
||||
{ label: '快手', value: '快手' },
|
||||
{ label: '其他', value: '其他' },
|
||||
];
|
||||
|
||||
// 店铺列表
|
||||
const shopList = ref<ShopVO.Info[]>([]);
|
||||
const shopListLoading = ref(false);
|
||||
|
||||
// 推广费类型列表
|
||||
const feeTypeList = ref<PromotionFeeTypeVO.Info[]>([]);
|
||||
const feeTypeListLoading = ref(false);
|
||||
|
||||
// 监听props变化
|
||||
watch(
|
||||
() => props.open,
|
||||
(newVal) => {
|
||||
if (newVal) {
|
||||
modalApi.open();
|
||||
isEdit.value = !!props.promotionFeeData;
|
||||
if (props.promotionFeeData) {
|
||||
// 编辑模式,填充表单数据
|
||||
formData.value = {
|
||||
shopId: props.promotionFeeData.shopId,
|
||||
feeTypeId: props.promotionFeeData.feeTypeId,
|
||||
feeName: props.promotionFeeData.feeName,
|
||||
platform: props.promotionFeeData.platform,
|
||||
campaignName: props.promotionFeeData.campaignName || '',
|
||||
feeAmount: props.promotionFeeData.feeAmount,
|
||||
baseAmount: props.promotionFeeData.baseAmount,
|
||||
feeRate: props.promotionFeeData.feeRate,
|
||||
clickCount: props.promotionFeeData.clickCount,
|
||||
impressionCount: props.promotionFeeData.impressionCount,
|
||||
conversionCount: props.promotionFeeData.conversionCount,
|
||||
feeDate: props.promotionFeeData.feeDate,
|
||||
remark: props.promotionFeeData.remark || '',
|
||||
};
|
||||
} else {
|
||||
// 新增模式,重置表单数据
|
||||
resetFormData();
|
||||
}
|
||||
} else {
|
||||
modalApi.close();
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// 加载店铺列表
|
||||
const loadShopList = async () => {
|
||||
shopListLoading.value = true;
|
||||
try {
|
||||
const response = await getShopPageApi({
|
||||
page: 1,
|
||||
pageSize: 1000,
|
||||
filters: {},
|
||||
});
|
||||
shopList.value = response.records;
|
||||
} catch (error) {
|
||||
console.error('加载店铺列表失败:', error);
|
||||
} finally {
|
||||
shopListLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 加载推广费类型列表
|
||||
const loadFeeTypeList = async () => {
|
||||
feeTypeListLoading.value = true;
|
||||
try {
|
||||
const response = await getActivePromotionFeeTypeListApi();
|
||||
feeTypeList.value = response;
|
||||
} catch (error) {
|
||||
console.error('加载推广费类型列表失败:', error);
|
||||
} finally {
|
||||
feeTypeListLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 重置表单数据
|
||||
const resetFormData = () => {
|
||||
formData.value = {
|
||||
shopId: undefined as any,
|
||||
feeTypeId: undefined as any,
|
||||
feeName: '',
|
||||
platform: undefined,
|
||||
campaignName: '',
|
||||
feeAmount: undefined as any,
|
||||
baseAmount: undefined,
|
||||
feeRate: undefined,
|
||||
clickCount: undefined,
|
||||
impressionCount: undefined,
|
||||
conversionCount: undefined,
|
||||
feeDate: undefined as any,
|
||||
remark: '',
|
||||
};
|
||||
};
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
|
||||
if (isEdit.value && props.promotionFeeData) {
|
||||
// 更新推广费记录
|
||||
const updateData: PromotionFeeDTO.Update = {
|
||||
id: props.promotionFeeData.id,
|
||||
...formData.value,
|
||||
};
|
||||
await updatePromotionFeeApi(updateData);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
// 创建推广费记录
|
||||
await createPromotionFeeApi(formData.value);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
} catch (error) {
|
||||
console.error('操作失败:', error);
|
||||
message.error(isEdit.value ? '更新失败' : '创建失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 取消操作
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
modalApi.close();
|
||||
emit('update:open', false);
|
||||
resetFormData();
|
||||
};
|
||||
|
||||
// 组件挂载时加载数据
|
||||
onMounted(() => {
|
||||
loadShopList();
|
||||
loadFeeTypeList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="isEdit ? '编辑推广费记录' : '新增推广费记录'">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="rules"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="店铺" name="shopId">
|
||||
<Select
|
||||
v-model:value="formData.shopId"
|
||||
placeholder="请选择店铺"
|
||||
:loading="shopListLoading"
|
||||
>
|
||||
<Select.Option
|
||||
v-for="shop in shopList"
|
||||
:key="shop.id"
|
||||
:value="shop.id"
|
||||
>
|
||||
{{ shop.name }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="推广费类型" name="feeTypeId">
|
||||
<Select
|
||||
v-model:value="formData.feeTypeId"
|
||||
placeholder="请选择推广费类型"
|
||||
:loading="feeTypeListLoading"
|
||||
>
|
||||
<Select.Option
|
||||
v-for="feeType in feeTypeList"
|
||||
:key="feeType.id"
|
||||
:value="feeType.id"
|
||||
>
|
||||
{{ feeType.typeName }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="推广费名称" name="feeName">
|
||||
<Input
|
||||
v-model:value="formData.feeName"
|
||||
placeholder="请输入推广费名称"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="平台" name="platform">
|
||||
<Select
|
||||
v-model:value="formData.platform"
|
||||
placeholder="请选择平台"
|
||||
allow-clear
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in platformOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="推广活动名称" name="campaignName">
|
||||
<Input
|
||||
v-model:value="formData.campaignName"
|
||||
placeholder="请输入推广活动名称"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="推广费金额" name="feeAmount">
|
||||
<InputNumber
|
||||
v-model:value="formData.feeAmount"
|
||||
placeholder="请输入推广费金额"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="基础金额" name="baseAmount">
|
||||
<InputNumber
|
||||
v-model:value="formData.baseAmount"
|
||||
placeholder="请输入基础金额(用于按比例计算)"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="费率" name="feeRate">
|
||||
<InputNumber
|
||||
v-model:value="formData.feeRate"
|
||||
placeholder="请输入费率(用于按比例计算)"
|
||||
:min="0"
|
||||
:max="1"
|
||||
:precision="4"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="点击次数" name="clickCount">
|
||||
<InputNumber
|
||||
v-model:value="formData.clickCount"
|
||||
placeholder="请输入点击次数"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="展示次数" name="impressionCount">
|
||||
<InputNumber
|
||||
v-model:value="formData.impressionCount"
|
||||
placeholder="请输入展示次数"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="转化次数" name="conversionCount">
|
||||
<InputNumber
|
||||
v-model:value="formData.conversionCount"
|
||||
placeholder="请输入转化次数"
|
||||
:min="0"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="发生日期" name="feeDate">
|
||||
<DatePicker
|
||||
v-model:value="formData.feeDate"
|
||||
placeholder="请选择推广费发生日期"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="备注" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入备注"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,377 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type {
|
||||
PromotionFeeDTO,
|
||||
PromotionFeeVO,
|
||||
} from '#/api/shop/promotion-fee/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
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 {
|
||||
deletePromotionFeeApi,
|
||||
getPromotionFeePageApi,
|
||||
} from '#/api/shop/promotion-fee';
|
||||
|
||||
import PromotionFeeFormModal from './components/PromotionFeeFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'PromotionFeeManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const formModalVisible = ref(false);
|
||||
const currentPromotionFeeData = ref<null | PromotionFeeVO.Info>(null);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
shopId: undefined as number | undefined,
|
||||
feeTypeId: undefined as number | undefined,
|
||||
platform: '',
|
||||
feeDateStart: undefined as string | undefined,
|
||||
feeDateEnd: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
{ label: '抖音', value: '抖音' },
|
||||
{ label: '快手', value: '快手' },
|
||||
{ label: '其他', value: '其他' },
|
||||
];
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
field: 'feeName',
|
||||
title: '推广费名称',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'shopName',
|
||||
title: '店铺名称',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'feeTypeName',
|
||||
title: '推广费类型',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '平台',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'platform' },
|
||||
},
|
||||
{
|
||||
field: 'campaignName',
|
||||
title: '推广活动',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '推广费金额',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'feeAmount' },
|
||||
},
|
||||
{
|
||||
field: 'feeDate',
|
||||
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: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<PromotionFeeDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
shopId: searchForm.value.shopId || undefined,
|
||||
feeTypeId: searchForm.value.feeTypeId || undefined,
|
||||
platform: searchForm.value.platform || undefined,
|
||||
feeDateStart: searchForm.value.feeDateStart || undefined,
|
||||
feeDateEnd: searchForm.value.feeDateEnd || undefined,
|
||||
},
|
||||
};
|
||||
const data = await getPromotionFeePageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取推广费记录列表失败:', error);
|
||||
message.error('获取推广费记录列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择店铺',
|
||||
// TODO: 这里需要从店铺API获取店铺列表
|
||||
options: [],
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'shopId',
|
||||
label: '店铺',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择推广费类型',
|
||||
// TODO: 这里需要从推广费类型API获取类型列表
|
||||
options: [],
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'feeTypeId',
|
||||
label: '推广费类型',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择平台',
|
||||
options: platformOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'platform',
|
||||
label: '平台',
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '开始日期',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'feeDateStart',
|
||||
label: '发生日期',
|
||||
},
|
||||
{
|
||||
component: 'DatePicker',
|
||||
componentProps: {
|
||||
placeholder: '结束日期',
|
||||
style: { width: '100%' },
|
||||
},
|
||||
fieldName: 'feeDateEnd',
|
||||
label: '至',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '推广费管理',
|
||||
});
|
||||
|
||||
// 处理新增
|
||||
const handleAdd = () => {
|
||||
currentPromotionFeeData.value = null;
|
||||
formModalVisible.value = true;
|
||||
};
|
||||
|
||||
// 处理编辑
|
||||
const handleEdit = (record: PromotionFeeVO.Info) => {
|
||||
currentPromotionFeeData.value = record;
|
||||
formModalVisible.value = true;
|
||||
};
|
||||
|
||||
// 处理删除
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await deletePromotionFeeApi(id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 处理表单成功
|
||||
const handleFormSuccess = () => {
|
||||
refreshTable();
|
||||
};
|
||||
|
||||
// 格式化金额
|
||||
const formatAmount = (amount: number) => {
|
||||
return `¥${amount.toFixed(2)}`;
|
||||
};
|
||||
|
||||
// 获取平台标签颜色
|
||||
const getPlatformColor = (platform: string | undefined) => {
|
||||
switch (platform) {
|
||||
case '京东': {
|
||||
return 'red';
|
||||
}
|
||||
case '天猫': {
|
||||
return 'purple';
|
||||
}
|
||||
case '快手': {
|
||||
return 'cyan';
|
||||
}
|
||||
case '抖音': {
|
||||
return 'blue';
|
||||
}
|
||||
case '拼多多': {
|
||||
return 'green';
|
||||
}
|
||||
case '淘宝': {
|
||||
return 'orange';
|
||||
}
|
||||
default: {
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="推广费管理" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理店铺推广费用记录,支持按店铺、类型、平台等维度查询和统计
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="mr-2 h-4 w-4" />
|
||||
新增推广费记录
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<span class="text-gray-500">
|
||||
支持按店铺、类型、平台等维度查询推广费记录
|
||||
</span>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 平台列 -->
|
||||
<template #platform="{ row }: { row: any }">
|
||||
<Tag v-if="row.platform" :color="getPlatformColor(row.platform)">
|
||||
{{ row.platform }}
|
||||
</Tag>
|
||||
<span v-else class="text-gray-400">-</span>
|
||||
</template>
|
||||
|
||||
<!-- 推广费金额列 -->
|
||||
<template #feeAmount="{ row }: { row: any }">
|
||||
<span class="font-medium text-red-600">
|
||||
{{ formatAmount(row.feeAmount) }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Button size="small" danger @click="handleDelete(row.id)">
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 表单弹窗 -->
|
||||
<PromotionFeeFormModal
|
||||
v-model:open="formModalVisible"
|
||||
:promotion-fee-data="currentPromotionFeeData"
|
||||
@success="handleFormSuccess"
|
||||
@cancel="formModalVisible = false"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
+381
@@ -0,0 +1,381 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ShopDTO, ShopVO } from '#/api/shop/shop/types';
|
||||
|
||||
import { computed, onUnmounted, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Form, Input, message, Select } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
createShopApi,
|
||||
updateShopApi,
|
||||
uploadShopLogoApi,
|
||||
} from '#/api/shop/shop';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[600px]',
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
onConfirm() {
|
||||
handleSubmit();
|
||||
},
|
||||
});
|
||||
|
||||
// 创建相机图标组件
|
||||
const CameraIcon = createIconifyIcon('mdi:camera');
|
||||
|
||||
// 内部状态管理
|
||||
const isEdit = ref(false);
|
||||
const currentShopData = ref<null | Partial<ShopVO.Info> | ShopVO.Info>(null);
|
||||
|
||||
// 响应式数据
|
||||
const formRef = ref();
|
||||
const loading = ref(false);
|
||||
const newLogoFile = ref<File | null>(null); // 新选择的logo文件
|
||||
const originalLogoUrl = ref(''); // 原始logo URL
|
||||
const imageLoadError = ref(false); // 图片加载错误状态
|
||||
|
||||
// 表单数据
|
||||
const formData = ref({
|
||||
name: '',
|
||||
platform: '',
|
||||
logoImageId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
];
|
||||
|
||||
// 模态框标题
|
||||
const modalTitle = computed(() => (isEdit.value ? '编辑店铺' : '添加店铺'));
|
||||
|
||||
// 当前显示的logo URL(优先显示新选择的)
|
||||
const currentLogoUrl = computed(() => {
|
||||
if (newLogoFile.value) {
|
||||
return URL.createObjectURL(newLogoFile.value);
|
||||
}
|
||||
return originalLogoUrl.value;
|
||||
});
|
||||
|
||||
// 初始化表单数据
|
||||
function initFormData() {
|
||||
if (isEdit.value && currentShopData.value) {
|
||||
// 编辑模式
|
||||
formData.value = {
|
||||
name: currentShopData.value.name || '',
|
||||
platform: currentShopData.value.platform || '',
|
||||
logoImageId: undefined,
|
||||
};
|
||||
|
||||
// 设置原始Logo URL
|
||||
originalLogoUrl.value = currentShopData.value.logo || '';
|
||||
} else {
|
||||
// 创建模式 - 如果有传入的shopData,则使用它来初始化表单
|
||||
formData.value = {
|
||||
name: currentShopData.value?.name || '',
|
||||
platform: currentShopData.value?.platform || '',
|
||||
logoImageId: undefined,
|
||||
};
|
||||
originalLogoUrl.value = currentShopData.value?.logo || '';
|
||||
}
|
||||
|
||||
// 重置新选择的logo和图片加载状态
|
||||
newLogoFile.value = null;
|
||||
imageLoadError.value = false;
|
||||
}
|
||||
|
||||
// 重置表单(在open方法中调用)
|
||||
function resetForm() {
|
||||
formRef.value?.resetFields();
|
||||
newLogoFile.value = null;
|
||||
originalLogoUrl.value = '';
|
||||
imageLoadError.value = false;
|
||||
}
|
||||
|
||||
// 处理提交
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
// 准备提交数据
|
||||
const submitData = { ...formData.value };
|
||||
|
||||
// 如果有新选择的logo,先上传获取ID
|
||||
if (newLogoFile.value) {
|
||||
const logoImageId = await uploadLogoAndGetId();
|
||||
if (logoImageId) {
|
||||
submitData.logoImageId = logoImageId;
|
||||
}
|
||||
} else if (!isEdit.value) {
|
||||
// 创建模式且没有选择Logo,移除logoImageId字段
|
||||
delete submitData.logoImageId;
|
||||
}
|
||||
|
||||
// 调用API
|
||||
if (
|
||||
isEdit.value &&
|
||||
currentShopData.value &&
|
||||
'id' in currentShopData.value &&
|
||||
currentShopData.value.id
|
||||
) {
|
||||
await updateShopApi(
|
||||
currentShopData.value.id,
|
||||
submitData as ShopDTO.Update,
|
||||
);
|
||||
message.success('更新成功');
|
||||
} else {
|
||||
await createShopApi(submitData as ShopDTO.Create);
|
||||
message.success('创建成功');
|
||||
}
|
||||
|
||||
emit('success');
|
||||
modalApi.close();
|
||||
} catch (error) {
|
||||
console.error('保存店铺失败:', error);
|
||||
message.error('保存店铺失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理取消
|
||||
function handleCancel() {
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(
|
||||
editMode: boolean = false,
|
||||
shopData?: null | Partial<ShopVO.Info> | ShopVO.Info,
|
||||
) {
|
||||
isEdit.value = editMode;
|
||||
currentShopData.value = shopData || null;
|
||||
|
||||
resetForm(); // 先重置表单
|
||||
initFormData(); // 再初始化数据
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
|
||||
// 选择logo文件
|
||||
function selectLogoFile() {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'file';
|
||||
input.accept = 'image/*';
|
||||
input.style.display = 'none';
|
||||
document.body.append(input);
|
||||
|
||||
input.addEventListener('change', (e) => {
|
||||
const file = (e.target as HTMLInputElement).files?.[0];
|
||||
if (file) {
|
||||
// 验证文件
|
||||
const isImage = file.type.startsWith('image/');
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件');
|
||||
input.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
const isLt2M = file.size / 1024 / 1024 < 2;
|
||||
if (!isLt2M) {
|
||||
message.error('图片大小不能超过 2MB');
|
||||
input.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置新选择的文件
|
||||
newLogoFile.value = file;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('Logo选择成功');
|
||||
}
|
||||
|
||||
input.remove();
|
||||
});
|
||||
|
||||
input.click();
|
||||
}
|
||||
|
||||
// 重置新选择的logo
|
||||
function removeNewLogo() {
|
||||
newLogoFile.value = null;
|
||||
imageLoadError.value = false; // 重置图片加载错误状态
|
||||
message.success('已重置logo');
|
||||
}
|
||||
|
||||
// 上传Logo并获取图片ID
|
||||
async function uploadLogoAndGetId(): Promise<number | undefined> {
|
||||
if (!newLogoFile.value) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await uploadShopLogoApi(newLogoFile.value);
|
||||
return response.id;
|
||||
} catch (error) {
|
||||
console.error('Logo上传失败:', error);
|
||||
message.error('Logo上传失败');
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 图片加载错误处理
|
||||
function handleImageError(event: Event) {
|
||||
console.error('图片加载失败:', event);
|
||||
imageLoadError.value = true;
|
||||
message.error('图片加载失败,请重新选择');
|
||||
}
|
||||
|
||||
// 组件卸载时清理
|
||||
onUnmounted(() => {
|
||||
if (newLogoFile.value) {
|
||||
const url = URL.createObjectURL(newLogoFile.value);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal :title="modalTitle" :confirm-loading="loading">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="店铺Logo" name="logoImageId">
|
||||
<div style="display: flex; align-items: center; gap: 16px">
|
||||
<!-- Logo预览区域 -->
|
||||
<div style="position: relative; display: inline-block">
|
||||
<!-- 有图片时显示图片 -->
|
||||
<img
|
||||
v-if="currentLogoUrl && !imageLoadError"
|
||||
:src="currentLogoUrl"
|
||||
alt="店铺Logo"
|
||||
style="
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
object-fit: cover;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #d9d9d9;
|
||||
background-color: #f5f5f5;
|
||||
"
|
||||
@error="handleImageError"
|
||||
/>
|
||||
<!-- 无图片或加载失败时显示空状态 -->
|
||||
<div
|
||||
v-else
|
||||
style="
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
border: 1px dashed #d9d9d9;
|
||||
border-radius: 8px;
|
||||
background-color: #fafafa;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
text-align: center;
|
||||
line-height: 1.2;
|
||||
"
|
||||
>
|
||||
<div
|
||||
style="
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
"
|
||||
>
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px" />
|
||||
<div>上传Logo</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 点击更换遮罩 -->
|
||||
<div
|
||||
style="
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
cursor: pointer;
|
||||
"
|
||||
@mouseenter="($event.target as HTMLElement).style.opacity = '1'"
|
||||
@mouseleave="($event.target as HTMLElement).style.opacity = '0'"
|
||||
@click="selectLogoFile"
|
||||
>
|
||||
<div
|
||||
style="
|
||||
color: white;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
"
|
||||
>
|
||||
<CameraIcon style="font-size: 16px; margin-bottom: 4px" />
|
||||
<div style="font-size: 12px">
|
||||
{{
|
||||
currentLogoUrl && !imageLoadError ? '更换Logo' : '上传Logo'
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 重置按钮 -->
|
||||
<div v-if="newLogoFile">
|
||||
<Button size="small" @click="removeNewLogo">重置</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
label="店铺名称"
|
||||
name="name"
|
||||
:rules="[{ required: true, message: '请输入店铺名称' }]"
|
||||
>
|
||||
<Input v-model:value="formData.name" placeholder="请输入店铺名称" />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="平台" name="platform">
|
||||
<Select
|
||||
v-model:value="formData.platform"
|
||||
placeholder="请选择平台"
|
||||
:options="platformOptions"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
@@ -0,0 +1,282 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { ShopDTO, ShopVO } from '#/api/shop/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Space } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteShopApi, getShopPageApi } from '#/api/shop/shop';
|
||||
|
||||
import ShopFormModal from './components/ShopFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'ShopManagement' });
|
||||
|
||||
// 创建图标组件
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const shopFormModalRef = ref();
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
name: '',
|
||||
platform: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 表单数据(已移至ShopFormModal组件)
|
||||
|
||||
// 平台选项
|
||||
const platformOptions = [
|
||||
{ label: '淘宝', value: '淘宝' },
|
||||
{ label: '京东', value: '京东' },
|
||||
{ label: '拼多多', value: '拼多多' },
|
||||
{ label: '天猫', value: '天猫' },
|
||||
];
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
width: 80,
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
title: 'Logo',
|
||||
width: 100,
|
||||
align: 'center' as const,
|
||||
slots: { default: 'logo' },
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
title: '店铺名称',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'platform',
|
||||
title: '平台',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
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: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ShopDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
name: searchForm.value.name || undefined,
|
||||
platform: searchForm.value.platform,
|
||||
},
|
||||
};
|
||||
const data = await getShopPageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
message.error('获取店铺列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入店铺名称',
|
||||
},
|
||||
fieldName: 'name',
|
||||
label: '店铺名称',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择平台',
|
||||
options: platformOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'platform',
|
||||
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() {
|
||||
shopFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑店铺
|
||||
function handleEdit(record: ShopVO.Info) {
|
||||
shopFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除店铺
|
||||
async function handleDelete(record: ShopVO.Info) {
|
||||
try {
|
||||
await deleteShopApi(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">
|
||||
管理电商店铺信息,包括店铺基本信息、平台信息和Logo设置
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加店铺
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- Logo列 -->
|
||||
<template #logo="{ row }: { row: any }">
|
||||
<div
|
||||
v-if="row.logo"
|
||||
style="display: flex; justify-content: center; align-items: center"
|
||||
>
|
||||
<img
|
||||
:src="row.logo"
|
||||
:alt="row.name"
|
||||
style="
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
object-fit: cover;
|
||||
border-radius: 4px;
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
style="display: flex; justify-content: center; align-items: center"
|
||||
>
|
||||
<span style="color: #999">暂无Logo</span>
|
||||
</div>
|
||||
</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>
|
||||
|
||||
<!-- 店铺表单模态框 -->
|
||||
<ShopFormModal ref="shopFormModalRef" @success="handleModalSuccess" />
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user