// 基本信息(包括userAgent、上个页面传递的数据) var baseInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; var $eventListWrapper = $('#recent_event_list_wrap'), $eventList = $('#recent_event_list'), // 搜索无结果时显示 $noResultWrap = $('#no_result_wrap'); // 分页查询当前页数 var curPage = 1, // 最后一条记录的eventDate lastTime = "", // iscroll 滚动条实例 iscroller; template.helper("toJson", function(v, i) { return JSON.stringify(v); }); // 获取基本信息(包括userAgent、上个页面传递的数据) var getBaseInfoPromise = function() { // 登录的相关信息 var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent, patiInfo: baseEnv.webview.patiInfo } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, // 初始化就诊事件列表 initEventList = function(list) { var html = template("recent_event_tmpl", {list: list}) $eventList.append(html); }, // 分页查询列表 searchByPaging = function () { var url = healthProfileServer+"doctor/archives/event/report", pagesize = 50, params = { patient: baseInfo.patiInfo.code, page: curPage, pageSize: pagesize }; getReqPromise(url,params,'GET').then(function(res){ plus.nativeUI.closeWaiting(); if(!iscroller) { iscroller = initScroller($eventListWrapper,url, function() { // 传递分页参数 return $.extend({},params,{page: curPage,lastTime: lastTime}); },function(res) { if(res.status == 200) { var list = res.data; if(list && list.length) { curPage++; lastTime = list[list.length-1].eventDate; } initEventList(list); if(list.length < pagesize){ $(".pullUp").hide(); }else{ $(".pullUp").show(); } iscroller.refresh(); } else { mui.toast(res.msg); } }); } if(res.status == 200) { curPage++; var list = res.data; if(!list|| !list.length) { $eventListWrapper.hide(); $noResultWrap.show(); } else { $noResultWrap.hide(); $eventListWrapper.show(); initEventList(list); lastTime = list[list.length-1].eventDate; } if(list.length < pagesize){ $(".pullUp").hide(); }else{ $(".pullUp").show(); } iscroller.refresh(); } else { mui.toast(res.msg); } }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e) }); }, // 滚动条分页实例初始化 initScroller = function($el,url,getData,pullUpAction) { var scroller = $el.initScroll({pullDown: false,pullUpAction: function() { var data = getData(); getReqPromise(url,data,'GET').then(function(data) { if(pullUpAction && $.isFunction(pullUpAction)) { pullUpAction(data); updatePullUpText(scroller,data.list); } }) }}); return scroller; }, // 更新分页上拉加载的提示文本 updatePullUpText= function(scroller,list) { var $wrap = $(scroller.wrapper), $pullupLabel = $wrap.find('.pullUpLabel'); if(!list || !list.length) { $pullupLabel.text('没有更多'); } else { $pullupLabel.text('上拉加载更多'); } scroller.on('refresh',function() { if(!list || !list.length) { $pullupLabel.text('没有更多'); } else { $pullupLabel.text('上拉加载更多'); } }); }, // 绑定页面事件 bindEvents = function () { $eventList.on('click','li',function() { var data = JSON.parse($(this).attr("data-json")); if(data.dataFrom==1) { openWebview("single-profile.html",{eventInfo: data,patiInfo: baseInfo.patiInfo}); } else { openWebview("jiuzhenxiangqing.html",{eventInfo: data,patiInfo: baseInfo.patiInfo}); } }); }; // 页面业务处理流程开始 new Promise(function(resolve, reject) { // TODO 临时放开 //resolve(true); mui.plusReady(function() { // plus已经准备好,可以往下执行 resolve(true); }); }).then(function() { plus.nativeUI.showWaiting(); // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; }).then(function() { // 获取登录医生信息 baseInfo = getBaseInfoPromise(); searchByPaging(); // 绑定页面事件 bindEvents(); }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); });