<template>
	<view>
		<view class="ding" v-if="isToken">
			<image :src="userInfo.image" style="width: 116rpx;height: 116rpx;border-radius: 50%;" mode=""></image>
			<text class="userName">{{userInfo.name}}</text>
		</view>
		<view class="ding" v-if="!isToken"@click="login">
			<image src="../../static/ic_12@2x.png" style="width: 116rpx;height: 116rpx;" mode=""></image>
			<text class="userName">请登录</text>
		</view>
		<view class="topBack">
			<view class="top">
				<view class="one" @click="myVoice">
					<view style="display: flex;">
						<image src="../../static/fapiao.png" style="width: 32rpx;height: 36rpx;" mode=""></image>
						<text class="updateMi">我的发票</text>
					</view>
					<view>
						<image src="../../static/ic_15@2x.png" style="width: 28rpx;height: 28rpx;" mode=""></image>
					</view>
				</view>
				<view class="one" @click="uploadImg">
					<view style="display: flex;">
						<image src="../../static/changeImg.png" style="width: 32rpx;height: 36rpx;" mode=""></image>
						<text class="updateMi">更换证件照</text>
					</view>
					<view>
						<image src="../../static/ic_15@2x.png" style="width: 28rpx;height: 28rpx;" mode=""></image>
					</view>
				</view>
				<!-- <view class="one" @click="GoUpPass">
					<view style="display: flex;">
						<image src="../../static/ic_13@2x.png" style="width: 32rpx;height: 36rpx;" mode=""></image>
						<text class="updateMi">更改密码</text>
					</view>
					<view>
						<image src="../../static/ic_15@2x.png" style="width: 28rpx;height: 28rpx;" mode=""></image>
					</view>
				</view> -->
				<view class="one" @click="outLogin">
					<view style="display: flex;">
						<image src="../../static/ic_14@2x.png" style="width: 32rpx;height: 36rpx;" mode=""></image>
						<text class="out">退出登录</text>
					</view>
					<view>
						<image src="../../static/ic_15@2x.png" style="width: 28rpx;height: 28rpx;" mode=""></image>
					</view>
				</view>
			</view>
		</view>
		<view class="Btn">
			<view class="Onb" @click="GoIndex">
				<image src="../../static/hui.png" style="width: 44rpx;height: 44rpx;" mode=""></image>
				<text class="pei">培训</text>
			</view>
			<view class="Onb">
				<image src="../../static/lan.png" style="width: 44rpx;height: 44rpx;" mode=""></image>
				<text class="me">我的</text>
			</view>
		</view>
		<view class="mask" v-if="mask">
		</view>
		<view class="maskBox" v-if="mask">
			<view class="maskItem" @click="confrim">
				确认退出
			</view>
			<view class="maskItem" @click="concel">
				取消
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		data() {
			return {
				isToken: false,
				mask: false,
				userInfo: '', //用户信息
				fileList:[],
				urlImg:[]
			}
		},
		onShow() {
			this.isToken = uni.getStorageSync('Authorization') ? true : false
			this.userInfo = uni.getStorageSync('userInfo')
			console.log(uni.getStorageSync('userInfo'), 'user')
		},
		methods: {
			onClose() {},
			//我的发票
			myVoice() {
				uni.navigateTo({
					url: '/pages/index/my-invoice'
				})
			},
			//登录
			login(){
			uni.navigateTo({
				url:'/pages/index/login'
			})
			},
			//退出登录
			outLogin() {
				this.mask = true
			},
			GoIndex() {
				uni.navigateTo({
					url: './index'
				})
			},
			//修改证件照
			//上传照片
			uploadImg() {
				let that = this
				that.tempFilePaths = []
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						let list = chooseImageRes.tempFilePaths
						list.forEach((item, index) => {
							that.tempFilePaths.push(item);
						})
						let lists = that.tempFilePaths
						lists.forEach(ele => {
							const uploadTask = uni.uploadFile({
								url: 'http://ranqi-admin.t.brotop.cn//api/common/upload',
								filePath: ele,
								fileType: 'image',
								name: 'file',
								formData: {
									'user': 'test'
								},
								header: {
									'token': uni.getStorageSync('token') || ''
								},
								success: (uploadFileRes) => {
									let uploadList = JSON.parse(uploadFileRes.data).data
									that.fileList.unshift(uploadList.url) 
									that.urlImg.unshift(uploadList.fullurl)
									console.log(that.fileList, that.urlImg[0],'res')
									that.userInfo.image=uploadList.fullurl
								}
							});
						})

					}
				});
			},
			//修改密码
			GoUpPass() {
				uni.navigateTo({
					url: './updatePass'
				})
			},
			confrim() {
				this.mask = false
				request.post('/api/index/logout', {}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: '退出成功'
						})
						this.mask = false
						this.isToken = false
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/index/login'
							})
						}, 500)

					}
				}).catch(err => {})


			},
			concel() {
				this.mask = false
			}
		}
	}
</script>

<style>
	.mask {
		position: fixed;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
		background-color: #000;
		opacity: 0.6;
		z-index: 6;
	}

	.maskBox {
		width: 100%;
		height: 160rpx;
		position: fixed;
		bottom: 0rpx;
		left: 0;
		background-color: #fff;
		z-index: 9;
	}

	.maskItem {
		height: 80rpx;
		text-align: center;
		width: 100%;
		line-height: 80rpx;
		color: #007AFF;
		font-size: 28rpx;
		border-bottom: 2rpx solid #cfcfcf;
	}

	.ding {
		position: absolute;
		top: 35px;
		width: 100%;
		display: flex;
		align-items: center;
		margin-left: 24px;

	}

	.userName {
		color: #FFFFFF;
		font-size: 40rpx;
		margin-left: 15px;
	}

	.one {
		display: flex;
		align-items: center;
		height: 50px;
		margin: 0 16px;
		justify-content: space-between;
		border-bottom: 1px solid #EBEDF0;
	}

	.top {
		background: #ffffff;
		border-radius: 12px 12px 0 0;
		position: fixed;
		width: 100%;
		top: 140px;
	}

	.out {
		color: #323233;
		font-size: 30rpx;
		margin-left: 10px;
	}

	.updateMi {
		color: #323233;
		font-size: 30rpx;
		margin-left: 10px;
	}

	.topBack {
		height: 320rpx;
		width: 100%;
		background: linear-gradient(180deg, #1e4684, #285dad 100%);
		;
	}

	.me {
		color: #2E7FF9;
		font-size: 20rpx;
	}

	.pei {
		color: #969799;
		font-size: 20rpx;
	}

	.Onb {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.Btn {
		display: flex;
		width: 100%;
		justify-content: space-around;
		height: 50px;
		align-items: center;
		position: fixed;
		bottom: 0;
	}
</style>