zixunfenxi.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. var self;
  2. var type, level, area, title,sort=1;
  3. var path = {};
  4. var roleLevel, userRole;
  5. //初始化计算选择的年份
  6. var chooseYear;
  7. var now = new Date();
  8. if(now.getMonth() >= 6){
  9. chooseYear = now.getFullYear();
  10. }else{
  11. chooseYear = now.getFullYear() - 1;
  12. }
  13. //绑定按钮事件
  14. bindEvents();
  15. //初始化事件
  16. mui.plusReady(function() {
  17. self = plus.webview.currentWebview();
  18. type = self.type;
  19. level = self.level;
  20. area = self.area;
  21. //初始显示选中的年份
  22. $(".choose-label").text(chooseYear+"年");
  23. mui.later(function(){
  24. mui.fire(self, "loadData", {type: type, level: level, area: area});
  25. },500)
  26. //下拉刷新初始化
  27. initScroller();
  28. shaixuanInit(self);
  29. });
  30. function initScroller(){
  31. scroller1 = $("#wrapper1").initScroll(
  32. {
  33. pullDownAction: function(){
  34. $(".pullUp").hide();
  35. plus.nativeUI.showWaiting();
  36. type = type;
  37. level = level;
  38. area = area;
  39. mui.later(function(){
  40. mui.fire(self, "loadData", {type: type, level: level, area: area,title:title});
  41. },500)
  42. $(".c-lab-mor #labLi1").addClass("hit");
  43. $(".c-lab-mor #labLi2").removeClass("hit");
  44. $(".div-list").show();
  45. $(".div-list2").hide();
  46. },pullUpAction: function() {
  47. $(".pullUp").hide();
  48. return false;
  49. }
  50. }
  51. );
  52. }
  53. //返回事件
  54. mui.back = function(){
  55. if(level==4 || level==roleLevel){
  56. var mainPage =plus.webview.getWebviewById("admin.html");
  57. mui.fire(mainPage, "refreshData");
  58. //关闭筛选页面
  59. var shaixuan = plus.webview.getWebviewById("shaixuan2.html");
  60. if(shaixuan){
  61. shaixuan.close();
  62. }
  63. self.close();
  64. }
  65. else{
  66. level++;
  67. var params = path[level];
  68. if(!params){
  69. level++;
  70. params = path[level];
  71. }
  72. type = params.type;
  73. area = params.area;
  74. load(type, level, area);
  75. title = params.title || userRole.name;
  76. if(level==4){
  77. title = title.substring(0,3);
  78. }
  79. $("#title").html(title);
  80. $('#tjTitle').html("各科室管理");
  81. $(".c-lab-mor #labLi1").addClass("hit")
  82. }
  83. }
  84. /**
  85. * 初始化筛选事件
  86. */
  87. function shaixuanInit(main){
  88. var shaixuan = plus.webview.getWebviewById('shaixuan2.html');
  89. if(!shaixuan){
  90. shaixuan = mui.createWindow({
  91. id: 'shaixuan2.html',
  92. url: 'shaixuan2.html',
  93. styles: {
  94. top: 0,
  95. bottom: 0,
  96. left: '20%',
  97. width: '80%',
  98. scorllIndicator: "none"
  99. },
  100. show:{
  101. aniShow: "slide-in-right",
  102. duration: "400"
  103. }
  104. });
  105. }
  106. window.addEventListener("hideShaiXuan",function(){
  107. main.setStyle({mask:"none"});
  108. shaixuan.hide();
  109. }, false);
  110. window.addEventListener("showShaiXuan", function() {
  111. shaixuan.show();
  112. main.setStyle({mask:"rgba(0,0,0,0.5)"});
  113. main.addEventListener("maskClick",function(){
  114. main.setStyle({mask:"none"});
  115. shaixuan.hide();
  116. }, false);
  117. });
  118. }
  119. function bindEvents(){
  120. //标签切换
  121. $(".c-lab-mor li").click(function(){
  122. var tabid = $(this).attr("id");
  123. var top = $(this).offset().top;
  124. $(".c-lab-mor li").removeClass("hit");
  125. $(this).addClass("hit");
  126. $("#list div.l-list").hide();
  127. $("#list2 div.l-list").hide();
  128. if(tabid=="labLi1"){
  129. $("#list").show();
  130. $("#list2").hide();
  131. $("#div_list").show();
  132. }else{
  133. $("#list").hide();
  134. $("#list2").show();
  135. $("#div_list2").show();
  136. }
  137. scroller1.refresh();
  138. window.onscroll = function () {
  139. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  140. if(top!=-1 && top>0){
  141. window.scrollTo(0,top);
  142. top = -1;
  143. }
  144. }
  145. });
  146. //左滑筛选区域的数据
  147. $('.header-link').on("tap", function(){
  148. var self = plus.webview.currentWebview();
  149. mui.fire(self, "showShaiXuan");
  150. });
  151. window.addEventListener("refresh", function(e){
  152. chooseYear = e.detail.year;
  153. $(".choose-label").text(chooseYear+"年");
  154. loadData(type, level, area);
  155. loadLineData(type, level, area);
  156. });
  157. //说明信息相关事件
  158. $("#closeBtn").on("tap", function(){
  159. $(".information").hide();
  160. scroller1.refresh();
  161. });
  162. $(".info-icon").on("tap", function(){
  163. $(".information").show();
  164. scroller1.refresh();
  165. });
  166. }
  167. /*****************************************************************************/
  168. /***** 统计数据初始化 **********/
  169. /*****************************************************************************/
  170. //加载数据
  171. function loadData(type, level, area){
  172. clearData(type);
  173. var params = {level: level, area: area, year: chooseYear}
  174. loadAmount(params);
  175. if(level==3){//市级管理员才可以查看市下面的所有社区数据
  176. $(".c-lab-mor #labLi2").removeClass("c-hide");
  177. }
  178. }
  179. //后台接收数据
  180. function loadAmount(params){
  181. sendPost("/statistics/time",null,function(res){
  182. },function(res){
  183. if(res.status=="200"){
  184. var date = (res.data && res.data.substring(11,16)) || "";
  185. $(".jiezhi-time").html(date)
  186. }
  187. })
  188. console.log("第一个:"+JSON.stringify(params))
  189. sendPost("/statistics/Consulting_Title", params, null, countHandle);
  190. params.sort = 1;//排序(0:升序 1:降序)
  191. params.date = params.endDate;
  192. params.date = getEndDate();
  193. console.log("第二个:"+JSON.stringify(params))
  194. // params.lowlevel = "3";
  195. sendPost("/statistics/Consulting_StatList", params, null, listHandle);
  196. // delete params.lowLevel;
  197. if($(".c-lab-mor #labLi2").css("display")!="none"){
  198. if(roleLevel==3){//市级管理员才可以查看市下面的所有社区数据
  199. params.lowlevel = "1";
  200. console.log("第三个:"+JSON.stringify(params))
  201. sendPost("/statistics/Consulting_StatList", params, null, list2Handle);
  202. delete params.lowLevel;
  203. }
  204. }
  205. }
  206. //格式化数量
  207. function assNoRelyCount(list){
  208. var all = 0;
  209. for(var k in list){
  210. all += list[k].noRelyCount;
  211. }
  212. return all;
  213. }
  214. //排序
  215. function soreRank(arr) {
  216. var temp = [];
  217. var lis = [];
  218. for(var i=0;i<arr.length;i++)
  219. lis.push(arr[i])
  220. lis = _.uniq(lis);
  221. // lis.sort();
  222. // lis.reverse();
  223. for(var i=0;i<arr.length;i++)
  224. temp[i] = lis.indexOf(arr[i])+1;
  225. return temp;
  226. }
  227. //数量数组
  228. function amountArr(list){
  229. var amountArr = [];
  230. for(var k in list){
  231. amountArr.push(list[k].noRelyDoubleRate);
  232. }
  233. return amountArr;
  234. }
  235. function listHandle(res){
  236. if(res.status == 200) {
  237. template.helper("setRate", function(all, noRelyCount){
  238. if(all == 0)
  239. return 0;
  240. return (noRelyCount / all * 100).toFixed(2);
  241. });
  242. res = res.data;
  243. var $div;
  244. var list = res.resultList;
  245. var topArr = soreRank(amountArr(list));
  246. for(var j in list){
  247. list[j].top = topArr[j];
  248. }
  249. res.all = assNoRelyCount(list);
  250. res.list = list;
  251. res.level = level;
  252. $div = $('<div id="div_list" class="l-list clearfix"></div>');
  253. $('#div_list').remove();
  254. if($div){
  255. $div.append(template("list_tmpl", res));
  256. if(level>2){
  257. $("li", $div).on("tap", function(){
  258. level--;
  259. area = $(this).attr("data-code");
  260. load(type, level, area);
  261. var name = $(this).attr("data-name");
  262. title = name;
  263. $("#title").html(title);
  264. $('#tjTitle').html("各医生情况");
  265. path[level] = {type: type, level: level, area: area, title: name}
  266. })
  267. }
  268. $("#list").append($div);
  269. scroller1.refresh();
  270. plus.nativeUI.closeWaiting();
  271. }
  272. } else {
  273. mui.toast(res.msg);
  274. }
  275. }
  276. function list2Handle(res){
  277. if(res.status == 200) {
  278. template.helper("setRate", function(all, noRelyCount){
  279. if(all == 0)
  280. return 0;
  281. return (noRelyCount / all * 100).toFixed(2);
  282. });
  283. res = res.data;
  284. var $div;
  285. var list = res.resultList;
  286. var topArr = soreRank(amountArr(list));
  287. for(var j in list){
  288. list[j].top = topArr[j];
  289. }
  290. res.all = assNoRelyCount(list);
  291. res.list = list;
  292. res.level = level;
  293. $div = $('<div id="div_list2" class="l-list clearfix"></div>');
  294. $('#div_list2').remove();
  295. if($div){
  296. $div.append(template("list_tmpl", res));
  297. // $("li", $div).on("tap", function(){
  298. // level = 2;
  299. // area = $(this).attr("data-code");
  300. // load(type, level, area);
  301. // var name = $(this).attr("data-name");
  302. // title = name;
  303. // $("#title").html(title);
  304. // $('#tjTitle').html("各医生情况");
  305. // path[level] = {type: type, level: level, area: area, title: name}
  306. // })
  307. $("#list2").append($div);
  308. scroller1.refresh();
  309. plus.nativeUI.closeWaiting();
  310. }
  311. } else {
  312. mui.toast(res.msg);
  313. }
  314. }
  315. function countHandle(res){
  316. if(res.status == 200) {
  317. res = res.data.result[0] || [];
  318. $('#div_total').html(res.total);
  319. $('#div_noRelyRate').html(res.noRelyRate);
  320. $('#div_noRelyCount').html(res.noRelyCount);
  321. $('#div_relyRate').html(res.relyRate);
  322. } else {
  323. mui.toast(res.msg);
  324. }
  325. }
  326. function clearData(type){
  327. $("#textTj li").removeClass("l-over");
  328. $('#l-jmfx').show();
  329. $("#list").empty();
  330. $("#list2").empty();
  331. $(".l-data").html("0");
  332. }
  333. //获取结束时间
  334. function getEndDate(){
  335. chooseYear = parseInt(chooseYear);
  336. var endDate = new Date((chooseYear+1) + '-06-30'),
  337. now = new Date();
  338. if(now <= endDate){
  339. var month = now.getMonth()+1,
  340. date1 = now.getDate();
  341. if(month < 10){
  342. month = "0"+month;
  343. }
  344. if(date1 < 10){
  345. date1 = "0"+date1;
  346. }
  347. return now.getFullYear()+"-"+month+"-"+date1;
  348. }else{
  349. return (chooseYear+1) + '-06-30';
  350. }
  351. }
  352. /*****************************************************************************/
  353. /***** 柱状图初始化 **********/
  354. /*****************************************************************************/
  355. function loadLineData(type, level, area){
  356. plus.nativeUI.showWaiting();
  357. var url = "/statistics/getCoutListByTime";
  358. var params = {level: level, area: area, year: chooseYear}
  359. sendPost(url, params, null, dateLineHandle);
  360. }
  361. //初始化柱状图
  362. function drawChart(nameData,numData){
  363. nameData.push("时间段");
  364. var myChart = echarts.init(document.getElementById("l-zxt-con"));
  365. var option = {
  366. calculable : true,
  367. grid: {y: 25, y2:30, x:0, x2:20,width:$(".l-zxt-con").width(),borderColor:'#ffffff'},
  368. xAxis : [
  369. {
  370. type : 'category',
  371. axisLine: {show:true,lineStyle:{color:'#dcdcdc',width:1}},
  372. axisTick: {show:false},
  373. axisLabel: {show:true,lineStyle:{color:'#323232'}},
  374. splitArea: {show:false},
  375. splitLine: {show:false},
  376. data : nameData
  377. }
  378. ],
  379. yAxis : [
  380. {
  381. type : 'value',
  382. axisLine: {show:true,lineStyle:{color:'#dcdcdc',width:1}},
  383. axisTick: {show:false},
  384. axisLabel: {show:false},
  385. splitArea: {show:false},
  386. splitLine: {show:false},
  387. axisLabel:{show:false}
  388. }
  389. ],
  390. series : [
  391. {
  392. name:'首次回复时间分布',
  393. type:'bar',
  394. barWidth:20,
  395. itemStyle: {normal: {color:'#17B3EC', label:{show:true},barBorderRadius:0}},
  396. data:numData
  397. }
  398. ]
  399. };
  400. myChart.setOption(option);
  401. }
  402. function dateLineHandle(res){
  403. if(res.status==200){
  404. var resData = res.data.resultList;
  405. var nameData = [],numData = [];
  406. for(var p in resData){
  407. nameData.push(resData[p].name);
  408. numData.push(resData[p].num);
  409. }
  410. drawChart(nameData,numData);
  411. } else {
  412. mui.toast(res.msg);
  413. }
  414. plus.nativeUI.closeWaiting();
  415. }
  416. function load(type, level, area, from, to){
  417. $('#labLi2').toggle(level == 3);
  418. if($(".c-lab-mor .hit").attr("id")=="labLi2"){
  419. $('#list2').toggle(level == 3);
  420. $('#labLi2').removeClass("hit");
  421. }
  422. $('#list').show();
  423. $("#list2").hide();
  424. path[level] = {type: type, level: level, area: area}
  425. loadData(type, level, area);
  426. loadLineData(type, level, area);
  427. }
  428. window.addEventListener("loadData", function(e) {
  429. // userRole = JSON.parse(plus.storage.getItem("userRole"))[0] ;
  430. userRole = JSON.parse(plus.storage.getItem("selectedRole"));
  431. // roleLevel = userRole.code == '350200' ? 4 : userRole.code.length==6 ? 3 : 2;
  432. roleLevel=3;
  433. type = e.detail.type;
  434. $('.type-'+ type).show();
  435. level = e.detail.level || roleLevel;
  436. area = e.detail.area || userRole.code;
  437. title = e.detail.title || userRole.name;
  438. load(type, level, area);
  439. $('#tjTitle').html("各科室管理");
  440. if(!e.detail.title){
  441. $('#labLi2').toggle(level == 3);
  442. }
  443. $(".c-lab-mor #labLi2").removeClass("hit");
  444. if(level==4){
  445. title = title.substring(0,3);
  446. }
  447. $("#title").html(title);
  448. });
  449. window.addEventListener("toBack", function(e) {
  450. mui.back();
  451. });
  452. document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);