| | |
| | | type="icon" |
| | | icon="scan" |
| | | color="#0d867f" |
| | | @click="openScan" |
| | | style="color: #0d867f" |
| | | @click="openScan" |
| | | ></wd-button> |
| | | </template> |
| | | </CardTitle> |
| | | |
| | | <!-- 当前物料信息 --> |
| | | <view class="material-info" v-if="currentMaterial"> |
| | | <view v-if="currentMaterial" class="material-info"> |
| | | <wd-card custom-class="info-card"> |
| | | <view class="info-compact"> |
| | | <view class="icon_box"> |
| | |
| | | <text class="outbound_item_label">生产批次号:</text> |
| | | <text class="outbound_item_value">{{ item.monofilamentNumber || "-" }}</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">规格型号:</text> |
| | | <text class="outbound_item_value">{{ item.model || "-" }}</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">重量:</text> |
| | | <text class="outbound_item_value">{{ item.weight || "-" }} kg</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">厂家:</text> |
| | | <text class="outbound_item_value">{{ item.clienteleName || "-" }}</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">段长:</text> |
| | | <text class="outbound_item_value">{{ item.actuallyLength || "-" }} M</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">生产日期:</text> |
| | | <text class="outbound_item_value">{{ item.productionDate || "-" }}</text> |
| | | </view> |
| | | <template v-if="!item.isMesMissing"> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">规格型号:</text> |
| | | <text class="outbound_item_value">{{ item.model || "-" }}</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">重量:</text> |
| | | <text class="outbound_item_value">{{ item.weight || "-" }} kg</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">厂家:</text> |
| | | <text class="outbound_item_value">{{ item.clienteleName || "-" }}</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">段长:</text> |
| | | <text class="outbound_item_value">{{ item.actuallyLength || "-" }} M</text> |
| | | </view> |
| | | <view class="outbound_item_row"> |
| | | <text class="outbound_item_label">生产日期:</text> |
| | | <text class="outbound_item_value">{{ item.productionDate || "-" }}</text> |
| | | </view> |
| | | </template> |
| | | </view> |
| | | </view> |
| | | <view class="outbound_item_action"> |
| | |
| | | |
| | | <!-- 底部按钮 --> |
| | | <view v-if="goodsList.length > 0" class="outbound_footer"> |
| | | <wd-button block @click="handleOutbound" style="background: #0d867f"> |
| | | <wd-button block style="background: #0d867f" @click="handleOutbound"> |
| | | <text class="text-[#fff]">出库</text> |
| | | </wd-button> |
| | | </view> |
| | |
| | | return dayjs(date).format("YYYY-MM-DD HH:mm:ss"); |
| | | }; |
| | | |
| | | const handleMonofilamentNumber = (value?: string) => { |
| | | if (!value) return ""; |
| | | if (!value.includes("-")) { |
| | | if (value.length < 3) { |
| | | toast.error("单丝编号长度不足,无法添加 '-'"); |
| | | return ""; |
| | | } |
| | | const insertIndex = value.length - 3; |
| | | return `${value.slice(0, insertIndex)}-${value.slice(insertIndex)}`; |
| | | } |
| | | return value; |
| | | }; |
| | | |
| | | // 直接扫码 |
| | | const openScan = () => { |
| | | scanRef.value?.triggerScan(); |
| | |
| | | return; |
| | | } |
| | | |
| | | // 解析扫码数据,现在二维码只包含id |
| | | let scanData; |
| | | try { |
| | | scanData = JSON.parse(scanCode); |
| | | } catch (e) { |
| | | toast.error("二维码格式错误"); |
| | | return; |
| | | // 去掉首尾空格 |
| | | const scanText = String(scanCode).trim(); |
| | | |
| | | // 判断是否为 JSON 格式(绞线等原有二维码) |
| | | const isJsonCode = scanText.startsWith("{") || scanText.startsWith("["); |
| | | |
| | | let tagData: any = null; |
| | | let outPutId: string | number | undefined; |
| | | let monofilamentNumber: string | undefined; |
| | | let needContractCheck = false; // 是否需要进行合同号校验(只对绞线) |
| | | |
| | | if (isJsonCode) { |
| | | // ===== 绞线等原有二维码逻辑(JSON) ===== |
| | | let scanData; |
| | | try { |
| | | scanData = JSON.parse(scanText); |
| | | } catch { |
| | | toast.error("二维码格式错误"); |
| | | return; |
| | | } |
| | | |
| | | outPutId = scanData.id; |
| | | |
| | | if (!outPutId) { |
| | | toast.error("二维码格式错误,缺少id信息"); |
| | | return; |
| | | } |
| | | |
| | | // 检查是否已存在(根据 id 判断) |
| | | const exists = goodsList.value.some((item) => { |
| | | const itemId = item.id; |
| | | return itemId && itemId === outPutId && itemId !== "-"; |
| | | }); |
| | | |
| | | if (exists) { |
| | | toast.error("该条码已存在,请勿重复扫码"); |
| | | return; |
| | | } |
| | | |
| | | // 调用接口获取绞线/拉丝详细信息(含出库状态) |
| | | const { data } = await OutboundApi.getTagByIdAll({ |
| | | outPutId: outPutId, |
| | | }); |
| | | |
| | | const list = data || []; |
| | | if (!list.length) { |
| | | toast.error("未查询到条码信息"); |
| | | return; |
| | | } |
| | | |
| | | tagData = list[0]; |
| | | needContractCheck = true; // 只有绞线需要做合同号校验 |
| | | } else { |
| | | // ===== 单丝拉丝二维码逻辑(纯字符串) ===== |
| | | // 示例:ZD7z30202616101201#[@]01,Φ5.6,-,750826011001001,600.6 |
| | | // 需要提取以 75 开头的单丝号 |
| | | const parts = scanText.split(/[,\s]/).filter((p) => !!p); |
| | | monofilamentNumber = parts.find((p) => p.startsWith("75")); |
| | | |
| | | if (!monofilamentNumber) { |
| | | toast.error("二维码格式错误,未找到单丝号"); |
| | | return; |
| | | } |
| | | |
| | | // 检查是否已存在(根据单丝号判断) |
| | | const exists = goodsList.value.some((item) => { |
| | | const itemMono = item.monofilamentNumber; |
| | | return itemMono && itemMono === monofilamentNumber && itemMono !== "-"; |
| | | }); |
| | | |
| | | if (exists) { |
| | | toast.error("该条码已存在,请勿重复扫码"); |
| | | return; |
| | | } |
| | | |
| | | // 调用拉丝接口:GET /mes/app/getTagByLsMonofilamentNumber?monofilamentNumber=xxxx |
| | | let data; |
| | | try { |
| | | const response = await OutboundApi.getTagByLsMonofilamentNumber({ |
| | | monofilamentNumber, |
| | | }); |
| | | data = response.data; |
| | | } catch { |
| | | data = null; |
| | | } |
| | | |
| | | const list = Array.isArray(data) ? data : data ? [data] : []; |
| | | if (!list.length) { |
| | | const formattedMonofilamentNumber = handleMonofilamentNumber(monofilamentNumber); |
| | | if (!formattedMonofilamentNumber) { |
| | | return; |
| | | } |
| | | const newItem = { |
| | | id: monofilamentNumber || "-", |
| | | contractNo: "未在mes中生产", |
| | | monofilamentNumber: formattedMonofilamentNumber, |
| | | model: "-", |
| | | weight: "-", |
| | | clienteleName: "-", |
| | | actuallyLength: "-", |
| | | productionDate: "-", |
| | | type: "", |
| | | devicemodel: "", |
| | | state: "", |
| | | projectId: "", |
| | | productuser: "", |
| | | rawData: null, |
| | | scanCode: scanText, |
| | | scanTime: formatTime(new Date()), |
| | | isMesMissing: true, |
| | | }; |
| | | goodsList.value.push(newItem); |
| | | toast.success("扫码成功"); |
| | | return; |
| | | } |
| | | |
| | | tagData = list[0]; |
| | | outPutId = tagData?.id || monofilamentNumber; |
| | | // 拉丝不做合同号校验 |
| | | } |
| | | |
| | | const outPutId = scanData.id; |
| | | |
| | | if (!outPutId) { |
| | | toast.error("二维码格式错误,缺少id信息"); |
| | | return; |
| | | } |
| | | |
| | | // 检查是否已存在(根据id判断) |
| | | const exists = goodsList.value.some((item) => { |
| | | const itemId = item.id; |
| | | return itemId && itemId === outPutId && itemId !== "-"; |
| | | }); |
| | | |
| | | if (exists) { |
| | | toast.error("该条码已存在,请勿重复扫码"); |
| | | return; |
| | | } |
| | | |
| | | // 调用接口获取绞线/拉丝详细信息(含出库状态) |
| | | const { data } = await OutboundApi.getTagByIdAll({ |
| | | outPutId: outPutId, |
| | | }); |
| | | |
| | | const list = data || []; |
| | | if (!list.length) { |
| | | toast.error("未查询到条码信息"); |
| | | return; |
| | | } |
| | | |
| | | const tagData = list[0]; |
| | | |
| | | // 已出库校验 |
| | | // 已出库校验(绞线 / 拉丝 通用) |
| | | if (tagData?.state === "已出库") { |
| | | toast.error("该条码已出库,无法重复出库"); |
| | | return; |
| | | } |
| | | |
| | | // 合同号校验:检查扫码的合同号是否等于发货单的vsrccode |
| | | const scannedContractNo = tagData?.contractno || ""; |
| | | if (scannedContractNo && vsrccode.value && scannedContractNo !== vsrccode.value) { |
| | | toast.error(`合同号"${scannedContractNo}"与当前发货单为"${vsrccode.value}"不匹配`); |
| | | return; |
| | | // 合同号校验:只对绞线(JSON 场景)进行校验 |
| | | if (needContractCheck) { |
| | | const scannedContractNo = tagData?.contractno || ""; |
| | | if (scannedContractNo && vsrccode.value && scannedContractNo !== vsrccode.value) { |
| | | toast.error(`合同号"${scannedContractNo}"与当前发货单为"${vsrccode.value}"不匹配`); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | // 提取数据字段(根据接口返回的数据结构) |
| | |
| | | tagData?.monofilamentNumber || |
| | | tagData?.systemno || |
| | | tagData?.systemNo || |
| | | monofilamentNumber || |
| | | "-", |
| | | model: tagData?.model || "-", |
| | | weight: tagData?.actuallylength || tagData?.actuallyLength || tagData?.weight || "-", |
| | |
| | | productuser: tagData?.productuser || "", |
| | | // 保留原始数据 |
| | | rawData: tagData, |
| | | scanCode: scanCode, |
| | | scanCode: scanText, |
| | | }; |
| | | |
| | | // 添加到列表 |
| | |
| | | const requestData = goodsList.value.map((item) => ({ |
| | | outPutId: item.id, |
| | | projectId: item.projectId || "", |
| | | monofilamentNumber: item.monofilamentNumber || "", |
| | | })); |
| | | |
| | | // 按出库单明细构建请求体 |
| | |
| | | cdeliveryid: currentMaterial.value?.cdeliveryid || "", |
| | | cdeliverybid: currentMaterial.value?.cdeliverybid || "", |
| | | materialcode: currentMaterial.value?.materialcode || "", |
| | | vfree4: currentMaterial.value?.vfree4 || "", |
| | | }; |
| | | |
| | | try { |
| | |
| | | uni.$on("scanMaterial", getScanCode); |
| | | }; |
| | | |
| | | // 安全解码(兼容已解码或未编码的情况) |
| | | const safeDecode = (val: any) => { |
| | | if (typeof val !== "string") return val || ""; |
| | | try { |
| | | // 如果是编码过的(包含 %),decode 一次;否则直接返回 |
| | | return val.includes("%") ? decodeURIComponent(val) : val; |
| | | } catch { |
| | | return val; |
| | | } |
| | | }; |
| | | |
| | | onLoad((options: any) => { |
| | | // 从路由参数中获取物料基本信息、出库单信息和 vsrccode |
| | | currentMaterial.value = { |
| | | materialname: options.materialname || "-", |
| | | materialspec: options.materialspec || "-", |
| | | materialname: safeDecode(options.materialname || "-"), |
| | | materialspec: safeDecode(options.materialspec || "-"), |
| | | shippedQuantity: Number(options.shippedQuantity || 0), |
| | | cdeliveryid: options.cdeliveryid || "", |
| | | cdeliverybid: options.cdeliverybid || "", |
| | | materialcode: options.materialcode || "", |
| | | cdeliveryid: safeDecode(options.cdeliveryid || ""), |
| | | cdeliverybid: safeDecode(options.cdeliverybid || ""), |
| | | materialcode: safeDecode(options.materialcode || ""), |
| | | vfree4: safeDecode(options.vfree4 || ""), |
| | | }; |
| | | vsrccode.value = options.vsrccode || ""; |
| | | }); |