| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <template>
- <div class="tree" style="width: 100%;height:100%;">
- <div class="left_tree_title" style="text-indent: 10px;width: 100%;display: flex;align-items: center;height:50px;">
- <span style="width: 50px">年度</span>
- <el-select v-model="year" placeholder="请选择">
- <el-option
- v-for="item in yearList"
- :key="item.id"
- :label="item.year"
- :value="item.year">
- </el-option>
- </el-select>
- </div>
- <el-tree
- class="el-treeWhite"
- :data="treeData"
- :props="treeProps"
- :expand-on-click-node="false"
- @node-click="nodeClick"
- node-key="id"
- :default-expanded-keys="tableDefaultExpandedKeys"
- style="width:100%;height:calc(100% - 60px);overflow:auto;"
- />
- </div>
- </template>
- <script>
- import {getNodeByPidAndCode} from "../../api/duChaAPI.js";
- import request from "../../utils/gw_ajax_request.js";
- import {dateFormat} from "../../utils/gw_date";
- import {getTrees} from "@util/gw_formatTree.js";
- import globalVariable from "@api/globalVariable.js";
- import {getYearList} from "@api/jcOneMapApi";
- export default {
- components: {},
- // props: ['pid','type','pidNodes','level','height','width','fsType'],
- props: {
- pid: {},
- type: {},
- pidNodes: {},
- level: {},
- height: {},
- width: {},
- fsType: {
- default: "ry"
- }
- },
- data() {
- return {
- treeData: [],
- code: "45",
- tableDefaultExpandedKeys: ["001", "002", "003", "006"],
- treeProps: {
- label: "pnm",
- children: "children",
- disabled: false,
- expandOnClickNode: false,
- first: true
- },
- checkedData: [],
- changedData: [],
- yearList: [],
- year: ""
- };
- },
- mounted: function () {
- if (this.width == undefined) {
- this.width = "250";
- }
- if (this.height == undefined) {
- this.height = "550";
- }
- this.getLeftTreeData();
- this.getYearlists();
- },
- computed: {
- userId: function () {
- return localStorage.getItem("userid")
- ? localStorage.getItem("userid")
- : "1098101939614724096";
- }
- },
- methods: {
- getYearlists() {
- getYearList().then(res => {
- this.yearList = res.data;
- let lastItemIndex = this.yearList.length - 1;
- this.year = this.yearList[lastItemIndex].year;
- });
- },
- // 节点点击事件
- nodeClick: function (data, node) {
- this.$emit("provTreeSelectChange", {
- id: data.id,
- pid: data.pid,
- year: this.year,
- ppid: node.parent.data.pid,
- pnm: data.pnm
- });
- },
- //根据用户id获取左侧树
- getLeftTreeData() {
- var _self = this;
- let url = "/dc/gd/base/getRyNode";
- if (this.fsType == "szy") {
- url = "/dc/gd/base/getSzyNodeProvincial";
- } else if (this.fsType == "noGroup") {
- url = "/dc/gd/base/getNodeProvincialExceptGroup";
- }
- let params = null;
- // if (_self.fsType == 'szy') {
- params = {
- userId: this.userId,
- orgType: this.type,
- level: this.level,
- year: this.year
- };
- // } else {
- // params = {
- // 'userId': this.userId,
- // 'orgType': this.type,
- // 'level': this.level,
- // }
- // }
- request.get(url, {params: params}).then(res => {
- let data = res.data;
- data.forEach(ele => {
- if (ele.pid == null || ele.pid == "") {
- ele.pid = "001";
- }
- if (ele.sttm == null || ele.sttm == "") {
- ele.sttm = "";
- } else {
- ele.sttm = dateFormat(ele.sttm, "yy-MM-dd");
- }
- if (ele.entm == null || ele.entm == "") {
- ele.entm = "";
- } else {
- ele.entm = dateFormat(ele.entm, "yy-MM-dd");
- }
- });
- //
- if (data != null && data.length > 0) {
- data = getTrees(data, data[0].pid);
- _self.treeData = data;
- }
- // 获取第一个节点给子页面带过去
- this.getFirstNode(data);
- });
- },
- getFirstNode(data) {
- let node = "";
- try {
- if (data != null && data != "") {
- if (data[0].id.length == 6) {
- node = data[0].id;
- } else if (data[0].id.length == 3) {
- node = data[0].children[0].id;
- }
- }
- } catch (e) {
- }
- globalVariable.setFirstNode(node);
- }
- },
- watch: {
- year(val) {
- if (val) {
- this.getLeftTreeData();
- this.$emit("changeYear", val);
- }
- },
- type(val) {
- this.getLeftTreeData();
- this.$emit("changeYear", val);
- }
- }
- };
- </script>
- <style scoped>
- </style>
|