diff --git a/src/components/customerOrg/ContactPerson.vue b/src/components/customerOrg/ContactPerson.vue index 3937be8..cb47174 100644 --- a/src/components/customerOrg/ContactPerson.vue +++ b/src/components/customerOrg/ContactPerson.vue @@ -81,22 +81,22 @@ - + - + - + - + @@ -141,7 +141,7 @@ import { mapState } from 'vuex' import { getapi, postapi, putapi, deletapi } from "@/api/api"; - +import { objCopy } from '../../utlis/proFunc' export default { components: { @@ -149,13 +149,7 @@ export default { data() { return { personId:'', - form: { - customerOrgId:'', - displayName: "", - title: "", - remark: "", - }, - + form: {}, //联系人表单信息 formTitle:'新增', dialogContactPerson: false, //联系人弹窗 显示控制 @@ -163,9 +157,8 @@ export default { //{ value: '',label: '所有订单状态' }, { value: '0',label: '电话' }, { value: '1',label: '邮箱' }, - ], + ], - contactMethod: [], //联系方式form表单数据 rules: { displayName: [ { required: true, message: "请输入名称", trigger: "blur" }, @@ -212,13 +205,23 @@ export default { //联系人 相关操作 add() { //this.$message.success("新增 addContactPerson"); + if(!this.customerOrg.customerOrgId){ + alert("没有体检单位信息") + return + } + this.form = {customerOrgId:this.customerOrg.customerOrgId} this.dialogContactPerson = true this.formTitle = "新增" this.personId = '' + this.customerOrg.contactMethodList = [] }, + edit() { //this.$message.success("编辑 editContactPerson"); - if(!this.personId || !this.customerOrg.customerOrgId){ + if(!this.customerOrg.customerOrgId){ + alert("没有体检单位信息") + return + }else if(!this.personId){ alert("请先选择要编辑的联系人") return } @@ -226,39 +229,88 @@ export default { this.formTitle = "编辑" }, + //删除联系人行 del() { - this.$message.success("删除 delContactPerson"); + //this.$message.success("删除 delContactPerson"); + deletapi(`/api/app/contact-person/${this.personId}`).then( + (res) => { + this.getContactPersonList(this.customerOrg.customerOrgId) + this.customerOrg.contactMethodList = [] + this.$message.success("操作成功!"); + } + ); + }, - + //删除联系方式行 deleteRow (index){ this.customerOrg.contactMethodList.splice(index, 1) }, //联系人信息提交 - submit(){ - + submit(){ + let body = { + customerOrgId:'', + displayName: "", + title: "", + remark: "", + } + objCopy(this.form,body) + console.log('body',body) if(this.formTitle === '新增'){ - postapi('api/app/contact-person',form).then( + postapi('/api/app/contact-person',body).then( (res) => { - //console.log('res.data',res.data) + //console.log('api/app/contact-person') this.personId = res.data.id - return deletapi(`api/app/contact-method/${this.personId}`) + this.formTitle = '编辑' + return deletapi(`/api/app/contact-method/many/${this.personId}`) } ).then( (res) => { - //console.log('res.data',res.data) - this.personId = res.data.id - return postapi('api/app/contact-method/many',contactMethod) + //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 + }) + }); + 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("操作成功!"); - } + } ); }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 + }) + }); + 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("操作成功!"); + } + ); } }, @@ -268,14 +320,15 @@ export default { this.customerOrg.contactMethodList.push({ contactMethodValue: "", contactMethodType: "0", - contactPersonId: this.personId + contactPersonId: this.personId }) }, rowClick(row){ - // console.log('row',row) + console.log('row',row) // this.$message.success("rowClick"); - this.personId = row.id + this.form = row + this.personId = row.id this.getContactMethodList(row.id) }, diff --git a/src/utlis/proFunc.js b/src/utlis/proFunc.js index fabb17d..1b52dc8 100644 --- a/src/utlis/proFunc.js +++ b/src/utlis/proFunc.js @@ -1,4 +1,5 @@ +//多级联动选择数据处理 exports.tcdate = (date) => { for (var i = 0; i < date.length; i++) { if (date[i].treeChildren.length == 0) { @@ -8,3 +9,10 @@ exports.tcdate = (date) => { } } } + +//json 对像赋值 只从 from 对象 赋值 to 中有的 key 项 +exports.objCopy = (from,to) => { + for(let key in to){ + to[key] = from[key] + } +} \ No newline at end of file