// TODO 临时构造plus对象,使得能够在浏览器中进行调试 //var plus = null; // 基本信息(包括userAgent) var baseInfo = null, // 基础环境信息(包括当前webview、encry相关) baseEnv = null, docInfo = null; var $noResultWrap = $("#no_result_wrap"), $resultWrap = $("#result_wrap"), $preWeek = $("#preWeek"), $nextWeek = $("#nextWeek"), $thisWeek = $("#thisWeek"), $planList = $("#plan_list"), $addPlan = $("#addPlan"), $linshiSF = $("#linshiSF"); // iscroll 滚动条实例 var iscroller, page = 1, pageSize = 15, curDate = new Date(), //表示当前时间 curWeekHtml = "", //当前星期的时间 preWeekHtml = "", nextWeekHtml = "", chooseDate,//点击的日期 mySwiper = null; // 获取登录相关信息 var getBaseInfo = function() { docInfo = JSON.parse(plus.storage.getItem("docInfo")); // 登录的相关信息 var userAgent = JSON.parse(plus.storage.getItem("userAgent")); var date = baseEnv.webview.date; if(date){ curDate = new Date(date); } $("#month").find(".month").text((curDate.getMonth()+1) + "月"); $("#month").find(".year").text(curDate.getFullYear()); return { userAgent: userAgent, accessData: $.extend({},baseEnv.webview.accessData) } }, // 获取基础环境信息 getBaseEnvPromise = function () { var env = { webview: plus.webview.currentWebview() }; baseEnv = env; }, //获取随访列表 getPlanList = function(){ plus.nativeUI.showWaiting(); var url = '/doctor/followup/list', month = (curDate.getMonth() + 1) < 10 ? "0"+(curDate.getMonth() + 1) : curDate.getMonth() + 1, day = curDate.getDate() < 10 ? "0" +curDate.getDate() : curDate.getDate(); page = 1; var startDate = new Date(curDate), endDate = new Date(curDate); startDate.setDate(curDate.getDate() - curDate.getDay() + 0); endDate.setDate(curDate.getDate() - curDate.getDay() + 6); var start_month = (startDate.getMonth() + 1) < 10 ? "0"+(startDate.getMonth() + 1) : startDate.getMonth() + 1, start_day = startDate.getDate() < 10 ? "0" +startDate.getDate() : startDate.getDate(), end_month = (endDate.getMonth() + 1) < 10 ? "0"+(endDate.getMonth() + 1) : endDate.getMonth() + 1, end_day = endDate.getDate() < 10 ? "0" +endDate.getDate() : endDate.getDate(); var params = { startTime: startDate.getFullYear()+"-"+start_month+"-"+start_day+" 00:00:00", endTime: endDate.getFullYear()+"-"+end_month+"-"+end_day+" 23:59:59", page: page, pageSize: pageSize }; sendPost(url, params, function(){ mui.toast("获取随访列表失败"); }, function(res){ page = page + 1; var list = []; var week = ["周日","周一","周二","周三","周四","周五","周六"]; for(i=0; i< 7 ; i++){ var showDate = new Date(curDate); showDate.setDate(curDate.getDate() - curDate.getDay() + i); var obj = { year: showDate.getFullYear(), month: showDate.getMonth()+1, day: showDate.getDate(), week: week[i], date: showDate.format("yyyy-MM-dd"), length: 0 }; if(showDate.format("yyyy-MM-dd") == curDate.format("yyyy-MM-dd")){ obj.expand = 1; } var data = _.filter(res.data, function(o){ if(o.date == showDate.format("yyyy-MM-dd")){ o.length = o.list.length; if(o.length > 0){ for(j=0; j'+showDate.getDate()+''; //填充前一个星期的数据 var preWeekDate = new Date(curDate); preWeekDate.setDate(curDate.getDate() - curDate.getDay() - 7 + i); var preAct = (i == 1) ? "active":"", preDate = preWeekDate.format("yyyy-MM-dd"); preWeekHtml += '
'+preWeekDate.getDate()+'
'; //填充后一个星期的数据 var nextWeekDate = new Date(curDate); nextWeekDate.setDate(curDate.getDate() - curDate.getDay() + 7 + i); var nextAct = (i==1)?"active":"", nextDate = nextWeekDate.format("yyyy-MM-dd"); nextWeekHtml += '
'+nextWeekDate.getDate()+'
'; } }, showWeekDays = function(){ getWeekHtml(); $("[data-swiper-slide-index=0] .days").empty().append(curWeekHtml); $("[data-swiper-slide-index=1] .days").empty().append(nextWeekHtml); $("[data-swiper-slide-index=2] .days").empty().append(preWeekHtml); }, //显示当前时间对应的月份和年 showMonYear = function(){ var month = (curDate.getMonth() + 1)+"月", year = curDate.getFullYear(), showMonth = $("#month").find(".month").text(), showYear = $("#month").find(".year").text(); if(month != showMonth){ $("#month").find(".month").text(month); } if(year != showYear){ $("#month").find(".year").text(year); } }, initSwiper = function(){ mySwiper = new Swiper('.swiper-container',{ loop : true }); mySwiper.on('slideChangeStart',function(swiper){ swiper.lockSwipes(); }) mySwiper.on('slideChangeEnd',function(swiper){ swiper.unlockSwipes(); var activeIndex = swiper.activeIndex; var cur = $(swiper.slides[activeIndex]).find('.day span[class=active]').attr("data-val"); curDate = new Date(cur); showMonYear(); getPlanList(); getWeekHtml(); var nextIndex = (activeIndex == 4) ? 2 : (activeIndex +1), //当到达最后一页时,最后一页在循环中相当于index为1的页面 preIndex = (activeIndex == 0)? 2 : (activeIndex - 1);//当到达第一页面时,在循环中相当于index为3的页面 $(swiper.slides[nextIndex]).find(".days").empty().append(nextWeekHtml); $(swiper.slides[preIndex]).find('.days').empty().append(preWeekHtml); }); }, //初始化iscroll initScroll = function(){ //阻尼系数 var deceleration = mui.os.ios?0.003:0.0009; iscroller = mui('.mui-scroll-wrapper').scroll({ bounce: false, indicators: true, //是否显示滚动条 deceleration:deceleration }); mui('.mui-scroll-wrapper').pullRefresh({ down: { contentinit: '下拉显示上周信息', contentdown: '下拉显示上周信息', callback: function() { setTimeout(function() { mySwiper.slidePrev(); mui('.mui-scroll-wrapper').pullRefresh().endPulldownToRefresh(); }, 1000); } }, up:{ contentinit: '上拉显示下周信息', contentdown: '上拉显示下周信息', contentrefresh: '正在加载...', callback: function(){ var self = this; setTimeout(function() { mui('.mui-scroll-wrapper').scroll().scrollTo(0,0); mySwiper.slideNext(); mui('.mui-scroll-wrapper').pullRefresh().endPullupToRefresh(); mui('.mui-scroll-wrapper').scroll().reLayout(); }, 1000); } } }); }, setSex = function(s) { if(s == 1) { return "男"; } else if(s == 2) { return "女"; } }, setAge = function(str){ var r = str.substr(0,10); var arr = r.split('-'); var y = arr[0], m = arr[1], day = arr[2]; var now = new Date(), Y = now.getFullYear(), M = now.getMonth(), DAY = now.getDate(); if(y == Y){ return '0岁'; }else{ var diff = Y - y; //年岁之差 if(diff > 0){ if(m == M){ var dayDiff = DAY - day; if(dayDiff > 0){ return diff + '岁'; }else{ return (diff -1) + '岁'; } }else{ var monDiff = M - m; if(monDiff > 0){ return diff + '岁'; }else{ return (diff -1) + '岁'; } } }else{ return "未知"; } } return ""; }, //绑定事件 bindEvents = function(){ initSwiper(); $('#month').mobiscroll({ preset: 'date', theme: 'ios', lang: 'zh', dateOrder: 'yy mm', dateFormat: 'yy/mm', showLabel: true, showOnFocus: true, onSelect: function(valueText, inst) { var dateStr = valueText+"/01"; curDate = new Date(dateStr); var month = curDate.getMonth() + 1, year = curDate.getFullYear(); $(this).find(".month").text(month+"月"); $(this).find(".year").text(year); getPlanList(); showWeekDays(); if(mySwiper){ mySwiper.slideTo(1, 300, false); } } }); //新增随访 $addPlan.on("tap", function(){ openWebview("../../home/html/huanzhe.html", {follow_type : 1,origin:'suifang',chooseDate:chooseDate}); mui('#sheet1').popover('toggle'); }); //临时随访 $linshiSF.on("tap", function(){ openWebview("../../home/html/huanzhe.html", {follow_type : 2,origin:'suifang'}); mui('#sheet1').popover('toggle'); }); $planList.on('tap', '.mui-table-view-cell', function(){ var value = this.id; var $day = $(".days").find("span[data-val="+value+"]"); $day.closest(".days").find('span').removeClass("active"); $day.addClass("active"); }); $planList.on("tap", "li.plan_li2", function(){ var $this = $(this), status = $this.attr("data-status"), fv_id = $this.attr("data-id"); //随访状态 1-已完成,2-未开始,3-进行中 var jsonStr = $this.attr('data-json'); var docMsg = JSON.stringify(docInfo); var datas = JSON.parse(jsonStr); if(datas.prescriptionCode && status!=2){ openWebview("fvDetail.html", {followup_id: fv_id,status:status,prescriptionCode:datas.prescriptionCode}); }else{ if(datas.prescriptionCode){//长处方登记页面 var patientInfo={} patientInfo.code = datas.patientCode mui.openWindow('follow_way.html', 'xf_follow_way', { extras: { followup_id:fv_id, followClass:datas.followupClass, patientInfo:patientInfo, prescriptionCode: datas.prescriptionCode } }) }else{ openWebview("suifang_detail.html", {data: jsonStr,docInfo:docMsg}); } } }) $(".days").on('tap','.day',function(e){ var date = $(this).find('span').attr('data-val'); $(this).closest(".days").find('span').removeClass("active"); $(this).find('span').addClass("active"); curDate = new Date(date); showMonYear(); //滚动iscroll var $obj = $("#"+curDate.format("yyyy-MM-dd")); var height = $obj.offset().top; mui.scrollTo(-(parseFloat(height)-125), 300); //展开对应的日期数据 var classList = document.getElementById(curDate.format("yyyy-MM-dd")).classList; if (!classList.contains("mui-active")) { //展开时,需要收缩其他同类 var collapse = $obj.parent().find('.mui-collapse.mui-active'); if (collapse) { collapse.removeClass("mui-active"); } } classList.toggle("mui-active"); }); $("#today").on('tap',function(){ curDate = new Date(); showMonYear(); getPlanList(); showWeekDays(); if(mySwiper){ mySwiper.slideTo(1, 300, false); } }); //每天新增随访 $(document).on("tap", '.add_icon', function(){ var $li = $(this).closest("li"); chooseDate = $li.attr("id"); mui('#sheet1').popover('toggle'); }) $('#add').on("tap", function(){ chooseDate = $('.swiper-slide.swiper-slide-active').find('span.active').attr("data-val"); }) } template.helper("setSex", setSex); template.helper("setAge", setAge); mui.plusReady(function() { getBaseEnvPromise(); baseInfo = getBaseInfo(); showWeekDays(); getPlanList(); initScroll(); // 绑定页面事件 bindEvents(); window.addEventListener("refresh", function(){ showMonYear(); getPlanList(); }); }); template.helper("setPhoto", function(p) { return getImgUrl(p); });