xianshi.js 3.3 KB
// pages/xianshi/xianshi.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    xianshilist:[],
    endTime:'',
    page:1,
    dday:'',
    hou:'',
    min:'',
    sec:'',
    showtime:false

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
    this.getxianshi();
    this.getxianshik()

    setTimeout(function(){
      that.setData({
        showtime: true
      })
    },1000)
  },



  // 限时抢购
  getxianshi() {
    let that = this
    let url = '/special/get_all';
    let data = {
      page: that.data.page,
      pageNum: 10

    }
    app.post(url, data, "POST").then((r) => {
      console.log(r)
      that.setData({
        // xianshilist: that.data.xianshilist.concat(r.msg.list) ,
       
        // status: r.msg.status,
         endTime: r.msg.residue_time,
        
      })
     

      that.countDown()

      console.log(that.data.xianshilist)
      // that.setData({
      //   messagelist: that.data.messagelist.concat(r.msg)
      // })

      // console.log(that.data.messagelist)

    }).catch((err) => { })
  },
  getxianshik() {
    let that = this
    let url = '/special/get_all';
    let data = {
      page: that.data.page,
      pageNum: 10

    }
    app.post(url, data, "POST").then((r) => {
      console.log(r)
      that.setData({
        xianshilist: that.data.xianshilist.concat(r.msg.list) ,
        // endTime: r.msg.residue_time,
        status: r.msg.status
      })


      that.countDown()

      console.log(that.data.xianshilist)
      // that.setData({
      //   messagelist: that.data.messagelist.concat(r.msg)
      // })

      // console.log(that.data.messagelist)

    }).catch((err) => { })
  },


  look_more(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/shop_detail/shop_detail?id=' + id
    })
  },
  // 倒计时
  countDown() {
    console.log(788)
    var that = this;

    var time = that.data.endTime;
    var interval = setInterval(function () {
      // 秒数
      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);

      that.setData({
        day: that.timeFormat(day),
        hou: that.timeFormat(hou),
        min: that.timeFormat(min),
        sec: that.timeFormat(sec)
      })

      time--;
      if (time <= 0) {
        clearInterval(interval);

      }
    }.bind(this), 1000);
  },

  timeFormat(param) {
    return param < 10 ? '0' + param : param;
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let newpage=this.data.page;
    newpage++;
    this.setData({
      page:newpage
    })
    this.getxianshik()
  },

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

  }
})