From 209a9501018b451a4cf2871de33584bf54e4231d Mon Sep 17 00:00:00 2001 From: bb_pan Date: Wed, 9 Jul 2025 16:09:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=90=E6=96=99=E7=AB=99-=E9=80=80=E6=96=99?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../materialsStation/toolsLease/codeOut.vue | 150 +++++------------- 1 file changed, 40 insertions(+), 110 deletions(-) diff --git a/src/pages/materialsStation/toolsLease/codeOut.vue b/src/pages/materialsStation/toolsLease/codeOut.vue index f3ffbf8..516ec1c 100644 --- a/src/pages/materialsStation/toolsLease/codeOut.vue +++ b/src/pages/materialsStation/toolsLease/codeOut.vue @@ -103,22 +103,8 @@ @scanSuccess="handleScanSuccess" @scanError="handleScanError" /> - - - - 设备编码 - - - - - - - - 编码检索 - - - -
+ +
设备编码 @@ -132,6 +118,7 @@
+ @@ -233,18 +220,18 @@ onLoad((opt) => { // queryParamsTemp.value.id = queryParamsTemp.value.parentId console.log('xxxxxxxx', queryParamsTemp.value) queryCodeParams.value.typeId = queryParamsTemp.value.typeId - queryCodeParams.value.proId = queryParamsTemp.value.proId + queryCodeParams.value.proId = queryParamsTemp.value.proId || queryParamsTemp.value.projectId queryCodeParams.value.teamId = queryParamsTemp.value.teamId queryParams.value = { ...queryParamsTemp.value } if (queryParamsTemp.value.isBack) { getCodeList() // 获取编码列表 } else { - codeDeviceList.value = queryParamsTemp.value.maCodeList || [] // 初始化编码设备列表 - if (queryParamsTemp.value.maCodeList && queryParamsTemp.value.maCodeList.length > 0) { - allChecked.value = queryParamsTemp.value.maCodeList.every((e) => e.checked) - } getCodeDeviceListData() } + codeDeviceList.value = queryParamsTemp.value.maCodeList || [] // 初始化编码设备列表 + if (queryParamsTemp.value.maCodeList && queryParamsTemp.value.maCodeList.length > 0) { + allChecked.value = queryParamsTemp.value.maCodeList.every((e) => e.checked) + } }) onShow((opt) => { @@ -274,25 +261,12 @@ const getCodeList = async () => { const res = await getMachineByIdApi(params) console.log('🚀 ~ getCodeList ~ res:', res) if (res.code === 200 && res.data && res.data.length > 0) { - codeDeviceList.value = res.data.map((item) => { + codeRange.value = res.data.map((item) => { return { - ...item, - checked: false, // 默认未选中 - materialModel: item.typeName, + text: item.maCode, + value: item.maCode, } }) - // 将queryParamsTemp.value.maCodeList 与 codeDeviceList.value 去重合并 - codeDeviceList.value = [ - ...new Map( - [...codeDeviceList.value, ...queryParamsTemp.value.maCodeList].map((item) => [ - item.maId, - item, - ]), - ).values(), - ] - // 更新全选状态 - allChecked.value = codeDeviceList.value.every((e) => e.checked) - console.log('🚀 ~ getCodeList ~ allChecked.value:', allChecked.value) } } catch (error) { console.log('🚀 ~ getCodeList ~ error:', error) @@ -318,13 +292,7 @@ const getCodeDeviceListData = async () => { } console.log('🚀 ~ getCodeDeviceListData ~ res:', res) - // codeDeviceList.value.push(...res.data) - // if (codeDeviceList.value.length > 0) { - // codeDeviceList.value = codeDeviceList.value.map((e) => { - // return { ...e, checked: false, outType: 0, checked: false } - // }) - // } - // total.value = res.total + setTimeout(() => { uni.hideLoading() }, 300) @@ -347,7 +315,20 @@ const getCodeInfoData = async () => { title: '加载中...', mask: true, }) - const res = await getCodeDeviceListAPI(queryCodeParams.value) + let res = null + if (queryParamsTemp.value.isBack) { + res = await getMachineByIdApi(queryCodeParams.value) + } else { + res = await getCodeDeviceListAPI(queryCodeParams.value) + } + if (!res.data || !res.data.length) { + uni.hideLoading() + uni.showToast({ + title: '暂无数据', + icon: 'none', + }) + return + } const newItem = { ...res.data[0], checked: true, @@ -430,61 +411,10 @@ const onHandleOutbound = async () => { // 扫码识别按钮 const scanStart = () => { + // handleQrCode('201811-00531') if (scanQrCodeRef.value) { scanQrCodeRef.value.scanQrCode() } - // uni.scanCode({ - // success: async (res) => { - // console.log('🚀 ~ scanStart ~ res:', res) - // let qrCode = res.result - // qrCode = qrCode.includes('qrcode=') ? qrCode.split('qrcode=')[1] : qrCode - // console.log('🚀 ~ success: ~ qrCode:', qrCode) - // if (!qrCode) { - // uni.showToast({ title: '扫码识别失败', icon: 'none' }) - // } else { - // const params = { qrCode, typeId: queryParams.value.typeId } - // console.log('🚀 ~ success: ~ queryParams.value.isAddCode:', queryParams.value.isAddCode) - // try { - // const res = await getCodeScanAPI(params) - // console.log('🚀 ~ success: ~ res:', res) - // if (res.code === 200) { - // if (res.data && res.data.recordList.length > 0) { - // codeDeviceList.value.unshift(...res.data.recordList) - // // 去重 - // if (codeDeviceList.value.length > 0) { - // const seen = new Set() - // codeDeviceList.value = codeDeviceList.value.filter((item) => { - // if (!item.maCode || seen.has(item.maCode)) { - // uni.showToast({ title: '设备已添加', icon: 'none' }) - // return false - // } - // seen.add(item.maCode) - // return true - // }) - // //materialModel - // codeDeviceList.value.forEach((item) => { - // item.materialName = item.typeName - // item.materialModel = item.typeModelName - // item.outType = 2 // 出库方式 二维码 - // item.checked = true // 默认未选中 - // }) - // allChecked.value = codeDeviceList.value.every((e) => e.checked) - // } - // } else { - // uni.showToast({ title: res.data.msg, icon: 'none', duration: 1500 }) - // } - // } else { - // uni.showToast({ title: '扫码识别失败', icon: 'none' }) - // } - // } catch (error) { - // console.log('🚀 ~ success: ~ error:', error) - // } - // } - // }, - // fail: (error) => { - // console.error('扫描出错:', error.message) - // }, - // }) } // 处理RFID识别 @@ -523,19 +453,19 @@ const handleQrCode = async (qrCode) => { if (queryParamsTemp.value.isBack) { res = await getMachine(params) console.log('🚀 ~ handleQrCode ~ res:', res) - if (res.data && res.data.length > 0) { - codeDeviceList.value.forEach((item) => { - const checkedItem = res.data.find((e) => e.maCode === item.maCode) - console.log('🚀 ~ codeDeviceList.value.forEach ~ checkedItem:', checkedItem) - if (checkedItem) { - item.checked = true - uni.showToast({ - title: `设备编码 ${item.maCode} 已勾选`, - icon: 'none', - }) - } - }) + const newItem = { + ...res.data[0], + checked: true, + outType: 0, } + // 根据maCode去重 + const exists = codeDeviceList.value.some((item) => item.maCode === newItem.maCode) + if (exists) { + uni.showToast({ title: '设备已添加', icon: 'none' }) + } else { + codeDeviceList.value.unshift(newItem) + } + allChecked.value = codeDeviceList.value.every((e) => e.checked) return } else { res = await getCodeScanAPI(params) @@ -559,7 +489,7 @@ const handleQrCode = async (qrCode) => { item.materialName = item.typeName item.materialModel = item.typeModelName item.outType = 2 // 出库方式 二维码 - item.checked = true // 默认未选中 + item.checked = true // 默认选中 }) allChecked.value = codeDeviceList.value.every((e) => e.checked) }