// 基本信息(包括userAgent) var baseInfo = null, //滚动条 scroller1=null, // 基础环境信息(包括当前webview) baseEnv = null, patient = null, patientName ="", page=0, pagesize=10; //文章列表 $articleList = $(".mui-table-view"); // 获取登录相关信息 var getBaseInfo = function() { // 登录的相关信息 var userAgent = JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; var self = plus.webview.currentWebview(); return Promise.resolve().then(function(res) { return env; }); }, //事件绑定 bindEvents = function(){ $('#scroll1').on('tap','li[data-article]',function() { var article = $(this).attr('data-article'); var batchNo = $(this).attr('data-batch-no')||""; openWebviewExtras("jiluxiangqing.html",{article:article,batchNo:batchNo}); }); }, loadListPromise = function(page) { plus.nativeUI.showWaiting(); return new Promise(function(resolve, reject) { sendPost("/doctor/health/edu/logs",{ page: page, pagesize: pagesize },function(res){ plus.nativeUI.closeWaiting(); if(res.msg){ mui.toast(res.msg); }else{ mui.toast("加载失败!"); } },function(res){ plus.nativeUI.closeWaiting(); if(res.status==200){ resolve(res.list) }else{ if(res.msg){ mui.toast(res.msg); }else{ mui.toast("加载失败!"); } } }) }); }, initScroll = function () { var page = 1; var pullRefresh = mui('.mui-scroll-wrapper').pullRefresh({ down: { callback: function() { page = 1; var self = this; var ul = self.element.querySelector('.mui-table-view'); var $scrollEl = $(ul).closest('.mui-scroll'); var $noResult = $scrollEl.find('.no-result'); loadListPromise(page) .then(function(list) { if(list && list.length) { page++; setTimeout(function() { var html = template('liTempl',{list: list}); $(ul).html(html); self.endPulldownToRefresh(); }, 1000); } }) .catch(function(e) { console && console.error(e) }) } }, up: { callback: function() { var self = this; var ul = self.element.querySelector('.mui-table-view'); var $scrollEl = $(ul).closest('.mui-scroll'); var $noResult = $scrollEl.find('.no-result'); loadListPromise(page) .then(function(list) { if(list && list.length) { page++; setTimeout(function() { var ul = self.element.querySelector('.mui-table-view'); var html = template('liTempl',{list: list}); $(ul).append(html); self.endPullupToRefresh(list.length < pagesize); }, 1000); } else { if(page == 1) { $noResult.show(); } self.endPullupToRefresh(true); } }) .catch(function(e) { console && console.error(e) }) } } }).pullupLoading(); }; template.helper("dateFormat", function(d) { return new Date(d).format('yyyy-MM-dd hh:mm') }); template.helper("handleSenders", function(str) { if(str) { var arr = str.split(',').slice(0,3); str = arr.join(','); } return str; }); // 页面业务处理流程开始 new Promise(function(resolve, reject) { // TODO 临时放开 //resolve(true); mui.plusReady(function() { // hrefhrefplus已经准备好,可以往下执行 resolve(true); }); }).then(function() { // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; }).then(function() { // 获取登录基本信息 baseInfo = getBaseInfo(); var self = plus.webview.currentWebview(); patient = self.patient; patientName = self.patientName; initScroll(); // 绑定页面事件 bindEvents(); }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); });