home.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. toastr.options = {
  2. "closeButton": true,
  3. "positionClass": "toast-top-center",
  4. "preventDuplicates": true
  5. }
  6. new Vue({
  7. el: '#main',
  8. data: {
  9. jsonUrl:"../../../dataJson/jumingHealthJson/高血压人群.json",
  10. jsonData:null,
  11. city:'贵港市',
  12. town:[
  13. {
  14. "townName": "贵港市",
  15. "result": "0"
  16. },
  17. {
  18. "townName": "港北区",
  19. "result": "26531"
  20. },
  21. {
  22. "townName": "港南区",
  23. "result": "25634"
  24. },
  25. {
  26. "townName": "桂平市",
  27. "result": "113485"
  28. },
  29. {
  30. "townName": "平南县",
  31. "result": "74128"
  32. },
  33. {
  34. "townName": "覃塘区",
  35. "result": "12587"
  36. },
  37. ],
  38. mapData:null,
  39. skipShow:0,
  40. lineHeightIndex:null,
  41. },
  42. mounted: function() {
  43. this.bindEvents();
  44. this.getJsonData();
  45. },
  46. methods: {
  47. getJsonData:function(){
  48. var vm = this;
  49. bigDataAPI.getJsonData(this.jsonUrl).then(function(res){
  50. vm.jsonData = res;
  51. var options = _.map(res.town,function(item,idx){
  52. var it = {name:item.townName,value:item.result}
  53. return it;
  54. })
  55. vm.mapData ={data:options,zoom:1,index:vm.lineHeightIndex};
  56. })
  57. },
  58. bindEvents:function(){
  59. var vm = this;
  60. EventBus.$on("refresh-json-data", function(arg) {
  61. var type = arg.type;//0:高血压 1糖尿病 2孕产妇 365岁以上老年人人数
  62. if(type==0){
  63. vm.jsonUrl = "../../../dataJson/jumingHealthJson/高血压人群.json";
  64. }else if(type==1){
  65. vm.jsonUrl = "../../../dataJson/jumingHealthJson/糖尿病人群.json";
  66. }else if(type==2){
  67. vm.jsonUrl = "../../../dataJson/jumingHealthJson/孕产妇人群.json";
  68. }else if(type==3){
  69. vm.jsonUrl = "../../../dataJson/jumingHealthJson/65岁以上老年人人数.json";
  70. }
  71. vm.getJsonData();
  72. });
  73. },
  74. setCity(item){
  75. this.city = item.townName;
  76. },
  77. clickMap:function(res){
  78. this.city = res.name;
  79. },
  80. refreshAllData:function(cityVal){
  81. var vm = this;
  82. cityVal = parseInt(cityVal)
  83. switch(cityVal){
  84. case 0: vm.jsonUrl = "../../../dataJson/jumingHealthJson/高血压人群.json"; break;//贵港市
  85. case 26531: vm.jsonUrl = "../../../dataJson/jumingHealthJson/港北区.json"; break;//港北区
  86. case 25634: vm.jsonUrl = "../../../dataJson/jumingHealthJson/港南区.json";break;//港南区
  87. case 113485: vm.jsonUrl = "../../../dataJson/jumingHealthJson/桂平市.json"; break;//桂平市
  88. case 74128: vm.jsonUrl = "../../../dataJson/jumingHealthJson/平南县.json"; break;//平南县
  89. case 12587:vm.jsonUrl = "../../../dataJson/jumingHealthJson/覃塘区.json"; break;//覃塘区
  90. default:break;
  91. }
  92. vm.getJsonData();
  93. },
  94. skipClick:function(){
  95. console.log(222)
  96. this.skipShow == 0 ? this.skipShow = 1 : this.skipShow = 0
  97. }
  98. },
  99. watch:{
  100. jsonData:function(data){
  101. this.jsonData = data;
  102. },
  103. city:function(value){
  104. var that =this;
  105. that.lineHeightIndex =value;
  106. // debugger
  107. this.town.map(function(v,i){
  108. if(v.townName == value) {
  109. that.refreshAllData(v.result);
  110. }
  111. })
  112. }
  113. }
  114. });
  115. //数字格式化
  116. function toThousands(str) {
  117. if(!str)return
  118. str =parseInt(str);
  119. if(typeof(str) == 'number')str = str.toString()
  120. var newStr = "";
  121. var count = 0;
  122. if(str.indexOf(".") == -1) {
  123. for(var i = str.length - 1; i >= 0; i--) {
  124. if(count % 3 == 0 && count != 0) {
  125. newStr = str.charAt(i) + "," + newStr;
  126. } else {
  127. newStr = str.charAt(i) + newStr;
  128. }
  129. count++;
  130. }
  131. str = newStr;
  132. } else {
  133. for(var i = str.indexOf(".") - 1; i >= 0; i--) {
  134. if(count % 3 == 0 && count != 0) {
  135. newStr = str.charAt(i) + "," + newStr;
  136. } else {
  137. newStr = str.charAt(i) + newStr; //逐个字符相接起来
  138. }
  139. count++;
  140. }
  141. str = newStr + (str + "00").substr((str + "00").indexOf("."), 3);
  142. }
  143. return str;
  144. }