var baseInfo = null,// 基础环境信息(包括当前webview) teamCode,// 从缓存取出所选团队 self, keyword, // 搜索关键字 type = 0, //类型 startDate = getDateBefore(6), endDate = getNowDate(); var page1 = 1, page2 = 1, pagesize = 10, $search = $('#search'), // 搜索框 scrollers = [], loaded = [false, false]; // 选择血糖血压容器 function selTypeDiv() { if(type == 0) { $("#viewTabs").find("li").eq(0).addClass("curr") $(".selectDate li").first().addClass("curr"); $("#xuetangView").show(); $("#xueyaView").hide(); } else { $("#viewTabs").find("li").eq(1).addClass("curr") $(".selectDate").find("li").eq(4).addClass("curr"); $("#xuetangView").hide(); $("#xueyaView").show(); } } // 获取登录相关信息 function getBaseInfo() { self = plus.webview.currentWebview(); teamCode = self.teamCode; type = self.type; selTypeDiv(); } function initPatientListByTeam(isInit) { if(isInit){ if(type == 0){ page1 = 1; }else{ page2 = 1; } } var url = "/doctor/scheme/getTrackPatientIndexCountList"; plus.nativeUI.showWaiting(); sendGet(url, { type: type == 0 ? 1 : 2, teamCode: teamCode, startDate: startDate, endDate: endDate, keyword: keyword ? keyword : "", page: type == 0 ? page1 : page2, size: pagesize }, null, function(res) { plus.nativeUI.closeWaiting(); $(".pullUp").hide(); $(".pullDown").hide(); if(res.status == 200) { if(res.data.length > 0) { loaded[type] == true; $("#XTlist").show(); $("#XYlist").show(); $(".no-result").hide(); var html = template('listDataToHtml', {data: res.data}) if(isInit) { if(type == 0){ $("#XTlist").html(html); }else{ $("#XYlist").html(html); } // scrollers[type].scrollTo(0,0,100); } else { if(type == 0){ $("#XTlist").append(html); }else{ $("#XYlist").append(html); } } if(res.data.length < pagesize){ scrollers[type].endPullupToRefresh(true); }else{ if(type == 0){ page1 ++; }else{ page2 ++; } scrollers[type].enablePullupToRefresh(); } } else { if(isInit) { if(type == 0){ $("#XTlist").hide(); $("#xuetangView .no-result").show(); }else{ $("#XYlist").hide(); $("#xueyaView .no-result").show(); } } else { mui.toast("暂无更多数据!"); } } } else { mui.toast(res.msg); } }, true) } // 绑定页面事件 function bindEvents() { // 头像路径 template.helper("getPatientImg", function(str){ if(str){ if(str.indexOf("../") > -1){ return str; //原福州代码中返回的相对路径 } var url = getImgUrl(str); return url; } return ""; }); // 搜索 $search.bind("input propertychange", function() { keyword = $search.val(); initPatientListByTeam(true); }); // 血糖血压切换 $(document).on("tap", "#viewTabs li", function() { $(this).addClass("curr").siblings().removeClass("curr"); $(".selectDate").children().removeClass("curr"); type = $(this).index(); selTypeDiv(); if(!loaded[type]){ startDate = getDateBefore(6); initPatientListByTeam(true); } }); // 天数选择 $(document).on("tap", ".selectDate li", function() { var days = $(this).attr("data-days"); startDate = getDateBefore(days); $(this).addClass("curr").siblings().removeClass("curr"); page = 1; initPatientListByTeam(true); }); // 血糖时间段切换 // $(document).on("tap", "#duringList li", function() { // $(this).addClass("curr").siblings().removeClass("curr"); // }) // 跳转个人血糖记录页 $(document).on("tap", "#XTlist li", function() { var patient = $(this).attr("data-patient"); openWebview("xuetang-view.html",{ code: patient, dateT: endDate }); }) // 跳转个人血压记录页 $(document).on("tap", "#XYlist li", function() { var patient = $(this).attr("data-patient"); openWebview("xueya-view.html",{ code: patient, dateT: endDate }); }) } function initScroll(){ $.each(document.querySelectorAll('.mui-scroll-wrapper'), function(index, pullRefreshEl) { var pullRefresh = mui(pullRefreshEl).pullRefresh({ down:{ callback: function(){ var self = this; setTimeout(function(){ initPatientListByTeam(true); self.endPulldownToRefresh(); }, 300); } }, up: { callback: function(){ var self = this; setTimeout(function(){ initPatientListByTeam(false); // self.endPullupToRefresh(); }, 300); } } }); scrollers.push(pullRefresh); }) } // 页面业务处理流程开始 new Promise(function(resolve, reject) { mui.plusReady(function() { resolve(true); }) }).then(function() { getBaseInfo(); }).then(function() { bindEvents(); initScroll(); initPatientListByTeam(true); }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); })