| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <template>
- <el-tree
- class="el-treeWhite"
- :data="treeData"
- :props="treeProps"
- :expand-on-click-node="false"
- @node-click="nodeClick"
- node-key="code"
- :default-expanded-keys="tableDefaultExpandedKeys"
-
- style="max-height:500px;overflow:auto;"
- ></el-tree>
- </template>
- <script>
- import { getVillageList_ny } from "../api/duChaTianBao.js";
- export default {
- components: {},
- props:['rootCode','rootType'],
- data() {
- return {
- treeData: [],
- tableDefaultExpandedKeys: [],
- treeProps: {
- label: "name",
- children: "children",
- disabled: false,
- expandOnClickNode: false ,
- first:true,
- }
- };
- },
- mounted: function() {
-
- this.loadTreeListData();
- },
- watch:{
- rootCode:function(){
- this.loadTreeListData();
- }
- },
- computed: {
- userId: function() {
- return localStorage.getItem("userid")
- ? localStorage.getItem("userid")
- : "1098101939614724096";
- }
- },
- methods: {
- loadTreeListData:function(){
-
- getVillageList_ny(this.rootCode).then((res) =>{
- console.log(res);
- var children = [];
- res.data.list.forEach((element,index)=>{
-
- let childrens = [];
- element.list.forEach((eleChild) =>{
- childrens.push({
- 'name':eleChild.villageName,
- 'code':eleChild.villageCode,
- });
- })
- children.push({
- 'name':element.townName,
- 'code':element.townCode,
- children:childrens
- });
- })
- console.log(children);
- this.treeData = children;
- },(err) =>{});
-
-
- },
- 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;
- }
- this.$emit("provTreeSelectChange", { 'code':data.code, 'name': data.name});
- },
- loadAddvData: function(node, resolve) {
- var _self = this;
-
- try {
- if(this.first){
- this.first = false;
- }else{
- getVillageList_ny(node.data.code,node.data.type).then(
- response => {
- var data = response.data;
- var children = [];
- data.list.forEach((element,index)=>{
-
- children.push(element);
-
- })
- resolve(children);
- },
- response => {}
- );
- }
- } catch (e) {
-
- }
- },
- }
- };
- </script>
- <style scoped>
- </style>
|