manyidufenxi.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. var self;
  2. var type, level, area, title,sort=1;
  3. var path = {};
  4. var roleLevel, userRole;
  5. var EndTimeRecord;
  6. var monthGap;
  7. //绑定按钮事件
  8. bindEvents();
  9. //初始化事件
  10. mui.plusReady(function() {
  11. self = plus.webview.currentWebview();
  12. type = self.type;
  13. level = self.level;
  14. area = self.area;
  15. mui.later(function(){
  16. mui.fire(self, "loadData", {type: type, level: level, area: area});
  17. },500)
  18. //下拉刷新初始化
  19. initScroller();
  20. });
  21. function initScroller(){
  22. scroller1 = $("#wrapper1").initScroll(
  23. {
  24. pullDownAction: function(){
  25. $(".pullUp").hide();
  26. plus.nativeUI.showWaiting();
  27. type = type;
  28. level = level;
  29. area = area;
  30. mui.later(function(){
  31. mui.fire(self, "loadData", {type: type, level: level, area: area,title:title});
  32. },500)
  33. $(".c-lab-mor #labLi1").addClass("hit");
  34. $(".c-lab-mor #labLi2").removeClass("hit");
  35. $(".div-list").show();
  36. $(".div-list2").hide();
  37. },pullUpAction: function() {
  38. $(".pullUp").hide();
  39. return false;
  40. }
  41. }
  42. );
  43. }
  44. //返回事件
  45. mui.back = function(){
  46. if(level==3 || level==roleLevel){
  47. var mainPage =plus.webview.getWebviewById("admin.html");
  48. mui.fire(mainPage, "refreshData");
  49. self.close();
  50. }
  51. else{
  52. level++;
  53. var params = path[level];
  54. if(!params){
  55. level++;
  56. params = path[level];
  57. }
  58. type = params.type;
  59. area = params.area;
  60. load(type, level, area);
  61. title = params.title || userRole.name;
  62. if(level==3){
  63. title = title.substring(0,3);
  64. }
  65. $("#title").html(title);
  66. $('#tjTitle').html("科室情况");
  67. $(".c-lab-mor #labLi1").addClass("hit")
  68. }
  69. }
  70. function bindEvents(){
  71. //标签切换
  72. $(".c-lab-mor li").click(function(){
  73. var tabid = $(this).attr("id");
  74. var top = $(this).offset().top;
  75. $(".c-lab-mor li").removeClass("hit");
  76. $(this).addClass("hit");
  77. $("#list div.l-list").hide();
  78. $("#list2 div.l-list").hide();
  79. if(tabid=="labLi1"){
  80. $("#list").show();
  81. $("#list2").hide();
  82. $("#div_list").show();
  83. }else{
  84. loadData(type, level, area)
  85. $("#list").hide();
  86. $("#list2").show();
  87. $("#div_list2").show();
  88. }
  89. scroller1.refresh();
  90. window.onscroll = function () {
  91. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  92. if(top!=-1 && top>0){
  93. window.scrollTo(0,top);
  94. top = -1;
  95. }
  96. }
  97. });
  98. }
  99. /*****************************************************************************/
  100. /***** 统计数据初始化 **********/
  101. /*****************************************************************************/
  102. //加载数据
  103. function loadData(type, level, area){
  104. clearData(type);
  105. var params = {level: level, area: area}
  106. loadAmount(params);
  107. if(level==3){//市级管理员才可以查看市下面的所有社区数据
  108. $(".c-lab-mor #labLi2").removeClass("c-hide");
  109. }
  110. }
  111. //后台接收数据
  112. function loadAmount(params){
  113. sendPost("/statistics/time",null,function(res){
  114. },function(res){
  115. if(res.status=="200"){
  116. var date = (res.data && res.data.substring(11,16)) || "";
  117. $(".jiezhi-time").html(date)
  118. }
  119. })
  120. sendPost("/statistics/getAVGSocre", params, null, countHandle);
  121. params.sort = 1;//排序(0:升序 1:降序)
  122. params.index = 28;
  123. params.date = getEndDate();
  124. sendPost("/statistics/lowlevel_all", params,null, listHandle);
  125. if($(".c-lab-mor #labLi2").css("display")!="none"){
  126. if(roleLevel==3){//市级管理员才可以查看市下面的所有社区数据
  127. params.lowLevel = "1";
  128. sendPost("/statistics/lowlevel_all", params, null, list2Handle);
  129. delete params.lowLevel;
  130. }
  131. }
  132. }
  133. function listHandle(res){
  134. if(res.status == 200) {
  135. template.helper("setRate", function(num){
  136. if(num == 0)
  137. return 0;
  138. return num*1;
  139. });
  140. res = res.data;
  141. var $div;
  142. var list = JSON.parse(res.index_28).data;
  143. var topArr = soreRank(getAvgCount(list));
  144. for(var i=0;i<list.length;i++){
  145. list[i].top = topArr[i];
  146. }
  147. res.list = list;
  148. res.level = level;
  149. $('#div_list').remove();
  150. $div = $('<div id="div_list" class="l-list clearfix"></div>');
  151. if($div){
  152. $div.append(template("list_tmpl", res));
  153. if(level>2){
  154. $("li", $div).on("tap", function(){
  155. level--;
  156. area = $(this).attr("data-code");
  157. load(type, level, area);
  158. var name = $(this).attr("data-name");
  159. title = name;
  160. $("#title").html(title);
  161. $('#tjTitle').html("医生情况");
  162. path[level] = {type: type, level: level, area: area, title: name}
  163. })
  164. }
  165. $("#list").append($div);
  166. scroller1.refresh();
  167. plus.nativeUI.closeWaiting();
  168. }
  169. } else {
  170. mui.toast(res.msg);
  171. }
  172. }
  173. function list2Handle(res){
  174. if(res.status == 200) {
  175. template.helper("setRate", function(num){
  176. if(num == 0)
  177. return 0;
  178. return 50+((num*1-80)/20*50).toFixed(2)*1;
  179. });
  180. res = res.data;
  181. var $div;
  182. var list = JSON.parse(res.index_28).data;
  183. var topArr = soreRank(getAvgCount(list));
  184. for(var i=0;i<list.length;i++){
  185. list[i].top = topArr[i];
  186. }
  187. res.list = list;
  188. res.level = level;
  189. $('#div_list2').remove();
  190. $div = $('<div id="div_list2" class="l-list clearfix"></div>');
  191. if($div){
  192. $div.append(template("list_tmpl", res));
  193. // $("li", $div).on("tap", function(){
  194. // level = 2;
  195. // area = $(this).attr("data-code");
  196. // load(type, level, area);
  197. // var name = $(this).attr("data-name");
  198. // title = name;
  199. // $("#title").html(title);
  200. // $('#tjTitle').html("各团队情况");
  201. // path[level] = {type: type, level: level, area: area, title: name}
  202. // })
  203. $("#list2").append($div);
  204. scroller1.refresh();
  205. plus.nativeUI.closeWaiting();
  206. }
  207. } else {
  208. mui.toast(res.msg);
  209. }
  210. }
  211. function getAvgCount(list){
  212. var arr = [];
  213. for(var k in list){
  214. arr.push(list[k].avgCount);
  215. }
  216. return arr;
  217. }
  218. //排序
  219. function soreRank(arr) {
  220. var temp = [];
  221. var lis = [];
  222. for(var i=0;i<arr.length;i++)
  223. lis.push(arr[i])
  224. lis = _.uniq(lis);
  225. for(var i=0;i<arr.length;i++)
  226. temp[i] = lis.indexOf(arr[i])+1;
  227. return temp;
  228. }
  229. function countHandle(res){
  230. if(res.status == 200) {
  231. res = res.data.rs;
  232. if(res.avgCount == 0){
  233. $('#avgScore').html('暂无评');
  234. }else{
  235. $('#avgScore').html(res.avgCount);
  236. }
  237. } else {
  238. mui.toast(res.msg);
  239. }
  240. }
  241. function clearData(type){
  242. $("#textTj li").removeClass("l-over");
  243. $('#l-jmfx').show();
  244. $("#list").empty();
  245. $("#list2").empty();
  246. $(".l-data").html("0");
  247. }
  248. /*****************************************************************************/
  249. /***** 折线图初始化 **********/
  250. /*****************************************************************************/
  251. function loadLineData(type, level, area){
  252. plus.nativeUI.showWaiting();
  253. var now = new Date();
  254. var month = (now.getMonth()*1+1)<10?"0"+(now.getMonth()+1):(now.getMonth()+1);
  255. var date = now.getDate()<10?"0"+now.getDate():now.getDate();
  256. var endDate = now.getFullYear()+'-'+month+'-'+date;
  257. monthGap = getMonthByDiff('2017-01-01',endDate);//月份数
  258. var num = Math.ceil(monthGap/5);//5个月为一模块
  259. addSlide(num);
  260. loadOneData(level, area,endDate,1);
  261. }
  262. ///滚动加载前面数据
  263. document.querySelector('.mui-slider').addEventListener('slide', function(event) {
  264. var num = Math.ceil(monthGap/5)*1;//5个月为一模块
  265. var slideNumber = event.detail.slideNumber;
  266. var before = num - slideNumber*1 + 1;
  267. if(before <= num){
  268. var $li = $('#l-zxt-con'+before)
  269. if($li.html() == ''){
  270. loadOneData(level, area,EndTimeRecord,before);
  271. }
  272. }
  273. })
  274. function loadOneData(level, area,endDate,num){
  275. var statDate = fiveMonth(endDate);
  276. var url = "/statistics/getAVGSocreByMonth";
  277. EndTimeRecord = lastDate(statDate);//储存结束时间
  278. var params = {level: level, area: area,statDate:statDate,endDate:endDate};
  279. sendPost(url, params, null, function(res){
  280. dateLineHandle(res,num);
  281. });
  282. }
  283. //相差几月
  284. function getMonthByDiff(a,b){
  285. var ba = b.split('-');
  286. var aa = a.split('-');
  287. if(ba[1] > aa[1]||ba[1] == aa[1]){
  288. return 12*(ba[0]-aa[0])*1+(ba[1]-aa[1])*1+1
  289. }else{
  290. return 12*(ba[0]-1-aa[0])*1+(ba[1]*1+12-aa[1])*1+1
  291. }
  292. }
  293. //该上月份最后一天
  294. function lastDate(date){
  295. var arr = date.split('-');
  296. var year = arr[0];
  297. var month = arr[1]*1-1;
  298. if(month<1){
  299. month = 12;
  300. year = year - 1;
  301. }
  302. var day = new Date(year,month,0).getDate();
  303. var newMonth = month<10?"0"+month:month;
  304. var statDate = year+'-'+newMonth+'-'+day;
  305. return statDate;
  306. }
  307. //5个月前
  308. function fiveMonth(endDate){
  309. var arr = endDate.split('-');
  310. var reduce = arr[1]*1-4;
  311. if(reduce>0){
  312. reduce = reduce<10?"0"+reduce:reduce;
  313. var statDate = arr[0]+'-'+reduce+'-01';
  314. return statDate;
  315. }else{
  316. var newReduce = (12+reduce*1)<10?"0"+(12+reduce*1):(12+reduce*1);
  317. var statDate = arr[0]*1-1+'-'+newReduce+'-01';
  318. return statDate;
  319. }
  320. }
  321. //添加轮播块
  322. function addSlide(num){
  323. var html = '';
  324. for(var i=num;i>0;i--){
  325. html += '<div class="mui-slider-item"><div class="l-zxt-con" id="l-zxt-con'+i+'" style="height: 240px;width: 100%;padding:20px 10px 0px;"></div></div>'
  326. }
  327. $('#chart_contain').empty().append(html);
  328. var slider = mui('.mui-slider').slider();//轮播启动
  329. if(EndTimeRecord){
  330. slider.gotoItem(1,0)//处理不加载数据bug
  331. slider.gotoItem(0,0)//处理不加载数据bug
  332. }
  333. slider.gotoItem(num*1-1);//跳到最后一页
  334. setTimeout(function(){
  335. $('#chart_contain').css('visibility','visible');//显示
  336. },1000)
  337. }
  338. function dateLineHandle(res,num){
  339. if(res.status==200){
  340. var resData = res.data;
  341. var nameData = [],numData = [];
  342. _.map(resData,function(v){
  343. nameData.push(v.month);
  344. numData.push(v.socre);
  345. })
  346. drawChart(nameData,numData,num);
  347. } else {
  348. mui.toast(res.msg);
  349. }
  350. plus.nativeUI.closeWaiting();
  351. }
  352. //初始化图
  353. function drawChart(nameData,numData,num){
  354. echarts.init(document.getElementById("l-zxt-con"+num)).setOption({
  355. calculable : true,
  356. grid: {y: 25, y2:30, x:0, x2:20,width:$(".l-zxt-con").width(),borderColor:'#ffffff'},
  357. xAxis : [
  358. {
  359. type : 'category',
  360. axisLine: {show:true,lineStyle:{color:'#dcdcdc',width:1}},
  361. axisTick: {show:false},
  362. axisLabel: {show:true,textStyle:{color:'#323232'}},
  363. splitArea: {show:false},
  364. splitLine: {show:false},
  365. data : nameData
  366. }
  367. ],
  368. yAxis : [
  369. {
  370. type : 'value',
  371. axisLine: {show:false,lineStyle:{color:'#dcdcdc',width:1}},
  372. axisTick: {show:false},
  373. axisLabel: {show:false},
  374. splitArea: {show:false},
  375. splitLine: {show:false},
  376. axisLabel:{show:false}
  377. }
  378. ],
  379. series : [
  380. {
  381. name:'平均评分',
  382. type:'line',
  383. itemStyle: {normal: {color:'#17B3EC', label:{show:true}}},
  384. data:numData
  385. }
  386. ]
  387. });
  388. }
  389. function load(type, level, area, from, to){
  390. $('#labLi2').toggle(level == 3);
  391. if($(".c-lab-mor .hit").attr("id")=="labLi2"){
  392. $('#list2').toggle(level == 3);
  393. $('#labLi2').removeClass("hit");
  394. }
  395. $('#list').show();
  396. $("#list2").hide();
  397. path[level] = {type: type, level: level, area: area}
  398. loadData(type, level, area);
  399. loadLineData(type, level, area);
  400. }
  401. window.addEventListener("loadData", function(e) {
  402. // userRole = JSON.parse(plus.storage.getItem("userRole"))[0] ;
  403. userRole = JSON.parse(plus.storage.getItem("selectedRole"));
  404. // roleLevel = userRole.code == '350200' ? 4 : userRole.code.length==6 ? 3 : 2;
  405. roleLevel = 3
  406. type = e.detail.type;
  407. $('.type-'+ type).show();
  408. level = e.detail.level || roleLevel;
  409. area = e.detail.area || userRole.code;
  410. title = e.detail.title || userRole.name;
  411. load(type, level, area);
  412. $('#tjTitle').html("科室情况");
  413. if(!e.detail.title){
  414. $('#labLi2').toggle(level == 3);
  415. }
  416. $(".c-lab-mor #labLi2").removeClass("hit");
  417. if(level==4){
  418. title = title.substring(0,3);
  419. }
  420. $("#title").html(title);
  421. });
  422. window.addEventListener("toBack", function(e) {
  423. mui.back();
  424. });
  425. //获取结束时间
  426. function getEndDate(){
  427. var now = new Date(),
  428. year = now.getFullYear(),
  429. month = now.getMonth() + 1,
  430. day = now.getDate();
  431. if(month < 10){
  432. month = '0'+month;
  433. }
  434. if(day < 10){
  435. day = "0"+ day;
  436. }
  437. return year+"-"+month+"-"+day;
  438. }