e29536c695fa0b55c1cc809c7c8b1d08267015bd.svn-base 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <div>
  3. <el-row>
  4. <!-- <el-tree
  5. class="el-treeWhite"
  6. :data="treeNew"
  7. :props="treeProps"
  8. :expand-on-click-node="false"
  9. @node-click="nodeClick"
  10. node-key="code"
  11. :default-expanded-keys="[0,1]"
  12. style="max-height:100%;overflow:auto;"
  13. >
  14. <span class="custom-tree-node" slot-scope="{ node, data }">
  15. <span>{{ data.nm }}</span>
  16. <span
  17. v-if="data.code.length == 2"
  18. style="float:right;color:blue;font-weight:thin"
  19. >({{data.children.length}})</span>
  20. </span>
  21. </el-tree> -->
  22. <el-tree
  23. class="el-treeWhite"
  24. :data="treeData"
  25. :props="treeProps"
  26. :expand-on-click-node="false"
  27. @node-click="nodeClick"
  28. node-key="id"
  29. :default-expanded-keys="tableDefaultExpandedKeys"
  30. style="max-height:100%;overflow:auto;"
  31. >
  32. <span class="custom-tree-node" slot-scope="{ node, data }">
  33. <span>{{ data.nm }}</span>
  34. <span v-if="data.id.length == 2" style="float:right;color:blue;font-weight:thin">
  35. ({{data.children.length}})
  36. </span>
  37. </span>
  38. </el-tree>
  39. </el-row>
  40. </div>
  41. </template>
  42. <script>
  43. import { getDuChaFenGongList } from "../api/duChaTianBao.js";
  44. export default {
  45. components: {},
  46. props: ["rootCode", "rootType"],
  47. data() {
  48. return {
  49. treeData: [],
  50. treeNew: [],
  51. jds: false,
  52. okc: 0,
  53. tot: 150,
  54. bfb: "",
  55. tableDefaultExpandedKeys: [],
  56. treeProps: {
  57. label: "nm",
  58. children: "children",
  59. disabled: false,
  60. expandOnClickNode: false,
  61. first: true
  62. },
  63. staticProvData: {
  64. "11": "北京市",
  65. "12": "天津市",
  66. "13": "河北省",
  67. "14": "山西省",
  68. "15": "内蒙古自治区",
  69. "21": "辽宁省",
  70. "22": "吉林省",
  71. "23": "黑龙江省",
  72. "31": "上海市",
  73. "32": "江苏省",
  74. "33": "浙江省",
  75. "34": "安徽省",
  76. "35": "福建省",
  77. "36": "江西省",
  78. "37": "山东省",
  79. "41": "河南省",
  80. "42": "湖北省",
  81. "43": "湖南省",
  82. "44": "广东省",
  83. "45": "广西壮族自治区",
  84. "46": "海南省",
  85. "50": "重庆市",
  86. "51": "四川省",
  87. "52": "贵州省",
  88. "53": "云南省",
  89. "54": "西藏自治区",
  90. "61": "陕西省",
  91. "62": "甘肃省",
  92. "63": "青海省",
  93. "64": "宁夏回族自治区",
  94. "65": "新疆维吾尔自治区",
  95. "66": "新疆生产建设兵团"
  96. }
  97. };
  98. },
  99. mounted: function() {
  100. this.loadTreeListData();
  101. if (this.isAdmin) {
  102. this.jds = true;
  103. } else {
  104. this.jds = false;
  105. }
  106. // this.bfb = this.okc/this.tot;
  107. },
  108. activated(){
  109. this.loadTreeListData();
  110. },
  111. computed: {
  112. userId: function() {
  113. return localStorage.getItem("userid")
  114. ? localStorage.getItem("userid")
  115. : "1098101939614724096";
  116. },
  117. isAdmin() {
  118. return localStorage.getItem("isAdmin") == 1 ? true : false;
  119. }
  120. },
  121. methods: {
  122. loadTreeListData: function() {
  123. try {
  124. getDuChaFenGongList(this.userId, 100).then(
  125. res => {
  126. let _self = this;
  127. console.log(res);
  128. var children = [];
  129. var tempTreeData = [];
  130. var hasProv = false;
  131. // res.data.forEach((element, index) => {
  132. // tempTreeData.forEach(provNode => {
  133. // if (element.code.startsWith(provNode.code)) {
  134. // provNode["children"].push(element);
  135. // hasProv = true;
  136. // }
  137. // });
  138. // if (!hasProv) {
  139. // let newProvNode = {};
  140. // newProvNode["nm"] =
  141. // _self.staticProvData[element.code.substr(0, 2)];
  142. // newProvNode["code"] = element.code.substr(0, 2);
  143. // newProvNode["children"] = [];
  144. // newProvNode["children"].push(element);
  145. // tempTreeData.push(newProvNode);
  146. // }
  147. // hasProv = false;
  148. // children.push(element);
  149. // });
  150. // console.log(tempTreeData);
  151. // this.treeData = tempTreeData;
  152. // var treeData1 = {};
  153. // treeData1["nm"] = "全部";
  154. // treeData1["code"] = 0;
  155. // // treeData1["children"] = [];
  156. // treeData1["children"]=this.treeData;
  157. // treeData1;
  158. // this.treeNew.push(treeData1);
  159. // for (var i = 0; i < this.treeData.length; i++) {
  160. // this.okc = this.okc + this.treeData[i].children.length;
  161. // }
  162. // this.okc;
  163. // this.$emit("provTreeSelectChange", {
  164. // code: children[0].code,
  165. // name: children[0].nm,
  166. // objCode: children[0].objId
  167. // });
  168. // this.$emit("provTreeSelectChange1", {
  169. // code: "",
  170. // name:treeData1.nm,
  171. // objCode: ""
  172. // });
  173. // this.$emit("LoadingCompleted", { type: false });
  174. let data = res.data
  175. data = _self.getTrees(data, data[0].pid)
  176. _self.treeData = data;
  177. _self.$emit("emitCurrentNodeId",data[0]);
  178. },
  179. err => {}
  180. );
  181. } catch (e) {
  182. this.$message.error("超时");
  183. }
  184. },
  185. //格式化树形数据
  186. getTrees(list, pId) {
  187. let items = {};
  188. // 获取每个节点的直属子节点,*记住是直属,不是所有子节点
  189. for(let i = 0; i < list.length; i++) {
  190. let key = list[i].parentId ? list[i].parentId : list[i].pid;
  191. if(items[key]) {
  192. items[key].push(list[i]);
  193. } else {
  194. items[key] = [];
  195. items[key].push(list[i]);
  196. }
  197. }
  198. return this.formatTree(items, pId);
  199. },
  200. /**利用递归格式化每个节点**/
  201. formatTree(items, pId) {
  202. let result = [];
  203. if(!items[pId]) {
  204. return result;
  205. }
  206. for(let t of items[pId]) {
  207. t.children = this.formatTree(items, t.id)
  208. result.push(t);
  209. }
  210. return result;
  211. },
  212. nodeClick: function(data) {
  213. // alert(data.code+data.name+data.type);
  214. //修改逻辑 如果是行政区划 给两个code 一个完整code 一个likecode 用于like查询 省的就是两位 市县的四位 以此类推
  215. // let likeCode = data.code;
  216. // if (data.type == 2) {
  217. // //行政区
  218. // likeCode = likeCode.endsWith("0000000000")
  219. // ? likeCode.substr(0, likeCode.length - 10)
  220. // : likeCode;
  221. // likeCode = likeCode.endsWith("00000000")
  222. // ? likeCode.substr(0, likeCode.length - 8)
  223. // : likeCode;
  224. // likeCode = likeCode.endsWith("000000")
  225. // ? likeCode.substr(0, likeCode.length - 6)
  226. // : likeCode;
  227. // likeCode = likeCode.endsWith("000")
  228. // ? likeCode.substr(0, likeCode.length - 3)
  229. // : likeCode;
  230. // }
  231. // if (data.code.length > 2) {
  232. // this.$emit("provTreeSelectChange1", {
  233. // name: data.nm,
  234. // objCode: data.objId,
  235. // code:data.code,
  236. // });
  237. // }else{
  238. // this.$emit("provTreeSelectChange1", {
  239. // name: data.nm,
  240. // code:data.code,
  241. // objCode: data.objId,
  242. // });
  243. // }
  244. this.$emit("emitCurrentNodeId",data);
  245. }
  246. }
  247. };
  248. </script>
  249. <style scoped>
  250. </style>