26d9ac838784c6144fbf9c5f52cceef2fe9e20f1.svn-base 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <el-tree
  3. class="el-treeWhite"
  4. :data="treeData"
  5. :props="treeProps"
  6. :expand-on-click-node="false"
  7. @node-click="nodeClick"
  8. node-key="code"
  9. :default-expanded-keys="tableDefaultExpandedKeys"
  10. style="max-height:500px;overflow:auto;"
  11. ></el-tree>
  12. </template>
  13. <script>
  14. import { getVillageList_ny } from "../api/duChaTianBao.js";
  15. export default {
  16. components: {},
  17. props:['rootCode','rootType'],
  18. data() {
  19. return {
  20. treeData: [],
  21. tableDefaultExpandedKeys: [],
  22. treeProps: {
  23. label: "name",
  24. children: "children",
  25. disabled: false,
  26. expandOnClickNode: false ,
  27. first:true,
  28. }
  29. };
  30. },
  31. mounted: function() {
  32. this.loadTreeListData();
  33. },
  34. watch:{
  35. rootCode:function(){
  36. this.loadTreeListData();
  37. }
  38. },
  39. computed: {
  40. userId: function() {
  41. return localStorage.getItem("userid")
  42. ? localStorage.getItem("userid")
  43. : "1098101939614724096";
  44. }
  45. },
  46. methods: {
  47. loadTreeListData:function(){
  48. getVillageList_ny(this.rootCode).then((res) =>{
  49. console.log(res);
  50. var children = [];
  51. res.data.list.forEach((element,index)=>{
  52. let childrens = [];
  53. element.list.forEach((eleChild) =>{
  54. childrens.push({
  55. 'name':eleChild.villageName,
  56. 'code':eleChild.villageCode,
  57. });
  58. })
  59. children.push({
  60. 'name':element.townName,
  61. 'code':element.townCode,
  62. children:childrens
  63. });
  64. })
  65. console.log(children);
  66. this.treeData = children;
  67. },(err) =>{});
  68. },
  69. nodeClick: function(data) {
  70. // alert(data.code+data.name+data.type);
  71. //修改逻辑 如果是行政区划 给两个code 一个完整code 一个likecode 用于like查询 省的就是两位 市县的四位 以此类推
  72. let likeCode = data.code;
  73. if(data.type == 2){ //行政区
  74. likeCode = likeCode.endsWith('0000000000')?likeCode.substr(0,likeCode.length-10):likeCode;
  75. likeCode = likeCode.endsWith('00000000')?likeCode.substr(0,likeCode.length-8):likeCode;
  76. likeCode = likeCode.endsWith('000000')?likeCode.substr(0,likeCode.length-6):likeCode;
  77. likeCode = likeCode.endsWith('000')?likeCode.substr(0,likeCode.length-3):likeCode;
  78. }
  79. this.$emit("provTreeSelectChange", { 'code':data.code, 'name': data.name});
  80. },
  81. loadAddvData: function(node, resolve) {
  82. var _self = this;
  83. try {
  84. if(this.first){
  85. this.first = false;
  86. }else{
  87. getVillageList_ny(node.data.code,node.data.type).then(
  88. response => {
  89. var data = response.data;
  90. var children = [];
  91. data.list.forEach((element,index)=>{
  92. children.push(element);
  93. })
  94. resolve(children);
  95. },
  96. response => {}
  97. );
  98. }
  99. } catch (e) {
  100. }
  101. },
  102. }
  103. };
  104. </script>
  105. <style scoped>
  106. </style>