alert.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. new Vue({
  2. el: '#main',
  3. data: {
  4. alertData1:'',//总人数
  5. alertData2:'',//新增人数
  6. alertData3:'',//门诊人次
  7. alertData4:'',//住院人次
  8. alertChart1:'',//左边第一块表格
  9. alertChart2:'',//右上第一块
  10. alertChart3:'',//右上第二块
  11. alertChart4:'',//右上第三块
  12. alertChart5:'',//右下
  13. bigData:'',//总数据
  14. alertType:0,
  15. alertTime:1,
  16. type:'',
  17. title:'',
  18. },
  19. mounted: function() {
  20. var vm = this;
  21. this.type = this.GetQueryString("type");
  22. if(this.type == 0){
  23. this.title = '高血压人群分布';
  24. vm.bigData = bigData;
  25. }else if(this.type == 1){
  26. this.title = '糖尿病人群分布';
  27. vm.bigData = bigData2;
  28. }else if(this.type == 2){
  29. this.title = '孕产妇人群';
  30. }else if(this.type == 3){
  31. this.title = '65岁以上老年人人数';
  32. }
  33. this.initData();
  34. var myDate = new Date();
  35. var maxMonth = myDate.getMonth()+1; //获取当前月份(0-11,0代表1月)
  36. var maxYear = myDate.getFullYear();
  37. var max = maxYear.toString()+'-'+maxMonth.toString();
  38. var moren = maxYear.toString()+'-'+(maxMonth-1).toString()+' 至 '+maxYear.toString()+'-'+(maxMonth-1).toString();
  39. layui.use('laydate', function(){
  40. var laydate = layui.laydate;
  41. //执行一个laydate实例
  42. laydate.render({
  43. elem: '#time', //指定元素,
  44. type:'month',
  45. range: '至', //或 range: '~' 来自定义分割字符
  46. theme: '#05273e',
  47. position: 'abolute',
  48. right:'200px',
  49. value: moren,
  50. max:max,
  51. btns: ['confirm'],
  52. done: function(value, date, endDate){
  53. console.log(value); //得到日期生成的值,如:2017-08-18
  54. console.log(date); //得到日期时间对象:{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
  55. console.log(endDate); //得结束的日期时间对象,开启范围选择(range: true)才会返回。对象成员同上。
  56. }
  57. // showBottom: false
  58. });
  59. });
  60. },
  61. methods: {
  62. initData:function(){
  63. var vm = this;
  64. vm.alertData1 = vm.bigData['总人数'];
  65. vm.alertData2 = vm.bigData['新增人数'];
  66. vm.alertData3 = vm.bigData['门诊人次'];
  67. vm.alertData4 = vm.bigData['住院人次'];
  68. this.setAlertChart1(0);
  69. this.setAlertChart2(0);
  70. this.setAlertChart3(0);
  71. this.setAlertChart4(0);
  72. this.setAlertChart5(0,0);
  73. console.log(vm.bigData)
  74. },
  75. setAlertChart1:function(type){
  76. var t = '';
  77. switch(type){
  78. case 0:t = '全部';break;
  79. case 1:t = '门诊';break;
  80. case 2:t = '住院';break;
  81. }
  82. var options = this.bigData[t]['区县分布'];
  83. options.series[0].label = {show: true,position: "right",color: '#b5e1fc'}
  84. this.alertChart1 = options;
  85. },
  86. setAlertChart2:function(type){
  87. var t = '';
  88. switch(type){
  89. case 0:t = '全部';break;
  90. case 1:t = '门诊';break;
  91. case 2:t = '住院';break;
  92. }
  93. var options = this.bigData[t]['年龄段分布'];
  94. options.color = ["#6576e0","#03fa6c","#ff616f","#0fa5f2","#00e6f3"];
  95. options.legend.formatter = function(name) {
  96. var index = 0;
  97. var clientlabels = options.legend.data;
  98. var clientcounts = _.map(options.series[0].data,function(item,idx){
  99. return item.value;
  100. });
  101. clientlabels.forEach(function(value,i){
  102. if(value == name){
  103. index = i;
  104. }
  105. });
  106. return name + " " + clientcounts[index];
  107. }
  108. options.legend.left = '48%';
  109. options.legend.top = 0.044 * window.screen.width;//85;
  110. options.legend.itemWidth = 0.005 * window.screen.width;//10;
  111. options.legend.itemHeight = 0.005 * window.screen.width;//10;
  112. options.legend.itemGap = 0.0078 * window.screen.width;//15;
  113. options.series[0].center = ['25%','55%'];
  114. this.alertChart2 = options
  115. },
  116. setAlertChart3:function(type){
  117. var t = '';
  118. switch(type){
  119. case 0:t = '全部';break;
  120. case 1:t = '门诊';break;
  121. case 2:t = '住院';break;
  122. }
  123. var options = this.bigData[t]['性别分布'];
  124. options.color = ["#00E7F3","#ff616f"];
  125. options.legend.formatter = function(name) {
  126. var index = 0;
  127. var clientlabels = options.legend.data;
  128. var clientcounts = _.map(options.series[0].data,function(item,idx){
  129. return item.value;
  130. });
  131. clientlabels.forEach(function(value,i){
  132. if(value == name){
  133. index = i;
  134. }
  135. });
  136. return name + " " + clientcounts[index];
  137. }
  138. options.legend.left = '48%';
  139. options.legend.top = 0.0625 * window.screen.width;//120
  140. options.legend.itemWidth = 0.005 * window.screen.width;//10;
  141. options.legend.itemHeight = 0.005 * window.screen.width;//10;
  142. options.legend.itemGap = 0.0078 * window.screen.width;//15;
  143. options.series[0].center = ['25%','55%'];
  144. this.alertChart3 = options
  145. },
  146. setAlertChart4:function(type){
  147. var t = '';
  148. switch(type){
  149. case 0:t = '全部';break;
  150. case 1:t = '门诊';break;
  151. case 2:t = '住院';break;
  152. }
  153. var options = this.bigData[t]["并发症"];
  154. options.series[0].label = {show: true,position: "right",color: '#b5e1fc'};
  155. options.series[0].itemStyle.normal.color = '#FFF71A';
  156. this.alertChart4 = options
  157. },
  158. setAlertChart5:function(type,time){
  159. var t = '',m='';
  160. switch(type){
  161. case 0:t = '全部';break;
  162. case 1:t = '门诊';break;
  163. case 2:t = '住院';break;
  164. }
  165. switch(time){
  166. case 0:m = '日';break;
  167. case 1:m = '月';break;
  168. case 2:m = '季';break;
  169. case 3:m = '年';break;
  170. }
  171. var options = this.bigData[t]['新增患者趋势'][m];
  172. options.tooltip = {
  173. trigger: 'axis',
  174. axisPointer: {
  175. type : 'shadow'
  176. },
  177. formatter: '{b} <br /> {a0}: {c0}<br />{a1}: {c1}' + "%"
  178. }
  179. options.series[0].itemStyle.color = '#FF606E';
  180. this.alertChart5 = options
  181. },
  182. alertTitle:function(type){
  183. this.alertTime = 1;
  184. this.setAlertChart1(type);
  185. this.setAlertChart2(type);
  186. this.setAlertChart3(type);
  187. this.setAlertChart4(type);
  188. this.setAlertChart5(type,1);
  189. this.alertType = type;
  190. },
  191. alertChart:function(time){
  192. var type = this.alertType;
  193. this.alertTime = time;
  194. this.setAlertChart5(type,time);
  195. },
  196. closeAlertClick:function(){
  197. parent.layer.closeAll();
  198. },
  199. GetQueryString :function (name){
  200. var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  201. var r = window.location.search.substr(1).match(reg);
  202. if(r!=null)return unescape(r[2]); return null;
  203. },
  204. chartArea:function(param){
  205. console.log(param);
  206. },
  207. clickBarItem:function(item){
  208. console.log(item)
  209. }
  210. }
  211. });
  212. //数字格式化
  213. function toThousands(str) {
  214. if(!str)return
  215. str =parseInt(str);
  216. if(typeof(str) == 'number')str = str.toString()
  217. var newStr = "";
  218. var count = 0;
  219. if(str.indexOf(".") == -1) {
  220. for(var i = str.length - 1; i >= 0; i--) {
  221. if(count % 3 == 0 && count != 0) {
  222. newStr = str.charAt(i) + "," + newStr;
  223. } else {
  224. newStr = str.charAt(i) + newStr;
  225. }
  226. count++;
  227. }
  228. str = newStr;
  229. } else {
  230. for(var i = str.indexOf(".") - 1; i >= 0; i--) {
  231. if(count % 3 == 0 && count != 0) {
  232. newStr = str.charAt(i) + "," + newStr;
  233. } else {
  234. newStr = str.charAt(i) + newStr; //逐个字符相接起来
  235. }
  236. count++;
  237. }
  238. str = newStr + (str + "00").substr((str + "00").indexOf("."), 3);
  239. }
  240. return str;
  241. }