<template>
	<view class="resume-detail" :style="{ paddingTop: (12 + statusBarHeight + 88 - 60) + 'px' }">
		<!-- 固定顶部导航栏 -->
		<view class="fixed-nav" :style="{ paddingTop: (12 + statusBarHeight) + 'px' }">
			<view class="navbar">
				<view class="navbar-content">
					<view class="navbar-left" @click="goBack">
						<u-icon name="arrow-left" size="36" color="#333"></u-icon>
					</view>
					<view class="navbar-title">简历详情</view>
					<view class="nav-right">
						<view class="nav-icon" @click="setCollection">
							<image v-if="resumeData.isCollection == 0" src="/static/images/index/guanzhu.svg" class="icon-img"></image>
							<image v-else src="/static/images/index/gzActive.svg" style="width: 50rpx;height: 50rpx;"></image>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view style="margin-top: 20px; border-top: 20rpx solid rgba(241, 245, 248, 1);">
			<previewResume :resumesId="resumesId" :postPushId="postPushId"></previewResume>
		</view>

		<!-- 底部操作按钮 -->
		<view v-if="postPushId != '' && isShowBtn == 0" class="bottom-actions">
			<view class="action-btn contact-btn" @click="contactCandidate">
				<text>立即联系</text>
			</view>
		</view>
	</view>
</template>

<script>
import previewResume from '@/components/resume/preview-resume.vue';
	
export default {
	components: {
		previewResume
	},
	data() {
		return {
			statusBarHeight: 0, // 状态栏高度
			resumeData: {},
			userEntity: "",
			eduList: "",
			intentions: "",
			resumeList: {},
			skills: "",
			postPushId: "",
			workExpList: [],
			workExpTimes: "",
			resumesStatus: ['离职＆随时到岗', '在职＆月内到岗', '在职＆考虑机会', '在职＆暂不考虑'],
			isShowBtn:0,
			resumesId: '',
			postPushId: ''
		}
	},
	onLoad(option) {
		// 获取状态栏高度
		let systemInfo = uni.getSystemInfoSync();
		this.statusBarHeight = systemInfo.statusBarHeight || 0;

		// 获取邀请码保存到本地
		if (option.invitation) {
			this.$queue.setData('inviterCode', option.invitation);
		}
		// #ifdef MP-WEIXIN
		if (option.scene) {
			const scene = decodeURIComponent(option.scene);
			this.$queue.setData('inviterCode', scene.split(',')[0]);
		}
		// #endif
		this.weekMember = uni.getStorageSync('weekMember')
		this.userId = uni.getStorageSync('userId') ? uni.getStorageSync('userId') : 0
		if (option.postPushId) {
			this.postPushId = option.postPushId
		}
		if (option.resumesId) {
			this.resumesId = option.resumesId
			this.getDetail()
		}
		// if (option.resumesId) {
		// 	this.resumesId = option.resumesId
		// 	this.getDetail()
		// } else if (option.userId) {
		// 	this.byuserId = option.userId
		// 	this.getDetail()
		// }
		if(option.isShowBtn){
			this.isShowBtn = option.isShowBtn
		}
	},
	methods: {
		/**
		 * 收藏简历
		 */
		setCollection() {
			this.$Request.postT("/app/myCollection/saveCollection", {
				resumesId: this.resumesId,
				type: 2
			}).then(res => {
				if (res.code == 0) {
					uni.showToast({
						title: res.msg
					})
					this.getDetail()
				}
			})
		},
		goBack() {
			uni.navigateBack();
		},
		contactCandidate() {
			//去联系
			this.getDetail()
			this.$Request.postJson('/app/chat/insertChatConversation', {
				userId: this.userEntity, //会话对象的id
				focusedUserId: uni.getStorageSync('userId'), //当前登录者Id
				postPushId: this.postPushId,
				resumesId: this.resumesId,
				type: 2,
			}).then(ret => {
				if (ret.code == 0) {
					uni.navigateTo({
						url: '/pages/msg/im?byUserId=' + this.userEntity
							 + '&chatConversationId=' + ret.data
								.chatConversationId + '&resumesId=' + this.resumesId + '&postPushId=' +
							this.postPushId
					})
				}
			})

		},
		getDetail() {
			uni.showLoading({
				title: '加载中'
			})
			let data = {
				resumesId: this.resumesId,
				userId: this.userId,
				companyId: uni.getStorageSync('companyId'),
			}
			if (this.postPushId && this.postPushId !== 'null' && this.postPushId !== 'undefined') {
			  data = {
			    ...data,
			    postPushId: this.postPushId
			  }
			}

			this.$Request.get('/app/resumes/selectResumesByResumesId', data).then(res => {
				if (res.code == 0) {
					uni.hideLoading()
					var data = res.data;
					this.resumeData = res.data;
					// this.userEntity = data.userEntity
					this.userEntity = data.userId
					this.eduList = data.eduList
					this.intentions = data.intentionList
					this.resumeList = data.resumesListDtoList !=null?data.resumesListDtoList : {}
					// this.skills = data.skills
					this.skills = data.skillList
					this.workExpList = data.workExpList

				} else {
					uni.hideLoading()
					uni.showModal({
						title: '提示',
						content: '用户简历不存在',
						showCancel: false,
						complete(ret) {
							uni.navigateBack()
						}
					})
				}
			})
		},
		//使用岗位名称查询出企业正在招聘的该岗位拿到对应的岗位id
		getJobList(ruleClassifyName) {
			let data = {
				status: 2,
				page: 1,
				limit: 1,
				ruleClassifyName: ruleClassifyName,
				companyId: uni.getStorageSync('companyId')
			}
			this.$Request.getT('/app/postPush/getPostPushList', data).then(res => {
				if (res.code == 0) {
					this.postPushId = res.data.records[0].postPushId
				}
			})
		},
		// 查看图片
		saveImg(imgs, index) {
			// console.log(imgs)
			let that = this;
			let imgArr = imgs
			// imgArr.push(imgs);
			// //预览图片
			uni.previewImage({
				urls: imgArr,
				current: imgArr[index]
			});
		},
	}
}
</script>
<style lang="scss" scoped>
.resume-detail {
	min-height: 100vh;
	padding-bottom: 120rpx;
	// padding-top 已改为动态计算，在模板中通过 :style 设置
}

