index.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div>
  3. <div class="head-container">
  4. <el-input
  5. v-model="deptName"
  6. :placeholder="searchPlaceHolder"
  7. clearable
  8. size="small"
  9. prefix-icon="el-icon-search"
  10. style="margin-bottom: 20px"
  11. />
  12. </div>
  13. <div class="tree-container">
  14. <div style="margin-bottom: 10px" v-show="showLowerCheck">
  15. <el-checkbox v-model="checkSub" @change="changeCheckBox"
  16. >关联下级</el-checkbox
  17. >
  18. </div>
  19. <el-tree
  20. :data="treeList"
  21. :props="defaultProps"
  22. :expand-on-click-node="false"
  23. :filter-node-method="filterNode"
  24. ref="tree"
  25. node-key="id"
  26. class="el-tree-ex"
  27. :default-expanded-keys="defaultKeys"
  28. :default-checked-keys="defaultKeys"
  29. @node-click="handleNodeClick"
  30. v-bind="$attrs"
  31. >
  32. <span class="custom-tree-node" slot-scope="{ node, data }">
  33. <el-tooltip
  34. class="item"
  35. effect="light"
  36. :content="node.label"
  37. placement="top-start"
  38. >
  39. <span>{{ node.label }}</span>
  40. </el-tooltip>
  41. </span>
  42. </el-tree>
  43. </div>
  44. </div>
  45. </template>
  46. <script>
  47. import tableListMixins from "@/mixins/tableList";
  48. import { deptTreeSelect, handsheDeptTreeSelect } from "@/api/system/public";
  49. export default {
  50. name: "orgTree",
  51. mixins: [tableListMixins],
  52. data() {
  53. return {
  54. //过滤信息
  55. deptName: "",
  56. // 机构树列表
  57. treeList: [],
  58. //默认选中节点
  59. defaultKeys: [],
  60. checkSub: true,
  61. defaultKey: null,
  62. };
  63. },
  64. props: {
  65. hangsheTree: {
  66. type: Boolean,
  67. default: false,
  68. },
  69. defaultProps: {
  70. type: Object,
  71. default: () => {
  72. return {
  73. children: "children",
  74. label: "shortName",
  75. };
  76. },
  77. },
  78. customRequest: {
  79. type: Function,
  80. },
  81. showLowerCheck: {
  82. type: Boolean,
  83. default: true,
  84. },
  85. searchPlaceHolder: {
  86. type: String,
  87. default: "请输入机构名称",
  88. },
  89. },
  90. watch: {
  91. // 根据名称筛选机构树
  92. deptName(val) {
  93. this.$refs.tree.filter(val);
  94. },
  95. defaultProps(val) {
  96. this.defaultProps = { ...val };
  97. },
  98. },
  99. mounted() {
  100. this.getDeptTree();
  101. },
  102. methods: {
  103. /** 下穿状态改变*/
  104. changeCheckBox(state) {
  105. this.$emit("checkChange", state);
  106. },
  107. /** 查询机构下拉树结构 */
  108. getDeptTree() {
  109. if (this.customRequest) {
  110. this.customRequest().then((response) => {
  111. this.treeList = response.data;
  112. this.dataFn(response.data);
  113. return;
  114. });
  115. } else {
  116. if (this.hangsheTree) {
  117. this.treeList = this.$store.getters.depTree;
  118. } else {
  119. this.treeList = this.$store.getters.orgTree;
  120. }
  121. this.dataFn(this.treeList);
  122. }
  123. },
  124. dataFn(arr) {
  125. console.log(arr, "arrr");
  126. this.defaultKeys.push(arr[0].id);
  127. this.$emit("defaultKey", arr[0].id);
  128. this.$emit("defaultOrg", arr[0]);
  129. this.defaultKey = arr[0].id;
  130. setTimeout(() => {
  131. this.$refs.tree.setCurrentKey(arr[0].id);
  132. }, 100);
  133. },
  134. // 筛选节点
  135. filterNode(value, data) {
  136. if (!value) return true;
  137. return data.name.indexOf(value) !== -1;
  138. },
  139. // 节点单击事件
  140. handleNodeClick(data, node) {
  141. this.$emit("click", data, node);
  142. },
  143. },
  144. };
  145. </script>
  146. <style lang="scss" scoped>
  147. .el-tree-ex {
  148. // overflow: auto;
  149. ::v-deep .is-current > .el-tree-node__content {
  150. background-color: #d1e0f1 !important;
  151. }
  152. }
  153. </style>