pengjun 2 years ago
parent
commit
78b7a03f59
  1. 144
      src/components/customerOrg/ContactPerson.vue

144
src/components/customerOrg/ContactPerson.vue

@ -108,7 +108,7 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-table :data="customerOrg.contactMethodList" border height="300" row-key="id" size="small"
<el-table :data="contactMethodListEdit" border height="300" row-key="id" size="small"
highlight-current-row ref="contactMethod" style="margin-top: 20px;"> highlight-current-row ref="contactMethod" style="margin-top: 20px;">
<el-table-column prop="contactMethodType" label="类型" width="200"> <el-table-column prop="contactMethodType" label="类型" width="200">
<template slot-scope="scope"> <template slot-scope="scope">
@ -142,7 +142,7 @@
import moment from "moment"; import moment from "moment";
import { mapState } from "vuex"; import { mapState } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api"; import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { objCopy } from "../../utlis/proFunc";
import { objCopy, deepCopy, arrayExistObj } from "../../utlis/proFunc";
export default { export default {
components: {}, components: {},
props:["customerOrgId"], props:["customerOrgId"],
@ -150,6 +150,7 @@ export default {
return { return {
personId: "", personId: "",
form: {}, // form: {}, //
contactMethodListEdit:[], //
formTitle: "新增", formTitle: "新增",
dialogContactPerson: false, // dialogContactPerson: false, //
@ -196,6 +197,7 @@ export default {
}).then((res) => { }).then((res) => {
//console.log('res.data',res.data) //console.log('res.data',res.data)
this.customerOrg.contactMethodList = res.data; this.customerOrg.contactMethodList = res.data;
this.contactMethodListEdit = deepCopy(res.data);
}); });
}, },
@ -245,30 +247,32 @@ export default {
}).then((res) => { }).then((res) => {
if(res.code != -1) { if(res.code != -1) {
this.personId = ""; this.personId = "";
this.getContactPersonList(this.customerOrg.customerOrgId); this.getContactPersonList(this.customerOrg.customerOrgId);
this.customerOrg.contactMethodList = []; this.customerOrg.contactMethodList = [];
this.$message.success("操作成功!"); this.$message.success("操作成功!");
} }
}).catch((err) => { }).catch((err) => {
console.log(`deletapi:/api/app/contact-person/${this.personId}`,err);
if (err == "cancel") {
this.$message.info("已取消删除");
}
}); });
}, },
// //
deleteRow(index) { deleteRow(index) {
this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
this.$confirm("此操作确定后将永久删除该记录, 是否继续?", "提示", {
confirmButtonText: "是", confirmButtonText: "是",
cancelButtonText: "否", cancelButtonText: "否",
type: "warning", type: "warning",
}).then(() => { }).then(() => {
this.customerOrg.contactMethodList.splice(index, 1);
this.submit('form');
this.contactMethodListEdit.splice(index, 1);
//this.submit('form');
}).catch((err) => { }).catch((err) => {
if(err == 'cancel'){ if(err == 'cancel'){
this.$message.info("已取消删除"); this.$message.info("已取消删除");
}else{
this.$message.error("操作失败,原因:" + err);
}
}
}); });
}, },
@ -281,72 +285,78 @@ export default {
title: "", title: "",
remark: "", remark: "",
}; };
this.$refs[formName].validate((valid, failField) => {
if (valid) {
objCopy(this.form, body);
console.log("body", body);
if (this.formTitle === "新增") {
postapi("/api/app/contact-person", body)
.then((res) => {
//console.log('api/app/contact-person')
this.personId = res.data.id;
this.formTitle = "编辑";
return deletapi(`/api/app/contact-method/many/${this.personId}`);
})
.then((res) => {
//console.log(`deletapi api/app/contact-method/${this.personId}`)
let contactMethod = []; //form
this.customerOrg.contactMethodList.forEach((item, index) => {
contactMethod.push({
contactMethodValue: item.contactMethodValue,
contactMethodType: item.contactMethodType,
contactPersonId: this.personId,
});
this.$refs[formName].validate((valid, fields) => {
if (!valid){
this.$message.warning(fields[Object.keys(fields)[0]][0].message);
return false;
}
objCopy(this.form, body);
console.log("body", body);
if (this.formTitle == "新增") {
postapi("/api/app/contact-person", body)
.then((res) => {
//console.log('api/app/contact-person')
this.personId = res.data.id;
this.formTitle = "编辑";
return deletapi(`/api/app/contact-method/many/${this.personId}`);
})
.then((res) => {
//console.log(`deletapi api/app/contact-method/${this.personId}`)
let contactMethod = []; //form
this.contactMethodListEdit.forEach( item => {
contactMethod.push({
contactMethodValue: item.contactMethodValue,
contactMethodType: item.contactMethodType,
contactPersonId: this.personId,
}); });
if(contactMethod.length > 0) return postapi("/api/app/contact-method/many", contactMethod);
})
.then((res) => {
//console.log('api/app/contact-method/many')
this.getContactPersonList(this.customerOrg.customerOrgId);
this.$message.success("操作成功!");
this.dialogContactPerson = false
}); });
} else {
putapi(`/api/app/contact-person/${this.personId}`, body)
.then((res) => {
//console.log(`/api/app/contact-person/${this.personId}`)
return deletapi(`/api/app/contact-method/many/${this.personId}`);
})
.then((res) => {
console.log(`deletapi api/app/contact-method/${this.personId}`);
let contactMethod = []; //form
this.customerOrg.contactMethodList.forEach((item, index) => {
contactMethod.push({
contactMethodValue: item.contactMethodValue,
contactMethodType: item.contactMethodType,
contactPersonId: this.personId,
});
if(contactMethod.length > 0) return postapi("/api/app/contact-method/many", contactMethod);
})
.then((res) => {
//console.log('api/app/contact-method/many')
//this.getContactPersonList(this.customerOrgId); //
this.customerOrg.contactPersonList.push(res.data)
this.getContactMethodList(res.data.id)
this.$message.success("操作成功!");
this.dialogContactPerson = false
});
} else {
putapi(`/api/app/contact-person/${this.personId}`, body)
.then((res) => {
//console.log(`/api/app/contact-person/${this.personId}`)
return deletapi(`/api/app/contact-method/many/${this.personId}`);
})
.then((res) => {
console.log(`deletapi api/app/contact-method/${this.personId}`);
let contactMethod = []; //form
this.contactMethodListEdit.forEach((item, index) => {
contactMethod.push({
contactMethodValue: item.contactMethodValue,
contactMethodType: item.contactMethodType,
contactPersonId: this.personId,
}); });
if(contactMethod.length > 0) return postapi("/api/app/contact-method/many", contactMethod);
})
.then((res) => {
//console.log('api/app/contact-method/many')
this.getContactPersonList(this.customerOrg.customerOrgId);
this.$message.success("操作成功!");
this.dialogContactPerson = false
}); });
}
} else {
//console.log('failField',failField)
this.$message.warning("未通过数据校验!");
return false;
}
if(contactMethod.length > 0) return postapi("/api/app/contact-method/many", contactMethod);
})
.then((res) => {
//console.log('api/app/contact-method/many')
//this.getContactPersonList(this.customerOrgId); //
let lfind = arrayExistObj(this.customerOrg.contactPersonList, 'id', this.personId)
if(lfind > - 1) objCopy(body,this.customerOrg.contactPersonList[lfind])
this.getContactMethodList(this.personId)
this.$message.success("操作成功!");
this.dialogContactPerson = false
});
}
}) })
}, },
// //
addMethod() { addMethod() {
this.customerOrg.contactMethodList.push({
this.contactMethodListEdit.push({
contactMethodValue: "", contactMethodValue: "",
contactMethodType: "0", contactMethodType: "0",
contactPersonId: this.personId, contactPersonId: this.personId,
@ -356,7 +366,7 @@ export default {
rowClick(row) { rowClick(row) {
console.log("row", row); console.log("row", row);
// this.$message.success("rowClick"); // this.$message.success("rowClick");
this.form = row;
this.form = deepCopy(row);
this.personId = row.id; this.personId = row.id;
this.getContactMethodList(row.id); this.getContactMethodList(row.id);
}, },

Loading…
Cancel
Save