var now = new Date(), patiCode, deviceSn, type, unit; mui.init(); mui.plusReady(function(){ var self = plus.webview.currentWebview(); patiCode = self.patiCode; deviceSn = self.deviceSn; type = self.type; $("#title").text(self.deviceName); if(type == 1){ unit = "mmol/L"; }else if(type == 2){ unit = "mmHg"; } //获取近半年的月份信息 getMonth(); bindEvents(); templateHelper(); }); function getMonth(){ var list = []; for(i=0; i<6; i++){ var d = new Date(); d.setMonth(now.getMonth() - i); list.push(d.format("yyyy-MM")); } var html = template("month-tmp", {list: list}); $("#content").empty().append(html); } function getMonthDate(month){ var lastDate = getMonthLastDate(month), days = lastDate.getDate(), dateList = []; if(now.getMonth() == lastDate.getMonth()){ var days2 = now.getDate(); for(i=0; i 0){ $activeMonth.removeClass("active"); $activeMonth.find(".fa").removeClass("fa-angle-up").addClass("fa-angle-down"); $activeMonth.parent().find(".date-list").hide(); } $this.addClass("active"); $this.find(".fa").removeClass("fa-angle-down").addClass("fa-angle-up"); $this.parent().find(".date-list").show(); if($this.parent().find(".date-panel").length > 0){ return false; } getMonthDateData(month); }); $("#content").on('click', ".date", function(){ var $this = $(this), date = $this.attr("data-val"); if($this.hasClass("active")){ $this.removeClass("active"); $this.find(".fa").removeClass("fa-angle-up").addClass("fa-angle-down"); $this.parent().find(".record-list").hide(); return false; } var $activeDate = $this.parent().parent().find(".date.active"); if($activeDate.length > 0){ $activeDate.removeClass("active"); $activeDate.find(".fa").removeClass("fa-angle-up").addClass("fa-angle-down"); $activeDate.parent().find(".record-list").hide(); } $this.addClass("active"); $this.find(".fa").removeClass("fa-angle-down").addClass("fa-angle-up"); $this.parent().find(".record-list").show(); if($this.parent().find(".record").length > 0){ return false; } getDateRecords(date); }); $(".header-link").on('click', function(){ openWebview("../../huanzhe/html/huanzhexinxi.html",{ patiCode: patiCode }); }) } function templateHelper(){ template.helper("getTime", function(str){ var s = str.replace(/\-/g, "/"); var d = new Date(s); return d.format("hh:mm"); }); template.helper("getTypeName", function(gi_type){ switch(gi_type){ case "1": return "早餐前"; break; case "2": return "早餐后"; break; case "3": return "午餐前"; break; case "4": return "午餐后"; break; case "5": return "晚餐前"; break; case "6": return "晚餐后"; break; case "7": return "睡前"; break; } }); template.helper("getXTValue", function(val, type){ val = parseFloat(val); var min = 0, max = 0; switch(type){ case "1": case "3": case "5": case "7": min = 4, max = 7; break; case "2": case "4": case "6": min = 4, max = 11.1; break; } if(val < min){ return ''+val+unit+''; }else if(val > max){ return ''+val+unit+''; }else{ return val+unit; } }); template.helper("getXYValue", function(val, type){ val = parseFloat(val); var min, max; if(type = 1){ min = 90; max = 140; }else{ min = 60; max = 90; } if(val < min){ return ''+val+unit+''; }else if(val > max){ return ''+val+unit+''; }else{ return val+unit; } }) }