123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563 |
- var scroller1,
- initLevel,
- level,
- code,
- title,
- preIndex = 0, //记录前一次请求时发送的index
- currType = 0; //记录当前选中的是签入(1)还是签出(0)
- var tags=[];
- var colorArr = ['ff5442', 'ffc800 ','4ce428', '24bbfa','fb5dab', "9b5ffd"],
- colorArr2 = ['9b5ffd', 'ffc800', 'fb5dab'];
- //记录index的对应的值, 签出和签入和转签对应的各个level的值
- var indexArr = [{4: 41, 3: 39, 2: 35}, {4: 40, 3: 38, 2: 34}, {4: 35, 3: 35}];
-
- var reqArr = []; //记录请求的信息
- var now = new Date(),
- endDate = now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
- mui.init();
- mui.plusReady(function(){
- var self = plus.webview.currentWebview();
-
- initLevel = level = self.level;
- code = self.code;
- title = self.title;
-
- $("#title").text(title);
-
- plus.nativeUI.showWaiting();
- initPage();
- initScroller();
- bindEvents();
- });
- function initScroller(){
- scroller1 = $("#wrapper1").initScroll(
- {
- pullDownAction: function(){
- plus.nativeUI.showWaiting();
- var info = reqArr[reqArr.length - 1];
- getAnalysisData();
- loadListData(info.tags, info.params);
- },pullUpAction: function() {
- $(".pullUp").hide();
- return false;
- }
- }
- );
- }
- function initPage(){
- getAnalysisData();
-
- var index;
- switch (parseInt(level)){
- case 4: //市级
- index = indexArr[0][level]; //初始查看区签出数据
- tags = ["各区","社区","团队"];
- break;
- case 3://区级
- index = indexArr[0][level]; //初始查看机构的签出数据
- tags = ["社区","团队"];
- break;
- case 2: //社区级
- index = indexArr[0][level]; //初始查看团队的签出数据
- tags = ["团队"];
- break;
- default:
- break;
- }
- var params2 = {
- sort:1,
- level:level,
- area:code,
- date: endDate,
- index: index
- };
- reqArr.push({tags: tags, params: params2, currType: currType, title: title});
- loadListData(tags, params2);
- }
- //获得顶部统计数据和饼图的数据
- function getAnalysisData(){
- var url = "/statistics/getRenewAnalysis",
- params = {level: level, code: code};
-
- sendGet(url, params, null, getAnalysisHandler);
- }
- //获得底部tab的值
- function loadListData(tags, params, notReloadTag){
- //加载数据截止时间
- 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)
- }
- });
-
- //加载显示tab
- if(!notReloadTag){
- var tagStr = "",
- index = 0;
- for(var i=0;i<tags.length;i++){
- var classz = "";
- var dataClick = "false";//是否已点击过
- if(params.lowLevel){ //如果存在之前点击tab的记录
- if(tags.length == 3){
- if(params.lowLevel == 2 && i == 1){
- classz="hit";
- dataClick="true";
- index = i;
- }
- if(params.lowLevel == 1 && i == 2){
- classz="hit";
- dataClick="true";
- index = i;
- }
- }else if(tags.length == 2){
- if(params.lowLevel == 1 && i == 1){
- classz="hit";
- dataClick="true";
- index = i;
- }
- }
- }else{
- if(i == 0){
- classz="hit";
- dataClick="true";
- }
- }
- tagStr += '<li id="tab_'+i+'" class="'+classz+'" data-click="'+dataClick+'"><a href="#" class="c-f16">'+tags[i]+'</a></li>';
- }
- $(".c-lab-mor").html(tagStr);
- //将其他的内容tab隐藏
- $(".tab-panel").addClass("c-hide").eq(index).removeClass("c-hide");
- }
-
- $(".group1").show();
- $(".group2").hide();
- //选中选择“签入”“签出”的tab
- var selectedId = $(".c-lab-mor li.hit").attr("id").split("tab_")[1];
- var $aList = $("#list"+selectedId).find(".tab a");
- var tabText = $(".c-lab-mor li.hit a").text();
- if(tabText == "团队"){
- $(".group1").hide();
- $(".group2").show();
- }
- $aList.removeClass("active");
- $("#list"+selectedId).find(".tab a[data-val="+currType+"]").addClass("active");
-
- var url = "/statistics/lowlevel_all";
- sendPost(url, params, null, listHandler);
- }
- function getAnalysisHandler(res){
- if(res.status == 200){
- if(level == 4){
- $("#totalNum").text(res.data.thisYearSwithch);
- $("#card1").show();
- $("#card2").hide();
- }else{
- $("#switchNum").text(res.data.thisYearSwithch);
- $("#outNum").text(res.data.outNum);
- $("#inNum").text(res.data.inNum);
- $("#card1").hide();
- $("#card2").show();
- }
-
- var len = res.data.switchHealth.length,
- sum = 0;
- for(var i=0; i<len; i++){
- sum += res.data.switchHealth[i].num;
- }
- var arrObj = [];
- for(var j=0; j<len; j++){
- var obj = res.data.switchHealth[j];
- obj.color = colorArr[j];
- if(sum == 0){
- obj.value = "0.00";
- }else{
- var rate = (obj.num / sum * 100).toFixed(2);
- obj.value = rate;
- }
- arrObj.push(obj);
- }
- echartsZQFun(arrObj);
- var html = template("reson_tmp", {list:arrObj});
- $("#reasonList").empty().append(html);
-
- //填充转签分布图
- var fenbuArrObj = [{
- color: colorArr2[0],
- name: "跨区",
- value: parseFloat(res.data.switchTown).toFixed(2)
- },{
- color: colorArr2[1],
- name: '跨社区',
- value: parseFloat(res.data.switchHospital).toFixed(2)
- },{
- color: colorArr2[2],
- name: '跨团队',
- value: parseFloat(res.data.switchTeam).toFixed(2)
- }];
- echartsFBFun(fenbuArrObj);
- var html = template("reson_tmp", {list:fenbuArrObj});
- $("#fenbuList").empty().append(html);
- }else{
- mui.toast(res.msg);
- }
- plus.nativeUI.closeWaiting();
- }
- function listHandler(res){
- if(res.status == 200){
- var data = res.data;
- var curIndex;
- for(var k in data){
- curIndex = k.split("index_")[1];
- var list = data[k];
- var topArr = soreRank(amountArr(list));
- for(var j in list){
- list[j].top = topArr[j];
- }
-
- data.all = assAmount(list);
- switch(parseInt(currType)){
- case 0:
- data.amountName = "签出数";
- break;
- case 1:
- data.amountName = "签入数";
- break;
- case 2:
- data.amountName = "转签数";
- break;
- }
- data.list = list;
- data.level = level;
-
- //查找对应的tab的内容显示区域
- var id = $(".c-lab-mor li.hit").attr("id"),
- tabText = $(".c-lab-mor li.hit a").text(),
- selectedId = id.split("tab_")[1];
-
- if(tabText == "团队"){
- data.level = 2; //团队时不需要显示向右箭头
- }
- //判断是否存在上一次请求显示的内容
- var $preDiv = $("#listPanel"+selectedId).find(".l_index_"+preIndex);
- if($preDiv.length > 0){
- $preDiv.hide();
- }
- //判断是否存在div
- var $div = $("#listPanel"+selectedId).find(".l_"+k);
- var html = template('list_tmpl', data);
- if($div.length == 0){
- var ulHtml = '<ul class="l_'+k+' l-gq-list">'+html+'<ul>';
- $("#listPanel"+selectedId).empty().append(ulHtml);
- }else{
- $div.empty().append(html);
- $div.show();
- }
- }
- preIndex = curIndex;
- scroller1.refresh();
- }else{
- mui.toast(res.msg);
- }
- }
- template.helper("setRate", function(all, amount){
- if(all == 0)
- return 0;
- return (amount / all * 100).toFixed(2);
- });
- //排序
- 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 assAmount(list){
- var all = 0;
- for(var k in list){
- all += list[k].amount;
- }
- return all;
- }
- //绘制转签原因分析的图
- function echartsZQFun(arry){
- var m=this;
- var myChart = echarts.init(document.getElementById('reasonMain'));
- var option = {
- tooltip: {
- trigger: 'item',
- formatter: "{a} <br/>{b}: {c}%",
- position: ['50%', '50%']
- },
- color:['#ff5442', '#ffc800 ','#4ce428', '#24bbfa','#fb5dab', "#9b5ffd"],
- series: [
- {
- name:'转签原因',
- type:'pie',
- radius : '65%',
- center:[70,'50%'],
- label: {
- normal: {
- show: false,
- textStyle: {
- color: "#000"
- }
- }
- },
- labelLine: {
- normal: {
- show: false
- }
- },
- data:arry
- }]
- };
- myChart.setOption(option);
- }
- //绘制分布图
- function echartsFBFun(arry){
- var m=this;
- var myChart = echarts.init(document.getElementById('fenbuMain'));
- var option = {
- tooltip: {
- trigger: 'item',
- formatter: "{a} <br/>{b}: {c}%",
- position: ['50%', '50%']
- },
- color:['#9b5ffd', '#ffc800', '#fb5dab'],
- series: [
- {
- name:'转签分布',
- type:'pie',
- radius : '65%',
- center:[70,'50%'],
- label: {
- normal: {
- show: false,
- textStyle: {
- color: "#000"
- }
- }
- },
- labelLine: {
- normal: {
- show: false
- }
- },
- data:arry
- }]
- };
- myChart.setOption(option);
- }
- function bindEvents(){
- //数据点击查看下一级数据
- $("body").on('tap',".l-gq-list li", function(){
- var tabText = $(".c-lab-mor li.hit a").text();
- var nextLevel = 3; //传递去下一个页面的level值
- if(tabText == "各区"){
- tags = ["社区","团队"];
- }else if(tabText == "社区"){
- if(currType == 2){
- currType = 0;
- }
- nextLevel = 2;
- tags = ["团队"];
- if((initLevel == level) && (initLevel == 4)){
- level --;
- }
- }else{
- //点击的是团队下的item
- return false;
- }
- //跳转去下一级页面的分析
- title = $(this).attr("data-name");
- code = $(this).attr("data-code");
- // mui.openWindow({
- // url: "renew-analysis2.html",
- // id: "renew-analysis2.html",
- // extras:{
- // level:nextLevel,
- // code:code1,
- // title: title1
- // }
- // });
-
- $("#title").text(title);
- level --;
- var params = {
- sort:1,
- level:level,
- area:code,
- date: endDate,
- index: indexArr[currType][level]
- };
- reqArr.push({tags: tags, params: params, currType: currType, title: title});
- getAnalysisData();
- loadListData(tags, params);
- });
-
- //tab切换
- $("body").on('tap', '.c-lab-mor li', function(){
- var $this = $(this);
-
- if($this.hasClass("hit")){
- return false;
- }
-
- $(".c-lab-mor li").removeClass("hit");
- $this.addClass("hit");
-
- var selectedId = $this.attr("id").split("tab_")[1];
- $(".tab-panel").addClass("c-hide");
-
- $("#list"+selectedId).removeClass("c-hide");
-
- currType = 0;
- var tabText = $(".c-lab-mor li.hit a").text(),
- lowLevel = 0,
- index = indexArr[0][level];
- if(tabText == "社区"){
- if(initLevel == 4){
- lowLevel = 2;
- }
- index = indexArr[0][3];
- }else if(tabText == "团队"){
- if(initLevel >= 3){
- lowLevel = 1;
- }
- index = indexArr[0][2];
- //团队下只有2个tab
- }else{
- index = indexArr[0][4];
- }
- var params = {
- sort:1,
- level:level,
- area:code,
- date: endDate,
- index: index
- };
- if(lowLevel){
- params.lowLevel = lowLevel;
- }
- // reqArr.push({tags: tags, params: params, currType: currType, title: title});
- loadListData(tags, params, 1);
- });
-
- //签入签出切换
- $("body").on('tap', '.tab a', function(){
- var $this = $(this);
-
- if($this.hasClass("active")){
- return false;
- }
-
- $this.siblings("a").removeClass("active");
- $this.addClass("active");
-
- var val = $this.attr("data-val"),
- tabText = $(".c-lab-mor li.hit").find("a").text(),
- lowLevel = 0,
- index = indexArr[val][level];
- currType = val;
- if(tabText == "社区"){
- if(initLevel == 4){
- lowLevel = 2;
- }
- index = indexArr[val][3];
- }else if(tabText == "团队"){
- if(initLevel >= 3){
- lowLevel = 1;
- }
- index = indexArr[val][2];
- }else{
- index = indexArr[val][4];
- }
- var params = {
- sort:1,
- level:level,
- area:code,
- date: endDate,
- index: index
- };
- if(lowLevel){
- params.lowLevel = lowLevel;
- }
- // reqArr.push({tags: tags, params: params, currType: currType});
- loadListData(tags, params, 1);
- });
-
- //说明信息相关事件
- $("#closeBtn").on("tap", function(){
- $(".information").hide();
- scroller1.refresh();
- });
-
- $(".info-icon").on("tap", function(){
- $(".information").show();
- scroller1.refresh();
- });
- }
- //返回事件
- var old_back = mui.back;
- mui.back = function(){
- if(reqArr.length == 1){
- var self = plus.webview.currentWebview(),
- opener = self.opener();
- opener.show();
- mui.later(function(){
- self.close();
- }, 300);
- }
- else{
- var preInfo = reqArr.pop();
- var info = reqArr[reqArr.length - 1];
- level = info.params.level;
- code = info.params.area;
- title = info.title;
- currType = info.currType;
-
- if(preInfo.params.level != level){
- getAnalysisData();
- }
- tags = info.tags;
-
- $("#title").html(title);
-
- loadListData(info.tags, info.params);
- }
- }
|