// component/privacy-popup/privacy-popup.ts
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    initCheck: {
      type: Boolean,
      value: false
    },
    changTabBar: {
      type: Boolean,
      value: true
    }
  },
  observers: {
    show: function (value) {
      if(this.properties.changTabBar){
        if (value) {
          wx.hideTabBar()
        } else {
          wx.showTabBar()
        }
      }
    }
  },
  pageLifetimes: {
    show() {
      if (this.properties.initCheck) {
        this.check()
      }
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    needAuthorization: false,
    privacyContractName: ''
  },
  /**
   * 组件的方法列表
   */
  methods: {
    check() {
      if (wx.canIUse('getPrivacySetting')) {
        wx.getPrivacySetting({
          success: res => {
            console.log(res)
            this.setData({
              ...res,
              show: res.needAuthorization
            })
            if (!res.needAuthorization) {
              this.privacySubmit()
            }
          }
        })
      } else {
        this.privacySubmit()
      }
    },
    handleAgreePrivacyAuthorization() {
      this.privacySubmit(true)
    },
    privacySubmit(status = false) {
      this.triggerEvent('privacySubmit', {
        status
      })
      this.hidden()
    },
    hidden() {
      this.setData({
        show: false
      })
    },
    cancel() {
      this.triggerEvent('privacyCancel')
      this.hidden()
    },
    openPrivacyContract() {
      wx.openPrivacyContract({
        success() {
          console.log('打开隐私协议')
        }
      })
    }
  }
})