newTree.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div class="flex-box">
  3. <div class="treebox">
  4. <div class="tree-text">组织机构</div>
  5. <el-input placeholder="可按名字匹配所在部门" v-model="filterText">
  6. </el-input>
  7. <el-tree ref="tree" @node-click="handleNodeClick" :data="treeList" node-key="o" :indent="20"
  8. :default-checked-keys="defaultListc" :default-expanded-keys="defaultList">
  9. <span class="span-ellipsis" slot-scope="{ node, data }">
  10. <span :title="node.label"><i v-if="data.children.length === 0" class="el-icon-caret-right icon-right"></i>
  11. {{ node.label }}</span>
  12. </span>
  13. </el-tree>
  14. </div>
  15. <div class="flex-transfer">
  16. <el-transfer v-model="value" :titles="['待选人员', '已选人员']" @change="handleCheckChange"
  17. :data="transferList"></el-transfer>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. props: ["defaultList", "type"],
  24. data() {
  25. return {
  26. filterTexts: "",
  27. filterText: "",
  28. transferList: [],
  29. treeList: [],
  30. treeLists: [],
  31. rightList: [],
  32. value: [],
  33. newArr: [],
  34. opt: [],
  35. treeId: 1,
  36. defaultProps: {
  37. children: "children",
  38. label: "label",
  39. },
  40. defaultListc: [],
  41. };
  42. },
  43. methods: {
  44. handleNodeClick(v) {
  45. for (let i = v.children.length - 1; i >= 0; i--) {
  46. if (v.children[i].haveUserFlag == "N") {
  47. v.children.splice(i, 1);
  48. }
  49. }
  50. // v.children.map((item,index) =>{
  51. // if(item.haveUserFlag == "N"){
  52. // v.children.splice(index, 1);
  53. // }
  54. // console.log(v.children);
  55. // })
  56. let list = {
  57. groupId: v.o,
  58. };
  59. if (this.filterTexts) {
  60. list.loginNameStr = this.filterTexts;
  61. }
  62. if (v.o !== this.treeId) {
  63. if (this.value.length !== 0) {
  64. let a = [];
  65. for (let i = 0; i <= this.transferList.length - 1; i++) {
  66. for (let y = 0; y <= this.value.length; y++) {
  67. if (this.transferList[i].key === this.value[y]) {
  68. console.log(this.transferList[i].key);
  69. console.log(this.value[y]);
  70. a.push(this.transferList[i]);
  71. }
  72. }
  73. }
  74. console.log(a);
  75. this.transferList = a;
  76. // console.log(this.transferList);
  77. } else {
  78. this.transferList = [];
  79. }
  80. }
  81. let s = false;
  82. if (v.children && v.children.length == 0) {
  83. s = true;
  84. }
  85. if (v.type) {
  86. return;
  87. }
  88. if (
  89. v.children &&
  90. v.children.length > 0 &&
  91. v.children[v.children.length - 1].type == 1
  92. ) {
  93. return;
  94. }
  95. if (v.o !== this.treeId) {
  96. this.$http({
  97. url: "/sysmgr/sysuserinfo/queryListByName",
  98. method: "post",
  99. headers: {
  100. "Content-Type": "application/json",
  101. },
  102. data: list
  103. }).then((res) => {
  104. v.children = v.children ? v.children : [];
  105. this.treeId = v.o;
  106. this.treeLists = res.data;
  107. res.data.map((item, index) => {
  108. this.transferList.push({
  109. label: item.loginNameStr,
  110. key: item.loginNoStr,
  111. });
  112. });
  113. const dalaoyang = (arr, key) => {
  114. let map = new Map()
  115. return arr.filter(item => !map.has(item[key]) && map.set(item[key], 1))
  116. }
  117. this.transferList = dalaoyang(this.transferList, "key")
  118. console.log(this.transferList);
  119. });
  120. } else {
  121. console.log(this.transferList);
  122. }
  123. },
  124. getTree(v, e) {
  125. let list = {
  126. parentorgid: v,
  127. // functionName: e,
  128. };
  129. if (e) {
  130. list.functionName = e;
  131. }
  132. this.loading = true;
  133. this.$http({
  134. url: "/sysmgr/csysdept/queryAllList",
  135. method: "post",
  136. headers: {
  137. "Content-Type": "application/json",
  138. },
  139. data: list,
  140. }).then((res) => {
  141. this.loading = false;
  142. this.treeList = res.data;
  143. let list = res.data[0].children.filter((item, i, array) => {
  144. return item.haveUserFlag === "Y";
  145. });
  146. this.treeList[0].children = list;
  147. });
  148. },
  149. handleCheckChange(v) {
  150. // let opt = [];
  151. // let list = this.$refs.tree.getCheckedNodes();
  152. // for (let i = 0; i < list.length; i++) {
  153. // if (this.type == 1) {
  154. // opt.push({
  155. // deptCode: list[i].o,
  156. // deptName: list[i].ou,
  157. // });
  158. // } else {
  159. // opt.push({
  160. // deptId: list[i].o,
  161. // deptName: list[i].ou,
  162. // });
  163. // }
  164. // }
  165. // console.log(opt);
  166. let opt = [];
  167. this.transferList.map((item) => {
  168. this.value.map((items) => {
  169. if (item.key === items) {
  170. opt.push(item);
  171. }
  172. });
  173. });
  174. console.log(opt);
  175. this.$emit("treeCheck", opt);
  176. },
  177. },
  178. created() {
  179. this.getTree();
  180. this.defaultListc = this.defaultList;
  181. },
  182. watch: {
  183. filterText(val) {
  184. // this.$refs.tree.filter(val);
  185. console.log(val);
  186. this.filterTexts = val;
  187. this.getTree("", this.filterTexts);
  188. },
  189. },
  190. };
  191. </script>
  192. <style scoped lang="scss">
  193. ::v-deep .el-checkbox.el-transfer-panel__item {
  194. display: block !important;
  195. }
  196. ::v-deep .el-transfer-panel__list.is-filterable {
  197. height: calc(100% - 110px);
  198. }
  199. ::v-deep .el-transfer-panel__body {
  200. height: 100%;
  201. }
  202. .tree-text {
  203. font-size: 20px;
  204. color: black;
  205. padding: 15px;
  206. font-weight: 600;
  207. }
  208. .flex-box {
  209. display: flex;
  210. width: 100%;
  211. justify-content: center;
  212. height: 80%;
  213. }
  214. ::v-deep .el-icon-caret-right {
  215. font-size: 12px;
  216. background-size: cover;
  217. margin-left: px;
  218. }
  219. .icon-right {
  220. margin-left: 5px;
  221. color: #fff;
  222. }
  223. .treebox {
  224. width: 30%;
  225. border: 1px solid #ddd;
  226. height: 100%;
  227. background-color: #fff;
  228. overflow: scroll;
  229. overflow-x: hidden;
  230. }
  231. .flex-transfer {
  232. width: 50%;
  233. height: 100%;
  234. margin-left: 30px;
  235. }
  236. ::v-deep .el-transfer-panel {
  237. width: 35%;
  238. height: 100%;
  239. }
  240. ::v-deep .el-transfer {
  241. height: 100%;
  242. }
  243. </style>