<template>
	<view class="main">
		<view class="user" @click="go('/pages/user/auth')">
			<image :src="user.avatar ? ip + user.avatar : '../../static/favicon.png'" class="head"></image>
			<view class="con" v-if="user.id">
				<view class="nickName">{{ user.type == 0 ? '个人用户' : '企业用户' }}</view>
				<view class="welcome">
					<text class="icon" v-if="user.isAuthentication == 0">&#xec72;</text>
					<text class="icon" v-else>&#xe607;</text>
					<text>{{ user.isAuthentication == 0 ? '未实名，点击去认证' : '已实名认证' }}</text>
				</view>
			</view>
			<view class="con" v-else>
				<view class="nickName">你还没登录</view>
				<view class="welcome">欢迎使用爱就业咨询服务平台</view>
			</view>
			<view class="icon edit">&#xe62b;</view>
		</view>
		<!--企业用户-->
		<view class="rows" v-if="user.type == 1">
			<view class="row">
				<view class="out">
					<view class="int">
						<view class="num">{{ user.receive || 0 }}</view>
						<view class="desc">收到简历</view>
					</view>
				</view>
			</view>
			<view class="row">
				<view class="out">
					<view class="int">
						<view class="num">{{ user.ask || 0 }}</view>
						<view class="desc">面试邀请</view>
					</view>
				</view>
			</view>
			<view class="row">
				<view class="out">
					<view class="int">
						<view class="num">{{ user.agree || 0 }}</view>
						<view class="desc">面试人数</view>
					</view>
				</view>
			</view>
		</view>
		<!--个人用户-->
		<view class="rows" v-else>
			<view class="row">
				<view class="out">
					<view class="int">
						<view class="num">{{ user.fullTime || 0 }}</view>
						<view class="desc">全职投递</view>
					</view>
				</view>
			</view>
			<view class="row">
				<view class="out">
					<view class="int">
						<view class="num">{{ user.partTime || 0 }}</view>
						<view class="desc">兼职投递</view>
					</view>
				</view>
			</view>
			<view class="row">
				<view class="out">
					<view class="int">
						<view class="num">{{ user.invite || 0 }}</view>
						<view class="desc">面试次数</view>
					</view>
				</view>
			</view>
		</view>
		<view v-if="user.type == 1">
			<view class="mtt">企业服务</view>
			<view class="menu">
				<view class="cd" @click="go('/pages/job/position/manage/list')">
					<view class="out">
						<view class="int">
							<view class="icon" style="background-color: #ff9800">&#xe602;</view>
							<view class="title">职位管理</view>
						</view>
					</view>
				</view>
				<view class="cd" @click="go('/pages/user/resume/deliver/receive/index')">
					<view class="out">
						<view class="int">
							<view class="icon" style="background-color: #4caf50">&#xe627;</view>
							<view class="title">收到简历</view>
							<view class="bage" v-if="user.noRead > 0">{{ user.noRead > 99 ? '99+' : user.noRead }}</view>
						</view>
					</view>
				</view>
				<view class="cd" @click="go('/pages/user/enterprise/index')">
					<view class="out">
						<view class="int">
							<view class="icon" style="background-color: #03a9f4">&#xe646;</view>
							<view class="title">企业信息</view>
							<view class="bage" v-if="user.id && !user.enterprise">去认证</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view v-else>
			<view class="mtt">求职服务</view>
			<view class="menu">
				<view class="cd" @click="go('/pages/user/resume/index')">
					<view class="out">
						<view class="int">
							<view class="icon" style="background-color: #3f51b5">&#xe606;</view>
							<view class="title">我的简历</view>
							<view class="bage" v-if="user.id && !user.resume">待完善</view>
						</view>
					</view>
				</view>
				<view class="cd" @click="go('/pages/user/resume/deliver/invite')">
					<view class="out">
						<view class="int">
							<view class="icon" style="background-color: #4caf50">&#xe605;</view>
							<view class="title">面试邀约</view>
							<view class="bage" v-if="user.accept > 0">{{ user.accept > 99 ? '99+' : user.accept }}</view>
						</view>
					</view>
				</view>
				<view class="cd" @click="go('/pages/user/resume/deliver/list')">
					<view class="out">
						<view class="int">
							<view class="icon" style="background-color: #607d8b">&#xe652;</view>
							<view class="title">投递历史</view>
						</view>
					</view>
				</view>
				<view class="cd" @click="go('/pages/job/position/favorite')">
					<view class="out">
						<view class="int">
							<view class="icon" style="background-color: #ff9800">&#xe626;</view>
							<view class="title">我的收藏</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mtt">更多功能</view>
		<view class="menu">
			<view class="cd" @click="go('/pages/statement/index/index')">
				<view class="out">
					<view class="int">
						<view class="icon" style="background-color: #03a9f4">&#xe63c;</view>
						<view class="title">结算广场</view>
					</view>
				</view>
			</view>
			<view class="cd">
				<view class="out">
					<button class="int share" open-type="feedback" hover-class="none">
						<view class="icon" style="background-color: #ffc107">&#xe648;</view>
						<view class="title">建议反馈</view>
					</button>
				</view>
			</view>
			<view class="cd">
				<view class="out">
					<button class="int share" open-type="share" hover-class="none">
						<view class="icon" style="background-color: #ff5722">&#xe637;</view>
						<view class="title">分享应用</view>
					</button>
				</view>
			</view>
			<view class="cd">
				<view class="out">
					<button class="int share" open-type="contact" hover-class="none">
						<view class="icon" style="background-color: #8bc34a">&#xe632;</view>
						<view class="title">联系客服</view>
					</button>
				</view>
			</view>
			<view class="cd" @click="show = true">
				<view class="out">
					<view class="int">
						<view class="icon" style="background-color: #607d8b">&#xe6ee;</view>
						<view class="title">切换角色</view>
					</view>
				</view>
			</view>
			<view class="cd" @click="go('/pages/notice/detail?id=28')">
				<view class="out">
					<view class="int">
						<view class="icon" style="background-color: #4581fb">&#xe634;</view>
						<view class="title">关于我们</view>
					</view>
				</view>
			</view>
			<view class="cd" @click="go('/pages/other/setting')">
				<view class="out">
					<view class="int">
						<view class="icon" style="background-color: #9e9e9e">&#xe63a;</view>
						<view class="title">设置</view>
					</view>
				</view>
			</view>
		</view>
		<u-action-sheet round="20" :actions="type" @select="selectClick" cancelText="取消" :show="show" @close="show = false"></u-action-sheet>
	</view>
