Component({
  data: {
    protocolAgree: false
  },
  methods: {
    protocolChange(data) {
      this.setData({
        protocolAgree: data
      })
    },
    authClick() {
      if(!this.data.protocolAgree) {
        return
      }
      const authPopup = this.$selectComponent('#authPopup')
      authPopup.open('芯易行通行管理系统')
    },
    protocol(e) {
      if(e.currentTarget.dataset.type === 'privacyPolicy') {
        my.ap.openURL({
          url: 'https://render.alipay.com/p/yuyan/180020010001104047/index.html?appid=2021003181682188',
        })
      }
    },
    // 授权获取三要素结果
    async authResult(e) {
      if(e.detail && e.detail.code === 200) {
        const params = {
          userId: e.detail.data.userId,
          username: e.detail.data.username,
          idNumber: e.detail.data.idNumber,
          phone: e.detail.data.phone,
          avatar: e.detail.data.avatar || null,
          personPictures: e.detail.data.personPictures || null,
          photoBase64: e.detail.data.photoBase64 || null
        }
        this.triggerEvent("updateState", params)
      } else {
        my.alert({
          title: '提示',
          content: '身份授权认证失败!'
        })
      }
    }
  }
})
