<template>
	<view class="container">
		<u-navbar title="个人中心" @rightClick="rightClick" :autoBack="true">
		</u-navbar>
		<view class="box" v-if="userInfo">
			<view class="">
				手机号：{{userInfo.mobile}}
			</view>
			<view class="">
				唯一身份标识：{{userInfo.yige_open_id}}
			</view>
			<view class="">
				姓名：{{userInfo.real_name}}
			</view>
			<view class="">
				身份证号：{{userInfo.identity_card}}
			</view>
			<view class="">
				昵称：{{userInfo.nickname}}
			</view>
			<view class="">
				头像{{userInfo.head_photo}}
			</view>
		</view>
	</view>
</template>

<script>
	import uniWeb from '../static/uni.webview.1.5.4.js'
	export default {
		data() {
			return {
				deviceType: "phone",
				loginType: 'account', //qywx  account,
				form: {
					username: "",
					password: ""
				},
				yigeauth: false,
				userInfo: null
			}
		},
		onLoad(options) {

			this.yigeauth = options.yigeauth === 'true' ? true : false
			/**
			 * 判断是否需要授权
			 */
			if (this.yigeauth) {
				// 需要授权
				this.getYigeauth()
			} else if (options.yigeopenid) {
				// 如果已经授权，并且返回了 openid，则通过 openid 去获取用户信息
				this.getUerByOpenId(options.yigeopenid)
			}
		},
		methods: {
			/**
			 *  app端通过 /auth/before/check 校验是否授权及相应返回参数
			 *  
			 * redirect":"aHROcDoVLZE5Mi4xNjguMC4yNDYvcmVkaXJ1Y30uaHRtbA" 回调地址 
			 * redirect 带有 yigeauth参数 为 true 需要授权 不返回 yigeopenid 为 false 不需要授权 返回 yigeopenid
			 *  appId": "1738044695273148416
			 * action": "auth"
			 * back":"aHROcDovLZE5Mi4xNjguMC4yNDYvaw5kZXguaHRtbA"
			 * 通过授权参数 yigeauth true 需要授权，false 不需要授权，通过 yigeopenid直接 获取信息
			 */
			getYigeauth() {
				this.$http.get('/auth/build_auth').then(res => {
					try {
						uniWeb.webView.postMessage({
							data: res.data
						})
					} catch (err) {
						console.log('err==>', err)
					}
				})
			},

			getUerByOpenId(yigeopenid) {
				this.$http.post('/auth/getUserByOpenId', {
					yigeOpenId: yigeopenid
				}).then(res => {
					if (res.code == 200) {
						// 获取用户信息
						this.userInfo = res.data
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	.container {
		width: 100vw;
		height: 100vh;
		overflow: hidden;
		// background: url('../static/img/loginBg.png');
		background-size: contain;
		position: relative;

		.box {
			padding: 30rpx;
			padding-top: 200rpx;
			word-break: break-all;
		}
	}
</style>