|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div v-can="permissionCodes.productStock.read" class="product-stock-record-list">
|
|
|
|
|
<div class="filters glass">
|
|
|
|
|
<div class="search-row">
|
|
|
|
|
<t-input
|
|
|
|
|
v-model="keyword"
|
|
|
|
|
class="keyword"
|
|
|
|
@@ -8,7 +9,20 @@
|
|
|
|
|
borderless
|
|
|
|
|
clearable
|
|
|
|
|
placeholder="搜索产品名称(拼音)或编码"
|
|
|
|
|
>
|
|
|
|
|
<template #suffix-icon>
|
|
|
|
|
<div class="actions">
|
|
|
|
|
<t-button
|
|
|
|
|
size="extra-small"
|
|
|
|
|
theme="primary"
|
|
|
|
|
variant="outline"
|
|
|
|
|
content="选择产品"
|
|
|
|
|
@click.stop="productSelectorVisible = true"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</t-input>
|
|
|
|
|
</div>
|
|
|
|
|
<t-dropdown-menu class="menus">
|
|
|
|
|
<t-dropdown-item
|
|
|
|
|
v-model="dateFilterType"
|
|
|
|
@@ -27,7 +41,8 @@
|
|
|
|
|
@scrolltolower="loadMore"
|
|
|
|
|
>
|
|
|
|
|
<div class="list-wrap">
|
|
|
|
|
<t-cell-group v-if="isCustomDate" class="date-summary" theme="card">
|
|
|
|
|
<t-cell-group v-if="isCustomDate || filteredSku" class="summary" theme="card">
|
|
|
|
|
<template v-if="isCustomDate">
|
|
|
|
|
<t-cell
|
|
|
|
|
title="开始时间"
|
|
|
|
|
:note="dateRange[0] || '-'"
|
|
|
|
@@ -40,6 +55,11 @@
|
|
|
|
|
arrow
|
|
|
|
|
@click="openEndTime"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-if="filteredSku">
|
|
|
|
|
<t-cell title="累计入库" :note="getStockSummaryText(inBaseQuantityTotal)" />
|
|
|
|
|
<t-cell title="累计出库" :note="getStockSummaryText(outBaseQuantityTotal)" />
|
|
|
|
|
</template>
|
|
|
|
|
</t-cell-group>
|
|
|
|
|
<t-cell-group v-if="filteredProduct && filteredSku" theme="card">
|
|
|
|
|
<t-cell class="sku">
|
|
|
|
@@ -144,6 +164,13 @@
|
|
|
|
|
</div>
|
|
|
|
|
</t-pull-down-refresh>
|
|
|
|
|
</div>
|
|
|
|
|
<product-selector
|
|
|
|
|
v-model="selectedProductSku"
|
|
|
|
|
v-model:visible="productSelectorVisible"
|
|
|
|
|
:selected-product="filteredProduct"
|
|
|
|
|
:show-field="false"
|
|
|
|
|
@select="handleProductSelect"
|
|
|
|
|
/>
|
|
|
|
|
<t-popup v-model="startVisible" placement="bottom">
|
|
|
|
|
<t-date-time-picker
|
|
|
|
|
v-if="startVisible"
|
|
|
|
@@ -176,11 +203,13 @@ import { PassTimeLabel, Time } from "timi-web";
|
|
|
|
|
import { UserAPI } from "timi-web-api";
|
|
|
|
|
import { onBeforeRouteLeave } from "vue-router";
|
|
|
|
|
import ProductAPI from "@/api/ProductAPI";
|
|
|
|
|
import ProductSelector from "@/components/productSelector/ProductSelector.vue";
|
|
|
|
|
import { useNavBarStore } from "@/store/navBarStore";
|
|
|
|
|
import type { Product, ProductSku, StockOperationType, StockRecord, StockRecordDirection } from "@/types/Product";
|
|
|
|
|
import type { Product, ProductSelection, ProductSku, StockOperationType, StockRecord, StockRecordDirection } from "@/types/Product";
|
|
|
|
|
import type { ProductSkuSelectionValue } from "@/types/ProductSkuSelection";
|
|
|
|
|
import { buildPresetDateRange, parseDateFilterType, parseDateTime } from "@/utils/date";
|
|
|
|
|
import { getErrorMessage } from "@/utils/error";
|
|
|
|
|
import { getProductPhotoURL, getProductQuantityText, getProductTypeText, getStockOperationText } from "@/utils/product";
|
|
|
|
|
import { getProductBaseUnitName, getProductPhotoURL, getProductQuantityText, getProductTypeText, getStockOperationText } from "@/utils/product";
|
|
|
|
|
import { Message } from "@/utils/message";
|
|
|
|
|
import { permissionCodes } from "@/utils/permission";
|
|
|
|
|
import { getCustomerPhotoURL } from "@/utils/customer";
|
|
|
|
@@ -197,6 +226,8 @@ const route = useRoute();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const navBarStore = useNavBarStore();
|
|
|
|
|
const recordList = ref<StockRecord[]>([]);
|
|
|
|
|
const inBaseQuantityTotal = ref<number>();
|
|
|
|
|
const outBaseQuantityTotal = ref<number>();
|
|
|
|
|
const pageIndex = ref(0);
|
|
|
|
|
const total = ref(0);
|
|
|
|
|
const loading = ref(false);
|
|
|
|
@@ -208,6 +239,8 @@ const returnToProductTab = getQueryText("returnTo") === "ProductTab";
|
|
|
|
|
const filteredProduct = ref<Product>();
|
|
|
|
|
const filteredSku = ref<ProductSku>();
|
|
|
|
|
const filteredSkuUnitId = ref("");
|
|
|
|
|
const selectedProductSku = ref<ProductSkuSelectionValue>();
|
|
|
|
|
const productSelectorVisible = ref(false);
|
|
|
|
|
const filteredSkuUnitList = computed(() => (filteredSku.value?.unitList || []).filter(unit => !!unit.id));
|
|
|
|
|
const filteredSkuPhotoURL = computed(() => filteredSku.value ? getProductPhotoURL(filteredSku.value) || (filteredProduct.value ? getProductPhotoURL(filteredProduct.value) : "") : "");
|
|
|
|
|
const activeReservationRequested = getQueryText("activeReservationOnly") === "true";
|
|
|
|
@@ -231,6 +264,7 @@ const startVisible = ref(false);
|
|
|
|
|
const endVisible = ref(false);
|
|
|
|
|
const activeReservationOnly = computed(() => activeReservationRequested && operationType.value === "ORDER_RESERVE");
|
|
|
|
|
let keywordTimer: number | undefined;
|
|
|
|
|
let skipNextKeywordChange = false;
|
|
|
|
|
let requestToken = 0;
|
|
|
|
|
const dateFilterLabel = computed(() => dateOptions.find(item => item.value === dateFilterType.value)?.label || "时间范围");
|
|
|
|
|
const isCustomDate = computed(() => dateFilterType.value === "custom");
|
|
|
|
@@ -317,6 +351,15 @@ function getStockQuantityText(record: StockRecord): string {
|
|
|
|
|
return `${getProductQuantityText(record.quantity)}${unitText}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getStockSummaryText(value?: number): string {
|
|
|
|
|
if (value === undefined) {
|
|
|
|
|
return loading.value ? "统计中" : "-";
|
|
|
|
|
}
|
|
|
|
|
const quantity = getProductQuantityText(value);
|
|
|
|
|
const unitName = getProductBaseUnitName(filteredSku.value);
|
|
|
|
|
return unitName ? `${quantity} ${unitName}` : quantity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getCustomerText(record: StockRecord): string {
|
|
|
|
|
return record.customer?.name || record.customer?.code || "未知客户";
|
|
|
|
|
}
|
|
|
|
@@ -385,6 +428,8 @@ async function loadMore(force = false): Promise<void> {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const list = result.list || [];
|
|
|
|
|
inBaseQuantityTotal.value = result.inBaseQuantityTotal;
|
|
|
|
|
outBaseQuantityTotal.value = result.outBaseQuantityTotal;
|
|
|
|
|
recordList.value = recordList.value.concat(list);
|
|
|
|
|
total.value = result.total || 0;
|
|
|
|
|
pageIndex.value += 1;
|
|
|
|
@@ -401,6 +446,7 @@ async function loadSkuFilter(): Promise<void> {
|
|
|
|
|
filteredProduct.value = undefined;
|
|
|
|
|
filteredSku.value = undefined;
|
|
|
|
|
filteredSkuUnitId.value = "";
|
|
|
|
|
selectedProductSku.value = undefined;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const sku = await ProductAPI.skuDetail(skuId.value);
|
|
|
|
@@ -411,6 +457,38 @@ async function loadSkuFilter(): Promise<void> {
|
|
|
|
|
filteredSku.value = sku;
|
|
|
|
|
filteredProduct.value = product;
|
|
|
|
|
filteredSkuUnitId.value = getDefaultFilteredSkuUnitId();
|
|
|
|
|
selectedProductSku.value = { skuId: sku.id || skuId.value, skuUnitId: filteredSkuUnitId.value };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleProductSelect(selection: ProductSelection): Promise<void> {
|
|
|
|
|
const selectedProductId = selection.product.id || selection.sku.productId || "";
|
|
|
|
|
const selectedSkuId = selection.sku.id || "";
|
|
|
|
|
if (!selectedSkuId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
window.clearTimeout(keywordTimer);
|
|
|
|
|
const selectedKeyword = selection.product.name || selection.product.code || "";
|
|
|
|
|
if (keyword.value !== selectedKeyword) {
|
|
|
|
|
skipNextKeywordChange = true;
|
|
|
|
|
keyword.value = selectedKeyword;
|
|
|
|
|
}
|
|
|
|
|
await router.replace({
|
|
|
|
|
name: "ProductStockRecordList",
|
|
|
|
|
query: {
|
|
|
|
|
...buildFilterQuery(),
|
|
|
|
|
productId: selectedProductId,
|
|
|
|
|
skuId: selectedSkuId
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
filteredProduct.value = selection.product;
|
|
|
|
|
filteredSku.value = selection.sku;
|
|
|
|
|
filteredSkuUnitId.value = selection.unit.id || "";
|
|
|
|
|
selectedProductSku.value = { skuId: selectedSkuId, skuUnitId: filteredSkuUnitId.value };
|
|
|
|
|
await reload();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
Message.error(getErrorMessage(error, "库存流水加载失败"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function selectOperationType(value: DropdownValue): Promise<void> {
|
|
|
|
@@ -527,6 +605,8 @@ async function reload(): Promise<void> {
|
|
|
|
|
pageIndex.value = 0;
|
|
|
|
|
recordList.value = [];
|
|
|
|
|
total.value = 0;
|
|
|
|
|
inBaseQuantityTotal.value = undefined;
|
|
|
|
|
outBaseQuantityTotal.value = undefined;
|
|
|
|
|
noMore.value = false;
|
|
|
|
|
await loadMore(true);
|
|
|
|
|
}
|
|
|
|
@@ -554,6 +634,10 @@ onMounted(async () => {
|
|
|
|
|
onBeforeRouteLeave(() => navBarStore.setBackTo(undefined));
|
|
|
|
|
|
|
|
|
|
watch(keyword, () => {
|
|
|
|
|
if (skipNextKeywordChange) {
|
|
|
|
|
skipNextKeywordChange = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
window.clearTimeout(keywordTimer);
|
|
|
|
|
keywordTimer = window.setTimeout(async () => {
|
|
|
|
|
try {
|
|
|
|
@@ -588,13 +672,26 @@ onUnmounted(() => {
|
|
|
|
|
position: sticky;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
|
|
.search-row {
|
|
|
|
|
gap: .5rem;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.keyword {
|
|
|
|
|
--td-input-vertical-padding: .25rem 1rem;
|
|
|
|
|
|
|
|
|
|
flex: 1;
|
|
|
|
|
min-width: 0;
|
|
|
|
|
border: 1px solid var(--td-component-border);
|
|
|
|
|
z-index: 2;
|
|
|
|
|
border-radius: 1rem;
|
|
|
|
|
|
|
|
|
|
.actions {
|
|
|
|
|
gap: .25rem;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.menus {
|
|
|
|
@@ -615,7 +712,7 @@ onUnmounted(() => {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
|
|
|
|
.date-summary {
|
|
|
|
|
.summary {
|
|
|
|
|
|
|
|
|
|
:deep(.t-cell__title) {
|
|
|
|
|
flex: 0 0 4.5rem;
|
|
|
|
|