<template>
	<view class="container">
		<view class="user-section">
			<!-- <view class="bg"></view> -->
			<view class="user-info-box flex_item" @click="ToMycode">
				<view class="portrait" v-if="userInfo.type != 2 && userInfo.type">
					<image :src="userInfo.avatar"></image>
				</view>
				<view class="portrait" v-if="!userInfo.type">
					<image src="../../static/error/missing-face.png"></image>
				</view>
				<view class="portrait" v-if="userInfo.type == 2">
					<image :src="userInfo.ext_info.photo"></image>
				</view>
				<view class="info">
					<view class="name-box flex_item">
						<view class="name clamp">
							{{ (userInfo.ext_info ? (userInfo.ext_info.name ? userInfo.ext_info.name : false) : false) || '游客' }}
						</view>
						<view class="name-text" v-if="userInfo.type == 1">用户</view>
						<view class="name-text" v-if="userInfo.type == 2">医生</view>
						<view class="name-text" v-if="userInfo.type == 3">机构</view>
					</view>
					<view class="name-box flex_item" v-if="userInfo.type">
						<view class="name-text left" v-if="userInfo.type != 1 && userInfo.ext_info.status == 0">审核中
						</view>
						<view class="name-text left" v-if="userInfo.type != 1 && userInfo.ext_info.status == 2">审核不通过
						</view>
					</view>
					<view v-if="userInfo.type == 2">所在医院：{{ userInfo.ext_info.hospital_name }}</view>
				</view>
				<!-- <view class="icon flex">
					<view class="my" @click.stop="navTo('/pages/user/msg')"><image src="/static/img/img012.png"></image></view>
				</view> -->
			</view>
			<!-- <view class="myinfo flex" v-if="userInfo.type == 1" @click="navTo('/pages/userinfo/patient')">我的资料</view> -->
			<image class="arc" src="/static/img/arc.png"></image>
		</view>
		<view class="cover-container">
			<view class="info-box" v-if="userInfo.type != 2"
				@click="navTo('/pages/shareQrCode/index?spread=' + userInfo.uid)">
				<view class="info">
					<image src="/static/img/img032.png" mode="aspectFit"></image>
				</view>
				<view class="text">二维码分享</view>
			</view>
			<view class="info-box" v-if="userInfo.type == 2"
				@click="navTo('/pages/shareQrCode/card?spread=' + userInfo.uid)">
				<view class="info">
					<image src="/static/img/img032.png" mode="aspectFit"></image>
				</view>
				<view class="text">二维码分享</view>
			</view>
			<view class="item-box">
				<view class="flex item-list" @click="navTo('/pages/wallet/commission')">
					<view class="flex_item list-icon">
						<view class="icon">
							<image src="/static/img/img033.png"></image>
						</view>
						<view class="text">我的余额</view>
					</view>
					<view class="icon"><text class="iconfont iconenter"></text></view>
				</view>
				<view class="fen"></view>
				<view class="flex item-list" @click="navTo('/pages/order/myorder')">
					<view class="flex_item list-icon">
						<view class="icon">
							<image src="/static/img/img034.png"></image>
						</view>
						<view class="text">我的订单</view>
					</view>
					<view class="icon"><text class="iconfont iconenter"></text></view>
				</view>
				<view class="fen"></view>
				<view class="flex item-list" @click="navTo('/pages/recommend/index')">
					<view class="flex_item list-icon">
						<view class="icon">
							<image src="/static/img/img036.png"></image>
						</view>
						<view class="text">我的推荐</view>
					</view>
					<view class="icon"><text class="iconfont iconenter"></text></view>
				</view>
				<view class="fen"></view>
				<view class="flex item-list" v-if="userInfo.type == 1" @click="navTo('/pages/userinfo/patient')">
					<view class="flex_item list-icon">
						<view class="icon">
							<image src="/static/img/img035.png"></image>
						</view>
						<view class="text">我的资料</view>
					</view>
					<view class="icon"><text class="iconfont iconenter"></text></view>
				</view>
				<view class="flex item-list" v-if="userInfo.type == 2" @click="navTo('/pages/userinfo/doctor')">
					<view class="flex_item list-icon">
						<view class="icon">
							<image src="/static/img/img035.png"></image>
						</view>
						<view class="text">我的资料</view>
					</view>
					<view class="icon"><text class="iconfont iconenter"></text></view>
				</view>
				<view class="flex item-list" v-if="userInfo.type == 3" @click="navTo('/pages/userinfo/mechanism')">
					<view class="flex_item list-icon">
						<view class="icon">
							<image src="/static/img/img035.png"></image>
						</view>
						<view class="text">我的资料</view>
					</view>
					<view class="icon"><text class="iconfont iconenter"></text></view>
				</view>

			</view>
		</view>
		<!-- 问诊评论 -->
		<view class="item-box bottom" v-if="userInfo.type == 2">
			<view class="icon-box flex_item">
				<view class="left-icon"></view>
				<view class="flex left-box">
					<view class="left-tit">问诊评论</view>
					<view class="more" @click="navTo('/pages/user/reply?id=' + userInfo.uid)">
						查看更多
						<text class="iconfont iconenter"></text>
					</view>
				</view>
			</view>
			<view class="left-txt" v-if="list == ''">暂无数据</view>
			<view class="ask-list flex_item" v-if="list != ''" v-for="(ls, index) in list" :key="index">
				<image :src="ls.avatar || '/static/error/missing-face.png'" class="ask-img"></image>
				<text class="ask-txt ellipsis">{{ ls.comment }}</text>
			</view>
		</view>
		<view class="list-cell" v-if="userInfo.type" @click="toLogout"><text class="cell-tit">退出登录</text></view>
	</view>