.fixed-nav {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 9999;
	background-color: #ffffff;
	// padding: 0 4rpx;
	// padding-top 已改为动态计算，在模板中通过 :style 设置
}

// 顶部导航栏
.navbar {
	background: #fff;
	height: 88rpx;
	padding: 0 8rpx;
	// padding: 80rpx 0 40rpx 0; // 已移除，因为现在是固定导航栏

	.navbar-content {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 30rpx;
		height: 60rpx;

		.navbar-left {
			width: 96rpx;
			display: flex;
			align-items: center;
		}

		.navbar-title {
			color: rgba(23, 23, 37, 1);
			font-family: DM Sans;
			font-size: 34rpx;
			font-weight: 400;
			line-height: 52rpx;
			letter-spacing: 0%;
			text-align: center;
		}

		.nav-right {
			display: flex;
			align-items: center;
			justify-content: flex-end;
			width: 96rpx;
		}
		
		.nav-icon {
			display: flex;
			align-items: center;
			justify-content: center;
			// width: 36rpx;
			// height: 36rpx;
		}
		
		.icon-img {
			width: 42rpx;
			height: 42rpx;
		}
	}
}

// 底部操作按钮
.bottom-actions {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: #fff;
	padding: 30rpx;
	box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);

	.action-btn {
		width: 100%;
		height: 88rpx;
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-weight: 500;
	}

	.contact-btn {
		background: linear-gradient(90deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%);
		color: #fff;
	}
}

.company-title {
	margin-bottom: 8rpx;
	color: rgba(23, 23, 37, 1);
	font-family: DM Sans;
	font-size: 28rpx;
	font-weight: 400;
}
</style>