From 5c5b7457cfba8010e5ff68eafd79be5c2ecf00a8 Mon Sep 17 00:00:00 2001 From: hayu <1604366271@qq.com> Date: Tue, 20 Jan 2026 18:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E8=B4=AD=E7=BC=96=E7=A0=81=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E9=99=90=E5=88=B6=E4=B8=80=E6=AC=A1=E6=9C=80=E5=A4=9A?= =?UTF-8?q?=E5=85=A550=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/new-purchase/entry/code-inbound.vue | 486 ++++++++++-------- 1 file changed, 282 insertions(+), 204 deletions(-) diff --git a/src/pages/new-purchase/entry/code-inbound.vue b/src/pages/new-purchase/entry/code-inbound.vue index 07bfa8d..b4961f9 100644 --- a/src/pages/new-purchase/entry/code-inbound.vue +++ b/src/pages/new-purchase/entry/code-inbound.vue @@ -51,13 +51,14 @@ @@ -76,10 +77,17 @@ - 入库 + + + 入库 - 全选({{ total }}) + + 全选 + ({{ total }}) + + (最多勾选50个) + @@ -107,6 +115,9 @@ const scanQrCodeRefBox = ref(null) // const taskId = ref('') // const maTypeName = ref('') // const typeName = ref('') +const MAX_CHECKED = 50 +const submitting = ref(false) + // 编码识别按钮 const onCodeIdentify = () => { @@ -329,237 +340,304 @@ const onScrollTolower = () => { // 复选框事件 const onChangeChecked = (item) => { - item.checked = !item.checked - let arr = [] - codeDeviceList.value.forEach((e) => { - if (e.checked == true) { - return arr.push(e) - } - }) - console.log(arr) - total.value = arr.length + if (item.checked) { + item.checked = false + total.value-- + } else { + item.checked = true + total.value++ + } } + + // 复选框事件 const checkedAll = () => { - if (total.value < codeDeviceList.value.length) { - total.value = codeDeviceList.value.length - codeDeviceList.value.forEach((e) => { - e.checked = true - }) - } else if (total.value == codeDeviceList.value.length) { - total.value = 0 - codeDeviceList.value.forEach((e) => { - e.checked = false - }) + // 当前未全选 → 执行“最多50个”的全选 + if (total.value < Math.min(codeDeviceList.value.length, MAX_CHECKED)) { + let count = 0 + codeDeviceList.value.forEach((e) => { + if (count < MAX_CHECKED) { + if (!e.checked) { + e.checked = true + count++ + } + } else { + e.checked = false + } + }) + total.value = Math.min(codeDeviceList.value.length, MAX_CHECKED) + + if (codeDeviceList.value.length > MAX_CHECKED) { + uni.showToast({ + title: `全选最多只能勾选${MAX_CHECKED}个`, + icon: 'none' + }) } + } + // 已经是“50个全选状态” → 取消全选 + else { + codeDeviceList.value.forEach((e) => { + e.checked = false + }) + total.value = 0 + } } + // 入库按钮 const onHandleOutbound = async () => { - const isSelect = codeDeviceList.value.some((e) => e.checked === true) - if (!isSelect) { + if (submitting.value) return + const isSelect = codeDeviceList.value.some((e) => e.checked === true) + if (!isSelect) { + uni.showToast({ + title: '请勾选需要入库的设备', + icon: 'none', + }) + return + } + let maxNum = Number(queryParams.value.purchaseNum) - Number(queryParams.value.inputNum) + console.log(maxNum) + if (total.value > maxNum) { + uni.showToast({ + title: '勾选设备超过待入库数量!', + icon: 'none', + }) + return + } + // 组装入库参数 + const paramsList = [] + codeDeviceList.value.map((e) => { + if (e.checked) { + paramsList.push({ + maCode: e.maCode, + }) + } + }) + uni.showModal({ + title: '提示', + content: '是否确定入库?', + success: async (req) => { + if (!req.confirm) return + + const paramsList = codeDeviceList.value + .filter(e => e.checked) + .map(e => ({ maCode: e.maCode })) + + if (paramsList.length === 0) { uni.showToast({ - title: '请勾选需要入库的设备', - icon: 'none', + title: '请选择需要入库的设备', + icon: 'none', }) return - } - let maxNum = Number(queryParams.value.purchaseNum) - Number(queryParams.value.inputNum) - console.log(maxNum) - if (total.value > maxNum) { - uni.showToast({ - title: '勾选设备超过待入库数量!', + } + + submitting.value = true + uni.showLoading({ + title: '提交中...', + mask: true + }) + + try { + const param = { + ...queryParams.value, + purchaseId: queryParams.value.id, + inPutList: paramsList, + } + const res = await setInboundCodeAPI(param) + if (res.code === 200) { + uni.showToast({ + title: '入库成功!', icon: 'none', - }) - return + }) + await getCodeDeviceListData() + queryParams.value.inputNum = + Number(queryParams.value.inputNum) + paramsList.length + } else { + uni.showToast({ + title: res.msg || '入库失败', + icon: 'none', + }) + } + } catch (error) { + console.log('🚀 ~ onHandleOutbound ~ error:', error) + } finally { + submitting.value = false + uni.hideLoading() + } } - // 组装入库参数 - const paramsList = [] - codeDeviceList.value.map((e) => { - if (e.checked) { - paramsList.push({ - maCode: e.maCode, - }) - } - }) - uni.showModal({ - title: '提示', - content: '是否确定入库?', - success: async (req) => { - if (req.confirm) { - try { - let param = { - ...queryParams.value, - // taskId: queryParams.value.taskId, - // typeId: queryParams.value.typeId, - purchaseId: queryParams.value.id, - inPutList: paramsList, - } - const res = await setInboundCodeAPI(param) - console.log(res, '入库') - if (res.code === 200) { - uni.showToast({ - title: '入库成功!', - icon: 'none', - }) - getCodeDeviceListData() - setTimeout(() => { - queryParams.value.inputNum = Number(queryParams.value.inputNum) + paramsList.length - }, 800) - } - } catch (error) { - console.log('🚀 ~ onHandleOutbound ~ error:', error) - } - } - } - }) + }) }