</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import uniList from '@/components/uni-list/uni-list.vue';
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
	import {
		getUserInfo
	} from '@/api/login.js';
	import {
		allComment
	} from '@/api/doctor.js';
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	import {
		logout
	} from '@/api/set.js';
	let startY = 0,
		moveY = 0,
		pageAtTop = true;
	export default {
		components: {
			uniList,
			uniListItem
		},
		data() {
			return {
				list: ''
			};
		},
		onShow() {
			// 判断是否已经登录
			console.log(this.hasLogin, 'user');
			this.loadBaseData();
			// if (this.hasLogin) {
			// } else {
			// 	this.userInfo = {
			// 		ext_info: {
			// 			status: ''
			// 		}
			// 	};
			// }
		},
		watch: {},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			...mapMutations(['setUserInfo', 'setOrderInfo', 'logout']),
			//退出登录
			toLogout() {
				uni.showModal({
					content: '确定要退出登录么',
					success: e => {
						if (e.confirm) {
							this.logout();
						}
					}
				});
			},
			// 加载初始数据
			loadBaseData() {
				let obj = this;
				getUserInfo({})
					.then(({
						data
					}) => {
						obj.setUserInfo(data);
						// obj.userInfo = data;
						console.log(obj.userInfo);
						// let arr = data.map(e => {
						// 	e.createtime = getTime(e.createtime);
						// 	return e;
						// });
						this.getDoctor();
						if (data.ext_info.status == 2) {
							uni.showModal({
								title: '提示',
								content: '您的审核未通过: \n ' + data.ext_info.reason + ' \n 是否重新提交审核！',
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
										if (data.type == 2) {
											uni.navigateTo({
												url: '/pages/public/DocRegister'
											});
										}
										if (data.type == 3) {
											uni.navigateTo({
												url: '/pages/public/MecRegister'
											});
										}
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
						// 1是病人 2是医生 3是机构
						if (obj.userInfo.type == 2) {
							uni.setTabBarItem({
								index: 0,
								text: '首页',
								iconPath: 'static/tabBar/tab-home.png',
								selectedIconPath: 'static/tabBar/tab-home-current.png'
							});
							uni.setTabBarItem({
								index: 1,
								text: '我的病人',
								iconPath: 'static/tabBar/tab-cate.png',
								selectedIconPath: 'static/tabBar/tab-cate-current.png',
								visible: true
							});
							uni.setTabBarItem({
								index: 2,
								text: '科普学习',
								iconPath: 'static/tabBar/tab-study.png',
								selectedIconPath: 'static/tabBar/tab-study-current.png',
								visible: false
							});
							uni.setTabBarItem({
								index: 3,
								text: '接单',
								iconPath: 'static/tabBar/jd.png',
								selectedIconPath: 'static/tabBar/jd-act.png',
								pagePath: '/pages/dd/dd'
							})
							uni.setTabBarItem({
								index: 4,
								text: '我的',
								iconPath: 'static/tabBar/tab-my.png',
								selectedIconPath: 'static/tabBar/tab-my-current.png'
							});
						}
						if (obj.userInfo.type == 1) {
							uni.setTabBarItem({
								index: 0,
								text: '首页',
								iconPath: 'static/tabBar/tab-home.png',
								selectedIconPath: 'static/tabBar/tab-home-current.png'
							});
							uni.setTabBarItem({
								index: 1,
								text: '咨询记录',
								iconPath: 'static/tabBar/tab-cate.png',
								selectedIconPath: 'static/tabBar/tab-cate-current.png',
								visible: true
							});
							uni.setTabBarItem({
								index: 2,
								text: '科普学习',
								iconPath: 'static/tabBar/tab-study.png',
								selectedIconPath: 'static/tabBar/tab-study-current.png',
								visible: true
							});
							uni.setTabBarItem({
								index: 3,
								text: '接单',
								iconPath: 'static/tabBar/jd.png',
								selectedIconPath: 'static/tabBar/jd-act.png',
								visible: false
							})
							uni.setTabBarItem({
								index: 4,
								text: '我的',
								iconPath: 'static/tabBar/tab-my.png',
								selectedIconPath: 'static/tabBar/tab-my-current.png'
							});
						}
						if (obj.userInfo.type == 3) {
							uni.setTabBarItem({
								index: 0,
								text: '首页',
								iconPath: 'static/tabBar/tab-home.png',
								selectedIconPath: 'static/tabBar/tab-home-current.png'
							});
							uni.setTabBarItem({
								index: 1,
								text: '咨询记录',
								iconPath: 'static/tabBar/tab-cate.png',
								selectedIconPath: 'static/tabBar/tab-cate-current.png'
							});
							uni.setTabBarItem({
								index: 2,
								text: '科普学习',
								iconPath: 'static/tabBar/tab-study.png',
								selectedIconPath: 'static/tabBar/tab-study-current.png',
								visible: false
							});
							uni.setTabBarItem({
								index: 3,
								text: '发布订单',
								iconPath: 'static/tabBar/jd.png',
								selectedIconPath: 'static/tabBar/jd-act.png',
								pagePath: '/pages/dd/dd'
							})
							uni.setTabBarItem({
								index: 4,
								text: '我的',
								iconPath: 'static/tabBar/tab-my.png',
								selectedIconPath: 'static/tabBar/tab-my-current.png'
							});
						}
						if (obj.userInfo.type == 2 && obj.userInfo.ext_info.price == '0.00') {
							uni.showModal({
								title: '提示',
								content: '您的用户信息尚未完善，是否前去完善？',
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
										uni.navigateTo({
											url: '/pages/userinfo/doctor'
										});
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						}
					})
					.catch(e => {
						if (e.message == '请登录') {
							uni.showModal({
								title: '提示',
								content: '您未登录，是否登录？',
								success: function(res) {
									if (res.confirm) {
										uni.navigateTo({
											url: '/pages/public/wxLogin'
										});
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						} else {
							console.log(e.message);
						}
					});
			},
			//获取医生详情
			getDoctor() {
				let obj = this;
				console.log(obj.userInfo, 55);
				allComment({
						uid: obj.userInfo.uid,
						limit: 5,
						page: 1
					})
					.then(({
						data
					}) => {
						obj.list = data;
					})
					.catch(e => {
						console.log(e.message);
					});
			},
			ToMycode() {
				if (this.userInfo.type == 1) {
					uni.navigateTo({
						url: '/pages/userinfo/patient'
					});
				}
				if (this.userInfo.type == 2) {
					uni.navigateTo({
						url: '/pages/userinfo/doctor'
					});
				}
				if (this.userInfo.type == 3) {
					uni.navigateTo({
						url: '/pages/userinfo/mechanism'
					});
				}
			},
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					// 保存地址
					saveUrl();
					uni.showModal({
						title: '提示',
						content: '您未登录，是否马上登录？',
						success: res => {
							if (res.confirm) {
								interceptor();
							}
						}
					});
					// 登录拦截
				} else {
					uni.navigateTo({
						url
					});
				}
			}
		}
	};
</script>
<style lang="scss">
	.list-cell {
		margin-top: 60rpx;

		.cell-tit {
			display: flex;
			align-items: center;
			justify-content: center;
			text-align: center;
			width: 560rpx;
			height: 80rpx;
			color: #fff;
			background: $base-color;
			border-radius: 40rpx;
			font-size: $font-base + 2rpx;
			margin: 0 auto;
		}
	}

	page {
		height: 100%;
		// padding-bottom: 188rpx;
	}

	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		background: #fff;
		border-radius: 10rpx;
	}

	.container {
		background-color: $page-color-base;
		height: 1650rpx;
		// padding-bottom: 188rpx;
	}

	.user-section {
		// height: 500rpx;
		padding: 60rpx 30rpx 0;
		padding-bottom: 90rpx;
		position: relative;
		background: linear-gradient(52deg, #7e99fe, #978ffa);

		.arc {
			position: absolute;
			left: 0;
			bottom: 0;
			// margin-top: -34rpx;
			width: 100%;
			height: 36rpx;
		}

		// .bg {
		// 	position: absolute;
		// 	left: 0;
		// 	top: 0;
		// 	width: 100%;
		// 	height: 100%;
		// 	background: linear-gradient(52deg, rgba(126, 153, 254, 1), rgba(151, 143, 250, 1));
		// }
	}

	.user-info-box {
		font-size: 32rpx;
		color: #ffffff;
		height: 200rpx;
		// display: flex;
		// align-items: center;
		// justify-content: space-between;
		// position: relative;
		z-index: 3;

		.portrait {
			width: 135rpx;
			height: 135rpx;

			image {
				width: 100%;
				height: 100%;
				border-radius: 100%;
			}
		}

		.info {
			padding: 0rpx 25rpx;
			width: 75%;

			.name-box {
				width: 100%;
				padding-bottom: 15rpx;

				.name {
					font-size: 32rpx;
					max-width: 60%;
				}

				.name-text {
					margin-left: 25rpx;
					font-size: 22rpx !important;
					border: 2rpx solid #ffffff;
					padding: 2rpx 25rpx;
					border-radius: 25rpx;
				}

				.left {
					margin-left: 0 !important;
				}
			}
		}

		.icon {
			image {
				width: 48rpx;
				height: 49rpx;
			}
		}
	}

	.myinfo {
		z-index: 999;
		position: absolute;
		right: 0;
		top: 25%;
		background-color: #ffffff;
		color: #6786fb;
		font-size: 24rpx;
		padding: 14rpx 29rpx;
		border-top-left-radius: 50rpx;
		border-bottom-left-radius: 50rpx;
	}

	.cover-container {
		// background: $page-color-base;
		margin-top: -100rpx;
		position: relative;
		// background: #f5f5f5;
		padding-bottom: 20rpx;

		.info-box {
			// position: absolute;
			// top: -80rpx;
			z-index: 999;
			margin: 0 auto;
			// margin-top:  -80rpx;
			width: 91%;
			color: #697079;
			left: 35rpx;
			border-radius: 25rpx;
			background-color: #ffffff;
			text-align: center;
			font-size: 24rpx;
			padding: 25rpx 0rpx;

			.info {
				width: 100%;
				height: 100rpx;
				text-align: center;

				image {
					width: 100rpx;
					height: 100%;
				}
			}

			.text {
				padding-top: 15rpx;
			}
		}
	}

	.bottom {
		padding-bottom: 100rpx !important;
	}

	.item-box {
		width: 100%;
		background-color: #ffffff;
		// position: relative;
		// top: 150rpx;
		padding: 15rpx 25rpx;
		padding-bottom: 0;
		margin-top: 30rpx;

		.item-list {
			width: 100%;
			padding: 10rpx 0rpx;

			.list-icon {
				image {
					width: 77rpx;
					height: 77rpx;
					margin-right: 35rpx;
				}

				.text {
					color: #323232;
					font-size: 28rpx;
					font-weight: bold;
				}
			}
		}

		.fen {
			width: 100%;
			height: 2rpx;
			background-color: #ececec;
			margin: 10rpx 0rpx;
		}
	}

	.icon-box {
		margin-bottom: 32rpx;
	}

	.left-icon {
		width: 12rpx;
		height: 42rpx;
		background: $base-color;
		border-radius: 6rpx;
	}

	.left-box {
		width: 100%;
	}

	.left-tit {
		font-size: 30rpx;
		font-weight: bold;
		color: rgba(51, 51, 51, 1);
		line-height: 42rpx;
		margin-left: 14rpx;
	}

	.more {
		font-size: 24rpx;
		color: #666666;
	}

	.left-txt {
		font-size: 28rpx;
		font-weight: 500;
		color: rgba(102, 102, 102, 1);
		line-height: 52rpx;
	}

	.ask-list {
		margin-bottom: 25rpx;

		.ask-img {
			width: 92rpx;
			height: 92rpx;
			border-radius: 50%;
		}

		.ask-txt {
			font-size: 28rpx;
			font-weight: 500;
			width: 80%;
			padding-left: 15rpx;
			color: rgba(102, 102, 102, 1);
			line-height: 48rpx;
		}
	}

	/*公用边框样式*/
	%icon {
		margin-right: 10rpx;
		display: inline-block;
		padding: 2rpx 10rpx;
		border: 1rpx solid $color-yellow;
		color: $color-yellow;
		line-height: 1;
		font-size: $font-base;
		border-radius: 10rpx;
	}
</style>
