deptTreeOnly.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div class="treebox" v-loading="loading">
  3. <el-input placeholder="输入关键字进行过滤" v-model="filterText"> </el-input>
  4. <el-tree
  5. :highlight-current="true"
  6. :check-strictly="true"
  7. ref="tree"
  8. :data="treeList"
  9. node-key="o"
  10. :default-checked-keys="defaultListc"
  11. :default-expanded-keys="defaultListc"
  12. @node-click="handleNodeClick"
  13. :filter-node-method="filterNode"
  14. >
  15. <span class="custom-tree-node" slot-scope="{ node, data }">
  16. <em
  17. style="display: inline-block; width: 20px"
  18. v-if="node.data.haveUserFlag == 'N' && node.data.children.length == 0"
  19. ></em>
  20. <i
  21. class="el-icon-caret-right"
  22. v-if="node.data.haveUserFlag == 'Y' && node.data.children.length == 0"
  23. ></i>
  24. <el-checkbox
  25. @change="handleCheckChange(node)"
  26. style="margin-right: 10px"
  27. v-model="node.checked"
  28. v-if="node.data.type == 1"
  29. ></el-checkbox>
  30. <span>{{ node.label }}</span>
  31. </span>
  32. </el-tree>
  33. </div>
  34. </template>
  35. <script>
  36. export default {
  37. props: ["defaultList", "type", "closeList"],
  38. data() {
  39. return {
  40. filterText: "",
  41. treeList: [],
  42. opt: [],
  43. defaultProps: {
  44. children: "children",
  45. label: "label",
  46. },
  47. defaultListc: [],
  48. loading: false,
  49. };
  50. },
  51. methods: {
  52. filterNode(value, data) {
  53. if (!value) return true;
  54. return data.label.indexOf(value) !== -1;
  55. },
  56. getTree(v) {
  57. this.loading = true;
  58. this.$http({
  59. url: "/sysmgr/csysdept/queryAllList",
  60. method: "post",
  61. headers: {
  62. "Content-Type": "application/json",
  63. },
  64. data: {
  65. parentorgid: v,
  66. },
  67. }).then((res) => {
  68. this.treeList = res.data;
  69. this.loading = false;
  70. });
  71. },
  72. handleNodeClick(v) {
  73. let s = false;
  74. if (v.children && v.children.length == 0) {
  75. s = true;
  76. }
  77. if (v.type) {
  78. return;
  79. }
  80. if (
  81. v.children &&
  82. v.children.length > 0 &&
  83. v.children[v.children.length - 1].type == 1
  84. ) {
  85. return;
  86. }
  87. console.log(v);
  88. this.$http({
  89. url: "/sysmgr/sysuserinfo/queryList",
  90. method: "post",
  91. headers: {
  92. "Content-Type": "application/json",
  93. },
  94. data: {
  95. groupId: v.o,
  96. },
  97. }).then((res) => {
  98. v.children = v.children ? v.children : [];
  99. res.data.forEach((item) => {
  100. v.children.push({
  101. id: item.groupId,
  102. label: item.loginNameStr,
  103. type: 1,
  104. displayname: v.displayname,
  105. loginNoStr: item.loginNoStr,
  106. o: item.id,
  107. });
  108. });
  109. });
  110. for (let i = 0; i < this.$refs.tree.store._getAllNodes().length; i++) {
  111. if (s && v.o == this.$refs.tree.store._getAllNodes()[i].data.o) {
  112. this.$refs.tree.store._getAllNodes()[i].expanded = true;
  113. }
  114. }
  115. },
  116. handleCheckChange(v) {
  117. console.log(v);
  118. let opt = {
  119. leaderAuditNo: v.data.loginNoStr,
  120. leaderAuditName: v.data.label,
  121. displayname: v.data.displayname,
  122. groupId: v.data.o,
  123. };
  124. this.$emit("treeCheck", opt);
  125. for (let i = 0; i < this.$refs.tree.store._getAllNodes().length; i++) {
  126. if (v.data.o == this.$refs.tree.store._getAllNodes()[i].data.o) {
  127. this.$refs.tree.store._getAllNodes()[i].checked = true;
  128. } else {
  129. this.$refs.tree.store._getAllNodes()[i].checked = false;
  130. }
  131. }
  132. this.$forceUpdate();
  133. },
  134. },
  135. created() {
  136. this.getTree();
  137. this.defaultListc = this.defaultList;
  138. },
  139. watch: {
  140. type() {
  141. this.defaultListc = this.defaultList;
  142. this.$forceUpdate();
  143. },
  144. defaultList() {
  145. this.$forceUpdate();
  146. },
  147. closeList() {
  148. this.$refs.tree.setCheckedNodes([]);
  149. },
  150. filterText(val) {
  151. this.$refs.tree.filter(val);
  152. },
  153. },
  154. };
  155. </script>
  156. <style scoped lang="scss">
  157. .el-icon-caret-right {
  158. color: #ccc;
  159. margin: 0 5px;
  160. }
  161. .treebox {
  162. border: 1px solid #ddd;
  163. }
  164. </style>