MemorizingWords.js 4.4 KB
// pages/MemorizingWords/MemorizingWords.js
const app=getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    page: 0,//0表示没有计划显示词包,1有计划显示计划
    wordspackage:[],//词包
    reciteInfo:[],//背诵信息
    swiper_index:1,//当前swiper_index滑块
    next_margin:'60rpx',//后边距
    previous_margin:'60rpx',//前边距
    circular:true,
    
  },
  //词包详情
  wordsPackgeDetail(e) { 
   let that=this;
    wx.navigateTo({
     url: '../MemorizingWords/wordsPackage/wordsPackage?id=' + e.currentTarget.id,
    })
  },
  //修改计划
  editPlan(){
    let that=this;
    let days = that.data.reciteInfo.days;
    let wordspackageid = that.data.reciteInfo.package_id;
    let everyday_words = that.data.reciteInfo.everyday_words;
    wx.navigateTo({
      url: '../MemorizingWords/wordsPlan/wordsPlan?wordspackageid=' + wordspackageid + '&days=' + days + '&wordnum=' + everyday_words,
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  //修改词包
  editwordspage(){
    let that=this;
    let reciteInfo = that.data.reciteInfo;
    let package_id = reciteInfo.package_id;//词包Id
    let wordspackage = that.data.wordspackage;
    let swiper_index = that.data.swiper_index;
    for (let i in wordspackage){
      if (wordspackage[i].id == package_id){
        wordspackage[i].jindu = reciteInfo.jindu;
        swiper_index=i;
      }   
    }
    wx.setStorageSync('ifeidtwordpackage',true);
    that.setData({
      page:0,
      wordspackage: wordspackage,
      swiper_index: swiper_index
    })
  },
  //搜索页
  searchPage() {
    wx.navigateTo({
      url: '../../pages/index/goldArticleSearch/goldArticleSearch?type='+2,
    })
  },
  //开始背单词
  startWords() {
    wx.navigateTo({
      url: '../MemorizingWords/wordsDetail/wordsDetail',
    })
  },
  //复习跳转
  review() {
    wx.navigateTo({
      url: '../MemorizingWords/reviewWords/reviewWords',
    })
  },
  //单词报告
  wordReport() {
    wx.navigateTo({
      url: '../MemorizingWords/wordsReport/wordsReport',
    })
  },
  //判断是否有计划
  getjudge(){
    let that=this;
    let url = 'Words/ifHasPlan';
    let params={
      token:wx.getStorageSync('token')
    };
    app.post(url,params).then((res)=>{
      if(res.data.code==1){
        if(res.data.data==0){
          that.setData({
            page:0
          })
         that.getPackage();
        } else{
          that.setData({
            page: 1
          })
          that.getReciteInfo();
        }
      }
    }).catch((errMsg)=>{
      console.log(errMsg)
    })
  },
  //获取全部词包
  getPackage(){
  let that=this;
   let reciteInfo = that.data.reciteInfo; 
   let package_id = reciteInfo.package_id;//词包Id
   let url ='Words/getPackage';
    app.post(url,{}).then((res)=>{
      if(res.data.code==1){
        let wordspackage=res.data.data;
        for (let obj of res.data.data){
         if (obj.id == package_id){
          obj.jindu = reciteInfo.jindu
         }else{
          obj.jindu = '0%'
         }
        }
        that.setData({
          wordspackage: wordspackage
        })
      }
    }).catch((errMsg)=>{
    })
  },
  //获取背单词页面数据
  getReciteInfo() {
  let that=this;
  let url ='Words/getReciteInfo';
  let params={
    token: wx.getStorageSync('token')
  }
  app.post(url,params).then((res)=>{
    if(res.data.code==1){
      that.setData({
        reciteInfo:res.data.data
      })
    }
  }).catch((errMsg)=>{
    console.log(errMsg)
  })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that=this;
    that.getjudge();
    that.getPackage();
    that.getReciteInfo();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;
    that.getjudge();
    that.getReciteInfo();
  },

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

  },

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

  },

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

  },

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

  },

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

  }
})