home.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. },
  40. mounted: function() {
  41. this.bindEvents();
  42. this.getJsonData();
  43. },
  44. methods: {
  45. getJsonData:function(){
  46. var vm = this;
  47. bigDataAPI.getJsonData(this.jsonUrl).then(function(res){
  48. vm.jsonData = res;
  49. var options = _.map(res.town,function(item,idx){
  50. var it = {name:item.townName,value:item.result}
  51. return it;
  52. })
  53. vm.mapData ={data:options,zoom:1};
  54. })
  55. },
  56. bindEvents:function(){
  57. var vm = this;
  58. EventBus.$on("refresh-json-data", function(arg) {
  59. var type = arg.type;//0:高血压 1糖尿病
  60. if(type==0){
  61. vm.jsonUrl = "../../../dataJson/jumingHealthJson/高血压人群.json";
  62. }else if(type==1){
  63. vm.jsonUrl = "../../../dataJson/jumingHealthJson/糖尿病人群.json";
  64. }
  65. vm.getJsonData();
  66. });
  67. },
  68. setCity(item){
  69. this.city = item.townName;
  70. var that =this;
  71. this.town.map(function(v,i){
  72. if(v.townName == item.townName) {
  73. that.$refs.map.selectLineHeight(i) //高亮地图
  74. }
  75. })
  76. },
  77. clickMap:function(res){
  78. var vm = this;
  79. this.city = res.name;
  80. switch(res.value){
  81. case "0": vm.jsonUrl = "../../../dataJson/jumingHealthJson/高血压人群.json"; break;//贵港市
  82. case "26531": vm.jsonUrl = "../../../dataJson/jumingHealthJson/港北区.json"; break;//港北区
  83. case "25634": vm.jsonUrl = "../../../dataJson/jumingHealthJson/港南区.json";break;//港南区
  84. case "113485": vm.jsonUrl = "../../../dataJson/jumingHealthJson/桂平市.json"; break;//桂平市
  85. case "74128": vm.jsonUrl = "../../../dataJson/jumingHealthJson/平南县.json"; break;//平南县
  86. case "12587":vm.jsonUrl = "../../../dataJson/jumingHealthJson/覃塘区.json"; break;//覃塘区
  87. default:break;
  88. }
  89. vm.getJsonData();
  90. }
  91. },
  92. watch:{
  93. // jsonData:function(data){
  94. // alert("jsonData:"+JSON.stringify(data))
  95. // this.jsonData = data;
  96. // }
  97. }
  98. });
  99. //数字格式化
  100. function toThousands(str) {
  101. if(!str)return
  102. str =parseInt(str);
  103. if(typeof(str) == 'number')str = str.toString()
  104. var newStr = "";
  105. var count = 0;
  106. if(str.indexOf(".") == -1) {
  107. for(var i = str.length - 1; i >= 0; i--) {
  108. if(count % 3 == 0 && count != 0) {
  109. newStr = str.charAt(i) + "," + newStr;
  110. } else {
  111. newStr = str.charAt(i) + newStr;
  112. }
  113. count++;
  114. }
  115. str = newStr;
  116. } else {
  117. for(var i = str.indexOf(".") - 1; i >= 0; i--) {
  118. if(count % 3 == 0 && count != 0) {
  119. newStr = str.charAt(i) + "," + newStr;
  120. } else {
  121. newStr = str.charAt(i) + newStr; //逐个字符相接起来
  122. }
  123. count++;
  124. }
  125. str = newStr + (str + "00").substr((str + "00").indexOf("."), 3);
  126. }
  127. return str;
  128. }