mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 01:09:19 +08:00
refactor(ecom): 订单状态统计规则从单一开关升级为多维度独立控制
- ec_order_status 表 auto_statistics 拆分为四个独立字段:include_sales_amount / include_product_cost / include_freight_cost / include_other_cost / include_refund - CompanyOverviewServiceImpl / ShopOverviewStatisticsServiceImpl / ProductOverviewServiceImpl / ExportStatusRangeHelper 全部改为按各维度独立统计 - OrderStatus PO/DTO/VO 层字段更新,Service 层校验逻辑同步调整 - ProductSpecImportHelper 导入逻辑适配新字段 - 前端订单状态配置页适配新字段及展示 - 新增 OrderStatusCard.vue 卡片组件 - 更新 ec_design.sql 设计文档
This commit is contained in:
+241
@@ -0,0 +1,241 @@
|
||||
<script lang="ts" setup>
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
|
||||
import { patchOrderStatusApi } from '#/api/ecommerce/order-status';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Card, message, Popconfirm, Switch } from 'ant-design-vue';
|
||||
|
||||
const props = defineProps<{
|
||||
status: OrderStatusVO.Info;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
delete: [OrderStatusVO.Info];
|
||||
edit: [OrderStatusVO.Info];
|
||||
/** 成功时携带 PATCH 返回的最新 VO;失败时不传,由父级决定是否重新拉列表 */
|
||||
patched: [vo?: OrderStatusVO.Info];
|
||||
}>();
|
||||
|
||||
const EditIcon = createIconifyIcon('lucide:pencil');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
type StatKey = keyof Pick<
|
||||
OrderStatusVO.Info,
|
||||
| 'includeSalesAmount'
|
||||
| 'includeProductCost'
|
||||
| 'includeFreightCost'
|
||||
| 'includeOtherCost'
|
||||
| 'includeRefund'
|
||||
>;
|
||||
|
||||
/** 后端 / JSON 可能为 0、1、'0'、'1';Switch 在 checkedValue=1 时须用 0|1 绑定 :checked,不能绑 boolean */
|
||||
function dim01(v: unknown): 0 | 1 {
|
||||
if (v === 1 || v === '1' || v === true) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
async function handleDimChange(key: StatKey, next: unknown) {
|
||||
const val = dim01(next);
|
||||
if (dim01(props.status[key]) === val) return;
|
||||
try {
|
||||
const updated = await patchOrderStatusApi(props.status.id, { [key]: val });
|
||||
message.success('更新成功');
|
||||
if (updated && typeof updated === 'object' && 'id' in updated) {
|
||||
emit('patched', updated as OrderStatusVO.Info);
|
||||
} else {
|
||||
emit('patched');
|
||||
}
|
||||
} catch {
|
||||
message.error('更新失败');
|
||||
emit('patched');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card
|
||||
hoverable
|
||||
:body-style="{ padding: 0 }"
|
||||
class="order-status-card group h-full"
|
||||
>
|
||||
<div class="card-head">
|
||||
<div class="flex min-w-0 flex-1 items-center gap-2">
|
||||
<span
|
||||
class="max-w-[70%] truncate text-base font-semibold text-slate-800 dark:text-[hsl(0deg_0%_95%)]"
|
||||
>
|
||||
{{ status.statusName }}
|
||||
</span>
|
||||
<span
|
||||
v-if="status.sortOrder != null"
|
||||
class="shrink-0 rounded-md bg-slate-100 px-2 py-0.5 text-xs text-slate-500 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||
>
|
||||
排序 {{ status.sortOrder }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="flex shrink-0 items-center gap-1 opacity-80 transition-opacity group-hover:opacity-100">
|
||||
<Button type="text" size="small" @click="emit('edit', status)">
|
||||
<EditIcon class="h-4 w-4" />
|
||||
</Button>
|
||||
<Popconfirm title="确定删除该订单状态?" @confirm="emit('delete', status)">
|
||||
<Button type="text" size="small" danger>
|
||||
<TrashIcon class="h-4 w-4" />
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 布局与 OrderStatusFormModal 中 Form 区块对齐(只读展示 + 维度开关) -->
|
||||
<div class="card-body">
|
||||
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
||||
<div class="min-w-0">
|
||||
<div class="mb-1 text-sm text-muted-foreground">状态名称</div>
|
||||
<div class="text-sm font-medium text-foreground">
|
||||
{{ status.statusName }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<div class="mb-1 text-sm text-muted-foreground">状态描述</div>
|
||||
<p
|
||||
class="desc-preview whitespace-pre-wrap text-sm text-foreground/90"
|
||||
>
|
||||
{{ status.description || '—' }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-2 mt-4 text-sm font-medium text-foreground">
|
||||
统计维度
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-x-4 gap-y-2 sm:grid-cols-2">
|
||||
<div
|
||||
class="stat-dim-row stat-dim--sales flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-blue-500 bg-blue-50/70 px-3 py-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-sky-400 dark:bg-sky-950/25"
|
||||
>
|
||||
<span class="text-sm text-muted-foreground">计入销售额 / 单量</span>
|
||||
<Switch
|
||||
:checked="dim01(status.includeSalesAmount)"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
@update:checked="(v: unknown) => handleDimChange('includeSalesAmount', v)"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="stat-dim-row stat-dim--product flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-emerald-500 bg-emerald-50/70 px-3 py-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-emerald-400 dark:bg-emerald-950/25"
|
||||
>
|
||||
<span class="text-sm text-muted-foreground">计入商品成本</span>
|
||||
<Switch
|
||||
:checked="dim01(status.includeProductCost)"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
@update:checked="(v: unknown) => handleDimChange('includeProductCost', v)"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="stat-dim-row stat-dim--freight flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-amber-500 bg-amber-50/70 px-3 py-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-amber-400 dark:bg-amber-950/25"
|
||||
>
|
||||
<span class="text-sm text-muted-foreground">计入运费成本</span>
|
||||
<Switch
|
||||
:checked="dim01(status.includeFreightCost)"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
@update:checked="(v: unknown) => handleDimChange('includeFreightCost', v)"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="stat-dim-row stat-dim--other flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-violet-500 bg-violet-50/70 px-3 py-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-violet-400 dark:bg-violet-950/25"
|
||||
>
|
||||
<span class="text-sm text-muted-foreground">计入其他成本</span>
|
||||
<Switch
|
||||
:checked="dim01(status.includeOtherCost)"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
@update:checked="(v: unknown) => handleDimChange('includeOtherCost', v)"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="stat-dim-row stat-dim--refund flex items-center justify-between gap-2 rounded-lg border border-slate-100 border-l-[3px] border-l-rose-500 bg-rose-50/70 px-3 py-2 sm:col-span-2 dark:border-[hsl(240deg_3.7%_22%)] dark:border-l-rose-400 dark:bg-rose-950/25"
|
||||
>
|
||||
<span class="text-sm text-muted-foreground">计入退款金额</span>
|
||||
<Switch
|
||||
:checked="dim01(status.includeRefund)"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
@update:checked="(v: unknown) => handleDimChange('includeRefund', v)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.order-status-card {
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
border: 1px solid #d7e1ee;
|
||||
background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
|
||||
box-shadow:
|
||||
0 14px 34px rgb(15 23 42 / 9%),
|
||||
0 2px 10px rgb(15 23 42 / 5%);
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: #b8c8de;
|
||||
box-shadow:
|
||||
0 20px 38px rgb(15 23 42 / 14%),
|
||||
0 6px 14px rgb(15 23 42 / 9%);
|
||||
}
|
||||
|
||||
.card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid #dde6f2;
|
||||
background: linear-gradient(180deg, rgb(237 245 255 / 95%) 0%, #ffffff 100%);
|
||||
}
|
||||
|
||||
.card-body {
|
||||
padding: 16px 18px 18px;
|
||||
}
|
||||
|
||||
/* 各维度 Switch 开启态与行主题色一致 */
|
||||
.stat-dim--sales :deep(.ant-switch-checked) {
|
||||
background: #1677ff !important;
|
||||
}
|
||||
.stat-dim--product :deep(.ant-switch-checked) {
|
||||
background: #16a34a !important;
|
||||
}
|
||||
.stat-dim--freight :deep(.ant-switch-checked) {
|
||||
background: #d97706 !important;
|
||||
}
|
||||
.stat-dim--other :deep(.ant-switch-checked) {
|
||||
background: #7c3aed !important;
|
||||
}
|
||||
.stat-dim--refund :deep(.ant-switch-checked) {
|
||||
background: #e11d48 !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* 右侧描述区:多行截断,避免把卡片撑得过高 */
|
||||
.desc-preview {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 5;
|
||||
line-clamp: 5;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-word;
|
||||
}
|
||||
</style>
|
||||
+90
-27
@@ -20,10 +20,18 @@ const emit = defineEmits<{
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
const STAT_DEFAULTS = {
|
||||
includeSalesAmount: 1,
|
||||
includeProductCost: 1,
|
||||
includeFreightCost: 1,
|
||||
includeOtherCost: 1,
|
||||
includeRefund: 0,
|
||||
} as const;
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[500px]',
|
||||
class: 'w-[640px]',
|
||||
onCancel() {
|
||||
close();
|
||||
},
|
||||
@@ -49,9 +57,8 @@ const formData = ref<Partial<OrderStatusDTO.Create>>({
|
||||
statusName: '',
|
||||
description: '',
|
||||
color: '',
|
||||
autoStatistics: 1,
|
||||
sortOrder: 0,
|
||||
isRefund: 0,
|
||||
...STAT_DEFAULTS,
|
||||
});
|
||||
|
||||
// 表单验证规则
|
||||
@@ -63,6 +70,10 @@ const rules = {
|
||||
// 表单引用
|
||||
const formRef = ref();
|
||||
|
||||
function toStatNumber(v: number | undefined, fallback: number) {
|
||||
return v === 0 || v === 1 ? v : fallback;
|
||||
}
|
||||
|
||||
// 打开模态框
|
||||
function open(edit: boolean, record?: OrderStatusVO.Info) {
|
||||
isEdit.value = edit;
|
||||
@@ -76,17 +87,34 @@ function open(edit: boolean, record?: OrderStatusVO.Info) {
|
||||
statusName: record.statusName,
|
||||
description: record.description || '',
|
||||
color: record.color || '',
|
||||
autoStatistics: record.autoStatistics,
|
||||
sortOrder: record.sortOrder || 0,
|
||||
isRefund: record.isRefund || 0,
|
||||
includeSalesAmount: toStatNumber(
|
||||
record.includeSalesAmount,
|
||||
STAT_DEFAULTS.includeSalesAmount,
|
||||
),
|
||||
includeProductCost: toStatNumber(
|
||||
record.includeProductCost,
|
||||
STAT_DEFAULTS.includeProductCost,
|
||||
),
|
||||
includeFreightCost: toStatNumber(
|
||||
record.includeFreightCost,
|
||||
STAT_DEFAULTS.includeFreightCost,
|
||||
),
|
||||
includeOtherCost: toStatNumber(
|
||||
record.includeOtherCost,
|
||||
STAT_DEFAULTS.includeOtherCost,
|
||||
),
|
||||
includeRefund: toStatNumber(
|
||||
record.includeRefund,
|
||||
STAT_DEFAULTS.includeRefund,
|
||||
),
|
||||
}
|
||||
: {
|
||||
statusName: '',
|
||||
description: '',
|
||||
color: '',
|
||||
autoStatistics: 1,
|
||||
sortOrder: 0,
|
||||
isRefund: 0,
|
||||
...STAT_DEFAULTS,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -108,27 +136,31 @@ async function handleSubmit() {
|
||||
await formRef.value?.validate();
|
||||
loading.value = true;
|
||||
|
||||
const dims = {
|
||||
includeSalesAmount: formData.value.includeSalesAmount!,
|
||||
includeProductCost: formData.value.includeProductCost!,
|
||||
includeFreightCost: formData.value.includeFreightCost!,
|
||||
includeOtherCost: formData.value.includeOtherCost!,
|
||||
includeRefund: formData.value.includeRefund!,
|
||||
};
|
||||
|
||||
if (isEdit.value && currentRecord.value) {
|
||||
// 更新订单状态
|
||||
const updateData: OrderStatusDTO.Update = {
|
||||
statusName: formData.value.statusName!,
|
||||
description: formData.value.description,
|
||||
color: formData.value.color,
|
||||
autoStatistics: formData.value.autoStatistics!,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
isRefund: formData.value.isRefund,
|
||||
...dims,
|
||||
};
|
||||
await updateOrderStatusApi(currentRecord.value.id, updateData);
|
||||
message.success('更新订单状态成功');
|
||||
} else {
|
||||
// 创建订单状态
|
||||
const createData: OrderStatusDTO.Create = {
|
||||
statusName: formData.value.statusName!,
|
||||
description: formData.value.description,
|
||||
color: formData.value.color,
|
||||
autoStatistics: formData.value.autoStatistics!,
|
||||
sortOrder: formData.value.sortOrder,
|
||||
isRefund: formData.value.isRefund,
|
||||
...dims,
|
||||
};
|
||||
await createOrderStatusApi(createData);
|
||||
message.success('创建订单状态成功');
|
||||
@@ -216,27 +248,58 @@ defineExpose({
|
||||
:min="0"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<Form.Item label="自动统计" name="autoStatistics">
|
||||
<div class="mb-2 text-sm font-medium text-foreground">
|
||||
统计维度(0/1)
|
||||
</div>
|
||||
<div class="grid grid-cols-2 gap-x-4 gap-y-2">
|
||||
<Form.Item label="计入销售额 / 单量" name="includeSalesAmount">
|
||||
<Switch
|
||||
v-model:checked="formData.autoStatistics"
|
||||
v-model:checked="formData.includeSalesAmount"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="参与"
|
||||
un-checked-children="不参与"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="计入商品成本" name="includeProductCost">
|
||||
<Switch
|
||||
v-model:checked="formData.includeProductCost"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="计入运费成本" name="includeFreightCost">
|
||||
<Switch
|
||||
v-model:checked="formData.includeFreightCost"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="计入其他成本" name="includeOtherCost">
|
||||
<Switch
|
||||
v-model:checked="formData.includeOtherCost"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="计入退款金额" name="includeRefund" class="col-span-2">
|
||||
<Switch
|
||||
v-model:checked="formData.includeRefund"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="计入"
|
||||
un-checked-children="不计入"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
<Form.Item label="是否为退款状态" name="isRefund">
|
||||
<Switch
|
||||
v-model:checked="formData.isRefund"
|
||||
:checked-value="1"
|
||||
:un-checked-value="0"
|
||||
checked-children="是"
|
||||
un-checked-children="否"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
+295
-210
@@ -1,294 +1,379 @@
|
||||
<script lang="ts" setup>
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref } from 'vue';
|
||||
import { Waterfall } from 'vue-waterfall-plugin-next';
|
||||
import 'vue-waterfall-plugin-next/dist/style.css';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, message, Popconfirm, Space, Switch, Tag } from 'ant-design-vue';
|
||||
import { Button, Card, Empty, message, Spin } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
deleteOrderStatusApi,
|
||||
getAllOrderStatusListApi,
|
||||
patchOrderStatusApi,
|
||||
} from '#/api/ecommerce/order-status';
|
||||
|
||||
import OrderStatusCard from './components/OrderStatusCard.vue';
|
||||
import OrderStatusFormModal from './components/OrderStatusFormModal.vue';
|
||||
|
||||
defineOptions({ name: 'OrderStatusConfig' });
|
||||
|
||||
// 创建图标组件
|
||||
/** 列表与筛选统一为 0 | 1,避免接口字符串与 Switch 受控值不一致 */
|
||||
function dim01(v: unknown): 0 | 1 {
|
||||
if (v === 1 || v === '1' || v === true) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function normalizeOrderStatus(s: OrderStatusVO.Info): OrderStatusVO.Info {
|
||||
return {
|
||||
...s,
|
||||
includeSalesAmount: dim01(s.includeSalesAmount),
|
||||
includeProductCost: dim01(s.includeProductCost),
|
||||
includeFreightCost: dim01(s.includeFreightCost),
|
||||
includeOtherCost: dim01(s.includeOtherCost),
|
||||
includeRefund: dim01(s.includeRefund),
|
||||
};
|
||||
}
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const orderStatusFormModalRef = ref();
|
||||
const waterfallRef = ref();
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
width: 80,
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
title: '状态名称',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'statusName' },
|
||||
},
|
||||
{
|
||||
field: 'description',
|
||||
title: '状态描述',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
const searchForm = ref({
|
||||
statusName: '',
|
||||
includeSalesAmount: undefined as number | undefined,
|
||||
});
|
||||
|
||||
{
|
||||
title: '自动统计',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'autoStatistics' },
|
||||
},
|
||||
{
|
||||
title: '退款状态',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'refundStatus' },
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
field: 'updateTime',
|
||||
title: '更新时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 'auto',
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
rowConfig: { isHover: true },
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
pagerConfig: {
|
||||
enabled: false,
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const data = await getAllOrderStatusListApi();
|
||||
return {
|
||||
items: data,
|
||||
total: data.length,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取订单状态列表失败:', error);
|
||||
message.error('获取订单状态列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
const searchFormSubmitRef = ref<null | (() => Promise<unknown>)>(null);
|
||||
|
||||
const [SearchForm, formApi] = useVbenForm({
|
||||
commonConfig: {
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// 搜索表单配置
|
||||
const gridReloadRef = ref<(() => void) | null>(null);
|
||||
const formOptions = computed(() => ({
|
||||
handleReset: handleSearchFormReset,
|
||||
handleSubmit: handleSearchFormSubmit,
|
||||
layout: 'horizontal',
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入状态名称(回车搜索)',
|
||||
onPressEnter: () => gridReloadRef.value?.(),
|
||||
placeholder: '状态名称(回车搜索)',
|
||||
allowClear: true,
|
||||
onPressEnter: () => void searchFormSubmitRef.value?.(),
|
||||
},
|
||||
defaultValue: '',
|
||||
fieldName: 'statusName',
|
||||
label: '状态名称',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择是否自动统计',
|
||||
options: [
|
||||
{ label: '参与自动统计', value: 1 },
|
||||
{ label: '不参与自动统计', value: 0 },
|
||||
],
|
||||
placeholder: '是否计入销售额',
|
||||
allowClear: true,
|
||||
onChange: () => gridReloadRef.value?.(),
|
||||
options: [
|
||||
{ label: '计入销售额', value: 1 },
|
||||
{ label: '不计入销售额', value: 0 },
|
||||
],
|
||||
},
|
||||
fieldName: 'autoStatistics',
|
||||
label: '自动统计',
|
||||
fieldName: 'includeSalesAmount',
|
||||
label: '销售额统计',
|
||||
},
|
||||
],
|
||||
showCollapseButton: false,
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '订单状态配置',
|
||||
submitButtonOptions: {
|
||||
content: '搜索',
|
||||
},
|
||||
resetButtonOptions: {
|
||||
content: '重置',
|
||||
},
|
||||
submitOnEnter: true,
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2',
|
||||
});
|
||||
gridReloadRef.value = () => gridApi.reload();
|
||||
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
searchFormSubmitRef.value = () => formApi.validateAndSubmitForm();
|
||||
|
||||
async function handleSearchFormSubmit(values: Record<string, any>) {
|
||||
searchForm.value = {
|
||||
statusName: String(values.statusName ?? '').trim(),
|
||||
includeSalesAmount:
|
||||
values.includeSalesAmount === '' || values.includeSalesAmount === undefined
|
||||
? undefined
|
||||
: Number(values.includeSalesAmount),
|
||||
};
|
||||
}
|
||||
|
||||
async function handleSearchFormReset() {
|
||||
await formApi.resetForm();
|
||||
searchForm.value = {
|
||||
statusName: '',
|
||||
includeSalesAmount: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const loading = ref(false);
|
||||
const orderStatusList = ref<OrderStatusVO.Info[]>([]);
|
||||
|
||||
const displayList = computed(() => {
|
||||
let list = [...orderStatusList.value];
|
||||
const { statusName, includeSalesAmount } = searchForm.value;
|
||||
if (statusName) {
|
||||
list = list.filter((s) => s.statusName.includes(statusName));
|
||||
}
|
||||
if (includeSalesAmount === 0 || includeSalesAmount === 1) {
|
||||
list = list.filter((s) => dim01(s.includeSalesAmount) === includeSalesAmount);
|
||||
}
|
||||
list.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0));
|
||||
return list;
|
||||
});
|
||||
|
||||
async function loadOrderStatuses() {
|
||||
loading.value = true;
|
||||
try {
|
||||
const data = await getAllOrderStatusListApi();
|
||||
orderStatusList.value = (data || []).map(normalizeOrderStatus);
|
||||
} catch {
|
||||
message.error('获取订单状态列表失败');
|
||||
orderStatusList.value = [];
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 处理添加订单状态
|
||||
function handleAdd() {
|
||||
orderStatusFormModalRef.value?.open(false);
|
||||
}
|
||||
|
||||
// 处理编辑订单状态
|
||||
function handleEdit(record: OrderStatusVO.Info) {
|
||||
orderStatusFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
// 处理删除订单状态
|
||||
async function handleDelete(record: OrderStatusVO.Info) {
|
||||
try {
|
||||
await deleteOrderStatusApi(record.id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('删除订单状态失败:', error);
|
||||
message.error('删除订单状态失败');
|
||||
await loadOrderStatuses();
|
||||
await handleWaterfallLayout();
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 处理模态框成功
|
||||
function handleModalSuccess() {
|
||||
refreshTable();
|
||||
async function handleModalSuccess() {
|
||||
await loadOrderStatuses();
|
||||
await handleWaterfallLayout();
|
||||
}
|
||||
|
||||
// 处理自动统计开关切换
|
||||
async function handleAutoStatisticsChange(row: OrderStatusVO.Info, checked: any) {
|
||||
const val = !!checked;
|
||||
try {
|
||||
await patchOrderStatusApi(row.id, { autoStatistics: val ? 1 : 0 });
|
||||
message.success('更新成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('更新自动统计失败:', error);
|
||||
message.error('更新自动统计失败');
|
||||
refreshTable(); // 恢复原状态
|
||||
/** 用 PATCH 返回体就地更新一条,避免再请求列表;找不到 id 时再全量拉取 */
|
||||
async function mergeOrderStatusFromPatch(vo: OrderStatusVO.Info) {
|
||||
const n = normalizeOrderStatus(vo);
|
||||
const idx = orderStatusList.value.findIndex(
|
||||
(s) => Number(s.id) === Number(n.id),
|
||||
);
|
||||
if (idx === -1) {
|
||||
await loadOrderStatuses();
|
||||
return;
|
||||
}
|
||||
const next = [...orderStatusList.value];
|
||||
next[idx] = n;
|
||||
orderStatusList.value = next;
|
||||
}
|
||||
|
||||
// 处理退款状态开关切换
|
||||
async function handleIsRefundChange(row: OrderStatusVO.Info, checked: any) {
|
||||
const val = !!checked;
|
||||
try {
|
||||
await patchOrderStatusApi(row.id, { isRefund: val ? 1 : 0 });
|
||||
message.success('更新成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
console.error('更新退款状态失败:', error);
|
||||
message.error('更新退款状态失败');
|
||||
refreshTable(); // 恢复原状态
|
||||
async function handlePatched(vo?: OrderStatusVO.Info) {
|
||||
if (vo) {
|
||||
await mergeOrderStatusFromPatch(vo);
|
||||
} else {
|
||||
await loadOrderStatuses();
|
||||
}
|
||||
await handleWaterfallLayout();
|
||||
}
|
||||
|
||||
async function handleWaterfallLayout() {
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
waterfallRef.value?.renderer?.();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadOrderStatuses();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="订单状态配置" auto-content-height>
|
||||
<Page
|
||||
title="订单状态配置"
|
||||
auto-content-height
|
||||
content-class="flex min-h-0 flex-1 flex-col bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
header-class="order-status-page-header"
|
||||
>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理订单状态类型,包括状态名称、描述和自动统计
|
||||
<div class="text-foreground/80 mt-2 max-w-4xl">
|
||||
管理订单状态及五个统计维度:销售额/单量、商品成本、运费成本、其他成本、退款金额;仅开启的维度会进入全店/店铺/商品概览与导出等统计。
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon />
|
||||
添加状态
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 状态名称列(带颜色) -->
|
||||
<template #statusName="{ row }: { row: OrderStatusVO.Info }">
|
||||
<Tag
|
||||
v-if="row.color"
|
||||
:color="row.color"
|
||||
type="outline"
|
||||
class="font-bold"
|
||||
<div class="flex min-h-0 flex-1 flex-col dark:bg-[hsl(222.34deg_10.43%_12.27%)]">
|
||||
<div class="flex min-h-0 flex-1 flex-col">
|
||||
<Card
|
||||
class="order-status-search mb-4 shrink-0 rounded-2xl border border-slate-200 bg-white/90 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)] dark:shadow-none"
|
||||
:body-style="{ padding: '16px' }"
|
||||
>
|
||||
{{ row.statusName }}
|
||||
</Tag>
|
||||
<span v-else>{{ row.statusName }}</span>
|
||||
</template>
|
||||
<SearchForm />
|
||||
</Card>
|
||||
|
||||
<!-- 自动统计列 -->
|
||||
<template #autoStatistics="{ row }: { row: OrderStatusVO.Info }">
|
||||
<Switch
|
||||
:checked="row.autoStatistics === 1"
|
||||
size="small"
|
||||
@change="(checked) => handleAutoStatisticsChange(row, checked)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- 退款状态列 -->
|
||||
<template #refundStatus="{ row }: { row: OrderStatusVO.Info }">
|
||||
<Switch
|
||||
:checked="row.isRefund === 1"
|
||||
size="small"
|
||||
@change="(checked) => handleIsRefundChange(row, checked)"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这个订单状态吗?"
|
||||
@confirm="handleDelete(row)"
|
||||
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
||||
<Card
|
||||
class="order-status-grid flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-2xl border border-slate-200 bg-white/90 shadow-[0_4px_12px_rgba(0,0,0,0.03)] dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)] dark:shadow-none"
|
||||
:body-style="{
|
||||
padding: '16px',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
flex: '1 1 0',
|
||||
minHeight: 0,
|
||||
overflow: 'hidden',
|
||||
}"
|
||||
>
|
||||
<Button size="small" danger> 删除 </Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
<div class="mb-3 flex shrink-0 items-center justify-between gap-3">
|
||||
<span class="text-sm text-gray-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
共 {{ displayList.length }} 个状态(全部 {{ orderStatusList.length }} 个)
|
||||
</span>
|
||||
<Button type="primary" @click="handleAdd">
|
||||
<PlusIcon class="mr-2 h-4 w-4" />
|
||||
添加状态
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="order-status-scroll flex min-h-0 min-w-0 flex-1 flex-col overflow-y-auto"
|
||||
>
|
||||
<Spin :spinning="loading && orderStatusList.length === 0">
|
||||
<div
|
||||
v-if="!loading && displayList.length === 0"
|
||||
class="flex min-h-[200px] items-center justify-center py-8"
|
||||
>
|
||||
<Empty description="暂无订单状态" />
|
||||
</div>
|
||||
|
||||
<Waterfall
|
||||
v-else-if="displayList.length > 0"
|
||||
ref="waterfallRef"
|
||||
:list="displayList"
|
||||
row-key="id"
|
||||
:horizontalOrder="true"
|
||||
:width="420"
|
||||
:breakpoints="{
|
||||
2000: { rowPerView: 3 },
|
||||
1400: { rowPerView: 2 },
|
||||
900: { rowPerView: 2 },
|
||||
600: { rowPerView: 1 },
|
||||
}"
|
||||
:gutter="20"
|
||||
class="order-status-waterfall"
|
||||
>
|
||||
<template #default="{ item }">
|
||||
<div class="w-full pb-1">
|
||||
<OrderStatusCard
|
||||
:status="item as OrderStatusVO.Info"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@patched="(v) => handlePatched(v)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Waterfall>
|
||||
</Spin>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 订单状态表单模态框 -->
|
||||
<OrderStatusFormModal
|
||||
ref="orderStatusFormModalRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.order-status-waterfall {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
:deep(.order-status-page-header) {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
:deep(.order-status-page-header > div:first-child) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.order-status-page-header > div:last-child) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style>
|
||||
html.dark .order-status-search.ant-card,
|
||||
html.dark .order-status-grid.ant-card {
|
||||
background-color: hsl(var(--card)) !important;
|
||||
border-color: hsl(var(--border)) !important;
|
||||
}
|
||||
|
||||
html.dark .order-status-search.ant-card .ant-card-body,
|
||||
html.dark .order-status-grid.ant-card .ant-card-body {
|
||||
background-color: hsl(var(--card)) !important;
|
||||
}
|
||||
|
||||
html.dark .order-status-search .ant-form-item-label > label {
|
||||
color: hsl(var(--muted-foreground));
|
||||
}
|
||||
|
||||
html.dark .order-status-search .ant-input,
|
||||
html.dark .order-status-search .ant-input-affix-wrapper,
|
||||
html.dark .order-status-search .ant-select-selector {
|
||||
background-color: hsl(var(--input-background)) !important;
|
||||
border-color: hsl(var(--border)) !important;
|
||||
color: hsl(var(--foreground)) !important;
|
||||
}
|
||||
|
||||
html.dark .order-status-search .ant-btn-default {
|
||||
background-color: hsl(var(--secondary));
|
||||
border-color: hsl(var(--border));
|
||||
color: hsl(var(--foreground));
|
||||
}
|
||||
|
||||
html.dark .order-status-scroll .ant-empty-description {
|
||||
color: hsl(var(--muted-foreground));
|
||||
}
|
||||
|
||||
/* 订单状态卡片深色(与商品卡同思路) */
|
||||
html.dark .order-status-card {
|
||||
border-color: hsl(240deg 3.7% 22%) !important;
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
hsl(222.34deg 10.43% 14%) 0%,
|
||||
hsl(222.34deg 10.43% 12.27%) 100%
|
||||
) !important;
|
||||
box-shadow: 0 8px 24px rgb(0 0 0 / 35%) !important;
|
||||
}
|
||||
|
||||
html.dark .order-status-card .card-head {
|
||||
border-bottom-color: hsl(240deg 3.7% 22%) !important;
|
||||
background: linear-gradient(
|
||||
180deg,
|
||||
hsl(222deg 14% 16%) 0%,
|
||||
hsl(222.34deg 10.43% 12.27%) 100%
|
||||
) !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user