| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <template>
- <el-tree
- class="el-treeWhite"
- ref="elTreeWhite"
- :data="treeData"
- :props="treeProps"
- :expand-on-click-node="false"
- :check-strictly="checkStrictly"
- @check-change="handleCheckChange"
- node-key="code"
- :default-expanded-keys="tableDefaultExpandedKeys"
- lazy
- show-checkbox
- :load="loadAddvData"
- style="max-height:100%;overflow:auto;"
- ></el-tree>
- </template>
- <script>
- import { getOrgByPid } from "../api/duChaAPI.js";
- export default {
- components: {},
- props:{
- rootCode:{},
- orgIdLists:{},
- checkStrictly:{ //在显示复选框的情况下,是否严格的遵循父子不互相关联的做法,默认为 false
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- treeData: [],
- tableDefaultExpandedKeys: [],
- treeProps: {
- label: "name",
- children: "children",
- disabled: false,
- expandOnClickNode: false ,
- first:true,
- }
- };
- },
- mounted: function() {
- this.loadTreeListData();
- },
- methods: {
- loadTreeListData:function(){
- let _this = this
- if(this.rootCode&&this.rootCode!=''){
- getOrgByPid(this.rootCode).then((res) =>{
- console.log(res);
- let children = [];
- res.data.forEach((element,index)=>{
- children.push({
- 'code':element.orgId,
- 'name':element.orgNm
- })
- });
- this.treeData = children;
- if(this.orgIdLists){
- this.$refs.elTreeWhite.setCheckedKeys(this.orgIdLists)
- setTimeout(()=>{
- let checkedNodes = _this.$refs.elTreeWhite.getCheckedNodes()
- // _this.$emit("provTreeSelectChange", checkedNodes); //第一次给树赋值不emit事件,父组件取当前拥有机构数据
- },0)
- }
- },(err) =>{});
- }else{
- getOrgByPid('1').then((res) =>{
- console.log(res);
- let children = [];
- res.data.forEach((element,index)=>{
- children.push({
- 'code':element.orgId,
- 'name':element.orgNm
- })
- });
- this.treeData = children;
- },(err) =>{});
- }
- },
- handleCheckChange(data) {
- // alert(data.code+data.name+data.type);
- let checkedNodes = this.$refs.elTreeWhite.getCheckedNodes()
- this.$emit("provTreeSelectChange", checkedNodes);
- },
- loadAddvData: function(node, resolve) {
- var _self = this;
- try {
- if(this.treeProps.first){
- this.treeProps.first = false;
- }else{
- getOrgByPid(node.data.code).then(
- response => {
- var data = response.data;
- let children = [];
- response.data.forEach((element,index)=>{
- children.push({
- 'code':element.orgId,
- 'name':element.orgNm
- })
- });
-
-
- resolve(children);
- },
- response => {}
- );
- }
- } catch (e) {
-
- }
- },
- }
- };
- </script>
- <style scoped>
- </style>
|