tuigaiqian.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. var self;
  2. var type, level, area, indexs, title,sort=1,banerIndex;
  3. var path = {};
  4. var roleLevel, userRole;
  5. var indexName = {'index_2': '退签人数:', 'index_9': '待审核数:', 'index_10': '改签人数:'}
  6. //绑定按钮事件
  7. bindEvents();
  8. //初始化事件
  9. mui.plusReady(function() {
  10. self = plus.webview.currentWebview();
  11. type = self.type;
  12. level = self.level;
  13. area = self.area;
  14. mui.later(function(){
  15. mui.fire(self, "loadData", {type: type, level: level, area: area});
  16. },500)
  17. //下拉刷新初始化
  18. initScroller();
  19. });
  20. function initScroller(){
  21. scroller1 = $("#wrapper1").initScroll(
  22. {
  23. pullDownAction: function(){
  24. $(".pullUp").hide();
  25. plus.nativeUI.showWaiting();
  26. type = type;
  27. level = level;
  28. area = area;
  29. mui.later(function(){
  30. mui.fire(self, "loadData", {type: type, level: level, area: area,title:title});
  31. },500)
  32. $(".c-lab-mor #labLi1").addClass("hit");
  33. $(".c-lab-mor #labLi2").removeClass("hit");
  34. $(".div-list").show();
  35. $(".div-list2").hide();
  36. },pullUpAction: function() {
  37. $(".pullUp").hide();
  38. return false;
  39. }
  40. }
  41. );
  42. }
  43. $('.l-refresh').on("tap", function(){
  44. self = plus.webview.currentWebview();
  45. type = self.type;
  46. level = self.level;
  47. area = self.area;
  48. mui.later(function(){
  49. mui.fire(self, "loadData", {type: type, level: level, area: area});
  50. },500)
  51. $(".c-lab-mor #labLi1").addClass("hit");
  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. self.close();
  59. }
  60. else{
  61. level++;
  62. var params = path[level];
  63. if(!params){
  64. level++;
  65. params = path[level];
  66. }
  67. type = params.type;
  68. area = params.area;
  69. load(type, level, area, params.from, params.to);
  70. title = params.title || userRole.name;
  71. if(level==4){
  72. title = title.substring(0,3);
  73. }
  74. $("#title").html(title);
  75. $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
  76. $(".c-lab-mor #labLi1").addClass("hit")
  77. }
  78. }
  79. function bindEvents(){
  80. //标签切换
  81. $(".c-lab-mor li").click(function(){
  82. var tabid = $(this).attr("id");
  83. var top = $(this).offset().top;
  84. $(".c-lab-mor li").removeClass("hit");
  85. $(this).addClass("hit");
  86. $("#list div.l-list").hide();
  87. $("#list2 div.l-list").hide();
  88. var index = "index_" + $(".l-qytj-barner").find("li.l-over").attr("data-index");
  89. if(tabid=="labLi1"){
  90. $("#list").show();
  91. $("#list2").hide();
  92. $("#l_"+ index).show();
  93. }else{
  94. $("#list").hide();
  95. $("#list2").show();
  96. $("#s_"+ index).show();
  97. }
  98. scroller1.refresh();
  99. window.onscroll = function () {
  100. var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  101. if(top!=-1 && top>0){
  102. window.scrollTo(0,top);
  103. top = -1;
  104. }
  105. }
  106. });
  107. //日、周、月按钮切换
  108. $(".div-btn-group").on("click",".div-btn",function(){
  109. var dataId = $(this).attr("data-id");
  110. $(".div-btn-group .div-btn").removeClass("active");
  111. $(this).addClass("active");
  112. var dateArr = dataPicker.getValue();
  113. loadLineData(type, level, area, dateArr.from, dateArr.to,
  114. dataId,
  115. $("#textTj").find('.l-over').attr("data-index"));
  116. });
  117. }
  118. /*****************************************************************************/
  119. /***** 统计数据初始化 **********/
  120. /*****************************************************************************/
  121. //加载数据
  122. function loadData(type, level, area, from, to){
  123. clearData(type);
  124. var params = {level: level, area: area, startDate: from, endDate: to}
  125. for(var k in indexs){
  126. params.index = indexs[k];
  127. loadAmount(params);
  128. }
  129. if(level==4){//市级管理员才可以查看市下面的所有社区数据
  130. $(".c-lab-mor #labLi2").removeClass("c-hide");
  131. }
  132. }
  133. //后台接收数据
  134. function loadAmount(params){
  135. sendPost("/statistics/time",null,function(res){
  136. },function(res){
  137. if(res.status=="200"){
  138. var date = (res.data && res.data.substring(11,16)) || "";
  139. $(".jiezhi-time").html(date)
  140. }
  141. })
  142. sendPost("/statistics/index_all", params,
  143. null,
  144. countHandle);
  145. params.sort = 1;//排序(0:升序 1:降序)
  146. params.date = params.endDate;
  147. sendPost("/statistics/lowlevel_all", params,
  148. null,
  149. listHandle);
  150. if($(".c-lab-mor #labLi2").css("display")!="none"){
  151. if(roleLevel==4){//市级管理员才可以查看市下面的所有社区数据
  152. params.lowLevel = 2;
  153. sendPost("/statistics/lowlevel_all", params,
  154. null,
  155. list2Handle);
  156. delete params.lowLevel;
  157. }
  158. }
  159. }
  160. //格式化数量
  161. function assAmount(list){
  162. var all = 0;
  163. for(var k in list){
  164. all += list[k].amount;
  165. }
  166. return all;
  167. }
  168. //排序
  169. function soreRank(arr) {
  170. var temp = [];
  171. var lis = [];
  172. for(var i=0;i<arr.length;i++)
  173. lis.push(arr[i])
  174. lis = _.uniq(lis);
  175. // lis.sort();
  176. // lis.reverse();
  177. for(var i=0;i<arr.length;i++)
  178. temp[i] = lis.indexOf(arr[i])+1;
  179. return temp;
  180. }
  181. //数量数组
  182. function amountArr(list){
  183. var amountArr = [];
  184. for(var k in list){
  185. amountArr.push(list[k].amount);
  186. }
  187. return amountArr;
  188. }
  189. function listHandle(res){
  190. if(res.status == 200) {
  191. template.helper("setRate", function(all, amount){
  192. if(all == 0)
  193. return 0;
  194. return (amount / all * 100).toFixed(2);
  195. });
  196. res = res.data;
  197. var $div;
  198. for(var k in res){
  199. var curIndex = k.split("index_")[1];
  200. var list = res[k];
  201. var topArr = soreRank(amountArr(list));
  202. for(var j in list){
  203. list[j].top = topArr[j];
  204. }
  205. if(curIndex=="1" && level!=2){
  206. res.rateName = "签约率";
  207. for(var j in list){
  208. if(list[j].rate){
  209. list[j].rate = list[j].rate.substring(0,4);
  210. }
  211. }
  212. }
  213. res.all = assAmount(list);
  214. res.amountName = indexName[k];
  215. res.list = list;
  216. res.level = level;
  217. var indexF = banerIndex!=undefined?"index_"+banerIndex:'index_9'
  218. $div = $('<div id="l_'+k+'" class="l-list clearfix '+ (k!=indexF? 'c-hide': '') +'"></div>');
  219. $('#l_'+k).remove();
  220. }
  221. if($div){
  222. $div.append(template("list_tmpl", res));
  223. if(level>2){
  224. $("li", $div).on("tap", function(){
  225. var v = dataPicker.getValue();
  226. level--;
  227. area = $(this).attr("data-code");
  228. load(type, level, area, v.from, v.to);
  229. var name = $(this).attr("data-name");
  230. title = name;
  231. $("#title").html(title);
  232. // mui.fire(plus.webview.getWebviewById("qianyuetongji1.html"),
  233. // "setTitle", {title: name});
  234. $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
  235. path[level] = {type: type, level: level, area: area, from: v.from, to: v.to, title: name}
  236. })
  237. }
  238. $("#list").append($div);
  239. scroller1.refresh();
  240. plus.nativeUI.closeWaiting();
  241. }
  242. } else {
  243. mui.toast(res.msg);
  244. }
  245. }
  246. function list2Handle(res){
  247. if(res.status == 200) {
  248. template.helper("setRate", function(all, amount){
  249. if(all == 0)
  250. return 0;
  251. return (amount / all * 100).toFixed(2);
  252. });
  253. res = res.data;
  254. var $div;
  255. for(var k in res){
  256. var curIndex = k.split("index_")[1];
  257. var list = res[k];
  258. var topArr = soreRank(amountArr(list));
  259. for(var j in list){
  260. list[j].top = topArr[j];
  261. }
  262. if(curIndex=="1" && level!=2){
  263. res.rateName = "签约率";
  264. for(var j in list){
  265. if(list[j].rate){
  266. list[j].rate = list[j].rate.substring(0,4);
  267. }
  268. }
  269. }
  270. res.all = assAmount(list);
  271. res.amountName = indexName[k];
  272. res.list = list;
  273. res.level = level;
  274. $div = $('<div id="s_'+k+'" class="l-list clearfix '+ (k!='index_1' && k!='index_3'? 'c-hide': '') +'"></div>');
  275. $('#s_'+k).remove();
  276. }
  277. if($div){
  278. $div.append(template("list_tmpl", res));
  279. $("li", $div).on("tap", function(){
  280. var v = dataPicker.getValue();
  281. level = 2;
  282. area = $(this).attr("data-code");
  283. load(type, level, area, v.from, v.to);
  284. var name = $(this).attr("data-name");
  285. title = name;
  286. $("#title").html(title);
  287. $('#tjTitle').html("各团队情况");
  288. path[level] = {type: type, level: level, area: area, from: v.from, to: v.to, title: name}
  289. })
  290. $("#list2").append($div);
  291. setTimeout(function(){
  292. if(banerIndex==curIndex){
  293. $("#list div.l-list").hide();
  294. $("#l_index_"+ banerIndex).show();
  295. $('#l-jmfx').toggle($(".l-qytj-barner .l-over").attr("data-index")=="1");
  296. }
  297. },300)
  298. scroller1.refresh();
  299. plus.nativeUI.closeWaiting();
  300. }
  301. } else {
  302. mui.toast(res.msg);
  303. }
  304. }
  305. function countHandle(res){
  306. if(res.status == 200) {
  307. res = res.data;
  308. for(var k in res){
  309. $('#'+ k).html(res[k]);
  310. }
  311. } else {
  312. mui.toast(res.msg);
  313. }
  314. }
  315. function clearData(type){
  316. $("#textTj li").removeClass("l-over");
  317. if(!banerIndex){
  318. // if(type==1){
  319. // $("#textTj li").eq(0).addClass("l-over");
  320. // } else {
  321. // $("#textTj li").eq(4).addClass("l-over");
  322. // }
  323. $("#textTj li").eq(0).addClass("l-over");
  324. }
  325. $('#l-jmfx').hide();
  326. $("#list").empty();
  327. $("#list2").empty();
  328. $(".l-data").html("0");
  329. }
  330. /*****************************************************************************/
  331. /***** 折线图初始化 **********/
  332. /*****************************************************************************/
  333. var dateData = {};
  334. function loadLineData(type, level, area, from, to, interval, index){
  335. plus.nativeUI.showWaiting();
  336. var url = "/statistics/interval_total";
  337. if(from=='')
  338. from = '2016-08-01';
  339. var params = {level: level, area: area, startDate: from, endDate: to,
  340. interval: $(".div-btn-group .div-btn.active").attr("data-id")}
  341. params.index = banerIndex || $(".l-qytj-barner li.l-over").attr('data-index');
  342. console.log("$"+JSON.stringify(params))
  343. sendPost(url, params, null, dateLineHandle);
  344. }
  345. /**
  346. * 获取多少天前的日期
  347. */
  348. function getDateBefore(days) {
  349. var now = new Date();
  350. var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
  351. var year = date.getFullYear();
  352. var month = date.getMonth() + 1;
  353. var day = date.getDate();
  354. var hour = date.getHours();
  355. var minute = date.getMinutes();
  356. var second = date.getSeconds();
  357. return year + '/' + (month < 10 ? '0' + month : month) + '/' + (day < 10 ? '0' + day : day);
  358. }
  359. //获取数据最大值
  360. function maxData(data){
  361. var maxData = Math.max.apply(Math,data);
  362. var yAxis = maxData<10?10:maxData;
  363. return yAxis;
  364. }
  365. //初始化折线图
  366. function drawChart(dateData){
  367. var recordCount = 10;//一页显示几条数据
  368. var allRecordData = dateData.amountArr.reverse();
  369. var dateArr = dateData.dateArr.reverse();
  370. var resultData = _.groupBy(allRecordData,function(item,i){return Math.floor(i/recordCount)});
  371. var dateArrData = _.groupBy(dateArr,function(item,i){return Math.floor(i/recordCount)});
  372. //以下为折线图处理
  373. var gnum = Math.ceil(allRecordData.length / recordCount);
  374. var HandStartX,HandStartY,HandEndX,HandEndY,CountX,CountY,startPos,isScrolling,number=allRecordData.length,times=allRecordData.length%recordCount;
  375. var canvasStr = '<div class="div-layer"></div>';
  376. for(var x in resultData){
  377. canvasStr='<canvas id="wcMotion'+x+'" class="canvas-wc animated" style="display:block"></canvas>'+canvasStr;
  378. }
  379. $(".l-zxt-inner").html(canvasStr);
  380. var dateType = $(".div-btn-group .div-btn.active").attr("data-id");
  381. window.setTimeout(function() {
  382. for(var x in resultData){
  383. var startDay = new Date(getDateBefore(times-1));
  384. var resultDateArr = dateArrData[x].reverse();
  385. var yAxis = maxData(resultData[x]);//求数据的最大值
  386. $('#wcMotion'+x).wcChart({
  387. height: 200, // width and height must be set if change
  388. yAxis:yAxis,
  389. day: startDay,
  390. points: [],
  391. dateArr:resultDateArr,
  392. dateType:dateType,
  393. data: resultData[x].reverse(),
  394. fill: {gradient: [["#17B3EC",.1], ["#17B3EC",.5]], gradientAngle: Math.PI * -45/180},
  395. animation: null // 修复bug#3298 【医生端】总体分析排版优化。(vivo手机)
  396. });
  397. if(x==0){
  398. $('#wcMotion'+x).show();
  399. }
  400. times+=recordCount;
  401. //折线图画布添加左滑和右滑效果
  402. var wcMotion = document.getElementById('wcMotion'+x);
  403. wcMotion.addEventListener('touchstart', function(event) {
  404. HandStartX=event.touches[0].clientX;
  405. HandStartY=event.touches[0].clientY;
  406. //touches数组对象获得屏幕上所有的touch,取第一个touch
  407. var touch = event.targetTouches[0];
  408. //取第一个touch的坐标值
  409. startPos = {x:touch.pageX,y:touch.pageY,time:+new Date};
  410. //这个参数判断是垂直滚动还是水平滚动
  411. isScrolling = 0;
  412. }, false);
  413. wcMotion.addEventListener('touchend', function(event) {
  414. HandEndX=event.changedTouches[0].clientX;
  415. HandEndY=event.changedTouches[0].clientY;
  416. CountX=HandEndX-HandStartX;
  417. CountY=HandEndY-HandStartY;
  418. if((Math.abs(CountX)>Math.abs(CountY))&& Math.abs(CountX)>50){
  419. var targetMotion = $(event.target);
  420. if(CountX<0){
  421. if(targetMotion.next().length>0 && !targetMotion.next().hasClass("div-layer")){
  422. targetMotion.siblings().hide();
  423. targetMotion.addClass("fadeOutLeft");
  424. targetMotion.next().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInLeft").addClass("fadeInRight").show();
  425. }
  426. console.log("左滑");
  427. }else{
  428. if(targetMotion.prev().length>0 && !targetMotion.prev().hasClass("div-layer")){
  429. targetMotion.siblings().hide();
  430. targetMotion.addClass("fadeOutRight");
  431. targetMotion.prev().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInRight").addClass("fadeInLeft").show();
  432. }
  433. console.log("右滑");
  434. }
  435. }
  436. }, false);
  437. wcMotion.addEventListener('touchmove', function(event) {
  438. //当屏幕有多个touch或者页面被缩放过,就不执行move操作
  439. if(event.targetTouches.length > 1 || event.scale && event.scale !== 1) return;
  440. var touch = event.targetTouches[0];
  441. endPos = {x:touch.pageX - startPos.x,y:touch.pageY - startPos.y};
  442. //isScrolling为1时,表示纵向滑动,0为横向滑动
  443. isScrolling = Math.abs(endPos.x) < Math.abs(endPos.y) ? 1:0;
  444. if(isScrolling === 0){
  445. //阻止触摸事件的默认行为,即阻止滚屏
  446. event.preventDefault();
  447. }
  448. }, false);
  449. }
  450. }, 500);
  451. }
  452. function dateLineHandle(res){
  453. if(res.status==200){
  454. for(var p in res.data){
  455. dateData[p] = formatDateData(res.data[p]);
  456. if(dateData[p].amountArr && dateData[p].amountArr.length>0){
  457. // $('#l-jmfx').toggle(p == "index_1" );
  458. $('#l-jmfx').show();
  459. $(".l-zxt-con").hide();
  460. mui.later(function(){
  461. $(".l-zxt-con").show();
  462. }, 100);
  463. $('#l-legend').hide();
  464. $("#echarts_wushuju").hide();
  465. $('#l-times').html(type==1? '(人)' : '(次)').hide();
  466. } else{
  467. $(".l-zxt-con").hide();
  468. $("#echarts_wushuju").show();
  469. $('#l-legend').hide();
  470. }
  471. drawChart(dateData[p]);//初始化折线图
  472. setTimeout(function(){
  473. $("#textTj").css("pointer-events","");
  474. plus.nativeUI.closeWaiting();
  475. },1000)
  476. }
  477. } else {
  478. mui.toast(res.msg);
  479. }
  480. }
  481. //折线图数据格式转化
  482. function formatDateData(data){
  483. var dateArr = [];
  484. var amountArr = [];
  485. data = data.data
  486. for(var k in data){
  487. dateArr.push(data[k].range.substring(5));
  488. amountArr.push(data[k].amount);
  489. }
  490. return {dateArr: dateArr, amountArr: amountArr};
  491. }
  492. /*****************************************************************************/
  493. /***** 中间图标点击事件 **********/
  494. /*****************************************************************************/
  495. var barImg= $("#textTj li");
  496. barImg.on("tap", function(){
  497. $("#textTj").css("pointer-events","none");
  498. $('#textTj li').removeClass("l-over");
  499. $(this).addClass("l-over");
  500. var index = "index_" + $(this).attr("data-index");
  501. $("#list div.l-list").hide();
  502. $("#list2 div.l-list").hide();
  503. if($(".c-lab-mor li.hit").attr("id")=="labLi2"){
  504. $("#s_"+ index).show();
  505. }else{
  506. $("#l_"+ index).show();
  507. }
  508. banerIndex = $(".l-qytj-barner .l-over").attr("data-index");
  509. var dateArr = dataPicker.getValue();
  510. loadLineData(type, level, area, dateArr.from, dateArr.to,
  511. $('#l-legend li.l-over').attr('data-val'),
  512. $(this).attr("data-index"));
  513. })
  514. $("#l-jmfx").on("tap", function(){
  515. var dateArr = dataPicker.getValue();
  516. var checked = dataPicker.getChecked();
  517. mui.openWindow({
  518. url: "analysis1.html",
  519. id: "analysis1.html",
  520. extras:{
  521. startDate: dateArr.from,
  522. endDate: dateArr.to,
  523. area: area,
  524. level: level,
  525. title: title,
  526. checked: checked
  527. },
  528. })
  529. })
  530. $('#l-legend li').on('tap', function(){
  531. $('#l-legend li').removeClass('l-over');
  532. $(this).addClass('l-over');
  533. var dateArr = dataPicker.getValue();
  534. loadLineData(type, level, area, dateArr.from, dateArr.to,
  535. $(this).attr("data-val"),
  536. $("#textTj").find('.l-over').attr("data-index"));
  537. })
  538. var dataPicker;
  539. $(function(){
  540. dataPicker = $('#datePickDIV').lpicker({onCheck: function(){
  541. var parent = plus.webview.getWebviewById("qianyuetongji1.html");
  542. var v = this.getValue();
  543. mui.fire(parent, "setDateVal", v);
  544. load(type, level, area, v.from, v.to);
  545. }});
  546. window.addEventListener("showMask", function() {
  547. dataPicker.toggle();
  548. });
  549. })
  550. function load(type, level, area, from, to){
  551. $('#labLi2').toggle(level == 4);
  552. if($(".c-lab-mor .hit").attr("id")=="labLi2"){
  553. $('#list2').toggle(level == 4);
  554. $('#labLi2').removeClass("hit");
  555. }
  556. $('#list').show();
  557. $("#list2").hide();
  558. path[level] = {type: type, level: level, area: area, from: from, to: to}
  559. indexs = type == 1? [2, 9, 10] : [3, 4, 5];
  560. loadData(type, level, area, from, to);
  561. loadLineData(type, level, area, from, to);
  562. if(banerIndex){
  563. $("#index_"+banerIndex).closest("li").trigger("tap");
  564. }
  565. }
  566. window.addEventListener("loadData", function(e) {
  567. // userRole = JSON.parse(plus.storage.getItem("userRole"))[0] ;
  568. userRole = JSON.parse(plus.storage.getItem("selectedRole"));
  569. roleLevel = userRole.code == '350200' ? 4 : userRole.code.length==6 ? 3 : 2;
  570. type = e.detail.type;
  571. $('.type-'+ type).show();
  572. level = e.detail.level || roleLevel;
  573. area = e.detail.area || userRole.code;
  574. title = e.detail.title || userRole.name;
  575. var dateArr = dataPicker.getValue();
  576. load(type, level, area, dateArr.from, dateArr.to);
  577. $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
  578. if(!e.detail.title){
  579. $('#labLi2').toggle(level == 4);
  580. }
  581. $(".c-lab-mor #labLi2").removeClass("hit");
  582. if(level==4){
  583. title = title.substring(0,3);
  584. }
  585. $("#title").html(title);
  586. });
  587. window.addEventListener("toBack", function(e) {
  588. mui.back();
  589. });
  590. document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);