| | |
| | | <view class="parent-dialog"> |
| | | <view class="dialog-header"> |
| | | <text class="dialog-title">新增杆包</text> |
| | | <view class="dialog-header-actions"> |
| | | <wd-button type="icon" icon="scan" color="#0D867F" @click="openScan"></wd-button> |
| | | <wd-icon name="close" class="close-icon" @click="closeParentDialog"></wd-icon> |
| | | </view> |
| | | </view> |
| | | <view class="dialog-content"> |
| | | <wd-cell-group> |
| | |
| | | /> |
| | | </wd-popup> |
| | | |
| | | <!-- 扫码组件 --> |
| | | <Scan ref="scanRef" emitName="scanRodBag" /> |
| | | |
| | | <wd-toast /> |
| | | </view> |
| | | </template> |
| | |
| | | import { getTeamId } from "@/utils/cache"; |
| | | import { useUserStore } from "@/store/modules/user"; |
| | | import WireDetailApi from "@/api/product/wire"; |
| | | import Scan from "@/components/scan/index.vue"; |
| | | |
| | | const toast = useToast(); |
| | | const userStore = useUserStore(); |
| | |
| | | wireId: "", |
| | | poleNumber: "", |
| | | }); |
| | | |
| | | // 扫码组件相关 |
| | | const scanRef = ref(); |
| | | |
| | | // 获取详情数据 |
| | | const getDetailData = async (id: string) => { |
| | |
| | | |
| | | // 新增父级数据 - 打开弹框 |
| | | const handleAddParent = () => { |
| | | const lastParent = parentDataList.value[0]; |
| | | |
| | | // 初始化新数据,如果有最后一条数据,使用其值作为默认值 |
| | | // 清空所有数据 |
| | | newParentData.value = { |
| | | poleNumber: lastParent?.poleNumber || "", |
| | | poleModel: lastParent?.poleModel || "", |
| | | polePackageNumber: lastParent?.polePackageNumber || "", |
| | | poleWeight: lastParent?.poleWeight || null, |
| | | supplier: lastParent?.supplier || "", |
| | | poleNumber: "", |
| | | poleModel: "", |
| | | polePackageNumber: "", |
| | | poleWeight: undefined, |
| | | supplier: "", |
| | | isConsumed: 1, |
| | | }; |
| | | |
| | |
| | | }); |
| | | }; |
| | | |
| | | // 打开扫码 |
| | | const openScan = () => { |
| | | if (scanRef.value) { |
| | | scanRef.value.triggerScan(); |
| | | } else { |
| | | toast.error("扫码组件未初始化"); |
| | | } |
| | | }; |
| | | |
| | | // 处理扫码结果 |
| | | const getScanCode = (code: any) => { |
| | | try { |
| | | console.log("扫码结果:", code.code); |
| | | |
| | | let scanData: any = {}; |
| | | |
| | | // 尝试解析 JSON 格式 |
| | | try { |
| | | scanData = JSON.parse(code.code); |
| | | } catch (e) { |
| | | // 如果不是 JSON,尝试按逗号分割 |
| | | const arr = code.code.split(","); |
| | | if (arr.length >= 5) { |
| | | // 根据 wireForm.vue 的格式:arr[2] 是杆型号,arr[3] 是领用杆号,arr[4] 是杆重 |
| | | scanData = { |
| | | poleModel: arr[2], |
| | | poleNumber: arr[3], |
| | | poleWeight: arr[4], |
| | | }; |
| | | } else { |
| | | // 如果格式不匹配,尝试其他解析方式 |
| | | // 可能是合格证二维码,包含炉次号、牌号、规格、净重等信息 |
| | | // 根据合格证信息,尝试提取关键字段 |
| | | const codeStr = code.code; |
| | | |
| | | // 尝试提取炉次号(格式:数字-数字-数字) |
| | | const batchMatch = codeStr.match(/(\d{6,}-\d{3,}-\d{3,})/); |
| | | if (batchMatch) { |
| | | scanData.poleNumber = batchMatch[1]; // 炉次号作为领用杆号 |
| | | } |
| | | |
| | | // 尝试提取牌号(A6等) |
| | | const brandMatch = codeStr.match(/牌号[::]\s*([A-Z]\d+)/i) || codeStr.match(/([A-Z]\d+)/); |
| | | if (brandMatch) { |
| | | scanData.poleModel = brandMatch[1]; // 牌号作为杆型号 |
| | | } |
| | | |
| | | // 尝试提取净重(数字+KG) |
| | | const weightMatch = |
| | | codeStr.match(/净重[::]\s*(\d+(?:\.\d+)?)\s*KG/i) || |
| | | codeStr.match(/(\d+(?:\.\d+)?)\s*KG/i); |
| | | if (weightMatch) { |
| | | scanData.poleWeight = parseFloat(weightMatch[1]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 只填充三个字段:领用杆号、杆型号、杆重(kg) |
| | | if (scanData.poleNumber) { |
| | | newParentData.value.poleNumber = scanData.poleNumber; |
| | | } |
| | | if (scanData.poleModel) { |
| | | newParentData.value.poleModel = scanData.poleModel; |
| | | } |
| | | if (scanData.poleWeight) { |
| | | newParentData.value.poleWeight = parseFloat(scanData.poleWeight); |
| | | } |
| | | |
| | | toast.success("扫码成功,已填充信息"); |
| | | } catch (error) { |
| | | console.error("解析扫码数据失败:", error); |
| | | toast.error("二维码格式错误,请检查二维码"); |
| | | } |
| | | }; |
| | | |
| | | onLoad(async (options: any) => { |
| | | paramsId.value = options.id; |
| | | await getDetailData(options.id); |
| | | await loadSupplierDict(); |
| | | await getData(); |
| | | // 开启扫码监听事件 |
| | | uni.$on("scanRodBag", getScanCode); |
| | | }); |
| | | |
| | | onUnload(() => { |
| | | // 取消扫码监听事件 |
| | | uni.$off("scanRodBag", getScanCode); |
| | | }); |
| | | </script> |
| | | |
| | |
| | | z-index: 10; |
| | | } |
| | | |
| | | .dialog-header-actions { |
| | | display: flex; |
| | | align-items: center; |
| | | gap: 8px; |
| | | } |
| | | |
| | | .dialog-title { |
| | | font-size: 16px; |
| | | color: #333; |