| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- <template>
- <div>
-
- <el-row>
- <!-- <el-tree
- class="el-treeWhite"
- :data="treeNew"
- :props="treeProps"
- :expand-on-click-node="false"
- @node-click="nodeClick"
- node-key="code"
- :default-expanded-keys="[0,1]"
- style="max-height:100%;overflow:auto;"
- >
- <span class="custom-tree-node" slot-scope="{ node, data }">
- <span>{{ data.nm }}</span>
- <span
- v-if="data.code.length == 2"
- style="float:right;color:blue;font-weight:thin"
- >({{data.children.length}})</span>
- </span>
- </el-tree> -->
- <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="max-height:100%;overflow:auto;"
- >
- <span class="custom-tree-node" slot-scope="{ node, data }">
- <span>{{ data.nm }}</span>
- <span v-if="data.id.length == 2" style="float:right;color:blue;font-weight:thin">
- ({{data.children.length}})
- </span>
- </span>
- </el-tree>
- </el-row>
- </div>
- </template>
- <script>
- import { getDuChaFenGongList } from "../api/duChaTianBao.js";
- export default {
- components: {},
- props: ["rootCode", "rootType"],
- data() {
- return {
- treeData: [],
- treeNew: [],
- jds: false,
- okc: 0,
- tot: 150,
- bfb: "",
- tableDefaultExpandedKeys: [],
- treeProps: {
- label: "nm",
- children: "children",
- disabled: false,
- expandOnClickNode: false,
- first: true
- },
- staticProvData: {
- "11": "北京市",
- "12": "天津市",
- "13": "河北省",
- "14": "山西省",
- "15": "内蒙古自治区",
- "21": "辽宁省",
- "22": "吉林省",
- "23": "黑龙江省",
- "31": "上海市",
- "32": "江苏省",
- "33": "浙江省",
- "34": "安徽省",
- "35": "福建省",
- "36": "江西省",
- "37": "山东省",
- "41": "河南省",
- "42": "湖北省",
- "43": "湖南省",
- "44": "广东省",
- "45": "广西壮族自治区",
- "46": "海南省",
- "50": "重庆市",
- "51": "四川省",
- "52": "贵州省",
- "53": "云南省",
- "54": "西藏自治区",
- "61": "陕西省",
- "62": "甘肃省",
- "63": "青海省",
- "64": "宁夏回族自治区",
- "65": "新疆维吾尔自治区",
- "66": "新疆生产建设兵团"
- }
- };
- },
- mounted: function() {
- this.loadTreeListData();
- if (this.isAdmin) {
- this.jds = true;
- } else {
- this.jds = false;
- }
- // this.bfb = this.okc/this.tot;
- },
- activated(){
- this.loadTreeListData();
- },
- computed: {
- userId: function() {
- return localStorage.getItem("userid")
- ? localStorage.getItem("userid")
- : "1098101939614724096";
- },
- isAdmin() {
- return localStorage.getItem("isAdmin") == 1 ? true : false;
- }
- },
- methods: {
- loadTreeListData: function() {
- try {
- getDuChaFenGongList(this.userId, 100).then(
- res => {
- let _self = this;
- console.log(res);
- var children = [];
- var tempTreeData = [];
- var hasProv = false;
- // res.data.forEach((element, index) => {
- // tempTreeData.forEach(provNode => {
- // if (element.code.startsWith(provNode.code)) {
- // provNode["children"].push(element);
- // hasProv = true;
- // }
- // });
- // if (!hasProv) {
- // let newProvNode = {};
- // newProvNode["nm"] =
- // _self.staticProvData[element.code.substr(0, 2)];
- // newProvNode["code"] = element.code.substr(0, 2);
- // newProvNode["children"] = [];
- // newProvNode["children"].push(element);
- // tempTreeData.push(newProvNode);
- // }
- // hasProv = false;
- // children.push(element);
- // });
- // console.log(tempTreeData);
- // this.treeData = tempTreeData;
- // var treeData1 = {};
- // treeData1["nm"] = "全部";
- // treeData1["code"] = 0;
- // // treeData1["children"] = [];
- // treeData1["children"]=this.treeData;
- // treeData1;
- // this.treeNew.push(treeData1);
- // for (var i = 0; i < this.treeData.length; i++) {
- // this.okc = this.okc + this.treeData[i].children.length;
- // }
- // this.okc;
- // this.$emit("provTreeSelectChange", {
- // code: children[0].code,
- // name: children[0].nm,
- // objCode: children[0].objId
- // });
- // this.$emit("provTreeSelectChange1", {
- // code: "",
- // name:treeData1.nm,
- // objCode: ""
- // });
- // this.$emit("LoadingCompleted", { type: false });
- let data = res.data
- data = _self.getTrees(data, data[0].pid)
- _self.treeData = data;
- _self.$emit("emitCurrentNodeId",data[0]);
- },
- err => {}
- );
- } catch (e) {
- this.$message.error("超时");
- }
- },
- //格式化树形数据
- getTrees(list, pId) {
- let items = {};
- // 获取每个节点的直属子节点,*记住是直属,不是所有子节点
- for(let i = 0; i < list.length; i++) {
- let key = list[i].parentId ? list[i].parentId : list[i].pid;
- if(items[key]) {
- items[key].push(list[i]);
- } else {
- items[key] = [];
- items[key].push(list[i]);
- }
- }
- return this.formatTree(items, pId);
- },
- /**利用递归格式化每个节点**/
- formatTree(items, pId) {
- let result = [];
- if(!items[pId]) {
- return result;
- }
- for(let t of items[pId]) {
- t.children = this.formatTree(items, t.id)
- result.push(t);
- }
- return result;
- },
- nodeClick: function(data) {
- // alert(data.code+data.name+data.type);
- //修改逻辑 如果是行政区划 给两个code 一个完整code 一个likecode 用于like查询 省的就是两位 市县的四位 以此类推
- // let likeCode = data.code;
- // if (data.type == 2) {
- // //行政区
- // likeCode = likeCode.endsWith("0000000000")
- // ? likeCode.substr(0, likeCode.length - 10)
- // : likeCode;
- // likeCode = likeCode.endsWith("00000000")
- // ? likeCode.substr(0, likeCode.length - 8)
- // : likeCode;
- // likeCode = likeCode.endsWith("000000")
- // ? likeCode.substr(0, likeCode.length - 6)
- // : likeCode;
- // likeCode = likeCode.endsWith("000")
- // ? likeCode.substr(0, likeCode.length - 3)
- // : likeCode;
- // }
- // if (data.code.length > 2) {
- // this.$emit("provTreeSelectChange1", {
- // name: data.nm,
- // objCode: data.objId,
- // code:data.code,
- // });
- // }else{
- // this.$emit("provTreeSelectChange1", {
- // name: data.nm,
- // code:data.code,
- // objCode: data.objId,
- // });
- // }
- this.$emit("emitCurrentNodeId",data);
- }
- }
- };
- </script>
- <style scoped>
- </style>
|