$(function() {
var teamCode = '',
tType = 0;
//接口
var pi = {
ztqk: 'statistics/getStatTitleInfo',//总体情况
zxtj: 'statistics/getReyStatbyTeam',//咨询统计
jmgzqs: 'statistics/getConcernbyTeam',//居民关注趋势
gzbhqs: 'statistics/getConcerAndCancel',//关注变化趋势
jgnfw: 'statistics/getServiceRankingList',//机构内排行
pjmyd: 'statistics/getAvgLine'//医生平均分
};
function openWebview(href,hrefId,extras) {
if(plus.os.name == "Android") {
var wv = plus.webview.create( href, hrefId, {hardwareAccelerated:false}, extras);
wv.show("slide-in-right",250);
} else {
mui.openWindow({
url:href,
id:hrefId,
extras:extras
})
}
}
var gzbg = {
// 下拉
$demoComtop: $('.demo-comtop'),
$linMask: $('.lin-mask'),
$linSelGroup: $('.lin-sel-group'),
$selTit: $('#selTit'),
// echarts
$qyqkChart: document.getElementById('qyqkChart'),
$zxtjChart: document.getElementById('zxtjChart'),
$jmgzChart: document.getElementById('jmgzChart'),
$gzbhChart: document.getElementById('gzbhChart'),
$jgChart: document.getElementById('jgChart'),
$mydChart: document.getElementById('mydChart'),
//总体情况
$qyrs: $('#qyrs'),
$fwrs: $('#fwrs'),
$pjmyd: $('#pjmyd'),
//咨询统计
$whfs: $('#whfs'),
$yhfs: $('#yhfs'),
$jgnph: $('.jgnph'),
$zbdj: $('.zbdj'),
//事件
es: ['tap'],
weeksData: null,
monthData: null,
type: 0,
startDate: '',
endDate: '',
self: null,
weeks: ['','第一周','第二周','第三周','第四周','第五周'],
dateArr: [],
init: function () {
var me = this;
me.self = plus.webview.currentWebview();
teamCode = me.self.teamCode;
me.bindEvent();
me.setDate();
},
setDate: function () {
if (this.type === 0) {
this.startDate = $d.init(1);
this.endDate = $d.init(2);
} else {
this.startDate = $d.init(3);
this.endDate = $d.init(4);
}
if (this.weeksData === null || this.monthData === null) {
this.loadDate();
} else {
this.setDateInPage();
}
},
getZTQKData: function () {//总体情况
return getReqPromise( pi.ztqk, {
startDate: this.startDate,
endDate: this.endDate
}, 'GET');
},
getZXTJData: function () {//咨询统计
return getReqPromise( pi.zxtj, {
startDate: this.startDate,
endDate: this.endDate,
isNow: 1
}, 'GET');
},
getJMGZQSData: function () {//居民关注趋势
return getReqPromise( pi.jmgzqs, {
startDate: this.startDate,
endDate: this.endDate,
type: this.type
}, 'GET');
},
getGZBHQSData: function () {//关注变化趋势
return getReqPromise( pi.gzbhqs, {
startDate: this.startDate,
endDate: this.endDate,
type: this.type
}, 'GET');
},
getJGNFWData: function () {//机构内排行
return getReqPromise( pi.jgnfw, {
startDate: this.startDate,
endDate: this.endDate
}, 'GET');
},
getPJMYDData: function () {//医生平均分
return getReqPromise( pi.pjmyd, {
startDate: this.startDate,
endDate: this.endDate,
type: this.type
}, 'GET');
},
loadDate: function () {
var me = this;
plus.nativeUI.showWaiting();
Promise.all([ me.getZTQKData(), me.getZXTJData(),me.getJMGZQSData(),me.getGZBHQSData(),me.getJGNFWData(),me.getPJMYDData()]).then(function (ress) {
if (me.type === 0) {
me.weeksData = ress;
}
if (me.type === 1) {
me.monthData = ress;
}
// console.error(JSON.stringify(ress))
// console.error(JSON.stringify(ress[3]))
me.setDateInPage();
plus.nativeUI.closeWaiting();
});
},
setDateInPage: function () {
var me = this,
data = me.type === 0 ? me.weeksData : me.type === 1 ? me.monthData : [],
d = [],
qyrs = 0,
fwrs = 0,
pjmyd = 0,
whfs = 0,
yhfs = 0;
if (data[0].status == 200) {
d= data[0].data;
qyrs = d[7].concernCount;
fwrs = d[1].consultCount + d[2].reservationCount + d[3].articleCount + d[4].guidanceCount + d[5].followupCount;
pjmyd = d[6].avgScore;
}
if (data[1].status == 200) {
whfs = data[1].data.onReyCount;
yhfs = data[1].data.totalCount;
}
me.$qyrs.html(qyrs);//qyrs
if(pjmyd==0){
me.$pjmyd.html("暂无评分");
}else{
me.$pjmyd.html(pjmyd);
}
//咨询统计
me.$whfs.html(whfs);
me.$yhfs.html(yhfs);
me.initChartsData();
},
initChartsData: function () {
var me = this,
data = me.type === 0 ? me.weeksData : me.type === 1 ? me.monthData : [],
qy = {dt:[],da:[]},
zxtj = [],
jgnfw = [],
jmgzqs = [],
gzbhqs = {},
pjmyd = {dt:[],da:[]},
xqzq = {da1: [], da2: []},
dArr = $d.init(5);
me.dateArr = $d.init(6);
if (data[1].status == 200) {
zxtj = data[1].data;
}
if (data[0].status == 200) {
var datas = data[0];
var fwrc = parseInt(datas.data[3].articleCount)+parseInt(datas.data[4].guidanceCount)+parseInt(datas.data[1].consultCount)
jgnfw = [datas.data[1].consultCount, datas.data[5].followupCount, datas.data[2].reservationCount, datas.data[4].guidanceCount, datas.data[3].articleCount];
me.$fwrs.html(fwrc);//fwrs
}
if (data[4].status == 200) {
var html = '';
html += '
' + (data[4].data[0].consultRK ? ('第' + data[4].data[0].consultRK + '名') : '未上榜') + '';
html += '' + (data[4].data[3].guidanceRK ? ('第' + data[4].data[3].guidanceRK + '名') : '未上榜') + '';
html += '' + (data[4].data[4].articleRK ? ('第' + data[4].data[4].articleRK + '名') : '未上榜') + '';
me.$jgnph.html(html);
}
if (data[5].status == 200) {
pjmyd = me.getDataXY(data[5].data, 2);
if (me.type === 0) {
// me.dateArr = $d.init(5);
pjmyd = $h.contrastDate( dArr, pjmyd, 'dt', 'da');
}
if (me.type === 1) {
var d1 = $h.getWeeksData( pjmyd, 'dt', 'da'),
pjmyd = d1.da;
me.dateArr = d1.dt;
}
}
if(data[2].status == 200){
jmgzqs = me.getDataXY(data[2].data, 3);
if (me.type === 0) {
// me.dateArr = $d.init(5);
jmgzqs = $h.contrastDate(dArr, jmgzqs, 'dt', 'da');
}
if (me.type === 1) {
var d1 = $h.getWeeksData( jmgzqs, 'dt', 'da'),
jmgzqs = d1.da;
me.dateArr = d1.dt;
}
}
//处理关注变化趋势
if(data[3].status == 200){
gzbhqs = data[3].data;
var concorn = gzbhqs[0].concorn//新增关注
var cancel = gzbhqs[0].cancel;//取消关注
concorn = me.getDataXY(concorn, 3);
cancel = me.getDataXY(cancel, 4);
if (me.type === 0) {
concorn = $h.contrastDate(dArr, concorn, 'dt', 'da');
cancel = $h.contrastDate(dArr, cancel, 'dt', 'da');
}
if (me.type === 1) {
var d1 = $h.getWeeksData( concorn, 'dt', 'da');
var d2 = $h.getWeeksData( cancel, 'dt', 'da');
concorn = d1.da;
cancel = d2.da;
me.dateArr = d1.dt;
}
gzbhqs = {concorn:concorn,cancel:cancel}
}
me.loadCharts(qy, zxtj, jgnfw, pjmyd, jmgzqs, gzbhqs);
},
loadCharts: function(qy, zxtj, jgnfw, pjmyd, jmgzqs, gzbhqs) {
var me = this,gzbhxAxisData=[],gzbhSeriesData1=[],gzbhSeriesData2=[];
var count = zxtj.onReyCount + zxtj.totalCount;
var zx = count == 0 ? (1/2)*100 : 0;
jgnfw.splice(1,2);//删除随访和代预约的值
//处理咨询统计
var unreplay = zxtj.onReyCount, //未回复数
total = zxtj.totalCount,
replay = parseInt(total) - parseInt(unreplay); //已回复咨询数
$("#totalCount").text(total);//总咨询数
Promise.all([
//咨询统计
$ic.init({
el: me.$zxtjChart,
seriesData: [{
name: '未回复咨询',
value: unreplay// || zx
}, {
name: '已回复咨询',
value: replay// || zx
}],
chartsType: 2,
seriesName:"咨询数量"
}),
//机构内服务
$ic.init({
el: me.$jgChart,
xAxisData: ['咨询', '指导', '教育'],//['咨询', '随访', '代预约', '指导', '教育']
seriesData: jgnfw,
chartsType: 3,
color: '#fbba31',
cb: me.eConsole
}),
//平均医生评分
$ic.init({
el: me.$mydChart,
xAxisData: me.dateArr,
seriesData: me.setSeries(1, pjmyd),
chartsType: 1,
}),
//居民关注趋势
$ic.init({
el: me.$jmgzChart,
xAxisData: me.dateArr,
seriesData: me.setSeries(2, jmgzqs),
chartsType: 1
}),
//关注变化趋势
$ic.init({
el: me.$gzbhChart,
xAxisData: me.dateArr,
legend: {
data:['新增关注','取消关注']
},
seriesData: [{
name:"新增关注",
type: "line",
symbol: "emptyCircle",
data: gzbhqs.concorn
},
{
name:"取消关注",
type: "line",
symbol: "emptyCircle",
data: gzbhqs.cancel
}],
chartsType: 1
}),
]);
},
getDataXY: function ( d, t) {
var data = {dt:[],da:[]};
if (this.type == 0) {
for (var i = 0, len = d.length; i< len; i++) {
data.dt.push(t == 1 ? d[i].applyDate : t == 2 ?d[i].dateNo:d[i].applyDate);
data.da.push(t == 1 ? d[i].signCount : t == 2 ?d[i].avgCount:t == 4?d[i].cancelCount:d[i].concernCount);
}
return data;
}
if (this.type == 1) {
for (var i = 0, len = d.length; i< len; i++) {
data.dt.push(t == 1 ? d[i].weekOfMonth : t == 2 ?d[i].weekNo:d[i].weekOfMonth);
data.da.push(t == 1 ? d[i].signCount : t == 2 ?d[i].avgCount:t == 4?d[i].cancelCount:d[i].concernCount);
}
return data;
}
},
getXQDataXY: function ( d, t) {
var data = {dt:[],da:[]};
for (var i = 0, len = d.length; i< len; i++) {
if (this.type === 0) {
data.dt.push(d[i].dateNo);
}
if (this.type === 1) {
data.dt.push(d[i].weekOfMonth);
}
data.da.push(t == 1 ? d[i].inCount : d[i].outCount);
}
return data;
},
setSeries: function ( type, seriesData) {
return [{
name: type == 1 ? '医生评分' :'居民关注' ,
type: "line",
symbol: "emptyCircle",
data: seriesData
}]
},
bindEvent: function () {
var me = this;
$h.setEvent([
[ me.$demoComtop, me.es[0], function () {
me.xlEventFun( this, me);
}, 'h1'],
[ me.$linMask, me.es[0], function () {
$(this).hide();
me.$linSelGroup.hide();
}],
[ me.$linSelGroup, me.es[0], function () {
me.switchWeeksToMonth( this, me);
}, 'li'],
]);
},
//周月切换
switchWeeksToMonth: function ( that, me) {
var type = $(that).attr('data-type');
$(that).siblings().removeClass('checked');
$(that).addClass('checked');
me.$selTit.html($(that).find('label').html());
me.$linMask.hide();
me.$linSelGroup.hide();
me.type = parseInt(type);
tType = me.type;
this.setDate();
},
//下拉
xlEventFun: function ( thst, me) {
var lCss = me.$linMask.css('display');
if (lCss == 'none') {
me.$linMask.show();
me.$linSelGroup.show();
} else {
me.$linMask.hide();
me.$linSelGroup.hide();
}
},
eConsole: function (param) {
// return;
if(typeof param.seriesIndex != 'undefined') {
switch(param.dataIndex) {
case 0:
openWebview('../html/tuanduizixunxiangqing.html', 'tuanduizixunxiangqing', {
teamCode: teamCode,
type: tType
})
break;
case 1:
openWebview('../html/tuanduisuifangxiangqing.html', 'tuanduisuifangxiangqing', {
teamCode: teamCode,
type: tType
})
break;
case 2:
openWebview('../html/tuanduidaiyuyuexiangqing.html', 'tuanduidaiyuyuexiangqing', {
teamCode: teamCode,
type: tType
})
break;
case 3:
openWebview('../html/tuanduizhidaoxiangqing.html', 'tuanduizhidaoxiangqing', {
teamCode: teamCode,
type: tType
})
break;
case 4:
openWebview('../html/tuanduijiaoyuxiangqing.html', 'tuanduijiaoyuxiangqing', {
teamCode: teamCode,
type: tType
})
break;
default:
break;
}
}
}
};
mui.init();
mui.plusReady(function(){
gzbg.init();
});
});