博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
微信小程序可以点击左右按钮切换,一次7天
阅读量:605 次
发布时间:2019-03-12

本文共 3079 字,大约阅读时间需要 10 分钟。

我们的需求就是这种效果

实现的代码

html部分

data: {    show: false,    active: -1,    weekDate: ['日', '一', '二', '三', '四', '五', '六'],    dateArr: [],    isTodayWeek: false,    todayIndex: 0,    lastweek: true,    nowdate: new Date().getDate(),    datetip: false, //圆点的高亮不高亮    datelist: [], //后台返的14天的状态数据    isdayorder: [], //当天的任务详情      },  //获取14天的亮度状态  getstatus() {    if (!wx.getStorageSync('token')) return    Api.request(oderRoot + '/api/work/schedule/status', {}, 'GET').then(res => {      var _time = new Date();      var year = _time.getFullYear()      var month = _time.getMonth() + 1      res.forEach((item, index) => {        month = parseInt(month)        var day = parseInt(item.date)        var lastDay = 0        if (index > 0) {          lastDay = parseInt(res[index - 1].date)        }        if (lastDay > day) {          if (month == 12) {            year += 1            month = 1          } else {            month += 1          }        }        if (day < 10) {          day = '0' + '' + day        }        if (month < 10) {          month = '0' + '' + month        }        item.day = year + '-' + month + '-' + day      })      // console.log(res)      this.setData({        datelist: res   //前端遍历是这个datelist       })    })  },  /**   * 上周切换   */  lastWeek: function () {    var _this = this;    var _time = new Date();    var lastDay, month, year;    if (_this.data.isToday - 7 <= 0) {      if (_this.data.month <= 1) {        month = 12        year = _this.data.year - 1      } else {        month = _this.data.month - 1        year = _this.data.year      }      lastDay = new Date(year, month, 0).getDate() + (_this.data.isToday - 7)    } else {      lastDay = _this.data.isToday - 7      month = _this.data.month      year = _this.data.year    }    _this.setData({      isToday: lastDay,      month: month,      year: year,      mountTotalDay: new Date(year, month, 0).getDate(),      nextWeek: false,      lastweek: true    })    // _this.dateInit(lastDay, _this.data.isWeek);  },  /**   * 下周切换   */  nextWeek: function () {    var _this = this;    var _time = new Date();    var nextDay, month, year;    if (_this.data.isToday + 7 > _this.data.mountTotalDay) {      nextDay = _this.data.isToday + 7 - _this.data.mountTotalDay      if (_this.data.month > 11) {        month = 1        year = _this.data.year + 1      } else {        month = _this.data.month + 1        year = _this.data.year      }    } else {      nextDay = _this.data.isToday + 7      month = _this.data.month      year = _this.data.year    }    _this.setData({      isToday: nextDay,      month: month,      year: year,      mountTotalDay: new Date(year, month, 0).getDate(),      lastweek: false,      nextWeek: true    })    // console.log(this.data.month,"month")    // _this.dateInit(nextDay, _this.data.isWeek);  }
{
{year}}-{
{month<10?'0'+month:month}}
{ {item}}
 
{ {item.date}}

 

转载地址:http://yjwaz.baihongyu.com/

你可能感兴趣的文章