tkitree.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <template xlang="wxml">
  2. <view class="tkitree">
  3. <view class="tkitree-mask show" v-if="showTree" @tap="_cancel"></view>
  4. <view class="tkitree-cnt show" v-if="showTree">
  5. <view class="tkitree-bar">
  6. <view
  7. class="tkitree-bar-cancel"
  8. :style="{ color: cancelColor }"
  9. hover-class="hover-c"
  10. @tap="_cancel"
  11. >取消
  12. </view>
  13. <view class="tkitree-bar-title" :style="{ color: titleColor }">{{
  14. title
  15. }}</view>
  16. <view
  17. class="tkitree-bar-confirm"
  18. :style="{ color: confirmColor }"
  19. hover-class="hover-c"
  20. @tap="_confirm"
  21. v-if="!custom"
  22. >确定
  23. </view>
  24. </view>
  25. <view class="tkitree-view">
  26. <view class="searchBox">
  27. <input
  28. type="text"
  29. placeholder="输入姓名搜索"
  30. v-model="searchname"
  31. class="searchname"
  32. />
  33. <button class="clear" @click="clear()">清空</button>
  34. </view>
  35. <scroll-view class="tkitree-view-sc" :scroll-y="true">
  36. <block v-for="(item, index) in treeList" :key="index">
  37. <view
  38. class="tkitree-item"
  39. :style="[
  40. {
  41. paddingLeft: item.rank * 15 + 'px',
  42. zIndex: item.rank * -1 + 50,
  43. },
  44. ]"
  45. :class="{
  46. border: border === true,
  47. show: item.show,
  48. last: item.lastRank,
  49. showchild: item.showChild,
  50. open: item.open,
  51. }"
  52. >
  53. <view class="tkitree-label" @tap.stop="_treeItemTap(item, index)">
  54. <image
  55. class="tkitree-icon"
  56. :src="
  57. item.lastRank
  58. ? lastIcon
  59. : item.showChild
  60. ? currentIcon
  61. : defaultIcon
  62. "
  63. >
  64. </image>
  65. {{ item.name }}
  66. </view>
  67. <view v-if="!custom">
  68. <view
  69. class="tkitree-check"
  70. @tap.stop="_treeItemSelect(item, index)"
  71. v-if="selectParent ? true : item.lastRank"
  72. >
  73. <view
  74. class="tkitree-check-yes"
  75. v-if="item.checked"
  76. :class="{ radio: !multiple }"
  77. :style="{ 'border-color': confirmColor }"
  78. >
  79. <view
  80. class="tkitree-check-yes-b"
  81. :style="{ 'background-color': confirmColor }"
  82. >
  83. </view>
  84. </view>
  85. <view
  86. class="tkitree-check-no"
  87. v-else
  88. :class="{ radio: !multiple }"
  89. :style="{ 'border-color': confirmColor }"
  90. ></view>
  91. </view>
  92. </view>
  93. <view v-if="custom">
  94. <u-button
  95. type="success"
  96. size="mini"
  97. @tap.stop="_treeItemSelect2(item, index)"
  98. >选中
  99. </u-button>
  100. </view>
  101. </view>
  102. </block>
  103. </scroll-view>
  104. </view>
  105. </view>
  106. </view>
  107. </template>
  108. <script>
  109. import tools from "./tools";
  110. import { getSelectUserTwo } from "@/js_sdk/http";
  111. export default {
  112. name: "tkitree",
  113. props: {
  114. reciveUserInfo: {
  115. type: String,
  116. },
  117. range: {
  118. type: Array,
  119. default: [],
  120. },
  121. idKey: {
  122. type: String,
  123. default: "id",
  124. },
  125. default_value: {
  126. type: Array,
  127. default: [],
  128. },
  129. rangeKey: {
  130. type: String,
  131. default: "label",
  132. },
  133. title: {
  134. type: String,
  135. default: "",
  136. },
  137. multiple: {
  138. // 是否可以多选
  139. type: Boolean,
  140. default: true,
  141. // default: true
  142. },
  143. selectParent: {
  144. //是否可以选父级
  145. type: Boolean,
  146. default: false,
  147. },
  148. foldAll: {
  149. //折叠时关闭所有已经打开的子集,再次打开时需要一级一级打开
  150. type: Boolean,
  151. default: false,
  152. },
  153. confirmColor: {
  154. // 确定按钮颜色
  155. type: String,
  156. default: "", // #07bb07
  157. },
  158. cancelColor: {
  159. // 取消按钮颜色
  160. type: String,
  161. default: "", // #757575
  162. },
  163. titleColor: {
  164. // 标题颜色
  165. type: String,
  166. default: "", // #757575
  167. },
  168. currentIcon: {
  169. // 展开时候的ic
  170. type: String,
  171. default:
  172. "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFEAAABRCAYAAACqj0o2AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoV2luZG93cykiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6MEQ0QTM0MzQ1Q0RBMTFFOUE0MjY4NzI1Njc1RjI1ODIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6MEQ0QTM0MzU1Q0RBMTFFOUE0MjY4NzI1Njc1RjI1ODIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDowRDRBMzQzMjVDREExMUU5QTQyNjg3MjU2NzVGMjU4MiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDowRDRBMzQzMzVDREExMUU5QTQyNjg3MjU2NzVGMjU4MiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PidwepsAAAK0SURBVHja7JxbTsJAFIYHww7ciStgCeoGvGxAiOsgURegoL5720AXYLiIr0aJviq3Zx3PhIEnKG3ndtr+f3KixrSUj/ZjzjClIqUUiFm2gAAQAREQEUAEREAERAQQAREQAREBREAEREBEEqa67h9RFDWllDv0awWYlqlQHmu1WjMRRMoV1QFttA12y3xRtdNczq8EsE4/f8FumX2q77ROvNXk8UGMEKdUz6tYJHljaZAbuyUH+UR1to5BEohTuqwPCeS4pAA/qY6o/kyHOAMCeRK3owJnj+rH1jjxhqpVsstaebCz6TmnHWyXyY+xHjSBWBY/bvSgadtXBj9u9KCN3rnIfkzkQVsTEEX0Y2IP2oKo/HhMICcFAThUcwVZNGU6FdbX/XURzkbVF4+ybGhjPrFdgP66QdXNurGtSdk6Xdb9nAJ8oDo3OQlsQZzkdPw41ONBo6vI5scDefRjZg+6gpg3Pxp50CXEvPjR2IOuIXL3oxUPuobI3Y9WPOgDIlc/WvOgL4iL/vqFCcD7LH0xB4hj7cfQ/fWH9qCT+FhG0tN+DBk1PzjOM0SVllixcsBT1AvYc/kAPhc0hRg/3uvxoCgKRN9+dOrBUBB9+9GpB0NC9OVH5x4MDdG1H714kANEV3705kEOEBf9dcPi/lQnsuvLg1wgSu3Ha0v7Uh4MMgUXeuG71H407a+VBy9CPQkOdw+MtB+nGbd/D+FBbhBNxo9SjwcngJjNj0E9yBFiFj8G9SBXiGn8GNyDnCEm8SMLD3KHGOdHNh7kDjHOj2w8mAeIi/5arX+c6b/fxHz9oADEdGdjR/fXCw/OOB5oVfCOgnepz8IB14PMw03jCmTE+QBx5z0gAmKSqK9OUF+hcAeIhu/QYr4Qie8rjW83hhMBERARQAREQAREBBABERCLnH8BBgA+TQI7U4t53AAAAABJRU5ErkJggg==",
  173. },
  174. defaultIcon: {
  175. // 折叠时候的ic
  176. type: String,
  177. default:
  178. "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFEAAABRCAYAAACqj0o2AAACE0lEQVR4Xu3c200DMRCF4XEltJAOkEugA+ggpUAHoQMqiFMCdEAJUMEiS4mEELlIO7bPOeN9i6K1rG/952myyea1WiCtXmEuYBPR4RBMxInoIOCwhOtJLKVszWyXc/5y2BvNEq6I+/3+kFK6M7OHnPM7jcLKjbZAvD/uaZtzflm5P4rbWyJWgDcze1LPuzVihfxUz7sH4ilJ2bx7Isrm3RtRMu8RiHJ5j0SUyXs0okTeCIj0eSMh0uaNhkiZNyIiXd7IiDR5oyNS5M2ACJ83EyJs3myIkHkzIsLlzYwIkzc7IkTeCojD81ZCHJa3GuKQvBURu+etjNgtb3XELnlHQGyedyTEZnlHQ2ySd0RE97wjI7rlHR3RJe+JeIrbLOecD6ePpZQ6W1kn2epo4MUrPOKyLN8ppYq1+y1VStncOjIdGnFZlo+U0uOtWOeOY2TE12Ouq//pEA7xXL7XfvcufR8K0Svfv6CREN3yDYfYIt9QiK3yjYTYLF95xB75SiP2ylcZsVu+cogj8pVCHJWvEuKwfOkREfKlRkTJlxkRJl86RMR8qRBR82VChM0XHpEhX2hElnyREWnyhUNkzBcKkTVfJETafIcjKuQ7FFEl35GIMvl2R1TMtyuiar49EWXzbY5oZpv/hibXTF2h3+s60FRKeT6+3TjMS3nrA3ZFRD8xrfY3ER1kJ+JEdBBwWGKeRAfEH1wS5WFZSDB/AAAAAElFTkSuQmCC",
  179. },
  180. lastIcon: {
  181. // 没有子集的ic
  182. type: String,
  183. default: "",
  184. },
  185. border: {
  186. // 是否有分割线
  187. type: Boolean,
  188. default: false,
  189. },
  190. custom: {
  191. // 是否进入自定义
  192. type: Boolean,
  193. default: false,
  194. },
  195. spread: {
  196. // 展开第一层
  197. type: Boolean,
  198. default: true,
  199. },
  200. },
  201. data() {
  202. return {
  203. fartherKey: "",
  204. showTree: false,
  205. treeList: [],
  206. selectIndex: -1,
  207. idArr: [],
  208. searchname: "",
  209. selectName: [],
  210. getMsg: "",
  211. };
  212. },
  213. computed: {},
  214. methods: {
  215. clear() {
  216. this.searchname = "";
  217. },
  218. // 搜索组织接口
  219. async getList() {
  220. let departmentList = await getSelectUserTwo(this.searchname);
  221. this._initTree(
  222. tools.transData(departmentList.data, "id", "parentid", "children")
  223. );
  224. // this.treeList=departmentList.data;
  225. let list = this.treeList;
  226. list.forEach((childItem, i) => {
  227. if (childItem.name == this.searchname) {
  228. childItem.show = true;
  229. }
  230. this.selectName.forEach((item) => {
  231. if (childItem.name == item) {
  232. childItem.checked = true;
  233. childItem.show = true;
  234. const obj = this.treeList.filter(
  235. (x) =>
  236. childItem.parentId[childItem.parentId.length - 1] ===
  237. x.parentId[x.parentId.length - 1]
  238. );
  239. obj.forEach((x) => {
  240. x.show = true;
  241. });
  242. }
  243. });
  244. this.treeList.forEach((k1, i1) => {
  245. if (k1.checked) {
  246. k1.parentId.forEach((k2, i2) => {
  247. this.treeList.forEach((k3, i3) => {
  248. if (k3.id == k2) {
  249. this.treeList[i3].checked = true;
  250. this.treeList[i3].show = true;
  251. this.treeList[i3].showChild = true;
  252. }
  253. });
  254. });
  255. }
  256. });
  257. });
  258. },
  259. _show() {
  260. this.showTree = true;
  261. },
  262. _hide() {
  263. this.showTree = false;
  264. },
  265. _cancel() {
  266. this._hide();
  267. this.$emit("cancel", "");
  268. },
  269. _confirm() {
  270. // 处理所选数据
  271. let rt = [],
  272. obj = {};
  273. this.treeList.forEach((v, i) => {
  274. if (this.treeList[i].checked) {
  275. obj = {};
  276. obj.parents = this.treeList[i].parents;
  277. obj = Object.assign(obj, this.treeList[i].source);
  278. // 移除子元素
  279. delete obj.children;
  280. rt.push(obj);
  281. }
  282. });
  283. this._hide();
  284. this.$emit("selectDengjiyuan", [...rt], this.fartherKey);
  285. },
  286. //扁平化树结构
  287. getSearchObj(item) {
  288. if (item.children && item.children.length) {
  289. item.children.forEach((child) => {
  290. if (child.name === this.searchname) {
  291. return true;
  292. }
  293. });
  294. } else if (item.name === this.searchname) {
  295. return true;
  296. } else {
  297. return false;
  298. }
  299. },
  300. _renderTreeList(list = [], rank = 0, parentId = [], parents = []) {
  301. list.forEach((item) => {
  302. this.treeList.push({
  303. id: item[this.idKey],
  304. name: item[this.rangeKey],
  305. source: item,
  306. parentId, // 父级id数组
  307. parents, // 父级id数组
  308. rank, // 层级
  309. showChild: false, //子级是否显示
  310. open: false, //是否打开
  311. show: rank === 0, // 自身是否显示
  312. hideArr: [],
  313. orChecked: item.checked ? item.checked : false,
  314. checked: item.checked ? item.checked : false,
  315. });
  316. if (Array.isArray(item.children) && item.children.length > 0) {
  317. let parentid = [...parentId],
  318. parentArr = [...parents],
  319. childrenid = [...childrenid];
  320. delete parentArr.children;
  321. parentid.push(item[this.idKey]);
  322. parentArr.push({
  323. [this.idKey]: item[this.idKey],
  324. [this.rangeKey]: item[this.rangeKey],
  325. });
  326. this._renderTreeList(item.children, rank + 1, parentid, parentArr);
  327. } else {
  328. this.treeList[this.treeList.length - 1].lastRank = true;
  329. }
  330. });
  331. },
  332. // 处理默认选择
  333. _defaultSelect() {
  334. let default_value = this.default_value;
  335. this.treeList.forEach((v, i) => {
  336. for (let j = 0; j < default_value; j++) {
  337. if (v.parentId.toString().indexOf(v2.parentId.toString()) >= 0) {
  338. }
  339. }
  340. // if (v.checked) {
  341. // this.treeList.forEach((v2, i2) => {
  342. // if (v.parentId.toString().indexOf(v2.parentId.toString()) >= 0) {
  343. // console.log(v2,v.parentId.toString().indexOf(v2.parentId.toString()));
  344. // v2.show = true
  345. // // if(v2.rank>0){
  346. // // v2.show=false
  347. // // }
  348. // if (v.parentId.includes(v2.id)) {
  349. // v2.showChild = true;
  350. // v2.open = true;
  351. // }
  352. // }
  353. // })
  354. // }
  355. });
  356. },
  357. // 点击
  358. _treeItemTap(item, index) {
  359. if (item.lastRank === true) {
  360. //点击最后一级时触发事件
  361. this.treeList[index].checked = !this.treeList[index].checked;
  362. this._fixMultiple(index);
  363. return;
  364. }
  365. let list = this.treeList;
  366. let id = item.id;
  367. item.showChild = !item.showChild;
  368. item.open = item.showChild ? true : !item.open;
  369. list.forEach((childItem, i) => {
  370. if (item.showChild === false) {
  371. //隐藏所有子级
  372. if (!childItem.parentId.includes(id)) {
  373. return;
  374. }
  375. if (!this.foldAll) {
  376. if (childItem.lastRank !== true && !childItem.open) {
  377. childItem.showChild = false;
  378. }
  379. // 为隐藏的内容添加一个标记
  380. if (childItem.show) {
  381. childItem.hideArr[item.rank] = id;
  382. }
  383. } else {
  384. if (childItem.lastRank !== true) {
  385. childItem.showChild = false;
  386. }
  387. }
  388. childItem.show = false;
  389. } else {
  390. // 打开子集
  391. if (childItem.parentId[childItem.parentId.length - 1] === id) {
  392. childItem.show = true;
  393. }
  394. // 打开被隐藏的子集
  395. if (childItem.parentId.includes(id) && !this.foldAll) {
  396. if (childItem.hideArr[item.rank] === id) {
  397. childItem.show = true;
  398. if (childItem.open && childItem.showChild) {
  399. childItem.showChild = true;
  400. } else {
  401. childItem.showChild = false;
  402. }
  403. childItem.hideArr[item.rank] = null;
  404. }
  405. }
  406. }
  407. });
  408. },
  409. _treeItemSelect(item, index) {
  410. this.treeList[index].checked = !this.treeList[index].checked;
  411. this._fixMultiple(index);
  412. // this.$emit('chenge',item,this.treeList[index].checked)
  413. this._chenge(item, this.treeList[index].checked);
  414. },
  415. _treeItemSelect2(item, index) {
  416. this._hide();
  417. this.$emit("selectDengjiyuan", item);
  418. },
  419. _chenge(e, e1) {
  420. if (e.checked == true) {
  421. let isClud = this.selectName.indexOf(e.name);
  422. if (isClud > -1) {
  423. return;
  424. } else {
  425. this.selectName.push(e.name);
  426. }
  427. } else {
  428. let isClud = this.selectName.indexOf(e.name);
  429. if (isClud > -1) {
  430. this.selectName.splice(isClud, 1);
  431. } else {
  432. return;
  433. }
  434. }
  435. this.searchname = "";
  436. this.idArr.push(e.id);
  437. if (e.source.children == undefined) {
  438. this.treeList.forEach((k, i) => {
  439. this.idArr.forEach((k1, i1) => {
  440. if (k.id == k1 && e1 == true) {
  441. this.treeList[i].checked = true;
  442. } else if (k.id == k1 && e1 == false) {
  443. this.treeList[i].checked = false;
  444. }
  445. });
  446. });
  447. if (e.checked) {
  448. e.parentId.forEach((k, i) => {
  449. this.treeList.forEach((k1, i1) => {
  450. if (k1.id == k) {
  451. this.treeList[i1].checked = true;
  452. }
  453. });
  454. });
  455. } else {
  456. e.parentId.forEach((k, i) => {
  457. this.treeList.forEach((k1, i1) => {
  458. if (k1.id == k) {
  459. this.treeList[i1].checked = false;
  460. }
  461. });
  462. });
  463. }
  464. this.treeList.forEach((k1, i1) => {
  465. if (k1.checked) {
  466. k1.parentId.forEach((k2, i2) => {
  467. this.treeList.forEach((k3, i3) => {
  468. if (k3.id == k2) {
  469. this.treeList[i3].checked = true;
  470. }
  471. });
  472. });
  473. }
  474. });
  475. this.idArr = [];
  476. return;
  477. }
  478. this.handkeCheck1(e.source.children);
  479. this.treeList.forEach((k, i) => {
  480. this.idArr.forEach((k1, i1) => {
  481. if (k.id == k1 && e1 == true) {
  482. this.treeList[i].checked = true;
  483. } else if (k.id == k1 && e1 == false) {
  484. this.treeList[i].checked = false;
  485. }
  486. });
  487. });
  488. if (e.checked) {
  489. e.parentId.forEach((k, i) => {
  490. this.treeList.forEach((k1, i1) => {
  491. if (k1.id == k) {
  492. this.treeList[i1].checked = true;
  493. }
  494. });
  495. });
  496. } else {
  497. e.parentId.forEach((k, i) => {
  498. this.treeList.forEach((k1, i1) => {
  499. if (k1.id == k) {
  500. this.treeList[i1].checked = false;
  501. }
  502. });
  503. });
  504. }
  505. this.treeList.forEach((k1, i1) => {
  506. if (k1.checked) {
  507. k1.parentId.forEach((k2, i2) => {
  508. this.treeList.forEach((k3, i3) => {
  509. if (k3.id == k2) {
  510. this.treeList[i3].checked = true;
  511. }
  512. });
  513. });
  514. }
  515. });
  516. this.idArr = [];
  517. // this.handkeCheck(this.range, e, e1)
  518. },
  519. handkeCheck1(list) {
  520. list.forEach((k, i) => {
  521. this.idArr.push(k.id);
  522. if (k.children == undefined) return;
  523. this.handkeCheck1(k.children);
  524. });
  525. },
  526. handkeCheck(list, e, e1) {
  527. // 点击数据权限
  528. list.forEach((k, i) => {
  529. if (k.children != undefined) {
  530. if (k.id == e.id && e.checked == true) {
  531. k.checked = true;
  532. this.handkeChecks(k.children, e, e1);
  533. } else if (k.id == e.id && e.checked == false) {
  534. k.checked = false;
  535. this.handkeChecks(k.children, e, e1);
  536. } else {
  537. this.handkeCheck(k.children, e, e1);
  538. }
  539. } else {
  540. // console.log(1);
  541. if (k.id == e.id && e.checked == true) {
  542. k.checked = true;
  543. } else if (k.id == e.id && e.checked == false) {
  544. k.checked = false;
  545. }
  546. }
  547. });
  548. // console.log(this.treeList);
  549. // this._reTreeList()
  550. // this._initTree(list)
  551. // this._renderTreeList(list)
  552. // list.splice()
  553. // this.lists = list
  554. // this.$forceUpdate()
  555. // console.log(this.lists,'执行了强制刷新');
  556. },
  557. handkeChecks(list, e, e1) {
  558. // console.log(list, e, e1,'循环执行');
  559. // console.log(list,'list','循环执行');
  560. // console.log(e.id,'e','循环执行');
  561. // console.log(e1,'e1','循环执行');
  562. list.forEach((k, i) => {
  563. if (k.children != undefined) {
  564. if (e.checked) {
  565. k.checked = true;
  566. this.handkeChecks(k.children, e, e1);
  567. } else {
  568. k.checked = false;
  569. this.handkeChecks(k.children, e, e1);
  570. }
  571. } else {
  572. // console.log(k, 'else');
  573. if (e.checked) {
  574. k.checked = true;
  575. } else {
  576. k.checked = false;
  577. }
  578. }
  579. });
  580. },
  581. // 处理单选多选
  582. _fixMultiple(index) {
  583. // console.log(index,'33333');
  584. if (this.spread) {
  585. // 如果是单选
  586. this.treeList.forEach((v, i) => {
  587. if (i != index) {
  588. this.treeList[i].checked = false;
  589. } else {
  590. this.treeList[i].checked = true;
  591. // console.log(index,'4444');
  592. }
  593. });
  594. }
  595. },
  596. // 重置数据
  597. _reTreeList() {
  598. this.treeList.forEach((v, i) => {
  599. this.treeList[i].checked = v.orChecked;
  600. });
  601. },
  602. _initTree(range = this.range) {
  603. // console.log('接收值的事件');
  604. this.treeList = [];
  605. this._renderTreeList(range);
  606. this.$nextTick(() => {
  607. // this._defaultSelect(range)
  608. });
  609. let list = this.treeList;
  610. //展开第一列
  611. if (this.custom) {
  612. list.forEach((childItem, i) => {
  613. console.log("child", childItem);
  614. if (childItem.rank == "1") {
  615. childItem.show = true;
  616. }
  617. });
  618. }
  619. },
  620. },
  621. watch: {
  622. range(list) {
  623. // console.log('监视值的改变1');
  624. this._initTree(list);
  625. },
  626. multiple() {
  627. // console.log('监视值的改变2');
  628. if (this.range.length) {
  629. this._reTreeList();
  630. }
  631. },
  632. selectParent() {
  633. // console.log('监视值的改变3');
  634. if (this.range.length) {
  635. this._reTreeList();
  636. }
  637. },
  638. searchname() {
  639. this.getList();
  640. },
  641. deep: true, // 深度监听
  642. immediate: true, // 初次监听即执行
  643. },
  644. mounted() {
  645. this._initTree();
  646. uni.$on("sendMsg", (data) => {
  647. this.getMsg = data.msg;
  648. });
  649. },
  650. };
  651. </script>
  652. <style scoped>
  653. @import "./style.css";
  654. .searchname {
  655. margin: 0;
  656. width: 80%;
  657. float: left;
  658. }
  659. .clear {
  660. width: 20%;
  661. float: left;
  662. }
  663. </style>