mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 16:29:20 +08:00
refactor: 重构电商模块目录结构
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user