扫码货位:支持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]
},
//
scanLocationBarcode() {
// ## NS##a5-4
async scanLocationBarcode() {
uni.scanCode({
onlyFromCamera: true,
scanType: ['barcode'],
success: (res) => {
const scanned = (res.result || '').trim().toLowerCase()
success: async (res) => {
const scanned = (res.result || '').trim()
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
for (const loc of this.popupAllLocationList) {
const code = (loc.code || '').toLowerCase()
const name = (loc.name || '').toLowerCase()
if (code === scanned || name === scanned ||
code.includes(scanned) || scanned.includes(code)) {
const search = scanned.toLowerCase()
if (code === search || name === search ||
code.includes(search) || search.includes(code)) {
matched = loc
break
}
}
if (matched) {
this.popupSelectedLoc = matched
//
this.popupLocationSearch = ''
this.popupLocationList = [...this.popupAllLocationList]
uni.showToast({ title: '已选中货位: ' + matched.code, icon: 'success' })