<template>
	<view class="work-experience">
		<!-- 自定义导航栏 -->
		<view class="custom-navbar">
			<view class="navbar-content">
				<view class="nav-left" @click="goBack">
					<u-icon name="arrow-leftward" color="#333" size="42"></u-icon>
				</view>
				<view class="nav-title">教育经历</view>
				<view class="nav-right"></view>
			</view>
		</view>
		
		<!-- 主要内容 -->
		<view class="main-content">
			<!-- 公司信息 -->
			<view class="form-section">				
				<!-- 公司名称 -->
				<view class="form-item">
					<view class="form-label">学校名称</view>
					<input 
						v-model="formData.companyName" 
						placeholder="请填写公司名称" 
						class="form-input"
					/>
				</view>
				
			</view>
			
			<!-- 岗位履历 -->
			<view class="form-section">
				<!-- 任职时间 -->
				<view class="form-item">
					<view class="form-label">
						<text class="required-mark">*</text>
						<text class="label-text">在校时间</text>
					</view>
					<view class="form-input">
						<uni-datetime-picker
										v-model="formData.employmentTime"
										type="daterange"
										rangeSeparator="至"
										:border="false"
										startPlaceholder="选择入校时间"
										endPlaceholder="选择离校时间"
									/>
						<!-- <text v-if="resume.employmentTime">{{ resume.employmentTime }}</text> -->
						<!-- <text v-else class="placeholder">{{ hasCrossBorderExperience ? '选择任职时间&离职时间' : '选择在职时间&离职时间' }}</text> -->
						<image src="../../static/images/index/Iconly_Light_Calendar.svg" style="width: 48rpx; height: 48rpx;" mode="aspectFit"></image>
					</view>
				</view>
				
				<!-- 所在部门 -->
				<view class="form-item">
					<view class="form-label">
						<text class="required-mark">*</text>
						<text class="label-text">学历</text>
					</view>
					<view class="form-input">
						<picker class="picker" mode="selector" :range="departments" @change="selectDepartment">
							<text>{{departments.length>0?departments[formData.departmentIndex]:'请选择学历'}}</text>
						</picker>
						<u-icon name="arrow-down" color="#999" size="36"></u-icon>
					</view>
				</view>
				<!-- 工作业绩 -->
				<view class="form-item">
					<view class="form-label">专业</view>
					<view class="form-input">
						<textarea auto-height v-model="formData.workPerformance" placeholder="选填,请输入"></textarea>
					</view>
				</view>
				
				<!-- 工作内容 -->
				<view class="form-item">
					<view class="form-label">经历内容</view>
					<view class="form-input">
						<textarea auto-height v-model="formData.workContent" placeholder="选填,请输入"></textarea>
					</view>
				</view>
				
			</view>
		</view>
		
		<!-- 底部保存按钮 -->
		<view class="bottom-btn-container">
			<view class="save-btn" @click="saveWorkExperience">
				<text>保存</text>
			</view>
		</view>
		
		<!-- 添加技能弹窗 -->
		<u-popup v-model="showAddSkill" mode="center" border-radius="24" width="80%">
			<view class="add-skill-popup">
				<view class="popup-title">添加技能</view>
				<view class="popup-content">
					<input 
						v-model="newSkillName" 
						placeholder="请输入技能名称" 
						class="skill-input"
						maxlength="10"
					/>
				</view>
				<view class="popup-buttons">
					<view class="popup-btn cancel-btn" @click="cancelAddSkill">取消</view>
					<view class="popup-btn confirm-btn" @click="confirmAddSkill">确定</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	var id=''
