deptTreeUserNew.vue 5.7 KB

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