index.vue 22 KB

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