export default {
	data() {
		return {
			showAddSkill: false,
			newSkillName: '',
			currentResumeIndex: 0,
			
			formData: {
				companyName: '',
				employmentTime: [],
				departmentIndex: 0,
				workContent: '',
				workPerformance: ''
			},
			departments:[
					"初中",
						"高中",
						"中专",
						"大专",
						"本科",
						"硕士",
						"博士",
						"博士后"
				],
		}
	},
	onLoad(options) {
		// 接收从在线简历页面传递的业务类型参数
		id=options&&options.id?options.id:''
		if(id!=''&&id!=0)
		this.getData()
		// 监听技能设置更新
	},
	beforeDestroy() {
		
	},
	computed: {
		
	},
	methods: {
		goBack() {
			uni.navigateBack()
		},
		getData(){
			var that=this
			this.$Request.getT("/app/userFirst/selectEdu", {eduId:id}).then((res) => {
			  if (res.code == 0) {
				  res=res.data
			     that.formData.companyName= res.school
				that.formData.employmentTime= [res.startTime,res.endTime]
				that.formData.departmentIndex= that.departments.indexOf(res.degree)<=0?0:that.departments.indexOf(res.degree)
				that.formData.workContent= res.profession
				that.formData.workPerformance= res.detail
			  } else {
			    uni.showToast({
			      title: res.msg,
			      icon: "none",
			    });
			  }
			});
		},
		selectDepartment(e){
			this.formData.departmentIndex=e.detail.value
		},
		formatter(type, value) {
		                if (type === 'year') {
		                    return `${value}年`
		                }
		                if (type === 'month') {
		                    return `${value}月`
		                }
		                if (type === 'day') {
		                    return `${value}日`
		                }
		                return value
		            },

		saveWorkExperience() {
			console.log(this.formData.resumes)
		  if (!this.formData.companyName) {
		    uni.showToast({ title: "请输入学校名称", icon: "none" });
		    return;
		  }
		  if (this.formData.employmentTime.length<=0) {
		    uni.showToast({ title: "请选择在校时间", icon: "none" });
		    return;
		  }
		  
			let data={
				eduId:id,
				school:this.formData.companyName,
				profession:this.formData.workPerformance,
				startTime:this.formData.employmentTime.length<=0?'':this.formData.employmentTime[0],
				endTime:this.formData.employmentTime.length<=0?'':this.formData.employmentTime[1],
				degree:this.departments[this.formData.departmentIndex],
				detail:this.formData.workContent
			}
		  uni.showLoading({ title: "提交中..." });
		  this.$Request.postJson("/app/userFirst/addEdu", data).then((res) => {
			  uni.hideLoading();
		    if (res.code == 0) {
		        uni.showToast({ title: "保存成功", icon: "none" });
		        // 实际开发中可以在这里添加跳转逻辑
				uni.$emit('updateResume')
		      setTimeout(() => {
		        uni.navigateBack()
		      }, 1000);
		    } else {
		      uni.showToast({
		        title: res.msg,
		        icon: "none",
		      });
		    }
		  });
		},
	}
}
</script>

<style lang="scss" scoped>
.work-experience {
	min-height: 100vh;
	padding-bottom: 120rpx;
}

.custom-navbar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	padding-top: 80rpx;
	background-color: #ffffff;
	z-index: 9999;
	
	.navbar-content {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 100%;
		padding: 0 40rpx;
		
		.nav-left, .nav-right {
			width: 60rpx;
			height: 60rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
		
		.nav-title {
			color: rgba(51, 51, 51, 1);
			font-family: DM Sans;
			font-size: 36rpx;
			font-weight: 700;
			line-height: 26px;
			letter-spacing: 0px;
			text-align: center;
		}
	}
}

.main-content {
	margin-top: 88rpx;
	padding: 80rpx 20rpx 40rpx 20rpx;
}

.form-section {
	background: #fff;
	border-radius: 16rpx;
	padding: 0rpx 10rpx;
	
	.section-title {
		color: rgba(23, 23, 37, 1);
		font-family: Inter;
		font-size: 32rpx;
		font-weight: 600;
		line-height: 48rpx;
		letter-spacing: 0%;
		text-align: left;
		padding: 16rpx 0 32rpx 0;
	}
}

