home.js 3.7 KB

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