var switchery = null; var date = new Date(); var year = date.getFullYear(); var begindate; var enddate; var page = 1; var pagesize = 10; var pagetype = 5; var patientCode = ""; var charType = 1; var scroller1 = null; var self = null; var type = null; var charts = []; var $viewTabs = $('#viewTabs'), $swiperWrapper = $('.swiper-wrapper'), $duringList = $('#duringList'), $qushiView = $('#qushiView'), $liebiaoView = $('#liebiaoView'), $xtEdit = $('.xt-edit'), $btns = $('.btns'), $cancelBtn = $('.cancel-btn'), $okBtn = $('.ok-btn'), $popMain = $('.pop-main'), $popBtns = $('.pop-btns'), $xtAdd = $('.xt-add'), $popCancelBtn = $('.pop-cancel-btn'), $selDate = $('#selDate'), $popEditBtn = $('.pop-edit-btn'), $popDelBtn = $('.pop-del-btn'), d1 = [], d2 = [], d3 = [], d4 = [], page = 0, pagesize = 10, dayNum = 6, swiper = null, thatIndex = 1, isTrue = false, isLoad = false, $zcNum = $('.zc-num'), $pgNum = $('.pg-num'), $pdNum = $('.pd-num'); var norTime = '', sn = 0; var xuetangDuring = ['', '早餐前', '早餐后', '午餐前', '午餐后', '晚餐前', '晚餐后', '睡前']; mui.plusReady(function() { self = plus.webview.currentWebview(); patientCode = self.code; begindate = self.dateT; norTime = self.dateT; type = self.type; enddate = getDateFromCurrentDate(begindate, -dayNum); bindEvents(); scroller1 = new IScrollPullUpDown('wrapper6', { probeType: 2, bounceTime: 250, bounceEasing: 'quadratic', mouseWheel: false, scrollbars: true, fadeScrollbars: true, interactiveScrollbars: false, click: true, }, null, pullUpAction); // checkLoad(thatIndex); init(); }); function changeTabCon() { var qsv = $qushiView.css('display'), lbv = $liebiaoView.css('display'); if(qsv === 'block') { lbv.hide(); } } function getNormalLevel(index) { return [ [], [7, 4], [11.1, 4], [7, 4], [11.1, 4], [7, 4], [11.1, 4], [7, 4] ][index]; } function getxAxisData(data) { var a = [], b = []; b = _.chain(data).pluck('date').map(function(d) { return d.substr(5, 5) }).value(); for(var i = b.length - 1; i >= 0; i--) { a.push(b[i]); } return a; } function getSeriesData(data) { var index = $duringList.find('li.curr').attr('data-index'); var a = [], b = []; b = _.chain(data).pluck('value1').map(function(v) { var max = getNormalLevel(index)[0], min = getNormalLevel(index)[1]; return buildData(v, max, min); }).value(); for(var i = b.length - 1; i >= 0; i--) { if(!!b[i]) { a.push(b[i]); } } return a; } function queryListByTypeP(type, begindate, enddate, page, pagesize, code) { plus.nativeUI.showWaiting(); //拼请求内容 var params = {}; params.type = type; params.page = page; params.pagesize = pagesize; params.begin = begindate + " 00:00:00"; params.end = enddate + " 23:59:59"; params.patient = code; return new Promise(function(resolve, reject) { sendPost("doctor/health_index/list", params, function(res) { resolve(res) console.log(res); }, function(res) { if(res.status == 200) { plus.nativeUI.closeWaiting(); resolve(res) } else { queryListFailed(res); } }); }) } //上拉加载数据 function pullUpAction(theScrollerTemp) { $(".pullUp").show(); setTimeout(function() { loadListPromise(); }, 1000); } function loadListPromise() { page++; Promise.all([ queryListByTypeP(1, getDateFromCurrentDate(norTime, -2000), norTime, page, pagesize, patientCode) ]) .then(function(res) { $(".pullUp").hide(); var data = res[0]; if (data.list.length > 0) { for(var i = 0, len = data.list.length; i < len; i++) { var czrq = new Date(data.list[i]['czrq'].replace(/\-/g, "/")), recordDate = new Date(data.list[i]['recordDate'].replace(/\-/g, "/")), sortDate = new Date(data.list[i]['sortDate'].replace(/\-/g, "/")); data.list[i]['czrq'] = czrq.getFullYear() + '-' + (czrq.getMonth() + 1) + '-' + (czrq.getDate()); data.list[i]['recordDate'] = recordDate.getFullYear() + '-' + (recordDate.getMonth() + 1) + '-' + (recordDate.getDate()); data.list[i]['sortDate'] = sortDate.getFullYear() + '-' + (sortDate.getMonth() + 1) + '-' + (sortDate.getDate()); for(var j = 1; j <= 7; j++) { var d = data.list[i]['time' + j]; if(d) { data.list[i]['tahttime' + j] = d; data.list[i]['time' + j] = (d.toString()).substring(11, 16); } } } console.log(data.list); $('#lbvCon').append(template('xtTmp', { data: data.list })); scroller1.refresh(); } else { if(!isLoad) { mui.toast("暂无数据!"); } else { mui.toast("暂无更多数据!"); } } isLoad = true; }) .catch(function(e) { console && console.error(e) }); } function resetSwiper() { $swiperWrapper.find('.swiper-slide').html(''); swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide sn = swiper.slides.length - 1; begindate = norTime; } function pData(d) { var index = $duringList.find('li.curr').attr('data-index'); var max = getNormalLevel(index)[0], min = getNormalLevel(index)[1], pgN = 0, pdN = 0, zcN = 0; for(var i = 0, len = d.length; i < len; i++) { var value = d[i].value1; if(value < min) { pdN += 1; } if(value > max) { pgN += 1; } if(value >= min && value <= max) { zcN += 1; } } $zcNum.html(zcN); $pgNum.html(pgN); $pdNum.html(pdN); } function init() { Promise.all([(function() { $swiperWrapper .append($('
  • ')) .append($('
  • ')) .append($('
  • ')) .append($('
  • ')); })()]) .then(function(echarts) { swiper = new Swiper('.swiper-container', { paginationClickable: false, onSlideChangeStart: function(swiper) { var ind = swiper.activeIndex; if(ind < sn) { begindate = enddate; enddate = getDateFromCurrentDate(begindate, -dayNum); } else { enddate = begindate; begindate = getDateFromCurrentDate(begindate, dayNum); } sn = ind; plus.nativeUI.showWaiting(); loadPromise(thatIndex, enddate, begindate, sn); } }); }) .then(function() { plus.nativeUI.showWaiting(); $swiperWrapper.find('.swiper-slide'); swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide sn = swiper.slides.length - 1; checkLoad(thatIndex); }) .catch(function(e) { console && console.error(e) }) } function loadPromise(t, enddate, begindate, n) { Promise.all([ queryChatByTypePromise(1, enddate, begindate, t, patientCode) ]) .then(function(res) { d1 = res[0]; loadData(n); }) .catch(function(e) { console && console.error(e) }); } function loadData(n) { new Promise(function(resolve, reject) { var yAxisName = '单位(mmol/L)'; var el = document.getElementById('chart' + n); if (typeof d1.list == 'undefined') { d1.list = []; } pData(d1.list); Promise.all([ createChartPromise(el, 1, yAxisName, getxAxisData(d1.list), getSeriesData(d1.list)) ]) .then(function(echarts) { plus.nativeUI.closeWaiting(); charts.push(echarts[0]); $(el).append('
    < ' + enddate + ' 至 ' + begindate + ' >
    '); }) .then(function() { }) .catch(function(e) { console && console.error(e) }) }); } function checkLoad(d) { loadPromise(d, enddate, begindate, sn); } //function loadPromise(t, cb) { // Promise.all([ // queryChatByTypePromise(1, getBeforeDate(begindate, 7), begindate, t, patientCode), // queryChatByTypePromise(1, getBeforeDate(begindate, 30), begindate, t, patientCode), // queryChatByTypePromise(1, getBeforeDate(begindate, 90), begindate, t, patientCode), // queryChatByTypePromise(1, getBeforeDate(begindate, 365 / 2), begindate, t, patientCode) // ]) // .then(function(res) { // // plus.nativeUI.closeWaiting(); // d1 = res[0]; // d2 = res[1]; // d3 = res[2]; // d4 = res[3]; // cb && cb.call(this); // }) // .catch(function(e) { // console && console.error(e) // }); //} //function loadData() { // new Promise(function(resolve, reject) { // var yAxisName = '单位(mmol/L)'; // $swiperWrapper // .append('
  • ') // .append('
  • ') // .append('
  • ') // .append('
  • '); // // var el1 = document.getElementById('chart0'), // el2 = document.getElementById('chart1'), // el3 = document.getElementById('chart2'), // el4 = document.getElementById('chart3') // Promise.all([ // createChartPromise(el1, 1, yAxisName, getxAxisData(d1.list), getSeriesData(d1.list)), // createChartPromise(el2, 1, yAxisName, getxAxisData(d2.list), getSeriesData(d2.list)), // createChartPromise(el3, 1, yAxisName, getxAxisData(d3.list), getSeriesData(d3.list)), // createChartPromise(el4, 1, yAxisName, getxAxisData(d4.list), getSeriesData(d4.list)) // ]) // .then(function(echarts) { // charts.push(echarts[0]); // charts.push(echarts[1]); // charts.push(echarts[2]); // charts.push(echarts[3]); // $(el1).append('
    < ' + getBeforeDate(begindate, 7) + ' 至 ' + begindate + ' >
    '); // $(el2).append('
    < ' + getBeforeDate(begindate, 30) + ' 至 ' + begindate + ' >
    '); // $(el3).append('
    < ' + getBeforeDate(begindate, 90) + ' 至 ' + begindate + ' >
    '); // $(el4).append('
    < ' + getBeforeDate(begindate, 365 / 2) + ' 至 ' + begindate + ' >
    '); // }) // .then(function() { // swiper = new Swiper('.swiper-container', { // paginationClickable: false, // onSlideChangeStart: function(swiper) { // var ind = swiper.activeIndex; // switch(ind) { // case 0: // $selDate.find('li').removeClass('curr').eq(3).addClass('curr'); // dayNum = -1; // break; // case 1: // $selDate.find('li').removeClass('curr').eq(2).addClass('curr'); // dayNum = 90; // break; // case 2: // $selDate.find('li').removeClass('curr').eq(1).addClass('curr'); // dayNum = 30; // break; // case 3: // $selDate.find('li').removeClass('curr').eq(0).addClass('curr'); // dayNum = 7; // break; // } // } // }); // $swiperWrapper.find('.swiper-slide') // swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide // }) // .catch(function(e) { // console && console.error(e) // }) // }); //} // //function checkLoad(d) { // if(!isTrue) { // loadPromise(d, loadData); // } else { // loadData(); // } //} function getDateFromCurrentDate(fromDate, dayInterval) { var curDate = new Date(Date.parse(fromDate.replace(/-/g, "/"))); curDate.setDate(curDate.getDate() + dayInterval); var year = curDate.getFullYear(); var month = (curDate.getMonth() + 1) < 10 ? "0" + (curDate.getMonth() + 1) : (curDate.getMonth() + 1); var day = curDate.getDate() < 10 ? "0" + curDate.getDate() : curDate.getDate(); return year + "-" + month + "-" + day; }; function bindEvents() { //tab $viewTabs.on('click', 'li', function(e) { e.stopPropagation(); var index = $(this).index(); $(this).siblings().removeClass('curr'); $(this).addClass('curr'); if(index === 0) { $qushiView.show(); $liebiaoView.hide(); $xtEdit.hide(); } else { $qushiView.hide(); $liebiaoView.show(); $xtEdit.show(); var data = null; if(dayNum == 6) { data = d1.list; } if(dayNum == 30) { data = d2.list; } if(dayNum == 90) { data = d3.list; } if(dayNum == -1) { data = d4.list; } if(!isLoad) { // isLoad = true; loadListPromise(); } } }); //天数选择 $selDate.on('click', 'li', function(e) { var index = $(this).index(); $(this).siblings().removeClass('curr'); $(this).addClass('curr'); resetSwiper(); switch(index) { case 0: dayNum = 6; break; case 1: dayNum = 30; break; case 2: dayNum = 90; break; case 3: dayNum = 365 / 2; break; } enddate = getDateFromCurrentDate(begindate, -dayNum); checkLoad(thatIndex); }); //就餐时间段选择 $duringList.on('tap', 'li', function(e) { e.stopPropagation(); var d = $(this).attr('data-index'); if(thatIndex == d) { return; } thatIndex = parseInt(d); $(this).closest('#duringList').find('li').removeClass('curr'); $(this).addClass('curr'); enddate = getDateFromCurrentDate(begindate, -dayNum); checkLoad(thatIndex); }); }