<template>
	<view class="user-content">
		<!-- 头部 -->
		<view class="user-head">
			<view class="user-photo">
				<u-avatar :src="userAvatarUrl" size="large" class="avatar"></u-avatar>
			</view>
			<view class="user-info">
				<text class="user-name">用户名</text>
				<text class="user-phone">15785829632</text>
			</view>
		</view>
		<!-- 列表 -->
		<view class="user-list">
			<u-cell-group>
				<u-cell-item icon="file-text" icon-size="40" :icon-style="{color:'#ffaa00'}" index="0" @click="toPage" title="服务协议及隐私政策"></u-cell-item>
				<!-- <u-cell-item icon="info-circle" icon-size="38" :icon-style="{color:'#55aa00'}" index="1" @click="toPage" title="关于我们"></u-cell-item> -->
				<u-cell-item icon="lock" icon-size="38" :icon-style="{color:'#00aaff'}" index="2" @click="toPage" title="修改密码"></u-cell-item>
			</u-cell-group>
		</view>
		<!-- 退出 -->
		<view class="user-btn">
			<u-button type="success" :custom-style="quitButton" @click="quitOutSys" shape="circle">退出登录</u-button>
		</view>
	</view>
</template>

<script>
	import { getUserInfo, logout } from '@/api/user.js'
	import { getSysVersion } from '@/api/data.js'
	import { checkVersionToLoadUpdate, clzConfirm } from '@/libs/tools';
	import market from "@/js_sdk/dc-market/market.js"
	export default {
		data() {
			return {
				quitButton: {
					borderRadius:'100rpx',
					fontSize:'30rpx',
					background: '#ed1c24'
				},
				userInfoData: null,  //  用户信息
				userAvatarUrl: ''  //  用户头像
			};
		},
		onShow() {
			this.getUserInfo()
		},
		onLoad() {
		},
		methods:{
			//  获取用户信息
			getUserInfo(){
				getUserInfo().then(res => {
					if(res.status == 200){
						this.userInfoData = res.data
					}else{
						this.userInfoData = null
					}
				})
			},
			// 打开对应的页面
			toPage(index){
				let pageUrl=[
					'/pages/agreement/agreement?fromPage=usercenter',
					'/pages/userCenter/changePwd'
					]
				uni.navigateTo({
					url: pageUrl[index]
				})
			},
			// 退出登录确认弹框
			quitOutSys() {
				const _this = this;
				clzConfirm({
					title: '提示',
					content: '确定退出登录？',
					success: function(res) {
						if (res.confirm || res.index == 0) {
							_this.quitSys();
						}
					}
				});
			},
			// 退出登录，返回登录页
			quitSys() {
				logout().then(res => {
					console.log(res);
					if (res.status == 200) {
						this.$store.commit("$closeWebsocket")
						this.$store.state.vuex_token = '';
						this.$store.state.vuex_userData = '';
						uni.setStorageSync('setStatusIndexFunc', 0);
						this.$toashMsg(res.message)
						setTimeout(function() {
							uni.reLaunch({
								url: '/pages/login/login'
							});
						}, 500);
					}
				});
			},
			// 获取最新版本信息
			getVersion() {
				let version = getApp().globalData.version
				console.log(version)
				getSysVersion({versionType:version.platform=='android'?'ANDROID':'IOS'}).then(ret => {
					console.log(JSON.stringify(ret))
					if(ret.status == 200){
						console.log(ret.data)
						this.$store.state.vuex_versionInfo = ret.data
						//进行版本型号的比对 以及下载更新请求
						checkVersionToLoadUpdate(ret.data, 1, market); 
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.user-content{
		width: 100%;
		.user-head{
			background: #ed1c24;
			display: flex;
			align-items: center;
			padding: 35rpx 55rpx;
			.user-photo{
				flex-shrink: 0;
				margin-right: 5rpx;
				// width: 130rpx;
				// height: 130rpx;
				// border-radius: 50%;
				// overflow: hidden;
			}
			.user-info{
				flex-grow: 1;
				padding: 0 20rpx;
				color: #FFFFFF;
				.user-name{
					display: block;
					font-size: 30rpx;
					margin-bottom: 20rpx;
				}
				.user-phone{
					display: block;
					font-size: 26rpx;
				}
			}
		}
		.user-list{
			border-radius: 15upx;
			margin: 20upx;
			overflow: hidden;
			box-shadow: 0upx 3upx 6upx #eee;
		}
		.user-btn{
			padding: 85rpx 200rpx;
		}
	}
</style>
