// 基本信息(包括userAgent、上个页面传递的数据) var baseInfo = null, // 基础环境信息(包括当前webview) baseEnv = null; var $zhenliaoListWrapper = $('#zhenliao_list_wrap'), $zhenliaoList = $('#zhenliao_list'), $zixingListWrapper = $('#zixing_list_wrap'), $zixingList = $('#zixing_list'), $tabs = $('.sign-comonhd'), // 搜索无结果时显示 $noResultWrap = $('#no_result_wrap'); // 分页查询当前页数 var curPage = 1, // iscroll 滚动条实例 zhenLiaoIscroller, zixingIscroller; template.helper("toJson", function(v, i) { return JSON.stringify(v); }); // 获取基本信息(包括userAgent、上个页面传递的数据) var getBaseInfoPromise = function() { // 登录的相关信息 var userAgent = plus && JSON.parse(plus.storage.getItem("userAgent")) return { userAgent: userAgent, patiInfo: baseEnv.webview.patiInfo } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus&&plus.webview.currentWebview() }; return Promise.resolve().then(function(res) { return env; }); }, // 初始化诊疗用药列表 initZhenLiaoYongYaoList = function(list) { var html = template("zhenliao_tmpl", {list: _.map(list,function(v) { v.belongCatalogName = (_.values(v.CATALOG)[0] || "").slice(0,2); return v; })}) $zhenliaoList.append(html); }, // 初始化自行用药列表 initZiXingYongYaoList = function(list) { var html = template("zixing_tmpl", {list: list}) $zixingList.append(html); }, // 诊疗用药分页查询列表 searchZhenLiaoYongYaoByPaging = function () { var url = healthProfileServer+"doctor/archives/event/drug", curPage = 1, pagesize = 50, // params = { // strSSID: baseInfo.patiInfo.ssc, // startNum: (curPage-1) * pagesize, // endNum: curPage * pagesize // }; params = { patient: baseInfo.patiInfo.code, page: curPage, pageSize: pagesize } getReqPromise(url,params,'GET').then(function(res){ plus.nativeUI.closeWaiting(); if(res.status == 200) { curPage++; var data = JSON.parse(res.data), list = data.EhrList; if(!list|| !list.length) { $zhenliaoListWrapper.hide(); if($tabs.find('.sanp-flex.curr').index() == 0) { $noResultWrap.show(); } } else { if($tabs.find('.sanp-flex.curr').index() == 0) { $noResultWrap.hide(); } if(!zhenLiaoIscroller) { zhenLiaoIscroller = initScroller($zhenliaoListWrapper,url, function() { // 传递分页参数 return $.extend({},params,{page: curPage}); },function(res) { if(res.status == 200) { if(res.data.length==0){ //cy $(".pullUp").hide() }else{ var data = JSON.parse(res.data), list = data.EhrList; if(list && list.length) { curPage++; } initZhenLiaoYongYaoList(list); zhenLiaoIscroller.refresh(); } } else { mui.toast(res.msg); } }); } $zhenliaoListWrapper.show(); initZhenLiaoYongYaoList(list); } } else { mui.toast(res.msg); } zhenLiaoIscroller && zhenLiaoIscroller.refresh(); }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e) }); }, // 自行用药分页查询列表 searchZiXingYaoByPaging = function () { var url = "doctor/health_record/list_medication", curPage = 1, pagesize = 20, params = { // patient: "03b4965a075048f2a667652d5aea7b6f", patient: baseInfo.patiInfo.code, page: curPage, pagesize: pagesize, sortDate: (function() { var date = new Date(); return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate()+' 23:59:59'; })() }, laseSortDate = params.sortDate; getReqPromise(url,params,'GET').then(function(res){ if(res.status == 200) { var list = res.list; if(!list|| !list.length) { $zixingListWrapper.hide(); if($tabs.find('.sanp-flex.curr').index() == 1) { $noResultWrap.show(); } } else { laseSortDate = list[list.length -1].sortDate; if($tabs.find('.sanp-flex.curr').index() == 1) { $noResultWrap.hide(); } if(!zixingIscroller) { zixingIscroller = initScroller($zixingListWrapper,url, function() { // 传递分页参数 return $.extend({},params,{page: curPage+1,sortDate: laseSortDate}); },function(res) { if(res.status == 200) { var list = res.list; if(list && list.length) { laseSortDate = list[list.length -1].sortDate; curPage++; } initZiXingYongYaoList(list); if(list.length < pagesize){ $(".pullUp").hide(); }else{ $(".pullUp").show(); } zixingIscroller.refresh(); } else { mui.toast(res.msg); } }); } initZiXingYongYaoList(list); } if(list.length < pagesize){ $(".pullUp").hide(); }else{ $(".pullUp").show(); } zixingIscroller && zixingIscroller.refresh(); } else { mui.toast(res.msg); } }).catch(function(e) { console && console.error(e) }); }, // 滚动条分页实例初始化 initScroller = function($el,url,getData,pullUpAction) { var scroller = $el.initScroll({pullDown: false,pullUpAction: function() { var data = getData(); getReqPromise(url,data,'GET').then(function(data) { if(pullUpAction && $.isFunction(pullUpAction)) { pullUpAction(data); updatePullUpText(scroller,data.list); } }) }}); return scroller; }, // 更新分页上拉加载的提示文本 updatePullUpText= function(scroller,list) { var $wrap = $(scroller.wrapper), $pullupLabel = $wrap.find('.pullUpLabel'); if(!list || !list.length) { $pullupLabel.text('没有更多'); } else { $pullupLabel.text('上拉加载更多'); } scroller.on('refresh',function() { if(!list || !list.length) { $pullupLabel.text('没有更多'); } else { $pullupLabel.text('上拉加载更多'); } }); }, // 绑定页面事件 bindEvents = function () { $zhenliaoList.on('click','li',function() { var data = JSON.parse($(this).attr("data-json")); openWebview("single-profile.html",{eventInfo: { id: data.EVENT, catalogCode: data.CATALOG_CODE, type: (function() { if(data.TYPE=="1"){ return "门诊"; } else if(data.TYPE=="2"){ return "住院"; } })(), serial: data.SERIAL },patiInfo: baseInfo.patiInfo}); }); $tabs.on('click','.sanp-flex',function() { var index = $(this).index(); $(this).siblings().removeClass('curr'); $(this).addClass('curr'); if(index==0) { $zixingListWrapper.hide(); if($zhenliaoList.find('li').length == 0) { $noResultWrap.show(); } else { $noResultWrap.hide(); } $zhenliaoListWrapper.show(); } else if(index == 1) { $zhenliaoListWrapper.hide(); if($zixingList.find('li.li-item').length == 0) { $zixingListWrapper.hide(); $noResultWrap.show(); } else { $noResultWrap.hide(); $zixingListWrapper.show(); } } }); }; // 页面业务处理流程开始 new Promise(function(resolve, reject) { // TODO 临时放开 //resolve(true); mui.plusReady(function() { // plus已经准备好,可以往下执行 resolve(true); }); }).then(function() { plus.nativeUI.showWaiting(); // 获取基础环境信息 return getBaseEnvPromise().then(function(env) { baseEnv = env; }).then(function() { // 获取登录医生信息 baseInfo = getBaseInfoPromise(); searchZhenLiaoYongYaoByPaging(); searchZiXingYaoByPaging(); // 绑定页面事件 bindEvents(); }) }).catch(function(e) { plus.nativeUI.closeWaiting(); console && console.error(e); });