123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- // 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<o.length; j++){
- o.list[j].jsonStr = JSON.stringify(o.list[j]);
- }
- }
-
- return o;
- }
- });
- $.extend(obj,data[0]);
- list.push(obj);
- }
- var html = template("plan_list_temp", {data:list});
- $planList.empty().append(html);
- if(res.status != 200){
- mui.toast("获取随防数据失败");
- }
- plus.nativeUI.closeWaiting();
- },"GET");
- },
- getWeekHtml = function(){
- curWeekHtml = "";
- preWeekHtml = "";
- nextWeekHtml = "";
- for(i=0; i< 7 ; i++){
- var showDate = new Date(curDate);
- showDate.setDate(curDate.getDate() - curDate.getDay() + i);
- var active = (showDate.getDate() == curDate.getDate())? "active" : "",
- date = showDate.format("yyyy-MM-dd");
- curWeekHtml += '<div class="ui-col-1 c-t-center c-f14 c-333 day"><span class="'+active+'" data-val="'+date+'">'+showDate.getDate()+'</span></div>';
-
- //填充前一个星期的数据
- 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 += '<div class="ui-col-1 c-t-center c-f14 c-333 day"><span class="'+preAct+'" data-val="'+preDate+'">'+preWeekDate.getDate()+'</span></div>';
-
- //填充后一个星期的数据
- 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 += '<div class="ui-col-1 c-t-center c-f14 c-333 day"><span class="'+nextAct+'" data-val="'+nextDate+'">'+nextWeekDate.getDate()+'</span></div>';
- }
- },
- 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);
- });
|