// TODO 临时构造plus对象,使得能够在浏览器中进行调试 // var plus = null; // 基本信息(包括userAgent、上个页面传递的数据) var baseInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; var $patientListWrapper = $('#patient_list_wrap'), $patientList = $('#pati_list'), // 搜索输入框 $searchbarInput = $('.searchbar .search-input'), // 搜索无结果时显示 $noResultWrap = $('#no_result_wrap'), patientInfo = null; // 分页查询当前页数 var curPage = 0, pageSize = 15, myScroll = null, hasMore = true; // 获取基本信息(包括userAgent、上个页面传递的数据) var getBaseInfoPromise = function() { // 登录的相关信息 var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, // 分页查询列表 searchByPaging = function (isRefresh) { curPage = isRefresh ? 0 : curPage+1; var url = "/doctor/concern/getConcernPatients", params = { page:curPage,pageSize:pageSize}; getReqPromise(url,params,'GET').then(function(res){ var data = res.data; if(!data || !data.length) { $patientListWrapper.hide(); $noResultWrap.show(); } else { $noResultWrap.hide(); $patientListWrapper.show(); } data = _.map(data,function(item){ item.photo = getImgUrl(item.photo); return item; }) if(isRefresh){ myScroll.refresh(true); $patientList.empty().append(template("pati_list_tmpl", {list: data})); }else{ $patientList.append(template('pati_list_tmpl', {list: data})); } if(data.length < pageSize){ hasMore = false; myScroll.endPullUpToRefresh(!hasMore); $(".mui-pull-bottom-tips").hide(); }else{ hasMore = true; $(".mui-pull-bottom-tips").show() } }).catch(function(e) { console && console.error(e) }); }, // 滚动条分页实例初始化 initScroller = function() { //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; mui('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); myScroll = mui(".mui-scroll").pullToRefresh({ up: { callback: function(){ var self = this; setTimeout(function() { searchByPaging(); self.endPullUpToRefresh(!hasMore); }, 1000); } }, down: { callback: function() { var self = this; setTimeout(function() { searchByPaging(true); self.endPullDownToRefresh(); }, 1000); } } }); }, // 绑定页面事件 bindEvents = function () { $patientList.on('tap','li[data-patient-code]',function(e) { var code = $(this).attr("data-patient-code"); var mobile = $(this).attr("data-patient-phone"); var address = $(this).attr("data-patient-address"); if(baseEnv.webview.origin=="suifang") {//“随访”功能 if(baseEnv.webview.follow_type == 1){ openWebview("../../suifang/html/add_plan.html",{patientInfo: {code:code,mobile:mobile,address:address},chooseDate:baseEnv.webview.chooseDate}); return false; } if(baseEnv.webview.follow_type == 2){ openWebview("../../suifang/html/follow_way.html",{patientInfo: {code:code,mobile:mobile,address:address}}); return false; } }else{ openWebview("../../huanzhe/html/huanzhexinxi.html",{ patiCode: code }); } return false; }) $searchbarInput.on('tap',function() { mui.openWindow({ id: "searchhuanzhe2", url: "../../huanzhe/html/searchhuanzhe.html", extras: {} }) }); /*刷新事件*/ // window.addEventListener("refresh", function group(e) { // searchByPaging(true); // }); }; // 页面业务处理流程开始 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 = getBaseInfoPromise(); initScroller(); searchByPaging(true); // 绑定页面事件 bindEvents(); if(baseEnv.webview.origin){//“随访”功能,需要返回按钮 $(".mui-action-back").show(); } }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); }); function setAge(age) { if(age == 0) { return "<1"; } if(age == -1) return "未知"; return age; } template.helper("setAge", setAge); function setSex(s) { if(s == 1) { return "男"; } else if(s == 2) { return "女"; } } template.helper("setSex", setSex);