deptTreeUserNew.vue 6.0 KB

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