XiaoRuby
2023-08-23 0d5b719e7c3ae2c18525d35cac4a8a0dc127f86e
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<template>
  <div class="main-div">
    <div class="side_div">
      <el-input placeholder="输入关键字进行过滤" v-model="filterText">
      </el-input>
      <el-tree
        class="filter-tree"
        :data="data"
        node-key="id"
        :props="defaultProps"
        default-expand-all
        :filter-node-method="filterNode"
        ref="tree"
        @node-click="handleNodeClick"
      >
      </el-tree>
    </div>
    <div class="table_div">
      <div class="table_top_div">
        <span class="top_span" v-if="msg !== ''">{{ msg }}</span>
        <div style="text-align: right; float: right">
          <el-button
            type="primary"
            size="small"
            icon="el-icon-circle-plus-outline"
            >新增</el-button
          >
          <el-button size="small" icon="el-icon-delete-solid">删除</el-button>
        </div>
      </div>
      <div class="table-main-div">
        <el-table
          ref="multipleTable"
          :data="tableData"
          border
          height="100%"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column label="日期" width="120">
            <template slot-scope="scope">{{ scope.row.date }}</template>
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="120">
          </el-table-column>
          <el-table-column prop="address" label="地址" show-overflow-tooltip>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>
 
<script>
import { getOrganizationalApi } from "@/api/laboratory/organizational";
export default {
  name: "Organizational",
  data() {
    return {
      filterText: "",
      msg: "",
      data: [],
      // tree树默认值配置
      defaultProps: {
        children: "children",
        label: "department",
        id: "id",
      },
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
    };
  },
  methods: {
    // 树上方搜索框过滤器
    filterNode(value, data) {
      if (!value) return true;
      return data.department.indexOf(value) !== -1;
    },
    // 初始化获取树数据
    treeInitialization() {
      getOrganizationalApi().then((res) => {
        this.data = res.data;
      });
    },
    // 获取树路径
    getParentData(node, department) {
      if (node !== null) {
        if (node.data.department !== undefined) {
          this.msg = node.data.department + " > " + department;
        }
        this.getParentData(node.parent, this.msg);
      }
    },
    // 点击树节点
    handleNodeClick(data, node, element) {
      this.getParentData(node.parent, node.data.department);
      console.log(`output->this.msg`, this.msg);
      console.log(`output->data`, data);
      console.log(`output->node`, node);
      console.log(`output->element`, element);
    },
    // 改变多选框状态
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    // 点击多选框以后的操作
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
  mounted() {
    this.treeInitialization();
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val);
    },
  },
};
</script>
 
<style lang="scss">
.main-div {
  width: 99.2% !important;
  height: 94vh !important;
  margin: 5px 5px 5px 5px;
}
.side_div {
  float: left;
  width: 300px;
  height: 95%;
  margin-bottom: 5px;
  background-color: #ffffff;
  padding: 15px;
}
.table_div {
  margin-left: 6px;
  float: left;
  width: calc(100% - 306px);
  height: 95%;
  background-color: #ffffff;
}
.filter-tree {
  margin-top: 6px;
}
.table_top_div {
  height: 80px;
  width: 100%;
  padding-top: 23px;
  padding-right: 50px;
}
.table-main-div {
  width: 100%;
  height: 90.3%;
  padding: 10px;
}
.top_span {
  margin-left: 12px;
  font-size: 16px;
  font-weight: 500;
  color: #999999;
}
</style>