add sku total
This commit is contained in:
@@ -16,7 +16,8 @@ import type {
|
||||
ProductStockManualRevokeRequest,
|
||||
ProductStockPage,
|
||||
StockRecord,
|
||||
StockRecordPage
|
||||
StockRecordPage,
|
||||
StockRecordPageResult
|
||||
} from "@/types/Product";
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
<template>
|
||||
<t-form-item
|
||||
class="product-selector"
|
||||
:label="props.label"
|
||||
:required-mark="props.requiredMark"
|
||||
content-align="right"
|
||||
arrow
|
||||
@click="open"
|
||||
>
|
||||
<span class="picker-text" v-text="selectedProductName || props.placeholder" />
|
||||
</t-form-item>
|
||||
<product-sku-form-item :sku="selectedSku" :unit="selectedUnit" />
|
||||
<template v-if="props.showField">
|
||||
<t-form-item
|
||||
class="product-selector"
|
||||
:label="props.label"
|
||||
:required-mark="props.requiredMark"
|
||||
content-align="right"
|
||||
arrow
|
||||
@click="open"
|
||||
>
|
||||
<span class="picker-text" v-text="selectedProductName || props.placeholder" />
|
||||
</t-form-item>
|
||||
<product-sku-form-item :sku="selectedSku" :unit="selectedUnit" />
|
||||
</template>
|
||||
<bottom-popup
|
||||
v-model="visible"
|
||||
v-model="popupVisible"
|
||||
title="选择产品 SKU"
|
||||
height="80vh"
|
||||
right-button-text=""
|
||||
@@ -47,15 +49,18 @@ import { getProductPhotoURL } from "@/utils/product";
|
||||
|
||||
interface Props {
|
||||
modelValue: ProductSkuSelectionValue | undefined;
|
||||
visible?: boolean;
|
||||
showField?: boolean;
|
||||
selectedProduct?: Product;
|
||||
label?: string;
|
||||
requiredMark?: boolean;
|
||||
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<{
|
||||
"update:modelValue": [value: Props["modelValue"]];
|
||||
"update:visible": [value: boolean];
|
||||
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 keyword = ref("");
|
||||
const expandedProductKeyList = ref<Array<string | number>>([]);
|
||||
@@ -94,8 +106,10 @@ const selectorItemList = computed<ProductSkuSelectorItem[]>(() => visibleProduct
|
||||
product
|
||||
})));
|
||||
|
||||
async function open(): Promise<void> {
|
||||
visible.value = true;
|
||||
watch(popupVisible, async visible => {
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
expandedProductKeyList.value = [];
|
||||
if (loading.value || productList.value.length) {
|
||||
return;
|
||||
@@ -108,10 +122,14 @@ async function open(): Promise<void> {
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
function open(): void {
|
||||
popupVisible.value = true;
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
visible.value = false;
|
||||
popupVisible.value = false;
|
||||
expandedProductKeyList.value = [];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
<template>
|
||||
<div v-can="permissionCodes.productStock.read" class="product-stock-record-list">
|
||||
<div class="filters glass">
|
||||
<t-input
|
||||
v-model="keyword"
|
||||
class="keyword"
|
||||
type="search"
|
||||
borderless
|
||||
clearable
|
||||
placeholder="搜索产品名称(拼音)或编码"
|
||||
/>
|
||||
<div class="search-row">
|
||||
<t-input
|
||||
v-model="keyword"
|
||||
class="keyword"
|
||||
type="search"
|
||||
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,19 +41,25 @@
|
||||
@scrolltolower="loadMore"
|
||||
>
|
||||
<div class="list-wrap">
|
||||
<t-cell-group v-if="isCustomDate" class="date-summary" theme="card">
|
||||
<t-cell
|
||||
title="开始时间"
|
||||
:note="dateRange[0] || '-'"
|
||||
arrow
|
||||
@click="openStartTime"
|
||||
/>
|
||||
<t-cell
|
||||
title="结束时间"
|
||||
:note="dateRange[1] || '-'"
|
||||
arrow
|
||||
@click="openEndTime"
|
||||
/>
|
||||
<t-cell-group v-if="isCustomDate || filteredSku" class="summary" theme="card">
|
||||
<template v-if="isCustomDate">
|
||||
<t-cell
|
||||
title="开始时间"
|
||||
:note="dateRange[0] || '-'"
|
||||
arrow
|
||||
@click="openStartTime"
|
||||
/>
|
||||
<t-cell
|
||||
title="结束时间"
|
||||
:note="dateRange[1] || '-'"
|
||||
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;
|
||||
|
||||
@@ -215,6 +215,11 @@ export type StockRecordPage = {
|
||||
size: number;
|
||||
};
|
||||
|
||||
export type StockRecordPageResult = ProductPageResult<StockRecord> & {
|
||||
inBaseQuantityTotal?: number;
|
||||
outBaseQuantityTotal?: number;
|
||||
};
|
||||
|
||||
export type ProductStockChangeRequest = {
|
||||
requestNo: string;
|
||||
storeId?: string;
|
||||
|
||||
Reference in New Issue
Block a user