collect.js 2.8 KB
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    windowHeight: 654,
    maxtime: "",
    isHiddenLoading: true,
    isHiddenToast: true,
    dataList: {},
    countDownDay: 0,
    countDownHour: 0,
    countDownMinute: 0,
    collectList: ''
  },
  bindViewTap: function () {
    wx.navigateTo({
      // url: '../logs/logs'
    })
  },

  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      windowHeight: wx.getStorageSync('windowHeight')
    });
    this.collectFunc()
  },

  // 收藏功能
  collectFunc() {
    let that = this;
    let url = '/user/index/collect';
    let params = {
      page: 1
    }
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      "XX-Device-Type": 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res);
      // 列表值
      that.setData({
        collectList: res.data.list
      })

      that.countDown()

      console.log(that.data.collectList)


    }).catch((err) => {

    })
  },

  timeFormat(param) { //小于10的格式化函数
    return param < 10 ? '0' + param : param;
  },
  //团购倒计时
  countDown() {
    let that = this
    let objs = Object.assign([], that.data.collectList)
    let now_time = parseInt(new Date().getTime())


    for (let obj of objs) {

      let end_time = obj.end_time * 1000
      let open_time = obj.open_time * 1000
      if (now_time < open_time) {
        //活动未开始
      } else if (now_time > end_time) {
        //活动结束
        obj.over = true
      } else {
        let time = (end_time - now_time) / 1000;
        let day = parseInt(time / (60 * 60 * 24));
        let hou = parseInt(time % (60 * 60 * 24) / 3600);
        let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
        let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);

      
        obj.day = that.timeFormat(day),
          obj.hou = that.timeFormat(hou),
          obj.min = that.timeFormat(min),
          obj.sec = that.timeFormat(sec)

      }

    }

    that.setData({
      collectList: objs
    })

    

    setTimeout(that.countDown, 1000);
    // console.log(that.data.shop)
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})