var d = dialog({ contentType: 'load', skin: 'bk-popup' }); var pagetype = 38; var pagesize = [15,15,15], page = [0,1,1], //3个tab对应的分页的页数 loaded = [true, false, false], //3个tab对应的页面是否加载过,第一个tab默认加载过 lastYear = ['2016', '2016', '2016']; // 记录数据最后的年份信息 var userAgent = window.localStorage.getItem(agentName); var userInfo; $(function(){ checkUserAgent(); initScroller(); }); function initScroller(){ //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; mui('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); mui.ready(function() { //循环初始化所有下拉刷新,上拉加载。 $.each(document.querySelectorAll('.mui-slider-group .mui-scroll-wrapper'), function(index, pullRefreshEl) { if(index == 0){ mui(pullRefreshEl).pullRefresh({ down: { callback: function() { var self = this; setTimeout(function() { d.showModal(); var isrenewal = $("#checkbox").prop("checked"); getPrescriptionList(index, true, isrenewal? 1 : 2); // getPrescriptionList(index, true); self.endPulldownToRefresh(); }, 1000); } }, up: { callback: function() { var self = this; setTimeout(function(){ d.showModal(); getPrescriptionList(index); self.endPullupToRefresh(); }, 1000); } } }); }else{ mui(pullRefreshEl).pullRefresh({ down: { callback: function() { var self = this; setTimeout(function() { getXFList(index, true); self.endPulldownToRefresh(); }, 1000); } }, up: { callback: function() { var self = this; setTimeout(function() { getXFList(index); self.endPullupToRefresh(); }, 1000); } } }); } }); }); } function queryInit(){ userInfo = JSON.parse(userAgent); if(!canPrescription){ $('#memberContainer').hide(); $("#slider").hide(); $("#building").show(); }else{ initFamilyData(); checkPatientInfo(); bindEvents(); templatehelper(); } wxGetSign(); } //初始化家庭成员 function initFamilyData(){ appendFamilyMember($('#memberContainer'),function(){ loaded = [false, false, false]; page = [0,1,1]; checkPatientInfo(); //切换家人时,将‘只查看可续方记录’的checkbox设置为未选中 // $("#checkbox").prop("checked", false); },function(){ //判断有授权家人,修改样式 $("#slider").css({ 'top': '90px', 'height': 'calc(100% - 90px)' }); }); } //判断患者是否是慢病患者 function checkPatientInfo(){ d.showModal(); var url = 'patient/baseinfo', params = {}; sendPost(url, params, 'json', 'post', queryFailed, function(res){ if(res.status == 200){ var isChronicDisease = res.data.prescription; //慢病病人标记 if(isChronicDisease){ //显示3个tab mui('#slider').slider().gotoItem(0); $(".mui-slider-indicator .c-33").eq(1).show(); $(".mui-slider-indicator .c-33").eq(2).show(); mui('#slider').slider().setStopped(false); }else{ //显示1个tab mui('#slider').slider().gotoItem(0); $(".mui-slider-indicator .c-33").eq(1).hide(); $(".mui-slider-indicator .c-33").eq(2).hide(); mui('#slider').slider().setStopped(true); } getPrescriptionList(0, true); }else{ queryFailed(res); } }); } /** * 获得处方记录 * @param {number} index 对应tab的index * @param {boolean} isInit 是否是初始加载(用于初始加载和下拉刷新) * @param {boolean} isRenewal 是否只获取可续方的列表 1-是,2-无过滤 */ function getPrescriptionList(index, isInit, isRenewal){ var tmpIndex = parseInt(index) + 1; if(isInit){ page[index] = 0; if(tmpIndex == 1){ //处方列表的获取可续方处方数据的特殊处理 $("#recordList0").show(); $("#item1 .straight-line").show(); } mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().scrollTo(0, 0, 1000); } var url = "/patient/prescriptionInfo/getRecipeMasterList", params = { type: 1, //type: 1-查询处方,2-我的续方, 3-续方记录 isRenewal: isRenewal ? isRenewal : 2, //1: 可续方, 2:无过滤 startDate: '', endDate: '', // recipeNo: page[index], page: page[index], size: pagesize[index] }; sendPost(url, params, 'json', 'GET', queryFailed, function(res){ d.close(); if(res.status == 200){ loaded[index] = true; //暂时默认数据是按年份group了的 [{year: 2017, list:[]}] if(res.data.list.length > 0){ $("#next").removeClass("disabled"); var year = parseInt((new Date()).getFullYear()); var obj = _.groupBy(res.data.list, function(o){ for(y = year; y >= 2016; y--){ if(o.createTime.substr(0,4) == y){ lastYear[index] = y; return y; } } }); for(y in obj){ var list = obj[y]; for(var i=0; i 0){ var year = parseInt((new Date()).getFullYear()); var obj = _.groupBy(res.data, function(o){ for(y = year; y >= 2016; y--){ if(o.createTime.substr(0,4) == y){ return -y; } } }); var temp = 'record'+index+'_tmp'; var html = template(temp, {list: obj}); if(isInit){ $("#item"+tmpIndex+" .mui-scroll-wrapper").show(); $("#item"+tmpIndex+" .div-no-info").hide(); $("#recordList"+index).empty().append(html); }else{ $("#recordList"+index).append(html); } if(res.data.length < pagesize){ mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); }else{ page[index] ++; } }else{ if(isInit){ //无数据 $("#item"+tmpIndex+" .mui-scroll-wrapper").hide(); $("#item"+tmpIndex+" .div-no-info").show(); }else{ mui("#item"+tmpIndex+" .mui-scroll-wrapper").pullRefresh().endPullupToRefresh(true); } } }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 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(); } } function bindEvents(){ document.querySelector('.mui-slider').addEventListener('slide', function(event) { var index = event.detail.slideNumber; console.log(index); if(!loaded[index]){ //tab未加载过,则加载数据 d.showModal(); if(index == 0){ getPrescriptionList(index, true); }else{ getXFList(index, true); } } }); //只查看可续方记录按钮 $("#checkbox").on('change', function(){ d.showModal(); if(this.checked){ //获取可续方的记录 getPrescriptionList(0, true, 1); }else{ //获取全部记录 getPrescriptionList(0, true); } }); //'处方记录'tab内item的点击事件 $("#recordList0").on('tap', '.prescription-item', function(){ var code = $(this).attr('data-code'); //跳转去处方详情页 window.location.href = 'prescription_detail.html?code='+code; }).on('tap', '.btn', function(e){ e.stopPropagation(); //防止事件冒泡 var status = $(this).attr("data-status"), code = $(this).closest('.prescription-item').attr('data-code'); //两种状态:1.申请续方 2.续方审核中 if(status == 1){ //跳转去’新增续方咨询‘页面 var patient = $(this).closest('.prescription-item').attr('data-patient'), name = $(this).closest('.prescription-item').attr('data-pname'); window.location.href = "../../yszx/html/add-prescription-consult.html?patient="+patient+'&name='+name+'&prescriptionCode='+code; }else{ //跳转去’续方记录‘页面 var prescriptionCode = $(this).attr("data-preCode"); window.location.href = "re-prescription_info.html?code="+prescriptionCode+'&toUser='+userInfo.uid; } }); //'我的续方'tab内item对应的点击事件 $("#recordList1").on('tap', '.prescription-item', function(){ var code = $(this).attr('data-code'); //跳转去续方详情页面,只有审核通过的页面才有我的续方页面 window.location.href = "re-prescription_detail.html?code="+code; }).on('tap', '.btn', function(e){ e.stopPropagation(); var code = $(this).closest('.prescription-item').attr("data-code"); //订单跟踪按钮,跳转去订单跟踪页面 window.location.href = "order_tracking.html?code="+code+'&toUser='+userInfo.uid; }); //'续方管理'tab内item对应的点击事件 $("#recordList2").on('tap', ' .prescription-item', function(){ var code = $(this).attr('data-code'); //跳转去续方记录页面 window.location.href = "re-prescription_info.html?code="+code+'&toUser='+userInfo.uid; }); //获取下一条处方数据 $("#next").on('tap', function(){ if($(this).hasClass("disabled")){ return false; } d.showModal(); getPrescriptionList(0); }) } function templatehelper(){ template.helper('getDateTime', function(str){ if(str && str.length > 0){ //str = 2017-07-31 11:09:53.0 return str.substr(0, 19); } return ''; }); template.helper('getAbs', function(str) { console.log(str) return str.substr(1, 4); }); template.helper('showStatus', function(status){ return getStatusInfoAndImg(status).name; }); template.helper('returnStatusImg', function(status){ return getStatusInfoAndImg(status).img; }); template.helper('getDate', function(str){ if(str && str.length > 0){ return str.substr(5, 6); } }); template.helper('getXF', function(arr, date){ var isXFDesease = false; if(arr){ for(i=0; i now){ //6个月内的时间 return '续方'; } } } return ''; }); } //获取微信信息,并配置微信api接口 function wxGetSign(){ var params = {}; params.pageUrl = window.location.href; $.ajax(server + "weixin/getSign", { data: params, dataType: "json", type: "post", success: function(res){ if (res.status == 200) { var t = res.data.timestamp; var noncestr = res.data.noncestr; var signature = res.data.signature; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: appId, // 必填,公众号的唯一标识 timestamp: t, // 必填,生成签名的时间戳 nonceStr: noncestr, // 必填,生成签名的随机串 signature: signature,// 必填,签名,见附录1 jsApiList: [ 'closeWindow' ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); } } }); }