update ProductStockBatchConfigure.vue style
This commit is contained in:
@@ -1,99 +1,133 @@
|
||||
<template>
|
||||
<div v-can="permissionCodes.productStock.create" class="product-stock-batch-configure">
|
||||
<t-cell-group theme="card" class="batch-info">
|
||||
<t-form class="form" label-width="5rem">
|
||||
<t-form-item label="入库备注" required-mark>
|
||||
<t-textarea
|
||||
<t-form class="form" label-width="5rem">
|
||||
<t-form-item label="入库备注" required-mark>
|
||||
<div class="remark-wrap">
|
||||
<t-input
|
||||
v-model="productStockBatchStore.remark"
|
||||
:disabled="isSaving"
|
||||
borderless
|
||||
maxlength="500"
|
||||
autosize
|
||||
placeholder="请输入本批次入库备注"
|
||||
placeholder="本批次入库备注"
|
||||
@update:model-value="invalidateRequestNo"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<media-selector
|
||||
:model-value="globalAttachmentUrlList"
|
||||
v-model:photo-items="productStockBatchStore.attachmentItems"
|
||||
:upload="uploadPhotos"
|
||||
:edit-mode="true"
|
||||
:loading="isSaving"
|
||||
:show-remove="!isSaving"
|
||||
title="共用附件(未单独添加时使用)"
|
||||
@update:photo-items="invalidateRequestNo"
|
||||
<t-button
|
||||
type="button"
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:content="quickRemarkText"
|
||||
:disabled="isSaving"
|
||||
@click="applyQuickRemark"
|
||||
/>
|
||||
<div class="attachment-tip" v-text="'每个 SKU 都必须有附件;未单独添加时使用共用附件'" />
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-cell-group>
|
||||
<div v-if="productStockBatchStore.selectedItemList.length" class="item-list">
|
||||
<article
|
||||
</div>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<media-selector
|
||||
:model-value="globalAttachmentUrlList"
|
||||
v-model:photo-items="productStockBatchStore.attachmentItems"
|
||||
:upload="uploadPhotos"
|
||||
:edit-mode="true"
|
||||
:loading="isSaving"
|
||||
:show-remove="!isSaving"
|
||||
title="共有入库记录(无专有记录时使用)"
|
||||
@update:photo-items="invalidateRequestNo"
|
||||
/>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-form v-if="productStockBatchStore.selectedItemList.length" class="items form" label-width="0">
|
||||
<t-form-item
|
||||
v-for="item in productStockBatchStore.selectedItemList"
|
||||
:key="item.sku.id"
|
||||
class="sku-item"
|
||||
class="item"
|
||||
label-width="0"
|
||||
>
|
||||
<header class="sku-header">
|
||||
<div class="sku-title">
|
||||
<strong v-text="item.sku.name || '未命名 SKU'" />
|
||||
<span class="sku-note" v-text="getSkuNote(item)" />
|
||||
<div class="content">
|
||||
<div class="main">
|
||||
<div class="left">
|
||||
<t-image
|
||||
v-if="getProductPhotoURL(item.sku)"
|
||||
:src="getProductPhotoURL(item.sku)"
|
||||
:alt="item.productName || '产品图片'"
|
||||
fit="cover"
|
||||
class="avatar"
|
||||
/>
|
||||
<div
|
||||
v-else
|
||||
class="avatar fallback"
|
||||
v-text="(item.productName || item.sku.name || '产').slice(0, 1)"
|
||||
/>
|
||||
</div>
|
||||
<div class="right">
|
||||
<div class="header">
|
||||
<div class="title">
|
||||
<div class="name clip-text" v-text="item.productName || '未命名产品'" />
|
||||
<t-tag
|
||||
v-if="!isDefaultSku(item) && item.sku.name"
|
||||
size="small"
|
||||
theme="primary"
|
||||
variant="light-outline"
|
||||
:content="item.sku.name"
|
||||
/>
|
||||
</div>
|
||||
<t-button
|
||||
theme="danger"
|
||||
variant="text"
|
||||
size="extra-small"
|
||||
content="移除"
|
||||
:disabled="isSaving"
|
||||
@click.stop="removeItem(item.sku.id || '')"
|
||||
/>
|
||||
</div>
|
||||
<div class="input">
|
||||
<t-stepper
|
||||
v-model="item.quantity"
|
||||
class="quantity"
|
||||
:max="Number.MAX_SAFE_INTEGER"
|
||||
:min="0"
|
||||
size="large"
|
||||
:step="getProductQuantityStep(item.sku)"
|
||||
:integer="!item.sku.allowDecimalQuantity"
|
||||
:disabled="isSaving"
|
||||
theme="outline"
|
||||
@change="invalidateRequestNo"
|
||||
/>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
:content="getSelectedUnitName(item)"
|
||||
:disabled="isSaving"
|
||||
@click.stop="openUnitPicker(item)"
|
||||
/>
|
||||
<t-button
|
||||
size="extra-small"
|
||||
variant="outline"
|
||||
content="专有入库记录"
|
||||
:disabled="isSaving"
|
||||
:aria-expanded="isAttachmentVisible(item.sku.id || '')"
|
||||
@click.stop="toggleAttachmentVisibility(item.sku.id || '')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<t-button
|
||||
theme="danger"
|
||||
variant="text"
|
||||
size="small"
|
||||
content="移除"
|
||||
:disabled="isSaving"
|
||||
@click.stop="removeItem(item.sku.id || '')"
|
||||
<media-selector
|
||||
v-if="isAttachmentVisible(item.sku.id || '')"
|
||||
:model-value="getAttachmentUrlList(item.attachmentItems)"
|
||||
v-model:photo-items="item.attachmentItems"
|
||||
:upload="uploadPhotos"
|
||||
:edit-mode="true"
|
||||
title=""
|
||||
:loading="isSaving"
|
||||
:show-remove="!isSaving"
|
||||
@update:photo-items="invalidateRequestNo"
|
||||
/>
|
||||
</header>
|
||||
<div class="unit-selection">
|
||||
<strong v-text="'入库单位'" />
|
||||
<div class="unit-list" role="group" :aria-label="`选择${item.sku.name || 'SKU'}入库单位`">
|
||||
<t-button
|
||||
v-for="unit in getSelectableUnits(item)"
|
||||
:key="unit.id"
|
||||
size="small"
|
||||
:theme="item.skuUnitId === unit.id ? 'primary' : 'default'"
|
||||
:variant="item.skuUnitId === unit.id ? 'base' : 'outline'"
|
||||
:disabled="isSaving"
|
||||
:aria-pressed="item.skuUnitId === unit.id"
|
||||
@click="selectUnit(item, unit)"
|
||||
>
|
||||
<span v-text="unit.name || '未命名单位'" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<t-form class="form" label-width="5rem">
|
||||
<t-form-item label="数量" required-mark>
|
||||
<t-input
|
||||
v-model="item.quantity"
|
||||
:disabled="isSaving"
|
||||
type="number"
|
||||
align="right"
|
||||
borderless
|
||||
:placeholder="item.sku.allowDecimalQuantity ? '最多三位小数' : '请输入整数'"
|
||||
@update:model-value="invalidateRequestNo"
|
||||
/>
|
||||
</t-form-item>
|
||||
<t-form-item label-width="0">
|
||||
<media-selector
|
||||
:model-value="getAttachmentUrlList(item.attachmentItems)"
|
||||
v-model:photo-items="item.attachmentItems"
|
||||
:upload="uploadPhotos"
|
||||
:edit-mode="true"
|
||||
:loading="isSaving"
|
||||
:show-remove="!isSaving"
|
||||
title="SKU 附件(可选)"
|
||||
@update:photo-items="invalidateRequestNo"
|
||||
/>
|
||||
<div class="attachment-tip" v-text="'添加 SKU 附件后,该 SKU 不使用共用附件'" />
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</article>
|
||||
</div>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
<t-empty v-else description="没有已选 SKU,请返回重新选择" />
|
||||
<t-popup v-model="unitPickerVisible" placement="bottom">
|
||||
<t-picker v-model="unitPickerDraft" :columns="unitPickerOptions" title="选择入库单位" @cancel="unitPickerVisible = false" @confirm="confirmUnitPicker" />
|
||||
</t-popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -102,19 +136,21 @@ import { onBeforeRouteLeave } from "vue-router";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||
import { useNavBarStore } from "@/store/navBarStore";
|
||||
import { useProductStockBatchStore, type ProductStockBatchSelection } from "@/store/productStockBatchStore";
|
||||
import { type ProductStockBatchSelection, useProductStockBatchStore } from "@/store/productStockBatchStore";
|
||||
import MediaSelector from "@/components/mediaSelector/MediaSelector.vue";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import type { ProductStockManualInBatchItem, ProductStockManualInBatchRequest, ProductSkuUnit } from "@/types/Product";
|
||||
import type { ProductSkuUnit, ProductStockManualInBatchItem, ProductStockManualInBatchRequest } from "@/types/Product";
|
||||
import type { PhotoItem } from "@/types/Photo";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { createProductRequestNo } from "@/utils/product";
|
||||
import { createProductRequestNo, getProductPhotoURL, getProductQuantityStep } from "@/utils/product";
|
||||
import { emitListDataChanged, listDataEventKeys } from "@/utils/listDataEvents";
|
||||
import { Message } from "@/utils/message";
|
||||
import { permissionCodes } from "@/utils/permission";
|
||||
import { getCurrentStoreId } from "@/utils/store";
|
||||
import { uploadPhotoList } from "@/utils/photo";
|
||||
|
||||
type PickerValue = string | number;
|
||||
|
||||
defineOptions({ name: "ProductStockBatchConfigure" });
|
||||
|
||||
const router = useRouter();
|
||||
@@ -125,9 +161,18 @@ const userStore = useUserStore();
|
||||
const activeStoreId = ref("");
|
||||
const isSaving = ref(false);
|
||||
const uploadCount = ref(0);
|
||||
const visibleAttachmentSkuIdSet = ref<Set<string>>(new Set());
|
||||
const unitPickerVisible = ref(false);
|
||||
const unitPickerSkuId = ref("");
|
||||
const unitPickerDraft = ref<PickerValue[]>([]);
|
||||
const quickRemarkText = "正常入库";
|
||||
const globalAttachmentUrlList = computed(() => productStockBatchStore.attachmentItems.map(item => item.url));
|
||||
const unitPickerOptions = computed(() => {
|
||||
const item = productStockBatchStore.selectedItemList.find(candidate => candidate.sku.id === unitPickerSkuId.value);
|
||||
return getSelectableUnits(item).map(unit => ({ label: unit.name || "未命名单位", value: unit.id || "" }));
|
||||
});
|
||||
const canSubmit = computed(() => {
|
||||
const itemList = productStockBatchStore.selectedItemList;
|
||||
const itemList = getSubmitItemList();
|
||||
return !isSaving.value
|
||||
&& uploadCount.value === 0
|
||||
&& !!productStockBatchStore.remark.trim()
|
||||
@@ -139,8 +184,12 @@ function getSelectableUnits(item?: ProductStockBatchSelection): ProductSkuUnit[]
|
||||
return (item?.sku.unitList || []).filter(unit => unit.allowPurchase && !!unit.id);
|
||||
}
|
||||
|
||||
function getSkuNote(item: ProductStockBatchSelection): string {
|
||||
return [item.productName || "未命名产品", item.sku.specSummary].filter(Boolean).join(" · ");
|
||||
function getSelectedUnitName(item: ProductStockBatchSelection): string {
|
||||
return getSelectableUnits(item).find(unit => unit.id === item.skuUnitId)?.name || "选择入库单位";
|
||||
}
|
||||
|
||||
function isDefaultSku(item: ProductStockBatchSelection): boolean {
|
||||
return !item.sku.specValueIdList?.length;
|
||||
}
|
||||
|
||||
function getAttachmentUrlList(itemList: PhotoItem[]): string[] {
|
||||
@@ -159,6 +208,39 @@ function invalidateRequestNo(): void {
|
||||
productStockBatchStore.requestNo = "";
|
||||
}
|
||||
|
||||
function applyQuickRemark(): void {
|
||||
if (isSaving.value) {
|
||||
return;
|
||||
}
|
||||
productStockBatchStore.remark = quickRemarkText;
|
||||
invalidateRequestNo();
|
||||
}
|
||||
|
||||
function isAttachmentVisible(skuId: string): boolean {
|
||||
return visibleAttachmentSkuIdSet.value.has(skuId);
|
||||
}
|
||||
|
||||
function toggleAttachmentVisibility(skuId: string): void {
|
||||
if (isSaving.value || !skuId) {
|
||||
return;
|
||||
}
|
||||
const nextVisibleAttachmentSkuIdSet = new Set(visibleAttachmentSkuIdSet.value);
|
||||
if (nextVisibleAttachmentSkuIdSet.has(skuId)) {
|
||||
nextVisibleAttachmentSkuIdSet.delete(skuId);
|
||||
} else {
|
||||
nextVisibleAttachmentSkuIdSet.add(skuId);
|
||||
}
|
||||
visibleAttachmentSkuIdSet.value = nextVisibleAttachmentSkuIdSet;
|
||||
}
|
||||
|
||||
function isQuantityZero(item: ProductStockBatchSelection): boolean {
|
||||
return !item.quantity.trim() || Number(item.quantity) === 0;
|
||||
}
|
||||
|
||||
function getSubmitItemList(): ProductStockBatchSelection[] {
|
||||
return productStockBatchStore.selectedItemList.filter(item => !isQuantityZero(item));
|
||||
}
|
||||
|
||||
function isQuantityValid(item: ProductStockBatchSelection): boolean {
|
||||
if (!/^\d+(?:\.\d{1,3})?$/.test(item.quantity) || !(0 < Number(item.quantity))) {
|
||||
return false;
|
||||
@@ -197,6 +279,30 @@ function selectUnit(item: ProductStockBatchSelection, unit: ProductSkuUnit): voi
|
||||
}
|
||||
}
|
||||
|
||||
function openUnitPicker(item: ProductStockBatchSelection): void {
|
||||
if (isSaving.value) {
|
||||
return;
|
||||
}
|
||||
const unitList = getSelectableUnits(item);
|
||||
if (!unitList.length) {
|
||||
Message.warning("当前 SKU 没有可用于入库的单位");
|
||||
return;
|
||||
}
|
||||
unitPickerSkuId.value = item.sku.id || "";
|
||||
unitPickerDraft.value = [unitList.find(unit => unit.id === item.skuUnitId)?.id || unitList[0]?.id || ""];
|
||||
unitPickerVisible.value = true;
|
||||
}
|
||||
|
||||
function confirmUnitPicker(value: Array<string | number>): void {
|
||||
const item = productStockBatchStore.selectedItemList.find(candidate => candidate.sku.id === unitPickerSkuId.value);
|
||||
const skuUnitId = String(value[0] || "");
|
||||
const unit = item ? getSelectableUnits(item).find(candidate => candidate.id === skuUnitId) : undefined;
|
||||
if (item && unit) {
|
||||
selectUnit(item, unit);
|
||||
}
|
||||
unitPickerVisible.value = false;
|
||||
}
|
||||
|
||||
function removeItem(skuId: string): void {
|
||||
if (isSaving.value) {
|
||||
return;
|
||||
@@ -204,6 +310,13 @@ function removeItem(skuId: string): void {
|
||||
const itemIndex = productStockBatchStore.selectedItemList.findIndex(item => item.sku.id === skuId);
|
||||
if (-1 < itemIndex) {
|
||||
invalidateRequestNo();
|
||||
const nextVisibleAttachmentSkuIdSet = new Set(visibleAttachmentSkuIdSet.value);
|
||||
nextVisibleAttachmentSkuIdSet.delete(skuId);
|
||||
visibleAttachmentSkuIdSet.value = nextVisibleAttachmentSkuIdSet;
|
||||
if (unitPickerSkuId.value === skuId) {
|
||||
unitPickerVisible.value = false;
|
||||
unitPickerSkuId.value = "";
|
||||
}
|
||||
productStockBatchStore.selectedItemList.splice(itemIndex, 1);
|
||||
}
|
||||
}
|
||||
@@ -226,7 +339,12 @@ function validate(): boolean {
|
||||
Message.warning("请至少选择一个 SKU");
|
||||
return false;
|
||||
}
|
||||
for (const item of productStockBatchStore.selectedItemList) {
|
||||
const itemList = getSubmitItemList();
|
||||
if (!itemList.length) {
|
||||
Message.warning("请至少填写一个大于 0 的入库数量");
|
||||
return false;
|
||||
}
|
||||
for (const item of itemList) {
|
||||
if (!getSelectableUnits(item).some(unit => unit.id === item.skuUnitId)) {
|
||||
Message.warning((item.sku.name || "SKU") + ":请选择入库单位");
|
||||
return false;
|
||||
@@ -251,7 +369,7 @@ function validate(): boolean {
|
||||
}
|
||||
|
||||
function buildRequest(): ProductStockManualInBatchRequest {
|
||||
const itemList: ProductStockManualInBatchItem[] = productStockBatchStore.selectedItemList.map(item => {
|
||||
const itemList: ProductStockManualInBatchItem[] = getSubmitItemList().map(item => {
|
||||
const attachmentList = getAttachmentList(item.attachmentItems);
|
||||
return {
|
||||
skuId: item.sku.id || "",
|
||||
@@ -322,79 +440,99 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
<style scoped lang="less">
|
||||
.product-stock-batch-configure {
|
||||
gap: 1rem;
|
||||
padding: var(--app-nav-height) 0 1rem;
|
||||
padding: calc(var(--app-nav-height) + 1rem) 0 1rem 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.form {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.batch-info {
|
||||
padding: .25rem .75rem;
|
||||
}
|
||||
|
||||
.item-list {
|
||||
gap: 1rem;
|
||||
margin: 0 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sku-item {
|
||||
gap: 1rem;
|
||||
border: 1px solid var(--td-component-border);
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
background: var(--td-bg-color-container);
|
||||
border-radius: 1rem;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.sku-header {
|
||||
gap: .75rem;
|
||||
.remark-wrap {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.sku-title {
|
||||
gap: .25rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.items {
|
||||
margin: 0 1rem;
|
||||
overflow: hidden;
|
||||
background: var(--td-bg-color-container);
|
||||
box-shadow: var(--td-shadow-1);
|
||||
border-radius: 1rem;
|
||||
|
||||
strong {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: 1rem;
|
||||
.item {
|
||||
padding: .625rem;
|
||||
min-width: 0;
|
||||
|
||||
:deep(.t-form__controls),
|
||||
:deep(.t-form__controls-content) {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.content {
|
||||
gap: .5rem;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.main {
|
||||
gap: .5rem;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
|
||||
.left {
|
||||
display: flex;
|
||||
|
||||
.avatar {
|
||||
width: 3.5rem;
|
||||
height: 3.5rem;
|
||||
border-radius: .5rem;
|
||||
}
|
||||
}
|
||||
|
||||
.right {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
|
||||
.header {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
.title {
|
||||
gap: .375rem;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
min-width: 0;
|
||||
align-items: center;
|
||||
justify-content: start;
|
||||
}
|
||||
}
|
||||
|
||||
.input {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: end;
|
||||
}
|
||||
|
||||
.attachment-tip {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
margin-top: .25rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.sku-note {
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: .75rem;
|
||||
}
|
||||
|
||||
.unit-list {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.unit-selection {
|
||||
gap: .5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
strong {
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: .875rem;
|
||||
}
|
||||
}
|
||||
|
||||
.attachment-tip {
|
||||
color: var(--td-text-color-secondary);
|
||||
margin-top: .25rem;
|
||||
font-size: .75rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -102,7 +102,7 @@ import { useUserStore } from "timi-web-api";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
import ProductProfile from "@/pages/product/component/ProductProfile.vue";
|
||||
import ProductStockPackageSummary from "@/pages/product/component/ProductStockPackageSummary.vue";
|
||||
import ProductStockOperationPopup from "@/pages/product/ProductStockOperationPopup.vue";
|
||||
import ProductStockOperationPopup from "@/pages/product/component/ProductStockOperationPopup.vue";
|
||||
import { useNavBarStore } from "@/store/navBarStore";
|
||||
import type { Product, ProductSku, ProductStock, ProductSkuUnit, StockOperationType } from "@/types/Product";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
|
||||
@@ -54,7 +54,7 @@ export const useProductStockBatchStore = defineStore("product-stock-batch", () =
|
||||
const defaultUnit = item.sku.unitList?.find(unit => unit.allowPurchase && unit.id);
|
||||
selectedItemList.value.push({
|
||||
...item,
|
||||
quantity: "",
|
||||
quantity: "0",
|
||||
skuUnitId: defaultUnit?.id || "",
|
||||
attachmentItems: []
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user