const app = getApp()
import {
  throttle,
  getWaterDrop
} from '../../utils/index/index'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isHomePage: {
      type: Boolean,
      value: false
    },
  },
  props: {
    onSure: {
      type: Function,
      value: () => {}
    },
    onBack: {
      type: Function,
      value: () => {}
    },
    suerName: '确定',
    logoutName: '退出',
    showBtn: true,
    logOut: '/pages/home/index',
    isCustomBack: false
  },
  /**
   * 组件的初始数据
   */
  data: {
    intervalId: null,
  },
  didMount() {
    this.interval()
  },
  /**
   * 组件的方法列表
   */
  methods: {
    interval() {
      var that = this;
      if (app.globalData.sn) {
        that.setData({
          appVersion: app.globalData.appVersion,
          sn: app.globalData.sn,
        })
      } else {
        that.data.intervalId = setInterval(function () {
          if (app.globalData.sn) {
            that.setData({
              appVersion: app.globalData.appVersion,
              sn: app.globalData.sn,
            })
            clearInterval(that.data.intervalId);
          }
        }, 1000);
      }
    },
    logOut() {
      clearInterval(this.data.intervalId);
      app.data.isOkBrushingCard = false
      app.data.isOkQrCodeSignIn = false
      if (!this.props.isHomePage) {
        console.log(this.props.isCustomBack)
        if (this.props.isCustomBack) {
          this.props.onBack('back');
        }else {
          my.reLaunch({
            url: this.props.logOut,
          })
        }
      }
    },
    clickSure: throttle( function () {
      clearInterval(this.data.intervalId);
      this.props.onSure('sure');
    }, 5000),
  },
  observers: {}
})
