|  | @@ -1,11 +1,11 @@
 | 
	
		
			
				|  |  |  <template>
 | 
	
		
			
				|  |  |    <div>
 | 
	
		
			
				|  |  |      <!-- 
 | 
	
		
			
				|  |  | -			拖拽
 | 
	
		
			
				|  |  | -			draggable
 | 
	
		
			
				|  |  | -			@node-drop="handleDrop"
 | 
	
		
			
				|  |  | -			@node-drag-enter="handleDragEnter"
 | 
	
		
			
				|  |  | -			:allow-drop="allowDrop"
 | 
	
		
			
				|  |  | +		拖拽
 | 
	
		
			
				|  |  | +		draggable
 | 
	
		
			
				|  |  | +		@node-drop="handleDrop"
 | 
	
		
			
				|  |  | +		@node-drag-enter="handleDragEnter"
 | 
	
		
			
				|  |  | +		:allow-drop="allowDrop"
 | 
	
		
			
				|  |  |      -->
 | 
	
		
			
				|  |  |      <el-tree
 | 
	
		
			
				|  |  |        :props="props"
 | 
	
	
		
			
				|  | @@ -16,14 +16,25 @@
 | 
	
		
			
				|  |  |        :expand-on-click-node="expand"
 | 
	
		
			
				|  |  |        ref="tree"
 | 
	
		
			
				|  |  |        v-loading="loading"
 | 
	
		
			
				|  |  | +      @check-change="handleCheckChange"
 | 
	
		
			
				|  |  |      >
 | 
	
		
			
				|  |  |        <template slot-scope="{data,node}">
 | 
	
		
			
				|  |  |          <div class="row">
 | 
	
		
			
				|  |  |            <span class="content">{{data.name}}</span>
 | 
	
		
			
				|  |  |            <span class="handle">
 | 
	
		
			
				|  |  |              <el-button type="text" size="mini" @click.stop.prevent="addNode(data,node)">新增</el-button>
 | 
	
		
			
				|  |  | -            <el-button v-if="data.id!=-1" type="text" size="mini" @click.stop.prevent="delNode(data,node)">删除</el-button>
 | 
	
		
			
				|  |  | -            <el-button v-if="data.id!=-1" type="text" size="mini" @click.stop.prevent="putNode(data,node)">更新</el-button>
 | 
	
		
			
				|  |  | +            <el-button
 | 
	
		
			
				|  |  | +              v-if="data.id!=-1"
 | 
	
		
			
				|  |  | +              type="text"
 | 
	
		
			
				|  |  | +              size="mini"
 | 
	
		
			
				|  |  | +              @click.stop.prevent="delNode(data,node)"
 | 
	
		
			
				|  |  | +            >删除</el-button>
 | 
	
		
			
				|  |  | +            <el-button
 | 
	
		
			
				|  |  | +              v-if="data.id!=-1"
 | 
	
		
			
				|  |  | +              type="text"
 | 
	
		
			
				|  |  | +              size="mini"
 | 
	
		
			
				|  |  | +              @click.stop.prevent="putNode(data,node)"
 | 
	
		
			
				|  |  | +            >更新</el-button>
 | 
	
		
			
				|  |  |            </span>
 | 
	
		
			
				|  |  |          </div>
 | 
	
		
			
				|  |  |        </template>
 | 
	
	
		
			
				|  | @@ -32,7 +43,8 @@
 | 
	
		
			
				|  |  |  </template>
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  <script>
 | 
	
		
			
				|  |  | -import { getNode, addNode, delNode, putNode } from "@/Api/tree";
 | 
	
		
			
				|  |  | +// import { getNode, addNode, delNode, putNode } from "@/Api/tree";
 | 
	
		
			
				|  |  | +import { getNode, addNode, delNode, putNode } from "@/Api/dept";
 | 
	
		
			
				|  |  |  export default {
 | 
	
		
			
				|  |  |    name: "tree",
 | 
	
		
			
				|  |  |    data() {
 | 
	
	
		
			
				|  | @@ -59,7 +71,7 @@ export default {
 | 
	
		
			
				|  |  |    methods: {
 | 
	
		
			
				|  |  |      //加载节点
 | 
	
		
			
				|  |  |      loadNode(node, resolve) {
 | 
	
		
			
				|  |  | -      // console.log(node);
 | 
	
		
			
				|  |  | +      // console.log(resolve);
 | 
	
		
			
				|  |  |        if (node.level === 0) {
 | 
	
		
			
				|  |  |          let data = [
 | 
	
		
			
				|  |  |            {
 | 
	
	
		
			
				|  | @@ -67,12 +79,19 @@ export default {
 | 
	
		
			
				|  |  |              id: -1
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |          ];
 | 
	
		
			
				|  |  | -        return resolve(data);
 | 
	
		
			
				|  |  | +        resolve(data);
 | 
	
		
			
				|  |  | +        this.$nextTick(() => {
 | 
	
		
			
				|  |  | +          this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        // return resolve(data);
 | 
	
		
			
				|  |  |        } else if (node.level === 1) {
 | 
	
		
			
				|  |  |          getNode().then(res => {
 | 
	
		
			
				|  |  |            // console.log(res.data);
 | 
	
		
			
				|  |  |            // res.data.leaf = false
 | 
	
		
			
				|  |  | -          return resolve(res.data);
 | 
	
		
			
				|  |  | +          resolve(res.data);
 | 
	
		
			
				|  |  | +          this.$nextTick(() => {
 | 
	
		
			
				|  |  | +            this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
 | 
	
		
			
				|  |  | +          });
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |        } else {
 | 
	
		
			
				|  |  |          // console.log(node);
 | 
	
	
		
			
				|  | @@ -82,6 +101,9 @@ export default {
 | 
	
		
			
				|  |  |            .then(res => {
 | 
	
		
			
				|  |  |              // console.log(res);
 | 
	
		
			
				|  |  |              resolve(res.data);
 | 
	
		
			
				|  |  | +            this.$nextTick(() => {
 | 
	
		
			
				|  |  | +              this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  |            })
 | 
	
		
			
				|  |  |            .catch(e => {
 | 
	
		
			
				|  |  |              // console.log(e);
 | 
	
	
		
			
				|  | @@ -92,7 +114,7 @@ export default {
 | 
	
		
			
				|  |  |      //添加节点
 | 
	
		
			
				|  |  |      addNode(data, node) {
 | 
	
		
			
				|  |  |        // this.expand = false;
 | 
	
		
			
				|  |  | -      console.log(data, node);
 | 
	
		
			
				|  |  | +      // console.log(data, node);
 | 
	
		
			
				|  |  |        this.$prompt("请输入名字", "插入节点", {
 | 
	
		
			
				|  |  |          confirmButtonText: "确定",
 | 
	
		
			
				|  |  |          cancelButtonText: "取消"
 | 
	
	
		
			
				|  | @@ -140,6 +162,9 @@ export default {
 | 
	
		
			
				|  |  |            console.log("删除节点", res);
 | 
	
		
			
				|  |  |            this.$refs.tree.remove(node);
 | 
	
		
			
				|  |  |            this.loading = false;
 | 
	
		
			
				|  |  | +          this.$nextTick(() => {
 | 
	
		
			
				|  |  | +            this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
 | 
	
		
			
				|  |  | +          });
 | 
	
		
			
				|  |  |            // this.expand = true;
 | 
	
		
			
				|  |  |          })
 | 
	
		
			
				|  |  |          .catch(e => {
 | 
	
	
		
			
				|  | @@ -166,8 +191,11 @@ export default {
 | 
	
		
			
				|  |  |                console.log(data.id, data);
 | 
	
		
			
				|  |  |                data.name = value;
 | 
	
		
			
				|  |  |                this.$refs.tree.updateKeyChildren(data.id, data);
 | 
	
		
			
				|  |  | -              this.$forceUpdate();
 | 
	
		
			
				|  |  | +              // this.$forceUpdate();
 | 
	
		
			
				|  |  |                this.loading = false;
 | 
	
		
			
				|  |  | +              this.$nextTick(() => {
 | 
	
		
			
				|  |  | +                this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
 | 
	
		
			
				|  |  | +              });
 | 
	
		
			
				|  |  |              })
 | 
	
		
			
				|  |  |              .catch(e => {
 | 
	
		
			
				|  |  |                this.loading = false;
 | 
	
	
		
			
				|  | @@ -181,6 +209,15 @@ export default {
 | 
	
		
			
				|  |  |            console.log("取消修改", e);
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  | +    /** 选择状态改变
 | 
	
		
			
				|  |  | +     * @param {Object} data 节点详细数据
 | 
	
		
			
				|  |  | +     * @param {Boolean} checked 是否被选中
 | 
	
		
			
				|  |  | +     * @param {Boolean} indeterminate 是否内部被选择部分
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    handleCheckChange(data, checked, indeterminate) {
 | 
	
		
			
				|  |  | +      // console.log(data, checked, indeterminate);
 | 
	
		
			
				|  |  | +      this.$emit("check-node", this.$refs.tree.getCheckedNodes()); //返回所有节点
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // 以下未使用 ✳
 | 
	
		
			
				|  |  |      //拖拽 更新节点
 | 
	
	
		
			
				|  | @@ -239,7 +276,7 @@ export default {
 | 
	
		
			
				|  |  |    align-items: center;
 | 
	
		
			
				|  |  |    justify-content: space-between;
 | 
	
		
			
				|  |  |    font-size: 14px;
 | 
	
		
			
				|  |  | -  padding-right: 8px;
 | 
	
		
			
				|  |  | +  // padding-right: 8px;
 | 
	
		
			
				|  |  |    .handle {
 | 
	
		
			
				|  |  |      // background-color: #ccc;
 | 
	
		
			
				|  |  |      padding: 0px 5px;
 | 
	
	
		
			
				|  | @@ -248,7 +285,5 @@ export default {
 | 
	
		
			
				|  |  |      line-height: 15px;
 | 
	
		
			
				|  |  |      margin-left: 30px;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | -  .content {
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  </style>
 |