index.vue 3.6 KB

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