liuxiaolong
2019-05-06 770c069996e1d2979c1170c1639c18b02d07e72f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<template>
  <b-modal
    :title="title"
    ref="myModalRef"
    ok-title="保存"
    @ok="handleOk"
    @cancel="clearName"
    cancel-title="取消"
    :hide-header="!title"
    :hide-footer="isShowFooter"
  >
    <div>
      <Tree
        ref="tree"
        :data="treeData"
        :isOpenAll="false"
        :currentId="currentId"
        @currentNode="currentNode"
        @check-change="({list,ids})=>{checkedList=list;checkedIds=ids}"
        :showCheckbox="true"
      />
    </div>
  </b-modal>
</template>
 
<script>
import Tree from './Tree'
export default {
  props: {
    title: String,
    item: Object,
    treeData: {
      default: []
    },
    isShowFooter: {
      default: false
    }
  },
  data: () => ({
    name: '',
    currentOrgItem: null,
    currentId: '',
    checkedList: [],
    checkedIds: []
  }),
  methods: {
    // * 打开modal
    showModel() {
      this.$refs.myModalRef.show()
      console.log(this.treeData, 'this.treeData')
      this.$nextTick(() => {
        this.reView(this.item)
      })
    },
    hideModel() {
      this.$refs.myModalRef.hide()
    },
    // * 组织机构数点击回调
    currentNode(node) {
      this.currentOrgItem = node
      this.currentId = node.id
      if (this.isShowFooter) {
        this.$emit('submit', {
          node: this.currentOrgItem,
          id: this.currentId
        })
      }
    },
    // 回显
    reView(item) {
      console.log(item, 'item----')
      if (item) {
        this.currentOrgItem = item
        this.currentId = item.id
        /* 设置选中项 */
        this.$refs.tree.setCurrentKey(item.id)
      } else {
        this.currentOrgItem = null
        this.currentId = ''
        /*  清空  */
        this.$refs.tree.removeCurrentNode()
      }
    },
    // * 提交表单
    handleOk(e) {
      e.preventDefault()
      if (!this.currentOrgItem || this.checkedList.length === 0) {
        this.$toast({
          type: 'error',
          message: '请选择节点'
        })
        return
      }
      this.$emit('submit', {
        node: this.currentOrgItem,
        id: this.currentId,
        list: this.checkedList,
        ids: this.checkedIds
      })
    },
    // * 取消
    clearName() {},
    handleCheckChange(data) {
      console.log(data, 'data')
    }
  },
  components: {
    Tree
  }
}
</script>