var Request = GetRequest(); $(function () { var $viewTabs = $('#viewTabs'), $swiperWrapper = $('.swiper-wrapper'), $duringList = $('#duringList'), $qushiView = $('#qushiView'), $liebiaoView = $('#liebiaoView'), $xtEdit = $('.xt-edit'), $btns = $('.btns'), $xtAdd = $('.xt-add'), $cancelBtn = $('.cancel-btn'), $okBtn = $('.ok-btn'), $popMain = $('.pop-main'), $popBtns = $('.pop-btns'), $popEditBtn = $('.pop-edit-btn'), $popDelBtn = $('.pop-del-btn'), $popCancelBtn = $('.pop-cancel-btn'), $selDate = $('#selDate'), swiper = null, isTrue = false, page = 0, pagesize = 10, d1 = [], d2 = [], d3 = [], d4 = [], dayNum = 6, $xyList = $('.xy-list-con'), $xyTmp = $('#xyTmp'), isLoad = false; var scroller1 = new IScrollPullUpDown('wrapper6',{ probeType:2, bounceTime: 250, bounceEasing: 'quadratic', mouseWheel:false, scrollbars:true, fadeScrollbars:true, click:true, // preventDefault: false, interactiveScrollbars:false },null,pullUpAction); //上拉加载数据 function pullUpAction(theScrollerTemp) { $(".pullUp").show(); setTimeout(function () { loadListPromise(); }, 1000); } var norTime = '', begindate = '', enddate = '', sn = 0; var charts = []; //判断最后的日期 sendPost("patient/health_index/last", {}, "json", "get", function(){ dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'请求失败'}).show(); }, function(res){ if(res.status == 200){ var d0 = decodeURIComponent(Request["dateT"]); if(res.data.sg){ var d1 = (res.data.sg.recordDate).split(' ')[0]; var d2 = Date.parse(new Date(d0)) var d3 = Date.parse(new Date(d1)) if(d2= 0; i--) { a.push(b[i]); } return a; } function getSeriesData(data) { var a = [], b = []; b = _.chain(data).pluck('value1').map(function(v) { return v; }).value(); for (var i = b.length - 1; i >= 0; i--) { a.push(b[i]); } return a; } function queryListByTypeP(type,begindate,enddate,page,pagesize) { //拼请求内容 d.show(); var params = {}; params.type = type; params.page = page; params.pagesize = pagesize; params.start = begindate+" 00:00:00"; params.end = enddate+" 23:59:59"; return new Promise(function(resolve, reject) { //发送ajax请求 sendPost("patient/health_index/list", params, "json", "post", queryListFailed, function (res) { d.close(); if (res.status == 200) { resolve(res) } else { queryListFailed(res); } }); }) } function loadListPromise () { page++; Promise.all([ queryListByTypeP( 4, getDateFromCurrentDate(norTime, -2000), norTime, page, pagesize) ]) .then(function(res) { $(".pullUp").hide(); var data = res[0]; if (data.list.length > 0) { $xyList.append(template('xyTmp',{data:data.list})); scroller1.myScroll.refresh(); } else { if(!isLoad) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无数据'}).show(); $xtEdit.unbind('click'); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无更多数据'}).show(); } } isLoad = true; }) .catch(function(e) { console && console.error(e) }); } //初始化swiper 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; loadPromise(sn, enddate, begindate); } }); }) .then(function () { $swiperWrapper.find('.swiper-slide'); swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide sn = swiper.slides.length - 1; loadPromise( sn, enddate, begindate); }) .catch(function(e) { console && console.error(e) }) } function loadPromise ( n, enddate, begindate) { Promise.all([ queryChatByTypePromise( 4, enddate, begindate, 0) ]) .then(function(res) { d1 = res[0]; loadData(n); }) .catch(function(e) { console && console.error(e) }); } //初始化echart function loadData(n) { new Promise(function(resolve, reject) { var yAxisName = '单位(cm)'; var el = document.getElementById('chart' + n); Promise.all([ createChartPromise( el, 4, yAxisName, getxAxisData(d1.list), getSeriesData(d1.list)) ]) .then(function(echarts) { charts.push(echarts[0]); $(el).append('
    < ' + enddate + ' 至 ' + begindate + ' >
    '); }) .then(function() { }) .catch(function(e) { console && console.error(e) }) }); } function pushHistory() { var state = { title: "腰围", url: "#" }; window.history.pushState(state, "腰围", "#"); } pushHistory(); function bindEvents() { setTimeout( function () { window.addEventListener("popstate", function(e) { location.href = 'health-record.html'; }, false); }, 300); $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(); } // $xyList.html(template('xyTmp',{data:data})); } }); $selDate.on( 'click', 'li', function (e) { var index = $(this).index(); $(this).siblings().removeClass('curr'); $(this).addClass('curr'); console.log(index); $swiperWrapper.find('.swiper-slide').html(''); swiper.slideTo(swiper.slides.length - 1, 0, false); //切换到最后一个slide sn = swiper.slides.length - 1; begindate = norTime; 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); loadPromise( sn, enddate, begindate); }); $xtEdit.on( 'click', function () { $(this).hide(); $btns.show(); $xtAdd.hide(); $liebiaoView.find('.l-edit-icon').addClass('active'); }); $cancelBtn.on( 'click',function () { $liebiaoView.find('.l-edit-icon').removeClass('active'); $xtEdit.show(); $xtAdd.show(); $btns.hide(); }); $okBtn.on( 'click', function () { $liebiaoView.find('.l-edit-icon').removeClass('active'); $xtEdit.show(); $xtAdd.show(); $btns.hide(); }); $liebiaoView.on( 'click', '.l-item', function () { var lei = $(this).find('.l-edit-icon'), id = $(this).attr('data-id'), val = $(this).attr('data-val'), sn = $(this).attr('data-sn'), time = $(this).attr('data-time'); if (lei.hasClass('active')) { $popMain.addClass('active'); $popBtns.addClass('active'); if (sn != '') { $popEditBtn.hide(); } $popEditBtn.attr('data-id',id); $popEditBtn.attr('data-val',val); $popEditBtn.attr('data-time',time); $popDelBtn.attr('data-id',id); } }); // 修改 $popEditBtn.on( 'click', function () { var id = $(this).attr('data-id'), val = $(this).attr('data-val'), time = $(this).attr('data-time'); window.location.href = 'health-index-add-waistline.html?id=' + id + '&val=' + val + '&time=' + time; }); // 删除 $popDelBtn.on( 'click', function () { var id = $(this).attr('data-id'); sendPost("patient/health_index/modify?id=" + id, {}, "json", "post", queryListFailed, function (res) { d.close(); if (res.status == 200) { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'删除成功'}).show(); setTimeout(function(){ location.reload(); },2000); } else { dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'删除失败'}).show(); setTimeout(function(){ location.reload(); },2000); } }); });// $popCancelBtn.on('click',function () { $popMain.removeClass('active'); $popBtns.removeClass('active'); });// $popMain.on( 'click', function () { $(this).removeClass('active'); $popBtns.removeClass('active'); }); } bindEvents(); }); //根据sd获取n天前的时间; 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; };