Browse Source

cusOrg

master
pengjun 2 years ago
parent
commit
12b24f4f14
  1. 80
      src/components/customerOrg/customerOrgEdit.vue
  2. 2
      src/utlis/tree.js

80
src/components/customerOrg/customerOrgEdit.vue

@ -155,7 +155,7 @@
<el-button type="primary" @click="add('form','child')" class="btnClass">新增子单位</el-button>
</div>
<div class="btnList">
<el-button type="success" @click="Onsubmit('form')" class="btnClass">保存</el-button>
<el-button type="success" @click="onSubmit('form')" class="btnClass">保存</el-button>
</div>
<div class="btnList">
<el-button type="danger" @click="del('form')" class="btnClass">删除</el-button>
@ -166,7 +166,8 @@
<script>
import { mapState, mapMutations } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { tcdate, objCopy, deepCopy } from "../../utlis/proFunc";
import { tcdate, objCopy, deepCopy, arrayExistObj } from "../../utlis/proFunc";
import { getTreeNode, getTreePids} from "../../utlis/tree";
export default {
components: {},
@ -292,18 +293,68 @@ export default {
});
},
//
getCustomerOrgTree() {
getapi("/api/app/customerorg/getbycodeall").then((res) => {
//customerOrgTree = res.data;
console.log("res.data", res.data);
this.setData({ key: "customerOrg.customerOrgTree", value: res.data });
tcdate(this.customerOrg.customerOrgTree);
});
//()
getCustomerOrgTree(oprType,body) {
// getapi("/api/app/customerorg/getbycodeall").then((res) => {
// //customerOrgTree = res.data;
// console.log("res.data", res.data);
// this.setData({ key: "customerOrg.customerOrgTree", value: res.data });
// tcdate(this.customerOrg.customerOrgTree);
// });
switch (oprType) {
case 'insert':
let node = {
id: body.id,
displayName:body.displayName,
parentId:body.parentId
}
if(body.parentId){
let pNode = getTreeNode(this.customerOrg.customerOrgTree, "treeChildren", "id", body.parentId)
if(pNode.treeChildren){
pNode.treeChildren.push(node)
}else{
pNode.treeChildren = [node]
}
}else{
this.customerOrg.customerOrgTree.push(node)
}
break;
// "id": "3a0c5101-a6a6-e48a-36ec-33e7567a99e6",
// "displayName": "",
// "parentId": null,
// "code": "00001",
// "treeChildren": [
case 'update':
let node2 = getTreeNode(this.customerOrg.customerOrgTree, "treeChildren", "id", body.id);
node2.displayName = body.displayName
break;
case 'delete':
let lfind = -1
let pids = getTreePids(this.customerOrg.customerOrgTree,"treeChildren", 'parentId','id',body)
//tree, childNodeName, pidName, idName, idVal getTreeNode(this.customerOrg.customerOrgTree, "treeChildren", "id", body);
//console.log('pids',pids,body)
if(!pids || pids.length < 1){
lfind = arrayExistObj(this.customerOrg.customerOrgTree, 'id', body)
if(lfind > - 1) this.customerOrg.customerOrgTree.splice(lfind,1)
}else{
let node3 = getTreeNode(this.customerOrg.customerOrgTree, "treeChildren", "id", pids[0]);
//console.log('node3',node3)
lfind = arrayExistObj(node3.treeChildren, 'id', body)
if(lfind > - 1) node3.treeChildren.splice(lfind,1)
}
break;
default:
break;
}
},
//
Onsubmit(formName) {
onSubmit(formName) {
let body = {};
console.log("vuex data", this.customerOrg.customerOrgRd);
this.$refs[formName].validate((valid, fields) => {
@ -342,7 +393,7 @@ export default {
//this.setData({ key: "customerOrg.customerOrgRd", value: res });
this.customerOrg.customerOrgId = res.data.id;
this.customerOrg.customerOrgRd = res.data;
this.getCustomerOrgTree();
this.getCustomerOrgTree('insert',res.data);
}
});
} else {
@ -353,7 +404,8 @@ export default {
).then((res) => {
if (res.code == 1) {
this.$message.success("更新 操作成功");
this.getCustomerOrgTree();
let lbody = {id:this.customerOrg.customerOrgRd.id,...body}
this.getCustomerOrgTree('update',lbody);
}
});
}
@ -393,9 +445,9 @@ export default {
}).then((res) => {
if(res.code != -1) {
this.$message.success("删除 操作成功");
this.getCustomerOrgTree('delete',this.customerOrg.customerOrgRd.id);
this.setData({ key: "customerOrg.customerOrgRd", value: { id: "" } });
this.$refs[formName].resetFields();
this.getCustomerOrgTree();
}
}).catch((err) => {
this.$message({

2
src/utlis/tree.js

@ -51,7 +51,7 @@ function madeTree(dataSource, childNodeName, pidName, idName, pidVal) {
}
//通过ID值,找出所有子节点值
//通过node值,找出所有子节点值
function getTreeAllChildIdsByNode(treeNode, childNodeName, idName) {
let childIds = [];
let lchildNodeName = childNodeName || 'children';

Loading…
Cancel
Save