<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">欢迎使用岑溪人民医院小程序</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="cmd">
			<view class="s_item" @click="go('/pages/help/my')">
				<text class="icon ic" style="color: #f44336">&#xe60b;</text>
				<text class="title">我的回访</text>
				<text class="icon arrow">&#xe62b;</text>
			</view>
		</view>
	</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.eyJsb2dpbl91c2VyX2tleSI6IjdhZGY4MzFmLWE0NjQtNGY5YS04YTY5LWMzM2QyNDU2MzI2ZSJ9.EPHElRmlVoFTfT4OxHNpvIC7bDKc1gKpNiO1u_dBOerYh5JFIuSrSkgp0PtQ0kOhO9iuvU0dttEGbsgofdrcpQ'
		};
		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;
					uni.setStorageSync('money', res.data.data.money || 0);
					uni.setStorageSync('bankName', res.data.data.bankName);
					if (res.data.data.type == null) {
						uni.navigateTo({ url: '/pages/user/switch' });
						return;
					}
				}
			});
		},
		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;
		}
	}
}
</style>
