<template>
	<view class="content">
		<u-cell-group>
			<u-cell size="large" title="手机号" :value="user.mobile" isLink></u-cell>
			<u-cell size="large" title="微信号" :value="user.wx_name || '未绑定'" isLink @click="tobindwx"></u-cell>
			<u-cell size="large" title="登录密码" value="修改密码" isLink @click="topwd"></u-cell>
		</u-cell-group>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	export default {
		data() {
			return {
				user: {}
			}
		},
		onLoad() {
			this.getuser()
		},
		methods: {
			topwd() {
				uni.navigateTo({
					url: '/pageC/edit-pwd'
				})
			},
			tobindwx() {
				var that = this
				uni.login({
					"provider": "weixin",
					"onlyAuthorize": true, // 微信登录仅请求授权认证
					success: function(event){
						const {code} = event
						//客户端成功获取授权临时票据（code）,向业务服务器发起登录请求。
						$api.req({
							url: 'user/bind-wechat',
							method: 'post',
							data: {
								code: event.code
							}
						}, function(res) {
							if(res.code == 10000) {
								$api.info('绑定成功')
							}
						})
					},
					fail: function (err) {
						// 登录授权失败
						// err.code是错误码
					}
				})
			},
			getuser() {
				var that = this
				$api.req({
					url: 'user/info',
					method:'get',
					
				} ,function(res) {
					if(res.code == 10000) {
						that.user = res.data
					}
				})
				
			}
		}
	}
</script>

<style lang="scss">
	.content {
		background: #FFFFFF;
	}
</style>
