Browse Source

库位缓存

master
han\hanst 2 weeks ago
parent
commit
d41acb900c
  1. 69
      src/views/modules/recv/recv.vue

69
src/views/modules/recv/recv.vue

@ -103,7 +103,17 @@
spellcheck="false" /> spellcheck="false" />
</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="recvItem.locationNo" placeholder="请输入库位" /></el-form-item></el-col>
<el-autocomplete
v-model.trim="recvItem.locationNo"
:fetch-suggestions="querySearchLocation"
placeholder="请输入库位"
:trigger-on-focus="true"
clearable
style="width: 100%;"
@select="handleLocationSelect"
@blur="handleLocationBlur"
/>
</el-form-item></el-col>
<el-col :span="12"><el-form-item label="批号"><el-input v-model="recvItem.batchNo" placeholder="请输入批号" /></el-form-item></el-col> <el-col :span="12"><el-form-item label="批号"><el-input v-model="recvItem.batchNo" placeholder="请输入批号" /></el-form-item></el-col>
<el-col :span="8" style="margin-top: 10px"><el-form-item><el-button type="text" style="font-size: 16px;margin-left: 30px" @click="processFlag = 1">回退</el-button></el-form-item></el-col> <el-col :span="8" style="margin-top: 10px"><el-form-item><el-button type="text" style="font-size: 16px;margin-left: 30px" @click="processFlag = 1">回退</el-button></el-form-item></el-col>
<el-col :span="8" style="margin-top: 10px"><el-form-item><el-button type="text" style="font-size: 16px;margin-left: 20px" @click="receivePo">保存</el-button></el-form-item></el-col> <el-col :span="8" style="margin-top: 10px"><el-form-item><el-button type="text" style="font-size: 16px;margin-left: 20px" @click="receivePo">保存</el-button></el-form-item></el-col>
@ -199,7 +209,9 @@ export default {
warehouseId:localStorage.getItem('selectedWarehouse'), warehouseId:localStorage.getItem('selectedWarehouse'),
fullscreenLoading: false, // 控制全屏loading fullscreenLoading: false, // 控制全屏loading
loadingText: '加载中...', // 动态loading文本 loadingText: '加载中...', // 动态loading文本
autoCalculate: true // 自动计算包装数开关
autoCalculate: true, // 自动计算包装数开关
locationHistoryList: [],
locationHistoryLimit: 20
}; };
}, },
computed: { computed: {
@ -217,6 +229,11 @@ export default {
}, },
displayLineWdr() { displayLineWdr() {
return `${this.recvItem.lineNo || ''}/${this.recvItem.releaseNo}`; return `${this.recvItem.lineNo || ''}/${this.recvItem.releaseNo}`;
},
locationHistoryKey() {
// 按站点隔离,避免不同站点的库位混在同一份历史里。
const site = this.site || 'defaultSite';
return `recv_location_history_${site}`;
} }
}, },
watch: { watch: {
@ -471,6 +488,51 @@ export default {
} }
}); });
}, },
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.recvItem.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));
},
// 校验库位 // 校验库位
async validateLocation() { async validateLocation() {
if (!this.recvItem.locationNo || !this.recvItem.receiveCaseDB) { if (!this.recvItem.locationNo || !this.recvItem.receiveCaseDB) {
@ -593,6 +655,8 @@ export default {
receivePo(receiveData).then(({ data }) => { receivePo(receiveData).then(({ data }) => {
if (data.code === 0) { if (data.code === 0) {
this.$message.success("操作成功"); this.$message.success("操作成功");
// 提交成功后再记一次,避免只填了默认库位、未失焦就保存时漏记。
this.saveLocationHistory(item.locationNo);
this.clearAllHandlingUnitCache(); this.clearAllHandlingUnitCache();
let printLabelType; let printLabelType;
if (item.partNo && item.partNo.startsWith("80")) { if (item.partNo && item.partNo.startsWith("80")) {
@ -653,6 +717,7 @@ export default {
}, },
}, },
mounted() { mounted() {
this.loadLocationHistory();
this.$nextTick(() => this.$refs.scanCodeRef.focus()); this.$nextTick(() => this.$refs.scanCodeRef.focus());
}, },

Loading…
Cancel
Save