add sku total
This commit is contained in:
@@ -16,7 +16,8 @@ import type {
|
|||||||
ProductStockManualRevokeRequest,
|
ProductStockManualRevokeRequest,
|
||||||
ProductStockPage,
|
ProductStockPage,
|
||||||
StockRecord,
|
StockRecord,
|
||||||
StockRecordPage
|
StockRecordPage,
|
||||||
|
StockRecordPageResult
|
||||||
} from "@/types/Product";
|
} from "@/types/Product";
|
||||||
import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store";
|
import { getCurrentStoreId, withCurrentStoreId } from "@/utils/store";
|
||||||
|
|
||||||
@@ -153,7 +154,7 @@ async function stocktakeLoss(request: ProductStockChangeRequest): Promise<Produc
|
|||||||
return await axios.post(`${STOCK_URI}/stocktake-loss`, withCurrentStoreId(request));
|
return await axios.post(`${STOCK_URI}/stocktake-loss`, withCurrentStoreId(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function recordList(page: StockRecordPage): Promise<ProductPageResult<StockRecord>> {
|
async function recordList(page: StockRecordPage): Promise<StockRecordPageResult> {
|
||||||
return await axios.post(`${STOCK_URI}/record/list`, withCurrentStoreId(page));
|
return await axios.post(`${STOCK_URI}/record/list`, withCurrentStoreId(page));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<template v-if="props.showField">
|
||||||
<t-form-item
|
<t-form-item
|
||||||
class="product-selector"
|
class="product-selector"
|
||||||
:label="props.label"
|
:label="props.label"
|
||||||
@@ -10,8 +11,9 @@
|
|||||||
<span class="picker-text" v-text="selectedProductName || props.placeholder" />
|
<span class="picker-text" v-text="selectedProductName || props.placeholder" />
|
||||||
</t-form-item>
|
</t-form-item>
|
||||||
<product-sku-form-item :sku="selectedSku" :unit="selectedUnit" />
|
<product-sku-form-item :sku="selectedSku" :unit="selectedUnit" />
|
||||||
|
</template>
|
||||||
<bottom-popup
|
<bottom-popup
|
||||||
v-model="visible"
|
v-model="popupVisible"
|
||||||
title="选择产品 SKU"
|
title="选择产品 SKU"
|
||||||
height="80vh"
|
height="80vh"
|
||||||
right-button-text=""
|
right-button-text=""
|
||||||
@@ -47,15 +49,18 @@ import { getProductPhotoURL } from "@/utils/product";
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
modelValue: ProductSkuSelectionValue | undefined;
|
modelValue: ProductSkuSelectionValue | undefined;
|
||||||
|
visible?: boolean;
|
||||||
|
showField?: boolean;
|
||||||
selectedProduct?: Product;
|
selectedProduct?: Product;
|
||||||
label?: string;
|
label?: string;
|
||||||
requiredMark?: boolean;
|
requiredMark?: boolean;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), { label: "产品", requiredMark: false, placeholder: "请选择产品 SKU" });
|
const props = withDefaults(defineProps<Props>(), { label: "产品", requiredMark: false, placeholder: "请选择产品 SKU", showField: true });
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
"update:modelValue": [value: Props["modelValue"]];
|
"update:modelValue": [value: Props["modelValue"]];
|
||||||
|
"update:visible": [value: boolean];
|
||||||
select: [selection: ProductSelection];
|
select: [selection: ProductSelection];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
@@ -79,7 +84,14 @@ const selectedSkuIdList = computed(() => props.modelValue?.skuId ? [props.modelV
|
|||||||
|
|
||||||
// ---------- 弹窗与产品列表 ----------
|
// ---------- 弹窗与产品列表 ----------
|
||||||
|
|
||||||
const visible = ref(false);
|
const internalVisible = ref(false);
|
||||||
|
const popupVisible = computed({
|
||||||
|
get: () => props.visible ?? internalVisible.value,
|
||||||
|
set: value => {
|
||||||
|
internalVisible.value = value;
|
||||||
|
emit("update:visible", value);
|
||||||
|
}
|
||||||
|
});
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const keyword = ref("");
|
const keyword = ref("");
|
||||||
const expandedProductKeyList = ref<Array<string | number>>([]);
|
const expandedProductKeyList = ref<Array<string | number>>([]);
|
||||||
@@ -94,8 +106,10 @@ const selectorItemList = computed<ProductSkuSelectorItem[]>(() => visibleProduct
|
|||||||
product
|
product
|
||||||
})));
|
})));
|
||||||
|
|
||||||
async function open(): Promise<void> {
|
watch(popupVisible, async visible => {
|
||||||
visible.value = true;
|
if (!visible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
expandedProductKeyList.value = [];
|
expandedProductKeyList.value = [];
|
||||||
if (loading.value || productList.value.length) {
|
if (loading.value || productList.value.length) {
|
||||||
return;
|
return;
|
||||||
@@ -108,10 +122,14 @@ async function open(): Promise<void> {
|
|||||||
} finally {
|
} finally {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function open(): void {
|
||||||
|
popupVisible.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function close(): void {
|
function close(): void {
|
||||||
visible.value = false;
|
popupVisible.value = false;
|
||||||
expandedProductKeyList.value = [];
|
expandedProductKeyList.value = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-can="permissionCodes.productStock.read" class="product-stock-record-list">
|
<div v-can="permissionCodes.productStock.read" class="product-stock-record-list">
|
||||||
<div class="filters glass">
|
<div class="filters glass">
|
||||||
|
<div class="search-row">
|
||||||
<t-input
|
<t-input
|
||||||
v-model="keyword"
|
v-model="keyword"
|
||||||
class="keyword"
|
class="keyword"
|
||||||
@@ -8,7 +9,20 @@
|
|||||||
borderless
|
borderless
|
||||||
clearable
|
clearable
|
||||||
placeholder="搜索产品名称(拼音)或编码"
|
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-menu class="menus">
|
||||||
<t-dropdown-item
|
<t-dropdown-item
|
||||||
v-model="dateFilterType"
|
v-model="dateFilterType"
|
||||||
@@ -27,7 +41,8 @@
|
|||||||
@scrolltolower="loadMore"
|
@scrolltolower="loadMore"
|
||||||
>
|
>
|
||||||
<div class="list-wrap">
|
<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
|
<t-cell
|
||||||
title="开始时间"
|
title="开始时间"
|
||||||
:note="dateRange[0] || '-'"
|
:note="dateRange[0] || '-'"
|
||||||
@@ -40,6 +55,11 @@
|
|||||||
arrow
|
arrow
|
||||||
@click="openEndTime"
|
@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>
|
||||||
<t-cell-group v-if="filteredProduct && filteredSku" theme="card">
|
<t-cell-group v-if="filteredProduct && filteredSku" theme="card">
|
||||||
<t-cell class="sku">
|
<t-cell class="sku">
|
||||||
@@ -144,6 +164,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</t-pull-down-refresh>
|
</t-pull-down-refresh>
|
||||||
</div>
|
</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-popup v-model="startVisible" placement="bottom">
|
||||||
<t-date-time-picker
|
<t-date-time-picker
|
||||||
v-if="startVisible"
|
v-if="startVisible"
|
||||||
@@ -176,11 +203,13 @@ import { PassTimeLabel, Time } from "timi-web";
|
|||||||
import { UserAPI } from "timi-web-api";
|
import { UserAPI } from "timi-web-api";
|
||||||
import { onBeforeRouteLeave } from "vue-router";
|
import { onBeforeRouteLeave } from "vue-router";
|
||||||
import ProductAPI from "@/api/ProductAPI";
|
import ProductAPI from "@/api/ProductAPI";
|
||||||
|
import ProductSelector from "@/components/productSelector/ProductSelector.vue";
|
||||||
import { useNavBarStore } from "@/store/navBarStore";
|
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 { buildPresetDateRange, parseDateFilterType, parseDateTime } from "@/utils/date";
|
||||||
import { getErrorMessage } from "@/utils/error";
|
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 { Message } from "@/utils/message";
|
||||||
import { permissionCodes } from "@/utils/permission";
|
import { permissionCodes } from "@/utils/permission";
|
||||||
import { getCustomerPhotoURL } from "@/utils/customer";
|
import { getCustomerPhotoURL } from "@/utils/customer";
|
||||||
@@ -197,6 +226,8 @@ const route = useRoute();
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const navBarStore = useNavBarStore();
|
const navBarStore = useNavBarStore();
|
||||||
const recordList = ref<StockRecord[]>([]);
|
const recordList = ref<StockRecord[]>([]);
|
||||||
|
const inBaseQuantityTotal = ref<number>();
|
||||||
|
const outBaseQuantityTotal = ref<number>();
|
||||||
const pageIndex = ref(0);
|
const pageIndex = ref(0);
|
||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
@@ -208,6 +239,8 @@ const returnToProductTab = getQueryText("returnTo") === "ProductTab";
|
|||||||
const filteredProduct = ref<Product>();
|
const filteredProduct = ref<Product>();
|
||||||
const filteredSku = ref<ProductSku>();
|
const filteredSku = ref<ProductSku>();
|
||||||
const filteredSkuUnitId = ref("");
|
const filteredSkuUnitId = ref("");
|
||||||
|
const selectedProductSku = ref<ProductSkuSelectionValue>();
|
||||||
|
const productSelectorVisible = ref(false);
|
||||||
const filteredSkuUnitList = computed(() => (filteredSku.value?.unitList || []).filter(unit => !!unit.id));
|
const filteredSkuUnitList = computed(() => (filteredSku.value?.unitList || []).filter(unit => !!unit.id));
|
||||||
const filteredSkuPhotoURL = computed(() => filteredSku.value ? getProductPhotoURL(filteredSku.value) || (filteredProduct.value ? getProductPhotoURL(filteredProduct.value) : "") : "");
|
const filteredSkuPhotoURL = computed(() => filteredSku.value ? getProductPhotoURL(filteredSku.value) || (filteredProduct.value ? getProductPhotoURL(filteredProduct.value) : "") : "");
|
||||||
const activeReservationRequested = getQueryText("activeReservationOnly") === "true";
|
const activeReservationRequested = getQueryText("activeReservationOnly") === "true";
|
||||||
@@ -231,6 +264,7 @@ const startVisible = ref(false);
|
|||||||
const endVisible = ref(false);
|
const endVisible = ref(false);
|
||||||
const activeReservationOnly = computed(() => activeReservationRequested && operationType.value === "ORDER_RESERVE");
|
const activeReservationOnly = computed(() => activeReservationRequested && operationType.value === "ORDER_RESERVE");
|
||||||
let keywordTimer: number | undefined;
|
let keywordTimer: number | undefined;
|
||||||
|
let skipNextKeywordChange = false;
|
||||||
let requestToken = 0;
|
let requestToken = 0;
|
||||||
const dateFilterLabel = computed(() => dateOptions.find(item => item.value === dateFilterType.value)?.label || "时间范围");
|
const dateFilterLabel = computed(() => dateOptions.find(item => item.value === dateFilterType.value)?.label || "时间范围");
|
||||||
const isCustomDate = computed(() => dateFilterType.value === "custom");
|
const isCustomDate = computed(() => dateFilterType.value === "custom");
|
||||||
@@ -317,6 +351,15 @@ function getStockQuantityText(record: StockRecord): string {
|
|||||||
return `${getProductQuantityText(record.quantity)}${unitText}`;
|
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 {
|
function getCustomerText(record: StockRecord): string {
|
||||||
return record.customer?.name || record.customer?.code || "未知客户";
|
return record.customer?.name || record.customer?.code || "未知客户";
|
||||||
}
|
}
|
||||||
@@ -385,6 +428,8 @@ async function loadMore(force = false): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const list = result.list || [];
|
const list = result.list || [];
|
||||||
|
inBaseQuantityTotal.value = result.inBaseQuantityTotal;
|
||||||
|
outBaseQuantityTotal.value = result.outBaseQuantityTotal;
|
||||||
recordList.value = recordList.value.concat(list);
|
recordList.value = recordList.value.concat(list);
|
||||||
total.value = result.total || 0;
|
total.value = result.total || 0;
|
||||||
pageIndex.value += 1;
|
pageIndex.value += 1;
|
||||||
@@ -401,6 +446,7 @@ async function loadSkuFilter(): Promise<void> {
|
|||||||
filteredProduct.value = undefined;
|
filteredProduct.value = undefined;
|
||||||
filteredSku.value = undefined;
|
filteredSku.value = undefined;
|
||||||
filteredSkuUnitId.value = "";
|
filteredSkuUnitId.value = "";
|
||||||
|
selectedProductSku.value = undefined;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const sku = await ProductAPI.skuDetail(skuId.value);
|
const sku = await ProductAPI.skuDetail(skuId.value);
|
||||||
@@ -411,6 +457,38 @@ async function loadSkuFilter(): Promise<void> {
|
|||||||
filteredSku.value = sku;
|
filteredSku.value = sku;
|
||||||
filteredProduct.value = product;
|
filteredProduct.value = product;
|
||||||
filteredSkuUnitId.value = getDefaultFilteredSkuUnitId();
|
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> {
|
async function selectOperationType(value: DropdownValue): Promise<void> {
|
||||||
@@ -527,6 +605,8 @@ async function reload(): Promise<void> {
|
|||||||
pageIndex.value = 0;
|
pageIndex.value = 0;
|
||||||
recordList.value = [];
|
recordList.value = [];
|
||||||
total.value = 0;
|
total.value = 0;
|
||||||
|
inBaseQuantityTotal.value = undefined;
|
||||||
|
outBaseQuantityTotal.value = undefined;
|
||||||
noMore.value = false;
|
noMore.value = false;
|
||||||
await loadMore(true);
|
await loadMore(true);
|
||||||
}
|
}
|
||||||
@@ -554,6 +634,10 @@ onMounted(async () => {
|
|||||||
onBeforeRouteLeave(() => navBarStore.setBackTo(undefined));
|
onBeforeRouteLeave(() => navBarStore.setBackTo(undefined));
|
||||||
|
|
||||||
watch(keyword, () => {
|
watch(keyword, () => {
|
||||||
|
if (skipNextKeywordChange) {
|
||||||
|
skipNextKeywordChange = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
window.clearTimeout(keywordTimer);
|
window.clearTimeout(keywordTimer);
|
||||||
keywordTimer = window.setTimeout(async () => {
|
keywordTimer = window.setTimeout(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -588,13 +672,26 @@ onUnmounted(() => {
|
|||||||
position: sticky;
|
position: sticky;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
|
.search-row {
|
||||||
|
gap: .5rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
.keyword {
|
.keyword {
|
||||||
--td-input-vertical-padding: .25rem 1rem;
|
--td-input-vertical-padding: .25rem 1rem;
|
||||||
|
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
border: 1px solid var(--td-component-border);
|
border: 1px solid var(--td-component-border);
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
border-radius: 1rem;
|
border-radius: 1rem;
|
||||||
|
|
||||||
|
.actions {
|
||||||
|
gap: .25rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.menus {
|
.menus {
|
||||||
@@ -615,7 +712,7 @@ onUnmounted(() => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|
||||||
.date-summary {
|
.summary {
|
||||||
|
|
||||||
:deep(.t-cell__title) {
|
:deep(.t-cell__title) {
|
||||||
flex: 0 0 4.5rem;
|
flex: 0 0 4.5rem;
|
||||||
|
|||||||
@@ -215,6 +215,11 @@ export type StockRecordPage = {
|
|||||||
size: number;
|
size: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type StockRecordPageResult = ProductPageResult<StockRecord> & {
|
||||||
|
inBaseQuantityTotal?: number;
|
||||||
|
outBaseQuantityTotal?: number;
|
||||||
|
};
|
||||||
|
|
||||||
export type ProductStockChangeRequest = {
|
export type ProductStockChangeRequest = {
|
||||||
requestNo: string;
|
requestNo: string;
|
||||||
storeId?: string;
|
storeId?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user