import Taro, { Component } from '@tarojs/taro'
import { connect } from '@tarojs/redux'
import * as actions from '@actions/user'
import './index.scss'
import getUserPhone from '@utils/getUserPhone'

@connect(state => state.user, { ...actions })
export default class Index extends Component {
  config = {
    navigationBarTitleText: '个人中心'
  }
  state = {
  	person:''
  }
  componentWillMount() {
    const {userInfo:{person}} = this.props
    this.setState({
    	person:person
    })
  }

  getPhoneNumber(e) {
    getUserPhone(e, (phoneNumber) => {
      if (!phoneNumber) {
        Taro.showToast({
          title: '获取手机号失败',
          icon: 'none'
        })
        return
      }
      Taro.reLaunch({
        url: `/pages/project/index`
      })
    })
  }
  
  handleLogin() {
    Taro.navigateTo({
      url: `/pages/person/login/index`
    })
  }
  
  render() {
  	const {person}=this.state

    return (
      <View className='auth-page'>
        <Image className="avatar_img" src={person.avatarurl}/>
        <View className="user_name">{person.nickname}</View>
        <Button  className='auth-btn' open-type="getPhoneNumber" onGetphonenumber={this.getPhoneNumber}>微信授权一键登录</Button>
        <View className='adver-btn' onClick={this.handleLogin}><Text>我是置业顾问,立即登录~</Text></View>
      </View>
    )
  }
}
