import weast from 'weast'
import userInfo from '../stores/userInfoStore'

function storeToProps () {
  return {
    userInfo: userInfo,
    motto: 'Hello World',
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  }
}

class Index extends weast.Page {
  constructor (props) {
    super(props)
  }
  getUserInfo(){
    this.props.userInfo.receiveUserInfo()
  }
  bindViewTap() {
    console.log('用户信息已获取')
  },
  render() {
    return (
      <wxml>
        <view class="container">
          <view class="userinfo">
            <button wx:if="{{!userInfo.auth && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
            <block wx:else>
              <image bindtap="bindViewTap" class="userinfo-avatar" src="{{props.userInfo.avatarUrl}}" background-size="cover"></image>
              <text class="userinfo-nickname">{{props.userInfo.nickName}}</text>
            </block>
          </view>
          <view class="usermotto">
            <text class="user-motto">{{props.motto}}</text>
          </view>
        </view>
      </wxml>
    )
  }
}
export default observer(storeToProps, Index);
