| | |
| | | return |
| | | } |
| | | |
| | | // 发送数据到 MES 接口 |
| | | // 发送数据 |
| | | submitGlassData(parsedData) |
| | | |
| | | } catch (error) { |
| | |
| | | headerStr.includes('qty') || headerStr === '数量') { |
| | | headerMap.quantity = index |
| | | } |
| | | // 订单号 |
| | | else if (headerStr.includes('订单') || headerStr.includes('order') || |
| | | headerStr.includes('orderno') || headerStr === '订单号') { |
| | | headerMap.orderNumber = index |
| | | } |
| | | // 膜系 |
| | | else if (headerStr.includes('膜系') || headerStr.includes('films') || |
| | | headerStr.includes('film') || headerStr === '膜系id') { |
| | |
| | | const height = row[headerMap.height] ? String(row[headerMap.height]).trim() : '' |
| | | const thickness = row[headerMap.thickness] ? String(row[headerMap.thickness]).trim() : '' |
| | | const quantity = row[headerMap.quantity] ? String(row[headerMap.quantity]).trim() : '' |
| | | // 订单序号(接口要求整数,这里尝试解析为整数,不可解析则置空) |
| | | const orderNumber = parseInt(row[headerMap.orderNumber]) || '' |
| | | const filmsId = row[headerMap.filmsId] ? String(row[headerMap.filmsId]).trim() : '' |
| | | const flowCardId = row[headerMap.flowCardId] ? String(row[headerMap.flowCardId]).trim() : '' |
| | | const productName = row[headerMap.productName] ? String(row[headerMap.productName]).trim() : '' |
| | |
| | | height: parseNumber(height), |
| | | thickness: parseNumber(thickness), |
| | | quantity: '1', // 每条记录数量为1 |
| | | orderNumber: orderNumber, |
| | | filmsId: filmsId, |
| | | flowCardId: flowCardId || finalGlassId, |
| | | productName: productName, |
| | |
| | | |
| | | const response = await engineeringApi.importEngineer(requestData) |
| | | |
| | | if (response?.code === 200 || response?.code === 0 || response?.data) { |
| | | ElMessage.success(`成功导入 ${glassDataList.length} 条玻璃数据,工程号:${requestData.engineerId}`) |
| | | // 检查 MES 接口是否调用成功 |
| | | // MES 接口成功时返回格式:{ code: 200/0, data: true/false, message: "..." } |
| | | if (response?.code === 200 || response?.code === 0) { |
| | | // MES 接口调用成功 |
| | | const engineerId = response?.data?.engineerId || response?.engineerId || '' |
| | | const successMsg = engineerId |
| | | ? `成功导入 ${glassDataList.length} 条玻璃数据,工程号:${engineerId}` |
| | | : `成功导入 ${glassDataList.length} 条玻璃数据` |
| | | ElMessage.success(successMsg) |
| | | |
| | | // 将导入的玻璃ID填充到输入框,方便用户查看和编辑 |
| | | const glassIds = glassDataList.map(item => item.glassId).filter(id => id) |
| | |
| | | glassIdsInput.value = glassIds.join('\n') |
| | | } |
| | | } else { |
| | | throw new Error(response?.message || '导入失败') |
| | | // MES 接口返回失败 |
| | | throw new Error(response?.message || 'MES 接口返回失败') |
| | | } |
| | | } catch (error) { |
| | | console.error('提交玻璃数据失败:', error) |
| | | |
| | | // 显示错误信息 |
| | | const errorMsg = error?.response?.data?.message || error?.message || '未知错误' |
| | | // 判断错误类型,给出更友好的提示 |
| | | let errorMsg = '未知错误' |
| | | |
| | | // 检查是否是后端返回的错误响应(后端转发 MES 失败) |
| | | if (error?.response?.status === 500 && error?.response?.data) { |
| | | // 后端返回的统一错误格式 |
| | | errorMsg = error.response.data.message || error.response.data || '转发 MES 接口失败' |
| | | } else if (error?.response?.data?.message) { |
| | | // MES 接口返回的错误 |
| | | errorMsg = error.response.data.message |
| | | } else if (error?.message) { |
| | | errorMsg = error.message |
| | | } |
| | | |
| | | ElMessage.error('提交数据失败: ' + errorMsg) |
| | | |
| | | // 即使失败,也尝试填充玻璃ID到输入框 |