| | |
| | | <script setup> |
| | | import { ref, onMounted, nextTick, reactive } from "vue"; |
| | | import { userLoginFacotryList } from "@/api/login"; |
| | | import { getProductWorkOrderById } from "@/api/productionManagement/productionReporting"; |
| | | import modal from "@/plugins/modal"; |
| | | import useUserStore from "@/store/modules/user"; |
| | | |
| | |
| | | } |
| | | const getcode = () => { |
| | | uni.scanCode({ |
| | | success: res => { |
| | | success: async res => { |
| | | // 解析二维码内容 |
| | | const scanResult = res.result; |
| | | let orderRow = ""; |
| | | |
| | | // 尝试从扫码结果中提取orderRow参数 |
| | | // 判断扫描结果是否为纯数字(id) |
| | | const isNumericId = /^\d+$/.test(scanResult.trim()); |
| | | |
| | | if (isNumericId) { |
| | | // 如果是纯数字,根据 id 获取工单数据 |
| | | 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); |
| | | |
| | | orderRow = JSON.stringify({ |
| | | id: workData.id || workOrderId, |
| | | planQuantity: workData.planQuantity || workData.待生产数量 || 0, |
| | | productProcessRouteItemId: workData.productProcessRouteItemId || workData.产品工艺路线项ID || "", |
| | | }); |
| | | |
| | | console.log("构造的orderRow:", orderRow); |
| | | } else { |
| | | modal.msgError("未找到对应的工单信息"); |
| | | return; |
| | | } |
| | | } catch (error) { |
| | | modal.closeLoading(); |
| | | console.error("获取工单信息失败:", error); |
| | | modal.msgError("获取工单信息失败: " + (error.message || "未知错误")); |
| | | return; |
| | | } |
| | | } else { |
| | | // 如果不是纯数字,尝试从扫码结果中提取orderRow参数 |
| | | try { |
| | | // 处理混合格式: http://...?orderRow={...} |
| | | const orderRowStart = scanResult.indexOf("orderRow={"); |
| | | if (orderRowStart !== -1) { |
| | | // 提取从orderRow={开始的JSON内容 |
| | | const jsonPart = scanResult.substring(orderRowStart + 9); // 9是"orderRow=".length |
| | | // 尝试直接使用这个JSON部分 |
| | | orderRow = jsonPart; |
| | | } else { |
| | | // 如果直接是JSON字符串,尝试解析 |
| | | orderRow = scanResult; |
| | | } |
| | | } catch (e) { |
| | | console.error(e, "解析失败====????====="); |
| | | orderRow = ""; |
| | | } |
| | | console.log(orderRow, "orderRow======@@@@@@@@"); |
| | | |
| | | // 验证是否为有效的JSON |
| | | try { |
| | | JSON.parse(orderRow); |
| | | } catch (error) { |
| | | modal.msgError("订单解析失败"); |
| | | modal.msgError("订单解析失败,请检查二维码格式"); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | console.log(orderRow, "orderRow======@@@@@@@@"); |
| | | // 扫码成功后跳转到生产报工页面,并传递orderRow参数 |
| | | uni.navigateTo({ |
| | | url: `/pages/productionManagement/productionReport/index?orderRow=${orderRow}`, |
| | |
| | | title: "扫码失败", |
| | | icon: "none", |
| | | }); |
| | | // uni.navigateTo({ |
| | | // url: `/pages/productionManagement/productionReport/index`, |
| | | // }); |
| | | }, |
| | | }); |
| | | }; |