mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 23:49:19 +08:00
已更新以下页面: - 订单管理页 - 店铺概览页订单列表 - 推广费管理页 - 商品管理页 - 店铺管理页 - 月销量目标管理页 - 刷单记录管理页 - 订单状态配置页 - 推广费类型配置页 - 账号管理页 - 超级账号管理页 - 公司管理页 - 部门管理页 - 文件管理页 - 图片管理页 - 商品列表页(2个)
457 lines
12 KiB
Vue
457 lines
12 KiB
Vue
<script lang="ts" setup>
|
|
import type { VxeGridProps } from '#/adapter/vxe-table';
|
|
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
|
|
import type { ShopDTO, ShopVO } from '#/api/ecommerce/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, Popconfirm, Space, Tag } from 'ant-design-vue';
|
|
|
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
import {
|
|
deleteOrderApi,
|
|
getOrderPageApi,
|
|
} from '#/api/ecommerce/order';
|
|
import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status';
|
|
import type { OrderStatusVO } from '#/api/ecommerce/order-status/types';
|
|
import { getShopPageApi } from '#/api/ecommerce/shop';
|
|
|
|
import OrderFormModal from './components/OrderFormModal.vue';
|
|
|
|
defineOptions({ name: 'OrderManagement' });
|
|
// 创建图标组件
|
|
const PlusIcon = createIconifyIcon('lucide:plus');
|
|
|
|
// 响应式数据
|
|
const loading = ref(false);
|
|
const orderFormModalRef = ref();
|
|
|
|
// 店铺分页数据
|
|
const shopOptions = ref<{ label: string; value: number }[]>([]);
|
|
const shopPage = ref(1);
|
|
const shopPageSize = 20;
|
|
const shopTotal = ref(0);
|
|
const shopLoading = ref(false);
|
|
const shopSearchKeyword = ref('');
|
|
let shopSearchTimer: ReturnType<typeof setTimeout> | null = null;
|
|
|
|
// 订单状态选项
|
|
const orderStatusOptions = ref<{ label: string; value: number }[]>([]);
|
|
|
|
// 排序选项
|
|
const sortFieldOptions = [
|
|
{ label: '下单时间', value: 'orderTime' },
|
|
{ label: '创建时间', value: 'createTime' },
|
|
{ label: '实收金额', value: 'receivedAmount' },
|
|
{ label: '数量', value: 'quantity' },
|
|
];
|
|
const sortOrderOptions = [
|
|
{ label: '降序(从高到低)', value: 'desc' },
|
|
{ label: '升序(从低到高)', value: 'asc' },
|
|
];
|
|
|
|
// 搜索表单
|
|
const searchForm = ref({
|
|
platformOrderNo: '',
|
|
shopId: undefined as number | undefined,
|
|
statusId: undefined as number | undefined,
|
|
sortField: 'orderTime' as string | undefined,
|
|
sortOrder: 'desc' as string | undefined,
|
|
});
|
|
|
|
// 加载店铺列表(支持分页)
|
|
async function fetchShops(page = 1, append = false) {
|
|
if (shopLoading.value) return;
|
|
shopLoading.value = true;
|
|
try {
|
|
const params: PageQueryDTO<ShopDTO.Filters> = {
|
|
page,
|
|
pageSize: shopPageSize,
|
|
filters: shopSearchKeyword.value ? { name: shopSearchKeyword.value } : {},
|
|
};
|
|
const data = await getShopPageApi(params);
|
|
if (append) {
|
|
shopOptions.value = [...shopOptions.value, ...data.records.map((shop: ShopVO.Info) => ({
|
|
label: shop.name,
|
|
value: shop.id,
|
|
}))];
|
|
} else {
|
|
shopOptions.value = data.records.map((shop: ShopVO.Info) => ({
|
|
label: shop.name,
|
|
value: shop.id,
|
|
}));
|
|
}
|
|
shopTotal.value = data.total;
|
|
shopPage.value = page;
|
|
} catch (error) {
|
|
console.error('获取店铺列表失败:', error);
|
|
} finally {
|
|
shopLoading.value = false;
|
|
}
|
|
}
|
|
|
|
// 搜索店铺(防抖)
|
|
function handleShopSearch(value: string) {
|
|
if (shopSearchTimer) clearTimeout(shopSearchTimer);
|
|
shopSearchTimer = setTimeout(() => {
|
|
shopSearchKeyword.value = value;
|
|
shopPage.value = 1;
|
|
fetchShops(1, false);
|
|
}, 300);
|
|
}
|
|
|
|
// 滚动加载更多店铺
|
|
function handleShopPopupScroll(e: Event) {
|
|
const target = e.target as HTMLElement;
|
|
const { scrollTop, scrollHeight, clientHeight } = target;
|
|
// 滚动到底部附近时加载更多
|
|
if (scrollHeight - scrollTop - clientHeight < 50) {
|
|
const hasMore = shopPage.value * shopPageSize < shopTotal.value;
|
|
if (hasMore && !shopLoading.value) {
|
|
fetchShops(shopPage.value + 1, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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: 'orderTime',
|
|
title: '下单时间',
|
|
minWidth: 'auto',
|
|
sortable: true,
|
|
},
|
|
{
|
|
field: 'createTime',
|
|
title: '创建时间',
|
|
minWidth: 'auto',
|
|
sortable: true,
|
|
},
|
|
{
|
|
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, form }) => {
|
|
try {
|
|
loading.value = true;
|
|
// 从表单获取搜索参数
|
|
const searchParams = form || {};
|
|
const params: PageQueryDTO<OrderDTO.Filters> = {
|
|
page: page.currentPage,
|
|
pageSize: page.pageSize,
|
|
filters: {
|
|
platformOrderNo: searchParams.platformOrderNo || undefined,
|
|
shopId: searchParams.shopId,
|
|
statusId: searchParams.statusId,
|
|
},
|
|
};
|
|
// 添加排序参数
|
|
if (searchParams.sortField && searchParams.sortOrder) {
|
|
params.sorts = [
|
|
{
|
|
field: searchParams.sortField,
|
|
order: searchParams.sortOrder as 'asc' | 'desc',
|
|
},
|
|
];
|
|
}
|
|
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: '请输入平台订单号(回车搜索)',
|
|
onPressEnter: () => gridApi?.reload(),
|
|
},
|
|
fieldName: 'platformOrderNo',
|
|
label: '平台订单号',
|
|
},
|
|
{
|
|
component: 'Select',
|
|
componentProps: {
|
|
placeholder: '请选择店铺(支持搜索)',
|
|
options: shopOptions,
|
|
allowClear: true,
|
|
showSearch: true,
|
|
filterOption: false,
|
|
onSearch: handleShopSearch,
|
|
onPopupScroll: handleShopPopupScroll,
|
|
onChange: () => gridApi?.reload(),
|
|
loading: shopLoading,
|
|
dropdownMenuColumnStyle: { maxHeight: '300px', overflow: 'auto' },
|
|
},
|
|
fieldName: 'shopId',
|
|
label: '店铺',
|
|
},
|
|
{
|
|
component: 'Select',
|
|
componentProps: {
|
|
placeholder: '请选择状态',
|
|
options: orderStatusOptions,
|
|
allowClear: true,
|
|
onChange: () => gridApi?.reload(),
|
|
},
|
|
fieldName: 'statusId',
|
|
label: '订单状态',
|
|
},
|
|
{
|
|
component: 'Select',
|
|
componentProps: {
|
|
placeholder: '选择排序字段',
|
|
options: sortFieldOptions,
|
|
allowClear: true,
|
|
onChange: () => gridApi?.reload(),
|
|
},
|
|
fieldName: 'sortField',
|
|
label: '排序字段',
|
|
},
|
|
{
|
|
component: 'Select',
|
|
componentProps: {
|
|
placeholder: '选择排序方式',
|
|
options: sortOrderOptions,
|
|
allowClear: true,
|
|
onChange: () => gridApi?.reload(),
|
|
},
|
|
fieldName: 'sortOrder',
|
|
label: '排序方式',
|
|
},
|
|
],
|
|
showDefaultActions: true,
|
|
collapsed: true,
|
|
collapsedRows: 2,
|
|
}));
|
|
|
|
// 刷新表格数据
|
|
function refreshTable() {
|
|
if (gridApi) {
|
|
gridApi.reload();
|
|
}
|
|
}
|
|
|
|
// 获取店铺选项(首次加载)
|
|
async function fetchShopOptions() {
|
|
await fetchShops(1, false);
|
|
}
|
|
|
|
// 获取订单状态选项
|
|
async function fetchOrderStatusOptions() {
|
|
try {
|
|
const data = await getAllOrderStatusListApi();
|
|
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 handleModalSuccess() {
|
|
refreshTable();
|
|
}
|
|
|
|
// 初始化
|
|
onMounted(async () => {
|
|
await fetchShopOptions();
|
|
await fetchOrderStatusOptions();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<Page auto-content-height>
|
|
<!-- VbenVxeGrid 表格 -->
|
|
<Grid :loading="loading">
|
|
<!-- 工具栏工具 -->
|
|
<template #toolbar-tools>
|
|
<Space>
|
|
<Button type="primary" @click="handleAdd">
|
|
<PlusIcon />
|
|
添加订单
|
|
</Button>
|
|
</Space>
|
|
</template>
|
|
|
|
<!-- 商品信息列 -->
|
|
<template #productInfo="{ row }: { row: any }">
|
|
<div v-if="row.linkProductName">
|
|
<div style="font-weight: bold">{{ row.linkProductName }}</div>
|
|
<div v-if="row.linkSpecName" style="color: #666; font-size: 12px">
|
|
{{ row.linkSpecName }}
|
|
</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="row.orderStatus?.color || 'blue'">
|
|
{{ row.statusName || '未知状态' }}
|
|
</Tag>
|
|
</template>
|
|
|
|
<!-- 操作列 -->
|
|
<template #action="{ row }: { row: any }">
|
|
<Space>
|
|
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
|
<Popconfirm
|
|
title="确定要删除这个订单吗?"
|
|
@confirm="handleDelete(row)"
|
|
>
|
|
<Button size="small" danger> 删除 </Button>
|
|
</Popconfirm>
|
|
</Space>
|
|
</template>
|
|
</Grid>
|
|
|
|
<!-- 订单表单模态框 -->
|
|
<OrderFormModal ref="orderFormModalRef" @success="handleModalSuccess" />
|
|
</Page>
|
|
</template>
|