var Basecomponent = { 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.8, tableData: [], currentPage: 1, pagesize:50, recordTotal:0, p_id_v:'', p_name_v:'', form: { id:'', p_id: '', p_name:'', }, dialogVisible:false, oper_type:0, rules: { p_id: [ { required: true, message: '产品编号不可为空', trigger: 'blur' } ], p_name: [ { required: true, message: '产品名称不可为空', trigger: 'blur' } ], }, multipleSelection: [], importdialogVisible:false, fileListUpload:[], importTableData:[], disabled:true, if_show_process:false, percent_len:0, interval:'', if_show_process1:false, } }, mounted() { var _this = this; var objs; axios.post('/u_ma/get_p', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), p_id: _this.$data.p_id_v, p_name: _this.$data.p_name_v, index: _this.$data.currentPage, count: _this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, methods: { input_change(value) { console.log(value); this.get_p(); }, exportSap(){ document.getElementById("bt_export").blur(); var _this = this; var objs; axios.post('/u_ma/export_sap', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), p_id: _this.$data.p_id_v, p_name: _this.$data.p_name_v, }) .then(function (response) { console.log(response.data); var fileid = response.data.fileId; var downUrl = '/u_ma/download_file'+"?id="+fileid; downloadUrl("产品编码名称.csv",downUrl); }) .catch(function (error) { console.log(error); }); }, importData(){ document.getElementById("bt_import").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('/u_ma/import_p', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), data:this.$data.importTableData, }) .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.importdialogVisible=false; //更新页面 _this.get_p(); }) .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.p_id = results.data[i][0] if(obj.p_id==""|| obj.p_id==undefined){ continue; } obj.p_name = results.data[i][1] data.push(obj) } //data.splice(0, 1)//将数组第一位的表格名称去除 let num = 0 console.log('data', data) _this.$data.importTableData=data; } }) } else { this.$data.fileListUpload=[]; this.$message({ type: 'warning', message: '附件格式错误,请删除后重新上传!' }) } } else { this.$message({ type: 'warning', message: '请上传附件!' }) } }, importCsv(){ this.$data.fileListUpload=[]; this.$data.importTableData=[]; this.$data.importdialogVisible=true; }, importDialog_close(done){ done(); }, handleSelectionChange(val) { console.log("已选择"); console.log(val); this.multipleSelection = val; }, post_p(){ this.$refs['form_p'].validate((valid) => { if(valid){ this.$data.dialogVisible = false; var _this = this; console.log(_this.$data.form); var objs; axios.post('/u_ma/post_p', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), id: _this.$data.form.id, p_id: _this.$data.form.p_id, p_name: _this.$data.form.p_name, oper_type: _this.$data.oper_type, }) .then(function (response) { let r = response.data.r; let s = "" let errType = "" if (r == 0) { errType = "success" } else{ errType = "error" } if (_this.$data.oper_type == 1) { if (r ==0) { s = "新增产品信息成功!"; } else if(r == 1) { s = "已存在相同产品信息!"; }else{ s = "新增产品信息失败!"; } } else if (_this.$data.oper_type ==2){ if (r ==0) { s = "修改产品信息成功!"; } else{ s = "修改产品信息失败!"; } } _this.$message({ message: s, type: errType, duration: 1500 }); //更新页面 _this.get_p(); }) .catch(function (error) { console.log(error); }); } }); }, del_p(){ var _this = this; axios.post('/u_ma/del_p', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), ids: _this.$data.multipleSelection, }) .then(function (response) { let r = response.data.r; let s = "" let errType = "" if (r == 0) { s = "删除产品信息成功!"; errType = "success" } else{ s = "删除产品信息失败!"; errType = "error" } _this.$message({ message: s, type: errType, duration: 1500 }); if (r ==0) { _this.get_p();//更新页面 } }) .catch(function (error) { console.log(error); }); }, add_p(){ document.getElementById("bt_add").blur(); this.$data.disabled=false; this.$data.oper_type = 1; this.$data.form = { id:'', p_id: '', p_name:'', }; this.$nextTick(() => { this.$refs['form_p'].clearValidate() }); this.$data.dialogVisible = true; }, update_p(info){ this.$data.disabled=true; this.$data.oper_type = 2; this.$data.form = { id:info.id, p_id: info.p_id, p_name:info.p_name, }; this.$nextTick(() => { this.$refs['form_p'].clearValidate() }); this.$data.dialogVisible = true; }, get_p(){ document.getElementById("bt_search").blur(); this.$data.currentPage=1; var _this = this; var objs; axios.post('/u_ma/get_p', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), p_id: _this.$data.p_id_v, p_name: _this.$data.p_name_v, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, handleSizeChange(val) { this.$data.pagesize = val; var _this = this; var objs; axios.post('/u_ma/get_p', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), p_id: _this.$data.p_id_v, p_name: _this.$data.p_name_v, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); }, handleCurrentChange(val) { this.$data.currentPage = val; var _this = this; var objs; axios.post('/u_ma/get_p', { opuser:localStorage.getItem("online_user"), opuser_uuid:localStorage.getItem("uuid"), p_id: _this.$data.p_id_v, p_name: _this.$data.p_name_v, index: this.$data.currentPage, count: this.$data.pagesize }) .then(function (response) { console.log(response.data); objs = response.data.data; rcnt = response.data.total; _this.$data.tableData = objs; _this.$data.recordTotal = rcnt; }) .catch(function (error) { console.log(error); }); } } }