home.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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糖尿病
  62. if(type==0){
  63. vm.jsonUrl = "../../../dataJson/jumingHealthJson/高血压人群.json";
  64. }else if(type==1){
  65. vm.jsonUrl = "../../../dataJson/jumingHealthJson/糖尿病人群.json";
  66. }
  67. vm.getJsonData();
  68. });
  69. },
  70. setCity(item){
  71. this.city = item.townName;
  72. },
  73. clickMap:function(res){
  74. this.city = res.name;
  75. },
  76. refreshAllData:function(cityVal){
  77. var vm = this;
  78. cityVal = parseInt(cityVal)
  79. switch(cityVal){
  80. case 0: vm.jsonUrl = "../../../dataJson/jumingHealthJson/高血压人群.json"; break;//贵港市
  81. case 26531: vm.jsonUrl = "../../../dataJson/jumingHealthJson/港北区.json"; break;//港北区
  82. case 25634: vm.jsonUrl = "../../../dataJson/jumingHealthJson/港南区.json";break;//港南区
  83. case 113485: vm.jsonUrl = "../../../dataJson/jumingHealthJson/桂平市.json"; break;//桂平市
  84. case 74128: vm.jsonUrl = "../../../dataJson/jumingHealthJson/平南县.json"; break;//平南县
  85. case 12587:vm.jsonUrl = "../../../dataJson/jumingHealthJson/覃塘区.json"; break;//覃塘区
  86. default:break;
  87. }
  88. vm.getJsonData();
  89. },
  90. skipClick:function(){
  91. console.log(222)
  92. this.skipShow == 0 ? this.skipShow = 1 : this.skipShow = 0
  93. }
  94. },
  95. watch:{
  96. jsonData:function(data){
  97. this.jsonData = data;
  98. },
  99. city:function(value){
  100. var that =this;
  101. that.lineHeightIndex =value;
  102. // debugger
  103. this.town.map(function(v,i){
  104. if(v.townName == value) {
  105. that.refreshAllData(v.result);
  106. }
  107. })
  108. }
  109. }
  110. });
  111. //数字格式化
  112. function toThousands(str) {
  113. if(!str)return
  114. str =parseInt(str);
  115. if(typeof(str) == 'number')str = str.toString()
  116. var newStr = "";
  117. var count = 0;
  118. if(str.indexOf(".") == -1) {
  119. for(var i = str.length - 1; i >= 0; i--) {
  120. if(count % 3 == 0 && count != 0) {
  121. newStr = str.charAt(i) + "," + newStr;
  122. } else {
  123. newStr = str.charAt(i) + newStr;
  124. }
  125. count++;
  126. }
  127. str = newStr;
  128. } else {
  129. for(var i = str.indexOf(".") - 1; i >= 0; i--) {
  130. if(count % 3 == 0 && count != 0) {
  131. newStr = str.charAt(i) + "," + newStr;
  132. } else {
  133. newStr = str.charAt(i) + newStr; //逐个字符相接起来
  134. }
  135. count++;
  136. }
  137. str = newStr + (str + "00").substr((str + "00").indexOf("."), 3);
  138. }
  139. return str;
  140. }