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,839 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
|
||||
import { ORDER_STATUS_OPTIONS } from '#/api/ecommerce/order/types/types.enum';
|
||||
import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types';
|
||||
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Image,
|
||||
message,
|
||||
Popconfirm,
|
||||
Space,
|
||||
Tag,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
batchDeleteOrdersApi,
|
||||
deleteOrderApi,
|
||||
getOrderPageApi,
|
||||
} from '#/api/ecommerce/order';
|
||||
import { getProductPageApi } from '#/api/ecommerce/product';
|
||||
import { getPlatformListApi } from '#/api/ecommerce/platform';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
import PlatformTag from '#/components/platform/PlatformTag.vue';
|
||||
import {
|
||||
getFirstOrderItem,
|
||||
getOrderPayAmount,
|
||||
getOrderProduct,
|
||||
getOrderReceivedAmount,
|
||||
} from '#/utils/order-display';
|
||||
|
||||
import OrderDetailDrawer from './components/OrderDetailDrawer.vue';
|
||||
import OrderFormModal from './components/OrderFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'OrderManagement' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const router = useRouter();
|
||||
|
||||
const SOURCE_LABEL: Record<string, string> = {
|
||||
import: '导入',
|
||||
sync: '同步',
|
||||
manual: '手动',
|
||||
};
|
||||
|
||||
const loading = ref(false);
|
||||
const batchDeleteLoading = ref(false);
|
||||
/** vxe 勾选不触发 Vue 依赖,须用事件同步,勿用 computed 读 getCheckboxRecords */
|
||||
const hasSelected = ref(false);
|
||||
const orderFormModalRef = ref<InstanceType<typeof OrderFormModal>>();
|
||||
const detailDrawerRef = ref<InstanceType<typeof OrderDetailDrawer>>();
|
||||
|
||||
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('');
|
||||
const shopLoaded = ref(false);
|
||||
let shopSearchTimer: null | ReturnType<typeof setTimeout> = null;
|
||||
|
||||
const orderStatusOptions = ORDER_STATUS_OPTIONS;
|
||||
|
||||
const productOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const productPage = ref(1);
|
||||
const productPageSize = 20;
|
||||
const productTotal = ref(0);
|
||||
const productLoading = ref(false);
|
||||
const productSearchKeyword = ref('');
|
||||
const productLoaded = ref(false);
|
||||
let productSearchTimer: null | ReturnType<typeof setTimeout> = null;
|
||||
|
||||
/** 与后端 OrderPageQuerySupport 对齐 */
|
||||
const DEFAULT_LIST_DAYS = 30;
|
||||
const MAX_LIST_DAYS = 366;
|
||||
|
||||
function buildDefaultOrderTimeRange() {
|
||||
const end = dayjs().endOf('day');
|
||||
const start = dayjs()
|
||||
.subtract(DEFAULT_LIST_DAYS - 1, 'day')
|
||||
.startOf('day');
|
||||
return {
|
||||
start: start.format('YYYY-MM-DD HH:mm:ss'),
|
||||
end: end.format('YYYY-MM-DD HH:mm:ss'),
|
||||
range: [start, end] as [dayjs.Dayjs, dayjs.Dayjs],
|
||||
};
|
||||
}
|
||||
|
||||
const defaultOrderTime = buildDefaultOrderTimeRange();
|
||||
|
||||
const searchForm = ref({
|
||||
platformOrderNo: '',
|
||||
shopId: undefined as number | undefined,
|
||||
platformCode: undefined as string | undefined,
|
||||
status: undefined as string | undefined,
|
||||
startOrderTime: defaultOrderTime.start as string | undefined,
|
||||
endOrderTime: defaultOrderTime.end as string | undefined,
|
||||
productId: undefined as number | undefined,
|
||||
});
|
||||
|
||||
const platformOptions = ref<{ label: string; value: string }[]>([]);
|
||||
const platformLoaded = ref(false);
|
||||
|
||||
const currentSort = ref<null | { field: string; order: 'asc' | 'desc' }>(null);
|
||||
|
||||
function money(v?: null | number) {
|
||||
if (v == null || Number.isNaN(Number(v))) return '-';
|
||||
return `¥${Number(v).toFixed(2)}`;
|
||||
}
|
||||
|
||||
function sourceText(source?: string) {
|
||||
if (!source) return '-';
|
||||
return SOURCE_LABEL[source] ?? source;
|
||||
}
|
||||
|
||||
function regionText(row: OrderVO.Info) {
|
||||
return [row.province, row.city, row.town].filter(Boolean).join(' / ') || '-';
|
||||
}
|
||||
|
||||
function goodsTitle(row: OrderVO.Info) {
|
||||
return (
|
||||
getOrderProduct(row)?.name ||
|
||||
getFirstOrderItem(row)?.linkProductName ||
|
||||
row.firstLinkProductName ||
|
||||
'-'
|
||||
);
|
||||
}
|
||||
|
||||
function goodsSpec(row: OrderVO.Info) {
|
||||
const item = getFirstOrderItem(row);
|
||||
return item?.productSku?.name || item?.linkSkuName || '';
|
||||
}
|
||||
|
||||
function goodsImg(row: OrderVO.Info) {
|
||||
return getFirstOrderItem(row)?.goodsImg;
|
||||
}
|
||||
|
||||
function ensureOrderTimeFilters(): boolean {
|
||||
if (!searchForm.value.startOrderTime || !searchForm.value.endOrderTime) {
|
||||
const d = buildDefaultOrderTimeRange();
|
||||
searchForm.value.startOrderTime = d.start;
|
||||
searchForm.value.endOrderTime = d.end;
|
||||
}
|
||||
const start = dayjs(searchForm.value.startOrderTime);
|
||||
const end = dayjs(searchForm.value.endOrderTime);
|
||||
if (!start.isValid() || !end.isValid()) {
|
||||
message.warning('请选择有效的下单时间范围');
|
||||
return false;
|
||||
}
|
||||
if (end.isBefore(start)) {
|
||||
message.warning('下单结束时间不能早于开始时间');
|
||||
return false;
|
||||
}
|
||||
if (end.diff(start, 'day') + 1 > MAX_LIST_DAYS) {
|
||||
message.warning(`下单时间跨度不能超过 ${MAX_LIST_DAYS} 天,请缩小范围`);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
const mapped = data.records.map((shop: ShopVO.Info) => ({
|
||||
label: shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
shopOptions.value = append ? [...shopOptions.value, ...mapped] : mapped;
|
||||
shopTotal.value = data.total;
|
||||
shopPage.value = page;
|
||||
shopLoaded.value = true;
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchProducts(page = 1, append = false) {
|
||||
if (productLoading.value) return;
|
||||
productLoading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<ProductDTO.Filters> = {
|
||||
page,
|
||||
pageSize: productPageSize,
|
||||
filters: productSearchKeyword.value
|
||||
? { name: productSearchKeyword.value }
|
||||
: {},
|
||||
};
|
||||
const data = await getProductPageApi(params);
|
||||
const mapped = data.records.map((product: ProductVO.Info) => ({
|
||||
label: product.name,
|
||||
value: product.id,
|
||||
}));
|
||||
productOptions.value = append
|
||||
? [...productOptions.value, ...mapped]
|
||||
: mapped;
|
||||
productTotal.value = data.total;
|
||||
productPage.value = page;
|
||||
productLoaded.value = true;
|
||||
} catch (error) {
|
||||
console.error('获取商品列表失败:', error);
|
||||
} finally {
|
||||
productLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleProductSearch(value: string) {
|
||||
if (productSearchTimer) clearTimeout(productSearchTimer);
|
||||
productSearchTimer = setTimeout(() => {
|
||||
productSearchKeyword.value = value;
|
||||
productPage.value = 1;
|
||||
fetchProducts(1, false);
|
||||
}, 300);
|
||||
}
|
||||
|
||||
function handleProductPopupScroll(e: Event) {
|
||||
const target = e.target as HTMLElement;
|
||||
const { scrollTop, scrollHeight, clientHeight } = target;
|
||||
if (scrollHeight - scrollTop - clientHeight < 50) {
|
||||
const hasMore = productPage.value * productPageSize < productTotal.value;
|
||||
if (hasMore && !productLoading.value) {
|
||||
fetchProducts(productPage.value + 1, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchPlatformOptions() {
|
||||
try {
|
||||
const data = await getPlatformListApi();
|
||||
platformOptions.value = (data ?? []).map((p) => ({
|
||||
label: p.label,
|
||||
value: p.code,
|
||||
}));
|
||||
platformLoaded.value = true;
|
||||
} catch (error) {
|
||||
console.error('获取平台字典失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
const gridOptions: VxeGridProps<OrderVO.Info> = {
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
reserve: false,
|
||||
},
|
||||
columns: [
|
||||
{ type: 'seq' as const, width: 56, title: '序号' },
|
||||
{
|
||||
type: 'checkbox' as const,
|
||||
width: 48,
|
||||
fixed: 'left' as const,
|
||||
},
|
||||
{
|
||||
field: 'platformOrderNo',
|
||||
title: '平台订单号',
|
||||
minWidth: 180,
|
||||
showOverflow: 'tooltip' as const,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
title: '平台',
|
||||
width: 100,
|
||||
slots: { default: 'platform' },
|
||||
},
|
||||
{
|
||||
field: 'shopName',
|
||||
title: '店铺',
|
||||
minWidth: 120,
|
||||
showOverflow: 'tooltip' as const,
|
||||
sortable: true,
|
||||
slots: { default: 'shopName' },
|
||||
},
|
||||
{
|
||||
title: '商品',
|
||||
minWidth: 240,
|
||||
showOverflow: false,
|
||||
slots: { default: 'goods' },
|
||||
},
|
||||
{
|
||||
field: 'payAmount',
|
||||
title: '实付',
|
||||
width: 100,
|
||||
sortable: true,
|
||||
slots: { default: 'payAmount' },
|
||||
},
|
||||
{
|
||||
field: 'receivedAmount',
|
||||
title: '商家实收',
|
||||
width: 110,
|
||||
sortable: true,
|
||||
slots: { default: 'receivedAmount' },
|
||||
},
|
||||
{
|
||||
title: '订单状态',
|
||||
width: 110,
|
||||
slots: { default: 'orderStatus' },
|
||||
},
|
||||
{
|
||||
title: '来源',
|
||||
width: 80,
|
||||
slots: { default: 'source' },
|
||||
},
|
||||
{
|
||||
field: 'orderTime',
|
||||
title: '下单时间',
|
||||
minWidth: 160,
|
||||
sortable: true,
|
||||
},
|
||||
{
|
||||
title: '收件地区',
|
||||
minWidth: 140,
|
||||
showOverflow: 'tooltip' as const,
|
||||
slots: { default: 'region' },
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 180,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
rowConfig: { isHover: true, height: 72 },
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
sortConfig: {
|
||||
remote: true,
|
||||
trigger: 'cell',
|
||||
multiple: false,
|
||||
orders: ['desc', 'asc'],
|
||||
},
|
||||
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 {
|
||||
if (!ensureOrderTimeFilters()) {
|
||||
return { items: [], total: 0 };
|
||||
}
|
||||
loading.value = true;
|
||||
const searchParams = form || {};
|
||||
const filters = {
|
||||
platformOrderNo:
|
||||
searchParams.platformOrderNo ||
|
||||
searchForm.value.platformOrderNo ||
|
||||
undefined,
|
||||
shopId: searchParams.shopId ?? searchForm.value.shopId,
|
||||
platformCode:
|
||||
searchParams.platformCode ?? searchForm.value.platformCode,
|
||||
status: searchParams.status ?? searchForm.value.status,
|
||||
startOrderTime: searchForm.value.startOrderTime,
|
||||
endOrderTime: searchForm.value.endOrderTime,
|
||||
productId: searchParams.productId ?? searchForm.value.productId,
|
||||
};
|
||||
const params: PageQueryDTO<OrderDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters,
|
||||
};
|
||||
if (currentSort.value) {
|
||||
params.sorts = [
|
||||
{
|
||||
field: currentSort.value.field,
|
||||
order: currentSort.value.order,
|
||||
},
|
||||
];
|
||||
}
|
||||
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 gridReloadRef = ref<(() => void) | null>(null);
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '平台订单号(前缀匹配,回车搜索)',
|
||||
onChange: (e: any) => {
|
||||
searchForm.value.platformOrderNo = e.target.value;
|
||||
},
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
},
|
||||
fieldName: 'platformOrderNo',
|
||||
label: '平台订单号',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '全部平台',
|
||||
options: platformOptions,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
optionFilterProp: 'label',
|
||||
onFocus: () => {
|
||||
if (!platformLoaded.value) {
|
||||
fetchPlatformOptions();
|
||||
}
|
||||
},
|
||||
onChange: (val: string | undefined) => {
|
||||
searchForm.value.platformCode = val;
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
},
|
||||
fieldName: 'platformCode',
|
||||
label: '平台',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择店铺(支持搜索)',
|
||||
options: shopOptions,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
filterOption: false,
|
||||
onSearch: handleShopSearch,
|
||||
onFocus: () => {
|
||||
if (!shopLoaded.value) {
|
||||
fetchShops(1, false);
|
||||
}
|
||||
},
|
||||
onPopupScroll: handleShopPopupScroll,
|
||||
onChange: (val: any) => {
|
||||
searchForm.value.shopId = val;
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
loading: shopLoading,
|
||||
dropdownMenuColumnStyle: { maxHeight: '300px', overflow: 'auto' },
|
||||
},
|
||||
fieldName: 'shopId',
|
||||
label: '店铺',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择商品(支持搜索)',
|
||||
options: productOptions,
|
||||
allowClear: true,
|
||||
showSearch: true,
|
||||
filterOption: false,
|
||||
onSearch: handleProductSearch,
|
||||
onFocus: () => {
|
||||
if (!productLoaded.value) {
|
||||
fetchProducts(1, false);
|
||||
}
|
||||
},
|
||||
onPopupScroll: handleProductPopupScroll,
|
||||
onChange: (val: any) => {
|
||||
searchForm.value.productId = val ?? undefined;
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
loading: productLoading,
|
||||
dropdownMenuColumnStyle: { maxHeight: '300px', overflow: 'auto' },
|
||||
},
|
||||
fieldName: 'productId',
|
||||
label: '商品',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
options: orderStatusOptions,
|
||||
allowClear: true,
|
||||
onChange: (val: any) => {
|
||||
searchForm.value.status = val;
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
},
|
||||
fieldName: 'status',
|
||||
label: '订单状态',
|
||||
},
|
||||
{
|
||||
component: 'RangePicker',
|
||||
defaultValue: defaultOrderTime.range,
|
||||
componentProps: {
|
||||
placeholder: ['下单开始时间', '下单结束时间'],
|
||||
allowClear: false,
|
||||
showTime: { format: 'HH:mm:ss' },
|
||||
format: 'YYYY-MM-DD HH:mm:ss',
|
||||
style: { width: '100%' },
|
||||
onChange: (val: any) => {
|
||||
if (!val || !val[0] || !val[1]) {
|
||||
const d = buildDefaultOrderTimeRange();
|
||||
searchForm.value.startOrderTime = d.start;
|
||||
searchForm.value.endOrderTime = d.end;
|
||||
} else {
|
||||
searchForm.value.startOrderTime = (val[0] as dayjs.Dayjs).format(
|
||||
'YYYY-MM-DD HH:mm:ss',
|
||||
);
|
||||
searchForm.value.endOrderTime = (val[1] as dayjs.Dayjs).format(
|
||||
'YYYY-MM-DD HH:mm:ss',
|
||||
);
|
||||
}
|
||||
gridReloadRef.value?.();
|
||||
},
|
||||
},
|
||||
fieldName: 'orderTimeRange',
|
||||
label: '下单时间',
|
||||
rules: 'required',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 2,
|
||||
defaultValues: {
|
||||
orderTimeRange: defaultOrderTime.range,
|
||||
},
|
||||
}));
|
||||
|
||||
function refreshTable() {
|
||||
hasSelected.value = false;
|
||||
gridApi.reload();
|
||||
}
|
||||
|
||||
function handleSortChange({
|
||||
field,
|
||||
order,
|
||||
}: {
|
||||
field?: string;
|
||||
order?: 'asc' | 'desc' | null;
|
||||
}) {
|
||||
currentSort.value = field ? { field, order: order || 'desc' } : null;
|
||||
gridReloadRef.value?.();
|
||||
}
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '订单管理',
|
||||
gridEvents: {
|
||||
checkboxChange() {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
const rows = vxeTable?.getCheckboxRecords?.() ?? [];
|
||||
hasSelected.value = rows.length > 0;
|
||||
},
|
||||
checkboxAll() {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
const rows = vxeTable?.getCheckboxRecords?.() ?? [];
|
||||
hasSelected.value = rows.length > 0;
|
||||
},
|
||||
},
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
function goToShopDetail(shopId: number) {
|
||||
router.push(`/ecom/shop/overview/${shopId}`);
|
||||
}
|
||||
|
||||
function openDetail(row: OrderVO.Info) {
|
||||
detailDrawerRef.value?.open(row.id);
|
||||
}
|
||||
|
||||
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('删除订单失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleBatchDelete() {
|
||||
const vxeTable = (gridApi as any).grid;
|
||||
const selectedRows: OrderVO.Info[] = vxeTable?.getCheckboxRecords?.() ?? [];
|
||||
if (!selectedRows.length) {
|
||||
message.warning('请选择要删除的订单');
|
||||
return;
|
||||
}
|
||||
const orderIds = selectedRows.map((r) => r.id).filter((id) => id != null);
|
||||
if (!orderIds.length) {
|
||||
message.warning('所选行缺少订单ID');
|
||||
return;
|
||||
}
|
||||
batchDeleteLoading.value = true;
|
||||
try {
|
||||
await batchDeleteOrdersApi({ orderIds });
|
||||
message.success(`已删除 ${orderIds.length} 条订单`);
|
||||
vxeTable?.clearCheckboxRow?.();
|
||||
hasSelected.value = false;
|
||||
await gridApi.reload();
|
||||
} catch (error: any) {
|
||||
console.error('批量删除订单失败:', error);
|
||||
const msg =
|
||||
error?.response?.data?.message || error?.message || '批量删除失败';
|
||||
message.error(msg);
|
||||
} finally {
|
||||
batchDeleteLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
ensureOrderTimeFilters();
|
||||
await fetchPlatformOptions();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page auto-content-height>
|
||||
<Grid
|
||||
class="order-grid"
|
||||
:loading="loading"
|
||||
@sort-change="handleSortChange"
|
||||
>
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加订单
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定删除选中的订单吗?删除后不可恢复。"
|
||||
ok-text="确定删除"
|
||||
cancel-text="取消"
|
||||
:ok-button-props="{ danger: true, loading: batchDeleteLoading }"
|
||||
:disabled="!hasSelected"
|
||||
@confirm="handleBatchDelete"
|
||||
>
|
||||
<Button
|
||||
danger
|
||||
:disabled="!hasSelected"
|
||||
:loading="batchDeleteLoading"
|
||||
>
|
||||
批量删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<template #platform="{ row }: { row: OrderVO.Info }">
|
||||
<PlatformTag :code="row.platformCode" :label="row.platformLabel" />
|
||||
</template>
|
||||
|
||||
<template #shopName="{ row }: { row: OrderVO.Info }">
|
||||
<a
|
||||
style="color: #1890ff; cursor: pointer"
|
||||
@click="goToShopDetail(row.shopId)"
|
||||
>
|
||||
{{ row.shopName || `店铺#${row.shopId}` }}
|
||||
</a>
|
||||
</template>
|
||||
|
||||
<template #goods="{ row }: { row: OrderVO.Info }">
|
||||
<div class="goods-cell">
|
||||
<Image
|
||||
v-if="goodsImg(row)"
|
||||
:src="goodsImg(row)"
|
||||
:width="40"
|
||||
:height="40"
|
||||
class="goods-img"
|
||||
/>
|
||||
<div class="goods-meta">
|
||||
<div class="goods-name" :title="goodsTitle(row)">
|
||||
{{ goodsTitle(row) }}
|
||||
</div>
|
||||
<div class="goods-spec">
|
||||
{{ goodsSpec(row) }}
|
||||
<span v-if="(row.itemCount ?? 0) > 1">
|
||||
等 {{ row.itemCount }} 件
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #payAmount="{ row }: { row: OrderVO.Info }">
|
||||
{{ money(getOrderPayAmount(row)) }}
|
||||
</template>
|
||||
|
||||
<template #receivedAmount="{ row }: { row: OrderVO.Info }">
|
||||
{{ money(getOrderReceivedAmount(row)) }}
|
||||
</template>
|
||||
|
||||
<template #orderStatus="{ row }: { row: OrderVO.Info }">
|
||||
<Tag :color="row.statusColor || 'blue'">
|
||||
{{ row.statusLabel || '未知状态' }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<template #source="{ row }: { row: OrderVO.Info }">
|
||||
{{ sourceText(row.source) }}
|
||||
</template>
|
||||
|
||||
<template #region="{ row }: { row: OrderVO.Info }">
|
||||
{{ regionText(row) }}
|
||||
</template>
|
||||
|
||||
<template #action="{ row }: { row: OrderVO.Info }">
|
||||
<Space>
|
||||
<Button type="link" size="small" @click="openDetail(row)">
|
||||
详情
|
||||
</Button>
|
||||
<Button type="link" size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个订单吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<Button type="link" size="small" danger>删除</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<OrderFormModal ref="orderFormModalRef" @success="handleModalSuccess" />
|
||||
<OrderDetailDrawer ref="detailDrawerRef" />
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.goods-cell {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
min-height: 48px;
|
||||
}
|
||||
|
||||
.goods-img {
|
||||
flex-shrink: 0;
|
||||
overflow: hidden;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.goods-meta {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.goods-name {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.goods-spec {
|
||||
color: #8c8c8c;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
:deep(.order-grid .vxe-body--column) {
|
||||
vertical-align: middle;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user