var d = dialog({contentType:'load', skin:'bk-popup'}).show(); var dd = dialog({contentType:'load', skin:'bk-popup'}); var $tizhengList = $('#tizhengList'), $baojianList = $('#baojianList'); var xuetangRecord = null, xuyaRecord = null, tizhongRecord = null, yaoweiRecord = null, yundongRecord = null, yongyaoRecord = null, yinshiRecord = null, tzSta = false, xtdt = '', xydt = '', tzdt = '', ywdt = '', yddt = '', yydt = '', ysdt = ''; var xuetangDuring = ['','早餐前', '早餐后', '午餐前', '午餐后', '晚餐前', '晚餐后', '睡前']; function checkDate (v) { return (v < 10 ? '0' + v : v); } //获取最新的体征记录 function getRecentDataPromise() { var user = JSON.parse(localStorage.getItem(agentName)); return new Promise(function(resolve, reject) { sendPost("patient/health_index/last", {}, "json", "get", function() { d.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show(); }, function(res) { d.close(); if(res.status == 200) { console.log(res) // res.data.xt = JSON.parse(res.data.xt); // var xtD = new Date(res.data.xt.czrq); // res.data.xt.czrq = xtD.getFullYear() + '-' + // checkDate(xtD.getMonth() + 1) + // '-' + checkDate(xtD.getDate()); resolve(res) } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show(); } }); }) } //获取最新保健记录 function getBJRecentDataPromise () { return new Promise(function( resolve, reject){ sendPost("patient/health_record/recent", {}, "json", "get", function() { dd.close(); dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show(); }, function(res) { dd.close(); if(res.status == 200) { console.log(res); resolve(res) } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show(); } }); }); } function getLevelClazz(value,max,min) { if(!value||(!max && !min)) { return ''; } if(value < min) { return 'low'; } else if(value > max) { return 'high'; } else { return '' } } function bindEvents() { //标签切换 $(".pt-tab li").click(function(){ var id = $(this).attr("id"); $(".pt-tab li").removeClass("hit"); $(this).addClass("hit"); if(id=="tizhengLi"){ $("#tizhengList").show(); $("#baojianList").hide(); }else{ $("#tizhengList").hide(); $("#baojianList").show(); } }); $('#tizhengList').on('click','li',function() { var index = $(this).index(); var dat = new Date(), nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate(); if(index == 0) { window.location.href = 'xuetang-view.html?dateT=' + (xtdt || nowD); } if(index == 1) { window.location.href = 'xueya-view.html?dateT=' + (xydt || nowD); } if(index == 2) { window.location.href = 'tizhong-view.html?dateT=' + (tzdt || nowD); } if(index == 3) { window.location.href = 'yaowei-view.html?dateT=' + (ywdt || nowD); } }) $('#baojianList').on('click','li',function() { var index = $(this).index(); var dat = new Date(), nowD = dat.getFullYear() + '-' + (dat.getMonth() + 1) + '-' + dat.getDate(); if(index == 0) { window.location.href = 'yundong-view.html?dateT=' + (yddt || nowD); } if(index == 1) { window.location.href = 'yongyao-view.html?dateT=' + (yydt || nowD); } if(index == 2) { window.location.href = 'yinshi-view.html?dateT=' + (ysdt || nowD); } }) //点击新增事件 $(".div-add-btn").click(function(){ $(".modal-overlay").css("background","transparent"); $("#footer").css("z-index",4).hide(); var activeItem = $(".pt-tab li.hit").attr("id"); if(activeItem=="tizhengLi"){ if($(this).hasClass("active")){ $(".div-dialog-content.div-tizhengtezheng").hide(); }else{ $(".div-dialog-content.div-tizhengtezheng").show(); } }else{ if($(this).hasClass("active")){ $(".div-dialog-content.div-baojianjilu").hide(); }else{ $(".div-dialog-content.div-baojianjilu").show(); } } if($(this).hasClass("active")){ $(".modal-overlay").removeClass("modal-overlay-visible"); $(this).removeClass("active"); }else{ $(this).addClass("active"); $(".modal-overlay").addClass("modal-overlay-visible"); } }); //点击遮罩事件 $(".modal-overlay").on("click",function(){ $(".div-add-btn").removeClass("active"); $(".div-dialog-content").hide(); $(".modal-overlay").removeClass("modal-overlay-visible"); $("#footer").show(); }); //新增血糖 $(".addxuetang").on("click",function(){ $(this).addClass("active"); window.open('health-index-add-bloodsugar.html'); }); //新增血压 $(".addxueya").on("click",function(){ $(this).addClass("active"); window.open('health-index-add-bloodpressure.html'); }); //新增体重 $(".addtizhong").on("click",function(){ $(this).addClass("active"); window.open('health-index-add-weight.html'); }); //新增腰围 $(".addyaowei").on("click",function(){ $(this).addClass("active"); window.open('health-index-add-waistline.html'); }); //新增设备管理 $(".addshebei").on("click",function(){ $(this).addClass("active"); window.open('../../wdsb/html/my-equipments.html'); }); //新增运动 $(".addyundong").on("click",function(){ $(this).addClass("active"); window.open('add-sport-record.html'); }); //新增用药 $(".addyongyao").on("click",function(){ $(this).addClass("active"); window.open('add-drug-record.html'); }); //新增饮食 $(".addyinshi").on("click",function(){ $(this).addClass("active"); // 修复bug#2724 window.location.href = 'add-diet-record.html'; }); } function getRecordType(isDevice) { return isDevice === null ? "手动记录" : isDevice !== null ? "设备上传" : ''; // return isDevice == "0"?"手动记录":(isDevice=="1"?"设备上传":""); } //var html = template('tizheng_list_temp',{ // xuetang:{}, // xueya:{}, // tizhong:{}, // yaowei:{} //}); //$tizhengList.html(html); //体征记录 getRecentDataPromise() .then(function(res) { xuetangRecord = _.find(res.data,function(o) { var d = new Date(o.recordDate.replace(/\-/g, "/")); o.recordDate = d.getFullYear() + '-' + checkDate(d.getMonth() + 1) + '-' + checkDate(d.getDate()); return o.type =="1"; }) || {}; xuyaRecord = _.find(res.data,function(o) { return o.type =="2"; }) || {}; tizhongRecord = _.find(res.data,function(o) { return o.type =="3"; }) || {}; yaoweiRecord = _.find(res.data,function(o) { return o.type =="4"; }) || {}; var xuetangValue = ""; var xuetangValueIndex; var during = _.find(xuetangDuring,function(v,i){ xuetangValue = xuetangRecord['value'+[i]]; xuetangValueIndex = i; return i>0&&xuetangValue; }); xtdt = xuetangRecord.recordDate; xydt = xuyaRecord.recordDate; tzdt = tizhongRecord.recordDate; ywdt = yaoweiRecord.recordDate; return { xuetang: $.extend({},xuetangRecord,{ during: during, value: xuetangValue, levelClazz: (function() { // 不同时间段对应不同的血糖范围 var levels = [[],[6.1, 3.9],[7.8, 4.4], [6.1, 3.9],[7.8, 4.4], [6.1, 3.9],[7.8, 4.4], [6.1, 3.9]][xuetangValueIndex]; return getLevelClazz(xuetangValue, levels[0],levels[1]) })(), recordType: getRecordType(xuetangRecord.deviceSn) }), xueya: $.extend({},xuyaRecord,{ levelClazz: getLevelClazz(xuyaRecord.value1, 139, 90)||getLevelClazz(xuyaRecord.value2, 89, 60), recordType: getRecordType(xuyaRecord.deviceSn) }), tizhong: $.extend({},tizhongRecord,{ recordType: getRecordType(tizhongRecord.deviceSn) }), yaowei: $.extend({},yaoweiRecord,{ recordType: getRecordType(yaoweiRecord.deviceSn) }) } }) .then(function(data) { var html = template('tizheng_list_temp',data); $tizhengList.html(html) }) .then(function() { bindEvents(); }) .catch(function(e) { d.close(); console && console.error(e) }); //保健记录 getBJRecentDataPromise() .then(function (res) { yundongRecord = res.data.sprot; yongyaoRecord = res.data.medication; yinshiRecord = res.data.diet; yddt = yundongRecord.sortDate; yydt = yongyaoRecord.recordDate; ysdt = yinshiRecord.recordDate; return { yundong: yundongRecord, yongyao: yongyaoRecord, yinshi: yinshiRecord }; }).then(function (data) { var html = template('baojian_list_tmp',data); $baojianList.html(html) });