<template>
	<view class="guide-page">
		<view class="guide-item">
			<view class="guide-img">
				<image src="@/static/images/jobApplicant/woyaozhaogongzuo.svg" mode="aspectFix" />
			</view>
			<view class="guide-btn" @click="goWork">我要找工作</view>
		</view>
		<view class="guide-item">
			<view class="guide-img">
				<image src="@/static/images/jobApplicant/woyaozhaoren.svg" mode="aspectFix" />
			</view>
			<view class="guide-btn" @click="gotocompany">我要招人</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				companyinfo: ""
			};
		},
		onLoad() {
			this.getcompanystatus()
		},
		methods: {
			goWork() {

				//修改当前用户身份
				var res = this.updateUserResumes(1)
				if (!res) {
					uni.showToast({
						title: "登录信息过期，请重新登录",
						icon: "none"
					});
				}
				uni.navigateTo({
					url: '/pages/my/jobApplicant/welcomePage'
				})
			},

			// 查询用户企业状态
			getcompanystatus() {
				this.$Request.get("/app/company/selectCompanyByUserId", "")
					.then((res) => {
						if (res.code != 0) {
							uni.showToast({
								title: res.msg || "查询状态失败",
								icon: "none"
							});
							return;
						}
						this.companyinfo = res.data || {};
						console.log("查询用户企业状态", res)
					})
					.catch((err) => {
						console.error("查询失败：", err);
						uni.showToast({
							title: "网络异常",
							icon: "none"
						});
					});
			},
			gotocompany() {


				//修改当前用户身份
				var res = this.updateUserResumes(2)
				if (!res) {
					uni.showToast({
						title: "登录信息过期，请重新登录",
						icon: "none"
					});
				}

				console.log("ssss");
				//应该要判断这个人有没有公司，
				var status = this.companyinfo.status || ""
				if (!status) { //没有企业，那就是第一次进来，走企业注册流程
					uni.navigateTo({
						url: '/pages/my/businessLicense'
					})
				} else if (status == 2) { //审核通过，如果有职位，跳首页、如果没职位跳职位发布页。
					if (status == 2) {
						uni.preloadPage({
							url: "/pages/index/index"
						});
						uni.switchTab({
							url: '/pages/index/index'
						})

					} else {
						uni.redirectTo({
							url: '/pages/index/index.vue'
						})
					}
				} else if (status == 1) { //审核未通过，跳审核信息页。
					uni.navigateTo({
						url: '/package/jobIntention/underReview'
					})
				} else {
					uni.showToast({
						title: "网络异常",
						icon: "none"
					});
				}


			},
//修改用户身份状态
			updateUserResumes(userType) {
				// 调用接口提交
				uni.showLoading({
					title: "提交中..."
				});
				this.$Request.postJson("/app/user/updateUserEntity", {
						userType: userType
					})
					.then((res) => {
						uni.hideLoading();
						if (res.code === 0) {
							uni.setStorageSync('userType', userType)
							return true
						} else {
							return false
						}
					})
					.catch((err) => {

						uni.hideLoading();
						console.error("提交失败：", err);
						uni.showToast({
							title: "网络异常",
							icon: "none"
						});
						return false
					});
			},

		},
	};
</script>
<style scoped lang="scss">
	.guide-page {
		background: linear-gradient(90deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%);
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		padding: 120rpx 76rpx;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		gap: 36rpx;

		.guide-item {
			width: 100%;
			height: 100%;
			border-radius: 28rpx;
			background: rgba(255, 255, 255, 0.851);
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			padding: 0 56rpx;
			box-sizing: border-box;
			gap: 72rpx;

			.guide-img {
				width: 364rpx;
				height: 364rpx;
				overflow: hidden;

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

			.guide-btn {
				border-radius: 100rpx;
				background: rgba(255, 255, 255, 1);
				color: #016bf6;
				font-family: DM Sans;
				font-size: 32rpx;
				font-weight: 400;
				line-height: 48rpx;
				letter-spacing: 0%;
				text-align: center;
				width: 100%;
				padding: 16rpx;
				box-sizing: border-box;
			}
		}
	}
</style>