tkitree.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <template xlang="wxml">
  2. <view class="tkitree" v-if="showTree">
  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. 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 { getSelectUserTwo } 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 getSelectUserTwo(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() {
  263. console.log(123123);
  264. try {
  265. this.showTree = true;
  266. this.fartherKey = e;
  267. } catch (e) {
  268. console.log(e);
  269. }
  270. },
  271. _hide() {
  272. this.showTree = false;
  273. },
  274. _cancel() {
  275. this._hide();
  276. this.$emit("cancel", "");
  277. },
  278. _confirm() {
  279. // 处理所选数据
  280. let rt = [],
  281. obj = {};
  282. this.treeList.forEach((v, i) => {
  283. if (this.treeList[i].checked) {
  284. obj = {};
  285. obj.parents = this.treeList[i].parents;
  286. obj = Object.assign(obj, this.treeList[i].source);
  287. // 移除子元素
  288. delete obj.children;
  289. rt.push(obj);
  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. // 处理默认选择
  342. _defaultSelect() {
  343. let default_value = this.default_value;
  344. this.treeList.forEach((v, i) => {
  345. for (let j = 0; j < default_value; j++) {
  346. if (v.parentId.toString().indexOf(v2.parentId.toString()) >= 0) {
  347. }
  348. }
  349. // if (v.checked) {
  350. // this.treeList.forEach((v2, i2) => {
  351. // if (v.parentId.toString().indexOf(v2.parentId.toString()) >= 0) {
  352. // console.log(v2,v.parentId.toString().indexOf(v2.parentId.toString()));
  353. // v2.show = true
  354. // // if(v2.rank>0){
  355. // // v2.show=false
  356. // // }
  357. // if (v.parentId.includes(v2.id)) {
  358. // v2.showChild = true;
  359. // v2.open = true;
  360. // }
  361. // }
  362. // })
  363. // }
  364. });
  365. },
  366. // 点击
  367. _treeItemTap(item, index) {
  368. if (item.lastRank === true) {
  369. //点击最后一级时触发事件
  370. this.treeList[index].checked = !this.treeList[index].checked;
  371. this._fixMultiple(index);
  372. return;
  373. }
  374. let list = this.treeList;
  375. let id = item.id;
  376. item.showChild = !item.showChild;
  377. item.open = item.showChild ? true : !item.open;
  378. list.forEach((childItem, i) => {
  379. if (item.showChild === false) {
  380. //隐藏所有子级
  381. if (!childItem.parentId.includes(id)) {
  382. return;
  383. }
  384. if (!this.foldAll) {
  385. if (childItem.lastRank !== true && !childItem.open) {
  386. childItem.showChild = false;
  387. }
  388. // 为隐藏的内容添加一个标记
  389. if (childItem.show) {
  390. childItem.hideArr[item.rank] = id;
  391. }
  392. } else {
  393. if (childItem.lastRank !== true) {
  394. childItem.showChild = false;
  395. }
  396. }
  397. childItem.show = false;
  398. } else {
  399. // 打开子集
  400. if (childItem.parentId[childItem.parentId.length - 1] === id) {
  401. childItem.show = true;
  402. }
  403. // 打开被隐藏的子集
  404. if (childItem.parentId.includes(id) && !this.foldAll) {
  405. if (childItem.hideArr[item.rank] === id) {
  406. childItem.show = true;
  407. if (childItem.open && childItem.showChild) {
  408. childItem.showChild = true;
  409. } else {
  410. childItem.showChild = false;
  411. }
  412. childItem.hideArr[item.rank] = null;
  413. }
  414. }
  415. }
  416. });
  417. },
  418. _treeItemSelect(item, index) {
  419. this.treeList[index].checked = !this.treeList[index].checked;
  420. this._fixMultiple(index);
  421. // console.log(item.id, index,this.treeList[index].checked,9);
  422. // this.$emit('chenge',item,this.treeList[index].checked)
  423. this._chenge(item, this.treeList[index].checked);
  424. },
  425. _treeItemSelect2(item, index) {
  426. console.log(item, index, "点击事件1");
  427. this._hide();
  428. this.$emit("confirm", item);
  429. },
  430. _chenge(e, e1) {
  431. if (e.checked == true) {
  432. let isClud = this.selectName.indexOf(e.name);
  433. if (isClud > -1) {
  434. return;
  435. } else {
  436. this.selectName.push(e.name);
  437. }
  438. } else {
  439. let isClud = this.selectName.indexOf(e.name);
  440. if (isClud > -1) {
  441. this.selectName.splice(isClud, 1);
  442. } else {
  443. return;
  444. }
  445. }
  446. this.searchname = "";
  447. this.idArr.push(e.id);
  448. if (e.source.children == undefined) {
  449. this.treeList.forEach((k, i) => {
  450. this.idArr.forEach((k1, i1) => {
  451. if (k.id == k1 && e1 == true) {
  452. this.treeList[i].checked = true;
  453. } else if (k.id == k1 && e1 == false) {
  454. this.treeList[i].checked = false;
  455. }
  456. });
  457. });
  458. if (e.checked) {
  459. e.parentId.forEach((k, i) => {
  460. this.treeList.forEach((k1, i1) => {
  461. if (k1.id == k) {
  462. this.treeList[i1].checked = true;
  463. }
  464. });
  465. });
  466. } else {
  467. e.parentId.forEach((k, i) => {
  468. this.treeList.forEach((k1, i1) => {
  469. if (k1.id == k) {
  470. this.treeList[i1].checked = false;
  471. }
  472. });
  473. });
  474. }
  475. this.treeList.forEach((k1, i1) => {
  476. if (k1.checked) {
  477. k1.parentId.forEach((k2, i2) => {
  478. this.treeList.forEach((k3, i3) => {
  479. if (k3.id == k2) {
  480. this.treeList[i3].checked = true;
  481. }
  482. });
  483. });
  484. }
  485. });
  486. this.idArr = [];
  487. return;
  488. }
  489. this.handkeCheck1(e.source.children);
  490. this.treeList.forEach((k, i) => {
  491. this.idArr.forEach((k1, i1) => {
  492. if (k.id == k1 && e1 == true) {
  493. this.treeList[i].checked = true;
  494. } else if (k.id == k1 && e1 == false) {
  495. this.treeList[i].checked = false;
  496. }
  497. });
  498. });
  499. if (e.checked) {
  500. e.parentId.forEach((k, i) => {
  501. this.treeList.forEach((k1, i1) => {
  502. if (k1.id == k) {
  503. this.treeList[i1].checked = true;
  504. }
  505. });
  506. });
  507. } else {
  508. e.parentId.forEach((k, i) => {
  509. this.treeList.forEach((k1, i1) => {
  510. if (k1.id == k) {
  511. this.treeList[i1].checked = false;
  512. }
  513. });
  514. });
  515. }
  516. this.treeList.forEach((k1, i1) => {
  517. if (k1.checked) {
  518. k1.parentId.forEach((k2, i2) => {
  519. this.treeList.forEach((k3, i3) => {
  520. if (k3.id == k2) {
  521. this.treeList[i3].checked = true;
  522. }
  523. });
  524. });
  525. }
  526. });
  527. this.idArr = [];
  528. // this.handkeCheck(this.range, e, e1)
  529. },
  530. handkeCheck1(list) {
  531. list.forEach((k, i) => {
  532. this.idArr.push(k.id);
  533. if (k.children == undefined) return;
  534. this.handkeCheck1(k.children);
  535. });
  536. },
  537. handkeCheck(list, e, e1) {
  538. // 点击数据权限
  539. list.forEach((k, i) => {
  540. if (k.children != undefined) {
  541. if (k.id == e.id && e.checked == true) {
  542. k.checked = true;
  543. // console.log(k.id,'第一');
  544. this.handkeChecks(k.children, e, e1);
  545. } else if (k.id == e.id && e.checked == false) {
  546. k.checked = false;
  547. this.handkeChecks(k.children, e, e1);
  548. } else {
  549. this.handkeCheck(k.children, e, e1);
  550. }
  551. } else {
  552. // console.log(1);
  553. if (k.id == e.id && e.checked == true) {
  554. k.checked = true;
  555. } else if (k.id == e.id && e.checked == false) {
  556. k.checked = false;
  557. }
  558. }
  559. });
  560. // console.log(this.treeList);
  561. // this._reTreeList()
  562. // this._initTree(list)
  563. // this._renderTreeList(list)
  564. // list.splice()
  565. // this.lists = list
  566. // this.$forceUpdate()
  567. // console.log(this.lists,'执行了强制刷新');
  568. },
  569. handkeChecks(list, e, e1) {
  570. // console.log(list, e, e1,'循环执行');
  571. // console.log(list,'list','循环执行');
  572. // console.log(e.id,'e','循环执行');
  573. // console.log(e1,'e1','循环执行');
  574. list.forEach((k, i) => {
  575. if (k.children != undefined) {
  576. if (e.checked) {
  577. k.checked = true;
  578. this.handkeChecks(k.children, e, e1);
  579. } else {
  580. k.checked = false;
  581. this.handkeChecks(k.children, e, e1);
  582. }
  583. } else {
  584. // console.log(k, 'else');
  585. if (e.checked) {
  586. k.checked = true;
  587. } else {
  588. k.checked = false;
  589. }
  590. }
  591. });
  592. },
  593. // 处理单选多选
  594. _fixMultiple(index) {
  595. // console.log(index,'33333');
  596. if (this.spread) {
  597. // 如果是单选
  598. this.treeList.forEach((v, i) => {
  599. if (i != index) {
  600. this.treeList[i].checked = false;
  601. } else {
  602. this.treeList[i].checked = true;
  603. // console.log(index,'4444');
  604. }
  605. });
  606. }
  607. },
  608. // 重置数据
  609. _reTreeList() {
  610. this.treeList.forEach((v, i) => {
  611. this.treeList[i].checked = v.orChecked;
  612. });
  613. },
  614. _initTree(range = this.range) {
  615. // console.log('接收值的事件');
  616. this.treeList = [];
  617. this._renderTreeList(range);
  618. this.$nextTick(() => {
  619. // this._defaultSelect(range)
  620. });
  621. let list = this.treeList;
  622. //展开第一列
  623. if (this.custom) {
  624. list.forEach((childItem, i) => {
  625. console.log("child", childItem);
  626. if (childItem.rank == "1") {
  627. childItem.show = true;
  628. }
  629. });
  630. }
  631. },
  632. },
  633. watch: {
  634. range(list) {
  635. // console.log('监视值的改变1');
  636. this._initTree(list);
  637. },
  638. multiple() {
  639. // console.log('监视值的改变2');
  640. if (this.range.length) {
  641. this._reTreeList();
  642. }
  643. },
  644. selectParent() {
  645. // console.log('监视值的改变3');
  646. if (this.range.length) {
  647. this._reTreeList();
  648. }
  649. },
  650. // searchname() {
  651. // this.getList();
  652. // },
  653. deep: true, // 深度监听
  654. immediate: true, // 初次监听即执行
  655. },
  656. mounted() {
  657. this._initTree();
  658. uni.$on("sendMsg", (data) => {
  659. this.getMsg = data.msg;
  660. });
  661. },
  662. };
  663. </script>
  664. <style scoped>
  665. @import "./style.css";
  666. .searchname {
  667. margin: 0;
  668. width: 80%;
  669. float: left;
  670. }
  671. .clear {
  672. width: 20%;
  673. float: left;
  674. }
  675. </style>