<template>
	<view class="content">
		<view class="content1">
			<view class='flex flex-space-between' @click="switchPicture">
				<view>
					<text>头像</text>
				</view>
				<view style='align-items: center;' class="flex">
					<view class="pictures">
						<image :src="headUrl" class="picture"></image>
					</view>
					<image src="../../static/images/myimg/gengduo1@3x.png" class="arrow"></image>
				</view>
			</view>
			<u-line color="#EEEEEE" class="line"></u-line>
			<view class='flex flex-space-between'>
				<view>
					<text>姓名</text>
				</view>
				<view style='align-items: center;' class="flex" @click="editName">
					<view class="username">
						{{firstAuthentication.authenticationStatus=='已认证'?firstAuthentication.driverName:firstAuthentication.authenticationStatus=='已过期'?'已过期':'未认证'}}
					</view>
					<!-- <image src="../../static/images/myimg/gengduo1@3x.png" class="arrow"></image> -->
				</view>
			</view>
		</view>
		<view class="content2">
<!-- 
			<view class='flex flex-space-between' @click='UpdataAccount'>
				<view>
					<text>修改账号</text>
				</view>
				<image src="../../static/images/myimg/gengduo1@3x.png" class="arrow"></image>
			</view> -->
			<!-- <u-line color="#EEEEEE" class="line"></u-line> -->
			<view class='flex flex-space-between' @click='UpdataPassword'>
				<view>
					<text>修改密码</text>
				</view>
				<image src="../../static/images/myimg/gengduo1@3x.png" class="arrow"></image>
			</view>
			<u-line color="#EEEEEE" class="line"></u-line>
			<view class='flex flex-space-between' @click='fankui'>
				<view>
					<text>意见反馈</text>
				</view>
				<image src="../../static/images/myimg/gengduo1@3x.png" class="arrow"></image>
			</view>
			<!-- <u-line color="#EEEEEE" class="line"></u-line>
			<view class='flex flex-space-between' @click='clearStorage'>
				<view>
					<text>清除缓存</text>
				</view>
				<image src="../../static/images/myimg/gengduo1@3x.png" class="arrow"></image>
			</view> -->
		</view>
		<view class='exitloginwrap'>
			<button @click='logout()' class='exitlogin'>退出登录</button>
		</view>
		<u-modal :show="isShowAlert" :title="alertTitle" :content='alertContent' :closeOnClickOverlay='true'
			:showCancelButton='true' confirmColor='#2772FB' @confirm="logOut" @close="cancelClick"
			@cancel="cancelClick"></u-modal>
	</view>
</template>

<script>
	var _this
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				alertTitle: '',
				isShowAlert: false,
				alertContent: '您确定要退出吗?',
				headUrl: "../../static/images/myimg/YongHu@3x.png",
				username: "",
				gridList: [{
					num: 0,
					name: '退出登录',
					// icon:'cuIcon-exit',
					src: '../../static/images/sign/return@3x.png',
					tips: 0,
					url: '',
					show: true
				}, ],
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		onShow() {
			this.getList()
			this.firstAuthentication=uni.getStorageSync("firstAuthentication")
		},
		onLoad() {
			_this = this
			console.log(this.userInfo)
			console.log(this.hasLogin)
		},
		methods: {
				editName(){
					uni.showToast({
						icon:'none',
						title:'可在司机认证中修改'
					})
				},
			UpdataAccount() {
				uni.navigateTo({
					url: `/pages/mine/settings/editPhone`
				})
			},
			UpdataPassword() {
				uni.navigateTo({
					url: `/pages/mine/settings/editPassword?phone=${this.userInfo.phone}`
				})
			},
			clearStorage() {
				let that = this
				uni.clearStorageSync();
				this.$request.baseRequest('post', '/auth/api/logout').then(res => {
					if (res.code==200) {
						that.$store.commit('logout')
						// that.$api.logout()
								uni.navigateTo({
									url: `/pages/public/login`
								})
					}
				})
				
		
			},
		
			cancelClick() {
				this.isShowAlert = false
			},
			logOut() {
				uni.clearStorageSync();
				this.$request.baseRequest('post', '/auth/api/logout', {}).then(res => {
						uni.removeStorage({
							key: 'userInfo'
						})
						this.isShowAlert = false
						this.$store.commit('logout')

						uni.switchTab({
							url: `/pages/goodSource/index`
						})
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});


			},
			getList() {
				this.headUrl = this.userInfo.avatarUrl
				if (this.headUrl == null || this.headUrl == "") {
					this.headUrl = "../../static/images/myimg/YongHu@3x.png"
				}
				this.username = this.userInfo.userName
			},
			switchPicture() {
				uni.navigateTo({
					url: `/pages/mine/settings/editAvatar`
				})
			},
			exitlogin() {

			},
			fankui() {
				uni.navigateTo({
					url: `/pages/mine/fankui`
				})
			},
			logout() {
				// const that = this
				this.isShowAlert = true
				// uni.showModal({
				// 	title: '询问',
				// 	content: '您确定要退出吗？',
				// 	cancelText: '取消',
				// 	confirmText: '确定',
				// 	success: (e) => {
				// 		if (e.confirm) {
				// 			uni.hideTabBarRedDot({
				// 				index: 3
				// 			})
				// 			uni.clearStorageSync();
				// 			that.$store.commit('logout')
				// 			that.$api.logout()
				// 			uni.navigateTo({
				// 				url: `/pages/public/login`
				// 			})
				// 		}
				// 	}
				// })
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		height: 100vh;

color: #333333;
	}

	.content1,
	.content2 {
		background: white;
		padding: 20rpx 40rpx;
	}

	.content2 {
		margin-top: 10rpx;
		.flex{
			height: 70rpx;
		}
	}

	.pictures {
		justify-content: flex-end;
		width: 35px;
		height: 35px;
		background-color: #E0FAF6;
		border-radius: 18px;
	}

	.picture {
		width: 35px;
		height: 35px;
		border-radius: 18px;
	}

	.arrow {
		margin-left: 15px;
		width: 8px;
		height: 12px;
		// justify-content: flex-end

	}

	.username {
		color: #6D6D72;
	}

	.sign {
		width: 18px;
		height: 18px;
		top: 4px;
		margin-right: 6px;
	}

	.exitloginwrap {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		padding-bottom: 20px;
	}

	.exitlogin {
		width: 90%;
		background: #fff;
		border-radius: 30px;
		color: #FB1E1E;
		font-size: 17px;
	}

	.exitlogin:after {
		border: none;
	}

	.line {
		margin: 20rpx 0 !important;
	}
</style>
