workDeptThree.vue 5.1 KB

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