mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 06:29:20 +08:00
feat(ecom): 订单管理新增批量删除功能
- OrderServiceImpl 新增 deleteOrders 批量删除接口,单次最多500条 - 新增 BatchDeleteOrderDTO 参数校验 - 前端订单列表新增勾选框,支持批量删除选中订单 - OssServiceImpl 简化上传逻辑,移除冗余代码 - 更新 OSS 凭证配置
This commit is contained in:
@@ -25,7 +25,11 @@ import {
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteOrderApi, getOrderPageApi } from '#/api/ecommerce/order';
|
||||
import {
|
||||
batchDeleteOrdersApi,
|
||||
deleteOrderApi,
|
||||
getOrderPageApi,
|
||||
} from '#/api/ecommerce/order';
|
||||
import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status';
|
||||
import { getProductPageApi } from '#/api/ecommerce/product';
|
||||
import { getShopPageApi } from '#/api/ecommerce/shop';
|
||||
@@ -47,6 +51,9 @@ function goToProductDetail(productId: number) {
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const batchDeleteLoading = ref(false);
|
||||
/** vxe 勾选不触发 Vue 依赖,须用事件同步,勿用 computed 读 getCheckboxRecords */
|
||||
const hasSelected = ref(false);
|
||||
const orderFormModalRef = ref();
|
||||
|
||||
// 店铺分页数据
|
||||
@@ -200,12 +207,21 @@ function handleProductPopupScroll(e: Event) {
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
checkboxConfig: {
|
||||
highlight: true,
|
||||
reserve: false,
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
type: 'checkbox' as const,
|
||||
width: 48,
|
||||
fixed: 'left' as const,
|
||||
},
|
||||
{
|
||||
field: 'platformOrderNo',
|
||||
title: '平台订单号',
|
||||
@@ -500,6 +516,7 @@ const formOptions = computed(() => ({
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
hasSelected.value = false;
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
@@ -541,6 +558,18 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
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();
|
||||
|
||||
@@ -566,6 +595,35 @@ async function handleDelete(record: OrderVO.Info) {
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -588,6 +646,18 @@ onMounted(async () => {
|
||||
<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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user