Browse Source

库位支持“历史缓存 + 点击可选”。

master
han\hanst 4 days ago
parent
commit
e91290fcce
  1. 66
      src/views/modules/production-inbound/inboundRegister.vue

66
src/views/modules/production-inbound/inboundRegister.vue

@ -79,7 +79,16 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
<el-col :span="12"><el-form-item label="库位"> <el-col :span="12"><el-form-item label="库位">
<el-input v-model="inboundItem.locationNo" placeholder="请输入库位" />
<el-autocomplete
v-model.trim="inboundItem.locationNo"
:fetch-suggestions="querySearchLocation"
placeholder="请输入库位"
:trigger-on-focus="true"
clearable
style="width: 100%;"
@select="handleLocationSelect"
@blur="handleLocationBlur"
/>
</el-form-item></el-col> </el-form-item></el-col>
<el-col :span="12"><el-form-item label="批号"> <el-col :span="12"><el-form-item label="批号">
<el-input v-model="inboundItem.batchNo" placeholder="请输入批号" /> <el-input v-model="inboundItem.batchNo" placeholder="请输入批号" />
@ -228,7 +237,9 @@ export default {
fullscreenLoading: false, fullscreenLoading: false,
loadingText: '加载中...', loadingText: '加载中...',
autoCalculate: false, autoCalculate: false,
issueQty: ''
issueQty: '',
locationHistoryList: [],
locationHistoryLimit: 20
}; };
}, },
computed: { computed: {
@ -250,6 +261,10 @@ export default {
}, },
displayReleaseSeq() { displayReleaseSeq() {
return `${this.inboundItem.releaseNo || ''}/${this.inboundItem.sequenceNo || ''}`; return `${this.inboundItem.releaseNo || ''}/${this.inboundItem.sequenceNo || ''}`;
},
locationHistoryKey() {
const site = this.site || 'defaultSite';
return `production_inbound_location_history_${site}`;
} }
}, },
watch: { watch: {
@ -502,6 +517,51 @@ export default {
const day = String(dateObj.getDate()).padStart(2, '0'); const day = String(dateObj.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`; 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() { checkQuantity() {
const transQty = parseFloat(this.inboundItem.transQty) || 0; const transQty = parseFloat(this.inboundItem.transQty) || 0;
@ -689,6 +749,7 @@ export default {
submitShopOrderInbound(submitData).then(({ data }) => { submitShopOrderInbound(submitData).then(({ data }) => {
if (data.code === 0) { if (data.code === 0) {
this.$message.success("入库成功"); this.$message.success("入库成功");
this.saveLocationHistory(item.locationNo);
this.clearAllHandlingUnitCache(); this.clearAllHandlingUnitCache();
// unitIds // unitIds
@ -772,6 +833,7 @@ export default {
} }
}, },
mounted() { mounted() {
this.loadLocationHistory();
this.$nextTick(() => this.$refs.scanCodeRef.focus()); this.$nextTick(() => this.$refs.scanCodeRef.focus());
}, },

Loading…
Cancel
Save