// 基本信息(包括userAgent) var baseInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; //文章列表 $articleView = $(".mui-table-view"); var article = ''; var batchNo = ""; var mscroll = null; // 获取登录相关信息 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(){ $articleView.on('tap','.patient-list li',function() { var patientCode = $(this).attr('data-code'); openWebviewExtras("../../huanzhe/html/huanzhexinxi.html",{patiCode:patientCode}); }) }, loadArticlePromise = function() { plus.nativeUI.showWaiting(); return new Promise(function(resolve, reject) { sendPost("doctor/health/edu/log",{ article: article, batchNo: batchNo },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; mscroll = mui('.mui-scroll-wrapper').pullRefresh({ down: { callback: function() { var self = this; loadArticlePromise() .then(function(list) { if(list && list.length) { var data = list[0]; var txtContent = $('
').append(data.content).text(); data.txtContent = txtContent; var html = template('liTempl',data); $('.mui-table-view').html(html); } self.endPulldownToRefresh(); }) .catch(function(e) { console && console.error(e) }) } } }); }; template.helper("dateFormat", function(d) { return new Date(d).format('yyyy-MM-dd hh:mm') }); // 页面业务处理流程开始 new Promise(function(resolve, reject) { // TODO 临时放开 //resolve(true); mui.plusReady(function() { // plus已经准备好,可以往下执行 resolve(true); }); }).then(function() { // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; }).then(function() { // 获取登录基本信息 baseInfo = getBaseInfo(); var self = plus.webview.currentWebview(); article = self.article; batchNo = self.batchNo || ""; initScroll(); // 绑定页面事件 bindEvents(); mscroll.pulldownLoading(); }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); }); template.helper("setPhoto", function(p) { return getImgUrl(p); });