tkitree.vue 22 KB

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