扫码货位:支持NS##a5-4格式,自动匹配仓库编码并切换仓库

This commit is contained in:
97694732@qq.com 2026-06-04 17:14:33 +08:00
parent 6705a6a560
commit 3cbcd6b834

View File

@ -1526,28 +1526,68 @@ export default {
this.popupLocationList = [...this.popupAllLocationList] this.popupLocationList = [...this.popupAllLocationList]
}, },
// // ## NS##a5-4
scanLocationBarcode() { async scanLocationBarcode() {
uni.scanCode({ uni.scanCode({
onlyFromCamera: true, onlyFromCamera: true,
scanType: ['barcode'], scanType: ['barcode'],
success: (res) => { success: async (res) => {
const scanned = (res.result || '').trim().toLowerCase() const scanned = (res.result || '').trim()
if (!scanned) return if (!scanned) return
//
// ##
const sepIdx = scanned.indexOf('##')
if (sepIdx > 0) {
const whCode = scanned.substring(0, sepIdx).trim()
const locCode = scanned.substring(sepIdx + 2).trim()
if (whCode && locCode) {
//
const whIdx = this.popupWarehouseList.findIndex(w => {
const code = (w.code || '').toLowerCase()
const name = (w.name || '').toLowerCase()
const search = whCode.toLowerCase()
return code === search || name === search || code.includes(search)
})
if (whIdx !== -1) {
//
this.selectPopupWarehouse(whIdx)
//
setTimeout(() => {
const matchedLoc = this.popupAllLocationList.find(l => {
const code = (l.code || '').toLowerCase()
const name = (l.name || '').toLowerCase()
const search = locCode.toLowerCase()
return code === search || name === search ||
code.includes(search) || search.includes(code)
})
if (matchedLoc) {
this.popupSelectedLoc = matchedLoc
this.popupLocationSearch = ''
this.popupLocationList = [...this.popupAllLocationList]
uni.showToast({ title: '已匹配仓库' + whCode + ' 货位:' + matchedLoc.code, icon: 'success' })
} else {
uni.showToast({ title: '已切换仓库' + whCode + ',但未找到货位' + locCode, icon: 'none' })
}
}, 500)
return
}
}
}
//
let matched = null let matched = null
for (const loc of this.popupAllLocationList) { for (const loc of this.popupAllLocationList) {
const code = (loc.code || '').toLowerCase() const code = (loc.code || '').toLowerCase()
const name = (loc.name || '').toLowerCase() const name = (loc.name || '').toLowerCase()
if (code === scanned || name === scanned || const search = scanned.toLowerCase()
code.includes(scanned) || scanned.includes(code)) { if (code === search || name === search ||
code.includes(search) || search.includes(code)) {
matched = loc matched = loc
break break
} }
} }
if (matched) { if (matched) {
this.popupSelectedLoc = matched this.popupSelectedLoc = matched
//
this.popupLocationSearch = '' this.popupLocationSearch = ''
this.popupLocationList = [...this.popupAllLocationList] this.popupLocationList = [...this.popupAllLocationList]
uni.showToast({ title: '已选中货位: ' + matched.code, icon: 'success' }) uni.showToast({ title: '已选中货位: ' + matched.code, icon: 'success' })