// pages/login/index.js
import {
  api
} from '../../utils/api.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
      checked:false,
      openData:{
        openId:"",
        sessionKey:''
      }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.init()
  },

  init(){
    const openId = wx.getStorageSync("openId")
    const sessionKey = wx.getStorageSync('seesionKey')
    const tmp = {openId: openId,sessionKey: sessionKey}
    this.setData({openData:tmp})
  },

  goPrivate(){
    wx.openPrivacyContract()
  },

  read(){
    if (this.data.checked === false){
      wx.showModal({
        content: '请先勾选我已经阅读并同意《植趣用户协议》',
      })
    }
  },

  getPhoneNumber(e){
    if (e.detail.errMsg != 'getPhoneNumber:ok') {
      return
    }
    const data = {code:e.detail.code, ...this.data.openData}
    wx.showLoading({
      title: '请稍后',
    })
    api("/auth/getPhone", 'GET', data).then(res => {
      wx.hideLoading()
      if (res.code === 200) {
          wx.navigateBack()
      } else {
          wx.showToast({
              icon: 'error',
              title: res.msg
          })
      }
  })
  },
   change(e){
    const tmp =  this.data.checked === false
    console.log(tmp);
    this.setData({checked:tmp})
   }
})