123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652 |
- var self;
- var type, level, area, indexs, title,sort=1,banerIndex;
- var path = {};
- var roleLevel, userRole;
- var indexName = {'index_2': '退签人数:', 'index_9': '待审核数:', 'index_10': '改签人数:'}
- //绑定按钮事件
- bindEvents();
- //初始化事件
- mui.plusReady(function() {
- self = plus.webview.currentWebview();
- type = self.type;
- level = self.level;
- area = self.area;
- mui.later(function(){
- mui.fire(self, "loadData", {type: type, level: level, area: area});
- },500)
- //下拉刷新初始化
- initScroller();
- });
- function initScroller(){
- scroller1 = $("#wrapper1").initScroll(
- {
- pullDownAction: function(){
- $(".pullUp").hide();
- plus.nativeUI.showWaiting();
- type = type;
- level = level;
- area = area;
- mui.later(function(){
- mui.fire(self, "loadData", {type: type, level: level, area: area,title:title});
- },500)
- $(".c-lab-mor #labLi1").addClass("hit");
- $(".c-lab-mor #labLi2").removeClass("hit");
- $(".div-list").show();
- $(".div-list2").hide();
- },pullUpAction: function() {
- $(".pullUp").hide();
- return false;
- }
- }
- );
- }
- $('.l-refresh').on("tap", function(){
- self = plus.webview.currentWebview();
- type = self.type;
- level = self.level;
- area = self.area;
- mui.later(function(){
- mui.fire(self, "loadData", {type: type, level: level, area: area});
- },500)
- $(".c-lab-mor #labLi1").addClass("hit");
- })
- //返回事件
- mui.back = function(){
- if(level==4 || level==roleLevel){
- var mainPage =plus.webview.getWebviewById("admin.html");
- mui.fire(mainPage, "refreshData");
- self.close();
- }
- else{
- level++;
- var params = path[level];
- if(!params){
- level++;
- params = path[level];
- }
- type = params.type;
- area = params.area;
- load(type, level, area, params.from, params.to);
- title = params.title || userRole.name;
- if(level==4){
- title = title.substring(0,3);
- }
- $("#title").html(title);
- $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
- $(".c-lab-mor #labLi1").addClass("hit")
- }
- }
- function bindEvents(){
- //标签切换
- $(".c-lab-mor li").click(function(){
- var tabid = $(this).attr("id");
- var top = $(this).offset().top;
- $(".c-lab-mor li").removeClass("hit");
- $(this).addClass("hit");
- $("#list div.l-list").hide();
- $("#list2 div.l-list").hide();
- var index = "index_" + $(".l-qytj-barner").find("li.l-over").attr("data-index");
- if(tabid=="labLi1"){
- $("#list").show();
- $("#list2").hide();
- $("#l_"+ index).show();
- }else{
- $("#list").hide();
- $("#list2").show();
- $("#s_"+ index).show();
- }
- scroller1.refresh();
- window.onscroll = function () {
- var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
- if(top!=-1 && top>0){
- window.scrollTo(0,top);
- top = -1;
- }
- }
- });
- //日、周、月按钮切换
- $(".div-btn-group").on("click",".div-btn",function(){
- var dataId = $(this).attr("data-id");
- $(".div-btn-group .div-btn").removeClass("active");
- $(this).addClass("active");
- var dateArr = dataPicker.getValue();
- loadLineData(type, level, area, dateArr.from, dateArr.to,
- dataId,
- $("#textTj").find('.l-over').attr("data-index"));
- });
- }
- /*****************************************************************************/
- /***** 统计数据初始化 **********/
- /*****************************************************************************/
- //加载数据
- function loadData(type, level, area, from, to){
- clearData(type);
- var params = {level: level, area: area, startDate: from, endDate: to}
- for(var k in indexs){
- params.index = indexs[k];
- loadAmount(params);
- }
- if(level==4){//市级管理员才可以查看市下面的所有社区数据
- $(".c-lab-mor #labLi2").removeClass("c-hide");
- }
- }
- //后台接收数据
- function loadAmount(params){
- sendPost("/statistics/time",null,function(res){
-
- },function(res){
- if(res.status=="200"){
- var date = (res.data && res.data.substring(11,16)) || "";
- $(".jiezhi-time").html(date)
- }
- })
-
- sendPost("/statistics/index_all", params,
- null,
- countHandle);
- params.sort = 1;//排序(0:升序 1:降序)
- params.date = params.endDate;
- sendPost("/statistics/lowlevel_all", params,
- null,
- listHandle);
- if($(".c-lab-mor #labLi2").css("display")!="none"){
- if(roleLevel==4){//市级管理员才可以查看市下面的所有社区数据
- params.lowLevel = 2;
- sendPost("/statistics/lowlevel_all", params,
- null,
- list2Handle);
- delete params.lowLevel;
- }
- }
-
- }
- //格式化数量
- function assAmount(list){
- var all = 0;
- for(var k in list){
- all += list[k].amount;
- }
- return all;
- }
- //排序
- function soreRank(arr) {
- var temp = [];
- var lis = [];
- for(var i=0;i<arr.length;i++)
- lis.push(arr[i])
- lis = _.uniq(lis);
- // lis.sort();
- // lis.reverse();
- for(var i=0;i<arr.length;i++)
- temp[i] = lis.indexOf(arr[i])+1;
-
- return temp;
- }
- //数量数组
- function amountArr(list){
- var amountArr = [];
- for(var k in list){
- amountArr.push(list[k].amount);
- }
- return amountArr;
- }
- function listHandle(res){
- if(res.status == 200) {
- template.helper("setRate", function(all, amount){
- if(all == 0)
- return 0;
- return (amount / all * 100).toFixed(2);
- });
-
- res = res.data;
- var $div;
- for(var k in res){
- var curIndex = k.split("index_")[1];
- var list = res[k];
- var topArr = soreRank(amountArr(list));
- for(var j in list){
- list[j].top = topArr[j];
- }
- if(curIndex=="1" && level!=2){
- res.rateName = "签约率";
- for(var j in list){
- if(list[j].rate){
- list[j].rate = list[j].rate.substring(0,4);
- }
- }
- }
- res.all = assAmount(list);
- res.amountName = indexName[k];
- res.list = list;
- res.level = level;
- var indexF = banerIndex!=undefined?"index_"+banerIndex:'index_9'
- $div = $('<div id="l_'+k+'" class="l-list clearfix '+ (k!=indexF? 'c-hide': '') +'"></div>');
- $('#l_'+k).remove();
- }
-
- if($div){
- $div.append(template("list_tmpl", res));
- if(level>2){
- $("li", $div).on("tap", function(){
- var v = dataPicker.getValue();
- level--;
- area = $(this).attr("data-code");
- load(type, level, area, v.from, v.to);
- var name = $(this).attr("data-name");
- title = name;
- $("#title").html(title);
- // mui.fire(plus.webview.getWebviewById("qianyuetongji1.html"),
- // "setTitle", {title: name});
- $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
- path[level] = {type: type, level: level, area: area, from: v.from, to: v.to, title: name}
- })
- }
- $("#list").append($div);
- scroller1.refresh();
- plus.nativeUI.closeWaiting();
- }
- } else {
- mui.toast(res.msg);
- }
- }
- function list2Handle(res){
- if(res.status == 200) {
- template.helper("setRate", function(all, amount){
- if(all == 0)
- return 0;
- return (amount / all * 100).toFixed(2);
- });
-
- res = res.data;
- var $div;
- for(var k in res){
- var curIndex = k.split("index_")[1];
- var list = res[k];
- var topArr = soreRank(amountArr(list));
- for(var j in list){
- list[j].top = topArr[j];
- }
- if(curIndex=="1" && level!=2){
- res.rateName = "签约率";
- for(var j in list){
- if(list[j].rate){
- list[j].rate = list[j].rate.substring(0,4);
- }
- }
- }
- res.all = assAmount(list);
- res.amountName = indexName[k];
- res.list = list;
- res.level = level;
- $div = $('<div id="s_'+k+'" class="l-list clearfix '+ (k!='index_1' && k!='index_3'? 'c-hide': '') +'"></div>');
- $('#s_'+k).remove();
- }
-
- if($div){
- $div.append(template("list_tmpl", res));
- $("li", $div).on("tap", function(){
- var v = dataPicker.getValue();
- level = 2;
- area = $(this).attr("data-code");
- load(type, level, area, v.from, v.to);
- var name = $(this).attr("data-name");
- title = name;
- $("#title").html(title);
- $('#tjTitle').html("各团队情况");
- path[level] = {type: type, level: level, area: area, from: v.from, to: v.to, title: name}
- })
- $("#list2").append($div);
- setTimeout(function(){
- if(banerIndex==curIndex){
- $("#list div.l-list").hide();
- $("#l_index_"+ banerIndex).show();
- $('#l-jmfx').toggle($(".l-qytj-barner .l-over").attr("data-index")=="1");
- }
- },300)
- scroller1.refresh();
- plus.nativeUI.closeWaiting();
- }
-
- } else {
- mui.toast(res.msg);
- }
- }
- function countHandle(res){
- if(res.status == 200) {
- res = res.data;
- for(var k in res){
- $('#'+ k).html(res[k]);
- }
- } else {
- mui.toast(res.msg);
- }
- }
- function clearData(type){
- $("#textTj li").removeClass("l-over");
- if(!banerIndex){
- // if(type==1){
- // $("#textTj li").eq(0).addClass("l-over");
- // } else {
- // $("#textTj li").eq(4).addClass("l-over");
- // }
- $("#textTj li").eq(0).addClass("l-over");
- }
- $('#l-jmfx').hide();
- $("#list").empty();
- $("#list2").empty();
- $(".l-data").html("0");
- }
- /*****************************************************************************/
- /***** 折线图初始化 **********/
- /*****************************************************************************/
- var dateData = {};
- function loadLineData(type, level, area, from, to, interval, index){
-
- plus.nativeUI.showWaiting();
- var url = "/statistics/interval_total";
- if(from=='')
- from = '2016-08-01';
- var params = {level: level, area: area, startDate: from, endDate: to,
- interval: $(".div-btn-group .div-btn.active").attr("data-id")}
- params.index = banerIndex || $(".l-qytj-barner li.l-over").attr('data-index');
- console.log("$"+JSON.stringify(params))
- sendPost(url, params, null, dateLineHandle);
- }
- /**
- * 获取多少天前的日期
- */
- function getDateBefore(days) {
- var now = new Date();
- var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var day = date.getDate();
- var hour = date.getHours();
- var minute = date.getMinutes();
- var second = date.getSeconds();
- return year + '/' + (month < 10 ? '0' + month : month) + '/' + (day < 10 ? '0' + day : day);
- }
- //获取数据最大值
- function maxData(data){
- var maxData = Math.max.apply(Math,data);
- var yAxis = maxData<10?10:maxData;
- return yAxis;
- }
- //初始化折线图
- function drawChart(dateData){
-
- var recordCount = 10;//一页显示几条数据
- var allRecordData = dateData.amountArr.reverse();
- var dateArr = dateData.dateArr.reverse();
- var resultData = _.groupBy(allRecordData,function(item,i){return Math.floor(i/recordCount)});
- var dateArrData = _.groupBy(dateArr,function(item,i){return Math.floor(i/recordCount)});
- //以下为折线图处理
- var gnum = Math.ceil(allRecordData.length / recordCount);
- var HandStartX,HandStartY,HandEndX,HandEndY,CountX,CountY,startPos,isScrolling,number=allRecordData.length,times=allRecordData.length%recordCount;
- var canvasStr = '<div class="div-layer"></div>';
- for(var x in resultData){
- canvasStr='<canvas id="wcMotion'+x+'" class="canvas-wc animated" style="display:block"></canvas>'+canvasStr;
- }
- $(".l-zxt-inner").html(canvasStr);
- var dateType = $(".div-btn-group .div-btn.active").attr("data-id");
- window.setTimeout(function() {
- for(var x in resultData){
- var startDay = new Date(getDateBefore(times-1));
- var resultDateArr = dateArrData[x].reverse();
- var yAxis = maxData(resultData[x]);//求数据的最大值
- $('#wcMotion'+x).wcChart({
- height: 200, // width and height must be set if change
- yAxis:yAxis,
- day: startDay,
- points: [],
- dateArr:resultDateArr,
- dateType:dateType,
- data: resultData[x].reverse(),
- fill: {gradient: [["#17B3EC",.1], ["#17B3EC",.5]], gradientAngle: Math.PI * -45/180},
- animation: null // 修复bug#3298 【医生端】总体分析排版优化。(vivo手机)
- });
- if(x==0){
- $('#wcMotion'+x).show();
- }
- times+=recordCount;
-
- //折线图画布添加左滑和右滑效果
- var wcMotion = document.getElementById('wcMotion'+x);
- wcMotion.addEventListener('touchstart', function(event) {
- HandStartX=event.touches[0].clientX;
- HandStartY=event.touches[0].clientY;
- //touches数组对象获得屏幕上所有的touch,取第一个touch
- var touch = event.targetTouches[0];
- //取第一个touch的坐标值
- startPos = {x:touch.pageX,y:touch.pageY,time:+new Date};
- //这个参数判断是垂直滚动还是水平滚动
- isScrolling = 0;
- }, false);
-
- wcMotion.addEventListener('touchend', function(event) {
- HandEndX=event.changedTouches[0].clientX;
- HandEndY=event.changedTouches[0].clientY;
- CountX=HandEndX-HandStartX;
- CountY=HandEndY-HandStartY;
- if((Math.abs(CountX)>Math.abs(CountY))&& Math.abs(CountX)>50){
- var targetMotion = $(event.target);
- if(CountX<0){
- if(targetMotion.next().length>0 && !targetMotion.next().hasClass("div-layer")){
- targetMotion.siblings().hide();
- targetMotion.addClass("fadeOutLeft");
- targetMotion.next().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInLeft").addClass("fadeInRight").show();
- }
- console.log("左滑");
- }else{
- if(targetMotion.prev().length>0 && !targetMotion.prev().hasClass("div-layer")){
- targetMotion.siblings().hide();
- targetMotion.addClass("fadeOutRight");
- targetMotion.prev().removeClass("fadeOutRight").removeClass("fadeOutLeft").removeClass("fadeInRight").addClass("fadeInLeft").show();
- }
- console.log("右滑");
- }
- }
-
- }, false);
-
- wcMotion.addEventListener('touchmove', function(event) {
- //当屏幕有多个touch或者页面被缩放过,就不执行move操作
- if(event.targetTouches.length > 1 || event.scale && event.scale !== 1) return;
- var touch = event.targetTouches[0];
- endPos = {x:touch.pageX - startPos.x,y:touch.pageY - startPos.y};
- //isScrolling为1时,表示纵向滑动,0为横向滑动
- isScrolling = Math.abs(endPos.x) < Math.abs(endPos.y) ? 1:0;
- if(isScrolling === 0){
- //阻止触摸事件的默认行为,即阻止滚屏
- event.preventDefault();
- }
- }, false);
-
- }
- }, 500);
-
- }
- function dateLineHandle(res){
-
- if(res.status==200){
- for(var p in res.data){
- dateData[p] = formatDateData(res.data[p]);
- if(dateData[p].amountArr && dateData[p].amountArr.length>0){
- // $('#l-jmfx').toggle(p == "index_1" );
- $('#l-jmfx').show();
- $(".l-zxt-con").hide();
- mui.later(function(){
- $(".l-zxt-con").show();
- }, 100);
- $('#l-legend').hide();
- $("#echarts_wushuju").hide();
- $('#l-times').html(type==1? '(人)' : '(次)').hide();
- } else{
- $(".l-zxt-con").hide();
- $("#echarts_wushuju").show();
- $('#l-legend').hide();
- }
- drawChart(dateData[p]);//初始化折线图
- setTimeout(function(){
- $("#textTj").css("pointer-events","");
- plus.nativeUI.closeWaiting();
- },1000)
- }
- } else {
- mui.toast(res.msg);
- }
- }
- //折线图数据格式转化
- function formatDateData(data){
- var dateArr = [];
- var amountArr = [];
- data = data.data
- for(var k in data){
- dateArr.push(data[k].range.substring(5));
- amountArr.push(data[k].amount);
- }
- return {dateArr: dateArr, amountArr: amountArr};
- }
- /*****************************************************************************/
- /***** 中间图标点击事件 **********/
- /*****************************************************************************/
- var barImg= $("#textTj li");
- barImg.on("tap", function(){
- $("#textTj").css("pointer-events","none");
- $('#textTj li').removeClass("l-over");
- $(this).addClass("l-over");
-
- var index = "index_" + $(this).attr("data-index");
- $("#list div.l-list").hide();
- $("#list2 div.l-list").hide();
- if($(".c-lab-mor li.hit").attr("id")=="labLi2"){
- $("#s_"+ index).show();
- }else{
- $("#l_"+ index).show();
- }
- banerIndex = $(".l-qytj-barner .l-over").attr("data-index");
-
- var dateArr = dataPicker.getValue();
- loadLineData(type, level, area, dateArr.from, dateArr.to,
- $('#l-legend li.l-over').attr('data-val'),
- $(this).attr("data-index"));
- })
- $("#l-jmfx").on("tap", function(){
- var dateArr = dataPicker.getValue();
- var checked = dataPicker.getChecked();
-
- mui.openWindow({
- url: "analysis1.html",
- id: "analysis1.html",
- extras:{
- startDate: dateArr.from,
- endDate: dateArr.to,
- area: area,
- level: level,
- title: title,
- checked: checked
- },
- })
- })
- $('#l-legend li').on('tap', function(){
- $('#l-legend li').removeClass('l-over');
- $(this).addClass('l-over');
-
- var dateArr = dataPicker.getValue();
- loadLineData(type, level, area, dateArr.from, dateArr.to,
- $(this).attr("data-val"),
- $("#textTj").find('.l-over').attr("data-index"));
- })
- var dataPicker;
- $(function(){
- dataPicker = $('#datePickDIV').lpicker({onCheck: function(){
- var parent = plus.webview.getWebviewById("qianyuetongji1.html");
- var v = this.getValue();
- mui.fire(parent, "setDateVal", v);
-
- load(type, level, area, v.from, v.to);
- }});
-
- window.addEventListener("showMask", function() {
- dataPicker.toggle();
- });
-
- })
- function load(type, level, area, from, to){
- $('#labLi2').toggle(level == 4);
- if($(".c-lab-mor .hit").attr("id")=="labLi2"){
- $('#list2').toggle(level == 4);
- $('#labLi2').removeClass("hit");
- }
- $('#list').show();
- $("#list2").hide();
- path[level] = {type: type, level: level, area: area, from: from, to: to}
- indexs = type == 1? [2, 9, 10] : [3, 4, 5];
- loadData(type, level, area, from, to);
- loadLineData(type, level, area, from, to);
- if(banerIndex){
- $("#index_"+banerIndex).closest("li").trigger("tap");
- }
-
- }
- window.addEventListener("loadData", function(e) {
- // userRole = JSON.parse(plus.storage.getItem("userRole"))[0] ;
- userRole = JSON.parse(plus.storage.getItem("selectedRole"));
- roleLevel = userRole.code == '350200' ? 4 : userRole.code.length==6 ? 3 : 2;
-
- type = e.detail.type;
- $('.type-'+ type).show();
-
- level = e.detail.level || roleLevel;
- area = e.detail.area || userRole.code;
- title = e.detail.title || userRole.name;
- var dateArr = dataPicker.getValue();
- load(type, level, area, dateArr.from, dateArr.to);
-
- $('#tjTitle').html(level==4? "各区管理" : level==3? "各社区情况" : "各团队情况");
- if(!e.detail.title){
- $('#labLi2').toggle(level == 4);
- }
- $(".c-lab-mor #labLi2").removeClass("hit");
- if(level==4){
- title = title.substring(0,3);
- }
- $("#title").html(title);
- });
- window.addEventListener("toBack", function(e) {
- mui.back();
- });
- document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
|