var tpmcomponent = { template:`
搜索 新增 删除
产品型号及名称:
点击上传(csv文件) 下载导入模板文件 导出
取 消 确 定
`, data(){ // 获取当前屏幕的分辨率 let screenW = window.screen.width; let screenH = window.screen.height; console.log("screen width:",screenW); console.log("screen height:",screenH); return { tHeight:screenH*0.7, tableData: [], tableData1:[], currentPage: 1, pagesize:50, recordTotal:0, p_name_v:'', g_p_name:'', dialogVisible:false, oper_type:0, multipleSelection: [], importdialogVisible:false, fileListUpload:[], importTableData:[], disabled:false, if_show_process:false, percent_len:0, interval:'', if_show_process1:false, fileList:[], rules: { p_name_cn: [ { required: true, message: '产品型号及名称(中)不可为空', trigger: 'blur' } ], p_name_en: [ { required: true, message: '产品型号及名称(英)不可为空', trigger: 'blur' } ], p_ibase_cn: [ { required: true, message: '检验依据(中)不可为空', trigger: 'blur' } ], p_ibase_en: [ { required: true, message: '检验依据(英)不可为空', trigger: 'blur' } ], }, p_name_options:[], drawer:false, direction: 'rtl', tableData_result:[], drawer_result:false, } }, mounted() { this.get_inspection(); }, methods: { export_ins(){ document.getElementById("bt_export").blur(); var _this = this; var objs; axios.post('/pkpi/export_inspection', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), p_name: _this.$data.g_p_name, }) .then(function (response) { console.log(response.data); var fileid = response.data.fileId; var downUrl = 'file/'+fileid; downloadUrl("检验项目.csv",downUrl); }) .catch(function (error) { console.log(error); }); }, show_i_result(row){ this.$data.tableData_result=row.result_contain; this.$data.drawer_result=true; }, download_template(){ document.getElementById("bt_download").blur(); var downUrl = 'file/'+"检测项目导入.csv"; downloadUrl("检测项目导入.csv",downUrl); return; }, show_op(row){ var _this = this; axios.post('/pkpi/get_inspection_op_history', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), p_name:row.p_name, }) .then(function (response) { console.log(response.data); objs = response.data.data; _this.$data.tableData1 = objs; }) .catch(function (error) { console.log(error); }); this.drawer=true; }, handleClose(done) { done(); }, show_dis(row){ this.$data.disabled=true; this.$data.g_p_name=row.p_name; this.$data.importTableData=row.data; this.$data.dialogVisible=true; }, post_inspection(){ document.getElementById("bt_ok").blur(); if(this.$data.importTableData.length==0){ this.$message({ message: "请选择导入文件", type: "warning", duration: 1500 }); return; } this.$confirm('是否确认导入?', '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { var _this = this; _this.$data.percent_len=0; _this.$data.if_show_process1=true; _this.$data.interval= setInterval(()=>{ if(_this.$data.percent_len>=99){ clearInterval(_this.$data.interval); return; } if (_this.$data.percent_len<98){ _this.$data.percent_len+=2 } },20) axios.post('/pkpi/post_inspection', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), data:this.$data.importTableData, p_name:this.$data.g_p_name, }) .then(function (response) { let r = response.data.r; let s = "" let errType = "" if (r == 0) { let len = _this.$data.importTableData.length; errType = "success" s = "导入成功("+len+"条)"; _this.$data.percent_len=100; _this.$data.if_show_process1=false; } else if(r == 1) { errType = "error" s = "正在导入,请稍后!"; clearInterval(_this.$data.interval); } else{ errType = "error" s = "导入失败!"; clearInterval(_this.$data.interval); } console.log(s); _this.$message({ message: s, type: errType, duration: 3000 }); _this.$data.dialogVisible=false; //更新页面 _this.get_inspection(); }) .catch(function (error) { console.log(error); }); }).catch(() => { this.$message({ type: 'info', message: '已取消' }); return; }); }, handleChange(file, fileList) { document.getElementById("bt_upload").blur(); this.fileTemp = file.raw console.log("filetype:",this.fileTemp); if (this.fileTemp) { console.log("begin ...") console.log(this.fileTemp.type); if ((this.fileTemp.type == 'text/csv') || (this.fileTemp.type == '.csv') || (this.fileTemp.type == 'application/vnd.ms-excel')) { let _this = this//如果需要点击事件结束之后对DOM进行操作使用)_this.xx=xx进行操作 Papa.parse(_this.fileTemp, { encoding:'gb2312', complete (results) { console.log(results)//这个是csv文件的数据 let data = [] //遍历csv文件中的数据,存放到data中 方法不唯一,可自己更改 for (let i = 0; i < results.data.length; ++i) { if(i==0){ continue; } let obj = {} obj.inspection_items_cn = results.data[i][0] if(obj.inspection_items_cn==""|| obj.inspection_items_cn==undefined){ continue; } obj.inspection_items_en = results.data[i][1] obj.inspection_rs_cn = results.data[i][2] if(obj.inspection_rs_cn==""|| obj.inspection_rs_cn==undefined){ continue; } obj.inspection_rs_en = results.data[i][3] obj.inspection_scheme_cn = results.data[i][4] obj.inspection_scheme_en = results.data[i][5] obj.inspection_type= results.data[i][6] obj.Result_contain=[]; if(obj.inspection_type=="文本"){ let tobj={} var cnt = 0; for(let j=7; j