123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- var self;
- var type, level, area, title,sort=1;
- var path = {};
- var roleLevel, userRole;
- //初始化计算选择的年份
- var chooseYear;
- var now = new Date();
- if(now.getMonth() >= 6){
- chooseYear = now.getFullYear();
- }else{
- chooseYear = now.getFullYear() - 1;
- }
- //绑定按钮事件
- bindEvents();
- //初始化事件
- mui.plusReady(function() {
- self = plus.webview.currentWebview();
- type = self.type;
- level = self.level;
- area = self.area;
-
- //初始显示选中的年份
- $(".choose-label").text(chooseYear+"年");
-
- mui.later(function(){
- mui.fire(self, "loadData", {type: type, level: level, area: area});
- },500)
- //下拉刷新初始化
- initScroller();
- shaixuanInit(self);
- });
- 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==4 || level==roleLevel){
- var mainPage =plus.webview.getWebviewById("admin.html");
- mui.fire(mainPage, "refreshData");
- //关闭筛选页面
- var shaixuan = plus.webview.getWebviewById("shaixuan2.html");
- if(shaixuan){
- shaixuan.close();
- }
- 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==4){
- title = title.substring(0,3);
- }
- $("#title").html(title);
- $('#tjTitle').html("各科室管理");
- $(".c-lab-mor #labLi1").addClass("hit")
- }
- }
- /**
- * 初始化筛选事件
- */
- function shaixuanInit(main){
- var shaixuan = plus.webview.getWebviewById('shaixuan2.html');
- if(!shaixuan){
- shaixuan = mui.createWindow({
- id: 'shaixuan2.html',
- url: 'shaixuan2.html',
- styles: {
- top: 0,
- bottom: 0,
- left: '20%',
- width: '80%',
- scorllIndicator: "none"
- },
- show:{
- aniShow: "slide-in-right",
- duration: "400"
- }
- });
-
- }
- window.addEventListener("hideShaiXuan",function(){
- main.setStyle({mask:"none"});
- shaixuan.hide();
- }, false);
-
- window.addEventListener("showShaiXuan", function() {
- shaixuan.show();
- main.setStyle({mask:"rgba(0,0,0,0.5)"});
- main.addEventListener("maskClick",function(){
- main.setStyle({mask:"none"});
- shaixuan.hide();
- }, false);
- });
- }
- 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{
- $("#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;
- }
- }
- });
-
- //左滑筛选区域的数据
- $('.header-link').on("tap", function(){
- var self = plus.webview.currentWebview();
- mui.fire(self, "showShaiXuan");
- });
-
- window.addEventListener("refresh", function(e){
- chooseYear = e.detail.year;
- $(".choose-label").text(chooseYear+"年");
- loadData(type, level, area);
- loadLineData(type, level, area);
- });
-
- //说明信息相关事件
- $("#closeBtn").on("tap", function(){
- $(".information").hide();
- scroller1.refresh();
- });
-
- $(".info-icon").on("tap", function(){
- $(".information").show();
- scroller1.refresh();
- });
- }
- /*****************************************************************************/
- /***** 统计数据初始化 **********/
- /*****************************************************************************/
- //加载数据
- function loadData(type, level, area){
- clearData(type);
- var params = {level: level, area: area, year: chooseYear}
- 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)
- }
- })
- console.log("第一个:"+JSON.stringify(params))
- sendPost("/statistics/Consulting_Title", params, null, countHandle);
- params.sort = 1;//排序(0:升序 1:降序)
- params.date = params.endDate;
- params.date = getEndDate();
- console.log("第二个:"+JSON.stringify(params))
- // params.lowlevel = "3";
- sendPost("/statistics/Consulting_StatList", params, null, listHandle);
- // delete params.lowLevel;
- if($(".c-lab-mor #labLi2").css("display")!="none"){
- if(roleLevel==3){//市级管理员才可以查看市下面的所有社区数据
- params.lowlevel = "1";
- console.log("第三个:"+JSON.stringify(params))
- sendPost("/statistics/Consulting_StatList", params, null, list2Handle);
- delete params.lowLevel;
- }
- }
-
- }
- //格式化数量
- function assNoRelyCount(list){
- var all = 0;
- for(var k in list){
- all += list[k].noRelyCount;
- }
- 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].noRelyDoubleRate);
- }
- return amountArr;
- }
- function listHandle(res){
- if(res.status == 200) {
- template.helper("setRate", function(all, noRelyCount){
- if(all == 0)
- return 0;
- return (noRelyCount / all * 100).toFixed(2);
- });
-
- res = res.data;
- var $div;
- var list = res.resultList;
- var topArr = soreRank(amountArr(list));
- for(var j in list){
- list[j].top = topArr[j];
- }
- res.all = assNoRelyCount(list);
- res.list = list;
- res.level = level;
- $div = $('<div id="div_list" class="l-list clearfix"></div>');
- $('#div_list').remove();
-
- 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(all, noRelyCount){
- if(all == 0)
- return 0;
- return (noRelyCount / all * 100).toFixed(2);
- });
-
- res = res.data;
- var $div;
- var list = res.resultList;
- var topArr = soreRank(amountArr(list));
- for(var j in list){
- list[j].top = topArr[j];
- }
- res.all = assNoRelyCount(list);
- res.list = list;
- res.level = level;
- $div = $('<div id="div_list2" class="l-list clearfix"></div>');
- $('#div_list2').remove();
-
- 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 countHandle(res){
- if(res.status == 200) {
- res = res.data.result[0] || [];
- $('#div_total').html(res.total);
- $('#div_noRelyRate').html(res.noRelyRate);
- $('#div_noRelyCount').html(res.noRelyCount);
- $('#div_relyRate').html(res.relyRate);
- } 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 getEndDate(){
- chooseYear = parseInt(chooseYear);
- var endDate = new Date((chooseYear+1) + '-06-30'),
- now = new Date();
- if(now <= endDate){
- var month = now.getMonth()+1,
- date1 = now.getDate();
- if(month < 10){
- month = "0"+month;
- }
- if(date1 < 10){
- date1 = "0"+date1;
- }
- return now.getFullYear()+"-"+month+"-"+date1;
- }else{
- return (chooseYear+1) + '-06-30';
- }
- }
- /*****************************************************************************/
- /***** 柱状图初始化 **********/
- /*****************************************************************************/
- function loadLineData(type, level, area){
- plus.nativeUI.showWaiting();
- var url = "/statistics/getCoutListByTime";
- var params = {level: level, area: area, year: chooseYear}
- sendPost(url, params, null, dateLineHandle);
- }
- //初始化柱状图
- function drawChart(nameData,numData){
- nameData.push("时间段");
- var myChart = echarts.init(document.getElementById("l-zxt-con"));
- var option = {
- 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,lineStyle:{color:'#323232'}},
- splitArea: {show:false},
- splitLine: {show:false},
- data : nameData
- }
- ],
- yAxis : [
- {
- type : 'value',
- axisLine: {show:true,lineStyle:{color:'#dcdcdc',width:1}},
- axisTick: {show:false},
- axisLabel: {show:false},
- splitArea: {show:false},
- splitLine: {show:false},
- axisLabel:{show:false}
- }
- ],
- series : [
- {
- name:'首次回复时间分布',
- type:'bar',
- barWidth:20,
- itemStyle: {normal: {color:'#17B3EC', label:{show:true},barBorderRadius:0}},
- data:numData
- }
- ]
- };
-
- myChart.setOption(option);
- }
- function dateLineHandle(res){
- if(res.status==200){
- var resData = res.data.resultList;
- var nameData = [],numData = [];
- for(var p in resData){
- nameData.push(resData[p].name);
- numData.push(resData[p].num);
- }
- drawChart(nameData,numData);
- } else {
- mui.toast(res.msg);
- }
- plus.nativeUI.closeWaiting();
- }
- 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();
- });
- document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
|