index.vue 22 KB

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