123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- var self;
- var type, level, area, title,sort=1;
- var path = {};
- var roleLevel, userRole;
- var EndTimeRecord;
- var monthGap;
- //绑定按钮事件
- 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;
- }
- }
- );
- }
- //返回事件
- mui.back = function(){
- if(level==3 || 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);
- title = params.title || userRole.name;
- if(level==3){
- title = title.substring(0,3);
- }
- $("#title").html(title);
- $('#tjTitle').html("科室情况");
- $(".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();
- if(tabid=="labLi1"){
- $("#list").show();
- $("#list2").hide();
- $("#div_list").show();
- }else{
- loadData(type, level, area)
- $("#list").hide();
- $("#list2").show();
- $("#div_list2").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;
- }
- }
- });
- }
- /*****************************************************************************/
- /***** 统计数据初始化 **********/
- /*****************************************************************************/
- //加载数据
- function loadData(type, level, area){
- clearData(type);
- var params = {level: level, area: area}
- loadAmount(params);
- if(level==3){//市级管理员才可以查看市下面的所有社区数据
- $(".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/getAVGSocre", params, null, countHandle);
- params.sort = 1;//排序(0:升序 1:降序)
- params.index = 28;
- params.date = getEndDate();
- sendPost("/statistics/lowlevel_all", params,null, listHandle);
- if($(".c-lab-mor #labLi2").css("display")!="none"){
- if(roleLevel==3){//市级管理员才可以查看市下面的所有社区数据
- params.lowLevel = "1";
- sendPost("/statistics/lowlevel_all", params, null, list2Handle);
- delete params.lowLevel;
- }
- }
- }
- function listHandle(res){
- if(res.status == 200) {
- template.helper("setRate", function(num){
- if(num == 0)
- return 0;
- return num*1;
- });
-
- res = res.data;
- var $div;
- var list = JSON.parse(res.index_28).data;
- var topArr = soreRank(getAvgCount(list));
- for(var i=0;i<list.length;i++){
- list[i].top = topArr[i];
- }
- res.list = list;
- res.level = level;
- $('#div_list').remove();
- $div = $('<div id="div_list" class="l-list clearfix"></div>');
- if($div){
- $div.append(template("list_tmpl", res));
- if(level>2){
- $("li", $div).on("tap", function(){
- level--;
- area = $(this).attr("data-code");
- load(type, level, area);
- var name = $(this).attr("data-name");
- title = name;
- $("#title").html(title);
- $('#tjTitle').html("医生情况");
- path[level] = {type: type, level: level, area: area, 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(num){
- if(num == 0)
- return 0;
- return 50+((num*1-80)/20*50).toFixed(2)*1;
- });
-
- res = res.data;
- var $div;
- var list = JSON.parse(res.index_28).data;
- var topArr = soreRank(getAvgCount(list));
- for(var i=0;i<list.length;i++){
- list[i].top = topArr[i];
- }
- res.list = list;
- res.level = level;
- $('#div_list2').remove();
- $div = $('<div id="div_list2" class="l-list clearfix"></div>');
-
- if($div){
- $div.append(template("list_tmpl", res));
- // $("li", $div).on("tap", function(){
- // level = 2;
- // area = $(this).attr("data-code");
- // load(type, level, area);
- // var name = $(this).attr("data-name");
- // title = name;
- // $("#title").html(title);
- // $('#tjTitle').html("各团队情况");
- // path[level] = {type: type, level: level, area: area, title: name}
- // })
- $("#list2").append($div);
- scroller1.refresh();
- plus.nativeUI.closeWaiting();
- }
-
- } else {
- mui.toast(res.msg);
- }
- }
- function getAvgCount(list){
- var arr = [];
- for(var k in list){
- arr.push(list[k].avgCount);
- }
- return arr;
- }
- //排序
- function soreRank(arr) {
- var temp = [];
- var lis = [];
- for(var i=0;i<arr.length;i++)
- lis.push(arr[i])
- lis = _.uniq(lis);
- for(var i=0;i<arr.length;i++)
- temp[i] = lis.indexOf(arr[i])+1;
-
- return temp;
- }
- function countHandle(res){
- if(res.status == 200) {
- res = res.data.rs;
- if(res.avgCount == 0){
- $('#avgScore').html('暂无评');
- }else{
- $('#avgScore').html(res.avgCount);
- }
- } else {
- mui.toast(res.msg);
- }
- }
- function clearData(type){
- $("#textTj li").removeClass("l-over");
- $('#l-jmfx').show();
- $("#list").empty();
- $("#list2").empty();
- $(".l-data").html("0");
- }
- /*****************************************************************************/
- /***** 折线图初始化 **********/
- /*****************************************************************************/
- function loadLineData(type, level, area){
- plus.nativeUI.showWaiting();
- var now = new Date();
- var month = (now.getMonth()*1+1)<10?"0"+(now.getMonth()+1):(now.getMonth()+1);
- var date = now.getDate()<10?"0"+now.getDate():now.getDate();
- var endDate = now.getFullYear()+'-'+month+'-'+date;
- monthGap = getMonthByDiff('2017-01-01',endDate);//月份数
- var num = Math.ceil(monthGap/5);//5个月为一模块
- addSlide(num);
- loadOneData(level, area,endDate,1);
- }
- ///滚动加载前面数据
- document.querySelector('.mui-slider').addEventListener('slide', function(event) {
- var num = Math.ceil(monthGap/5)*1;//5个月为一模块
- var slideNumber = event.detail.slideNumber;
- var before = num - slideNumber*1 + 1;
- if(before <= num){
- var $li = $('#l-zxt-con'+before)
- if($li.html() == ''){
- loadOneData(level, area,EndTimeRecord,before);
- }
- }
- })
- function loadOneData(level, area,endDate,num){
- var statDate = fiveMonth(endDate);
- var url = "/statistics/getAVGSocreByMonth";
- EndTimeRecord = lastDate(statDate);//储存结束时间
- var params = {level: level, area: area,statDate:statDate,endDate:endDate};
- sendPost(url, params, null, function(res){
- dateLineHandle(res,num);
- });
- }
- //相差几月
- function getMonthByDiff(a,b){
- var ba = b.split('-');
- var aa = a.split('-');
- if(ba[1] > aa[1]||ba[1] == aa[1]){
- return 12*(ba[0]-aa[0])*1+(ba[1]-aa[1])*1+1
- }else{
- return 12*(ba[0]-1-aa[0])*1+(ba[1]*1+12-aa[1])*1+1
- }
- }
- //该上月份最后一天
- function lastDate(date){
- var arr = date.split('-');
- var year = arr[0];
- var month = arr[1]*1-1;
- if(month<1){
- month = 12;
- year = year - 1;
- }
- var day = new Date(year,month,0).getDate();
- var newMonth = month<10?"0"+month:month;
- var statDate = year+'-'+newMonth+'-'+day;
- return statDate;
- }
- //5个月前
- function fiveMonth(endDate){
- var arr = endDate.split('-');
- var reduce = arr[1]*1-4;
- if(reduce>0){
- reduce = reduce<10?"0"+reduce:reduce;
- var statDate = arr[0]+'-'+reduce+'-01';
- return statDate;
- }else{
- var newReduce = (12+reduce*1)<10?"0"+(12+reduce*1):(12+reduce*1);
- var statDate = arr[0]*1-1+'-'+newReduce+'-01';
- return statDate;
- }
- }
- //添加轮播块
- function addSlide(num){
- var html = '';
- for(var i=num;i>0;i--){
- 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>'
- }
- $('#chart_contain').empty().append(html);
- var slider = mui('.mui-slider').slider();//轮播启动
- if(EndTimeRecord){
- slider.gotoItem(1,0)//处理不加载数据bug
- slider.gotoItem(0,0)//处理不加载数据bug
- }
- slider.gotoItem(num*1-1);//跳到最后一页
- setTimeout(function(){
- $('#chart_contain').css('visibility','visible');//显示
- },1000)
- }
- function dateLineHandle(res,num){
- if(res.status==200){
- var resData = res.data;
- var nameData = [],numData = [];
- _.map(resData,function(v){
- nameData.push(v.month);
- numData.push(v.socre);
- })
- drawChart(nameData,numData,num);
- } else {
- mui.toast(res.msg);
- }
- plus.nativeUI.closeWaiting();
- }
- //初始化图
- function drawChart(nameData,numData,num){
- echarts.init(document.getElementById("l-zxt-con"+num)).setOption({
- calculable : true,
- grid: {y: 25, y2:30, x:0, x2:20,width:$(".l-zxt-con").width(),borderColor:'#ffffff'},
- xAxis : [
- {
- type : 'category',
- axisLine: {show:true,lineStyle:{color:'#dcdcdc',width:1}},
- axisTick: {show:false},
- axisLabel: {show:true,textStyle:{color:'#323232'}},
- splitArea: {show:false},
- splitLine: {show:false},
- data : nameData
- }
- ],
- yAxis : [
- {
- type : 'value',
- axisLine: {show:false,lineStyle:{color:'#dcdcdc',width:1}},
- axisTick: {show:false},
- axisLabel: {show:false},
- splitArea: {show:false},
- splitLine: {show:false},
- axisLabel:{show:false}
- }
- ],
- series : [
- {
- name:'平均评分',
- type:'line',
- itemStyle: {normal: {color:'#17B3EC', label:{show:true}}},
- data:numData
- }
- ]
- });
- }
- function load(type, level, area, from, to){
- $('#labLi2').toggle(level == 3);
- if($(".c-lab-mor .hit").attr("id")=="labLi2"){
- $('#list2').toggle(level == 3);
- $('#labLi2').removeClass("hit");
- }
- $('#list').show();
- $("#list2").hide();
- path[level] = {type: type, level: level, area: area}
- loadData(type, level, area);
- loadLineData(type, level, area);
- }
- 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;
- roleLevel = 3
-
- type = e.detail.type;
- $('.type-'+ type).show();
-
- level = e.detail.level || roleLevel;
- area = e.detail.area || userRole.code;
- title = e.detail.title || userRole.name;
- load(type, level, area);
-
- $('#tjTitle').html("科室情况");
- if(!e.detail.title){
- $('#labLi2').toggle(level == 3);
- }
- $(".c-lab-mor #labLi2").removeClass("hit");
- if(level==4){
- title = title.substring(0,3);
- }
- $("#title").html(title);
- });
- window.addEventListener("toBack", function(e) {
- mui.back();
- });
- //获取结束时间
- function getEndDate(){
- var now = new Date(),
- year = now.getFullYear(),
- month = now.getMonth() + 1,
- day = now.getDate();
- if(month < 10){
- month = '0'+month;
- }
- if(day < 10){
- day = "0"+ day;
- }
- return year+"-"+month+"-"+day;
- }
|