f1607d4788c7e3a1ca98adf3f3a6f54060b434cd.svn-base 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div>
  3. <div class="left_tree_title">年度:
  4. <el-select v-model="year" placeholder="请选择">
  5. <el-option
  6. v-for="item in yearList"
  7. :key="item.id"
  8. :label="item.year"
  9. :value="item.year">
  10. </el-option>
  11. </el-select>
  12. </div>
  13. <el-tree
  14. class="el-treeWhite"
  15. :data="treeData"
  16. :props="treeProps"
  17. :expand-on-click-node="false"
  18. @node-click="nodeClick"
  19. node-key="id"
  20. :default-expanded-keys="tableDefaultExpandedKeys"
  21. style="max-height:100%;overflow:auto;"
  22. ></el-tree>
  23. </div>
  24. </template>
  25. <script>
  26. import {getNodeByPidAndCode} from "../../api/duChaAPI.js";
  27. import request from '../../utils/gw_ajax_request.js';
  28. import {dateFormat} from "../../utils/gw_date";
  29. import globalVariable from "@api/globalVariable.js";
  30. import {getYearList} from '@api/jcOneMapApi'
  31. export default {
  32. components: {},
  33. props: ['pid', 'type', 'pidNodes'],
  34. data() {
  35. return {
  36. treeData: [],
  37. code: '45',
  38. tableDefaultExpandedKeys: ['001', '002', '003', '006'],
  39. treeProps: {
  40. label: "pnm",
  41. children: "children",
  42. disabled: false,
  43. expandOnClickNode: false,
  44. first: true,
  45. },
  46. checkedData: [],
  47. changedData: [],
  48. yearList: [],
  49. year: ''
  50. };
  51. },
  52. mounted: function () {
  53. this.getYearlists();
  54. // this.getLeftTreeData();
  55. },
  56. computed: {
  57. userId: function () {
  58. return localStorage.getItem("userid")
  59. ? localStorage.getItem("userid")
  60. : "1098101939614724096";
  61. }
  62. },
  63. methods: {
  64. getYearlists() {
  65. getYearList().then(res => {
  66. this.yearList = res.data;
  67. let lastItemIndex = this.yearList.length - 1
  68. this.year = this.yearList[lastItemIndex].year
  69. })
  70. },
  71. // 节点点击事件
  72. nodeClick: function (data) {
  73. // alert(data.id);
  74. this.$emit("provTreeSelectChange", {'id': data.id});
  75. },
  76. //根据用户id获取左侧树
  77. getLeftTreeData() {
  78. var _self = this;
  79. request.get('/dc/gd/base/getLyNode', {
  80. params: {
  81. 'userId': this.userId,
  82. 'orgType': this.type,
  83. 'year': this.year
  84. }
  85. }).then((res) => {
  86. let data = res.data
  87. data.forEach(ele => {
  88. if (ele.pid == null || ele.pid == '') {
  89. ele.pid = '001'
  90. }
  91. if (ele.sttm == null || ele.sttm == '') {
  92. ele.sttm = ''
  93. } else {
  94. ele.sttm = dateFormat(ele.sttm, 'yy-MM-dd');
  95. }
  96. if (ele.entm == null || ele.entm == '') {
  97. ele.entm = ''
  98. } else {
  99. ele.entm = dateFormat(ele.entm, 'yy-MM-dd');
  100. }
  101. });
  102. if (data != null && data.length > 0) {
  103. data = _self.getTrees(data, data[0].pid)
  104. _self.treeData = data;
  105. }
  106. // 获取第一个节点给子页面带过去
  107. this.getFirstNode(data);
  108. })
  109. },
  110. //格式化树形数据
  111. getTrees(list, pId) {
  112. let items = {};
  113. // 获取每个节点的直属子节点,*记住是直属,不是所有子节点
  114. for (let i = 0; i < list.length; i++) {
  115. let key = list[i].parentId ? list[i].parentId : list[i].pid;
  116. if (items[key]) {
  117. items[key].push(list[i]);
  118. } else {
  119. items[key] = [];
  120. items[key].push(list[i]);
  121. }
  122. }
  123. return this.formatTree(items, pId);
  124. },
  125. /**利用递归格式化每个节点**/
  126. formatTree(items, pId) {
  127. let result = [];
  128. if (!items[pId]) {
  129. return result;
  130. }
  131. for (let t of items[pId]) {
  132. t.children = this.formatTree(items, t.id)
  133. result.push(t);
  134. }
  135. return result;
  136. },
  137. getFirstNode(data) {
  138. let node = '';
  139. try {
  140. if (data != null && data != '') {
  141. if (data[0].id.length == 6) {
  142. node = data[0].id;
  143. } else if (data[0].id.length == 3) {
  144. node = data[0].children[0].id;
  145. }
  146. }
  147. } catch (e) {
  148. }
  149. globalVariable.setFirstNode(node);
  150. },
  151. },
  152. watch: {
  153. year(val) {
  154. if (val) {
  155. this.getLeftTreeData();
  156. this.$emit('changeYear', val);
  157. }
  158. }
  159. }
  160. };
  161. </script>
  162. <style scoped>
  163. </style>