feat: recycle system

This commit is contained in:
Timi
2026-11-12 16:51:57 +08:00
parent b1ba681042
commit 7e221e745a
90 changed files with 5981 additions and 3542 deletions
+99 -115
View File
@@ -34,7 +34,12 @@
@click="viewStock"
/>
</t-cell-group>
<t-cell-group title="SKU 列表" theme="card" class="skus" v-entrance-transition>
<t-cell-group
class="skus empty-cell-title-margin"
title="SKU 列表"
theme="card"
v-entrance-transition
>
<t-cell
class="sku"
v-for="sku in product.skuList || []"
@@ -58,26 +63,32 @@
<template #title>
<div class="title">
<h5 class="name" v-text="getSkuTitle(sku)" />
<t-tag
size="small"
variant="light-outline"
:theme="sku.status === 'ACTIVE' ? 'success' : 'warning'"
:content="sku.status === 'ACTIVE' ? '启用' : '停用'"
/>
</div>
</template>
<template #note>
<t-tag
size="small"
variant="light-outline"
:theme="sku.status === 'ACTIVE' ? 'success' : 'warning'"
:content="sku.status === 'ACTIVE' ? '启用' : '停用'"
/>
</template>
<template #description>
<div class="tags">
<t-tag
v-for="unit in sku.unitList || []"
:key="unit.id || unit.name"
size="small"
theme="primary"
variant="light-outline"
:content="`${unit.name}${unit.isBase ? '(基础)' : ''}`"
/>
<div class="sku-description">
<div class="tags">
<t-tag
v-for="unit in sku.unitList || []"
:key="unit.id || unit.name"
size="small"
theme="primary"
variant="light-outline"
:content="`${unit.name}${unit.isBase ? '(基础)' : ''}`"
/>
<t-tag
v-if="getYieldRowsForSku(sku).length"
size="small"
variant="light-outline"
:content="`产出 ${getYieldRowsForSku(sku).length} 个回收物`"
/>
</div>
</div>
</template>
</t-cell>
@@ -87,63 +98,24 @@
</div>
</main>
<bottom-popup
v-model="skuDetailVisible"
title="SKU 详情"
height="min(80vh, 48rem)"
left-button-text="关闭"
right-button-text=""
:z-index="skuDetailPopupZIndex"
:overlay-props="{ zIndex: skuDetailPopupZIndex - 1 }"
@left-button-click="closeSkuDetail"
>
<div v-if="selectedSku" class="sku-popup">
<t-cell-group>
<t-cell title="明细名称" :note="selectedSku.name || '未命名 SKU'" />
<t-cell title="SKU 编码" :note="selectedSku.code || '无编码'" />
<t-cell v-if="selectedSku.barcode" title="SKU 条码" :note="selectedSku.barcode" />
<t-cell title="库存管理" :note="selectedSku.stockEnabled ? '启用' : '关闭'" />
<t-cell title="允许小数数量" :note="selectedSku.allowDecimalQuantity ? '允许' : '不允许'" />
<t-cell v-if="selectedSku.stockEnabled" title="最低库存" :note="`${getProductQuantityText(selectedSku.minStockQuantity)} 基础单位`" />
<t-cell v-if="selectedSku.remark" title="备注" :note="Text.display(selectedSku.remark)" />
</t-cell-group>
<div class="media-wrap">
<attachment-selector
v-if="skuPhotoItemList.length"
:items="skuPhotoItemList"
title="SKU 图片"
readonly
/>
</div>
<div class="unit">
<div class="header">
<strong>销售单位</strong>
<span>采购、销售和库存操作共用</span>
</div>
<product-sku-unit-list v-if="selectedSku.unitList?.length" :unit-list="selectedSku.unitList" />
<center-tips v-else :content="'暂无销售单位'" />
</div>
</div>
</bottom-popup>
</div>
</template>
<script setup lang="ts">
import type { NavbarAction } from "@/types/NavbarAction.ts";
import { DialogPlugin } from "tdesign-mobile-vue";
import { BottomPopup } from "timi-tdesign-mobile";
import { useUserStore } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import RecycleAPI from "@/api/RecycleAPI";
import ProductProfile from "@/pages/product/component/ProductProfile.vue";
import ProductSkuUnitList from "@/pages/product/component/ProductSkuUnitList.vue";
import type { PhotoItem } from "@/types/Photo";
import type { Product, ProductSku } from "@/types/Product";
import type { RecycleProductYield } from "@/types/Recycle";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getErrorMessage } from "@/utils/error";
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
import { emitListDataChanged, events, isCurrentStoreEvent, listDataEventKeys, type ListDataChangedPayload } from "@/utils/listDataEvents";
import {
getProductPhotoURL,
getProductQuantityText,
getProductStatusText
} from "@/utils/product";
import { Message } from "@/utils/message";
@@ -173,7 +145,7 @@ function resolveId(): string {
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
useExpandToMaster({
path: "/management/products",
path: "/product/products",
id: () => resolveId()
});
/** 非空说明当前被内联在主从分栏的右栏里 */
@@ -184,9 +156,6 @@ const router = useRouter();
const userStore = useUserStore();
const product = ref<Product>();
const isLoading = ref(false);
const selectedSku = ref<ProductSku>();
const skuDetailVisible = ref(false);
const skuDetailPopupZIndex = 1000;
const attachmentItemList = computed<PhotoItem[]>(() => (product.value?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
@@ -195,14 +164,6 @@ const attachmentItemList = computed<PhotoItem[]>(() => (product.value?.attachmen
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const skuPhotoItemList = computed<PhotoItem[]>(() => (selectedSku.value?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
attachment: item,
attachType: item.attachType || "PHOTO",
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
const actionList = computed<NavbarAction[]>(() => {
const list: NavbarAction[] = [];
if (userStore.hasPermissions(permissionCodes.product.update)) {
@@ -226,6 +187,10 @@ async function load(): Promise<void> {
} finally {
isLoading.value = false;
}
// 没有回收配置权限时列表不展示,也就没有必要多打一次接口
if (canManageYield.value) {
await loadYieldList();
}
}
async function edit(): Promise<void> {
@@ -239,7 +204,7 @@ async function edit(): Promise<void> {
return;
}
await router.push(`/management/products/${product.value.id}/edit`);
await router.push(`/product/products/${product.value.id}/edit`);
}
function goBack(): void {
@@ -269,13 +234,52 @@ function getSkuTitle(sku: NonNullable<Product["skuList"]>[number]): string {
return sku.specSummary || sku.name || "未命名 SKU";
}
function openSkuDetail(sku: ProductSku): void {
selectedSku.value = sku;
skuDetailVisible.value = true;
async function openSkuDetail(sku: ProductSku): Promise<void> {
const productId = product.value?.id;
const skuId = sku.id;
if (!productId || !skuId) {
return;
}
if (pane) {
await router.push({
path: route.path,
query: {
...route.query,
skuProductId: productId,
skuId
}
});
return;
}
await router.push({
name: "ProductSkuDetail",
params: { productId, skuId },
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
function closeSkuDetail(): void {
skuDetailVisible.value = false;
// ---------- 产出回收物 ----------
const canManageYield = computed(() => userStore.hasPermissions(permissionCodes.recycleExchange.configManage));
const yieldRowList = ref<RecycleProductYield[]>([]);
let unregisterYieldChanged: (() => void) | undefined;
async function loadYieldList(): Promise<void> {
const id = product.value?.id;
if (!id) {
yieldRowList.value = [];
return;
}
try {
yieldRowList.value = await RecycleAPI.yieldProductList(id);
} catch (error) {
Message.error(getErrorMessage(error, "产出回收物加载失败"));
}
}
function getYieldRowsForSku(sku: ProductSku): RecycleProductYield[] {
const skuId = sku.id || "";
return yieldRowList.value.filter(row => row.skuId === skuId);
}
function getCurrentRouteDepth(): number {
@@ -335,7 +339,7 @@ function remove(): void {
pane.close();
return;
}
await router.replace("/management/products");
await router.replace("/product/products");
} catch (error) {
Message.error(getErrorMessage(error, "产品移除失败"));
} finally {
@@ -350,6 +354,11 @@ watch(() => [props.productId, route.params.id], async () => {
});
onMounted(async () => {
unregisterYieldChanged = events.register(listDataEventKeys.productYieldChanged, async (payload: ListDataChangedPayload) => {
if (isCurrentStoreEvent(payload) && payload.entityId === resolveId()) {
await loadYieldList();
}
});
try {
await load();
@@ -359,6 +368,11 @@ onMounted(async () => {
}
});
onUnmounted(() => {
unregisterYieldChanged?.();
unregisterYieldChanged = undefined;
});
</script>
<style scoped lang="less">
@@ -380,8 +394,10 @@ onMounted(async () => {
.title {
gap: .5rem;
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
.name {
margin: 0;
@@ -393,37 +409,13 @@ onMounted(async () => {
display: flex;
flex-wrap: wrap;
}
}
}
}
.sku-popup {
padding: 0 0 calc(1rem + env(safe-area-inset-bottom, 0px));
max-height: 100%;
overflow-y: auto;
.media-wrap {
margin: 0 1rem;
}
.unit {
margin-top: .75rem;
border-top: 1px solid var(--td-component-border);
.header {
gap: .5rem;
display: flex;
padding: .75rem 1rem .5rem;
align-items: baseline;
justify-content: space-between;
span {
color: var(--td-text-color-secondary);
font-size: .75rem;
text-align: right;
.sku-description {
gap: .375rem;
display: flex;
flex-direction: column;
}
}
}
}
@@ -436,12 +428,4 @@ onMounted(async () => {
}
:global(html.theme-dark) .sku-popup {
.sku-spec-panel,
.sku-spec-item,
.unit-item {
background: rgba(148, 163, 184, .12);
}
}
</style>
+3 -3
View File
@@ -265,7 +265,7 @@ const routeId = computed(() => props.productId || String(route.params.id || ""))
// 竖屏整页编辑转横屏:回到分栏,并用 view=edit 让列表页把右栏还原成编辑
useExpandToMaster({
path: "/management/products",
path: "/product/products",
id: () => routeId.value,
query: { view: "edit" }
});
@@ -1087,7 +1087,7 @@ async function save(): Promise<void> {
emitListDataChanged(listDataEventKeys.productChanged, productId);
emitListDataChanged(listDataEventKeys.productStockChanged, productId);
Message.success("产品已创建");
await router.replace(`/management/products/${productId}`);
await router.replace(`/product/products/${productId}`);
return;
}
const productId = form.id;
@@ -1112,7 +1112,7 @@ async function save(): Promise<void> {
pane.close(true);
return;
}
await router.replace(`/management/products/${productId}`);
await router.replace(`/product/products/${productId}`);
} catch (error) {
Message.error(getErrorMessage(error, "产品保存失败,请检查 SKU 编码、规格组合和单位配置"));
} finally {
+46 -7
View File
@@ -24,7 +24,7 @@
class="list"
:split="isWide"
:selected="!!selectedId"
:direction="paneDirection"
:direction="paneTransitionDirection"
>
<template #master>
<t-pull-down-refresh
@@ -115,7 +115,13 @@
</t-pull-down-refresh>
</template>
<template #detail>
<product-edit v-if="selectedId === createPaneId" :key="createPaneId" />
<product-sku-detail
v-if="showingSkuDetail"
:key="`${skuDetailProductId}-${skuDetailId}`"
:product-id="skuDetailProductId"
:sku-id="skuDetailId"
/>
<product-edit v-else-if="selectedId === createPaneId" :key="createPaneId" />
<product-edit
v-else-if="editing"
:key="`edit-${selectedId}`"
@@ -135,9 +141,10 @@
<script setup lang="ts">
import { type DropdownValue } from "tdesign-mobile-vue";
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
import { MasterDetailPage, useMasterDetailPane, type PaneDirection } from "timi-tdesign-mobile";
import ProductDetail from "@/pages/product/ProductDetail.vue";
import ProductEdit from "@/pages/product/ProductEdit.vue";
import ProductSkuDetail from "@/pages/product/ProductSkuDetail.vue";
import { useUserStore } from "timi-web-api";
import { onBeforeRouteLeave } from "vue-router";
import ProductAPI from "@/api/ProductAPI";
@@ -158,10 +165,32 @@ const route = useRoute();
const createPaneId = "__create__";
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
useMasterDetailPane({
path: "/management/products",
detail: id => id === createPaneId ? "/management/products/create" : `/management/products/${id}`,
edit: id => `/management/products/${id}/edit`
path: "/product/products",
detail: id => id === createPaneId ? "/product/products/create" : `/product/products/${id}`,
edit: id => `/product/products/${id}/edit`
});
const skuDetailProductId = computed(() => String(route.query.skuProductId || ""));
const skuDetailId = computed(() => String(route.query.skuId || ""));
const showingSkuDetail = computed(() => !!skuDetailId.value && skuDetailProductId.value === selectedId.value);
const paneTransitionDirection = ref<PaneDirection>(paneDirection.value || "forward");
watch(paneDirection, direction => {
if (direction) {
paneTransitionDirection.value = direction;
}
});
watch([skuDetailProductId, skuDetailId], ([productId, skuId], [previousProductId, previousSkuId]) => {
const wasSkuDetail = !!previousSkuId && previousProductId === selectedId.value;
const isSkuDetail = !!skuId && productId === selectedId.value;
if (!wasSkuDetail && isSkuDetail) {
paneTransitionDirection.value = "forward";
} else if (wasSkuDetail && !isSkuDetail) {
paneTransitionDirection.value = "back";
} else if (wasSkuDetail && isSkuDetail && previousSkuId !== skuId) {
paneTransitionDirection.value = "none";
}
});
const productListRef = ref<ComponentPublicInstance | null>(null);
const userStore = useUserStore();
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.product.create));
@@ -419,10 +448,20 @@ async function toCreate(): Promise<void> {
openDetail(createPaneId);
return;
}
await router.push("/management/products/create");
await router.push("/product/products/create");
}
async function toDetail(item: Product): Promise<void> {
if (route.query.skuId || route.query.skuProductId) {
await router.replace({
path: route.path,
query: {
...route.query,
skuProductId: undefined,
skuId: undefined
}
});
}
openDetail(item.id || "");
}
+380
View File
@@ -0,0 +1,380 @@
<template>
<div class="tui-page-layout tui-navbar">
<t-navbar
fixed
:z-index="20"
:title="skuTitle"
left-arrow
@left-click="goBack"
/>
<main class="tui-page-content scroll column">
<div v-can="permissionCodes.product.read" class="product-sku-detail">
<t-loading v-if="isLoading" class="loading" size="32px" />
<template v-if="sku && product">
<t-cell-group theme="card" v-entrance-transition>
<t-cell title="所属产品" :note="product.name || '未命名产品'" />
<t-cell title="SKU 名称" :note="sku.name || '未命名 SKU'" />
<t-cell title="SKU 编码" :note="sku.code || '无编码'" />
<t-cell v-if="sku.barcode" title="SKU 条码" :note="sku.barcode" />
<t-cell title="状态" :note="getProductStatusText(sku.status)" />
<t-cell title="库存管理" :note="sku.stockEnabled ? '启用' : '关闭'" />
<t-cell title="允许小数数量" :note="sku.allowDecimalQuantity ? '允许' : '不允许'" />
<t-cell v-if="sku.stockEnabled" title="最低库存" :note="`${getProductQuantityText(sku.minStockQuantity)} 基础单位`" />
<t-cell v-if="sku.remark" title="备注" :note="Text.display(sku.remark)" />
<div v-if="skuPhotoItemList.length" class="attach-wrap bg-white">
<attachment-selector :items="skuPhotoItemList" title="SKU 图片" readonly />
</div>
</t-cell-group>
<product-sku-unit-list :unit-list="sku.unitList" />
<t-cell-group
v-if="canManageYield"
class="yields fix-last-cell-line empty-cell-title-margin"
theme="card"
title="产出回收物"
>
<t-swipe-cell
class="item"
v-for="row in yieldRowList"
:key="getYieldKey(row)"
>
<t-cell class="yield">
<template #leftIcon>
<t-image v-if="getYieldCoverId(row)" class="avatar" :src="getAttachmentReadURL(getYieldCoverId(row), 96)" :alt="row.recycleName || '回收物图片'" fit="cover" />
<div v-else class="avatar fallback" v-text="(row.recycleName || '产').slice(0, 1)" />
</template>
<template #title>
<div class="title">
<span v-text="row.recycleName || '未知回收物'"></span>
<div class="actions">
<template v-if="editingKey === getYieldKey(row)">
<t-button theme="primary" size="extra-small" :loading="saving" content="保存" @click.stop="saveYield(row)" />
<t-button size="extra-small" content="取消" :disabled="saving" @click.stop="cancelEdit" />
</template>
<t-button v-else theme="primary" size="extra-small" content="编辑" :disabled="!!editingKey || saving || yieldLoading" @click.stop="editYield(row)" />
</div>
</div>
</template>
<template #description>
<div class="editor">
<span>产出</span>
<t-stepper
:model-value="editingKey === getYieldKey(row) ? editingQuantity : row.quantityPerBase"
:integer="!row.allowDecimalQuantity"
:min="row.allowDecimalQuantity ? .001 : 1"
:max="Number.MAX_SAFE_INTEGER"
:step="row.allowDecimalQuantity ? .05 : 1"
size="large"
theme="outline"
:disabled="saving || editingKey !== getYieldKey(row)"
@update:model-value="editingQuantity = $event"
/>
<t-tag
variant="light"
:content="row.recycleUnit || '单位'"
/>
</div>
</template>
</t-cell>
<template #right>
<t-button v-if="draftKey !== getYieldKey(row)" theme="danger" :disabled="!!editingKey || saving" @click.stop="deleteYield(row)">删除</t-button>
</template>
</t-swipe-cell>
<t-cell
title="添加"
:disabled="yieldLoading || saving || !!editingKey"
arrow
@click="pickerVisible = true"
/>
<center-tips v-if="!yieldRowList.length" :content="yieldLoading ? '正在加载' : '该 SKU 不产出回收物'" />
</t-cell-group>
</template>
<center-tips v-if="!isLoading && !sku" :content="'SKU 不存在或已被移除'" />
</div>
</main>
<recycle-item-picker-popup v-model:visible="pickerVisible" title="选择产出物" manage empty-text="暂无回收物,可点击右上角新建" @select="selectItem" />
</div>
</template>
<script setup lang="ts">
import { DialogPlugin } from "tdesign-mobile-vue";
import { useUserStore } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import RecycleAPI from "@/api/RecycleAPI";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuUnitList from "@/pages/product/component/ProductSkuUnitList.vue";
import RecycleItemPickerPopup from "@/pages/recycle/components/RecycleItemPickerPopup.vue";
import type { PhotoItem } from "@/types/Photo";
import type { Product, ProductSku } from "@/types/Product";
import type { RecycleItem, RecycleProductYield } from "@/types/Recycle";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getErrorMessage } from "@/utils/error";
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
import { normalizePackageQuantity } from "@/utils/package";
import { getProductQuantityText, getProductStatusText } from "@/utils/product";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { Text } from "timi-web";
defineOptions({ name: "ProductSkuDetail" });
const props = defineProps<{
productId?: string;
skuId?: string;
}>();
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
function resolveProductId(): string {
return props.productId || String(route.params.productId || "");
}
function resolveSkuId(): string {
return props.skuId || String(route.params.skuId || "");
}
const product = ref<Product>();
const sku = ref<ProductSku>();
const isLoading = ref(false);
const skuTitle = computed(() => sku.value?.specSummary || sku.value?.name || "SKU 详情");
const skuPhotoItemList = computed<PhotoItem[]>(() => (sku.value?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
attachment: item,
attachType: item.attachType || "PHOTO",
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 90)
})));
async function goBack(): Promise<void> {
await router.back();
}
const canManageYield = computed(() => userStore.hasPermissions(permissionCodes.recycleExchange.configManage));
const yieldRowList = ref<RecycleProductYield[]>([]);
const yieldLoading = ref(false);
const pickerVisible = ref(false);
const editingKey = ref("");
const editingQuantity = ref<string | number>(1);
const draftKey = ref("");
const saving = ref(false);
async function load(): Promise<void> {
const productId = resolveProductId();
const skuId = resolveSkuId();
if (!productId || !skuId) {
return;
}
isLoading.value = true;
sku.value = undefined;
yieldRowList.value = [];
editingKey.value = "";
draftKey.value = "";
try {
const [productResult, skuResult] = await Promise.all([
ProductAPI.detail(productId),
ProductAPI.skuDetail(skuId)
]);
if (skuResult.productId && skuResult.productId !== productId) {
Message.error("SKU 与所属产品不匹配");
return;
}
product.value = productResult;
sku.value = skuResult;
if (canManageYield.value) {
await loadYieldList();
}
} catch (error) {
Message.error(getErrorMessage(error, "SKU 详情加载失败"));
} finally {
isLoading.value = false;
}
}
async function loadYieldList(): Promise<void> {
const skuId = sku.value?.id || resolveSkuId();
if (!skuId) {
yieldRowList.value = [];
return;
}
yieldLoading.value = true;
try {
const rowList = await RecycleAPI.yieldList(skuId);
yieldRowList.value = rowList.map(row => ({ ...row, skuId }));
} catch (error) {
Message.error(getErrorMessage(error, "产出回收物加载失败"));
} finally {
yieldLoading.value = false;
}
}
function getYieldCoverId(row: RecycleProductYield): string {
return row.attachmentList?.find(attachment => attachment.id && attachment.mimeType?.startsWith("image/"))?.id || "";
}
function getYieldKey(row: RecycleProductYield): string {
return `${row.skuId || ""}-${row.recycleItemId || ""}`;
}
function editYield(row: RecycleProductYield): void {
if (saving.value || editingKey.value) return;
editingKey.value = getYieldKey(row);
editingQuantity.value = row.quantityPerBase ?? 1;
}
function cancelEdit(): void {
if (draftKey.value) yieldRowList.value = yieldRowList.value.filter(row => getYieldKey(row) !== draftKey.value);
draftKey.value = "";
editingKey.value = "";
}
function selectItem(item: RecycleItem): void {
const skuId = sku.value?.id;
if (!skuId || !item.id) return;
if (yieldRowList.value.some(row => row.recycleItemId === item.id)) {
Message.warning("该产出关系已存在");
return;
}
const row: RecycleProductYield = {
skuId, recycleItemId: item.id, recycleName: item.name, recycleUnit: item.unitName,
attachmentList: item.attachmentList, allowDecimalQuantity: item.allowDecimalQuantity, quantityPerBase: "1"
};
yieldRowList.value.push(row);
draftKey.value = getYieldKey(row);
editYield(row);
}
function notifyYieldChange(): void {
const productId = product.value?.id || sku.value?.productId;
if (productId) emitListDataChanged(listDataEventKeys.productYieldChanged, productId);
}
async function saveYield(row: RecycleProductYield): Promise<void> {
const quantity = normalizePackageQuantity(editingQuantity.value);
if (!row.skuId || !row.recycleItemId || saving.value) return;
if (!quantity || quantity === "0") {
Message.warning("产出数量必须大于零,最多三位小数");
return;
}
saving.value = true;
try {
await RecycleAPI.yieldSave(row.skuId, row.recycleItemId, quantity);
draftKey.value = "";
editingKey.value = "";
Message.success("产出配置已保存");
notifyYieldChange();
await loadYieldList();
} catch (error) {
Message.error(getErrorMessage(error, "产出配置保存失败"));
} finally {
saving.value = false;
}
}
function deleteYield(row: RecycleProductYield): void {
if (!row.skuId || !row.recycleItemId || saving.value || editingKey.value) return;
const skuId = row.skuId;
const itemId = row.recycleItemId;
const dialog = DialogPlugin.confirm({
title: "移除产出回收物",
content: `移除后该 SKU 不再产出${row.recycleName || "该回收物"},已产生的额度仍会保留。确定移除?`,
cancelBtn: "取消",
confirmBtn: { content: "移除", theme: "danger" },
onConfirm: async () => {
dialog.destroy();
saving.value = true;
try {
await RecycleAPI.yieldDelete(skuId, itemId);
Message.success("产出回收物已移除");
notifyYieldChange();
await loadYieldList();
} catch (error) {
Message.error(getErrorMessage(error, "产出回收物移除失败"));
} finally {
saving.value = false;
}
}
});
}
watch(() => [props.productId, props.skuId, route.params.productId, route.params.skuId], async () => {
await load();
});
onMounted(async () => {
await load();
});
</script>
<style scoped lang="less">
.product-sku-detail {
gap: 1rem;
display: flex;
padding: 0 0 1rem;
flex-direction: column;
.attach-wrap {
padding: 1rem;
}
.unit {
.header {
gap: .5rem;
display: flex;
padding: .75rem 1rem .5rem;
align-items: baseline;
justify-content: space-between;
span {
color: var(--td-text-color-secondary);
font-size: .75rem;
text-align: right;
}
}
}
.yields {
--td-button-extra-small-height: 24px;
.item {
.yield {
.avatar {
width: 3.5rem;
height: 3.5rem;
}
.title {
gap: .5rem;
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
.actions {
gap: .5rem;
display: flex;
align-items: center;
}
}
.editor {
gap: .5rem;
display: flex;
align-items: center;
justify-content: end;
}
}
}
}
}
:deep(.avatar .t-image__img) {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: inherit;
}
</style>
+1 -1
View File
@@ -148,7 +148,7 @@ function resolveId(): string {
// 没带 productId(从别处跳进来)时不动,避免落到无效的列表路径
const masterProductId = props.productId || String(route.query.productId || "");
useExpandToMaster({
path: `/management/product-stocks/${masterProductId}/skus`,
path: `/product/product-stocks/${masterProductId}/skus`,
id: () => (masterProductId ? resolveId() : "")
});
@@ -171,7 +171,7 @@ function resolveId(): string {
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
useExpandToMaster({
path: "/management/product-stock-records",
path: "/product/product-stock-records",
id: () => resolveId()
});
/** 非空说明当前被内联在主从分栏的右栏里 */
@@ -270,7 +270,7 @@ async function toFulfillment(): Promise<void> {
return;
}
await router.push({
path: `/management/order-fulfillments/${relatedFulfillmentId.value}`,
path: `/product/order-fulfillments/${relatedFulfillmentId.value}`,
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
+2 -2
View File
@@ -240,8 +240,8 @@ const route = useRoute();
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里;库存流水没有内联编辑视图
const { selectedId, detailVersion, paneDirection, isWide, openDetail } = useMasterDetailPane({
path: "/management/product-stock-records",
detail: id => `/management/product-stock-records/${id}`
path: "/product/product-stock-records",
detail: id => `/product/product-stock-records/${id}`
});
const pageNavBarBackTo = ref<string>();
+2 -2
View File
@@ -160,9 +160,9 @@ const emptyText = computed(() => {
// ---------- 主从分栏 ----------
const { selectedId, detailVersion, paneDirection, isWide, openDetail } = useMasterDetailPane({
path: `/management/product-stocks/${productId.value}/skus`,
path: `/product/product-stocks/${productId.value}/skus`,
// 整页详情带上 productId,转回分栏时才知道该回到哪个产品的 SKU 列表
detail: id => `/management/product-stocks/${id}?productId=${encodeURIComponent(productId.value)}`
detail: id => `/product/product-stocks/${id}?productId=${encodeURIComponent(productId.value)}`
});
function getSkuPhotoURL(item: ProductStock): string {
@@ -94,10 +94,6 @@
</div>
</t-form>
<div class="unit">
<div class="header">
<strong>销售单位</strong>
<span>采购、销售和库存操作共用</span>
</div>
<product-sku-unit-list :unit-list="sku.unitList" />
<t-button
class="cell-button"
@@ -1,10 +1,14 @@
<template>
<t-cell-group
v-if="unitList.length"
class="items empty-cell-title-margin"
title="销售单位"
theme="card"
>
<template v-if="!unitList.length">
<center-tips content="暂无销售单位" />
</template>
<t-cell
v-else
v-for="unit in unitList"
:key="unit.id || unit.clientKey || unit.name"
class="item"
@@ -91,11 +95,6 @@ function getSalePrice(unit: ProductSkuUnitItem): number | undefined {
<style scoped lang="less">
.items {
margin: 0;
:deep(.t-cell-group) {
margin: 0;
}
.item {