| | |
| | | </up-grid> |
| | | </view> |
| | | </view> |
| | | <PdaScan :active="pdaScanActive" |
| | | eventName="scan_work_report" /> |
| | | <ScanWaitMask :show="scanMaskShow" |
| | | :status="scanMaskStatus" /> |
| | | <PdaScan /> |
| | | <DownloadProgressMask /> |
| | | </view> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, onMounted, nextTick, reactive, computed } from "vue"; |
| | | import { onShow } from "@dcloudio/uni-app"; |
| | | import { userLoginFacotryList } from "@/api/login"; |
| | | import { getProductWorkOrderById } from "@/api/productionManagement/productionReporting"; |
| | | import DownloadProgressMask from "@/components/DownloadProgressMask.vue"; |
| | | import ScanWaitMask from "@/components/ScanWaitMask.vue"; |
| | | import PdaScan from "@/components/pda-scan/pda-scan.vue"; |
| | | import modal from "@/plugins/modal"; |
| | | import useUserStore from "@/store/modules/user"; |
| | |
| | | const show = ref(false); |
| | | const factoryList = ref([]); |
| | | const factoryListTem = ref([]); |
| | | const pdaScanActive = ref(false); |
| | | const pendingWorkReportScan = ref(false); |
| | | let scanWorkReportTimer = null; |
| | | const scanMaskShow = ref(false); |
| | | const scanMaskStatus = ref("waiting"); |
| | | const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); |
| | | const iconStyle = { |
| | | fontSize: "1.125rem", |
| | | color: "#2979ff", |
| | |
| | | factoryList.value = []; |
| | | }); |
| | | } |
| | | const getcode = async () => { |
| | | const canUsePdaBroadcast = () => { |
| | | |
| | | const canUsePdaBroadcast = () => { |
| | | try { |
| | | if (typeof plus === "undefined") return false; |
| | | if (plus?.os?.name !== "Android") return false; |
| | | if (!plus?.android) return false; |
| | | |
| | | const sys = uni.getSystemInfoSync?.() || {}; |
| | | const brand = String(sys?.brand || "").toUpperCase(); |
| | | const model = String(sys?.model || "").toUpperCase(); |
| | | |
| | | return ( |
| | | brand.includes("DROI") || |
| | | model.includes("MV-IDP5204") || |
| | | model.includes("IDP") |
| | | ); |
| | | } catch (e) { |
| | | return false; |
| | | } |
| | | }; |
| | | |
| | | const handleWorkReportScan = async scanResultRaw => { |
| | | const scanResult = scanResultRaw == null ? "" : String(scanResultRaw); |
| | | let orderRow = ""; |
| | | |
| | | const isNumericId = /^\d+$/.test(scanResult.trim()); |
| | | |
| | | if (isNumericId) { |
| | | const workOrderId = scanResult.trim(); |
| | | modal.loading("正在获取工单信息..."); |
| | | try { |
| | | if (typeof plus === "undefined") return false; |
| | | if (plus?.os?.name !== "Android") return false; |
| | | if (!plus?.android) return false; |
| | | const workRes = await getProductWorkOrderById({ id: workOrderId }); |
| | | modal.closeLoading(); |
| | | |
| | | const sys = uni.getSystemInfoSync?.() || {}; |
| | | const brand = String(sys?.brand || "").toUpperCase(); |
| | | const model = String(sys?.model || "").toUpperCase(); |
| | | console.log("工单查询结果:", workRes); |
| | | |
| | | return ( |
| | | brand.includes("DROI") || |
| | | model.includes("MV-IDP5204") || |
| | | model.includes("IDP") |
| | | ); |
| | | } catch (e) { |
| | | return false; |
| | | } |
| | | }; |
| | | if (workRes.code === 200 && workRes.data) { |
| | | const workData = workRes.data; |
| | | console.log("工单数据:", workData); |
| | | |
| | | const handleWorkReportScan = async scanResultRaw => { |
| | | const scanResult = scanResultRaw == null ? "" : String(scanResultRaw); |
| | | let orderRow = ""; |
| | | |
| | | const isNumericId = /^\d+$/.test(scanResult.trim()); |
| | | |
| | | if (isNumericId) { |
| | | const workOrderId = scanResult.trim(); |
| | | modal.loading("正在获取工单信息..."); |
| | | try { |
| | | const workRes = await getProductWorkOrderById({ id: workOrderId }); |
| | | modal.closeLoading(); |
| | | |
| | | console.log("工单查询结果:", workRes); |
| | | |
| | | if (workRes.code === 200 && workRes.data) { |
| | | const workData = workRes.data; |
| | | console.log("工单数据:", workData); |
| | | |
| | | if (workData.endOrder === true) { |
| | | modal.msgError("该订单已结束,无法报工"); |
| | | return; |
| | | } |
| | | |
| | | orderRow = JSON.stringify(workData); |
| | | |
| | | console.log("构造的orderRow:", orderRow); |
| | | } else { |
| | | modal.msgError("未找到对应的工单信息"); |
| | | if (workData.endOrder === true) { |
| | | modal.msgError("该订单已结束,无法报工"); |
| | | return; |
| | | } |
| | | } catch (error) { |
| | | modal.closeLoading(); |
| | | console.error("获取工单信息失败:", error); |
| | | modal.msgError("获取工单信息失败: " + (error.message || "未知错误")); |
| | | return; |
| | | } |
| | | } else { |
| | | try { |
| | | const orderRowStart = scanResult.indexOf("orderRow={"); |
| | | if (orderRowStart !== -1) { |
| | | const jsonPart = scanResult.substring(orderRowStart + 9); |
| | | orderRow = jsonPart; |
| | | } else { |
| | | orderRow = scanResult; |
| | | } |
| | | } catch (e) { |
| | | console.error(e, "解析失败====????====="); |
| | | orderRow = ""; |
| | | } |
| | | |
| | | try { |
| | | JSON.parse(orderRow); |
| | | } catch (error) { |
| | | modal.msgError("订单解析失败,请检查二维码格式"); |
| | | orderRow = JSON.stringify(workData); |
| | | |
| | | console.log("构造的orderRow:", orderRow); |
| | | } else { |
| | | modal.msgError("未找到对应的工单信息"); |
| | | return; |
| | | } |
| | | } catch (error) { |
| | | modal.closeLoading(); |
| | | console.error("获取工单信息失败:", error); |
| | | modal.msgError("获取工单信息失败: " + (error.message || "未知错误")); |
| | | return; |
| | | } |
| | | } else { |
| | | try { |
| | | const orderRowStart = scanResult.indexOf("orderRow={"); |
| | | if (orderRowStart !== -1) { |
| | | const jsonPart = scanResult.substring(orderRowStart + 9); |
| | | orderRow = jsonPart; |
| | | } else { |
| | | orderRow = scanResult; |
| | | } |
| | | } catch (e) { |
| | | console.error(e, "解析失败====????====="); |
| | | orderRow = ""; |
| | | } |
| | | |
| | | uni.navigateTo({ |
| | | url: `/pages/productionManagement/productionReport/index?orderRow=${orderRow}`, |
| | | }); |
| | | }; |
| | | try { |
| | | JSON.parse(orderRow); |
| | | } catch (error) { |
| | | modal.msgError("订单解析失败,请检查二维码格式"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | if (canUsePdaBroadcast()) { |
| | | uni.navigateTo({ |
| | | url: `/pages/productionManagement/productionReport/index?orderRow=${orderRow}`, |
| | | }); |
| | | }; |
| | | |
| | | onShow(() => { |
| | | uni.$off("scan"); |
| | | uni.$on("scan", async data => { |
| | | console.log("onscan"); |
| | | console.log("扫码结果:", data.code); |
| | | if (!pendingWorkReportScan.value) return; |
| | | |
| | | pendingWorkReportScan.value = false; |
| | | scanMaskStatus.value = "done"; |
| | | if (scanWorkReportTimer) { |
| | | clearTimeout(scanWorkReportTimer); |
| | | scanWorkReportTimer = null; |
| | | } |
| | | uni.$off("scan_work_report"); |
| | | uni.$on("scan_work_report", async data => { |
| | | pdaScanActive.value = false; |
| | | uni.$off("scan_work_report"); |
| | | await delay(350); |
| | | scanMaskShow.value = false; |
| | | await handleWorkReportScan(data?.code); |
| | | }); |
| | | }); |
| | | |
| | | const getcode = async () => { |
| | | pendingWorkReportScan.value = true; |
| | | scanMaskStatus.value = "waiting"; |
| | | scanMaskShow.value = true; |
| | | |
| | | if (scanWorkReportTimer) { |
| | | clearTimeout(scanWorkReportTimer); |
| | | scanWorkReportTimer = null; |
| | | } |
| | | |
| | | scanWorkReportTimer = setTimeout(() => { |
| | | pendingWorkReportScan.value = false; |
| | | scanWorkReportTimer = null; |
| | | scanMaskStatus.value = "timeout"; |
| | | delay(900).then(() => { |
| | | scanMaskShow.value = false; |
| | | }); |
| | | }, 20000); |
| | | |
| | | if (canUsePdaBroadcast()) return; |
| | | |
| | | uni.scanCode({ |
| | | success: async res => { |
| | | pendingWorkReportScan.value = false; |
| | | scanMaskStatus.value = "done"; |
| | | if (scanWorkReportTimer) { |
| | | clearTimeout(scanWorkReportTimer); |
| | | scanWorkReportTimer = null; |
| | | } |
| | | await handleWorkReportScan(data?.code); |
| | | }); |
| | | pdaScanActive.value = true; |
| | | uni.showToast({ |
| | | title: "请使用PDA扫码", |
| | | icon: "none", |
| | | }); |
| | | scanWorkReportTimer = setTimeout(() => { |
| | | pdaScanActive.value = false; |
| | | uni.$off("scan_work_report"); |
| | | scanWorkReportTimer = null; |
| | | }, 20000); |
| | | return; |
| | | } |
| | | |
| | | uni.scanCode({ |
| | | success: async res => { |
| | | await delay(350); |
| | | scanMaskShow.value = false; |
| | | await handleWorkReportScan(res.result); |
| | | }, |
| | | fail: err => { |
| | | pendingWorkReportScan.value = false; |
| | | scanMaskStatus.value = "timeout"; |
| | | delay(900).then(() => { |
| | | scanMaskShow.value = false; |
| | | }); |
| | | if (scanWorkReportTimer) { |
| | | clearTimeout(scanWorkReportTimer); |
| | | scanWorkReportTimer = null; |
| | | } |
| | | uni.showToast({ |
| | | title: "扫码失败", |
| | | icon: "none", |