</template>
<script>
export default {
	data() {
		return {
			ip: this.http.ip,
			user: {},
			type: [
				{ name: '找工作(个人)', value: 0 },
				{ name: '我要招聘(企业)', value: 1 }
			],
			show: false
		};
	},
	onShow() {
		/* 		 		 		 		 	 this.user = {
				token: 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjZkOTE1NTNkLWE1ZjktNDU4Yy05MTM2LTU2MDc0Y2M2ZmNkZiJ9.j4mYCmtjhup6CyxxQXznMjqdWi1HoAaF2nT4PpMWTl3B3UrQMwDACrYUWctml83wg4uf43PjIPOvfkFpaUADOw'
			};
			uni.setStorageSync('user', this.user); */

		if (this.hasLogin()) {
			this.getUserInfo();
		} else {
			this.user = {};
		}
	},
	methods: {
		getUserInfo() {
			this.http.request({
				url: '/app/user/info',
				success: (res) => {
					this.user = res.data.data;
					if (res.data.data.type == null) {
						uni.navigateTo({ url: '/pages/user/switch' });
						return;
					}
				}
			});
		},
		//切换角色
		selectClick(e) {
			uni.showModal({
				title: '提示',
				content: e.value == 0 ? '确定切换到个人用户?' : '确定切换到企业用户?',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/app/user/choice',
							data: { type: e.value },
							method: 'POST',
							success: (res) => {
								this.getUserInfo();
							}
						});
					}
				}
			});
		},
		go(url) {
			if (this.hasLogin()) {
				uni.navigateTo({ url: url });
			} else {
				uni.navigateTo({ url: '/pages/user/login' });
			}
		}
	},
	onShareAppMessage: function (res) {
		return {
			title: '爱就业咨询服务平台',
			path: '/pages/index/index',
			imageUrl: 'https://chenglantimes.com/prod-api/profile/upload/2024/06/16/blob_20240616055022A009.jpeg',
			success: (res) => {},
			fail: (res) => {}
		};
	}
};
</script>
<style lang="scss">
.main {
	padding: 5px 15px 25px 15px;
	.user {
		overflow: hidden;
		image {
			float: left;
			width: 60px;
			height: 60px;
			border-radius: 50%;
		}
		.con {
			float: left;
			padding-left: 15px;
			.nickName {
				padding-top: 5px;
			}
			.welcome {
				font-size: 14px;
				padding-top: 5px;
				color: #989898;
				.icon {
					padding-right: 3px;
				}
			}
		}
		.edit {
			float: right;
			margin-top: 14px;
		}
	}
	.rows {
		overflow: hidden;
		margin-top: 10px;
		.row {
			float: left;
			width: 33%;
			text-align: center;
			.out {
				.int {
					padding: 5px;
					.num {
						font-weight: bold;
					}
					.desc {
						padding-top: 5px;
						font-size: 14px;
					}
				}
			}
		}
	}
	.mtt {
		margin-top: 10px;
	}
}
</style>
