// 基本信息(包括userAgent) var baseInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; // 搜索结果 var $resultList = $('.activiy-list'); var self; var docInfo; var scrollered, page = 1, size = 10; // 获取登录相关信息 var getBaseInfo = function() { // 登录的相关信息 var userAgent = JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent, teamInfo: JSON.parse(plus.storage.getItem("teamInfo")) } }, // 获取基础环境信息 getBaseEnvPromise = function () { self = plus.webview.currentWebview(); docInfo = JSON.parse(plus.storage.getItem("docInfo")); var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, //下拉刷新上拉加载 updatePullUpText = function(scroller, list) { var $wrap = $(scroller.wrapper), $pullupLabel = $wrap.find('.pullUpLabel'); $(".pullUp").removeClass("loading"); if(!list) { $pullupLabel.text('没有更多'); } else if(list.length < 10) { $(".pullUp").hide(); } else { $pullupLabel.text('上拉加载更多'); } scroller.on('refresh', function() { if(!list) { $pullupLabel.text('没有更多'); } else if(list.length < 10) { $(".pullUp").hide(); } else { $pullupLabel.text('上拉加载更多'); } }); }, // 初始化活动列表 activityList = function(boolean) { plus.nativeUI.showWaiting(); var params = { task:"{}", page: page, size: size } sendPost("/doctor/healthBank/selectTask", params, queryFails, function(res) { if(res.status == 200) { plus.nativeUI.closeWaiting(); var list = _.map(res.data.detailModelList, function(o) { if(o.img){ o.img = getImgUrl(o.img) }else{ o.img = "../images/morenhuodong_banner01_img.png"; } return o; }) if(list.length < 10) { $(".lastmsg").show() } updatePullUpText(scrollered, list); var html = template("result_tmpl", {list: list}); if(boolean) { $resultList.empty().append(html); if(list.length == 0) { $("#no_result_wrap").show(); } else { $("#no_result_wrap").hide(); } } else { $resultList.append(html); } $('#wrapper').show(); scrollered.refresh(); } else { plus.nativeUI.closeWaiting(); queryFails(res); } }, 'post') }, //查询失败回调 queryFails = function(res) { if(res) { mui.toast(res.msg) } else { mui.toast("加载失败!") } }, // 绑定页面事件 bindEvents = function () { //初始化下拉刷新 上拉加载 scrollered = $("#wrapper").initScroll({ pullDownAction: function() { page = 1 activityList(true) }, pullUpAction: function() { page++ activityList(false) } }); $resultList.on("tap", "li", function() { activityId = $(this).attr("data-code") openWebview("activity-detail.html", { activityId: activityId }); }); }; // 页面业务处理流程开始 mui.plusReady(function() { //获取当前页面 var self = plus.webview.currentWebview(); getBaseEnvPromise(); //绑定事件 bindEvents(); //数据渲染 activityList(true); })