feat: 优化店铺订单同步交互

This commit is contained in:
2026-08-10 17:16:13 +08:00
parent 2e5af7eec5
commit 64567d15d8
25 changed files with 715 additions and 1403 deletions
@@ -1,174 +0,0 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { BrushOrderDTO, BrushOrderVO } from '#/api/ecommerce/brush-order';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { Button, DatePicker, Popconfirm, Space } from 'ant-design-vue';
import { computed, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteBrushOrderApi,
getBrushOrderPageApi,
} from '#/api/ecommerce/brush-order';
import BrushOrderFormModal from '#/views/ecommerce/brush-order/components/BrushOrderFormModal.vue';
defineOptions({ name: 'BrushOrderCard' });
const PlusIcon = createIconifyIcon('lucide:plus');
const RepeatIcon = createIconifyIcon('lucide:repeat');
const props = defineProps<{
shopId: number;
data?: ShopVO.BrushOrderKpi;
}>();
const kpi = computed(() => props.data);
const gridReloadRef = ref<(() => void) | null>(null);
const searchForm = ref({
startBrushTime: undefined as string | undefined,
endBrushTime: undefined as string | undefined,
});
const modalVisible = ref(false);
const editingData = ref<BrushOrderVO.Info | undefined>();
const gridOptions: VxeGridProps<any> = {
columns: [
{ type: 'seq', title: '序号', width: 60 },
{ field: 'productName', title: '商品名称', minWidth: 160 },
{ field: 'productSkuName', title: 'SKU 名称', minWidth: 160 },
{
field: 'brushAmount', title: '刷单金额', width: 120,
formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`,
},
{ field: 'brushTime', title: '刷单时间', minWidth: 160 },
{ field: 'remark', title: '备注', minWidth: 120 },
{
title: '操作',
width: 150,
fixed: 'right',
slots: { default: 'action' },
},
],
height: 'auto',
maxHeight: 340,
border: true,
stripe: true,
size: 'small',
pagerConfig: { enabled: true, pageSizes: [10, 20, 50] },
proxyConfig: {
ajax: {
query: async ({ page }) => {
const params: PageQueryDTO<BrushOrderDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: props.shopId || undefined,
startBrushTime: searchForm.value.startBrushTime,
endBrushTime: searchForm.value.endBrushTime,
},
};
const data = await getBrushOrderPageApi(params);
return { items: data.records, total: data.total };
},
},
},
};
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
showSearchForm: false,
});
gridReloadRef.value = () => gridApi.reload();
function handleAdd() {
editingData.value = undefined;
modalVisible.value = true;
}
function handleEdit(row: BrushOrderVO.Info) {
editingData.value = row;
modalVisible.value = true;
}
async function handleDelete(id: number) {
await deleteBrushOrderApi(id);
gridReloadRef.value?.();
}
</script>
<template>
<div class="rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(222.34deg_10.43%_16%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
<!-- 标题栏 + 筛选区(单行) -->
<div class="flex items-center justify-between gap-3 border-b border-slate-100 px-6 py-3 dark:border-[hsl(222.34deg_10.43%_16%)]">
<h3 class="flex shrink-0 items-center gap-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
<RepeatIcon class="h-4 w-4" />
<span>刷单费</span>
</h3>
<div class="flex items-center gap-2">
<DatePicker
v-model:value="searchForm.startBrushTime"
placeholder="开始时间"
class="!w-40"
allow-clear
show-time
@change="() => gridReloadRef?.()"
/>
<span class="text-xs text-slate-400">至</span>
<DatePicker
v-model:value="searchForm.endBrushTime"
placeholder="结束时间"
class="!w-40"
allow-clear
show-time
@change="() => gridReloadRef?.()"
/>
</div>
<Button type="primary" size="small" @click="handleAdd">
<template #icon><PlusIcon /></template>
新增记录
</Button>
</div>
<!-- KPI 指标卡 -->
<div class="grid grid-cols-3 gap-4 border-b border-slate-100 px-6 py-4 dark:border-[hsl(222.34deg_10.43%_16%)]">
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计刷单费</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalBrushAmount || 0).toLocaleString() }}</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">本月刷单次数</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">{{ kpi?.thisMonthCount ?? 0 }} 次</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">平均刷单金额</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.avgAmount || 0).toLocaleString() }}</div>
</div>
</div>
<div class="p-4">
<Grid>
<template #action="{ row }: { row: BrushOrderVO.Info }">
<Space>
<Button size="small" type="primary" @click="handleEdit(row)">编辑</Button>
<Popconfirm title="确定删除?" @confirm="handleDelete(row.id)">
<Button size="small" danger>删除</Button>
</Popconfirm>
</Space>
</template>
</Grid>
</div>
<BrushOrderFormModal
v-model:open="modalVisible"
:brush-order-data="editingData"
@success="gridReloadRef?.()"
/>
</div>
</template>
@@ -1,179 +0,0 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { ShopMonthlyTargetDTO, ShopMonthlyTargetVO } from '#/api/ecommerce/shop-monthly-target';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { Button, DatePicker, Popconfirm, Space } from 'ant-design-vue';
import { computed, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deleteShopMonthlyTargetApi,
getShopMonthlyTargetPageApi,
} from '#/api/ecommerce/shop-monthly-target';
import ShopMonthlyTargetFormModal from '#/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue';
defineOptions({ name: 'MonthlyTargetCard' });
const PlusIcon = createIconifyIcon('lucide:plus');
const CalendarIcon = createIconifyIcon('lucide:calendar');
const props = defineProps<{
shopId: number;
data?: ShopVO.MonthlyTargetKpi;
}>();
const kpi = computed(() => props.data);
const gridReloadRef = ref<(() => void) | null>(null);
const searchForm = ref({
startTargetMonth: undefined as string | undefined,
endTargetMonth: undefined as string | undefined,
});
const modalVisible = ref(false);
const editingData = ref<ShopMonthlyTargetVO.Info | undefined>();
const gridOptions: VxeGridProps<any> = {
columns: [
{ type: 'seq', title: '序号', width: 60 },
{ field: 'targetMonth', title: '目标月份', width: 120 },
{
field: 'targetAmount', title: '目标销售额', width: 140,
formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`,
},
{ field: 'targetOrderCount', title: '目标单量', width: 120 },
{ field: 'remark', title: '备注', minWidth: 140 },
{
title: '操作',
width: 120,
fixed: 'right',
slots: { default: 'action' },
},
],
height: 'auto',
maxHeight: 340,
border: true,
stripe: true,
size: 'small',
pagerConfig: { enabled: true, pageSizes: [10, 20, 50] },
proxyConfig: {
ajax: {
query: async ({ page }) => {
const params: PageQueryDTO<ShopMonthlyTargetDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: props.shopId || undefined,
startTargetMonth: searchForm.value.startTargetMonth,
endTargetMonth: searchForm.value.endTargetMonth,
},
};
const data = await getShopMonthlyTargetPageApi(params);
return { items: data.records, total: data.total };
},
},
},
};
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
showSearchForm: false,
});
gridReloadRef.value = () => gridApi.reload();
function handleAdd() {
editingData.value = undefined;
modalVisible.value = true;
}
function handleEdit(row: ShopMonthlyTargetVO.Info) {
editingData.value = row;
modalVisible.value = true;
}
async function handleDelete(id: number) {
await deleteShopMonthlyTargetApi(id);
gridReloadRef.value?.();
}
</script>
<template>
<div class="rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(222.34deg_10.43%_16%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
<!-- 标题栏 + 筛选区(单行) -->
<div class="flex items-center justify-between gap-3 border-b border-slate-100 px-6 py-3 dark:border-[hsl(222.34deg_10.43%_16%)]">
<h3 class="flex shrink-0 items-center gap-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
<CalendarIcon class="h-4 w-4" />
<span>月度目标</span>
</h3>
<div class="flex items-center gap-2">
<DatePicker
v-model:value="searchForm.startTargetMonth"
placeholder="开始月份"
picker="month"
class="!w-32"
allow-clear
@change="() => gridReloadRef?.()"
/>
<span class="text-xs text-slate-400">至</span>
<DatePicker
v-model:value="searchForm.endTargetMonth"
placeholder="结束月份"
picker="month"
class="!w-32"
allow-clear
@change="() => gridReloadRef?.()"
/>
</div>
<Button type="primary" size="small" @click="handleAdd">
<template #icon><PlusIcon /></template>
新增目标
</Button>
</div>
<!-- KPI 指标卡 -->
<div class="grid grid-cols-2 gap-4 border-b border-slate-100 px-6 py-4 dark:border-[hsl(222.34deg_10.43%_16%)] sm:grid-cols-4">
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">年度目标总额</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalTargetAmount || 0).toLocaleString() }}</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">目标单量合计</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">{{ Number(kpi?.totalOrderCount || 0).toLocaleString() }}</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">本月目标</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.thisMonthTargetAmount || 0).toLocaleString() }}</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">当前达成率</div>
<div class="mt-1 text-lg font-bold text-emerald-600 dark:text-emerald-400">{{ kpi?.achievementRate ?? 0 }}%</div>
</div>
</div>
<!-- 表格 -->
<div class="p-4">
<Grid>
<template #action="{ row }: { row: ShopMonthlyTargetVO.Info }">
<Space>
<Button size="small" type="primary" @click="handleEdit(row)">编辑</Button>
<Popconfirm title="确定删除?" @confirm="handleDelete(row.id)">
<Button size="small" danger>删除</Button>
</Popconfirm>
</Space>
</template>
</Grid>
</div>
<!-- 弹窗 -->
<ShopMonthlyTargetFormModal
v-model:open="modalVisible"
:shop-monthly-target-data="editingData"
@success="gridReloadRef?.()"
/>
</div>
</template>
@@ -1,172 +0,0 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { PromotionFeeDTO, PromotionFeeVO } from '#/api/ecommerce/promotion-fee';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { Button, DatePicker, Popconfirm, Space } from 'ant-design-vue';
import { computed, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import {
deletePromotionFeeApi,
getPromotionFeePageApi,
} from '#/api/ecommerce/promotion-fee';
import PromotionFeeFormModal from '#/views/ecommerce/promotion-fee/components/PromotionFeeFormModal.vue';
defineOptions({ name: 'PromotionFeeCard' });
const PlusIcon = createIconifyIcon('lucide:plus');
const CoinsIcon = createIconifyIcon('lucide:coins');
const props = defineProps<{
shopId: number;
data?: ShopVO.PromotionFeeKpi;
}>();
const kpi = computed(() => props.data);
const gridReloadRef = ref<(() => void) | null>(null);
const searchForm = ref({
feeDateStart: undefined as string | undefined,
feeDateEnd: undefined as string | undefined,
});
const modalVisible = ref(false);
const editingData = ref<PromotionFeeVO.Info | undefined>();
const gridOptions: VxeGridProps<any> = {
columns: [
{ type: 'seq', title: '序号', width: 60 },
{ field: 'productId', title: '商品ID', width: 90 },
{ field: 'campaignName', title: '活动名称', minWidth: 140 },
{
field: 'feeAmount', title: '费用金额', width: 130,
formatter: ({ cellValue }) => `¥${Number(cellValue || 0).toLocaleString()}`,
},
{ field: 'feeDate', title: '费用日期', width: 120 },
{ field: 'remark', title: '备注', minWidth: 120 },
{
title: '操作',
width: 150,
fixed: 'right',
slots: { default: 'action' },
},
],
height: 'auto',
maxHeight: 340,
border: true,
stripe: true,
size: 'small',
pagerConfig: { enabled: true, pageSizes: [10, 20, 50] },
proxyConfig: {
ajax: {
query: async ({ page }) => {
const params: PageQueryDTO<PromotionFeeDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: props.shopId || undefined,
feeDateStart: searchForm.value.feeDateStart,
feeDateEnd: searchForm.value.feeDateEnd,
},
};
const data = await getPromotionFeePageApi(params);
return { items: data.records, total: data.total };
},
},
},
};
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
showSearchForm: false,
});
gridReloadRef.value = () => gridApi.reload();
function handleAdd() {
editingData.value = undefined;
modalVisible.value = true;
}
function handleEdit(row: PromotionFeeVO.Info) {
editingData.value = row;
modalVisible.value = true;
}
async function handleDelete(id: number) {
await deletePromotionFeeApi(id);
gridReloadRef.value?.();
}
</script>
<template>
<div class="rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(222.34deg_10.43%_16%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
<!-- 标题栏 + 筛选区 -->
<div class="flex items-center justify-between gap-3 border-b border-slate-100 px-6 py-3 dark:border-[hsl(222.34deg_10.43%_16%)]">
<h3 class="flex shrink-0 items-center gap-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
<CoinsIcon class="h-4 w-4" />
<span>推广费</span>
</h3>
<div class="flex items-center gap-2">
<DatePicker
v-model:value="searchForm.feeDateStart"
placeholder="开始日期"
class="!w-32"
allow-clear
@change="() => gridReloadRef?.()"
/>
<span class="text-xs text-slate-400">至</span>
<DatePicker
v-model:value="searchForm.feeDateEnd"
placeholder="结束日期"
class="!w-32"
allow-clear
@change="() => gridReloadRef?.()"
/>
</div>
<Button type="primary" size="small" @click="handleAdd">
<template #icon><PlusIcon /></template>
新增记录
</Button>
</div>
<!-- KPI 指标卡 -->
<div class="grid grid-cols-3 gap-4 border-b border-slate-100 px-6 py-4 dark:border-[hsl(222.34deg_10.43%_16%)]">
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计推广费</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalFeeAmount || 0).toLocaleString() }}</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">本月推广费</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.thisMonthFee || 0).toLocaleString() }}</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">日均推广费</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.avgDailyFee || 0).toLocaleString() }}</div>
</div>
</div>
<div class="p-4">
<Grid>
<template #action="{ row }: { row: PromotionFeeVO.Info }">
<Space>
<Button size="small" type="primary" @click="handleEdit(row)">编辑</Button>
<Popconfirm title="确定删除?" @confirm="handleDelete(row.id)">
<Button size="small" danger>删除</Button>
</Popconfirm>
</Space>
</template>
</Grid>
</div>
<PromotionFeeFormModal
v-model:open="modalVisible"
:promotion-fee-data="editingData"
@success="gridReloadRef?.()"
/>
</div>
</template>
@@ -1,189 +0,0 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { OrderDTO, OrderVO } from '#/api/ecommerce/order';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { Button, Input, Space, Tag } from 'ant-design-vue';
import { computed, ref } from 'vue';
import { createIconifyIcon } from '@vben/icons';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getOrderPageApi } from '#/api/ecommerce/order';
import {
getOrderLinkProductName,
getOrderLinkSkuName,
getOrderPayAmount,
getOrderQuantity,
getOrderUnitPrice,
} from '#/utils/order-display';
import OrderFormModal from '#/views/ecommerce/order/components/OrderFormModal.vue';
defineOptions({ name: 'ShopOrderCard' });
const PlusIcon = createIconifyIcon('lucide:plus');
const PackageIcon = createIconifyIcon('lucide:package');
const props = defineProps<{
shopId: number;
data?: ShopVO.ShopOrderKpi;
}>();
const kpi = computed(() => props.data);
const gridReloadRef = ref<(() => void) | null>(null);
const searchForm = ref({
platformOrderNo: undefined as string | undefined,
});
const orderModalRef = ref<InstanceType<typeof OrderFormModal> | null>(null);
const gridOptions: VxeGridProps<OrderVO.Info> = {
columns: [
{ type: 'seq', title: '序号', width: 60 },
{ field: 'platformOrderNo', title: '平台订单号', minWidth: 160 },
{
title: '商品名称',
minWidth: 140,
formatter: ({ row }) => getOrderLinkProductName(row),
},
{
title: 'SKU',
minWidth: 140,
formatter: ({ row }) => getOrderLinkSkuName(row) || '-',
},
{
title: '数量',
width: 70,
formatter: ({ row }) => String(getOrderQuantity(row)),
},
{
title: '单价',
width: 100,
formatter: ({ row }) => `¥${getOrderUnitPrice(row).toFixed(2)}`,
},
{
title: '实付金额',
width: 110,
formatter: ({ row }) => `¥${getOrderPayAmount(row).toFixed(2)}`,
},
{ field: 'statusLabel', title: '状态', width: 100, slots: { default: 'statusLabel' } },
{ field: 'orderTime', title: '下单时间', minWidth: 160 },
{
title: '操作',
width: 80,
fixed: 'right',
slots: { default: 'action' },
},
],
height: 'auto',
maxHeight: 340,
border: true,
stripe: true,
size: 'small',
pagerConfig: { enabled: true, pageSizes: [10, 20, 50] },
proxyConfig: {
ajax: {
query: async ({ page }) => {
const params: PageQueryDTO<OrderDTO.Filters> = {
page: page.currentPage,
pageSize: page.pageSize,
filters: {
shopId: props.shopId || undefined,
platformOrderNo: searchForm.value.platformOrderNo,
},
};
const data = await getOrderPageApi(params);
return { items: data.records, total: data.total };
},
},
},
};
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions,
showSearchForm: false,
});
gridReloadRef.value = () => gridApi.reload();
function handleView(row: OrderVO.Info) {
orderModalRef.value?.open(true, row);
}
function handleImport() {
orderModalRef.value?.open(false);
}
const statusColorMap: Record<string, string> = {
'已付款': 'blue',
'已发货': 'purple',
'已完成': 'green',
'已退款': 'red',
'已取消': 'default',
};
function resolveStatusColor(row: OrderVO.Info) {
return row.statusColor || statusColorMap[row.statusLabel] || 'default';
}
</script>
<template>
<div class="rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(222.34deg_10.43%_16%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
<!-- 标题栏 + 筛选区(单行) -->
<div class="flex items-center justify-between gap-3 border-b border-slate-100 px-6 py-3 dark:border-[hsl(222.34deg_10.43%_16%)]">
<h3 class="flex shrink-0 items-center gap-2 text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
<PackageIcon class="h-4 w-4" />
<span>店铺订单</span>
</h3>
<div class="flex items-center gap-2">
<Input
v-model:value="searchForm.platformOrderNo"
placeholder="平台订单号"
class="!w-44"
allow-clear
@change="() => gridReloadRef?.()"
/>
</div>
<Button type="primary" size="small" @click="handleImport">
<template #icon><PlusIcon /></template>
导入订单
</Button>
</div>
<!-- KPI 指标卡 -->
<div class="grid grid-cols-3 gap-4 border-b border-slate-100 px-6 py-4 dark:border-[hsl(222.34deg_10.43%_16%)]">
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计实收金额</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalReceivedAmount || 0).toLocaleString() }}</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计佣金</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">¥{{ Number(kpi?.totalCommission || 0).toLocaleString() }}</div>
</div>
<div class="text-center">
<div class="text-xs font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">累计订单数</div>
<div class="mt-1 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">{{ kpi?.totalOrderCount ?? 0 }} 笔</div>
</div>
</div>
<div class="p-4">
<Grid>
<template #statusLabel="{ row }: { row: OrderVO.Info }">
<Tag :color="resolveStatusColor(row)">{{ row.statusLabel }}</Tag>
</template>
<template #action="{ row }: { row: OrderVO.Info }">
<Space>
<Button size="small" type="primary" @click="handleView(row)">查看</Button>
</Space>
</template>
</Grid>
</div>
<OrderFormModal
ref="orderModalRef"
@success="gridReloadRef?.()"
/>
</div>
</template>
@@ -1,19 +1,9 @@
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue';
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import { Page } from '@vben/common-ui';
import { message } from 'ant-design-vue';
import { getShopDetailsApi } from '#/api/ecommerce/shop';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import MonthlyTargetCard from './components/MonthlyTargetCard.vue';
import PromotionFeeCard from './components/PromotionFeeCard.vue';
import BrushOrderCard from './components/BrushOrderCard.vue';
import ShopOrderCard from './components/ShopOrderCard.vue';
defineOptions({ name: 'ShopDetails' });
const route = useRoute();
@@ -22,58 +12,14 @@ const shopId = computed(() => {
const id = route.params.id;
return id ? Number(id) : 0;
});
const loading = ref(false);
const dashboard = ref<ShopVO.Dashboard | null>(null);
async function fetchDashboard() {
if (!shopId.value) return;
loading.value = true;
try {
dashboard.value = await getShopDetailsApi({ shopId: shopId.value });
} catch {
message.error('获取店铺看板数据失败');
} finally {
loading.value = false;
}
}
onMounted(() => {
fetchDashboard();
});
</script>
<template>
<Page
:title="dashboard ? `店铺详情(${dashboard.shopInfo?.name})` : '店铺详情'"
:title="shopId ? `店铺详情(#${shopId})` : '店铺详情'"
auto-content-height
content-class="flex min-h-0 flex-1 flex-col bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
>
<div class="mx-auto grid w-full grid-cols-1 gap-6 md:grid-cols-2">
<!-- 月度目标 -->
<MonthlyTargetCard
v-if="dashboard"
:shop-id="shopId"
:data="dashboard.monthlyTarget"
/>
<!-- 推广费 -->
<PromotionFeeCard
v-if="dashboard"
:shop-id="shopId"
:data="dashboard.promotionFee"
/>
<!-- 刷单费 -->
<BrushOrderCard
v-if="dashboard"
:shop-id="shopId"
:data="dashboard.brushOrder"
/>
<!-- 店铺订单 -->
<ShopOrderCard
v-if="dashboard"
:shop-id="shopId"
:data="dashboard.shopOrder"
/>
</div>
<div class="text-slate-500">店铺详情看板接口已下线。</div>
</Page>
</template>
@@ -7,13 +7,26 @@ import { computed, onBeforeUnmount, ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { DatePicker, Form, message, Progress, Radio, Switch } from 'ant-design-vue';
import {
Button,
DatePicker,
Form,
message,
Progress,
Radio,
Space,
Switch,
Tag,
} from 'ant-design-vue';
import dayjs from 'dayjs';
import {
cancelPddFullSyncTaskApi,
createPddFullSyncTaskApi,
getPddFullSyncTaskApi,
getPddIncrementalSyncStatusApi,
getPddLatestFullSyncTaskApi,
resumePddFullSyncTaskApi,
syncPddOrdersByDayApi,
syncPddOrdersIncrementalApi,
togglePddIncrementalSyncApi,
@@ -33,13 +46,13 @@ const range = ref<[Dayjs, Dayjs]>([
dayjs().subtract(90, 'day'),
dayjs().subtract(1, 'day'),
]);
const incrementalEnabled = ref(false);
const incremental = ref<null | PddOrderSyncVO.IncrementalStatus>(null);
const fullTask = ref<null | PddOrderSyncVO.FullTask>(null);
let pollTimer: null | ReturnType<typeof setInterval> = null;
const [Modal, modalApi] = useVbenModal({
draggable: true,
class: 'w-[520px]',
class: 'w-[560px]',
onCancel() {
stopPoll();
modalApi.close();
@@ -61,6 +74,39 @@ const taskProgressPercent = computed(() => {
);
});
const isFullActive = computed(() => {
const s = fullTask.value?.status;
return s === 'PENDING' || s === 'RUNNING';
});
const canCancelFull = computed(() => isFullActive.value);
const canResumeFull = computed(() => fullTask.value?.status === 'FAILED');
const incHealthLabel = computed(() => {
const health = incremental.value?.health;
const map: Record<string, string> = {
OFF: '已关闭',
OK: '正常',
LAGGING: '游标滞后',
PAUSED: '出错暂停',
};
return health ? map[health] || health : '-';
});
const incHealthColor = computed(() => {
const health = incremental.value?.health;
if (health === 'PAUSED') return 'error';
if (health === 'LAGGING') return 'warning';
if (health === 'OK') return 'success';
return 'default';
});
function formatTime(time?: null | string) {
if (!time) return '-';
const d = dayjs(time);
return d.isValid() ? d.format('YYYY-MM-DD HH:mm:ss') : '-';
}
function stopPoll() {
if (pollTimer) {
clearInterval(pollTimer);
@@ -71,25 +117,38 @@ function stopPoll() {
async function loadIncrementalStatus() {
if (!shop.value) return;
try {
const status = await getPddIncrementalSyncStatusApi(shop.value.id);
incrementalEnabled.value = !!status.enabled;
incremental.value = await getPddIncrementalSyncStatusApi(shop.value.id);
} catch (error) {
console.error('加载增量开关失败:', error);
console.error('加载增量状态失败:', error);
}
}
async function loadLatestFullTask() {
if (!shop.value) return;
try {
const task = await getPddLatestFullSyncTaskApi(shop.value.id);
fullTask.value = task;
if (task && (task.status === 'PENDING' || task.status === 'RUNNING')) {
pollFullTask(task.id);
}
} catch (error) {
console.error('加载全量任务失败:', error);
}
}
async function handleToggleIncremental(checked: boolean | string | number) {
if (!shop.value) return;
const enabled = !!checked;
const prev = incremental.value;
try {
const status = await togglePddIncrementalSyncApi({
incremental.value = await togglePddIncrementalSyncApi({
shopId: shop.value.id,
enabled,
});
incrementalEnabled.value = !!status.enabled;
message.success(enabled ? '已开启增量同步' : '已关闭增量同步');
emit('success');
} catch (error) {
incrementalEnabled.value = !enabled;
incremental.value = prev;
console.error('切换增量开关失败:', error);
message.error('切换增量开关失败');
}
@@ -101,7 +160,11 @@ async function pollFullTask(taskId: number) {
try {
const task = await getPddFullSyncTaskApi(taskId);
fullTask.value = task;
if (task.status === 'SUCCESS' || task.status === 'FAILED' || task.status === 'CANCELLED') {
if (
task.status === 'SUCCESS' ||
task.status === 'FAILED' ||
task.status === 'CANCELLED'
) {
stopPoll();
modalApi.setState({ confirmLoading: false });
loading.value = false;
@@ -110,8 +173,12 @@ async function pollFullTask(taskId: number) {
`全量同步完成:${task.doneDays}/${task.totalDays} 天`,
);
emit('success');
} else {
} else if (task.status === 'FAILED') {
message.error(task.lastError || '全量同步失败');
emit('success');
} else {
message.info('全量同步已取消');
emit('success');
}
}
} catch (error) {
@@ -120,6 +187,39 @@ async function pollFullTask(taskId: number) {
}, 2000);
}
async function handleCancelFull() {
if (!fullTask.value) return;
try {
loading.value = true;
fullTask.value = await cancelPddFullSyncTaskApi(fullTask.value.id);
stopPoll();
message.success('已取消全量任务');
emit('success');
} catch (error) {
console.error('取消全量任务失败:', error);
message.error('取消全量任务失败');
} finally {
loading.value = false;
}
}
async function handleResumeFull() {
if (!fullTask.value) return;
try {
loading.value = true;
modalApi.setState({ confirmLoading: true });
const task = await resumePddFullSyncTaskApi(fullTask.value.id);
fullTask.value = task;
message.success('已续跑入队');
pollFullTask(task.id);
} catch (error) {
console.error('续跑全量任务失败:', error);
message.error('续跑全量任务失败');
loading.value = false;
modalApi.setState({ confirmLoading: false });
}
}
async function handleSubmit() {
if (!shop.value) return;
if (mode.value === 'day' && !confirmDate.value) {
@@ -130,6 +230,10 @@ async function handleSubmit() {
message.warning('请选择全量同步日期区间');
return;
}
if (mode.value === 'full' && isFullActive.value) {
message.warning('该店铺已有进行中的全量任务,请先等待或取消');
return;
}
try {
loading.value = true;
modalApi.setState({ confirmLoading: true });
@@ -143,28 +247,22 @@ async function handleSubmit() {
fullTask.value = task;
message.success('全量同步任务已创建,正在后台执行');
pollFullTask(task.id);
emit('success');
return;
}
const result =
mode.value === 'day'
? await syncPddOrdersByDayApi({
shopId: shop.value.id,
confirmDate: confirmDate.value.format('YYYY-MM-DD'),
})
: await syncPddOrdersIncrementalApi(shop.value.id);
await (mode.value === 'day'
? syncPddOrdersByDayApi({
shopId: shop.value.id,
confirmDate: confirmDate.value.format('YYYY-MM-DD'),
})
: syncPddOrdersIncrementalApi(shop.value.id));
const errHint =
result.errors && result.errors.length > 0
? `;注意:${result.errors[0]}`
: '';
message.success(
mode.value === 'day' || mode.value === 'incremental'
? '已入队,后台同步中'
: `同步完成:拉取 ${result.fetchedCount},入库 ${result.upsertedCount}${errHint}`,
);
message.success('已入队,后台同步中');
emit('success');
modalApi.close();
if (mode.value === 'incremental') {
await loadIncrementalStatus();
}
} catch (error) {
console.error('同步拼多多订单失败:', error);
message.error('同步拼多多订单失败');
@@ -182,9 +280,10 @@ async function open(record: ShopVO.Info) {
confirmDate.value = dayjs().subtract(1, 'day');
range.value = [dayjs().subtract(90, 'day'), dayjs().subtract(1, 'day')];
fullTask.value = null;
incremental.value = null;
stopPoll();
await loadIncrementalStatus();
modalApi.open();
await Promise.all([loadIncrementalStatus(), loadLatestFullTask()]);
}
onBeforeUnmount(() => stopPoll());
@@ -194,21 +293,81 @@ defineExpose({ open });
<template>
<Modal :title="modalTitle" content-class="px-5 py-4">
<Form layout="vertical">
<Form.Item label="自动增量同步">
<div class="flex items-center gap-3">
<!-- 状态面板 -->
<div class="mb-4 space-y-3">
<div class="rounded border border-slate-200 p-3 dark:border-[hsl(240deg_3.7%_22%)]">
<div class="mb-2 flex items-center justify-between">
<span class="text-sm font-medium">增量同步</span>
<Tag :color="incHealthColor">{{ incHealthLabel }}</Tag>
</div>
<div class="mb-2 flex items-center gap-3">
<Switch
:checked="incrementalEnabled"
:checked="!!incremental?.enabled"
checked-children="开"
un-checked-children="关"
@change="handleToggleIncremental"
/>
<span class="text-xs text-slate-500">开启后定时 Job 会拉取该店增量并转换</span>
<span class="text-xs text-slate-500">开启后定时 Job 拉取增量并转换</span>
</div>
</Form.Item>
<div class="grid grid-cols-1 gap-1 text-xs text-slate-600 sm:grid-cols-2 dark:text-slate-300">
<div>游标:{{ formatTime(incremental?.lastCursorAt) }}</div>
<div>上次成功:{{ formatTime(incremental?.lastSuccessTime) }}</div>
</div>
<p v-if="incremental?.lastError" class="mt-2 text-xs text-red-500">
{{ incremental.lastError }}
</p>
</div>
<div class="rounded border border-slate-200 p-3 dark:border-[hsl(240deg_3.7%_22%)]">
<div class="mb-2 flex items-center justify-between gap-2">
<span class="text-sm font-medium">全量同步任务</span>
<Space size="small">
<Button
v-if="canCancelFull"
size="small"
danger
:loading="loading"
@click="handleCancelFull"
>
取消
</Button>
<Button
v-if="canResumeFull"
size="small"
type="primary"
:loading="loading"
@click="handleResumeFull"
>
续跑
</Button>
</Space>
</div>
<template v-if="fullTask">
<div class="mb-2 text-sm">
#{{ fullTask.id }} · {{ fullTask.status }} ·
{{ fullTask.doneDays }}/{{ fullTask.totalDays }} 天
<span v-if="fullTask.failedDays" class="text-red-500">
· 失败日 {{ fullTask.failedDays }}
</span>
</div>
<div class="mb-2 text-xs text-slate-500">
区间 {{ fullTask.dateFrom }} ~ {{ fullTask.dateTo }}
<span v-if="fullTask.currentDate"> · 当前 {{ fullTask.currentDate }}</span>
</div>
<Progress :percent="taskProgressPercent" size="small" />
<p v-if="fullTask.lastError" class="mt-2 text-xs text-red-500">
{{ fullTask.lastError }}
</p>
</template>
<p v-else class="text-xs text-slate-500">暂无全量任务</p>
</div>
</div>
<!-- 操作区 -->
<Form layout="vertical">
<Form.Item label="同步方式">
<Radio.Group v-model:value="mode">
<Radio value="full">全量同步任务(按日区间)</Radio>
<Radio value="full" :disabled="isFullActive">全量同步任务(按日区间)</Radio>
<Radio value="day">按成交日同步一天</Radio>
<Radio value="incremental">手动增量一次</Radio>
</Radio.Group>
@@ -222,6 +381,7 @@ defineExpose({ open });
v-model:value="range"
class="w-full"
:allow-clear="false"
:disabled="isFullActive"
format="YYYY-MM-DD"
/>
</Form.Item>
@@ -240,17 +400,6 @@ defineExpose({ open });
<p v-else class="mb-3 text-xs text-slate-500">
按订单更新时间拉取自上次游标以来的变更,用于发货/售后等状态同步。
</p>
<div v-if="fullTask" class="rounded border border-slate-200 p-3">
<div class="mb-2 text-sm">
任务 #{{ fullTask.id }} · {{ fullTask.status }} ·
{{ fullTask.doneDays }}/{{ fullTask.totalDays }} 天
<span v-if="fullTask.currentDate">(当前 {{ fullTask.currentDate }})</span>
</div>
<Progress :percent="taskProgressPercent" size="small" />
<p v-if="fullTask.lastError" class="mt-2 text-xs text-red-500">
{{ fullTask.lastError }}
</p>
</div>
</Form>
</Modal>
</template>
@@ -1,19 +1,21 @@
<script lang="ts" setup>
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { PlatformVO } from '#/api/ecommerce/platform/types';
import type { PddOrderSyncVO } from '#/api/ecommerce/pdd/order-sync';
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
import type { PageQueryDTO } from '#/types/common';
import { computed, onMounted, onUnmounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { createIconifyIcon } from '@vben/icons';
import { Button, message, Popconfirm, Space, Tag } from 'ant-design-vue';
import dayjs from 'dayjs';
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getPddAuthorizeUrlApi } from '#/api/ecommerce/pdd/auth';
import { batchPddOrderSyncStatusApi } from '#/api/ecommerce/pdd/order-sync';
import { getPlatformListApi } from '#/api/ecommerce/platform';
import { deleteShopApi, getShopPageApi } from '#/api/ecommerce/shop';
@@ -25,8 +27,6 @@ defineOptions({ name: 'ShopManagement' });
const PLATFORM_CODE_PDD = 'pdd';
const router = useRouter();
const PlusIcon = createIconifyIcon('lucide:plus');
const loading = ref(false);
@@ -35,6 +35,9 @@ const shopFormModalRef = ref();
const pddShopDetailModalRef = ref();
const pddOrderSyncModalRef = ref();
/** shopId -> 同步摘要 */
const syncStatusMap = ref<Record<number, PddOrderSyncVO.ShopStatus>>({});
const searchForm = ref({
name: '',
platformCode: undefined as string | undefined,
@@ -77,6 +80,12 @@ const gridOptions: VxeGridProps<any> = {
showOverflow: false,
slots: { default: 'externalShop' },
},
{
title: '订单同步',
minWidth: 200,
showOverflow: false,
slots: { default: 'orderSync' },
},
{
field: 'createTime',
title: '创建时间',
@@ -89,7 +98,7 @@ const gridOptions: VxeGridProps<any> = {
},
{
title: '操作',
minWidth: 420,
minWidth: 360,
fixed: 'right' as const,
slots: { default: 'action' },
},
@@ -146,6 +155,7 @@ const gridOptions: VxeGridProps<any> = {
},
};
const data = await getShopPageApi(params);
await loadSyncStatusForShops(data.records || []);
return {
items: data.records,
total: data.total,
@@ -226,6 +236,89 @@ async function fetchPlatformOptions() {
}
}
async function loadSyncStatusForShops(records: ShopVO.Info[]) {
const pddIds = records
.filter((r) => r.platformCode === PLATFORM_CODE_PDD && hasExternalShop(r))
.map((r) => r.id);
if (pddIds.length === 0) {
syncStatusMap.value = {};
return;
}
try {
const list = await batchPddOrderSyncStatusApi(pddIds);
const map: Record<number, PddOrderSyncVO.ShopStatus> = {};
for (const item of list || []) {
map[item.shopId] = item;
}
syncStatusMap.value = map;
} catch (error) {
console.error('加载订单同步状态失败:', error);
syncStatusMap.value = {};
}
}
function formatRelative(time?: null | string) {
if (!time) return '';
const d = dayjs(time);
if (!d.isValid()) return '';
const mins = dayjs().diff(d, 'minute');
if (mins < 1) return '刚刚';
if (mins < 60) return `${mins} 分钟前`;
const hours = dayjs().diff(d, 'hour');
if (hours < 24) return `${hours} 小时前`;
const days = dayjs().diff(d, 'day');
if (days < 30) return `${days} 天前`;
return d.format('MM-DD');
}
function fullSyncLabel(status?: PddOrderSyncVO.ShopStatus) {
const task = status?.fullTask;
if (!task) return '-';
if (task.status === 'PENDING' || task.status === 'RUNNING') {
return `进行中 ${task.doneDays ?? 0}/${task.totalDays ?? 0}`;
}
if (task.status === 'FAILED') return '失败';
if (task.status === 'CANCELLED') return '已取消';
if (task.status === 'SUCCESS') {
const rel = formatRelative(task.finishTime);
return rel ? `已完成(${rel})` : '已完成';
}
return task.status;
}
function fullSyncColor(status?: PddOrderSyncVO.ShopStatus) {
const s = status?.fullTask?.status;
if (s === 'RUNNING' || s === 'PENDING') return 'processing';
if (s === 'FAILED') return 'error';
if (s === 'SUCCESS') return 'success';
if (s === 'CANCELLED') return 'default';
return 'default';
}
function incSyncLabel(status?: PddOrderSyncVO.ShopStatus) {
const inc = status?.incremental;
if (!inc) return '关';
const health = inc.health || (inc.enabled ? 'OK' : 'OFF');
const map: Record<string, string> = {
OFF: '关',
OK: '开·正常',
LAGGING: '开·滞后',
PAUSED: '开·暂停',
};
const base = map[health] || (inc.enabled ? '开' : '关');
const anchor = inc.lastSuccessTime || inc.lastCursorAt;
const rel = formatRelative(anchor);
return rel ? `${base} · ${rel}` : base;
}
function incSyncColor(status?: PddOrderSyncVO.ShopStatus) {
const health = status?.incremental?.health;
if (health === 'PAUSED') return 'error';
if (health === 'LAGGING') return 'warning';
if (health === 'OK') return 'success';
return 'default';
}
function refreshTable() {
gridApi?.reload();
}
@@ -261,10 +354,6 @@ function handleModalSuccess() {
refreshTable();
}
function handleViewOverview(record: ShopVO.Info) {
router.push(`/ecom/shop/overview/${record.id}`);
}
function handleViewExternalShop(record: ShopVO.Info) {
if (!record.pddShop) {
message.warning('暂无外部店铺详情,请先完成授权同步');
@@ -357,12 +446,7 @@ onUnmounted(() => {
</template>
<template #name="{ row }: { row: ShopVO.Info }">
<a
class="text-primary cursor-pointer hover:underline"
@click="handleViewOverview(row)"
>
{{ row.name }}
</a>
<span>{{ row.name }}</span>
</template>
<template #externalShop="{ row }: { row: ShopVO.Info }">
@@ -388,24 +472,30 @@ onUnmounted(() => {
<span v-else class="text-slate-400">-</span>
</template>
<template #orderSync="{ row }: { row: ShopVO.Info }">
<div
v-if="isPddShop(row) && hasExternalShop(row)"
class="flex cursor-pointer flex-col gap-1"
@click="handleSyncPddOrders(row)"
>
<div class="flex items-center gap-1 text-xs">
<span class="text-slate-500">全量</span>
<Tag :color="fullSyncColor(syncStatusMap[row.id])" class="!mr-0">
{{ fullSyncLabel(syncStatusMap[row.id]) }}
</Tag>
</div>
<div class="flex items-center gap-1 text-xs">
<span class="text-slate-500">增量</span>
<Tag :color="incSyncColor(syncStatusMap[row.id])" class="!mr-0">
{{ incSyncLabel(syncStatusMap[row.id]) }}
</Tag>
</div>
</div>
<span v-else class="text-slate-400">-</span>
</template>
<template #action="{ row }: { row: ShopVO.Info }">
<Space wrap>
<Button size="small" type="primary" @click="handleViewOverview(row)">
查看概览
</Button>
<Button
size="small"
@click="router.push(`/ecom/shop/details/${row.id}`)"
>
查看详情
</Button>
<Button
v-if="isPddShop(row) && row.pddShop"
size="small"
@click="handleViewExternalShop(row)"
>
外部店铺
</Button>
<Button
v-if="isPddShop(row) && hasExternalShop(row)"
size="small"
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import type { ShopDTO, ShopVO } from '#/api/ecommerce/shop/types';
import type { ShopVO } from '#/api/ecommerce/shop/types';
import type { Dayjs } from 'dayjs';
import {
@@ -16,7 +16,6 @@ import { Page } from '@vben/common-ui';
import { message, Spin } from 'ant-design-vue';
import dayjs from 'dayjs';
import { getShopOverviewStatisticsApi } from '#/api/ecommerce/shop';
import { getShopPageApi } from '#/api/ecommerce/shop/apis';
import { exportByPost } from '#/utils/export';
import {
@@ -250,19 +249,8 @@ const loadOverviewData = async () => {
isRequesting.value = true;
try {
loading.value = true;
const params: ShopDTO.OverviewQuery = {
shopId: shopId.value,
dateRange: [
dateRange.value[0].format('YYYY-MM-DD'),
dateRange.value[1].format('YYYY-MM-DD'),
],
taxRate: taxRate.value,
};
const data = await getShopOverviewStatisticsApi(params);
overviewData.value = data;
} catch (error) {
console.error('获取店铺概览数据失败:', error);
message.error('获取店铺概览数据失败');
// 原 /ec/shop/overview 已下线,待接入 Mongo BI 读模型
overviewData.value = null;
} finally {
loading.value = false;
isRequesting.value = false;