var Basecomponent = {
template:`
已删除
搜索
导入审批物料
删除
{{scope.row.price}}
{{scope.row.price_2}}
{{scope.row.price_3}}
{{scope.row.price_4}}
{{scope.row.price_5}}
{{scope.row.qs}}
上传
{{scope.row.as}}
上传
点击上传(csv文件)
确认导入
下载导入模板文件
`,
data(){
// 获取当前屏幕的分辨率
let screenW = window.screen.width;
let screenH = window.innerHeight;
console.log("screen width:",screenW);
console.log("screen height:",screenH);
return {
tHeight:screenH-40-232,
tableData: [],
currentPage: 1,
pagesize:50,
recordTotal:0,
code_v:'',
name_v:'',
supplier_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,
begin_t_v:'',
end_t_v:'',
fileList:[],
checked:false,
if_show_del_filed:false,
}
},
mounted() {
this.get_material()
},
methods: {
if_fin_cahnge(val){
if(val){
this.$data.if_show_del_filed=true;
this.$data.tableData =[];
}else{
this.$data.if_show_del_filed=false;
this.$data.tableData =[];
}
this.get_material();
},
del_material(){
var ids =[];
for (var i = 0; i < this.$data.multipleSelection.length; i++) {
ids.push(this.$data.multipleSelection[i].id);
}
var _this = this;
axios.post('/pp/del_material', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
ids: ids,
})
.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_material();;//更新页面
}
})
.catch(function (error) {
console.log(error);
});
},
down_qs_files(row){
var downUrl = '/pp/download_ds_file'+"?id="+row.qs;
downloadUrl(row.qs,downUrl);
},
down_as_files(row){
var downUrl = '/pp/download_ds_file'+"?id="+row.as;
downloadUrl(row.as,downUrl);
},
upload_param_2(row){
//console.log("---")
return {
id:row.id,
file_type:"2"
}
},
upload_param(row){
console.log("---")
return {
id:row.id,
file_type:"1"
}
},
upload_file_error(response, file, fileList){
this.$message({
message: "上传失败",
type: "error",
duration: 1500
});
},
upload_file_success(response, file, fileList){
this.$message({
message: "上传成功",
type: "success",
duration: 1500
});
this.get_material();
},
handleChange_file(file, fileList) {
console.log(file);
this.fileList = fileList.slice(-1);
},
download_template(){
document.getElementById("bt_download").blur();
var downUrl = '/pp/download_file'+"?id="+"审批导入.csv";
downloadUrl("导入审批物料模版.csv",downUrl);
},
input_change(value) {
console.log(value);
this.get_material();
},
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('/pp/import_approve_m', {
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 if(r == 2) {
errType = "error"
s = response.data.context;
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中 方法不唯一,可自己更改
console.log(results.data)
for (let i = 0; i < results.data.length; ++i) {
if(i==0){
continue;
}
let obj = {}
obj.supplier = results.data[i][0]
if(obj.supplier==""|| obj.supplier==undefined){
continue;
}
obj.supplier_code = results.data[i][1]
/*if(obj.supplier_code==""|| obj.supplier_code==undefined){
continue;
}*/
obj.pt = results.data[i][2]
/*if(obj.pt==""|| obj.pt==undefined){
continue;
}*/
obj.code = results.data[i][3]
/*if(obj.code==""|| obj.code==undefined){
continue;
}*/
obj.name = results.data[i][4]
/*if(obj.name==""|| obj.name==undefined){
continue;
}*/
obj.spec = results.data[i][5]
/*if(obj.spec==""|| obj.spec==undefined){
continue;
}*/
obj.unit = results.data[i][6]
/*if(obj.unit==""|| obj.unit==undefined){
continue;
}*/
obj.price = results.data[i][7]
/*if(obj.price==""|| obj.price==undefined){
continue;
}*/
obj.update_date = results.data[i][8]
/*if(obj.update_date==""|| obj.update_date==undefined){
continue;
}*/
obj.pc = results.data[i][9]
/*if(obj.pc==""|| obj.pc==undefined){
continue;
}*/
obj.vpoq = results.data[i][10]
/*if(obj.vpoq==""|| obj.vpoq==undefined){
continue;
}*/
obj.factory = results.data[i][11]
obj.factory_code = results.data[i][12]
obj.qs = results.data[i][13]
obj.as = results.data[i][14]
console.log(i,":",obj);
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);
});
}
});
},
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_material(){
document.getElementById("bt_search").blur();
//this.$data.currentPage=1;
var _this = this;
var objs;
axios.post('/pp/get_material', {
opuser:localStorage.getItem("online_user"),
opuser_uuid:localStorage.getItem("uuid"),
index: this.$data.currentPage,
count: this.$data.pagesize,
code: this.$data.code_v,
name:this.$data.name_v,
supplier:this.$data.supplier_v,
bt:this.$data.begin_t_v,
et:this.$data.end_t_v,
if_del:this.$data.checked,
})
.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;
this.get_material();
},
handleCurrentChange(val) {
this.$data.currentPage = val;
this.get_material();
}
}
}