newTree.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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", "oneORmore","treeListType"],
  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. groupName: item.groupName,
  112. });
  113. });
  114. const dalaoyang = (arr, key) => {
  115. let map = new Map()
  116. return arr.filter(item => !map.has(item[key]) && map.set(item[key], 1))
  117. }
  118. this.transferList = dalaoyang(this.transferList, "key")
  119. console.log(this.transferList);
  120. });
  121. } else {
  122. console.log(this.transferList);
  123. }
  124. },
  125. getTree(v, e) {
  126. let list = {
  127. parentorgId: v,
  128. type:this.treeListType,//* 1:全部传递 2:值传递第一层 3:值传递第一层之后数据
  129. };
  130. if (e) {
  131. list.name = e;
  132. }
  133. this.loading = true;
  134. this.$http({
  135. // url: "/sysmgr/csysdept/queryAllList",
  136. url: "/sysmgr/csysdept/queryAllListByParentorgId",
  137. method: "post",
  138. headers: {
  139. "Content-Type": "application/json",
  140. },
  141. data: list,
  142. }).then((res) => {
  143. this.loading = false;
  144. this.treeList = res.data;
  145. let list = res.data[0].children.filter((item, i, array) => {
  146. return item.haveUserFlag === "Y";
  147. });
  148. this.treeList[0].children = list;
  149. });
  150. },
  151. handleCheckChange(v) {
  152. // console.log(this.value);
  153. if (this.oneORmore == '2') {
  154. if (this.value.length > 1) {
  155. this.$message({
  156. message: '只能选择一人',
  157. type: 'error'
  158. });
  159. this.value = [this.value[0]]
  160. let opt = [];
  161. this.transferList.map((item) => {
  162. this.value.map((items) => {
  163. if (item.key === items) {
  164. opt.push(item);
  165. }
  166. });
  167. });
  168. // console.log(opt);
  169. this.$emit("treeCheck", opt);
  170. } else {
  171. let opt = [];
  172. this.transferList.map((item) => {
  173. this.value.map((items) => {
  174. if (item.key === items) {
  175. opt.push(item);
  176. }
  177. });
  178. });
  179. // console.log(opt);
  180. this.$emit("treeCheck", opt);
  181. }
  182. } else {
  183. let opt = [];
  184. this.transferList.map((item) => {
  185. this.value.map((items) => {
  186. if (item.key === items) {
  187. opt.push(item);
  188. }
  189. });
  190. });
  191. // console.log(opt);
  192. this.$emit("treeCheck", opt);
  193. }
  194. },
  195. },
  196. created() {
  197. this.getTree('00440063000000000000');
  198. this.defaultListc = this.defaultList;
  199. },
  200. watch: {
  201. filterText(val) {
  202. // this.$refs.tree.filter(val);
  203. console.log(val);
  204. this.filterTexts = val;
  205. this.getTree("00440063000000000000", this.filterTexts);
  206. },
  207. },
  208. };
  209. </script>
  210. <style scoped lang="scss">
  211. ::v-deep .el-checkbox.el-transfer-panel__item {
  212. display: block !important;
  213. }
  214. // ::v-deep .el-transfer-panel__list.is-filterable {
  215. // height: calc(100%);
  216. // }
  217. // ::v-deep .el-checkbox-group .el-transfer-panel__list {
  218. // height: 388px;
  219. // }
  220. .el-transfer-panel {
  221. height: 500px;
  222. }
  223. .el-transfer-panel__list.is-filterable {
  224. height: 400px;
  225. }
  226. ::v-deep .el-transfer-panel__body {
  227. height: 100%;
  228. }
  229. ::v-deep .el-transfer-panel__list{
  230. height: 100%;
  231. }
  232. .tree-text {
  233. font-size: 20px;
  234. color: black;
  235. padding: 15px;
  236. font-weight: 600;
  237. }
  238. .flex-box {
  239. display: flex;
  240. width: 100%;
  241. justify-content: center;
  242. height: 80%;
  243. }
  244. ::v-deep .el-icon-caret-right {
  245. font-size: 12px;
  246. background-size: cover;
  247. margin-left: px;
  248. }
  249. .icon-right {
  250. margin-left: 5px;
  251. color: #fff;
  252. }
  253. .treebox {
  254. width: 30%;
  255. border: 1px solid #ddd;
  256. height: 100%;
  257. background-color: #fff;
  258. overflow: scroll;
  259. overflow-x: hidden;
  260. max-height: 390px;
  261. height: 390px;
  262. }
  263. .flex-transfer {
  264. width: 50%;
  265. height: 390px;
  266. margin-left: 30px;
  267. }
  268. ::v-deep .el-transfer-panel {
  269. width: 35%;
  270. height: 100%;
  271. }
  272. ::v-deep .el-transfer {
  273. height: 100%;
  274. }
  275. </style>