02df2b678b312d91b88fbec85279ff810c9fffee.svn-base 4.9 KB

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