zhanghua
2025-04-14 829f5116884f98643ffc5b2a548a600d40c0cedb
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
<template>
  <el-select v-model="model.departName" placeholder="请选择部门">
    <el-option value="1">
      <el-tree
        ref="tree"
        :check-strictly="true"
        :data="departList"
        :props="defaultProps"
        :default-checked-keys="selectIds"
        show-checkbox
        @check-change="handleCheck"
        @node-click="nodeClick"
        default-expand-all
        node-key="id"
      >
      </el-tree>
    </el-option>
  </el-select>
</template>
<script>
export default {
  data() {
    return {
      model: {
        departId: 0,
        departName: "",
      },
      selectIds: [],
      departList: [],
      defaultProps: {
        children: "children",
        label: "departName",
      },
    };
  },
  created() {
    // 获取全部部门列表
    this.$axios.get("/sccg/depart/tree").then((res) => {
      this.departList = res.data;
      if (this.depart) {
        this.model.departId = this.depart.departId;
        this.model.departName = this.depart.departName;
        this.selectIds = [this.depart.departId];
      }
    });
  },
  methods: {
    nodeClick(data, checked) {
      this.checkedId = data.comcode;
      this.$refs.tree.setCheckedNodes([data]);
      this.model.departId = data.id;
      this.model.departName = data.departName;
    },
    handleCheck(data, checked) {
      if (checked == true) {
        this.checkedId = data.comcode;
        this.$refs.tree.setCheckedNodes([data]);
        this.model.departId = data.id;
        this.model.departName = data.departName;
        this.$emit("selectDepart", this.model);
      }
    },
  },
 
  props: ["depart"],
};
</script>
<style lang="scss" scoped>
</style>