reviewWordsDetail.js 7.5 KB
// pages/MemorizingWords/reviewWordsDetail/reviewWordsDetail.js
const app = getApp();
var temdata_i=0;//动态加载开始天数
var temdata_i1 = 0;//动态加载结束天数
Page({

  /**
   * 页面的初始数据
   */
  data: {
    starttime:'',
    endtime:'',
    page:0,
    pushdate:[],//动态加载开始的时间
    pushdate1: [],//动态加载结束的时间
    moudel:false,
    Recitewords:'',//根据时间段所需背单词数
    toView:''
  },
  
  //确定选择某时间段背的单词数
  confirmWords(){
   let that=this;
    if (that.data.starttime==''){
      wx.showToast({
        title: '请选择开始时间',
        icon: 'none',
        duration: 2000,
      })
    } else if (that.data.endtime==''){
      wx.showToast({
        title: '请选择结束时间',
        icon: 'none',
        duration: 2000,
      })
    }else{
      that.getTimeWords();
    }
  },
  //获取复习界面信息(错词,模糊词)
  getFuxiInfo(){
    let that=this;
    let url ='Words/getFuxiInfo';
    let params={
      token: wx.getStorageSync('token')
    }
    app.post(url,params).then((res)=>{
      if(res.data.code==1){
        that.setData({
          listdata:res.data.data
        })
      }
    })
  },
  //按时间共需复习单词数 
  getTimeWords(){
    let that=this;
    let url ='Words/getTimeWords';
    let params={
      token: wx.getStorageSync('token'),
      start_time: that.data.starttime,
      end_time: that.data.endtime
    }
    app.post(url,params).then((res)=>{
      if(res.data.code==1){
        if (parseInt(res.data.data.total_num)>0){
          that.setData({
            moudel: true,
            Recitewords: res.data.data.total_num
          })
        }else{
          wx.showToast({
            title: '没有错词请重新选择',
            icon: 'none',
            duration: 2000,
          })
        }
        
      }
    }).catch((errMsg)=>{
      console.log(errMsg)
    })

  },
  setmoudel_no(){
    let that=this;
    that.setData({
      moudel:false,
      starttime: '',
      endtime: '',
    })
  },
  setmoudel_yes(){
    let that = this;
    that.setData({
    moudel: true
    })
  },
  voidfun(){
  },
  gowordsDetail_review(e){
    let that=this;
    let id=e.currentTarget.id;
    if(id=='-1'){
      wx.showToast({
        title: '暂无错词,不需要复习',
        icon: 'none',
        duration: 2000,
      })
    }else{
      wx.navigateTo({
        url: '../wordsDetail_review/wordsDetail_review?id=' + id + '&starttime=' + that.data.starttime + '&endtime=' + that.data.endtime,
        success: function (res) { },
        fail: function (res) { },
        complete: function (res) { },
      })
    }
    
  },
  //开始:根据年月日获取(星期等信息)////later=0 当前  later=1明天  later=2后天...
  dateLater(later) {
    let that=this;
    let pushdate = that.data.pushdate;
    let dateObj = {};
    let date = new Date();
    date.setDate(date.getDate() + later);
    let timestamp = Date.parse(date);
    dateObj.dataday = date.getFullYear() + '-' + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth() + 1) + '-' + (date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate());
    if (later==0){
      dateObj.state = true;
      that.setData({
        toView: 'date' + dateObj.dataday,
        starttime: dateObj.dataday,
        endtime: dateObj.dataday,
      })
    }else{
      dateObj.state = false;
    }
    dateObj.timestamp = timestamp;
    pushdate.push(dateObj);
    that.setData({
      pushdate: pushdate, 
    })
    temdata_i++;
  },
  //开始:动态加载时间
  loaddate(){
    let that=this;
      that.dateLater(temdata_i);
  },
  //开始:
  setstarcell(e){
    let that=this;
    let index = parseInt(e.currentTarget.dataset.index);
    let pushdate = that.data.pushdate;
    let pushdate1 = that.data.pushdate1;
    let starttime = pushdate[index].dataday;
    for (let i in pushdate){
      pushdate[i].state=false;
      if (i == index){
        pushdate[i].state = true;
      }
    }
    for (let obj of pushdate1){
      obj.state = false;
      if (starttime == obj.dataday){
        obj.state=true;
      }
    }
    that.setData({
      pushdate: pushdate,
      pushdate1: pushdate1,
      starttime: starttime,
      endtime: starttime,
      toView: 'date' + pushdate[index].dataday
    })
  },
  //结束:根据年月日获取(星期等信息)////later=0 当前  later=1明天  later=2后天...
  dateLater1(later) {
    let that = this;
    let pushdate1 = that.data.pushdate1;
    let dateObj = {};
    let date = new Date();
    date.setDate(date.getDate() + later);
    let timestamp = Date.parse(date);
    dateObj.dataday = date.getFullYear() + '-' + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : date.getMonth() + 1) + '-' + (date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate());
    if (later == 0) {
      dateObj.state = true;
    } else {
      dateObj.state = false;
    }
    dateObj.timestamp = timestamp;
    pushdate1.push(dateObj);
    that.setData({
      pushdate1: pushdate1,
    })
    temdata_i1++;
  },
  //结束动态加载时间
  loaddate1() {
    let that = this;
    that.dateLater1(temdata_i1);
  },
  //结束
  setstarcell1(e) {
    let that = this;
    let starttimestamp=''//选中开始时间搓
    let endttimestamp = e.currentTarget.dataset.timestamp//选中结束时间搓
    let endtime = that.data.endtime;
    let index = parseInt(e.currentTarget.dataset.index);
    let pushdate1 = that.data.pushdate1;
    let pushdate = that.data.pushdate;
    for (let obj of pushdate){
      if (obj.state){
        starttimestamp = obj.timestamp
      }
    }
    if (starttimestamp==''){
      wx.showToast({
        title: '请选择开始时间',
        icon: 'none',
        duration: 2000,
      })
    } else if (starttimestamp > endttimestamp){
      wx.showToast({
        title: '结束时间应该大于开始时间',
        icon: 'none',
        duration: 2000,
      })
    }
    else{
      for (let i in pushdate1) {
        pushdate1[i].state = false;
        if (i == index) {
          pushdate1[i].state = true;
          endtime = pushdate1[i].dataday
        }
      }
      that.setData({
        pushdate1: pushdate1,
        endtime: endtime
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    that.setData({
      page:options.page,
      pushdate:[],
      pushdate1: [],
    })
    that.getFuxiInfo();
    temdata_i = 0;//动态加载开始天数
    temdata_i1 = 0;//动态加载结束天数
    if (options.page==1){
      for(var i=0;i<8;i++){
        that.dateLater(temdata_i);
        that.dateLater1(temdata_i1);
      }
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;
    that.getFuxiInfo();
    if (options.page == 1) {
      for (var i = 0; i < 8; i++) {
        that.dateLater(temdata_i);
        that.dateLater1(temdata_i1);
      }
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})