v1.6.0 #13

Merged
timi merged 28 commits from dev into master 2026-11-20 06:30:23 +00:00
3 changed files with 499 additions and 474 deletions
Showing only changes of commit 7b68e7642f - Show all commits
+7 -473
View File
@@ -1,500 +1,34 @@
<template>
<div class="tui-page-layout tui-navbar">
<t-navbar
fixed
:z-index="20"
title="库存流水详情"
left-arrow
@left-click="goBack"
/>
<t-navbar fixed :z-index="20" title="库存流水详情" left-arrow @left-click="goBack" />
<main class="tui-page-content scroll column">
<div v-can="permissionCodes.productStock.read" class="product-stock-record-detail">
<t-loading v-if="isLoading" class="loading" size="32px" />
<template v-else-if="record">
<section class="snapshot-head" v-entrance-transition>
<div class="eyebrow">库存 SKU 快照</div>
<h2 v-text="record.productNameSnapshot || '未命名产品'" />
<product-sku-tags
class="sku"
:product-name="record.productNameSnapshot"
:snapshot="record.skuSpecSnapshot"
:fallback="record.specSummarySnapshot || record.skuNameSnapshot || '默认 SKU'"
:unit="record.unitSnapshot"
/>
<div class="meta">
<span v-text="record.skuCodeSnapshot || '无 SKU 编码'" />
<t-tag size="small" variant="light-outline" :theme="getOperationTheme(record.onHandDelta)" :content="getStockOperationText(record.operationType)" />
</div>
</section>
<card-container description="库存变动信息" v-entrance-transition>
<div class="data">
<div class="card">
<span class="label">业务数量</span>
<strong :class="getDeltaClass(record.quantity)" v-text="getQuantityText(record)" />
</div>
<div class="card">
<span class="label">基础单位数量</span>
<strong :class="getDeltaClass(record.baseQuantity)" v-text="getSignedQuantityText(record.baseQuantity)" />
</div>
<div class="card">
<span class="label">实际库存变动</span>
<strong :class="getDeltaClass(record.onHandDelta)" v-text="getDeltaText(record.onHandDelta)" />
</div>
<div class="card">
<span class="label">预占库存变动</span>
<strong :class="getDeltaClass(record.reservedDelta)" v-text="getDeltaText(record.reservedDelta)" />
</div>
</div>
</card-container>
<t-cell-group title="库存快照" theme="card" v-entrance-transition>
<t-cell title="实际库存">
<template #note>
<span class="balance">
<span v-text="getProductQuantityText(record.onHandBefore)" />
<t-icon name="arrow-right" />
<span :class="getDeltaClass(record.onHandDelta)" v-text="getProductQuantityText(record.onHandAfter)" />
<span class="unit" v-text="baseUnitName || '基础单位'" />
</span>
</template>
</t-cell>
<t-cell title="预占库存">
<template #note>
<span class="balance">
<span v-text="getProductQuantityText(record.reservedBefore)" />
<t-icon name="arrow-right" />
<span :class="getDeltaClass(record.reservedDelta)" v-text="getProductQuantityText(record.reservedAfter)" />
<span class="unit" v-text="baseUnitName || '基础单位'" />
</span>
</template>
</t-cell>
</t-cell-group>
<t-cell-group title="库存流水" theme="card" v-entrance-transition>
<t-cell title="操作类型" :note="getStockOperationText(record.operationType)" />
<t-cell title="业务类型" :note="getBizTypeText(record.bizType)" />
<t-cell
v-if="relatedRedemptionId && canReadRedemption"
title="关联积分兑换单"
note="查看兑换详情"
arrow
@click="toRedemption"
/>
<t-cell
v-if="relatedFulfillmentId && canReadFulfillment"
title="关联履约单"
note="查看履约详情"
arrow
@click="toFulfillment"
/>
<t-cell title="发生时间">
<template #note>
<time-label :timestamp="record.occurredAt" underline />
</template>
</t-cell>
<t-cell title="操作人" :note="record.operator?.nick || record.operator?.name || record.operatorUserId || '未知操作人'" />
<t-cell v-if="record.sourceRecordId" title="原库存流水" :note="record.sourceRecordId" arrow @click="openRelatedRecord(record.sourceRecordId)" />
<t-cell v-if="record.revokeRecordId" title="冲正流水" :note="record.revokeRecordId" arrow @click="openRelatedRecord(record.revokeRecordId)" />
<t-cell v-if="record.remark" title="备注" :note="record.remark" />
<t-cell class="empty-cell-title-margin">
<template #title>
<span></span>
</template>
<template #description>
<attachment-selector :items="photoItemList" title="操作照片" readonly />
</template>
</t-cell>
</t-cell-group>
<t-button
v-if="canManualRevoke"
class="cell-button"
theme="danger"
@click="openManualRevoke"
v-entrance-transition
content="手工流水冲正"
/>
</template>
<t-empty v-else :description="isLoading ? '正在加载库存流水' : '库存流水不存在'" />
<bottom-popup
v-model="revokeVisible"
title="手工流水冲正"
left-button-text="取消"
:right-button-text="isOperating ? '提交中' : '提交'"
@left-button-click="revokeVisible = false"
@right-button-click="submitManualRevoke"
>
<div class="revoke-popup">
<p class="tip">将新增一条反向库存流水,原流水不会被修改或删除。</p>
<t-form>
<t-form-item label="冲正备注" required-mark>
<t-textarea v-model="revokeRemark" borderless autosize maxlength="500" placeholder="请输入冲正备注" />
</t-form-item>
</t-form>
<attachment-selector
v-model:items="revokePhotoItems"
:upload="uploadPhotoList"
required
title="冲正凭证照片"
/>
</div>
</bottom-popup>
</div>
<product-stock-record-content :record-id="resolveId()" />
</main>
</div>
</template>
<script setup lang="ts">
import { BottomPopup, useExpandToMaster, usePane } from "timi-tdesign-mobile";
import { TimeLabel } from "timi-web";
import { useUserStore, type Attachment } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import type { StockBizType, StockRecord } from "@/types/Product";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getErrorMessage } from "@/utils/error";
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
import { createProductRequestNo, getProductQuantityText, getStockOperationText } from "@/utils/product";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { uploadPhotoList } from "@/utils/photo";
import type { PhotoItem } from "@/types/Photo";
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
import ProductStockRecordContent from "@/pages/product/component/ProductStockRecordContent.vue";
defineOptions({ name: "ProductStockRecordDetail" });
const props = withDefaults(defineProps<{
/** 指定库存流水 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
recordId?: string;
}>(), {
recordId: ""
});
const props = withDefaults(defineProps<{ recordId?: string }>(), { recordId: "" });
const route = useRoute();
const router = useRouter();
const pane = usePane();
/** 内联渲染时 id 来自 prop,整页渲染时来自路由参数 */
function resolveId(): string {
return props.recordId || String(route.params.id || "");
}
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
useExpandToMaster({
path: "/product/product-stock-records",
id: () => resolveId()
});
/** 非空说明当前被内联在主从分栏的右栏里 */
const pane = usePane();
useExpandToMaster({ path: "/product/product-stock-records", id: () => resolveId() });
function goBack(): void {
if (pane) {
pane.close();
return;
}
void router.back();
}
const userStore = useUserStore();
const record = ref<StockRecord>();
const baseUnitName = ref("");
const isLoading = ref(false);
const isOperating = ref(false);
const revokeVisible = ref(false);
const revokeRemark = ref("");
const revokeRequestNo = ref("");
const revokePhotoItems = ref<PhotoItem[]>([]);
const canManualRevoke = computed(() => {
const operationType = record.value?.operationType;
return (operationType === "MANUAL_IN" || operationType === "MANUAL_OUT")
&& !record.value?.sourceRecordId
&& !record.value?.revokeRecordId
&& userStore.hasPermissions(permissionCodes.productStock.manualRevoke);
});
const canReadRedemption = computed(() => userStore.hasPermissions(permissionCodes.pointRedemption.create));
const relatedRedemptionId = computed(() => record.value?.operationType === "POINT_REDEMPTION_OUT"
&& record.value.bizType === "POINT_REDEMPTION" ? record.value.bizId : "");
const canReadFulfillment = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.read));
const relatedFulfillmentId = computed(() => record.value?.bizType === "ORDER_FULFILLMENT" ? record.value.bizId : "");
const photoItemList = computed<PhotoItem[]>(() => (record.value?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
attachment: item,
attachType: item.attachType || "PHOTO",
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 128)
})));
function getOperationTheme(value?: number | string): "success" | "danger" | "default" {
const amount = Number(value || 0);
return 0 < amount ? "success" : amount < 0 ? "danger" : "default";
}
function getDeltaText(value?: number | string): string {
return getSignedQuantityText(value);
}
function getSignedQuantityText(value?: number | string): string {
const amount = Number(value || 0);
const text = getProductQuantityText(String(value || "0").replace(/^-/, ""));
return `${0 < amount ? "+" : amount < 0 ? "-" : ""}${text}`;
}
function getDeltaClass(value?: number | string): string {
const amount = Number(value || 0);
return 0 < amount ? "positive" : amount < 0 ? "negative" : "gray";
}
function getQuantityText(item: StockRecord): string {
return `${getSignedQuantityText(item.quantity)} ${item.unitSnapshot || "业务单位"}`;
}
function getBizTypeText(type?: StockBizType): string {
return ({ PRODUCT_STOCK: "产品库存", ORDER_FULFILLMENT: "订单履约", POINT_REDEMPTION: "积分兑换" } as Record<string, string>)[type || ""] || "未知";
}
function buildAttachments(): Partial<Attachment>[] {
return revokePhotoItems.value.flatMap(item => item.tempFileId ? [{ tempFileId: item.tempFileId, attachType: "PHOTO" }] : []);
}
function openManualRevoke(): void {
if (!canManualRevoke.value) {
return;
}
revokeRemark.value = "";
revokeRequestNo.value = "";
revokePhotoItems.value = [];
revokeVisible.value = true;
}
async function openRelatedRecord(id?: string): Promise<void> {
if (id) {
await router.push({
name: "ProductStockRecordDetail",
params: { id },
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
}
async function toRedemption(): Promise<void> {
if (!relatedRedemptionId.value || !canReadRedemption.value) {
return;
}
await router.push({
name: "PointRedemptionDetail",
params: { id: relatedRedemptionId.value },
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
async function toFulfillment(): Promise<void> {
if (!relatedFulfillmentId.value || !canReadFulfillment.value) {
return;
}
await router.push({
path: `/product/order-fulfillments/${relatedFulfillmentId.value}`,
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
function getCurrentRouteDepth(): number {
const transitionDepth = Array.isArray(route.query.transitionDepth)
? route.query.transitionDepth[0]
: route.query.transitionDepth;
const depth = Number(transitionDepth);
if (transitionDepth && Number.isInteger(depth) && 0 <= depth && depth <= 20) {
return depth;
}
return Number(route.meta.depth ?? 0);
}
async function submitManualRevoke(): Promise<void> {
if (!canManualRevoke.value || !record.value?.id || isOperating.value) {
return;
}
if (!revokeRemark.value.trim()) {
Message.warning("冲正备注不能为空");
return;
}
if (!revokePhotoItems.value.some(item => !!item.tempFileId)) {
Message.warning("库存流水冲正必须上传至少一张照片");
return;
}
isOperating.value = true;
try {
if (!revokeRequestNo.value) {
revokeRequestNo.value = createProductRequestNo();
}
await ProductAPI.manualRevoke({
requestNo: revokeRequestNo.value,
sourceRecordId: record.value.id,
remark: revokeRemark.value.trim(),
attachmentList: buildAttachments()
});
revokeVisible.value = false;
emitListDataChanged(listDataEventKeys.productStockChanged, record.value.id);
Message.success("手工库存流水已冲正");
await loadData();
} catch (error) {
Message.error(getErrorMessage(error, "库存流水冲正失败,重试会复用同一请求号"));
} finally {
isOperating.value = false;
}
}
async function loadData(): Promise<void> {
const id = resolveId();
if (!id) {
return;
}
isLoading.value = true;
try {
const result = await ProductAPI.recordDetail(id);
record.value = result;
baseUnitName.value = "";
if (result.skuId) {
try {
const sku = await ProductAPI.skuDetail(result.skuId);
baseUnitName.value = sku.unitList?.find(unit => unit.isBase)?.name || sku.unitList?.[0]?.name || "";
} catch {
baseUnitName.value = "";
}
}
} catch (error) {
Message.error(getErrorMessage(error, "库存流水加载失败"));
} finally {
isLoading.value = false;
}
}
onMounted(async () => {
await loadData();
});
watch(resolveId, async (id, previousId) => {
if (id && id !== previousId) {
await loadData();
}
});
</script>
<style scoped lang="less">
.product-stock-record-detail {
gap: 1rem;
display: flex;
padding: 0 0 2rem;
flex-direction: column;
.loading {
margin: 3rem auto;
}
.snapshot-head {
margin: 0 1rem;
padding: 1rem;
background: var(--td-bg-color-container);
box-shadow: var(--td-shadow-1);
border-radius: 1rem;
.eyebrow {
color: var(--td-brand-color);
font-size: .75rem;
font-weight: 700;
}
h2 {
margin: .5rem 0 .25rem;
font-size: 1.25rem;
}
.sku {
color: var(--td-text-color-secondary);
}
.meta {
gap: .5rem;
display: flex;
margin-top: .75rem;
align-items: center;
justify-content: space-between;
span {
color: var(--td-text-color-secondary);
font-size: .75rem;
}
}
}
.positive {
color: var(--td-success-color);
}
.negative {
color: var(--td-error-color);
}
.balance {
gap: .25rem;
display: inline-flex;
align-items: center;
.arrow,
.unit {
color: var(--td-text-color-secondary);
}
}
.data {
gap: .75rem;
display: grid;
padding: .75rem;
grid-template-columns: repeat(2, minmax(0, 1fr));
.card {
gap: .25rem;
min-width: 0;
padding: .5rem .75rem;
display: flex;
background: var(--td-bg-color-secondarycontainer);
border-radius: .75rem;
flex-direction: column;
.label {
color: var(--td-text-color-secondary);
font-size: .75rem;
}
strong {
overflow: hidden;
font-size: 1.25rem;
word-break: break-all;
text-align: center;
line-height: 1.4;
}
}
}
.actions {
padding: 0 1rem;
}
}
:global(html.theme-dark) {
.product-stock-record-detail {
.data .card {
background: rgba(15, 23, 42, .72);
border-color: rgba(148, 163, 184, .16);
}
}
}
.revoke-popup {
padding: .5rem 1rem calc(1rem + var(--tui-safe-bottom, 0px));
.tip {
margin: 0 0 .75rem;
color: var(--td-text-color-secondary);
font-size: .875rem;
}
}
</style>
@@ -27,7 +27,7 @@
<t-segmented :value="direction" :options="directionOptions" @change="changeDirection" />
</div>
<t-cell-group v-if="records.length" class="list empty-cell-title-margin" theme="card">
<t-cell v-for="record in records" :key="record.id" class="item">
<t-cell v-for="record in records" :key="record.id" class="item" arrow @click="openRecord(record)">
<template #leftIcon>
<t-image
v-if="getCustomerPhotoURL(record.customer, 64)"
@@ -103,6 +103,18 @@
</div>
<t-empty v-else description="暂无库存流水查看权限" />
</bottom-popup>
<bottom-popup
v-model="detailVisible"
title="库存流水详情"
height="75vh"
left-button-text="关闭"
right-button-text=""
@left-button-click="detailVisible = false"
>
<div class="detail-scroll">
<product-stock-record-content v-if="detailVisible" :record-id="selectedRecordId" />
</div>
</bottom-popup>
</template>
<script setup lang="ts">
@@ -110,6 +122,7 @@ import { BottomPopup } from "timi-tdesign-mobile";
import { TimeLabel } from "timi-web";
import { UserAPI, useUserStore } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import ProductStockRecordContent from "@/pages/product/component/ProductStockRecordContent.vue";
import type { MonthCalendarDay } from "@/components/monthCalendar/monthCalendar";
import type { GaoProductStockMovementDailyStatView } from "@/types/GaoChart";
import type { ProductSelection, StockRecord, StockRecordDirection } from "@/types/Product";
@@ -180,6 +193,15 @@ function getDeltaText(value?: number | string): string {
return `${0 < amount ? "+" : amount < 0 ? "-" : ""}${text}`;
}
const detailVisible = ref(false);
const selectedRecordId = ref("");
function openRecord(record: StockRecord): void {
if (!record.id) return;
selectedRecordId.value = record.id;
detailVisible.value = true;
}
const visible = ref(false);
const selectedDate = ref("");
const selectedStart = ref(0);
@@ -247,6 +269,7 @@ async function loadRecords(): Promise<void> {
watch([() => props.storeId, skuId], () => {
visible.value = false;
detailVisible.value = false;
recordToken++;
});
@@ -254,6 +277,11 @@ defineExpose({ openDay });
</script>
<style scoped lang="less">
.detail-scroll {
height: 100%;
overflow-y: auto;
}
.records {
height: 100%;
overflow-y: auto;
@@ -0,0 +1,463 @@
<template>
<div v-can="permissionCodes.productStock.read" class="product-stock-record-detail">
<t-loading v-if="isLoading" class="loading" size="32px" />
<template v-else-if="record">
<section class="snapshot-head" v-entrance-transition>
<div class="eyebrow">库存 SKU 快照</div>
<h2 v-text="record.productNameSnapshot || '未命名产品'" />
<product-sku-tags
class="sku"
:product-name="record.productNameSnapshot"
:snapshot="record.skuSpecSnapshot"
:fallback="record.specSummarySnapshot || record.skuNameSnapshot || '默认 SKU'"
:unit="record.unitSnapshot"
/>
<div class="meta">
<span v-text="record.skuCodeSnapshot || '无 SKU 编码'" />
<t-tag size="small" variant="light-outline" :theme="getOperationTheme(record.onHandDelta)" :content="getStockOperationText(record.operationType)" />
</div>
</section>
<card-container description="库存变动信息" v-entrance-transition>
<div class="data">
<div class="card">
<span class="label">业务数量</span>
<strong :class="getDeltaClass(record.quantity)" v-text="getQuantityText(record)" />
</div>
<div class="card">
<span class="label">基础单位数量</span>
<strong :class="getDeltaClass(record.baseQuantity)" v-text="getSignedQuantityText(record.baseQuantity)" />
</div>
<div class="card">
<span class="label">实际库存变动</span>
<strong :class="getDeltaClass(record.onHandDelta)" v-text="getDeltaText(record.onHandDelta)" />
</div>
<div class="card">
<span class="label">预占库存变动</span>
<strong :class="getDeltaClass(record.reservedDelta)" v-text="getDeltaText(record.reservedDelta)" />
</div>
</div>
</card-container>
<t-cell-group title="库存快照" theme="card" v-entrance-transition>
<t-cell title="实际库存">
<template #note>
<span class="balance">
<span v-text="getProductQuantityText(record.onHandBefore)" />
<t-icon name="arrow-right" />
<span :class="getDeltaClass(record.onHandDelta)" v-text="getProductQuantityText(record.onHandAfter)" />
<span class="unit" v-text="baseUnitName || '基础单位'" />
</span>
</template>
</t-cell>
<t-cell title="预占库存">
<template #note>
<span class="balance">
<span v-text="getProductQuantityText(record.reservedBefore)" />
<t-icon name="arrow-right" />
<span :class="getDeltaClass(record.reservedDelta)" v-text="getProductQuantityText(record.reservedAfter)" />
<span class="unit" v-text="baseUnitName || '基础单位'" />
</span>
</template>
</t-cell>
</t-cell-group>
<t-cell-group title="库存流水" theme="card" v-entrance-transition>
<t-cell title="操作类型" :note="getStockOperationText(record.operationType)" />
<t-cell title="业务类型" :note="getBizTypeText(record.bizType)" />
<t-cell
v-if="relatedRedemptionId && canReadRedemption"
title="关联积分兑换单"
note="查看兑换详情"
arrow
@click="toRedemption"
/>
<t-cell
v-if="relatedFulfillmentId && canReadFulfillment"
title="关联履约单"
note="查看履约详情"
arrow
@click="toFulfillment"
/>
<t-cell title="发生时间">
<template #note>
<time-label :timestamp="record.occurredAt" underline />
</template>
</t-cell>
<t-cell title="操作人" :note="record.operator?.nick || record.operator?.name || record.operatorUserId || '未知操作人'" />
<t-cell v-if="record.sourceRecordId" title="原库存流水" :note="record.sourceRecordId" arrow @click="openRelatedRecord(record.sourceRecordId)" />
<t-cell v-if="record.revokeRecordId" title="冲正流水" :note="record.revokeRecordId" arrow @click="openRelatedRecord(record.revokeRecordId)" />
<t-cell v-if="record.remark" title="备注" :note="record.remark" />
<t-cell class="empty-cell-title-margin">
<template #title>
<span></span>
</template>
<template #description>
<attachment-selector :items="photoItemList" title="操作照片" readonly />
</template>
</t-cell>
</t-cell-group>
<t-button
v-if="canManualRevoke"
class="cell-button"
theme="danger"
@click="openManualRevoke"
v-entrance-transition
content="手工流水冲正"
/>
</template>
<t-empty v-else :description="isLoading ? '正在加载库存流水' : '库存流水不存在'" />
<bottom-popup
v-model="revokeVisible"
title="手工流水冲正"
left-button-text="取消"
:right-button-text="isOperating ? '提交中' : '提交'"
@left-button-click="revokeVisible = false"
@right-button-click="submitManualRevoke"
>
<div class="revoke-popup">
<p class="tip">将新增一条反向库存流水,原流水不会被修改或删除。</p>
<t-form>
<t-form-item label="冲正备注" required-mark>
<t-textarea v-model="revokeRemark" borderless autosize maxlength="500" placeholder="请输入冲正备注" />
</t-form-item>
</t-form>
<attachment-selector
v-model:items="revokePhotoItems"
:upload="uploadPhotoList"
required
title="冲正凭证照片"
/>
</div>
</bottom-popup>
</div>
</template>
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import { TimeLabel } from "timi-web";
import { useUserStore, type Attachment } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import type { StockBizType, StockRecord } from "@/types/Product";
import { getAttachmentReadURL } from "@/utils/attachment";
import { getErrorMessage } from "@/utils/error";
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
import { createProductRequestNo, getProductQuantityText, getStockOperationText } from "@/utils/product";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { uploadPhotoList } from "@/utils/photo";
import type { PhotoItem } from "@/types/Photo";
const props = defineProps<{ recordId: string }>();
const route = useRoute();
const router = useRouter();
function resolveId(): string {
return props.recordId;
}
const userStore = useUserStore();
const record = ref<StockRecord>();
const baseUnitName = ref("");
const isLoading = ref(false);
const isOperating = ref(false);
const revokeVisible = ref(false);
const revokeRemark = ref("");
const revokeRequestNo = ref("");
const revokePhotoItems = ref<PhotoItem[]>([]);
const canManualRevoke = computed(() => {
const operationType = record.value?.operationType;
return (operationType === "MANUAL_IN" || operationType === "MANUAL_OUT")
&& !record.value?.sourceRecordId
&& !record.value?.revokeRecordId
&& userStore.hasPermissions(permissionCodes.productStock.manualRevoke);
});
const canReadRedemption = computed(() => userStore.hasPermissions(permissionCodes.pointRedemption.create));
const relatedRedemptionId = computed(() => record.value?.operationType === "POINT_REDEMPTION_OUT"
&& record.value.bizType === "POINT_REDEMPTION" ? record.value.bizId : "");
const canReadFulfillment = computed(() => userStore.hasPermissions(permissionCodes.orderFulfillment.read));
const relatedFulfillmentId = computed(() => record.value?.bizType === "ORDER_FULFILLMENT" ? record.value.bizId : "");
const photoItemList = computed<PhotoItem[]>(() => (record.value?.attachmentList || [])
.filter(item => !!item.id)
.map(item => ({
attachment: item,
attachType: item.attachType || "PHOTO",
previewUrl: getAttachmentReadURL(item.id || ""),
url: getAttachmentReadURL(item.id || "", 128)
})));
function getOperationTheme(value?: number | string): "success" | "danger" | "default" {
const amount = Number(value || 0);
return 0 < amount ? "success" : amount < 0 ? "danger" : "default";
}
function getDeltaText(value?: number | string): string {
return getSignedQuantityText(value);
}
function getSignedQuantityText(value?: number | string): string {
const amount = Number(value || 0);
const text = getProductQuantityText(String(value || "0").replace(/^-/, ""));
return `${0 < amount ? "+" : amount < 0 ? "-" : ""}${text}`;
}
function getDeltaClass(value?: number | string): string {
const amount = Number(value || 0);
return 0 < amount ? "positive" : amount < 0 ? "negative" : "gray";
}
function getQuantityText(item: StockRecord): string {
return `${getSignedQuantityText(item.quantity)} ${item.unitSnapshot || "业务单位"}`;
}
function getBizTypeText(type?: StockBizType): string {
return ({ PRODUCT_STOCK: "产品库存", ORDER_FULFILLMENT: "订单履约", POINT_REDEMPTION: "积分兑换" } as Record<string, string>)[type || ""] || "未知";
}
function buildAttachments(): Partial<Attachment>[] {
return revokePhotoItems.value.flatMap(item => item.tempFileId ? [{ tempFileId: item.tempFileId, attachType: "PHOTO" }] : []);
}
function openManualRevoke(): void {
if (!canManualRevoke.value) {
return;
}
revokeRemark.value = "";
revokeRequestNo.value = "";
revokePhotoItems.value = [];
revokeVisible.value = true;
}
async function openRelatedRecord(id?: string): Promise<void> {
if (id) {
await router.push({
name: "ProductStockRecordDetail",
params: { id },
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
}
async function toRedemption(): Promise<void> {
if (!relatedRedemptionId.value || !canReadRedemption.value) {
return;
}
await router.push({
name: "PointRedemptionDetail",
params: { id: relatedRedemptionId.value },
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
async function toFulfillment(): Promise<void> {
if (!relatedFulfillmentId.value || !canReadFulfillment.value) {
return;
}
await router.push({
path: `/product/order-fulfillments/${relatedFulfillmentId.value}`,
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
function getCurrentRouteDepth(): number {
const transitionDepth = Array.isArray(route.query.transitionDepth)
? route.query.transitionDepth[0]
: route.query.transitionDepth;
const depth = Number(transitionDepth);
if (transitionDepth && Number.isInteger(depth) && 0 <= depth && depth <= 20) {
return depth;
}
return Number(route.meta.depth ?? 0);
}
async function submitManualRevoke(): Promise<void> {
if (!canManualRevoke.value || !record.value?.id || isOperating.value) {
return;
}
if (!revokeRemark.value.trim()) {
Message.warning("冲正备注不能为空");
return;
}
if (!revokePhotoItems.value.some(item => !!item.tempFileId)) {
Message.warning("库存流水冲正必须上传至少一张照片");
return;
}
isOperating.value = true;
try {
if (!revokeRequestNo.value) {
revokeRequestNo.value = createProductRequestNo();
}
await ProductAPI.manualRevoke({
requestNo: revokeRequestNo.value,
sourceRecordId: record.value.id,
remark: revokeRemark.value.trim(),
attachmentList: buildAttachments()
});
revokeVisible.value = false;
emitListDataChanged(listDataEventKeys.productStockChanged, record.value.id);
Message.success("手工库存流水已冲正");
await loadData();
} catch (error) {
Message.error(getErrorMessage(error, "库存流水冲正失败,重试会复用同一请求号"));
} finally {
isOperating.value = false;
}
}
async function loadData(): Promise<void> {
const id = resolveId();
if (!id) {
return;
}
isLoading.value = true;
try {
const result = await ProductAPI.recordDetail(id);
record.value = result;
baseUnitName.value = "";
if (result.skuId) {
try {
const sku = await ProductAPI.skuDetail(result.skuId);
baseUnitName.value = sku.unitList?.find(unit => unit.isBase)?.name || sku.unitList?.[0]?.name || "";
} catch {
baseUnitName.value = "";
}
}
} catch (error) {
Message.error(getErrorMessage(error, "库存流水加载失败"));
} finally {
isLoading.value = false;
}
}
onMounted(async () => {
await loadData();
});
watch(resolveId, async (id, previousId) => {
if (id && id !== previousId) {
await loadData();
}
});
</script>
<style scoped lang="less">
.product-stock-record-detail {
gap: 1rem;
display: flex;
padding: 0 0 2rem;
flex-direction: column;
.loading {
margin: 3rem auto;
}
.snapshot-head {
margin: 0 1rem;
padding: 1rem;
background: var(--td-bg-color-container);
box-shadow: var(--td-shadow-1);
border-radius: 1rem;
.eyebrow {
color: var(--td-brand-color);
font-size: .75rem;
font-weight: 700;
}
h2 {
margin: .5rem 0 .25rem;
font-size: 1.25rem;
}
.sku {
color: var(--td-text-color-secondary);
}
.meta {
gap: .5rem;
display: flex;
margin-top: .75rem;
align-items: center;
justify-content: space-between;
span {
color: var(--td-text-color-secondary);
font-size: .75rem;
}
}
}
.positive {
color: var(--td-success-color);
}
.negative {
color: var(--td-error-color);
}
.balance {
gap: .25rem;
display: inline-flex;
align-items: center;
.arrow,
.unit {
color: var(--td-text-color-secondary);
}
}
.data {
gap: .75rem;
display: grid;
padding: .75rem;
grid-template-columns: repeat(2, minmax(0, 1fr));
.card {
gap: .25rem;
min-width: 0;
padding: .5rem .75rem;
display: flex;
background: var(--td-bg-color-secondarycontainer);
border-radius: .75rem;
flex-direction: column;
.label {
color: var(--td-text-color-secondary);
font-size: .75rem;
}
strong {
overflow: hidden;
font-size: 1.25rem;
word-break: break-all;
text-align: center;
line-height: 1.4;
}
}
}
.actions {
padding: 0 1rem;
}
}
:global(html.theme-dark) {
.product-stock-record-detail {
.data .card {
background: rgba(15, 23, 42, .72);
border-color: rgba(148, 163, 184, .16);
}
}
}
.revoke-popup {
padding: .5rem 1rem calc(1rem + var(--tui-safe-bottom, 0px));
.tip {
margin: 0 0 .75rem;
color: var(--td-text-color-secondary);
font-size: .875rem;
}
}
</style>