作者 xudada

前端解析主单excel文件,前端赋值

@@ -26,6 +26,15 @@ @@ -26,6 +26,15 @@
26 <el-col style="margin-left: 30px" :span="2"> 26 <el-col style="margin-left: 30px" :span="2">
27 <el-button type="warning" plain @click="cancleBtn">清空</el-button> 27 <el-button type="warning" plain @click="cancleBtn">清空</el-button>
28 </el-col> 28 </el-col>
  29 + <el-col :span="2">
  30 + <el-upload
  31 + action=""
  32 + :on-change="handleChange"
  33 + :auto-upload="false"
  34 + :show-file-list="false">
  35 + <el-button slot="trigger" type="primary">Excel文件</el-button>
  36 + </el-upload>
  37 + </el-col>
29 </el-row> 38 </el-row>
30 <!-- 发货人信息--> 39 <!-- 发货人信息-->
31 <el-row> 40 <el-row>
@@ -2077,6 +2086,56 @@ Handling Information @@ -2077,6 +2086,56 @@ Handling Information
2077 import {loginedUserInfo} from "../../api/user"; 2086 import {loginedUserInfo} from "../../api/user";
2078 import {getList} from "../../api/consigner/consigner"; 2087 import {getList} from "../../api/consigner/consigner";
2079 import jsutil from "@/common/js/util"; 2088 import jsutil from "@/common/js/util";
  2089 + import XLSX from 'xlsx';
  2090 + function cleanString(str, maxLength = 20) {
  2091 + return str.replace(/[^a-zA-Z0-9\s]/g, '').slice(0, maxLength);
  2092 + }
  2093 +
  2094 + /*function parseCustomDate(dateStr) {
  2095 + if (typeof dateStr !== 'string') {
  2096 + return '无效日期';
  2097 + }
  2098 +
  2099 + // 自定义日期格式正则表达式
  2100 + const regex = /(\d{1,2})\/([a-zA-Z]{3})\/(\d{4})/;
  2101 + const match = dateStr.match(regex);
  2102 +
  2103 + if (match) {
  2104 + const day = match[1];
  2105 + const month = match[2];
  2106 + const year = match[3];
  2107 +
  2108 + // 月份缩写映射
  2109 + const monthMap = {
  2110 + Jan: '01', Feb: '02', Mar: '03', Apr: '04',
  2111 + May: '05', Jun: '06', Jul: '07', Aug: '08',
  2112 + Sep: '09', Oct: '10', Nov: '11', Dec: '12'
  2113 + };
  2114 +
  2115 + const formattedMonth = monthMap[month.toUpperCase()];
  2116 + if (formattedMonth) {
  2117 + return `${year}-${formattedMonth}-${day.padStart(2, '0')}`;
  2118 + }
  2119 + }
  2120 +
  2121 + return '无效日期';
  2122 + }*/
  2123 +
  2124 + function formatAF23(value) {
  2125 + if (typeof value !== 'string') {
  2126 + return '无效值';
  2127 + }
  2128 +
  2129 + // 删除 DIMS: 行和 VOL: 行
  2130 + const cleanedValue = value.replace(/DIMS:\s*/gi, '').replace(/VOL:\s*\d+\.\d+\s*CBM/gi, '');
  2131 +
  2132 + // 将剩余内容按行分割,并去除空行
  2133 + const lines = cleanedValue.split('\n').filter(line => line.trim() !== '');
  2134 +
  2135 + // 将非空行重新组合成字符串,并用换行符分隔
  2136 + return lines.join('\n').trim();
  2137 + }
  2138 +
