liuxiaolong
2019-05-06 2ab7a76a38fbf8fa107bf6371f5410ba54e1d394
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
<template>
  <b-modal
    :title="title"
    ref="myModalRef"
    ok-title="保存"
    @ok="handleOk"
    @cancel="clearName"
    cancel-title="取消"
  >
    <div>
      <PersonnelTree
          ref="tree"
          :data="treeData"
          :isOpenAll="false"
          :currentId="currentId"
          @currentNode="currentNode"
        />
    </div>
  </b-modal>
</template>
 
<script>
import PersonnelTree from '@/pages/Personnel/component/PersonnelTree'
export default {
  props: {
    title: String,
    item: Object,
    treeData: {
      default: []
    }
  },
  data: () => ({
    name: '',
    currentOrgItem: null,
    currentId: ''
  }),
  methods: {
    // * 打开modal
    showModel() {
      this.$refs.myModalRef.show()
      this.$nextTick(() => {
        this.reView(this.item)
      })
    },
    hideModel() {
      this.$refs.myModalRef.hide()
    },
    // * 组织机构数点击回调
    currentNode(node) {
      this.currentOrgItem = node
      this.currentId = node.id
    },
    // 回显
    reView(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.$toast({
          type: 'error',
          message: '请输组织机构'
        })
        return
      }
      this.$emit('submit', {
        node: this.currentOrgItem,
        id: this.currentId
      })
    },
    // * 取消
    clearName() {}
  },
  components: {
    PersonnelTree
  }
}
</script>