.form-item {
	margin-bottom: 30rpx;
	
	.form-label {
			color: rgba(31, 44, 55, 1);
			font-family: DM Sans;
			font-size: 16px;
			font-weight: 500;
			line-height: 22px;
			letter-spacing: 0%;
			text-align: left;
			margin-bottom: 20rpx;

		.required-mark {
			color: #FF3B30;
			font-size: 18px;
			font-weight: 500;
			margin-right: 4rpx;
		}
		
		.label-text {
			color: rgba(31, 44, 55, 1);
			font-family: DM Sans;
			font-size: 16px;
			font-weight: 500;
			line-height: 22px;
			letter-spacing: 0%;
			text-align: left;
		}
	}
	
	.form-input {
		width: 100%;
		min-height: 80rpx;
		padding: 0 40rpx;
		border: 1px solid rgba(227, 231, 236, 1);
		border-radius: 24px;
		background: rgba(255, 255, 255, 1);
		display: flex;
		align-items: center;
		justify-content: space-between;
		
		.placeholder {
			color: #999999;
		}
		picker{
			width: 100%;
		}
		textarea{
			width: 100%;
			padding: 20rpx 0;
			height: fit-content;
			min-height: 40rpx;
		}
	}
}

.skills-input-container {
	width: 100%;
	min-height: 80rpx;
	padding: 0rpx 40rpx;
	border: 1px solid rgba(227, 231, 236, 1);
	border-radius: 32px;
	background: rgba(255, 255, 255, 1);
	display: flex;
	align-items: center;
	justify-content: space-between;
	
	.skills-tags {
		display: flex;
		flex-wrap: wrap;
		gap: 12rpx;
		flex: 1;
		
		.skill-tag {
			padding: 8rpx 16rpx;
			background: #F5F5F5;
			border-radius: 8rpx;
			display: flex;
			align-items: center;
			gap: 8rpx;
			
			text {
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
	
	.add-skill-btn {
		width: 40rpx;
		height: 40rpx;
		border: 1rpx solid rgba(102, 102, 102, 1);
		border-radius: 8rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #fff;
		flex-shrink: 0;
	}
}

.add-resume-btn {
	width: 100%;
	height: 80rpx;
	border: 1rpx solid #007AFF;
	border-radius: 60rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-top: 20rpx;
	
	text {
		color: #007AFF;
		font-size: 28rpx;
		font-weight: 500;
	}
}

.bottom-btn-container {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	padding: 30rpx 20rpx;
	background: #fff;
	border-top: 1px solid #f0f0f0;
	z-index: 98;
}

.save-btn {
	width: 100%;
	height: 88rpx;
	background: linear-gradient(90deg, rgba(13, 39, 247, 1), rgba(19, 193, 234, 1) 100%);
	border-radius: 44rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	
	text {
		font-size: 32rpx;
		font-weight: 600;
		color: #fff;
	}
}

.add-skill-popup {
	background: #fff;
	border-radius: 24rpx;
	padding: 40rpx;
	
	.popup-title {
		color: rgba(34, 37, 42, 1);
		font-size: 36rpx;
		font-weight: 500;
		text-align: center;
		margin-bottom: 30rpx;
	}
	
	.popup-content {
		margin-bottom: 30rpx;
		
		.skill-input {
			width: 100%;
			height: 80rpx;
			padding: 0 20rpx;
			border: 1rpx solid #E5E5EA;
			border-radius: 12rpx;
			font-size: 28rpx;
			color: rgba(34, 37, 42, 1);
			background: #F7F8FA;
		}
	}
	
	.popup-buttons {
		display: flex;
		gap: 20rpx;
		
		.popup-btn {
			flex: 1;
			height: 80rpx;
			border-radius: 12rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			font-weight: 500;
		}
		
		.cancel-btn {
			background: #F7F8FA;
			color: rgba(102, 102, 102, 1);
		}
		
		.confirm-btn {
			background: #007AFF;
			color: #fff;
		}
	}
}

.checkbox-container {
	display: flex;
	flex-wrap: nowrap;
	gap: 10rpx;
	
	/deep/ .u-checkbox-group {
		display: flex;
		flex-wrap: nowrap;
		width: 100%;
	}
	
	/deep/ .u-checkbox {
		flex: 1;
		min-width: 0;
		margin-right: 0;
	}

	/deep/ .u-checkbox__label {
		color: var(--Grayscale/Grayscale 100, rgba(23, 23, 37, 1));
		font-family: DM Sans;
		font-size: 24rpx;
		font-weight: 400;
		line-height: 48rpx;
		letter-spacing: 0%;
		text-align: left;
	}
}
</style>