2080 2139
2081 export default { 2140 export default {
2082 components: { 2141 components: {
@@ -2123,23 +2182,23 @@ Handling Information @@ -2123,23 +2182,23 @@ Handling Information
2123 cvd_amount_of_insurance:'XXX', 2182 cvd_amount_of_insurance:'XXX',
2124 cvd_charge_code:'PP', 2183 cvd_charge_code:'PP',
2125 cvd_charge_prepaid:'PP', 2184 cvd_charge_prepaid:'PP',
2126 - cvd_currency_code:'EUR', 2185 + cvd_currency_code:'CNY',
2127 cvd_value_for_carriage:'NVD', 2186 cvd_value_for_carriage:'NVD',
2128 cvd_value_for_customs:'NCV', 2187 cvd_value_for_customs:'NCV',
2129 }, 2188 },
2130 flt:{ 2189 flt:{
2131 cariier:"HQ", 2190 cariier:"HQ",
2132 - day:'02', 2191 + day:'08',
2133 flightNumber:'405', 2192 flightNumber:'405',
2134 cariier2:"HQ", 2193 cariier2:"HQ",
2135 - day2:'02', 2194 + day2:'08',
2136 flightNumber2:'4055', 2195 flightNumber2:'4055',
2137 cariier3:"", 2196 cariier3:"",
2138 day3:'', 2197 day3:'',
2139 flightNumber3:'', 2198 flightNumber3:'',
2140 }, 2199 },
2141 isu:{ 2200 isu:{
2142 - isu_day_mounth_year:'2024-11-01', 2201 + isu_day_mounth_year:'2024-11-07',
2143 isu_place_or_airport_code:'ZHENGZHOU', 2202 isu_place_or_airport_code:'ZHENGZHOU',
2144 isu_signature:'CHINA', 2203 isu_signature:'CHINA',
2145 }, 2204 },
@@ -2190,11 +2249,11 @@ Handling Information @@ -2190,11 +2249,11 @@ Handling Information
2190 rtd_charge_weight:'', 2249 rtd_charge_weight:'',
2191 rtd_combination_point:'', 2250 rtd_combination_point:'',
2192 rtd_commodity_NUM:'', 2251 rtd_commodity_NUM:'',
2193 - rtd_goods_DES:'', 2252 + rtd_goods_DES:'CONSOLIDATED CARGO',
2194 rtd_goods_consol_DES:'', 2253 rtd_goods_consol_DES:'',
2195 rtd_gross_weight:'', 2254 rtd_gross_weight:'',
2196 rtd_number_pieces:'', 2255 rtd_number_pieces:'',
2197 - rtd_rate_charge:'', 2256 + rtd_rate_charge:'42.66',
2198 rtd_rate_class:'Q', 2257 rtd_rate_class:'Q',
2199 rtd_total:'', 2258 rtd_total:'',
2200 //体积 2259 //体积
@@ -2224,10 +2283,10 @@ Handling Information @@ -2224,10 +2283,10 @@ Handling Information
2224 ssr_request_content:["BUP DO NOT BREAKDOWN"], 2283 ssr_request_content:["BUP DO NOT BREAKDOWN"],
2225 }, 2284 },
2226 cer:{ 2285 cer:{
2227 - cer_signature:'GATE INTERNATIONAL' 2286 + cer_signature:' DHL GLOBAL'
2228 } 2287 }
2229 }, 2288 },
2230 - ssr_content:"BUP DO NOT BREAKDOWN", 2289 + ssr_content:"NO SOLID WOODEN PACKING MATERIALS",
2231 cne_contact:{ 2290 cne_contact:{
2232 contact_id:'TE', 2291 contact_id:'TE',
2233 contact_number:'', 2292 contact_number:'',
@@ -2341,12 +2400,12 @@ Handling Information @@ -2341,12 +2400,12 @@ Handling Information
2341 cvd_amount_of_insurance:'XXX', 2400 cvd_amount_of_insurance:'XXX',
2342 cvd_charge_prepaid:'PP', 2401 cvd_charge_prepaid:'PP',
2343 cvd_charge_code:'', 2402 cvd_charge_code:'',
2344 - cvd_currency_code:'', 2403 + cvd_currency_code:'USD',
2345 }, 2404 },
2346 hbs:{ 2405 hbs:{
2347 hbs_origin:'CGO', 2406 hbs_origin:'CGO',
2348 - hbs_destination:'',  
2349 - hbs_manifest_description:'', 2407 + hbs_destination:'AMS',
  2408 + hbs_manifest_description:'CELL PHONE',
2350 hbs_pieces:'', 2409 hbs_pieces:'',
2351 hbs_serial_number:'', 2410 hbs_serial_number:'',
2352 hbs_weight:'', 2411 hbs_weight:'',
@@ -2391,6 +2450,8 @@ Handling Information @@ -2391,6 +2450,8 @@ Handling Information
2391 gridData:[], 2450 gridData:[],
2392 dialogVisible:false, 2451 dialogVisible:false,
2393 dialogVisible1:false, 2452 dialogVisible1:false,
  2453 + fileContent: null,
  2454 + currentDate:new Date(),
2394 } 2455 }
2395 }, 2456 },
2396 methods:{ 2457 methods:{
@@ -2909,6 +2970,113 @@ Handling Information @@ -2909,6 +2970,113 @@ Handling Information
2909 }, 2970 },
2910 cancleBtn(){ 2971 cancleBtn(){
2911 Object.assign(this.$data, this.$options.data()); 2972 Object.assign(this.$data, this.$options.data());
  2973 + },
  2974 + handleChange(file, fileList) {
  2975 + const files = file.raw;
  2976 + const reader = new FileReader();
  2977 + reader.onload = (e) => {
  2978 + const data = new Uint8Array(e.target.result);
  2979 + const workbook = XLSX.read(data, { type: 'array' });
  2980 + const worksheetName = '格式化打印'; // 指定工作表名称
  2981 + const worksheet = workbook.Sheets[worksheetName];
  2982 + if (worksheet) {
  2983 + const AF1 = (worksheet['AF1'] && worksheet['AF1'].v) || '单元格不存在';
  2984 + const A16 = (worksheet['A16'] && worksheet['A16'].v) || '单元格不存在';
  2985 + const C16 = (worksheet['C16'] && worksheet['C16'].v) || '单元格不存在';
  2986 + const K16 = (worksheet['K16'] && worksheet['K16'].v) || '单元格不存在';
  2987 + const L16 = (worksheet['L16'] && worksheet['L16'].v) || '单元格不存在';
  2988 + const S16 = (worksheet['S16'] && worksheet['S16'].v) || '单元格不存在';
  2989 + const I18 = (worksheet['I18'] && worksheet['I18'].v) || '单元格不存在';
  2990 + const M18 = (worksheet['M18'] && worksheet['M18'].v) || '单元格不存在';
  2991 + const A20 = (worksheet['A20'] && worksheet['A20'].v) || '单元格不存在';
  2992 + const A22 = (worksheet['A22'] && worksheet['A22'].v) || '单元格不存在';
  2993 + const C22 = (worksheet['C22'] && worksheet['C22'].v) || '单元格不存在';
  2994 + const K22 = (worksheet['K22'] && worksheet['K22'].v) || '单元格不存在';
  2995 + const P22 = (worksheet['P22'] && worksheet['P22'].v) || '单元格不存在';
  2996 + const U22 = (worksheet['U22'] && worksheet['U22'].v) || '单元格不存在';
  2997 + const AF22 = (worksheet['AF22'] && worksheet['AF22'].v) || '单元格不存在';
  2998 + const AF23 = (worksheet['AF23'] && worksheet['AF23'].v) || '单元格不存在';
  2999 + const O34 = (worksheet['O34'] && worksheet['O34'].v) || '单元格不存在';
  3000 + //const O38 = (worksheet['O38'] && worksheet['O38'].v) || '单元格不存在';
  3001 + const X38 = (worksheet['X38'] && worksheet['X38'].v) || '单元格不存在';
  3002 + const AF38 = (worksheet['AF38'] && worksheet['AF38'].v) || '单元格不存在';
  3003 +
  3004 + const inFlightInfo = I18.split('/');
  3005 + const outFlightInfo = M18.split('/');
  3006 + const inFlightNumber = inFlightInfo[0];
  3007 + const inFlightDate = inFlightInfo.length > 1 ? inFlightInfo[1].split(' ')[0] : '';
  3008 + const outFlightNumber = outFlightInfo[0];
  3009 + const outFlightDate = outFlightInfo.length > 1 ? outFlightInfo[1].split(' ')[0] : '';
  3010 +
  3011 + const SSRInfo = A20.replace(/[^a-zA-Z0-9\s]/g, '');
  3012 + //const signatureDate = parseCustomDate(O38);
  3013 + const formattedAF23 = formatAF23(AF23);
  3014 +
  3015 + this.fileContent = {
  3016 + AF1: AF1,
  3017 + A16: A16,
  3018 + C16: C16,
  3019 + K16: K16,
  3020 + L16: L16,
  3021 + S16: S16,
  3022 + inFlightNumber: inFlightNumber,
  3023 + inFlightDate: inFlightDate,
  3024 + outFlightNumber: outFlightNumber,
  3025 + outFlightDate: outFlightDate,
  3026 + SSRInfo: SSRInfo,
  3027 + A22: A22,
  3028 + C22: C22,
  3029 + K22: K22,
  3030 + P22: P22,
  3031 + U22: U22,
  3032 + AF22: cleanString(AF22),
  3033 + AF23: formattedAF23,
  3034 + O34: cleanString(O34),
  3035 + //signatureDate: signatureDate,
  3036 + X38: X38,
  3037 + AF38: cleanString(AF38),
  3038 + };
  3039 +
  3040 + this.form.bill.waybillNum=this.fileContent.AF1;
  3041 + this.form.cvd.cvd_currency_code=this.fileContent.S16;
  3042 + this.form.rtg.destinationAirport=this.fileContent.A16;
  3043 + this.form.rtg.destinationCarrier=this.fileContent.C16;
  3044 + this.form.rtg.onwardAirport=this.fileContent.K16;
  3045 + this.form.rtg.onwardCarrier=this.fileContent.L16;
  3046 + this.form.flt.cariier=this.fileContent.inFlightNumber.substring(0,2);
  3047 + this.form.flt.day=this.fileContent.inFlightDate.substring(0,2);
  3048 + this.form.flt.flightNumber=this.fileContent.inFlightNumber.substring(2);
  3049 + this.form.flt.cariier2=this.fileContent.outFlightNumber.substring(0,2);
  3050 + this.form.flt.day2=this.fileContent.outFlightDate.substring(0,2);
  3051 + this.form.flt.flightNumber2=this.fileContent.outFlightNumber.substring(2);
  3052 + this.ssr_content=this.fileContent.SSRInfo;
  3053 + this.form.bill.quantity_picecs=this.fileContent.A22;
  3054 + this.form.bill.quantity_weight=parseFloat(this.fileContent.K22).toFixed(2);
  3055 + this.form.rtd.rtd_charge_weight=parseFloat(this.fileContent.C22).toFixed(2);
  3056 + this.form.rtd.rtd_rate_charge=this.fileContent.P22;
  3057 + this.form.rtd.rtd_total=parseFloat(this.fileContent.U22).toFixed(2);
  3058 + this.form.rtd.rtd_goods_DES=this.fileContent.AF22;
  3059 + this.form.ppd.ppd_weight_amount=parseFloat(this.fileContent.U22).toFixed(2);
  3060 + this.form.ppd.ppd_charge_summary_total=parseFloat(this.fileContent.U22).toFixed(2);
  3061 + this.form.cer.cer_signature=this.fileContent.O34;
  3062 + this.form.isu.isu_signature=this.fileContent.AF38;
  3063 + this.dimension_textarea=this.fileContent.AF23;
  3064 + this.convertAndCalculateVolume();
  3065 +
  3066 + this.form.isu.isu_day_mounth_year=this.formattedDate();
  3067 + } else {
  3068 + this.fileContent = { AF1: '工作表不存在' };
  3069 + }
  3070 + };
  3071 + reader.readAsArrayBuffer(files);
  3072 + },
  3073 + formattedDate() {
  3074 + // 格式化日期为 yyyy-MM-dd
  3075 + const date = this.currentDate;
  3076 + const year = date.getFullYear();
  3077 + const month = String(date.getMonth() + 1).padStart(2, '0');
  3078 + const day = String(date.getDate()).padStart(2, '0');
  3079 + return `${year}-${month}-${day}`;
2912 } 3080 }
2913 }, 3081 },
2914 activated(){ 3082 activated(){
@@ -2974,7 +3142,7 @@ Handling Information @@ -2974,7 +3142,7 @@ Handling Information
2974 this.form.flt.cariier2 = cleanedValue.slice(0, 2); 3142 this.form.flt.cariier2 = cleanedValue.slice(0, 2);
2975 this.form.flt.flightNumber2 = cleanedValue.slice(2); 3143 this.form.flt.flightNumber2 = cleanedValue.slice(2);
2976 } 3144 }
2977 - } 3145 + },
2978 }, 3146 },
2979 watch:{ 3147 watch:{
2980 ssr_content: { 3148 ssr_content: {