xiangpei
2024-11-30 330075c4185e849b8978b20e05e589deddb0e572
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
<template>
  <div>
    <el-dialog
      :title="`选择候选部门`"
      :visible.sync="show"
      width="65%"
      :close-on-click-modal="false"
      :before-close="close">
      <el-tree
        :data="deptTree"
        show-checkbox
        node-key="id"
        :check-strictly="true"
        :default-expanded-keys="['dept:100']"
        @check-change="handleCheckChange"
        :default-checked-keys="checkeds">
      </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,
      type: Array
    }
  },
  // watch: {
  //   checkeds: {
  //     handler(newV) {
  //       if (newV) {
  //         console.log("djjdjdjdjdjdjj")
  //         this.checkedAfterHandler = newV.map(item => {const arr = item.split(':'); return parseInt(arr[1])})
  //       }
  //     },
  //     deep: true
  //   }
  // },
  data() {
    return {
      deptTree: [],
      checkList: [],
    }
  },
  created() {
    flowableDeptTreeSelect().then(res => {
      this.deptTree = res.data
    })
  },
  methods: {
    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>