123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- var Request = GetRequest();
- var scroller1 = null;
- var render = function(tmpl, data){
- return tmpl.replace(/\{\{(\w+)\}\}/g, function(m, $1){
- return data[$1];
- });
- },
- //根据sd获取n天前的时间
- getBeforeDate = function ( sd, n) {
- var n = n;
- var d = new Date(sd.replace(/\-/g, "/"));
- var year = d.getFullYear();
- var mon=d.getMonth()+1;
- var day=d.getDate();
- if(day <= n){
- if(mon>1) {
- mon=mon-1;
- }
- else {
- year = year-1;
- mon = 12;
- }
- }
- d.setDate(d.getDate()-n);
- year = d.getFullYear();
- mon=d.getMonth()+1;
- day=d.getDate();
- s = year + "-" + (mon < 10 ? ('0' + mon) : mon) + "-" + (day < 10 ? ('0' + day) : day);
- return s;
- },
- //半年前
- halfYear = 365 / 2 * 24 * 3600 * 1000;
- $(function () {
- var $duringList = $('#duringList'),
- $qushiView = $('#qushiView'),
- $liebiaoView = $('#liebiaoView'),
- $xtEdit = $('.xt-edit'),
- $btns = $('.btns'),
- $cancelBtn = $('.cancel-btn'),
- $okBtn = $('.ok-btn'),
- $popMain = $('.pop-main'),
- $xtAdd = $('.xt-add'),
- $popBtns = $('.pop-btns'),
- $popEditBtn = $('.pop-edit-btn'),
- $popDelBtn = $('.pop-del-btn'),
- $popCancelBtn = $('.pop-cancel-btn'),
- isTrue = false,
- page = 0,
- pagesize = 10,
- $xyList = $('.xy-list-con'),
- $xyTmp = $('#xyTmp');
-
- var begindate = '',
- enddate = '';
- var charts = [];
-
- //判断最后的日期
- sendPost("patient/health_record/recent", {}, "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.diet){
- var d1 = res.data.diet.recordDate
- var d2 = Date.parse(new Date(d0))
- var d3 = Date.parse(new Date(d1))
- if(d2<d3){
- //取大
- begindate = d1
- }else{
- begindate = d0
- }
- }else{
- begindate = d0
- }
- enddate = getBeforeDate( begindate, 1000);
- loadData ();
- }else{
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'数据查询失败'}).show();
- }
- })
-
- function changeTabCon () {
- var qsv = $qushiView.css('display'),
- lbv = $liebiaoView.css('display');
- if (qsv === 'block') {
- lbv.hide();
- }
- }
- 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);
- $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'),
- image = $(this).attr('data-image'),
- val = $(this).attr('data-val'),
- time = $(this).attr('data-time');
- if (lei.hasClass('active')) {
- $popMain.addClass('active');
- $popBtns.addClass('active');
-
- $popEditBtn.attr('data-id',id);
- $popEditBtn.attr('data-image',image);
- $popEditBtn.attr('data-time',time);
- $popEditBtn.attr('data-val',val);
-
- $popDelBtn.attr('data-id',id);
-
- }
- });
- //
- $popMain.on( 'click', function () {
- $(this).removeClass('active');
- $popBtns.removeClass('active');
- });
- $popCancelBtn.on('click',function () {
- $popMain.removeClass('active');
- $popBtns.removeClass('active');
- });
- // 修改
- $popEditBtn.on( 'click', function () {
- var id = $(this).attr('data-id'),
- image = $(this).attr('data-image'),
- time = $(this).attr('data-time'),
- val = $(this).attr('data-val');
- window.location.href = 'add-diet-record.html?id=' + id + '&image=' + image + '&time=' + time + '&val=' + val;
- });
- // 删除
- $popDelBtn.on( 'click', function () {
- var id = $(this).attr('data-id');
- sendPost("patient/health_record/modifyHealthCare?id=" + id + '&type=1', {}, "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 {
- queryListFailed(res);
- }
- });
- });
- }
- function querySportList(page,pagesize,begindate,enddate) {
- //拼请求内容
- d.show();
- var params = {};
- 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_record/list_diet", params, "json", "post", queryListFailed, function (res) {
- d.close();
- if (res.status == 200) {
- resolve(res)
- } else {
- queryListFailed(res);
- }
- });
- })
- }
-
-
- bindEvents();
-
- 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 () {
- loadData();
- }, 1000);
- }
- function loadData () {
- page++;
- Promise.all([
- querySportList( page, pagesize, getBeforeDate( begindate, 1000), begindate)])
- .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(!isTrue) {
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无数据'}).show();
- $xtEdit.unbind('click');
- } else {
- dialog({contentType:'tipsbox',bottom:true, skin:'bk-popup' , content:'暂无更多数据'}).show();
- }
- }
- isTrue = true;
- })
- .catch(function(e) {
- console && console.error(e)
- });
- }
- })
|