// components/userNumberSync.ts
import request from '../../utils/request'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    isNotRead: true
  },

  /**
   * 组件的方法列表
   */
  methods: {
    closeBox(e) {
      const id = e.target.id
      if (id == 'componentBG') {
        this.setData({
          show: false
        })
      }
    },

    getphonenumber(e) {
      const sessionKey = wx.getStorageSync('sessionKey')
      this.doGetUserPhone(e.detail.encryptedData, e.detail.iv, sessionKey, request.appId)
    },

    /** 获取手机号授权 */
    doGetUserPhone(encryptedData, iv, sessionKey, appId) {
      request.post({
        url: '/api/user/getUserPhone',
        data: {
          encryptedData,
          iv,
          sessionKey,
          appId
        }
      }).then(res => {
        console.log(res, 'getUserPhone');
        wx.showToast({
          title: '登录成功！',
          icon: 'success'
        })
        this.setData({
          show: false
        })
        this.triggerEvent('getUserPhoneSuccess')
      }).catch(err => {
        console.log(err, 'err');
      })
    },

    agreedClick() {
      this.setData({
        isNotRead: !this.data.isNotRead
      })
    },

    // 跳转至用户协议页面
    checkUserProtocol() {
      wx.navigateTo({
        url: '/pages/userProtocol/userProtocol',
      })
    },

    skip() {
      this.setData({
        show: false
      })
    }
  }
})
