var patiCode = "";
var patiName = "";
var scrollerObArr=[],baseEnv;
var menuData = [{code:"1",name:"随访计划",url:"doctor/followup/list_by_team",page: 1,template: 'suifang_tmpl'},
{code:"2",name:"随访记录",url:"doctor/followup/list_by_team",page: 1,template: 'suifang_tmpl'}];
var slider = null;
var noResultWrap = '
'+
'
'+
'
';
var activeIndex = 0;
var pageSize = 10;
var docInfo ='';
var type = ""; //记录前一个页面的id
// 获取基础环境信息
var getBaseEnvPromise = function () {
var env = {
webview: plus&&plus.webview.currentWebview()
};
return Promise.resolve().then(function(res) {
return env;
});
},
//初始化iscroll对象
initScroller = function(menuData){
for(var x in menuData){
var $dom = $("#div-container"+x);
//实例化iscroll
var contentIscroll = $dom.lscroll({
iscrollOpt: {
click:true
},
pullDownAction: function(g){
var curPage = g.options.page;
getList(g.iScroll,curPage, true);
},
pullUpAction: function(g){
var curPage = g.options.page;
getList(g.iScroll,curPage, false);
}
});
scrollerObArr.push({myscroll:contentIscroll});
}
},
//加载数据
getList = function(myscroll,page,isInit){
var target = $(myscroll.wrapper).find(".div-content").find("ul.dest_list_wrap");
var index = parseInt($(myscroll.wrapper).find(".div-content").attr("id").replace("div-container",""));
var menu = menuData[index];
var teamCode = $(".lin-sel-group li").eq(activeIndex).attr('data-code');
if(isInit) {
menu.page = page
}
getReqPromise(menu.url,{
type: index+1,
patient: patiCode,
teamCode: teamCode||"",
page: page,
pagesize: pageSize
}).then(function(res) {
if(res.status==200){
var list = res.list || res.data;
if(list.length > 0){
var len = list.length;
menu.page++;
var html = template(menu.template, {list: list});
if(isInit){//下拉刷新
target.html(html);
}else{//上拉加载
target.append(html);
}
setTimeout(function(){
scrollerObArr[index].myscroll.refresh(len'+menuData[x].name+'';
//内容
contentStr+='';
}
$(".div-menu").html(menuStr);
$(".mui-slider-group").html(contentStr);
initScroller(menuData);//初始化iscroll事件
initPage(1,$("#Dtitle").attr("data-index"));
slider = mui('.mui-slider').slider();
$('.mui-scroll-wrapper').addClass('mui-slider-indicator');
mui('.mui-scroll-wrapper').scroll();
},
//页面初始化
initPage = function(page,status) {
var reqUrl = [];
var teamCode = $(".lin-sel-group li").eq(activeIndex).attr('data-code');
var params = _.map(menuData,function(o) {
return {
url: o.url,
data: {
patient: patiCode,
teamCode: teamCode||"",
type: 1,
page: o.page,
pagesize: pageSize,
}
}
});
var firstReq = [];
firstReq.push(params[0]);
getReqPromises(firstReq).then(function(datas) {
_.each(datas,function(o,i) {
var res = datas[i];
if(res.status == 200) {
var list = res.list || res.data;
if(list.length > 0) {
var len = list.length;
menuData[i].page++;
var html = template(menuData[i].template, {list: list});
$(".mui-slider-group").find(".div-content").find("ul.dest_list_wrap").eq(i).html(html);
setTimeout(function(){
scrollerObArr[i].myscroll.refresh(len已完成 3-->进行中2-->未开始(计划中)
if(docInfo.code != info.doctorCode && !(docInfo.isLeader=="1" && docInfo.adminTeamCode ==$("#Dtitle").attr("data-index")) && info.status!=1 ){
mui.toast("您暂时无法查看哦");
return ;
}
var str = ele.getAttribute("data-info");
var docMsg = JSON.stringify(docInfo);
var strObj = JSON.parse(str);
var otherPeople = false;
if(docInfo.code != info.doctorCode && !(docInfo.isLeader=="1" && docInfo.adminTeamCode ==$("#Dtitle").attr("data-index"))){
otherPeople = true
}
if(strObj.prescriptionCode){
if(strObj.status!='2'){
openWebview("../../suifang/html/fvDetail.html", {followup_id: strObj.id,status:strObj.status,prescriptionCode:strObj.prescriptionCode,otherPeople:otherPeople});
}else{
var patientInfo={}
patientInfo.code = strObj.patientCode
mui.openWindow('../../suifang/html/follow_way.html', 'follow_way', {
extras: {
followup_id:strObj.id,
followClass:strObj.followupClass,
patientInfo:patientInfo,
prescriptionCode: strObj.prescriptionCode
}
})
}
}else{
openWebview("../../suifang/html/suifang_detail.html", {data: str,docInfo:docMsg});
}
},
addNew = function() {
openWebview("choose_suifang.html", {patiCode: patiCode});
},
prepareData = function(){
if(type && type == "sf"){ //显示随访的数据
menuData = [
{code:"2",name:"随访",url:"doctor/followup/list_by_team",page: 1,template: 'suifang_tmpl'}
];
$("#statistics_btn").hide();
}else{
$("#statistics_btn").show();
}
}
// 页面业务处理流程开始
new Promise(function(resolve, reject) {
// TODO 临时放开
//resolve(true);
mui.plusReady(function() {
// plus已经准备好,可以往下执行
resolve(true);
});
}).then(function() {
template.helper('toInfo', function(v){
v.patientCode = patiCode;
return JSON.stringify(v);
});
template.helper("setSex", function(s) {
if(s == 1) {
return "男"
} else if(s == 2) {
return "女"
}
});
template.helper("setPhoto", function(p) {
return getImgUrl(p);
});
template.helper("setTime", function(p) {
if(p){
p = p.split('.')[0];
return new Date(Date.parse(p.replace(/-/g, "/"))).format("yyyy-MM-dd hh:mm:ss")
}else{
return "";
}
});
//随访
template.helper("setTime2", function(p) {
// 为了防止类似“2016-12-21 14:08:10.0”在IOS上无法识别问题
if(p){
p = p.split('.')[0];
return new Date(Date.parse(p.replace(/-/g, "/"))).format("yyyy-MM-dd hh:mm")
}else{
return "";
}
});
}).then(function() {
docInfo = JSON.parse(plus.storage.getItem("docInfo"));
// 获取基础环境信息
return getBaseEnvPromise().then(function(env) {
baseEnv = env;
patiCode =baseEnv.webview.patientCode;
patiName = baseEnv.webview.patientName;
})
})
.then(function() {
// plus.nativeUI.showWaiting();
// // TODO 团队选择
// return getReqPromise("doctor/family_contract/patient_doctor_teams",{
// patient: patiCode
// }).then(function(res) {
// if(res.status == 200) {
// var data = res.data,teams = [];
// // 是否有签约关系 1:有 0:无,此时jtTeam与ssTeam都没有
// if(data.hasSign=="1") {
// data.ssTeam && (function() {
// var team = data.ssTeam.team;
// team.hasSign = data.ssTeam.hasSign; // 医生与患者是否有签约关系
// team.isLeader = data.ssTeam.isLeader; // 是否是团队长
// teams.push(team)
// })();
// data.jtTeam && (function() {
// var team = data.jtTeam.team;
// team.hasSign = data.jtTeam.hasSign; // 医生与患者是否有签约关系
// team.isLeader = data.jtTeam.isLeader; // 是否是团队长
// teams.push(team)
// })();
// }
// }
// $('.lin-sel-group').html(template('teams_tmpl', {data:teams}));
// //初始默认选中第一个团队信息
// var $select = $(".lin-sel-group li").eq(activeIndex);
// var code = $select.attr("data-code");
// $(".lin-sel-group li").removeClass("checked");
// $select.addClass("checked");
// $("#Dtitle").html($select.find("label").html()).attr("data-index",code);
// })
})
.then(function() {
reference = baseEnv.webview.reference || 0;
type = baseEnv.webview.type;
prepareData();
initArticleType();
bindEvents();
})
.catch(function(e) {
plus.nativeUI.closeWaiting();
console && console.error(e);
})
window.addEventListener("refresh2", function(event){
$(".lin-sel-group li").eq(activeIndex).trigger("click");
})