123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- // 基本信息(包括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);
- });
|