mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 19:09:19 +08:00
feat: 完善sku成本
This commit is contained in:
@@ -80,24 +80,3 @@ export async function getProductSkusByIdsApi(skuIds: number[]) {
|
||||
skuIds,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步 SKU 成本到历史订单(单个 SKU)
|
||||
*/
|
||||
export async function syncCostsToOrdersApi(data: ProductSkuDTO.SyncCost) {
|
||||
return requestClient.post<number>('/ec/product-sku/sync-costs-to-orders', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量同步 SKU 成本到历史订单
|
||||
*/
|
||||
export async function batchSyncCostsToOrdersApi(data: ProductSkuDTO.BatchSyncCost) {
|
||||
return requestClient.post<number>('/ec/product-sku/batch-sync-costs-to-orders', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计指定 SKU 与时间范围内将参与成本同步的订单数量
|
||||
*/
|
||||
export async function countOrdersForCostSyncApi(data: ProductSkuDTO.BatchSyncCost) {
|
||||
return requestClient.post<number>('/ec/product-sku/count-orders-for-cost-sync', data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import type { ProductSkuCostDTO, ProductSkuCostVO } from './types';
|
||||
import type { ProductSkuVO } from '#/api/ec/product/sku/types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 同步 SKU 成本到历史订单(单个 SKU)
|
||||
*/
|
||||
export async function syncCostsToOrdersApi(data: ProductSkuCostDTO.SyncCost) {
|
||||
return requestClient.post<number>('/ec/product/sku/cost/sync-to-orders', data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量同步 SKU 当前生效成本到历史订单
|
||||
*/
|
||||
export async function batchSyncCostsToOrdersApi(
|
||||
data: ProductSkuCostDTO.BatchSyncCost,
|
||||
) {
|
||||
return requestClient.post<number>(
|
||||
'/ec/product/sku/cost/batch-sync-to-orders',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计指定 SKU 与时间范围内将参与成本同步的订单数量
|
||||
*/
|
||||
export async function countOrdersForCostSyncApi(
|
||||
data: ProductSkuCostDTO.BatchSyncCost,
|
||||
) {
|
||||
return requestClient.post<number>(
|
||||
'/ec/product/sku/cost/count-orders-for-sync',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询 SKU 成本历史
|
||||
*/
|
||||
export async function listSkuCostsApi(skuId: number) {
|
||||
return requestClient.get<ProductSkuCostVO.History[]>(
|
||||
`/ec/product/sku/cost/${skuId}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SKU 调价(按生效日追加 / 同日纠错)
|
||||
*/
|
||||
export async function adjustSkuCostApi(
|
||||
skuId: number,
|
||||
data: ProductSkuCostDTO.AdjustCost,
|
||||
) {
|
||||
return requestClient.post<ProductSkuVO.Info>(
|
||||
`/ec/product/sku/cost/${skuId}`,
|
||||
data,
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* 商品 SKU 成本模块 API
|
||||
*/
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* SKU 成本相关 DTO
|
||||
*/
|
||||
export namespace ProductSkuCostDTO {
|
||||
/** 同步 SKU 成本到订单(单个 SKU) */
|
||||
export interface SyncCost {
|
||||
skuId: number;
|
||||
productCost: number;
|
||||
shippingCost?: number;
|
||||
otherCost?: number;
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}
|
||||
|
||||
/** 批量同步 SKU 成本到订单 */
|
||||
export interface BatchSyncCost {
|
||||
skuIds: number[];
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}
|
||||
|
||||
/** SKU 调价(按生效日) */
|
||||
export interface AdjustCost {
|
||||
/** 生效起始日 yyyy-MM-dd */
|
||||
effectiveFrom: string;
|
||||
productCost: number;
|
||||
shippingCost?: number;
|
||||
otherCost?: number;
|
||||
remark?: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* SKU 成本相关 VO
|
||||
*/
|
||||
export namespace ProductSkuCostVO {
|
||||
/** 成本历史条目 */
|
||||
export interface History {
|
||||
id: number;
|
||||
/** 生效起始日 yyyy-MM-dd */
|
||||
effectiveFrom: string;
|
||||
productCost: number;
|
||||
shippingCost?: number;
|
||||
otherCost?: number;
|
||||
remark?: string;
|
||||
createTime?: string;
|
||||
}
|
||||
}
|
||||
@@ -64,30 +64,4 @@ export namespace ProductSkuDTO {
|
||||
/** SKU 编码 */
|
||||
skuCode: string;
|
||||
}
|
||||
|
||||
/** 同步 SKU 成本到订单(单个 SKU) */
|
||||
export interface SyncCost {
|
||||
/** SKU ID */
|
||||
skuId: number;
|
||||
/** 商品成本 */
|
||||
productCost: number;
|
||||
/** 运费成本 */
|
||||
shippingCost?: number;
|
||||
/** 其他成本 */
|
||||
otherCost?: number;
|
||||
/** 订单开始时间 */
|
||||
startTime: string;
|
||||
/** 订单结束时间 */
|
||||
endTime: string;
|
||||
}
|
||||
|
||||
/** 批量同步 SKU 成本到订单 */
|
||||
export interface BatchSyncCost {
|
||||
/** SKU ID 列表 */
|
||||
skuIds: number[];
|
||||
/** 订单时间下限(含) */
|
||||
startTime: string;
|
||||
/** 订单时间上限(含) */
|
||||
endTime: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ export namespace ProductSkuVO {
|
||||
shippingCost?: number;
|
||||
/** 其他成本 */
|
||||
otherCost?: number;
|
||||
/** 当前成本生效起始日 yyyy-MM-dd */
|
||||
costEffectiveFrom?: string;
|
||||
/** 备注 */
|
||||
remark?: string;
|
||||
/** SKU 图 URL(系统文件或渠道外链) */
|
||||
|
||||
@@ -68,6 +68,8 @@ export namespace ProductVO {
|
||||
shippingCost?: number;
|
||||
/** 其他成本 */
|
||||
otherCost?: number;
|
||||
/** 当前成本生效起始日 yyyy-MM-dd */
|
||||
costEffectiveFrom?: string;
|
||||
/** 备注 */
|
||||
remark?: string;
|
||||
/** SKU 图 URL(系统文件或渠道外链) */
|
||||
|
||||
+4
-4
@@ -10,8 +10,8 @@ import { DatePicker, message } from 'ant-design-vue';
|
||||
import {
|
||||
batchSyncCostsToOrdersApi,
|
||||
countOrdersForCostSyncApi,
|
||||
getProductSkusByIdsApi,
|
||||
} from '#/api/ec/product/sku/apis';
|
||||
} from '#/api/ec/product/sku/cost';
|
||||
import { getProductSkusByIdsApi } from '#/api/ec/product/sku/apis';
|
||||
|
||||
defineOptions({ name: 'ProductCostSyncToOrdersModal' });
|
||||
|
||||
@@ -201,10 +201,10 @@ defineExpose({ open });
|
||||
<template v-if="costSyncModalEntry === 'after-save'">
|
||||
检测到
|
||||
<strong>{{ pendingCostChangedSkus.length }}</strong>
|
||||
个SKU的成本已更新,请勾选需要同步的SKU:
|
||||
个SKU的<strong>当前生效</strong>成本已写入,请勾选需要同步到订单的SKU:
|
||||
</template>
|
||||
<template v-else>
|
||||
将所选SKU<strong>当前</strong>的商品成本、运费、其他成本写入订单(会覆盖该时间范围内订单上的对应成本字段)。请勾选需要同步的SKU,共
|
||||
将所选SKU<strong>当前生效</strong>的商品成本、运费、其他成本写入订单(会覆盖该时间范围内订单上的对应成本字段)。请勾选需要同步的SKU,共
|
||||
<strong>{{ pendingCostChangedSkus.length }}</strong> 个:
|
||||
</template>
|
||||
</div>
|
||||
+19
-3
@@ -21,6 +21,7 @@ const router = useRouter();
|
||||
|
||||
const emit = defineEmits<{
|
||||
edit: [product: ProductVO.Info];
|
||||
manageCost: [product: ProductVO.Info];
|
||||
}>();
|
||||
|
||||
/** 金额展示 */
|
||||
@@ -75,7 +76,7 @@ const skuColumns = [
|
||||
title: '运费成本',
|
||||
dataIndex: 'shippingCost',
|
||||
key: 'shippingCost',
|
||||
width: 110,
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: ProductVO.SkuInfo }) =>
|
||||
formatCost(record.shippingCost),
|
||||
},
|
||||
@@ -83,10 +84,17 @@ const skuColumns = [
|
||||
title: '其他成本',
|
||||
dataIndex: 'otherCost',
|
||||
key: 'otherCost',
|
||||
width: 110,
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: ProductVO.SkuInfo }) =>
|
||||
formatCost(record.otherCost),
|
||||
},
|
||||
{
|
||||
title: '成本生效日',
|
||||
dataIndex: 'costEffectiveFrom',
|
||||
key: 'costEffectiveFrom',
|
||||
width: 120,
|
||||
customRender: ({ text }: { text?: string }) => text || '-',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
@@ -129,6 +137,13 @@ function handleEdit() {
|
||||
emit('edit', current);
|
||||
}
|
||||
|
||||
function handleManageCost() {
|
||||
if (!product.value) return;
|
||||
const current = product.value;
|
||||
modalApi.close();
|
||||
emit('manageCost', current);
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
@@ -195,7 +210,7 @@ defineExpose({
|
||||
row-key="id"
|
||||
size="small"
|
||||
bordered
|
||||
:scroll="{ x: 820 }"
|
||||
:scroll="{ x: 920 }"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -206,6 +221,7 @@ defineExpose({
|
||||
<ChartIcon class="mr-1 h-4 w-4" />
|
||||
经营统计
|
||||
</Button>
|
||||
<Button @click="handleManageCost">管理成本</Button>
|
||||
<Button type="primary" @click="handleEdit">
|
||||
<EditIcon class="mr-1 h-4 w-4" />
|
||||
编辑商品
|
||||
+77
-40
@@ -23,7 +23,8 @@ import { getCategoryTreeApi } from '#/api/ec/product/category';
|
||||
import { createProductApi, updateProductApi } from '#/api/ec/product';
|
||||
import { uploadFileToOss } from '#/utils/oss-upload';
|
||||
import CategoryFormModal from '#/views/ec/product/category/components/CategoryFormModal.vue';
|
||||
import ProductCostSyncToOrdersModal from '#/views/ec/product/components/ProductCostSyncToOrdersModal.vue';
|
||||
import ProductCostSyncToOrdersModal from './ProductCostSyncToOrdersModal.vue';
|
||||
import ProductSkuCostDrawer from './ProductSkuCostDrawer.vue';
|
||||
|
||||
interface Emits {
|
||||
(e: 'success'): void;
|
||||
@@ -60,6 +61,9 @@ const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
const productCostSyncModalRef = ref<InstanceType<
|
||||
typeof ProductCostSyncToOrdersModal
|
||||
> | null>(null);
|
||||
const productSkuCostDrawerRef = ref<InstanceType<
|
||||
typeof ProductSkuCostDrawer
|
||||
> | null>(null);
|
||||
|
||||
async function openSyncModal(skuIds: number[]) {
|
||||
await productCostSyncModalRef.value?.open(skuIds, {
|
||||
@@ -71,6 +75,15 @@ async function openSyncModal(skuIds: number[]) {
|
||||
});
|
||||
}
|
||||
|
||||
function openCostDrawer() {
|
||||
const product = currentProductData.value as ProductVO.Info | null;
|
||||
if (!product?.id) {
|
||||
message.warning('请先保存商品后再管理成本');
|
||||
return;
|
||||
}
|
||||
productSkuCostDrawerRef.value?.open(product);
|
||||
}
|
||||
|
||||
// 内部状态管理
|
||||
const isEdit = ref(false);
|
||||
const currentProductData = ref<null | Partial<ProductVO.Info> | ProductVO.Info>(
|
||||
@@ -152,6 +165,7 @@ const categoryTreeDropdownRender: DropdownRender = (opt) => {
|
||||
type SkuFormRow = ProductDTO.Sku & {
|
||||
_clientKey?: string;
|
||||
id?: number;
|
||||
costEffectiveFrom?: string;
|
||||
/** 已有图预览 URL(系统文件或渠道外链) */
|
||||
imageUrl?: string;
|
||||
/** 新选择待上传的文件 */
|
||||
@@ -217,6 +231,7 @@ function initFormData() {
|
||||
productCost: spec.productCost ?? 0,
|
||||
shippingCost: spec.shippingCost ?? 0,
|
||||
otherCost: spec.otherCost ?? 0,
|
||||
costEffectiveFrom: spec.costEffectiveFrom,
|
||||
remark: spec.remark || '',
|
||||
imageUrl: spec.imageUrl || '',
|
||||
});
|
||||
@@ -552,6 +567,44 @@ function clearSkuNewImage(record: SkuFormRow) {
|
||||
}
|
||||
|
||||
// 表格列配置
|
||||
function canEditSkuCost(record: SkuFormRow) {
|
||||
// 新建商品,或编辑时新增的 SKU,可填初始成本;已有 SKU 调价走成本抽屉
|
||||
return !isEdit.value || record.id == null;
|
||||
}
|
||||
|
||||
function renderCostCell(
|
||||
record: SkuFormRow,
|
||||
field: 'productCost' | 'shippingCost' | 'otherCost',
|
||||
placeholder: string,
|
||||
) {
|
||||
if (!canEditSkuCost(record)) {
|
||||
const amount = Number(record[field] ?? 0).toFixed(2);
|
||||
const from = record.costEffectiveFrom
|
||||
? `自 ${record.costEffectiveFrom}`
|
||||
: '';
|
||||
return h(
|
||||
'div',
|
||||
{ class: 'text-xs leading-tight text-slate-700 dark:text-slate-200' },
|
||||
[
|
||||
h('div', `¥${amount}`),
|
||||
from
|
||||
? h('div', { class: 'text-[11px] text-slate-400' }, from)
|
||||
: null,
|
||||
],
|
||||
);
|
||||
}
|
||||
return h(InputNumber, {
|
||||
value: record[field] ?? 0,
|
||||
placeholder,
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record[field] = value ?? 0;
|
||||
},
|
||||
} as any);
|
||||
}
|
||||
|
||||
const skuColumns = [
|
||||
{
|
||||
title: '图片',
|
||||
@@ -670,67 +723,34 @@ const skuColumns = [
|
||||
title: '商品成本',
|
||||
dataIndex: 'productCost',
|
||||
key: 'productCost',
|
||||
width: 100,
|
||||
width: 110,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: SkuFormRow;
|
||||
}) => {
|
||||
return h(InputNumber, {
|
||||
value: record.productCost,
|
||||
placeholder: '商品成本',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record.productCost = value ?? 0;
|
||||
},
|
||||
} as any);
|
||||
},
|
||||
}) => renderCostCell(record, 'productCost', '商品成本'),
|
||||
},
|
||||
{
|
||||
title: '运费成本',
|
||||
dataIndex: 'shippingCost',
|
||||
key: 'shippingCost',
|
||||
width: 90,
|
||||
width: 100,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: SkuFormRow;
|
||||
}) => {
|
||||
return h(InputNumber, {
|
||||
value: record.shippingCost ?? 0,
|
||||
placeholder: '运费',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record.shippingCost = value ?? 0;
|
||||
},
|
||||
} as any);
|
||||
},
|
||||
}) => renderCostCell(record, 'shippingCost', '运费'),
|
||||
},
|
||||
{
|
||||
title: '其他成本',
|
||||
dataIndex: 'otherCost',
|
||||
key: 'otherCost',
|
||||
width: 90,
|
||||
width: 100,
|
||||
customRender: ({
|
||||
record,
|
||||
}: {
|
||||
record: SkuFormRow;
|
||||
}) => {
|
||||
return h(InputNumber, {
|
||||
value: record.otherCost ?? 0,
|
||||
placeholder: '其他',
|
||||
min: 0,
|
||||
precision: 2,
|
||||
style: { width: '100%' },
|
||||
'onUpdate:value': (value: null | number) => {
|
||||
record.otherCost = value ?? 0;
|
||||
},
|
||||
} as any);
|
||||
},
|
||||
}) => renderCostCell(record, 'otherCost', '其他'),
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
@@ -966,6 +986,13 @@ onUnmounted(() => {
|
||||
</template>
|
||||
{{ showSkus ? '收起 SKU' : '添加 SKU' }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="isEdit && currentProductData?.id"
|
||||
type="link"
|
||||
@click="openCostDrawer"
|
||||
>
|
||||
管理成本
|
||||
</Button>
|
||||
</Space>
|
||||
<Button v-if="showSkus" type="primary" @click="addSku">
|
||||
<template #icon>
|
||||
@@ -974,6 +1001,12 @@ onUnmounted(() => {
|
||||
添加 SKU
|
||||
</Button>
|
||||
</div>
|
||||
<p
|
||||
v-if="isEdit && showSkus"
|
||||
class="text-xs text-slate-400"
|
||||
>
|
||||
已有 SKU 的成本只读;调价请点「管理成本」。新增 SKU 仍可填初始成本。
|
||||
</p>
|
||||
|
||||
<div
|
||||
v-if="showSkus"
|
||||
@@ -1000,6 +1033,10 @@ onUnmounted(() => {
|
||||
</Modal>
|
||||
|
||||
<ProductCostSyncToOrdersModal ref="productCostSyncModalRef" />
|
||||
<ProductSkuCostDrawer
|
||||
ref="productSkuCostDrawerRef"
|
||||
@success="emit('success')"
|
||||
/>
|
||||
|
||||
<CategoryFormModal ref="categoryFormModalRef" @success="reloadCategoryTree" />
|
||||
</template>
|
||||
+321
@@ -0,0 +1,321 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ProductVO } from '#/api/ec/product/types';
|
||||
import type { ProductSkuCostVO } from '#/api/ec/product/sku/cost/types';
|
||||
|
||||
import { computed, reactive, ref, watch } from 'vue';
|
||||
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
DatePicker,
|
||||
Drawer,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
message,
|
||||
Space,
|
||||
Table,
|
||||
Typography,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs, { type Dayjs } from 'dayjs';
|
||||
|
||||
import { adjustSkuCostApi, listSkuCostsApi } from '#/api/ec/product/sku/cost';
|
||||
|
||||
import ProductCostSyncToOrdersModal from './ProductCostSyncToOrdersModal.vue';
|
||||
|
||||
defineOptions({ name: 'ProductSkuCostDrawer' });
|
||||
|
||||
const emit = defineEmits<{
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
const openFlag = ref(false);
|
||||
const productName = ref('');
|
||||
const skus = ref<ProductVO.SkuInfo[]>([]);
|
||||
const selectedSkuId = ref<number | null>(null);
|
||||
const history = ref<ProductSkuCostVO.History[]>([]);
|
||||
const historyLoading = ref(false);
|
||||
const saving = ref(false);
|
||||
|
||||
const formState = reactive({
|
||||
effectiveFrom: dayjs() as Dayjs,
|
||||
productCost: 0 as number,
|
||||
shippingCost: 0 as number,
|
||||
otherCost: 0 as number,
|
||||
remark: '',
|
||||
});
|
||||
|
||||
const costSyncModalRef = ref<InstanceType<
|
||||
typeof ProductCostSyncToOrdersModal
|
||||
> | null>(null);
|
||||
|
||||
const selectedSku = computed(() =>
|
||||
skus.value.find((s) => s.id === selectedSkuId.value) ?? null,
|
||||
);
|
||||
|
||||
const historyColumns = [
|
||||
{
|
||||
title: '生效日',
|
||||
dataIndex: 'effectiveFrom',
|
||||
key: 'effectiveFrom',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
title: '商品成本',
|
||||
dataIndex: 'productCost',
|
||||
key: 'productCost',
|
||||
width: 100,
|
||||
customRender: ({ text }: { text?: number }) =>
|
||||
`¥${Number(text ?? 0).toFixed(2)}`,
|
||||
},
|
||||
{
|
||||
title: '运费',
|
||||
dataIndex: 'shippingCost',
|
||||
key: 'shippingCost',
|
||||
width: 90,
|
||||
customRender: ({ text }: { text?: number }) =>
|
||||
`¥${Number(text ?? 0).toFixed(2)}`,
|
||||
},
|
||||
{
|
||||
title: '其他',
|
||||
dataIndex: 'otherCost',
|
||||
key: 'otherCost',
|
||||
width: 90,
|
||||
customRender: ({ text }: { text?: number }) =>
|
||||
`¥${Number(text ?? 0).toFixed(2)}`,
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
ellipsis: true,
|
||||
customRender: ({ text }: { text?: string }) => text || '—',
|
||||
},
|
||||
];
|
||||
|
||||
function formatMoney(v?: number) {
|
||||
return `¥${Number(v ?? 0).toFixed(2)}`;
|
||||
}
|
||||
|
||||
function fillFormFromSku(sku: ProductVO.SkuInfo | null) {
|
||||
formState.effectiveFrom = dayjs();
|
||||
formState.productCost = Number(sku?.productCost ?? 0);
|
||||
formState.shippingCost = Number(sku?.shippingCost ?? 0);
|
||||
formState.otherCost = Number(sku?.otherCost ?? 0);
|
||||
formState.remark = '';
|
||||
}
|
||||
|
||||
async function loadHistory(skuId: number) {
|
||||
historyLoading.value = true;
|
||||
try {
|
||||
history.value = (await listSkuCostsApi(skuId)) ?? [];
|
||||
} catch {
|
||||
history.value = [];
|
||||
message.error('加载成本历史失败');
|
||||
} finally {
|
||||
historyLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch(selectedSkuId, (id) => {
|
||||
const sku = skus.value.find((s) => s.id === id) ?? null;
|
||||
fillFormFromSku(sku);
|
||||
if (id != null) {
|
||||
void loadHistory(id);
|
||||
} else {
|
||||
history.value = [];
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 打开成本管理抽屉
|
||||
*/
|
||||
function open(product: ProductVO.Info, preferredSkuId?: number) {
|
||||
productName.value = product.name ?? '';
|
||||
skus.value = [...(product.skus ?? [])];
|
||||
const firstId =
|
||||
preferredSkuId ??
|
||||
(skus.value[0]?.id != null ? Number(skus.value[0].id) : null);
|
||||
selectedSkuId.value = firstId;
|
||||
if (firstId != null) {
|
||||
const sku = skus.value.find((s) => s.id === firstId) ?? null;
|
||||
fillFormFromSku(sku);
|
||||
void loadHistory(firstId);
|
||||
} else {
|
||||
fillFormFromSku(null);
|
||||
history.value = [];
|
||||
}
|
||||
openFlag.value = true;
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
if (selectedSkuId.value == null) {
|
||||
message.warning('请先选择 SKU');
|
||||
return;
|
||||
}
|
||||
if (!formState.effectiveFrom) {
|
||||
message.warning('请选择生效起始日');
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
const vo = await adjustSkuCostApi(selectedSkuId.value, {
|
||||
effectiveFrom: formState.effectiveFrom.format('YYYY-MM-DD'),
|
||||
productCost: formState.productCost ?? 0,
|
||||
shippingCost: formState.shippingCost ?? 0,
|
||||
otherCost: formState.otherCost ?? 0,
|
||||
remark: formState.remark?.trim() || undefined,
|
||||
});
|
||||
const idx = skus.value.findIndex((s) => s.id === selectedSkuId.value);
|
||||
if (idx >= 0 && vo) {
|
||||
skus.value[idx] = {
|
||||
...skus.value[idx]!,
|
||||
productCost: Number(vo.productCost ?? 0),
|
||||
shippingCost: Number(vo.shippingCost ?? 0),
|
||||
otherCost: Number(vo.otherCost ?? 0),
|
||||
costEffectiveFrom: vo.costEffectiveFrom,
|
||||
};
|
||||
}
|
||||
await loadHistory(selectedSkuId.value);
|
||||
emit('success');
|
||||
if (vo?.costChanged) {
|
||||
message.success('调价已保存');
|
||||
void costSyncModalRef.value?.open([selectedSkuId.value], {
|
||||
entry: 'manual',
|
||||
});
|
||||
} else {
|
||||
message.info('成本未变化,未写入新记录');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleSyncCurrent() {
|
||||
if (selectedSkuId.value == null) {
|
||||
message.warning('请先选择 SKU');
|
||||
return;
|
||||
}
|
||||
void costSyncModalRef.value?.open([selectedSkuId.value], { entry: 'manual' });
|
||||
}
|
||||
|
||||
defineExpose({ open });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Drawer
|
||||
v-model:open="openFlag"
|
||||
:title="`成本管理${productName ? ` · ${productName}` : ''}`"
|
||||
width="720"
|
||||
destroy-on-close
|
||||
:mask-closable="true"
|
||||
>
|
||||
<Alert
|
||||
type="info"
|
||||
show-icon
|
||||
class="mb-4"
|
||||
message="取某日成本 = 该 SKU 下 effective_from ≤ 业务日且最大的一条;同日再次保存会覆盖当日记录。"
|
||||
/>
|
||||
|
||||
<div v-if="skus.length === 0" class="py-10 text-center text-slate-400">
|
||||
该商品暂无 SKU,请先在编辑商品中添加
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<Typography.Title :level="5" class="!mb-2">选择 SKU</Typography.Title>
|
||||
<div class="mb-4 flex max-h-40 flex-col gap-1 overflow-y-auto">
|
||||
<button
|
||||
v-for="sku in skus"
|
||||
:key="sku.id"
|
||||
type="button"
|
||||
class="flex w-full flex-col rounded-lg border px-3 py-2 text-left text-sm transition-colors"
|
||||
:class="
|
||||
selectedSkuId === sku.id
|
||||
? 'border-blue-400 bg-blue-50 dark:border-blue-500 dark:bg-blue-950/40'
|
||||
: 'border-slate-200 hover:bg-slate-50 dark:border-[hsl(240deg_3.7%_22%)] dark:hover:bg-[hsl(240deg_3.7%_18%)]'
|
||||
"
|
||||
@click="selectedSkuId = sku.id"
|
||||
>
|
||||
<span class="font-medium text-slate-800 dark:text-slate-100">
|
||||
{{ sku.name || '未命名' }}
|
||||
<span class="ml-1 font-normal text-slate-500">{{ sku.skuCode || '无编码' }}</span>
|
||||
</span>
|
||||
<span class="mt-0.5 text-xs text-slate-500">
|
||||
当前 {{ formatMoney(sku.productCost) }} /
|
||||
{{ formatMoney(sku.shippingCost) }} /
|
||||
{{ formatMoney(sku.otherCost) }}
|
||||
<template v-if="sku.costEffectiveFrom">
|
||||
· 自 {{ sku.costEffectiveFrom }}
|
||||
</template>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<Typography.Title :level="5" class="!mb-2">调价</Typography.Title>
|
||||
<Form layout="vertical" class="mb-2">
|
||||
<Form.Item label="生效起始日" required>
|
||||
<DatePicker
|
||||
v-model:value="formState.effectiveFrom"
|
||||
class="w-full"
|
||||
format="YYYY-MM-DD"
|
||||
:allow-clear="false"
|
||||
/>
|
||||
</Form.Item>
|
||||
<div class="grid grid-cols-3 gap-3">
|
||||
<Form.Item label="商品成本">
|
||||
<InputNumber
|
||||
v-model:value="formState.productCost"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
class="w-full"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="运费成本">
|
||||
<InputNumber
|
||||
v-model:value="formState.shippingCost"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
class="w-full"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="其他成本">
|
||||
<InputNumber
|
||||
v-model:value="formState.otherCost"
|
||||
:min="0"
|
||||
:precision="2"
|
||||
class="w-full"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
<Form.Item label="备注">
|
||||
<Input
|
||||
v-model:value="formState.remark"
|
||||
placeholder="调价原因(可选)"
|
||||
allow-clear
|
||||
/>
|
||||
</Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" :loading="saving" @click="handleSave">
|
||||
保存调价
|
||||
</Button>
|
||||
<Button @click="handleSyncCurrent">同步当前成本到订单</Button>
|
||||
</Space>
|
||||
</Form>
|
||||
|
||||
<Typography.Title :level="5" class="!mb-2 !mt-6">成本历史</Typography.Title>
|
||||
<Table
|
||||
size="small"
|
||||
:loading="historyLoading"
|
||||
:columns="historyColumns"
|
||||
:data-source="history"
|
||||
:pagination="false"
|
||||
row-key="id"
|
||||
:scroll="{ y: 240 }"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<ProductCostSyncToOrdersModal ref="costSyncModalRef" />
|
||||
</Drawer>
|
||||
</template>
|
||||
+19
-1
@@ -17,12 +17,14 @@ import { deleteProductApi, getProductPageApi } from '#/api/ec/product';
|
||||
|
||||
import ProductDetailModal from './components/ProductDetailModal.vue';
|
||||
import ProductFormModal from './components/ProductFormModal.vue';
|
||||
import ProductSkuCostDrawer from './components/ProductSkuCostDrawer.vue';
|
||||
|
||||
defineOptions({ name: 'ProductManagement' });
|
||||
|
||||
const PlusIcon = createIconifyIcon('lucide:plus');
|
||||
const ChartIcon = createIconifyIcon('lucide:line-chart');
|
||||
const EditIcon = createIconifyIcon('lucide:square-pen');
|
||||
const CoinsIcon = createIconifyIcon('lucide:coins');
|
||||
const ImageIcon = createIconifyIcon('lucide:image');
|
||||
|
||||
const router = useRouter();
|
||||
@@ -33,6 +35,9 @@ const productFormModalRef = ref<InstanceType<typeof ProductFormModal> | null>(
|
||||
const productDetailModalRef = ref<InstanceType<typeof ProductDetailModal> | null>(
|
||||
null,
|
||||
);
|
||||
const productSkuCostDrawerRef = ref<InstanceType<
|
||||
typeof ProductSkuCostDrawer
|
||||
> | null>(null);
|
||||
|
||||
/** 列表行内最多展示的 SKU 编码标签数 */
|
||||
const MAX_SKU_CODE_TAGS = 4;
|
||||
@@ -107,7 +112,7 @@ const gridOptions: VxeGridProps<ProductVO.Info> = {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
minWidth: 260,
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
@@ -281,6 +286,10 @@ function handleEdit(record: ProductVO.Info) {
|
||||
productFormModalRef.value?.open(true, record);
|
||||
}
|
||||
|
||||
function handleCost(record: ProductVO.Info) {
|
||||
productSkuCostDrawerRef.value?.open(record);
|
||||
}
|
||||
|
||||
/** 打开商品详情模态框 */
|
||||
function openProductDetail(record: ProductVO.Info) {
|
||||
productDetailModalRef.value?.open(record);
|
||||
@@ -392,6 +401,10 @@ function handleDetailEdit(record: ProductVO.Info) {
|
||||
<EditIcon class="mr-0.5 h-3.5 w-3.5" />
|
||||
编辑
|
||||
</Button>
|
||||
<Button type="link" size="small" @click="handleCost(row)">
|
||||
<CoinsIcon class="mr-0.5 h-3.5 w-3.5" />
|
||||
成本
|
||||
</Button>
|
||||
<Button type="link" size="small" @click="goToOverview(row)">
|
||||
<ChartIcon class="mr-0.5 h-3.5 w-3.5" />
|
||||
统计
|
||||
@@ -412,6 +425,11 @@ function handleDetailEdit(record: ProductVO.Info) {
|
||||
<ProductDetailModal
|
||||
ref="productDetailModalRef"
|
||||
@edit="handleDetailEdit"
|
||||
@manage-cost="handleCost"
|
||||
/>
|
||||
<ProductSkuCostDrawer
|
||||
ref="productSkuCostDrawerRef"
|
||||
@success="handleModalSuccess"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user