// pages/date/index.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    openTime: 20.0,
    setInter: '',
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let _this=this;
    _this.startSetInter();
  },
  //开始开锁计时器
  startSetInter: function () {
    var _this = this;
    _this.data.setInter = setInterval(function () {
      var numVal = _this.data.openTime - 1;
      _this.setData({ openTime: numVal });
      wx.showToast({
        title: '执行中' + _this.data.openTime.toString() + '秒',
        icon: 'none'
      })
      if (_this.data.openTime == 0) {
        _this.endSetInter();
        wx.showToast({
          title: '倒计时结束!',
          icon: 'none'
        })
      }
    }, 1000);
  },
  //清除计时器 即清除setInter
  endSetInter: function () {
    var _this = this;
    wx.hideLoading()
    clearInterval(_this.data.setInter)
  },
})