diff --git a/src/views/modules/production-inbound/inboundRegister.vue b/src/views/modules/production-inbound/inboundRegister.vue index fc7cf17..a85c1fa 100644 --- a/src/views/modules/production-inbound/inboundRegister.vue +++ b/src/views/modules/production-inbound/inboundRegister.vue @@ -79,7 +79,16 @@ - + @@ -228,7 +237,9 @@ export default { fullscreenLoading: false, loadingText: '加载中...', autoCalculate: false, - issueQty: '' + issueQty: '', + locationHistoryList: [], + locationHistoryLimit: 20 }; }, computed: { @@ -250,6 +261,10 @@ export default { }, displayReleaseSeq() { return `${this.inboundItem.releaseNo || ''}/${this.inboundItem.sequenceNo || ''}`; + }, + locationHistoryKey() { + const site = this.site || 'defaultSite'; + return `production_inbound_location_history_${site}`; } }, watch: { @@ -502,6 +517,51 @@ export default { const day = String(dateObj.getDate()).padStart(2, '0'); return `${year}-${month}-${day}`; }, + loadLocationHistory() { + const rawHistory = localStorage.getItem(this.locationHistoryKey); + if (!rawHistory) { + this.locationHistoryList = []; + return; + } + try { + const parsedHistory = JSON.parse(rawHistory); + if (!Array.isArray(parsedHistory)) { + this.locationHistoryList = []; + return; + } + this.locationHistoryList = parsedHistory + .map(item => (item || '').toString().trim()) + .filter((item, index, arr) => item && arr.indexOf(item) === index) + .slice(0, this.locationHistoryLimit); + } catch (error) { + console.warn('解析库位历史缓存失败:', error); + this.locationHistoryList = []; + } + }, + querySearchLocation(queryString, cb) { + const normalizedKeyword = (queryString || '').trim().toLowerCase(); + const historyOptions = this.locationHistoryList.map(location => ({ value: location })); + const result = normalizedKeyword + ? historyOptions.filter(item => item.value.toLowerCase().includes(normalizedKeyword)) + : historyOptions; + cb(result); + }, + handleLocationSelect(selectedItem) { + // 选中历史值后立即置顶,保证高频库位下次优先展示。 + this.saveLocationHistory(selectedItem && selectedItem.value); + }, + handleLocationBlur() { + // 失焦即缓存,覆盖“手输后直接切换焦点”的场景。 + this.saveLocationHistory(this.inboundItem.locationNo); + }, + saveLocationHistory(locationNo) { + const normalizedLocation = (locationNo || '').trim(); + if (!normalizedLocation) return; + const dedupedHistory = [normalizedLocation, ...this.locationHistoryList.filter(item => item !== normalizedLocation)] + .slice(0, this.locationHistoryLimit); + this.locationHistoryList = dedupedHistory; + localStorage.setItem(this.locationHistoryKey, JSON.stringify(dedupedHistory)); + }, // 检查数量 checkQuantity() { const transQty = parseFloat(this.inboundItem.transQty) || 0; @@ -689,6 +749,7 @@ export default { submitShopOrderInbound(submitData).then(({ data }) => { if (data.code === 0) { this.$message.success("入库成功"); + this.saveLocationHistory(item.locationNo); this.clearAllHandlingUnitCache(); // 获取unitIds并打印标签 @@ -772,6 +833,7 @@ export default { } }, mounted() { + this.loadLocationHistory(); this.$nextTick(() => this.$refs.scanCodeRef.focus()); },