feat(product): summary and change unit for stock popup
This commit is contained in:
@@ -57,112 +57,36 @@
|
||||
v-model:visible="selectorVisible"
|
||||
@select="selectProduct"
|
||||
/>
|
||||
<bottom-popup
|
||||
v-model="visible"
|
||||
:title="`${selectedDate} 库存流水`"
|
||||
height="80vh"
|
||||
left-button-text="关闭"
|
||||
@left-button-click="visible = false"
|
||||
>
|
||||
<div class="records">
|
||||
<template v-if="canReadRecords">
|
||||
<div class="directions">
|
||||
<t-segmented block :value="direction" :options="directionOptions" @change="changeDirection" />
|
||||
</div>
|
||||
<div class="record-list">
|
||||
<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">
|
||||
<template #leftIcon>
|
||||
<t-image
|
||||
v-if="getCustomerPhotoURL(record.customer, 64)"
|
||||
:src="getCustomerPhotoURL(record.customer, 64)"
|
||||
:alt="getCustomerText(record)"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div
|
||||
v-else-if="record.customer"
|
||||
class="avatar fallback"
|
||||
v-text="getCustomerText(record).slice(0, 1)"
|
||||
/>
|
||||
<t-image
|
||||
v-else-if="record.operator"
|
||||
:src="getOperatorAvatar(record)"
|
||||
:alt="getOperatorText(record)"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<span
|
||||
v-else
|
||||
class="icon"
|
||||
:class="getDeltaClass(record.onHandDelta)"
|
||||
>
|
||||
<t-icon name="history" size="1.25rem" />
|
||||
</span>
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="record-title">
|
||||
<span v-if="record.customer" class="actor" v-text="getCustomerText(record)" />
|
||||
<span v-else-if="record.operator" class="actor"
|
||||
v-text="getOperatorText(record)" />
|
||||
<strong class="operation" :class="getOperationClass(record.operationType)"
|
||||
v-text="getStockOperationText(record.operationType)" />
|
||||
<strong class="product-name"
|
||||
v-text="record.productNameSnapshot || '未命名产品'" />
|
||||
<t-tag
|
||||
v-if="record.skuNameSnapshot && record.productNameSnapshot !== record.skuNameSnapshot"
|
||||
size="small" :content="record.skuNameSnapshot" />
|
||||
<span
|
||||
v-if="record.quantity !== undefined && record.quantity !== null && record.quantity !== ''"
|
||||
class="record-quantity"
|
||||
v-text="`${getProductQuantityText(record.quantity)} ${record.unitSnapshot || ''}`" />
|
||||
</div>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<time-label :timestamp="record.occurredAt" underline />
|
||||
<div><span class="delta" :class="getDeltaClass(record.onHandDelta)"
|
||||
v-text="getDeltaText(record.onHandDelta)" /></div>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-empty v-else-if="!recordsLoading" description="当天暂无流水" />
|
||||
<t-button v-if="!noMore" block variant="text" :loading="recordsLoading" @click="loadRecords">
|
||||
加载更多
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
<t-empty v-else description="暂无库存流水查看权限" />
|
||||
</div>
|
||||
</bottom-popup>
|
||||
<product-stock-calendar-records-popup
|
||||
ref="recordsPopup"
|
||||
v-model:unit-index="unitIndex"
|
||||
:store-id="storeId"
|
||||
:selection="selection"
|
||||
:summary="selectedSummary"
|
||||
:summary-loading="loading"
|
||||
@date-change="selectedDate = $event"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import { TimeLabel } from "timi-web";
|
||||
import { UserAPI, useUserStore } from "timi-web-api";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import GaoProductChartAPI from "@/api/GaoProductChartAPI";
|
||||
import GaoProductSkuChartAPI from "@/api/GaoProductSkuChartAPI";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import StoreChartAPI from "@/api/StoreChartAPI";
|
||||
import MonthCalendar from "@/components/monthCalendar/MonthCalendar.vue";
|
||||
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
|
||||
import ProductStockCalendarRecordsPopup from "@/pages/product/component/ProductStockCalendarRecordsPopup.vue";
|
||||
import { buildMonthCalendarDays, type MonthCalendarDay } from "@/components/monthCalendar/monthCalendar";
|
||||
import type { GaoProductStockMovementDailyStatView } from "@/types/GaoChart";
|
||||
import type { ProductSelection, StockRecord, StockRecordDirection } from "@/types/Product";
|
||||
import type { ProductSelection } from "@/types/Product";
|
||||
import type { ProductSkuSelectionValue } from "@/types/ProductSkuSelection";
|
||||
import { getProductQuantityText, getStockOperationText } from "@/utils/product";
|
||||
import { buildFallbackAvatar } from "@/utils/avatar";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { getCustomerPhotoURL } from "@/utils/customer";
|
||||
|
||||
const props = defineProps<{ storeId: string }>();
|
||||
const userStore = useUserStore();
|
||||
const canReadRecords = computed(() => userStore.hasPermissions(permissionCodes.productStock.read));
|
||||
const canReadProducts = computed(() => userStore.hasPermissions(permissionCodes.product.read));
|
||||
const selectorVisible = ref(false);
|
||||
const selectedProductSku = ref<ProductSkuSelectionValue>();
|
||||
@@ -181,46 +105,6 @@ const unitIndex = ref(0);
|
||||
const units = computed(() => selection.value?.sku.unitList || []);
|
||||
const currentUnit = computed(() => units.value[unitIndex.value]);
|
||||
|
||||
function getCustomerText(record: StockRecord): string {
|
||||
return record.customer?.name || record.customer?.code || "未知客户";
|
||||
}
|
||||
|
||||
function getOperatorText(record: StockRecord): string {
|
||||
return record.operator?.nick || record.operator?.name || "未知操作人";
|
||||
}
|
||||
|
||||
function getOperatorAvatar(record: StockRecord): string {
|
||||
return UserAPI.getAvatarURL(record.operator) || buildFallbackAvatar(getOperatorText(record), "#0f766e");
|
||||
}
|
||||
|
||||
function getOperationClass(type?: string): string {
|
||||
return ({
|
||||
INITIAL_IN: "initial-in",
|
||||
MANUAL_IN: "manual-in",
|
||||
MANUAL_OUT: "manual-out",
|
||||
MANUAL_REVOKE: "manual-revoke",
|
||||
ORDER_RESERVE: "order-reserve",
|
||||
ORDER_RELEASE: "order-release",
|
||||
ORDER_OUT: "order-out",
|
||||
ORDER_REVOKE: "order-revoke",
|
||||
ORDER_RETURN_IN: "return-in",
|
||||
POINT_REDEMPTION_OUT: "manual-out",
|
||||
POINT_REDEMPTION_RETURN_IN: "return-in",
|
||||
STOCKTAKE_GAIN: "stocktake-gain",
|
||||
STOCKTAKE_LOSS: "stocktake-loss"
|
||||
} as Record<string, string>)[type || ""] || "unknown";
|
||||
}
|
||||
|
||||
function getDeltaClass(value?: number | string): string {
|
||||
const amount = Number(value || 0);
|
||||
return 0 < amount ? "positive" : amount < 0 ? "negative" : "gray";
|
||||
}
|
||||
|
||||
function getDeltaText(value?: number | string): string {
|
||||
const amount = Number(value || 0);
|
||||
return `${0 < amount ? "+" : amount < 0 ? "-" : ""}${getProductQuantityText(String(value || "0").replace(/^-/, ""))}`;
|
||||
}
|
||||
|
||||
function nextUnit(): void {
|
||||
unitIndex.value = (unitIndex.value + 1) % units.value.length;
|
||||
}
|
||||
@@ -296,74 +180,14 @@ watch([month, () => props.storeId, skuId], async () => {
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
const visible = ref(false);
|
||||
const recordsPopup = ref<InstanceType<typeof ProductStockCalendarRecordsPopup>>();
|
||||
const selectedDate = ref("");
|
||||
const selectedStart = ref(0);
|
||||
const direction = ref<StockRecordDirection>("IN");
|
||||
const directionOptions = [{ label: "入库", value: "IN" }, { label: "出库", value: "OUT" }];
|
||||
|
||||
async function changeDirection(event: { value: string | number }): Promise<void> {
|
||||
if (event.value === "IN" || event.value === "OUT") await selectDirection(event.value);
|
||||
}
|
||||
|
||||
const records = ref<StockRecord[]>([]);
|
||||
const recordsLoading = ref(false);
|
||||
const noMore = ref(false);
|
||||
let page = 0;
|
||||
let recordToken = 0;
|
||||
const selectedSummary = computed(() => stats.value.find(item => item.dateValue === Number(selectedDate.value.replaceAll("-", ""))));
|
||||
|
||||
async function openDay(day: MonthCalendarDay): Promise<void> {
|
||||
const [year, monthNumber, dateNumber] = day.dateText.split("-").map(Number);
|
||||
const date = new Date(year, monthNumber - 1, dateNumber);
|
||||
selectedStart.value = date.getTime();
|
||||
selectedDate.value = day.dateText;
|
||||
visible.value = true;
|
||||
if (canReadRecords.value) await selectDirection("IN");
|
||||
await recordsPopup.value?.openDay(day);
|
||||
}
|
||||
|
||||
async function selectDirection(value: StockRecordDirection): Promise<void> {
|
||||
direction.value = value;
|
||||
recordToken++;
|
||||
records.value = [];
|
||||
page = 0;
|
||||
noMore.value = false;
|
||||
recordsLoading.value = false;
|
||||
await loadRecords();
|
||||
}
|
||||
|
||||
async function loadRecords(): Promise<void> {
|
||||
if (recordsLoading.value || noMore.value) return;
|
||||
const token = ++recordToken;
|
||||
recordsLoading.value = true;
|
||||
try {
|
||||
const start = new Date(selectedStart.value);
|
||||
const endAt = new Date(start.getFullYear(), start.getMonth(), start.getDate() + 1).getTime() - 1;
|
||||
const result = await ProductAPI.recordList({
|
||||
storeId: props.storeId,
|
||||
productId: selection.value?.product.id || undefined,
|
||||
skuId: skuId.value || undefined,
|
||||
beginAt: selectedStart.value,
|
||||
endAt,
|
||||
direction: direction.value,
|
||||
index: page,
|
||||
size: 15
|
||||
});
|
||||
if (token !== recordToken) return;
|
||||
const list = result.list || [];
|
||||
records.value.push(...list);
|
||||
page++;
|
||||
noMore.value = list.length < 15 || !(records.value.length < (result.total || 0));
|
||||
} catch (error) {
|
||||
if (token === recordToken) Message.error(getErrorMessage(error, "库存流水加载失败"));
|
||||
} finally {
|
||||
if (token === recordToken) recordsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch([() => props.storeId, skuId], () => {
|
||||
visible.value = false;
|
||||
recordToken++;
|
||||
});
|
||||
watch(() => props.storeId, () => {
|
||||
selectorVisible.value = false;
|
||||
clearSelection();
|
||||
@@ -415,187 +239,4 @@ watch(() => props.storeId, () => {
|
||||
|
||||
}
|
||||
|
||||
.records {
|
||||
height: 60vh;
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
flex-direction: column;
|
||||
|
||||
.directions {
|
||||
padding: .75rem;
|
||||
min-width: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.record-list {
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.list {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.item {
|
||||
padding: .625rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
display: inline-flex;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
align-items: center;
|
||||
border-radius: 50%;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.record-title {
|
||||
gap: .25rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
font-size: .75rem;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
|
||||
.actor {
|
||||
flex: 0 0 auto;
|
||||
color: var(--td-text-color-brand);
|
||||
}
|
||||
|
||||
.operation, .record-quantity {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.operation {
|
||||
color: var(--operation-color, var(--td-text-color-secondary));
|
||||
|
||||
&.initial-in {
|
||||
--operation-color: #2563eb;
|
||||
}
|
||||
|
||||
&.manual-in {
|
||||
--operation-color: #15803d;
|
||||
}
|
||||
|
||||
&.manual-out {
|
||||
--operation-color: #c2410c;
|
||||
}
|
||||
|
||||
&.manual-revoke {
|
||||
--operation-color: #be123c;
|
||||
}
|
||||
|
||||
&.order-reserve {
|
||||
--operation-color: #7c3aed;
|
||||
}
|
||||
|
||||
&.order-release {
|
||||
--operation-color: #0891b2;
|
||||
}
|
||||
|
||||
&.order-out {
|
||||
--operation-color: #dc2626;
|
||||
}
|
||||
|
||||
&.order-revoke {
|
||||
--operation-color: #4f46e5;
|
||||
}
|
||||
|
||||
&.return-in {
|
||||
--operation-color: #15803d;
|
||||
}
|
||||
|
||||
&.stocktake-gain {
|
||||
--operation-color: #0f766e;
|
||||
}
|
||||
|
||||
&.stocktake-loss {
|
||||
--operation-color: #a16207;
|
||||
}
|
||||
}
|
||||
|
||||
.product-name {
|
||||
overflow: hidden;
|
||||
flex: 0 1 auto;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.record-quantity {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
font-size: .75rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.delta {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.positive {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
.negative {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) .records .operation {
|
||||
&.initial-in {
|
||||
--operation-color: #93c5fd;
|
||||
}
|
||||
|
||||
&.manual-in, &.return-in {
|
||||
--operation-color: #86efac;
|
||||
}
|
||||
|
||||
&.manual-out {
|
||||
--operation-color: #fdba74;
|
||||
}
|
||||
|
||||
&.manual-revoke {
|
||||
--operation-color: #fda4af;
|
||||
}
|
||||
|
||||
&.order-reserve {
|
||||
--operation-color: #c4b5fd;
|
||||
}
|
||||
|
||||
&.order-release {
|
||||
--operation-color: #67e8f9;
|
||||
}
|
||||
|
||||
&.order-out {
|
||||
--operation-color: #fca5a5;
|
||||
}
|
||||
|
||||
&.order-revoke {
|
||||
--operation-color: #a5b4fc;
|
||||
}
|
||||
|
||||
&.stocktake-gain {
|
||||
--operation-color: #5eead4;
|
||||
}
|
||||
|
||||
&.stocktake-loss {
|
||||
--operation-color: #fcd34d;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,437 @@
|
||||
<template>
|
||||
<bottom-popup
|
||||
v-model="visible"
|
||||
:title="`${selectedDate} 库存流水`"
|
||||
height="80vh"
|
||||
left-button-text="关闭"
|
||||
@left-button-click="visible = false"
|
||||
>
|
||||
<div class="records">
|
||||
<template v-if="canReadRecords">
|
||||
<div class="directions">
|
||||
<t-segmented :value="direction" :options="directionOptions" @change="changeDirection" />
|
||||
<div v-if="selection" class="summary">
|
||||
<span v-if="summaryLoading">汇总加载中</span>
|
||||
<span v-else :class="direction === 'IN' ? 'in' : 'out'"
|
||||
v-text="`合计 ${formatQuantity(direction === 'IN' ? summary?.inQuantity : summary?.outQuantity)} ${currentUnit?.name || ''}`" />
|
||||
<t-button v-if="1 < units.length" size="extra-small" variant="outline" :content="`单位:${currentUnit?.name}`" @click="nextUnit" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="record-list">
|
||||
<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">
|
||||
<template #leftIcon>
|
||||
<t-image
|
||||
v-if="getCustomerPhotoURL(record.customer, 64)"
|
||||
:src="getCustomerPhotoURL(record.customer, 64)"
|
||||
:alt="getCustomerText(record)"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div
|
||||
v-else-if="record.customer"
|
||||
class="avatar fallback"
|
||||
v-text="getCustomerText(record).slice(0, 1)"
|
||||
/>
|
||||
<t-image
|
||||
v-else-if="record.operator"
|
||||
:src="getOperatorAvatar(record)"
|
||||
:alt="getOperatorText(record)"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<span
|
||||
v-else
|
||||
class="icon"
|
||||
:class="getDeltaClass(record.onHandDelta)"
|
||||
>
|
||||
<t-icon name="history" size="1.25rem" />
|
||||
</span>
|
||||
</template>
|
||||
<template #title>
|
||||
<div class="record-title">
|
||||
<span v-if="record.customer" class="actor" v-text="getCustomerText(record)" />
|
||||
<span v-else-if="record.operator" class="actor"
|
||||
v-text="getOperatorText(record)" />
|
||||
<strong class="operation" :class="getOperationClass(record.operationType)"
|
||||
v-text="getStockOperationText(record.operationType)" />
|
||||
<strong class="product-name"
|
||||
v-text="record.productNameSnapshot || '未命名产品'" />
|
||||
<t-tag
|
||||
v-if="record.skuNameSnapshot && record.productNameSnapshot !== record.skuNameSnapshot"
|
||||
size="small" :content="record.skuNameSnapshot" />
|
||||
<span
|
||||
v-if="record.quantity !== undefined && record.quantity !== null && record.quantity !== ''"
|
||||
class="record-quantity"
|
||||
v-text="`${getProductQuantityText(record.quantity)} ${record.unitSnapshot || ''}`" />
|
||||
</div>
|
||||
</template>
|
||||
<template #description>
|
||||
<div class="description">
|
||||
<time-label :timestamp="record.occurredAt" underline />
|
||||
<div><span class="delta" :class="getDeltaClass(record.onHandDelta)"
|
||||
v-text="getDeltaText(record.onHandDelta)" /></div>
|
||||
</div>
|
||||
</template>
|
||||
</t-cell>
|
||||
</t-cell-group>
|
||||
<t-empty v-else-if="!recordsLoading" description="当天暂无流水" />
|
||||
<t-button v-if="!noMore" block variant="text" :loading="recordsLoading" @click="loadRecords">
|
||||
加载更多
|
||||
</t-button>
|
||||
</div>
|
||||
</template>
|
||||
<t-empty v-else description="暂无库存流水查看权限" />
|
||||
</div>
|
||||
</bottom-popup>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { BottomPopup } from "timi-tdesign-mobile";
|
||||
import { TimeLabel } from "timi-web";
|
||||
import { UserAPI, useUserStore } from "timi-web-api";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import type { MonthCalendarDay } from "@/components/monthCalendar/monthCalendar";
|
||||
import type { GaoProductStockMovementDailyStatView } from "@/types/GaoChart";
|
||||
import type { ProductSelection, StockRecord, StockRecordDirection } from "@/types/Product";
|
||||
import { getProductQuantityText, getStockOperationText } from "@/utils/product";
|
||||
import { buildFallbackAvatar } from "@/utils/avatar";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { Message } from "@/utils/message";
|
||||
import { getCustomerPhotoURL } from "@/utils/customer";
|
||||
|
||||
const props = defineProps<{ storeId: string; selection?: ProductSelection; summary?: GaoProductStockMovementDailyStatView; summaryLoading: boolean }>();
|
||||
const emit = defineEmits<{ "date-change": [date: string] }>();
|
||||
const unitIndex = defineModel<number>("unitIndex", { required: true });
|
||||
const userStore = useUserStore();
|
||||
const canReadRecords = computed(() => userStore.hasPermissions(permissionCodes.productStock.read));
|
||||
const skuId = computed(() => props.selection?.sku.id || "");
|
||||
const units = computed(() => props.selection?.sku.unitList || []);
|
||||
const currentUnit = computed(() => units.value[unitIndex.value]);
|
||||
|
||||
function nextUnit(): void {
|
||||
unitIndex.value = (unitIndex.value + 1) % units.value.length;
|
||||
}
|
||||
|
||||
function formatQuantity(value: number | string | undefined): string {
|
||||
const ratio = Number(currentUnit.value?.baseQuantityPerUnit) || 1;
|
||||
return String(Number((Number(value || 0) / ratio).toFixed(4)));
|
||||
}
|
||||
|
||||
function getCustomerText(record: StockRecord): string {
|
||||
return record.customer?.name || record.customer?.code || "未知客户";
|
||||
}
|
||||
|
||||
function getOperatorText(record: StockRecord): string {
|
||||
return record.operator?.nick || record.operator?.name || "未知操作人";
|
||||
}
|
||||
|
||||
function getOperatorAvatar(record: StockRecord): string {
|
||||
return UserAPI.getAvatarURL(record.operator) || buildFallbackAvatar(getOperatorText(record), "#0f766e");
|
||||
}
|
||||
|
||||
function getOperationClass(type?: string): string {
|
||||
return ({
|
||||
INITIAL_IN: "initial-in",
|
||||
MANUAL_IN: "manual-in",
|
||||
MANUAL_OUT: "manual-out",
|
||||
MANUAL_REVOKE: "manual-revoke",
|
||||
ORDER_RESERVE: "order-reserve",
|
||||
ORDER_RELEASE: "order-release",
|
||||
ORDER_OUT: "order-out",
|
||||
ORDER_REVOKE: "order-revoke",
|
||||
ORDER_RETURN_IN: "return-in",
|
||||
POINT_REDEMPTION_OUT: "manual-out",
|
||||
POINT_REDEMPTION_RETURN_IN: "return-in",
|
||||
STOCKTAKE_GAIN: "stocktake-gain",
|
||||
STOCKTAKE_LOSS: "stocktake-loss"
|
||||
} as Record<string, string>)[type || ""] || "unknown";
|
||||
}
|
||||
|
||||
function getDeltaClass(value?: number | string): string {
|
||||
const amount = Number(value || 0);
|
||||
return 0 < amount ? "positive" : amount < 0 ? "negative" : "gray";
|
||||
}
|
||||
|
||||
function getDeltaText(value?: number | string): string {
|
||||
const amount = Number(value || 0);
|
||||
const quantity = String(value || "0").replace(/^-/, "");
|
||||
const text = props.selection ? `${formatQuantity(quantity)} ${currentUnit.value?.name || ""}` : getProductQuantityText(quantity);
|
||||
return `${0 < amount ? "+" : amount < 0 ? "-" : ""}${text}`;
|
||||
}
|
||||
|
||||
const visible = ref(false);
|
||||
const selectedDate = ref("");
|
||||
const selectedStart = ref(0);
|
||||
const direction = ref<StockRecordDirection>("IN");
|
||||
const directionOptions = [{ label: "入库", value: "IN" }, { label: "出库", value: "OUT" }];
|
||||
|
||||
async function changeDirection(event: { value: string | number }): Promise<void> {
|
||||
if (event.value === "IN" || event.value === "OUT") await selectDirection(event.value);
|
||||
}
|
||||
|
||||
const records = ref<StockRecord[]>([]);
|
||||
const recordsLoading = ref(false);
|
||||
const noMore = ref(false);
|
||||
let page = 0;
|
||||
let recordToken = 0;
|
||||
|
||||
async function openDay(day: MonthCalendarDay): Promise<void> {
|
||||
const [year, monthNumber, dateNumber] = day.dateText.split("-").map(Number);
|
||||
const date = new Date(year, monthNumber - 1, dateNumber);
|
||||
selectedStart.value = date.getTime();
|
||||
selectedDate.value = day.dateText;
|
||||
emit("date-change", day.dateText);
|
||||
visible.value = true;
|
||||
if (canReadRecords.value) await selectDirection("IN");
|
||||
}
|
||||
|
||||
async function selectDirection(value: StockRecordDirection): Promise<void> {
|
||||
direction.value = value;
|
||||
recordToken++;
|
||||
records.value = [];
|
||||
page = 0;
|
||||
noMore.value = false;
|
||||
recordsLoading.value = false;
|
||||
await loadRecords();
|
||||
}
|
||||
|
||||
async function loadRecords(): Promise<void> {
|
||||
if (recordsLoading.value || noMore.value) return;
|
||||
const token = ++recordToken;
|
||||
recordsLoading.value = true;
|
||||
try {
|
||||
const start = new Date(selectedStart.value);
|
||||
const endAt = new Date(start.getFullYear(), start.getMonth(), start.getDate() + 1).getTime() - 1;
|
||||
const result = await ProductAPI.recordList({
|
||||
storeId: props.storeId,
|
||||
productId: props.selection?.product.id || undefined,
|
||||
skuId: skuId.value || undefined,
|
||||
beginAt: selectedStart.value,
|
||||
endAt,
|
||||
direction: direction.value,
|
||||
index: page,
|
||||
size: 15
|
||||
});
|
||||
if (token !== recordToken) return;
|
||||
const list = result.list || [];
|
||||
records.value.push(...list);
|
||||
page++;
|
||||
noMore.value = list.length < 15 || !(records.value.length < (result.total || 0));
|
||||
} catch (error) {
|
||||
if (token === recordToken) Message.error(getErrorMessage(error, "库存流水加载失败"));
|
||||
} finally {
|
||||
if (token === recordToken) recordsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
watch([() => props.storeId, skuId], () => {
|
||||
visible.value = false;
|
||||
recordToken++;
|
||||
});
|
||||
|
||||
defineExpose({ openDay });
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.records {
|
||||
height: 60vh;
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
flex-direction: column;
|
||||
|
||||
.directions {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
padding: .75rem;
|
||||
min-width: 0;
|
||||
flex-shrink: 0;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.summary {
|
||||
gap: .75rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
font-size: .875rem;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
|
||||
.in { color: var(--td-success-color); }
|
||||
.out { color: var(--td-error-color); }
|
||||
}
|
||||
|
||||
.record-list {
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
}
|
||||
|
||||
.list {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.item {
|
||||
padding: .625rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.icon {
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
display: inline-flex;
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
align-items: center;
|
||||
border-radius: 50%;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.record-title {
|
||||
gap: .25rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
max-width: 100%;
|
||||
font-size: .75rem;
|
||||
align-items: center;
|
||||
white-space: nowrap;
|
||||
|
||||
.actor {
|
||||
flex: 0 0 auto;
|
||||
color: var(--td-text-color-brand);
|
||||
}
|
||||
|
||||
.operation, .record-quantity {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.operation {
|
||||
color: var(--operation-color, var(--td-text-color-secondary));
|
||||
|
||||
&.initial-in {
|
||||
--operation-color: #2563eb;
|
||||
}
|
||||
|
||||
&.manual-in {
|
||||
--operation-color: #15803d;
|
||||
}
|
||||
|
||||
&.manual-out {
|
||||
--operation-color: #c2410c;
|
||||
}
|
||||
|
||||
&.manual-revoke {
|
||||
--operation-color: #be123c;
|
||||
}
|
||||
|
||||
&.order-reserve {
|
||||
--operation-color: #7c3aed;
|
||||
}
|
||||
|
||||
&.order-release {
|
||||
--operation-color: #0891b2;
|
||||
}
|
||||
|
||||
&.order-out {
|
||||
--operation-color: #dc2626;
|
||||
}
|
||||
|
||||
&.order-revoke {
|
||||
--operation-color: #4f46e5;
|
||||
}
|
||||
|
||||
&.return-in {
|
||||
--operation-color: #15803d;
|
||||
}
|
||||
|
||||
&.stocktake-gain {
|
||||
--operation-color: #0f766e;
|
||||
}
|
||||
|
||||
&.stocktake-loss {
|
||||
--operation-color: #a16207;
|
||||
}
|
||||
}
|
||||
|
||||
.product-name {
|
||||
overflow: hidden;
|
||||
flex: 0 1 auto;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.record-quantity {
|
||||
color: var(--td-text-color-secondary);
|
||||
}
|
||||
}
|
||||
|
||||
.description {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
font-size: .75rem;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.delta {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.positive {
|
||||
color: var(--td-success-color);
|
||||
}
|
||||
|
||||
.negative {
|
||||
color: var(--td-error-color);
|
||||
}
|
||||
}
|
||||
|
||||
:global(html.theme-dark) .records .operation {
|
||||
&.initial-in {
|
||||
--operation-color: #93c5fd;
|
||||
}
|
||||
|
||||
&.manual-in, &.return-in {
|
||||
--operation-color: #86efac;
|
||||
}
|
||||
|
||||
&.manual-out {
|
||||
--operation-color: #fdba74;
|
||||
}
|
||||
|
||||
&.manual-revoke {
|
||||
--operation-color: #fda4af;
|
||||
}
|
||||
|
||||
&.order-reserve {
|
||||
--operation-color: #c4b5fd;
|
||||
}
|
||||
|
||||
&.order-release {
|
||||
--operation-color: #67e8f9;
|
||||
}
|
||||
|
||||
&.order-out {
|
||||
--operation-color: #fca5a5;
|
||||
}
|
||||
|
||||
&.order-revoke {
|
||||
--operation-color: #a5b4fc;
|
||||
}
|
||||
|
||||
&.stocktake-gain {
|
||||
--operation-color: #5eead4;
|
||||
}
|
||||
|
||||
&.stocktake-loss {
|
||||
--operation-color: #fcd34d;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user