yewufenxi.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. var self;
  2. var type, level, area, indexs, title,sort=1,banerIndex;
  3. var path = {};
  4. var roleLevel, userRole;
  5. var endDate;
  6. var startDate;
  7. var fromDate = "2016-08-01";
  8. var indexName = {'index_3': '咨询量:', 'index_4': '随访量:', 'index_5': '指导量:','index_27':'代预约量:','index_21': '绑定微信:','index_20': '绑定设备:'};
  9. var information = {
  10. "3":"咨询量为签约年度(当年7月1日至次年6月30日)居民咨询的次数,点击右上角可切换查看不同年份数据",
  11. "4":"随访量为签约年度(当年7月1日至次年6月30日)随访次数,点击右上角可切换查看不同年份数据",
  12. "5":"指导量为签约年度(当年7月1日至次年6月30日)发送健康指导的次数,点击右上角可切换查看不同年份数据",
  13. "27":"代预约量为签约年度(当年7月1日至次年6月30日)代居民预约挂号的次数,点击右上角可切换查看不同年份数据",
  14. "21":"绑定微信量为签约年度签约居民(含未缴费)已关注微信号的数量统计,点击右上角可以切换查看不同年份数据",
  15. "20":"绑定设备量为签约年度签约居民(含未缴费)已绑定的设备数量统计,点击右上角可以切换查看不同年份数据"
  16. };
  17. //初始化计算选择的年份
  18. var chooseYear;
  19. var now = new Date();
  20. if(now.getMonth() >= 6){
  21. chooseYear = now.getFullYear();
  22. }else{
  23. chooseYear = now.getFullYear() - 1;
  24. }
  25. //绑定按钮事件
  26. bindEvents();
  27. //页面初始化
  28. mui.plusReady(function() {
  29. self = plus.webview.currentWebview();
  30. type = self.type;
  31. // userRole = JSON.parse(plus.storage.getItem("userRole"))[0] ;
  32. userRole = JSON.parse(plus.storage.getItem("selectedRole"));
  33. roleLevel = userRole.code == '350200' ? 4 : userRole.code.length==6 ? 3 : 2;
  34. level = roleLevel;
  35. area = userRole.code;
  36. title = userRole.name;
  37. //初始显示选中的年份
  38. $(".choose-label").text(chooseYear+"年");
  39. //初始化开始时间和结束时间
  40. startDate = getStartDate();
  41. endDate = getEndDate();
  42. //初始化
  43. load({type: type, level: level, area: area,title: title, year: chooseYear});
  44. //下拉刷新初始化
  45. initScroller();
  46. shaixuanInit(self);
  47. });
  48. function load(obj){
  49. var level = obj.level;
  50. var title = obj.title;
  51. var date = endDate;
  52. $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
  53. $('#labLi2').toggle(level == 4);
  54. if($(".c-lab-mor .hit").attr("id")=="labLi2"){
  55. $('#list2').toggle(level == 4);
  56. $('#labLi2').removeClass("hit");
  57. }
  58. $('#list').show();
  59. $("#list2").hide();
  60. path[level] = {type: type, level: level, area: area, date: date}
  61. indexs = [3, 4, 5, 27, 21, 20];
  62. loadData(type, level, area, date);
  63. loadLineData(type, level, area, '', date, $('#l-legend li.l-over').attr('data-val'), $("#textTj .l-over").attr("data-index"));
  64. if(banerIndex){
  65. // $("#index_"+banerIndex).closest("li").trigger("tap");
  66. $("#textTj ul li").removeClass("l-over");
  67. $("#index_"+banerIndex).closest("li").addClass("l-over");
  68. }
  69. if(!title){
  70. $('#labLi2').toggle(level == 4);
  71. }
  72. $(".c-lab-mor #labLi2").removeClass("hit");
  73. if(level==4){
  74. title = title.substring(0,3);
  75. }
  76. $("#title").html(title);
  77. //底部左边列表 (初始化时只执行一次)
  78. var params ={level: level, area: area, sort: 1, year: chooseYear}
  79. params.index = $("#textTj ul li.l-over").attr("data-index");
  80. //增量(咨询量、随访量、指导量),到达量(绑定微信、绑定设备)
  81. var url = params.index==3?"statistics/lowlevel_total_mesh":params.index==4 || params.index==5 || params.index==27 ?"statistics/lowlevel_total":"statistics/lowlevel_all";
  82. if(params.index==3) params.index="3,22";
  83. if(params.index == 21 || params.index == 20){
  84. params.date = endDate;
  85. }else{
  86. params.endDate = endDate;
  87. }
  88. sendPost(url, params,null,listHandle);
  89. }
  90. //返回事件
  91. mui.back = function(){
  92. if(level==4 || level==roleLevel){
  93. var mainPage =plus.webview.getWebviewById("admin.html");
  94. mui.fire(mainPage, "refreshData");
  95. //关闭筛选页面
  96. var shaixuan = plus.webview.getWebviewById("shaixuan2.html");
  97. if(shaixuan){
  98. shaixuan.close();
  99. }
  100. self.close();
  101. }
  102. else{
  103. level++;
  104. var params = path[level];
  105. if(!params){
  106. level++;
  107. params = path[level];
  108. }
  109. type = params.type;
  110. area = params.area;
  111. title = params.title || userRole.name;
  112. load({type: type, level: level, area: area, fromDate: fromDate, endDate: endDate,title: title});
  113. if(level==4){
  114. title = title.substring(0,3);
  115. }
  116. $("#title").html(title);
  117. $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
  118. $(".c-lab-mor #labLi1").addClass("hit")
  119. }
  120. }
  121. /**
  122. * 初始化筛选事件
  123. */
  124. function shaixuanInit(main){
  125. var shaixuan = plus.webview.getWebviewById('shaixuan2.html');
  126. if(!shaixuan){
  127. shaixuan = mui.createWindow({
  128. id: 'shaixuan2.html',
  129. url: 'shaixuan2.html',
  130. styles: {
  131. top: 0,
  132. bottom: 0,
  133. left: '20%',
  134. width: '80%',
  135. scorllIndicator: "none"
  136. },
  137. show:{
  138. aniShow: "slide-in-right",
  139. duration: "400"
  140. }
  141. });
  142. }
  143. window.addEventListener("hideShaiXuan",function(){
  144. main.setStyle({mask:"none"});
  145. shaixuan.hide();
  146. }, false);
  147. window.addEventListener("showShaiXuan", function() {
  148. shaixuan.show();
  149. main.setStyle({mask:"rgba(0,0,0,0.5)"});
  150. main.addEventListener("maskClick",function(){
  151. main.setStyle({mask:"none"});
  152. shaixuan.hide();
  153. }, false);
  154. });
  155. }
  156. /*****************************************************************************/
  157. /***** 点击事件 **********/
  158. /*****************************************************************************/
  159. function bindEvents(){
  160. //index类别切换
  161. var barImg= $("#textTj li");
  162. barImg.on("tap", function(){
  163. $("#textTj").css("pointer-events","none");
  164. $('#textTj li').removeClass("l-over");
  165. $(this).addClass("l-over");
  166. var index = "index_" + $(this).attr("data-index");
  167. //获取到index值,然后替换information里面的数据
  168. $("#infoText").text(information[$(this).attr("data-index")]);
  169. $("#list ul").hide();
  170. $("#list2 ul").hide();
  171. if($(".c-lab-mor li.hit").attr("id")=="labLi2"){
  172. $("#s_"+ index).show();
  173. }else{
  174. $("#l_"+ index).show();
  175. }
  176. banerIndex = $(".l-qytj-barner .l-over").attr("data-index");
  177. loadLineData(type, level, area, fromDate, endDate,
  178. $('#l-legend li.l-over').attr('data-val'),
  179. $(this).attr("data-index"));
  180. //tab初始化
  181. $(".c-lab-mor li").eq(0).trigger("tap");
  182. $(".c-lab-mor li").eq(1).attr("data-visited","false");
  183. //底部左边列表
  184. var params ={level: level, area: area, sort: 1, year: chooseYear}
  185. params.index = $("#textTj li.l-over").attr("data-index");
  186. //增量(咨询量、随访量、指导量),到达量(绑定微信、绑定设备)
  187. var url = params.index==3?"statistics/lowlevel_total_mesh":params.index==4 || params.index==5 || params.index==27 ?"statistics/lowlevel_total":"statistics/lowlevel_all";
  188. if(params.index==3) params.index="3,22";
  189. if(params.index == 21 || params.index == 20){
  190. params.date = endDate;
  191. }else{
  192. params.endDate = endDate;
  193. }
  194. sendPost(url, params,null,listHandle);
  195. })
  196. //tab切换
  197. $(".c-lab-mor li").on("tap",function(){
  198. var tabid = $(this).attr("id");
  199. var top = $(this).offset().top;
  200. $(".c-lab-mor li").removeClass("hit");
  201. $(this).addClass("hit");
  202. $("#list ul").hide();
  203. $("#list2 ul").hide();
  204. var index = "index_" + $(".l-qytj-barner").find("li.l-over").attr("data-index");
  205. if(tabid=="labLi1"){
  206. $("#list").show();
  207. $("#list2").hide();
  208. $("#l_"+ index).show();
  209. }else{
  210. var visited = $(this).attr("data-visited");
  211. // if(visited == "false"){
  212. var params = {level: level, area: area, sort: 1, year: chooseYear};
  213. params.index = $("#textTj li.l-over").attr("data-index");
  214. var url = params.index==3?"statistics/lowlevel_total_mesh":params.index==4 || params.index==5 || params.index==27?"statistics/lowlevel_total":"statistics/lowlevel_all";
  215. if(params.index==3) params.index="3,22";
  216. if(params.index == 21 || params.index == 20){
  217. params.date = endDate;
  218. }else{
  219. params.endDate = endDate;
  220. }
  221. if(roleLevel==4){//市级管理员才可以查看市下面的所有社区数据
  222. params.lowLevel = 2;
  223. params.level = level;
  224. plus.nativeUI.showWaiting();
  225. sendPost(url, params,null, list2Handle);
  226. delete params.lowLevel;
  227. }
  228. // $(this).attr("data-visited","true");
  229. // }
  230. $("#list").hide();
  231. $("#list2").show();
  232. $("#s_"+ index).removeClass("c-hide").show();
  233. }
  234. scroller1.refresh();
  235. window.onscroll = function () {
  236. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  237. if(top!=-1 && top>0){
  238. window.scrollTo(0,top);
  239. top = -1;
  240. }
  241. }
  242. });
  243. //底部列表的点击事件
  244. $(".list-panel").on('tap', 'li', function(){
  245. var $this = $(this);
  246. if($this.data('next') == 1){
  247. var divId = $this.parent().parent().attr("id");
  248. if(divId == "list"){
  249. level--;
  250. area = $(this).attr("data-code");
  251. var name = $(this).attr("data-name");
  252. title = name;
  253. load({type: type, level: level, area: area, from: fromDate, to: endDate, title: name,index: $("#textTj .l-over").attr("data-index")});
  254. // var name = $(this).attr("data-name");
  255. // title = name;
  256. $("#title").html(title);
  257. $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
  258. path[level] = {type: type, level: level, area: area, from: fromDate, to: endDate, title: name}
  259. }else if(divId == "list2"){
  260. level = 2;
  261. area = $(this).attr("data-code");
  262. load({type: type, level: level, area: area, from: fromDate, to: endDate, title: name});
  263. var name = $(this).attr("data-name");
  264. title = name;
  265. $("#title").html(title);
  266. $('#tjTitle').html("各团队情况");
  267. path[level] = {type: type, level: level, area: area, from: fromDate, to: endDate, title: name}
  268. }
  269. }
  270. })
  271. //日、周、月按钮切换
  272. $(".div-btn-group").on("tap",".div-btn",function(){
  273. var dataId = $(this).attr("data-id");
  274. $(".div-btn-group .div-btn").removeClass("active");
  275. $(this).addClass("active");
  276. loadLineData(type, level, area, fromDate, endDate, dataId,$("#textTj").find('.l-over').attr("data-index"));
  277. });
  278. //左滑筛选区域的数据
  279. $('.header-link').on("tap", function(){
  280. var self = plus.webview.currentWebview();
  281. mui.fire(self, "showShaiXuan");
  282. });
  283. window.addEventListener("refresh", function(e){
  284. chooseYear = e.detail.year;
  285. startDate = getStartDate();
  286. endDate = getEndDate();
  287. //初始显示选中的年份
  288. $(".choose-label").text(chooseYear+"年");
  289. load({type: type, level: level, area: area,title: title, year: chooseYear});
  290. });
  291. //说明信息相关事件
  292. $("#closeBtn").on("tap", function(){
  293. $(".information").hide();
  294. scroller1.refresh();
  295. });
  296. $(".info-icon").on("tap", function(){
  297. $(".information").show();
  298. scroller1.refresh();
  299. });
  300. }
  301. /*****************************************************************************/
  302. /***** 统计数据刷新 **********/
  303. /*****************************************************************************/
  304. function initScroller(){
  305. scroller1 = $("#wrapper1").initScroll(
  306. {
  307. pullDownAction: function(){
  308. plus.nativeUI.showWaiting();
  309. $(".pullUp").hide();
  310. type = type;
  311. level = level;
  312. area = area;
  313. load({type: type, level: level, area: area,title: title});
  314. $(".c-lab-mor #labLi1").addClass("hit");
  315. $(".c-lab-mor #labLi2").removeClass("hit");
  316. $(".div-list").show();
  317. $(".div-list2").hide();
  318. },pullUpAction: function() {
  319. $(".pullUp").hide();
  320. return false;
  321. }
  322. }
  323. );
  324. }
  325. $('.l-refresh').on("tap", function(){
  326. self = plus.webview.currentWebview();
  327. type = self.type;
  328. level = self.level;
  329. area = self.area;
  330. load({type: type, level: level, area: area,title: title});
  331. $(".c-lab-mor #labLi1").addClass("hit");
  332. })
  333. /*****************************************************************************/
  334. /***** 统计数据初始化 **********/
  335. /*****************************************************************************/
  336. //加载数据
  337. function loadData(type, level, area, date){
  338. clearData(type);
  339. var params = {level: level, area: area, endDate: date, year: chooseYear}
  340. for(var k in indexs){
  341. params.index = indexs[k];
  342. loadAmount(params);
  343. }
  344. if(level==4){//市级管理员才可以查看市下面的所有社区数据
  345. $(".c-lab-mor #labLi2").removeClass("c-hide");
  346. }
  347. if(type==1){//从签约分析跳转过来
  348. $(".div-lv").removeClass("c-hide");
  349. }
  350. }
  351. /*****************************************************************************/
  352. /***** 折线图初始化 **********/
  353. /*****************************************************************************/
  354. var dateData = {};
  355. function loadLineData(type, level, area, from, to, interval, index){
  356. var level =level;
  357. plus.nativeUI.showWaiting();
  358. //增量(咨询量、随访量、指导量),到达量(绑定微信、绑定设备)
  359. var activeIndexss = banerIndex || $(".l-qytj-barner li.l-over").attr('data-index');
  360. var url = (activeIndexss==3 || activeIndexss==4 || activeIndexss==5 || activeIndexss==27)? "statistics/interval" : "/statistics/interval_total";
  361. // if(from=='')
  362. // from = '2016-08-01';
  363. var fromDate = startDate;
  364. // if(activeIndexss == 21 || activeIndexss == 20){
  365. // fromDate = "2016-08-01";
  366. // }
  367. var params = {level: level, area: area, startDate: fromDate, endDate: endDate,
  368. interval: $(".div-btn-group .div-btn.active").attr("data-id")}
  369. params.index = banerIndex || $(".l-qytj-barner li.l-over").attr('data-index');
  370. sendPost(url, params, null, dateLineHandle);
  371. }
  372. /**
  373. * 获取多少天前的日期
  374. */
  375. function getDateBefore(days) {
  376. var now = new Date();
  377. var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
  378. var year = date.getFullYear();
  379. var month = date.getMonth() + 1;
  380. var day = date.getDate();
  381. var hour = date.getHours();
  382. var minute = date.getMinutes();
  383. var second = date.getSeconds();
  384. return year + '/' + (month < 10 ? '0' + month : month) + '/' + (day < 10 ? '0' + day : day);
  385. }
  386. //获取数据最大值
  387. function maxData(data){
  388. var maxData = Math.max.apply(Math,data);
  389. var yAxis = maxData<10?10:maxData;
  390. return yAxis;
  391. }
  392. //初始化折线图
  393. function drawChart(dateData){
  394. var recordCount = 10;//一页显示几条数据
  395. var allRecordData = dateData.amountArr.reverse();
  396. var dateArr = dateData.dateArr.reverse();
  397. var resultData = _.groupBy(allRecordData,function(item,i){return Math.floor(i/recordCount)});
  398. var dateArrData = _.groupBy(dateArr,function(item,i){return Math.floor(i/recordCount)});
  399. //以下为折线图处理
  400. var gnum = Math.ceil(allRecordData.length / recordCount);
  401. var HandStartX,HandStartY,HandEndX,HandEndY,CountX,CountY,startPos,isScrolling,number=allRecordData.length,times=allRecordData.length%recordCount;
  402. var canvasStr = '<div class="div-layer"></div>';
  403. for(var x in resultData){
  404. canvasStr = '<canvas id="wcMotion'+x+'" class="canvas-wc animated" style="display:block"></canvas>'+canvasStr;
  405. }
  406. $(".l-zxt-inner").html(canvasStr);
  407. var dateType = $(".div-btn-group .div-btn.active").attr("data-id");
  408. window.setTimeout(function() {
  409. for(var x in resultData){
  410. var startDay = new Date(getDateBefore(times-1));
  411. var resultDateArr = dateArrData[x].reverse();
  412. var yAxis = maxData(resultData[x]);//求数据的最大值
  413. $('#wcMotion'+x).wcChart({
  414. height: 200, // width and height must be set if change
  415. yAxis:yAxis,
  416. day: startDay,
  417. points: [],
  418. dateType:dateType,
  419. dateArr:resultDateArr,
  420. data: resultData[x].reverse(),
  421. fill: {gradient: [["#17B3EC",.1], ["#17B3EC",.5]], gradientAngle: Math.PI * -45/180},
  422. animation: null // 修复bug#3298 【医生端】总体分析排版优化。(vivo手机)
  423. });
  424. if(x==0){
  425. $('#wcMotion'+x).show();
  426. }
  427. times+=recordCount;
  428. //折线图画布添加左滑和右滑效果
  429. var wcMotion = document.getElementById('wcMotion'+x);
  430. wcMotion.addEventListener('touchstart', function(event) {
  431. HandStartX=event.touches[0].clientX;
  432. HandStartY=event.touches[0].clientY;
  433. //touches数组对象获得屏幕上所有的touch,取第一个touch
  434. var touch = event.targetTouches[0];
  435. //取第一个touch的坐标值
  436. startPos = {x:touch.pageX,y:touch.pageY,time:+new Date};
  437. //这个参数判断是垂直滚动还是水平滚动
  438. isScrolling = 0;
  439. }, false);
  440. wcMotion.addEventListener('touchend', function(event) {
  441. HandEndX=event.changedTouches[0].clientX;
  442. HandEndY=event.changedTouches[0].clientY;
  443. CountX=HandEndX-HandStartX;
  444. CountY=HandEndY-HandStartY;
  445. if((Math.abs(CountX)>Math.abs(CountY))&& Math.abs(CountX)>50){
  446. var targetMotion = $(event.target);
  447. if(CountX<0){
  448. if(targetMotion.next().length>0 && !targetMotion.next().hasClass("div-layer")){
  449. targetMotion.siblings().hide();
  450. targetMotion.addClass("fadeOutLeft");
  451. targetMotion.next().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInLeft").addClass("fadeInRight").show();
  452. }
  453. console.log("左滑");
  454. }else{
  455. if(targetMotion.prev().length>0 && !targetMotion.prev().hasClass("div-layer")){
  456. targetMotion.siblings().hide();
  457. targetMotion.addClass("fadeOutRight");
  458. targetMotion.prev().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInRight").addClass("fadeInLeft").show();
  459. }
  460. console.log("右滑");
  461. }
  462. }
  463. }, false);
  464. wcMotion.addEventListener('touchmove', function(event) {
  465. //当屏幕有多个touch或者页面被缩放过,就不执行move操作
  466. if(event.targetTouches.length > 1 || event.scale && event.scale !== 1) return;
  467. var touch = event.targetTouches[0];
  468. endPos = {x:touch.pageX - startPos.x,y:touch.pageY - startPos.y};
  469. //isScrolling为1时,表示纵向滑动,0为横向滑动
  470. isScrolling = Math.abs(endPos.x) < Math.abs(endPos.y) ? 1:0;
  471. if(isScrolling === 0){
  472. //阻止触摸事件的默认行为,即阻止滚屏
  473. event.preventDefault();
  474. }
  475. }, false);
  476. }
  477. }, 500);
  478. }
  479. function dateLineHandle(res){
  480. var activeIndexss = banerIndex || $(".l-qytj-barner li.l-over").attr('data-index');
  481. if(res.status==200){
  482. for(var p in res.data){
  483. dateData[p] = activeIndexss=="20" || activeIndexss=="21"?formatDateData(res.data[p].data):formatDateData(res.data[p]);
  484. if(dateData[p].amountArr && dateData[p].amountArr.length>0){
  485. // $('#l-jmfx').toggle(p == "index_1" );
  486. $('#l-jmfx').show();
  487. $(".l-zxt-con").hide();
  488. mui.later(function(){
  489. $(".l-zxt-con").show();
  490. }, 100);
  491. $('#l-legend').hide();
  492. $("#echarts_wushuju").hide();
  493. $('#l-times').html(type==1? '(人)' : '(次)').hide();
  494. } else{
  495. $(".l-zxt-con").hide();
  496. $("#echarts_wushuju").show();
  497. $('#l-legend').hide();
  498. }
  499. drawChart(dateData[p]);//初始化折线图
  500. setTimeout(function(){
  501. $("#textTj").css("pointer-events","");
  502. plus.nativeUI.closeWaiting();
  503. },1000)
  504. }
  505. } else {
  506. mui.toast(res.msg);
  507. }
  508. }
  509. //折线图数据格式转化
  510. function formatDateData(data){
  511. var dateArr = [];
  512. var amountArr = [];
  513. for(var k in data){
  514. dateArr.push(data[k].range.substring(5));
  515. amountArr.push(data[k].amount);
  516. }
  517. return {dateArr: dateArr, amountArr: amountArr};
  518. }
  519. //获取当前时间
  520. endDate = getNowDate();
  521. function getNowDate() {
  522. var date = new Date();
  523. var month = date.getMonth() + 1;
  524. var strDate = date.getDate();
  525. if (month >= 1 && month <= 9) {
  526. month = "0" + month;
  527. }
  528. if (strDate >= 0 && strDate <= 9) {
  529. strDate = "0" + strDate;
  530. }
  531. var currentdate = date.getFullYear() + "-" + month + "-" + strDate;
  532. return currentdate;
  533. }
  534. function clearData(type){
  535. $("#textTj li").removeClass("l-over");
  536. if(!banerIndex){
  537. $("#textTj li").eq(0).addClass("l-over");
  538. }
  539. $('#l-jmfx').hide();
  540. $("#list").empty();
  541. $("#list2").empty();
  542. $(".l-data").html("0");
  543. }
  544. //后台接收数据
  545. function loadAmount(params){
  546. //数据截止时间
  547. sendPost("/statistics/time",null,function(res){
  548. },function(res){
  549. if(res.status=="200"){
  550. var date = (res.data && res.data.substring(11,16)) || "";
  551. $(".jiezhi-time").html(date);
  552. }
  553. })
  554. //增量(咨询量、随访量、指导量),到达量(绑定微信、绑定设备)
  555. var url = "statistics/total";
  556. if(params.index == 20 || params.index == 21){
  557. url = "statistics/index_all";
  558. }else{
  559. params.startDate = startDate; //增量需要开始时间和结束时间
  560. }
  561. sendPost(url, params, null, countHandle);
  562. }
  563. //获取左下列表
  564. function listHandle(res){
  565. if(res.status == 200) {
  566. template.helper("setRate", function(all, amount){
  567. if(all == 0)
  568. return 0;
  569. return (amount / all * 100).toFixed(2);
  570. });
  571. res = res.data;
  572. var $div;
  573. for(var k in res){
  574. var curIndex = k.split("index_")[1];
  575. var list = res[k];
  576. if(curIndex=="3"){//咨询量
  577. for(var i=0;i<list.length;i++){
  578. var amount = list[i].amount.split(",");
  579. list[i].amount = amount[0];//咨询量
  580. list[i].noAmount = amount[1];//未回复咨询量
  581. }
  582. }
  583. var topArr = [];
  584. if(curIndex == "21"){
  585. topArr = soreRank(bindRateArr(list));
  586. // topArr = soreRank(amountArr(list));
  587. }else{
  588. topArr = soreRank(amountArr(list));
  589. }
  590. for(var j in list){
  591. list[j].top = topArr[j];
  592. }
  593. if(curIndex=="1" && level!=2){
  594. res.rateName = "签约率";
  595. for(var j in list){
  596. if(list[j].rate){
  597. list[j].rate = list[j].rate.substring(0,4);
  598. }
  599. }
  600. }
  601. res.all = assAmount(list);
  602. res.amountName = indexName[k];
  603. res.list = list;
  604. res.level = level;
  605. res.index = curIndex;
  606. var indexF = banerIndex!=undefined?"index_"+banerIndex:'index_3'
  607. $div = $('<ul id="l_'+k+'" class="l-gq-list '+ (k!=indexF? 'c-hide': '') +'"></ul>');
  608. $('#l_'+k).remove();
  609. }
  610. //查看下一级详情
  611. if($div){
  612. //如果是微信绑定或设备绑定,则增加置顶展示当面层级的总绑定率及已缴费 未缴费居民数
  613. if(curIndex == '21'){
  614. var url = "/statistics/getLevelTotalSingle",
  615. params = {date: endDate, level: level, area: area};
  616. sendPost(url, params, null, function(res2){
  617. if(res2.status == 200){
  618. var html = template('top_li', res2.data);
  619. $div.append(html);
  620. $div.append(template("list_tmpl", res));
  621. $("#list").append($div);
  622. scroller1.refresh();
  623. plus.nativeUI.closeWaiting();
  624. }else{
  625. mui.toast(res2.msg);
  626. }
  627. }, 'post', '', true);
  628. return ;
  629. }else{
  630. $div.append(template("list_tmpl", res));
  631. $("#list").append($div);
  632. scroller1.refresh();
  633. plus.nativeUI.closeWaiting();
  634. }
  635. // var width = $(".l-qytj-barner li[data-index=3]").width();
  636. // $(".band-weixin").width(width).css("display","inline-block");
  637. // $(".band-dervice").width(width).css("display","inline-block");
  638. }
  639. } else {
  640. mui.toast(res.msg);
  641. }
  642. }
  643. //右下列表
  644. function list2Handle(res){
  645. if(res.status == 200) {
  646. template.helper("setRate", function(all, amount){
  647. if(all == 0)
  648. return 0;
  649. return (amount / all * 100).toFixed(2);
  650. });
  651. res = res.data;
  652. var $div;
  653. for(var k in res){
  654. var curIndex = k.split("index_")[1];
  655. var list = res[k];
  656. if(curIndex=="3"){//咨询量
  657. for(var i=0;i<list.length;i++){
  658. var amount = list[i].amount.split(",");
  659. list[i].amount = amount[0];//咨询量
  660. list[i].noAmount = amount[1];//未回复咨询量
  661. }
  662. }
  663. var topArr = [];
  664. if(curIndex == "21"){
  665. topArr = soreRank(bindRateArr(list));
  666. // topArr = soreRank(amountArr(list));
  667. }else{
  668. topArr = soreRank(amountArr(list));
  669. }
  670. for(var j in list){
  671. list[j].top = topArr[j];
  672. }
  673. if(curIndex=="1" && level!=2){
  674. res.rateName = "签约率";
  675. for(var j in list){
  676. if(list[j].rate){
  677. list[j].rate = list[j].rate.substring(0,4);
  678. }
  679. }
  680. }
  681. res.all = assAmount(list);
  682. res.amountName = indexName[k];
  683. res.list = list;
  684. res.level = level;
  685. res.index = curIndex;
  686. $div = $('<ul id="s_'+k+'" class="l-gq-list '+ (k!='index_1' && k!='index_3'? '': '') +'"></ul>');
  687. $('#s_'+k).remove();
  688. }
  689. if($div){
  690. $div.append(template("list_tmpl", res));
  691. $("#list2").append($div);
  692. setTimeout(function(){
  693. if(banerIndex==curIndex){
  694. $("#list ul").hide();
  695. $("#l_index_"+ banerIndex).show();
  696. $('#l-jmfx').toggle($(".l-qytj-barner .l-over").attr("data-index")=="1");
  697. }
  698. },300)
  699. scroller1.refresh();
  700. plus.nativeUI.closeWaiting();
  701. }
  702. } else {
  703. mui.toast(res.msg);
  704. }
  705. }
  706. function countHandle(res){
  707. if(res.status == 200) {
  708. res = res.data;
  709. for(var k in res){
  710. $('#'+ k).html(res[k]);
  711. }
  712. } else {
  713. mui.toast(res.msg);
  714. }
  715. }
  716. //数量数组
  717. function amountArr(list){
  718. var amountArr = [];
  719. for(var k in list){
  720. amountArr.push(list[k].amount);
  721. }
  722. return amountArr;
  723. }
  724. //绑定率数组
  725. function bindRateArr(list){
  726. var arr = [];
  727. for(var k in list){
  728. arr.push(list[k].bindRate);
  729. }
  730. return arr;
  731. }
  732. //格式化数量
  733. function assAmount(list){
  734. var all = 0;
  735. for(var k in list){
  736. all += parseInt(list[k].amount);
  737. }
  738. return all;
  739. }
  740. //排序
  741. function soreRank(arr) {
  742. var temp = [];
  743. var lis = [];
  744. for(var i=0;i<arr.length;i++)
  745. lis.push(arr[i])
  746. lis = _.uniq(lis);
  747. for(var i=0;i<arr.length;i++)
  748. temp[i] = lis.indexOf(arr[i])+1;
  749. return temp;
  750. }
  751. function getStartDate(){
  752. // 按年度来计算的时候,开始时间是该年度7月1号还是到下一个年的6月30号结束
  753. if(chooseYear == 2016){
  754. return chooseYear + "-08-01";
  755. }else{
  756. return chooseYear+'-07-01';
  757. }
  758. }
  759. //获取结束时间
  760. function getEndDate(){
  761. chooseYear = parseInt(chooseYear);
  762. var endDate = new Date((chooseYear+1) + '-06-30'),
  763. now = new Date();
  764. if(now <= endDate){
  765. var month = now.getMonth()+1,
  766. date1 = now.getDate();
  767. if(month < 10){
  768. month = "0"+month;
  769. }
  770. if(date1 < 10){
  771. date1 = "0"+date1;
  772. }
  773. return now.getFullYear()+"-"+month+"-"+date1;
  774. }else{
  775. return (chooseYear+1) + '-06-30';
  776. }
  777. }
  778. document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);