| | |
| | | remarks: item['备注 | Remarks'] |
| | | }; |
| | | }); |
| | | // 使用post方法直接传递数组 |
| | | iptOrder(transformedData).then(res => { |
| | | console.log(res, transformedData); |
| | | |
| | | // 数据校验和过滤 |
| | | const filteredData = []; |
| | | const invalidData = []; |
| | | |
| | | transformedData.forEach((item, index) => { |
| | | const errors = []; |
| | | |
| | | // 检查是否所有字段都为空(排除userExtra字段) |
| | | const { userExtra, ...otherFields } = item; |
| | | const allFieldsEmpty = Object.values(otherFields).every(value => |
| | | value === '' || value === null || value === undefined |
| | | ); |
| | | |
| | | // 如果所有字段都为空,跳过这条数据 |
| | | if (allFieldsEmpty) { |
| | | return; |
| | | } |
| | | |
| | | // 必填字段校验 |
| | | const requiredFields = [ |
| | | { field: 'ContainerNo', name: '集装箱号' }, |
| | | { field: 'BolNo', name: '提单号' }, |
| | | { field: 'containerType', name: '柜型' }, |
| | | { field: 'carrier', name: '船司' }, |
| | | { field: 'vesselNameAndVoyage', name: '船名航次' }, |
| | | { field: 'pickupLocation', name: '提柜地' }, |
| | | { field: 'eta', name: '预计到港' }, |
| | | { field: 'soc', name: 'SOC' }, |
| | | { field: 'dg', name: 'DG' }, |
| | | { field: 'overweight', name: '是否超重' }, |
| | | { field: 'exam', name: '是否查验' }, |
| | | { field: 'commodity', name: '品名' }, |
| | | { field: 'qty', name: '数量' }, |
| | | { field: 'GrWt', name: '毛重' }, |
| | | { field: 'volume', name: '体积' }, |
| | | { field: 'companyName', name: '收件人公司' }, |
| | | { field: 'postalCode', name: '邮编' }, |
| | | { field: 'address', name: '地址' } |
| | | ]; |
| | | |
| | | requiredFields.forEach(({ field, name }) => { |
| | | if (!item[field]) { |
| | | errors.push(`${name}不能为空`); |
| | | } |
| | | }); |
| | | |
| | | // 联系电话和邮箱至少填写一项 |
| | | if (!item.tel && !item.email) { |
| | | errors.push('联系电话和邮箱至少填写其中一项'); |
| | | } |
| | | |
| | | if (errors.length > 0) { |
| | | invalidData.push({ |
| | | row: index + 4, |
| | | containerNo: item.ContainerNo, |
| | | errors: errors |
| | | }); |
| | | } else { |
| | | filteredData.push(item); |
| | | } |
| | | }); |
| | | |
| | | // 显示被过滤掉的数据信息 |
| | | if (invalidData.length > 0 && filteredData.length > 0) { |
| | | const errorMessage = invalidData.map(data => |
| | | `第${data.row}行(集装箱号: ${data.containerNo || '无'}): ${data.errors.join('; ')}` |
| | | ).join('\n'); |
| | | |
| | | this.$message.warning({ |
| | | message: `以下${invalidData.length}条数据不符合要求,将被过滤:\n${errorMessage}`, |
| | | duration: 0, |
| | | showClose: true |
| | | }); |
| | | } |
| | | |
| | | if (filteredData.length === 0) { |
| | | this.$message.error('没有有效数据可以导入'); |
| | | return; |
| | | } |
| | | |
| | | // 使用post方法直接传递过滤后的数组 |
| | | iptOrder(filteredData).then(res => { |
| | | console.log(res, filteredData); |
| | | |
| | | if (res) { |
| | | this.$message({ |