chore: 提交当前代码修改
This commit is contained in:
parent
aea322298b
commit
ebc955a7aa
@ -137,6 +137,14 @@ export default {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
isSystemApi: true
|
isSystemApi: true
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
inventory: {
|
||||||
|
transferLocation: {
|
||||||
|
path: "storage.inventory.transferLocation",
|
||||||
|
auth: true,
|
||||||
|
method: "POST",
|
||||||
|
isSystemApi: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
stock: {
|
stock: {
|
||||||
|
|||||||
@ -57,7 +57,7 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view v-else class="list-wrap">
|
<view v-else class="list-wrap">
|
||||||
<view class="goods-item" v-for="(item, index) in list" :key="item.id || index">
|
<view class="goods-item" v-for="(item, index) in list" :key="getGoodsItemKey(item, index)">
|
||||||
<view class="item-summary" :style="{ zIndex: 10 + index }">
|
<view class="item-summary" :style="{ zIndex: 10 + index }">
|
||||||
<view class="item-title-row">
|
<view class="item-title-row">
|
||||||
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
|
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
|
||||||
@ -162,7 +162,7 @@
|
|||||||
>
|
>
|
||||||
<text class="storage-col storage-col--space">{{ getStorageSpaceText(storageItem) }}</text>
|
<text class="storage-col storage-col--space">{{ getStorageSpaceText(storageItem) }}</text>
|
||||||
<text class="storage-col storage-col--qty">{{ getStorageQuantityText(storageItem) }}</text>
|
<text class="storage-col storage-col--qty">{{ getStorageQuantityText(storageItem) }}</text>
|
||||||
<text class="storage-col storage-col--qty storage-col--highlight">{{ getStorageAvailableText(storageItem) }}</text>
|
<text class="storage-col storage-col--qty storage-col--highlight storage-col--action" @click.stop="openRelocationPage(item, storageItem, 'available')">{{ getStorageAvailableText(storageItem) }}</text>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
<view v-else class="storage-table__row storage-table__row--empty">
|
<view v-else class="storage-table__row storage-table__row--empty">
|
||||||
@ -202,7 +202,7 @@
|
|||||||
<text class="storage-col storage-col--batch">{{ getBatchNumberBySource(storageItem, item) }}</text>
|
<text class="storage-col storage-col--batch">{{ getBatchNumberBySource(storageItem, item) }}</text>
|
||||||
<text class="storage-col storage-col--space">{{ getStorageSpaceText(storageItem) }}</text>
|
<text class="storage-col storage-col--space">{{ getStorageSpaceText(storageItem) }}</text>
|
||||||
<text class="storage-col storage-col--qty">{{ getStorageQuantityText(storageItem) }}</text>
|
<text class="storage-col storage-col--qty">{{ getStorageQuantityText(storageItem) }}</text>
|
||||||
<text class="storage-col storage-col--qty storage-col--highlight">{{ getStorageAvailableText(storageItem) }}</text>
|
<text class="storage-col storage-col--qty storage-col--highlight storage-col--action" @click.stop="openRelocationPage(item, storageItem, 'available')">{{ getStorageAvailableText(storageItem) }}</text>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
<view v-else class="storage-table__row storage-table__row--empty">
|
<view v-else class="storage-table__row storage-table__row--empty">
|
||||||
@ -289,6 +289,15 @@
|
|||||||
onResult: this.handleBroadcastResult
|
onResult: this.handleBroadcastResult
|
||||||
});
|
});
|
||||||
this.safeDispatchBroadcast('resume');
|
this.safeDispatchBroadcast('resume');
|
||||||
|
const relocationRefreshMark = Number(uni.getStorageSync('product_query_need_refresh') || 0);
|
||||||
|
if (relocationRefreshMark > 0) {
|
||||||
|
uni.removeStorageSync('product_query_need_refresh');
|
||||||
|
const keyword = this.normalizeKeyword(this.keyword);
|
||||||
|
if (keyword) {
|
||||||
|
this.keyword = keyword;
|
||||||
|
this.handleSearch();
|
||||||
|
}
|
||||||
|
}
|
||||||
const cachedTop = Number(uni.getStorageSync('product_query_scroll_top') || 0);
|
const cachedTop = Number(uni.getStorageSync('product_query_scroll_top') || 0);
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
const top = cachedTop > 0 ? cachedTop : 0;
|
const top = cachedTop > 0 ? cachedTop : 0;
|
||||||
@ -309,6 +318,22 @@
|
|||||||
this.safeDispatchBroadcast('stop');
|
this.safeDispatchBroadcast('stop');
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getGoodsItemKey(item, index) {
|
||||||
|
if (!item || typeof item !== 'object') {
|
||||||
|
return `goods_${index}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const baseKey = item.id
|
||||||
|
|| item.goods_id
|
||||||
|
|| item.item_id
|
||||||
|
|| item.goods_code
|
||||||
|
|| item.item_code
|
||||||
|
|| item.barcode
|
||||||
|
|| item.code
|
||||||
|
|| 'unknown';
|
||||||
|
|
||||||
|
return `goods_${baseKey}_${index}`;
|
||||||
|
},
|
||||||
safeDispatchBroadcast(action, payload) {
|
safeDispatchBroadcast(action, payload) {
|
||||||
try {
|
try {
|
||||||
const task = this.$store.dispatch(`broadcast/${action}`, payload);
|
const task = this.$store.dispatch(`broadcast/${action}`, payload);
|
||||||
@ -825,6 +850,33 @@
|
|||||||
is_batch: this.queryMode === 'batch'
|
is_batch: this.queryMode === 'batch'
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
buildListWhereParams(keyword) {
|
||||||
|
const where = {};
|
||||||
|
|
||||||
|
if (this.isBarcodeLike(keyword)) {
|
||||||
|
where.barcode = {
|
||||||
|
operator: 'like',
|
||||||
|
value: keyword,
|
||||||
|
type: 'string'
|
||||||
|
};
|
||||||
|
} else if (keyword) {
|
||||||
|
where.item_name = {
|
||||||
|
operator: 'like',
|
||||||
|
value: keyword,
|
||||||
|
type: 'string'
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return where;
|
||||||
|
},
|
||||||
|
buildListQueryParams(keyword) {
|
||||||
|
return {
|
||||||
|
keyword,
|
||||||
|
with_stock: true,
|
||||||
|
is_batch: this.queryMode === 'batch',
|
||||||
|
where: this.buildListWhereParams(keyword)
|
||||||
|
};
|
||||||
|
},
|
||||||
setQueryMode(nextMode) {
|
setQueryMode(nextMode) {
|
||||||
if (!nextMode || nextMode === this.queryMode) {
|
if (!nextMode || nextMode === this.queryMode) {
|
||||||
return;
|
return;
|
||||||
@ -1039,6 +1091,112 @@
|
|||||||
?? item.usable_quantity
|
?? item.usable_quantity
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
getStorageSpaceCode(item) {
|
||||||
|
if (!item || typeof item !== 'object') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return item.space_barcode
|
||||||
|
|| item.space_code
|
||||||
|
|| item.space?.barcode
|
||||||
|
|| item.space?.code
|
||||||
|
|| item.space?.space_code
|
||||||
|
|| item.location_code
|
||||||
|
|| item.position_code
|
||||||
|
|| '';
|
||||||
|
},
|
||||||
|
getRelocationQuantityByType(item, quantityType = 'available') {
|
||||||
|
if (!item || typeof item !== 'object') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const value = quantityType === 'stock'
|
||||||
|
? (item.quantity ?? item.actual_quantity ?? item.stock ?? item.total_quantity ?? item.qty)
|
||||||
|
: (item.available_quantity ?? item.movable_quantity ?? item.moveable_quantity ?? item.can_move_quantity ?? item.free_quantity ?? item.usable_quantity);
|
||||||
|
|
||||||
|
return value === null || value === undefined || value === '' ? '' : String(value);
|
||||||
|
},
|
||||||
|
normalizePositiveId(value) {
|
||||||
|
const numericValue = Number(value);
|
||||||
|
if (!Number.isFinite(numericValue)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = Math.trunc(numericValue);
|
||||||
|
return normalized > 0 ? normalized : null;
|
||||||
|
},
|
||||||
|
getRelocationStorageId(item) {
|
||||||
|
if (!item || typeof item !== 'object') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const directCandidates = [
|
||||||
|
item.storage_id,
|
||||||
|
item.inventory_id,
|
||||||
|
item.stock_id,
|
||||||
|
item.storage_record_id,
|
||||||
|
item.stock_record_id,
|
||||||
|
item.warehouse_storage_id,
|
||||||
|
item.warehouse_stock_id,
|
||||||
|
item.record_id
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let i = 0; i < directCandidates.length; i++) {
|
||||||
|
const normalized = this.normalizePositiveId(directCandidates[i]);
|
||||||
|
if (normalized) {
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallbackId = this.normalizePositiveId(item.id);
|
||||||
|
if (!fallbackId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const spaceId = this.normalizePositiveId(item.space_id || item.space?.id);
|
||||||
|
if (spaceId && fallbackId === spaceId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallbackId;
|
||||||
|
},
|
||||||
|
openRelocationPage(productItem, storageItem, quantityType = 'available') {
|
||||||
|
if (!productItem || typeof productItem !== 'object' || !storageItem || typeof storageItem !== 'object') {
|
||||||
|
uni.showToast({
|
||||||
|
title: '缺少移库数据',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const relocationStorageId = this.getRelocationStorageId(storageItem) || this.getRelocationStorageId(productItem);
|
||||||
|
if (!relocationStorageId) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '未获取到库存记录ID',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const cacheKey = `relocation_prefill_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
||||||
|
uni.setStorageSync(cacheKey, {
|
||||||
|
stock: {
|
||||||
|
...productItem,
|
||||||
|
...storageItem,
|
||||||
|
relocation_storage_id: relocationStorageId
|
||||||
|
},
|
||||||
|
sourceSpace: {
|
||||||
|
id: storageItem.space_id || storageItem.space?.id || null,
|
||||||
|
name: this.getStorageSpaceText(storageItem),
|
||||||
|
code: this.getStorageSpaceCode(storageItem)
|
||||||
|
},
|
||||||
|
moveQuantity: this.getRelocationQuantityByType(storageItem, quantityType)
|
||||||
|
});
|
||||||
|
|
||||||
|
uni.navigateTo({
|
||||||
|
url: `/pages/work/storage/relocation?cacheKey=${cacheKey}`
|
||||||
|
});
|
||||||
|
},
|
||||||
getExtraImageCount(item) {
|
getExtraImageCount(item) {
|
||||||
const total = this.getImageList(item).length;
|
const total = this.getImageList(item).length;
|
||||||
return total > 4 ? total - 4 : 0;
|
return total > 4 ? total - 4 : 0;
|
||||||
@ -1089,13 +1247,15 @@
|
|||||||
|
|
||||||
const isBarcodeKeyword = this.isBarcodeLike(keyword);
|
const isBarcodeKeyword = this.isBarcodeLike(keyword);
|
||||||
const queryParams = this.buildQueryParams(keyword);
|
const queryParams = this.buildQueryParams(keyword);
|
||||||
|
const listQueryParams = this.buildListQueryParams(keyword);
|
||||||
console.log('[ProductQuery] 搜索参数:', queryParams);
|
console.log('[ProductQuery] 搜索参数:', queryParams);
|
||||||
|
console.log('[ProductQuery] 列表参数:', listQueryParams);
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
try {
|
try {
|
||||||
const [searchRes, listRes] = await Promise.all([
|
const [searchRes, listRes] = await Promise.all([
|
||||||
this.$http('stock.warehouse.search', queryParams),
|
this.$http('stock.warehouse.search', queryParams),
|
||||||
this.$http('stock.warehouse.list', queryParams).catch(error => {
|
this.$http('stock.warehouse.list', listQueryParams).catch(error => {
|
||||||
console.warn('[ProductQuery] stock.warehouse.list 调用失败:', error);
|
console.warn('[ProductQuery] stock.warehouse.list 调用失败:', error);
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
@ -1625,6 +1785,17 @@
|
|||||||
flex: none;
|
flex: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.storage-col--action {
|
||||||
|
color: #2979ff;
|
||||||
|
font-weight: 600;
|
||||||
|
text-decoration: underline;
|
||||||
|
text-decoration-color: rgba(41, 121, 255, 0.45);
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.storage-table--batch .storage-col--qty {
|
.storage-table--batch .storage-col--qty {
|
||||||
padding-left: 1rpx;
|
padding-left: 1rpx;
|
||||||
padding-right: 1rpx;
|
padding-right: 1rpx;
|
||||||
|
|||||||
@ -182,14 +182,25 @@
|
|||||||
|
|
||||||
<!-- 生产日期 -->
|
<!-- 生产日期 -->
|
||||||
<view class="form-item">
|
<view class="form-item">
|
||||||
<u-form-item label="生产日期" prop="production_date" @click="showDatePicker('production')">
|
<u-form-item label="生产日期" prop="production_date" :required="isShelfLifeMgmt" @click="showDatePicker('production')">
|
||||||
<view class="date-display">{{formData.production_date}}</view>
|
<view class="date-display">{{formData.production_date}}</view>
|
||||||
</u-form-item>
|
</u-form-item>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 有效期 -->
|
||||||
|
<view class="form-item">
|
||||||
|
<u-form-item label="有效期" prop="shelf_life">
|
||||||
|
<view class="input-with-unit">
|
||||||
|
<u-input class="input-field" v-model="formData.shelf_life" placeholder="请输入有效期" type="number" clearable
|
||||||
|
@blur="handleShelfLifeBlur" />
|
||||||
|
<text class="unit-text">天</text>
|
||||||
|
</view>
|
||||||
|
</u-form-item>
|
||||||
|
</view>
|
||||||
|
|
||||||
<!-- 到期日期 -->
|
<!-- 到期日期 -->
|
||||||
<view class="form-item">
|
<view class="form-item">
|
||||||
<u-form-item label="到期日期" prop="expiry_date" @click="showDatePicker('expiry')">
|
<u-form-item label="到期日期" prop="expiry_date" :required="isShelfLifeMgmt" @click="showDatePicker('expiry')">
|
||||||
<view class="date-display">{{formData.expiry_date}}</view>
|
<view class="date-display">{{formData.expiry_date}}</view>
|
||||||
</u-form-item>
|
</u-form-item>
|
||||||
</view>
|
</view>
|
||||||
@ -249,7 +260,9 @@
|
|||||||
product_name: '',
|
product_name: '',
|
||||||
product_snapshot: null,
|
product_snapshot: null,
|
||||||
production_date: '',
|
production_date: '',
|
||||||
|
shelf_life: '',
|
||||||
remark: '',
|
remark: '',
|
||||||
|
is_shelf_life_mgmt: false,
|
||||||
space_id: '',
|
space_id: '',
|
||||||
space_name: '',
|
space_name: '',
|
||||||
images: [],
|
images: [],
|
||||||
@ -310,6 +323,26 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
trigger: ['blur', 'change']
|
trigger: ['blur', 'change']
|
||||||
|
}],
|
||||||
|
production_date: [{
|
||||||
|
validator: (rule, value, callback) => {
|
||||||
|
if (this.isShelfLifeMgmt && !String(value || '').trim()) {
|
||||||
|
callback(new Error('保质期管理商品必须填写生产日期'));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
trigger: ['blur', 'change']
|
||||||
|
}],
|
||||||
|
expiry_date: [{
|
||||||
|
validator: (rule, value, callback) => {
|
||||||
|
if (this.isShelfLifeMgmt && !String(value || '').trim()) {
|
||||||
|
callback(new Error('保质期管理商品必须填写到期日期'));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
trigger: ['blur', 'change']
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -341,6 +374,13 @@
|
|||||||
// 是否绑定系统商品
|
// 是否绑定系统商品
|
||||||
isBoundToSystemProduct() {
|
isBoundToSystemProduct() {
|
||||||
return !!this.formData.system_product_id;
|
return !!this.formData.system_product_id;
|
||||||
|
},
|
||||||
|
isShelfLifeMgmt() {
|
||||||
|
const flag = this.formData.is_shelf_life_mgmt
|
||||||
|
?? this.formData.product_snapshot?.is_shelf_life_mgmt
|
||||||
|
?? this.detailData?.is_shelf_life_mgmt
|
||||||
|
?? this.detailData?.product_snapshot?.is_shelf_life_mgmt;
|
||||||
|
return flag === true || flag === 1 || flag === '1' || flag === 'true';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -372,6 +412,92 @@
|
|||||||
this.$store.dispatch('broadcast/stop');
|
this.$store.dispatch('broadcast/stop');
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
getTodayStartDate() {
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
return today;
|
||||||
|
},
|
||||||
|
clearExpiryAndShelfLifeWithAlert() {
|
||||||
|
this.formData.expiry_date = '';
|
||||||
|
this.formData.shelf_life = '';
|
||||||
|
uni.showModal({
|
||||||
|
title: '提示',
|
||||||
|
content: '超过有效期',
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
},
|
||||||
|
ensureExpiryDateNotPast() {
|
||||||
|
const expiryDate = this.parseDateString(this.formData.expiry_date);
|
||||||
|
if (!expiryDate) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expiryDate.getTime() < this.getTodayStartDate().getTime()) {
|
||||||
|
this.clearExpiryAndShelfLifeWithAlert();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
parseDateString(dateValue) {
|
||||||
|
const text = String(dateValue || '').trim();
|
||||||
|
if (!text) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedText = text.replace(/-/g, '/');
|
||||||
|
const date = new Date(normalizedText);
|
||||||
|
if (Number.isNaN(date.getTime())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
return date;
|
||||||
|
},
|
||||||
|
formatDateString(date) {
|
||||||
|
if (!(date instanceof Date) || Number.isNaN(date.getTime())) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const year = date.getFullYear();
|
||||||
|
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||||
|
const day = String(date.getDate()).padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day}`;
|
||||||
|
},
|
||||||
|
calculateShelfLifeFromDates(productionDateText, expiryDateText) {
|
||||||
|
const productionDate = this.parseDateString(productionDateText);
|
||||||
|
const expiryDate = this.parseDateString(expiryDateText);
|
||||||
|
if (!productionDate || !expiryDate) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const diffMilliseconds = expiryDate.getTime() - productionDate.getTime();
|
||||||
|
if (diffMilliseconds < 0) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(Math.round(diffMilliseconds / (24 * 60 * 60 * 1000)));
|
||||||
|
},
|
||||||
|
syncShelfLifeFromDates() {
|
||||||
|
const shelfLife = this.calculateShelfLifeFromDates(this.formData.production_date, this.formData.expiry_date);
|
||||||
|
this.formData.shelf_life = shelfLife;
|
||||||
|
},
|
||||||
|
syncExpiryFromProductionAndShelfLife() {
|
||||||
|
const productionDate = this.parseDateString(this.formData.production_date);
|
||||||
|
const shelfLifeText = String(this.formData.shelf_life || '').trim();
|
||||||
|
if (!productionDate || !shelfLifeText) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const shelfLifeDays = Number(shelfLifeText);
|
||||||
|
if (!Number.isFinite(shelfLifeDays) || shelfLifeDays < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const expiryDate = new Date(productionDate);
|
||||||
|
expiryDate.setDate(expiryDate.getDate() + Math.floor(shelfLifeDays));
|
||||||
|
this.formData.expiry_date = this.formatDateString(expiryDate);
|
||||||
|
},
|
||||||
// 初始化表单数据
|
// 初始化表单数据
|
||||||
initFormData(data) {
|
initFormData(data) {
|
||||||
if (!data || this.isInitializing) return;
|
if (!data || this.isInitializing) return;
|
||||||
@ -401,6 +527,9 @@
|
|||||||
|
|
||||||
this.formData = newFormData;
|
this.formData = newFormData;
|
||||||
this.boxQuantityManuallyEdited = false;
|
this.boxQuantityManuallyEdited = false;
|
||||||
|
if (this.formData.production_date && this.formData.expiry_date && !String(this.formData.shelf_life || '').trim()) {
|
||||||
|
this.syncShelfLifeFromDates();
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化商品图片
|
// 初始化商品图片
|
||||||
if (data.product_snapshot?.images) {
|
if (data.product_snapshot?.images) {
|
||||||
@ -484,12 +613,29 @@
|
|||||||
const dateStr = this.$u.timeFormat(e.value, 'yyyy-mm-dd');
|
const dateStr = this.$u.timeFormat(e.value, 'yyyy-mm-dd');
|
||||||
if (this.datePickerType === 'production') {
|
if (this.datePickerType === 'production') {
|
||||||
this.formData.production_date = dateStr;
|
this.formData.production_date = dateStr;
|
||||||
|
this.syncExpiryFromProductionAndShelfLife();
|
||||||
} else {
|
} else {
|
||||||
this.formData.expiry_date = dateStr;
|
this.formData.expiry_date = dateStr;
|
||||||
|
this.syncShelfLifeFromDates();
|
||||||
}
|
}
|
||||||
|
this.ensureExpiryDateNotPast();
|
||||||
this.showDatePickerDialog = false;
|
this.showDatePickerDialog = false;
|
||||||
this.emitFormData();
|
this.emitFormData();
|
||||||
},
|
},
|
||||||
|
handleShelfLifeBlur() {
|
||||||
|
const rawValue = String(this.formData.shelf_life || '').trim();
|
||||||
|
if (!rawValue) {
|
||||||
|
this.formData.shelf_life = '';
|
||||||
|
this.emitFormData();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = rawValue.replace(/\D/g, '');
|
||||||
|
this.formData.shelf_life = normalized;
|
||||||
|
this.syncExpiryFromProductionAndShelfLife();
|
||||||
|
this.ensureExpiryDateNotPast();
|
||||||
|
this.emitFormData();
|
||||||
|
},
|
||||||
|
|
||||||
// 确认库位选择
|
// 确认库位选择
|
||||||
handleSpaceConfirm(e) {
|
handleSpaceConfirm(e) {
|
||||||
@ -576,6 +722,7 @@
|
|||||||
actual_quantity: parseFloat(this.formData.actual_quantity) || 0,
|
actual_quantity: parseFloat(this.formData.actual_quantity) || 0,
|
||||||
box_quantity: this.formData.box_quantity ? parseInt(this.formData.box_quantity) : null,
|
box_quantity: this.formData.box_quantity ? parseInt(this.formData.box_quantity) : null,
|
||||||
boxes_per_pallet: this.formData.boxes_per_pallet ? parseFloat(this.formData.boxes_per_pallet) : null,
|
boxes_per_pallet: this.formData.boxes_per_pallet ? parseFloat(this.formData.boxes_per_pallet) : null,
|
||||||
|
shelf_life: this.formData.shelf_life ? parseInt(this.formData.shelf_life) : null,
|
||||||
pallet_quantity: this.formData.pallet_quantity ? parseFloat(this.formData.pallet_quantity) : null,
|
pallet_quantity: this.formData.pallet_quantity ? parseFloat(this.formData.pallet_quantity) : null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -147,6 +147,77 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
getTodayStartTimestamp() {
|
||||||
|
const today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
return today.getTime();
|
||||||
|
},
|
||||||
|
parseDateToTimestamp(dateValue) {
|
||||||
|
const text = String(dateValue || '').trim();
|
||||||
|
if (!text) {
|
||||||
|
return NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalizedText = text.replace(/-/g, '/');
|
||||||
|
const date = new Date(normalizedText);
|
||||||
|
if (Number.isNaN(date.getTime())) {
|
||||||
|
return NaN;
|
||||||
|
}
|
||||||
|
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
return date.getTime();
|
||||||
|
},
|
||||||
|
isShelfLifeMgmtDetail(detail) {
|
||||||
|
if (!detail || typeof detail !== 'object') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const flag = detail.is_shelf_life_mgmt
|
||||||
|
?? detail.product_snapshot?.is_shelf_life_mgmt;
|
||||||
|
return flag === true || flag === 1 || flag === '1' || flag === 'true';
|
||||||
|
},
|
||||||
|
validateShelfLifeRequiredFields() {
|
||||||
|
const invalidDetail = (this.details || []).find(detail => {
|
||||||
|
if (!this.isShelfLifeMgmtDetail(detail)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const productionDate = String(detail.production_date || '').trim();
|
||||||
|
const expiryDate = String(detail.expiry_date || '').trim();
|
||||||
|
return !productionDate || !expiryDate;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!invalidDetail) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const missingFields = [];
|
||||||
|
if (!String(invalidDetail.production_date || '').trim()) {
|
||||||
|
missingFields.push('生产日期');
|
||||||
|
}
|
||||||
|
if (!String(invalidDetail.expiry_date || '').trim()) {
|
||||||
|
missingFields.push('到期日期');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
detail: invalidDetail,
|
||||||
|
missingFields
|
||||||
|
};
|
||||||
|
},
|
||||||
|
validateExpiryDateNotPast() {
|
||||||
|
const todayStart = this.getTodayStartTimestamp();
|
||||||
|
const invalidDetail = (this.details || []).find(detail => {
|
||||||
|
const expiryDate = String(detail?.expiry_date || '').trim();
|
||||||
|
if (!expiryDate) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const expiryTimestamp = this.parseDateToTimestamp(expiryDate);
|
||||||
|
return Number.isFinite(expiryTimestamp) && expiryTimestamp < todayStart;
|
||||||
|
});
|
||||||
|
|
||||||
|
return invalidDetail || null;
|
||||||
|
},
|
||||||
// 初始化数据
|
// 初始化数据
|
||||||
async initData() {
|
async initData() {
|
||||||
await this.loadReceivingInfo();
|
await this.loadReceivingInfo();
|
||||||
@ -419,6 +490,28 @@
|
|||||||
},
|
},
|
||||||
async completeReceiving() {
|
async completeReceiving() {
|
||||||
this.showComplete = false;
|
this.showComplete = false;
|
||||||
|
const shelfLifeValidation = this.validateShelfLifeRequiredFields();
|
||||||
|
if (shelfLifeValidation) {
|
||||||
|
this.currentTab = 1;
|
||||||
|
this.selectedDetail = shelfLifeValidation.detail;
|
||||||
|
uni.showModal({
|
||||||
|
title: '商品信息不完整',
|
||||||
|
content: `${shelfLifeValidation.detail.product_name || '当前商品'}缺少${shelfLifeValidation.missingFields.join('、')}`,
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const expiredDetail = this.validateExpiryDateNotPast();
|
||||||
|
if (expiredDetail) {
|
||||||
|
this.currentTab = 1;
|
||||||
|
this.selectedDetail = expiredDetail;
|
||||||
|
uni.showModal({
|
||||||
|
title: '禁止收货',
|
||||||
|
content: `商品名称:${expiredDetail.product_name || '当前商品'}已过期,请移除拒绝收货`,
|
||||||
|
showCancel: false
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// 1. 显示确认弹窗
|
// 1. 显示确认弹窗
|
||||||
const confirmResult = await uni.showModal({
|
const confirmResult = await uni.showModal({
|
||||||
@ -477,7 +570,6 @@
|
|||||||
// 如果有详细的错误信息
|
// 如果有详细的错误信息
|
||||||
if (res.data && res.data.invalid_details) {
|
if (res.data && res.data.invalid_details) {
|
||||||
const firstError = res.data.invalid_details[0];
|
const firstError = res.data.invalid_details[0];
|
||||||
errorMsg = `${firstError.item_name}缺少${firstError.missing_fields.join('、')}`;
|
|
||||||
|
|
||||||
// 弹出详细错误提示
|
// 弹出详细错误提示
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
@ -488,7 +580,6 @@
|
|||||||
if (modalRes.confirm) {
|
if (modalRes.confirm) {
|
||||||
this.currentTab = 1;
|
this.currentTab = 1;
|
||||||
const index = this.details.findIndex(item => item.id === firstError.detail_id);
|
const index = this.details.findIndex(item => item.id === firstError.detail_id);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.selectedDetail = this.details[index];
|
this.selectedDetail = this.details[index];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -30,7 +30,6 @@
|
|||||||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<text v-if="formData.sourceSpaceName" class="field-tip">已识别:{{ formData.sourceSpaceName }}</text>
|
|
||||||
</u-form-item>
|
</u-form-item>
|
||||||
|
|
||||||
<u-form-item label="移入库位" required>
|
<u-form-item label="移入库位" required>
|
||||||
@ -46,7 +45,6 @@
|
|||||||
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
<u-icon name="camera" size="34rpx" color="#2979ff"></u-icon>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<text v-if="formData.targetSpaceName" class="field-tip">已识别:{{ formData.targetSpaceName }}</text>
|
|
||||||
</u-form-item>
|
</u-form-item>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@ -180,11 +178,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad(options = {}) {
|
||||||
this.safeDispatchBroadcast('setCallbacks', {
|
this.safeDispatchBroadcast('setCallbacks', {
|
||||||
onResult: this.handleBroadcastResult
|
onResult: this.handleBroadcastResult
|
||||||
});
|
});
|
||||||
this.safeDispatchBroadcast('start');
|
this.safeDispatchBroadcast('start');
|
||||||
|
this.applyPrefillFromOptions(options);
|
||||||
},
|
},
|
||||||
onShow() {
|
onShow() {
|
||||||
this.safeDispatchBroadcast('setCallbacks', {
|
this.safeDispatchBroadcast('setCallbacks', {
|
||||||
@ -199,6 +198,15 @@
|
|||||||
this.safeDispatchBroadcast('stop');
|
this.safeDispatchBroadcast('stop');
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
normalizePositiveId(value) {
|
||||||
|
const numericValue = Number(value);
|
||||||
|
if (!Number.isFinite(numericValue)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = Math.trunc(numericValue);
|
||||||
|
return normalized > 0 ? normalized : null;
|
||||||
|
},
|
||||||
safeDispatchBroadcast(action, payload) {
|
safeDispatchBroadcast(action, payload) {
|
||||||
try {
|
try {
|
||||||
const task = this.$store.dispatch(`broadcast/${action}`, payload);
|
const task = this.$store.dispatch(`broadcast/${action}`, payload);
|
||||||
@ -418,6 +426,45 @@
|
|||||||
this.formData.moveQuantity = quantity && quantity !== '--' ? String(quantity) : '';
|
this.formData.moveQuantity = quantity && quantity !== '--' ? String(quantity) : '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
applyPrefillFromOptions(options = {}) {
|
||||||
|
const cacheKey = String(options.cacheKey || '').trim();
|
||||||
|
if (!cacheKey) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const prefillData = uni.getStorageSync(cacheKey);
|
||||||
|
if (!prefillData || typeof prefillData !== 'object') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.removeStorageSync(cacheKey);
|
||||||
|
this.formData.relocationMode = 'product';
|
||||||
|
this.activeScanField = 'productKeyword';
|
||||||
|
|
||||||
|
if (prefillData.stock && typeof prefillData.stock === 'object') {
|
||||||
|
this.selectedStock = prefillData.stock;
|
||||||
|
this.formData.productKeyword = this.getStockBarcode(prefillData.stock) || this.getStockName(prefillData.stock);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefillData.sourceSpace && typeof prefillData.sourceSpace === 'object') {
|
||||||
|
this.formData.sourceSpaceId = prefillData.sourceSpace.id || null;
|
||||||
|
this.formData.sourceSpaceName = prefillData.sourceSpace.name || '';
|
||||||
|
this.formData.sourceSpaceKeyword = prefillData.sourceSpace.code || prefillData.sourceSpace.name || '';
|
||||||
|
if (this.selectedStock && typeof this.selectedStock === 'object') {
|
||||||
|
if (!this.selectedStock.space_name && prefillData.sourceSpace.name) {
|
||||||
|
this.selectedStock.space_name = prefillData.sourceSpace.name;
|
||||||
|
}
|
||||||
|
if (!this.selectedStock.space_barcode && prefillData.sourceSpace.code) {
|
||||||
|
this.selectedStock.space_barcode = prefillData.sourceSpace.code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const moveQuantity = String(prefillData.moveQuantity || '').trim();
|
||||||
|
if (moveQuantity) {
|
||||||
|
this.formData.moveQuantity = this.normalizeMoveQuantity(moveQuantity);
|
||||||
|
}
|
||||||
|
},
|
||||||
handleSelectorConfirm(item) {
|
handleSelectorConfirm(item) {
|
||||||
if (this.selectorType === 'stock') {
|
if (this.selectorType === 'stock') {
|
||||||
this.applyStockSelection(item);
|
this.applyStockSelection(item);
|
||||||
@ -442,11 +489,57 @@
|
|||||||
return item?.barcode || item?.goods_code || item?.item_code || '--';
|
return item?.barcode || item?.goods_code || item?.item_code || '--';
|
||||||
},
|
},
|
||||||
getStockSpace(item) {
|
getStockSpace(item) {
|
||||||
return item?.space?.name || item?.space_name || item?.space_barcode || item?.space?.barcode || '--';
|
return item?.space?.name
|
||||||
|
|| item?.space_name
|
||||||
|
|| item?.space?.space_name
|
||||||
|
|| item?.space_code
|
||||||
|
|| item?.space?.code
|
||||||
|
|| item?.space?.space_code
|
||||||
|
|| item?.space_barcode
|
||||||
|
|| item?.space?.barcode
|
||||||
|
|| item?.location_name
|
||||||
|
|| item?.position_name
|
||||||
|
|| '--';
|
||||||
},
|
},
|
||||||
getStockQuantity(item) {
|
getStockQuantity(item) {
|
||||||
return item?.available_quantity || item?.actual_quantity || item?.quantity || item?.stock || '--';
|
return item?.available_quantity || item?.actual_quantity || item?.quantity || item?.stock || '--';
|
||||||
},
|
},
|
||||||
|
getStockStorageId(item) {
|
||||||
|
if (!item || typeof item !== 'object') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const directCandidates = [
|
||||||
|
item.relocation_storage_id,
|
||||||
|
item.storage_id,
|
||||||
|
item.inventory_id,
|
||||||
|
item.stock_id,
|
||||||
|
item.storage_record_id,
|
||||||
|
item.stock_record_id,
|
||||||
|
item.warehouse_storage_id,
|
||||||
|
item.warehouse_stock_id,
|
||||||
|
item.record_id
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let i = 0; i < directCandidates.length; i++) {
|
||||||
|
const normalized = this.normalizePositiveId(directCandidates[i]);
|
||||||
|
if (normalized) {
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallbackId = this.normalizePositiveId(item.id);
|
||||||
|
if (!fallbackId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const spaceId = this.normalizePositiveId(item.space_id || item.space?.id);
|
||||||
|
if (spaceId && fallbackId === spaceId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return fallbackId;
|
||||||
|
},
|
||||||
getAvailableStockNumber() {
|
getAvailableStockNumber() {
|
||||||
if (!this.selectedStock) {
|
if (!this.selectedStock) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -534,7 +627,11 @@
|
|||||||
uni.showToast({ title: '请选择移库商品', icon: 'none' });
|
uni.showToast({ title: '请选择移库商品', icon: 'none' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.formData.relocationMode === 'product' && !this.validateMoveQuantity(true)) {
|
if (this.formData.relocationMode !== 'product') {
|
||||||
|
uni.showToast({ title: '当前仅支持按商品移库', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.formData.moveQuantity && !this.validateMoveQuantity(true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.formData.sourceSpaceId && this.formData.targetSpaceId && this.formData.sourceSpaceId === this.formData.targetSpaceId) {
|
if (this.formData.sourceSpaceId && this.formData.targetSpaceId && this.formData.sourceSpaceId === this.formData.targetSpaceId) {
|
||||||
@ -542,11 +639,67 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uni.showModal({
|
const storageId = this.getStockStorageId(this.selectedStock);
|
||||||
title: '提示',
|
if (!storageId) {
|
||||||
content: `当前项目暂未配置${this.formData.relocationMode === 'product' ? '按商品' : '按仓位'}移库提交接口,页面和扫码流程已接入。`,
|
uni.showToast({ title: '未获取到库存记录ID', icon: 'none' });
|
||||||
showCancel: false
|
return;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (!this.formData.targetSpaceId) {
|
||||||
|
uni.showToast({ title: '请先识别移入库位', icon: 'none' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
storage_id: storageId,
|
||||||
|
target_space_id: Number(this.formData.targetSpaceId)
|
||||||
|
};
|
||||||
|
|
||||||
|
const quantity = String(this.formData.moveQuantity || '').trim();
|
||||||
|
if (quantity) {
|
||||||
|
payload.quantity = Number(quantity);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.submitting = true;
|
||||||
|
try {
|
||||||
|
const res = await this.$http('storage.inventory.transferLocation', payload);
|
||||||
|
if (res && Number(res.code) === 200) {
|
||||||
|
uni.setStorageSync('product_query_need_refresh', Date.now());
|
||||||
|
uni.$emit('storage:relocation:success', {
|
||||||
|
timestamp: Date.now(),
|
||||||
|
storageId: Number(storageId)
|
||||||
|
});
|
||||||
|
uni.showToast({
|
||||||
|
title: res.message || '移库成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
|
||||||
|
if (Array.isArray(pages) && pages.length > 1) {
|
||||||
|
setTimeout(() => {
|
||||||
|
uni.navigateBack({
|
||||||
|
delta: 1
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handleReset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.showToast({
|
||||||
|
title: (res && res.message) || '移库失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('移库提交失败:', error);
|
||||||
|
uni.showToast({
|
||||||
|
title: (error && error.message) || '移库失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
this.submitting = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
handleReset() {
|
handleReset() {
|
||||||
this.formData = {
|
this.formData = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user