var listPage = function(){ var d = dialog({contentType:'load', skin:'bk-popup'}); //设置变量标记选项的值 var deseaseType = 0, startDate = '', endDate = ''; var page = 0, pagesize = 10, recipeNo = 0; // 记录 function pageInit(){ getPrescriptionList(true); initScroller(); bindEvents(); } function getPrescriptionList(isInit){ d.show(); if(isInit){ page = 0; //mui(".mui-scroll-wrapper").pullRefresh().scrollTo(0, 0, 1); } var url = 'patient/prescriptionInfo/getRecipeMasterList', params = { type: 1, //type: 1-查询处方,2-我的续方, 3-续方记录 isRenewal: 1, //1: 可续方,2: 无过滤 diagnosisCode: deseaseType, //0: 全部,1:高血压,2: 糖尿病 startDate: startDate?startDate+' 00:00:00':startDate, endDate: endDate?endDate+' 23:59:59':endDate, page: page, size: pagesize // recipeNo:recipeNo }; sendPost(url, params, 'json', 'get', queryFailed, function(res){ if(res.status == 200){ d.close(); if(res.data.list.length >0){ $("#next").removeClass("disabled") $(".mui-scroll-wrapper").show(); $(".div-no-info").hide(); var list = _.map(res.data.list, function(o){ o.jsonStr = JSON.stringify(o); var canXF = getXFStatus(o.prescriptionDt, o.createTime); o.canXF = canXF; recipeNo = o.code; return o; }); var html = template("prescription_tmp", {list: list}); if(!isInit){ $("#prescriptionList").append(html); }else{ $("#prescriptionList").empty().append(html); } if(res.data.list.length < pagesize){ mui(".mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); }else{ page ++; } }else{ if(isInit){ //初始请求,无数据 $(".mui-scroll-wrapper").hide(); $(".div-no-info").show(); $("#next").hide(); }else{ $("#next").addClass("disabled"); } } }else{ queryFailed(res); } }); } function getXFStatus(arr, date){ var isXFDesease = true, statusName = '', canXF = false; if(arr){ for(i=0; i now){ //6个月内的时间 statusName = '续方'; canXF = true; // } } } return canXF; } /** * 根据选择的时间类型获取开始和结束时间 */ function getDate(type){ var now = new Date(), d = new Date(); switch (type){ case 'all': startDate = ''; endDate = ""; break; case 'week': d.setDate(d.getDate() - 6); break; case 'month': d.setMonth(d.getMonth() - 1); d.setDate(d.getDate() + 1); break; case 'half-year': d.setMonth(d.getMonth() - 2); d.setDate(d.getDate() + 1); break; } if(type != 'all'){ endDate = now.Format('yyyy-MM-dd'); startDate = d.Format('yyyy-MM-dd'); } } function bindEvents(){ $(".c-lab-mor").on("click","li",function(){ var index = $(this).index(); $(".c-lab-mor li i").removeClass("active"); $(this).find("i").addClass("active"); if(index==0){//所有诊断 $(".div-diagnosis").show(); $(".div-dates").hide(); }else{ $(".div-diagnosis").hide(); $(".div-dates").show(); } $(".modal-overlay").show(); }); //所有诊断-tab点击事件 $(".div-diagnosis").on("click","li",function(){ $(".div-diagnosis li").removeClass("active"); $(this).addClass("active"); $(".c-lab-mor li i").removeClass("active"); $(".modal-overlay").hide(); $(".div-diagnosis").hide(); $(".c-lab-mor li").eq(0).find("span").html($(this).find("label").html()); //TODO 搜索数据处理 deseaseType = $(this).attr("data-val"); page = 1; getPrescriptionList(true); }); //全部时间-tab点击事件 $(".div-dates").on("click","li",function(){ $(".div-dates li").removeClass("active"); $(this).addClass("active"); $(".c-lab-mor li i").removeClass("active"); $(".modal-overlay").hide(); $(".div-dates").hide(); $(".c-lab-mor li").eq(1).find("span").html($(this).find("label").html()); //TODO 搜索数据处理 var value = $(this).attr("data-val"); getDate(value); page = 1; getPrescriptionList(true); }); //点击遮罩事件 $(".modal-overlay").on("click",function(){ $(".div-diagnosis").hide(); $(".div-dates").hide(); $(".c-lab-mor li i").removeClass("active"); $(".modal-overlay").hide(); }); //申请续方按钮事件 $(".ul-consultation").on("tap",".div-sqxf-btn",function(e){ e.stopPropagation(); var $this = $(this); if($this.hasClass('appy-btn')){ var code = $this.closest("li").attr("data-code"); window.localStorage.setItem("prescriptionCode", code); viewApi.back(); }else{ return false; } }) //域跳转处方详情页 .on("tap","li",function(){ var code = $(this).attr("data-code"); window.location.href = "../../prescription/html/prescription_detail.html?code="+code; }); //显示下一条数据 $("#next").on('tap', function(){ if($(this).hasClass("disabled")){ return false; } getPrescriptionList(false); }) } function initScroller(){ //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; mui('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); mui(".mui-scroll-wrapper").pullRefresh({ down: { callback: function() { var self = this; setTimeout(function() { getPrescriptionList(true); self.endPulldownToRefresh(); }, 1000); } }, up: { callback: function() { var self = this; setTimeout(function(){ getPrescriptionList(); self.endPullupToRefresh(); }, 1000); } } }); } function queryFailed(res){ d.close(); if(res && res.msg) { dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: res.msg }).show(); } else { dialog({ contentType: 'tipsbox', skin: 'bk-popup', content: '加载失败' }).show(); } } return { initPage: pageInit }; }