xiangpei
2024-11-30 b33517d527aff48ff30eb78d341bbce53d0ed3bb
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
<template>
  <div>
    <el-dialog
      :title="`选择候选部门`"
      :visible.sync="show"
      width="65%"
 
      :destroy-on-close="true"
      :close-on-click-modal="false"
      :before-close="close">
      <el-tree
        ref="tree"
        :data="deptTree"
        show-checkbox
        node-key="id"
        :check-strictly="true"
        :default-expanded-keys="['dept:100']"
        @check-change="handleCheckChange"
        >
      </el-tree>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="submit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
 
<script>
import {flowableDeptTreeSelect} from "@/api/system/user";
 
export default {
  name: "index",
  props: {
    show: {
      required: true,
      type: Boolean
    },
    checkeds: {
      required: true
    }
  },
  watch: {
    show: {
      handler(newV) {
        this.$nextTick(() => {
          if (this.$refs.tree && this.checkeds) {
            this.$refs.tree.setCheckedKeys(this.checkeds);
          }
        });
      },
      deep: true
    }
  },
  data() {
    return {
      deptTree: [],
      checkList: [],
    }
  },
  created() {
    flowableDeptTreeSelect().then(res => {
      this.deptTree = res.data
    })
  },
  methods: {
    setCheckList(value) {
      this.checkList = value
    },
    handleCheckChange(data, checked, indeterminate) {
      if (checked) {
        this.checkList.push(data)
      } else {
        this.checkList = this.checkList.filter(item => item !== data)
      }
      console.log(data, checked, indeterminate);
    },
    close() {
      this.$emit("close")
    },
    submit() {
      const checkedIds = this.checkList.map(item => item.id).join(",")
      const names = this.checkList.map(item => item.label).join(",")
      this.$emit("submit", checkedIds, names)
    }
  }
}
</script>
 
<style scoped>
 
</style>