<template>
	<view class="index-page">
		<!-- 个人信息 -->
		<view class="personal">
			<view class="body-input u-flex-col u-row-center ">
				<text class="input-title">学校名称</text>
				<u--input customStyle="padding:0 !important" type="text" placeholder="请填写您的学校名称" border
					placeholderClass='input-style' v-model="education_experience.name"></u--input>
			</view>
			<view class="body-input u-flex-col u-row-center">
				<text class="input-title">学历</text>
				<view class="" @click="xueli1 = true">
					<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
						placeholder="请选择您的学历" border placeholderClass='input-style' suffixIcon="arrow-right"
						suffixIconStyle="font-size: 32rpx;font-weight: 400;color: #CACACA;"
						v-model="education"></u--input>
				</view>
			</view>
			<view class="body-input u-flex-col u-row-center">
				<text class="input-title">专业名称</text>
				<u--input disabledColor="#fff" customStyle="padding:0 !important" type="text" placeholder="请填写专业名称"
					border placeholderClass='input-style' v-model="education_experience.major"></u--input>
			</view>
			<view class="body-input u-flex-col u-row-center">
				<text class="input-title">时间</text>
				<view class="u-flex u-row-between">
					<view class="" @click="entryShow = true">
						<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
							placeholder="上学时间" border placeholderClass='input-style'
							v-model="education_experience.start_time"></u--input>
					</view>
					<view class="">-</view>
					<view class="" @click="dimissionShow = true">
						<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
							placeholder="毕业时间" inputAlign="center" border placeholderClass='input-style'
							v-model="education_experience.end_time"></u--input>
					</view>
				</view>
			</view>
			<view class="u-flex u-row-between bottom">
				<view class="button1" @click="dele" v-if="type==2">
					删除
				</view>
				<view class="button" @click="next">
					保存
				</view>
			</view>
		</view>
		<!-- 选择器 -->
		<!-- 选择器 -->
		<u-datetime-picker title="上学时间" :minDate="minDate1" @confirm="entryConfirm" :show="entryShow" mode="year-month"
			@cancel='close()'></u-datetime-picker>
		<u-datetime-picker title="毕业时间" :minDate="minDate" @confirm="dimissionConfirm" :show="dimissionShow"
			mode="year-month" @cancel='close()'></u-datetime-picker>
		<!-- 		<u-picker title="学历" keyName="name" :show="xueli" @confirm="confirm" :columns="list"
			@close="close()"></u-picker> -->
		<u-picker title="学历" :columns="list" ref="uPicker" :show="xueli1" keyName="name" @confirm="confirm"
			@change="changeHandler" @cancel="xueli1 = false"></u-picker>
		<u-modal :showCancelButton="true" :show="delec" :title="title" :content='content' @confirm="confirm1"
			@cancel="delec = false"></u-modal>
	</view>
</template>

<script>
	import {
		get_education,
		update,
		resumeDetail,
		destroy
	} from "@/units/inquire.js"
	export default {
		data() {
			return {
				id: "",
				delec: false,
				type: 1,
				title: "您确定要删除该项目经历吗？",
				minDate: "",
				minDate1: "",
				list: [],
				xueli: [],
				tongzhao: [],
				dimissionShow: false,
				entryShow: false,
				xueli1: false,
				education: "", //学历
				education_experience: {
					name: "", //学校名称
					is_recruit: "", //是否统招
					education_id: "", //学历id
					major: "", //专业名称
					start_time: "", //开始时间
					end_time: "", //结束时间

				}
			}
		},
		onLoad(opsition) {
			this.id = opsition.id
			console.log(this.id);
			this.type = opsition.type
			if (opsition.type == 1) {
				uni.setNavigationBarTitle({
					title: "添加教育经历"
				})
			} else {
				this.resumeDetail()
				uni.setNavigationBarTitle({
					title: "编辑教育经历"
				})
			}
			this.minDate = Number(new Date('2000-01-01'));
			this.minDate1 = Number(new Date('2000-01-01'));
			this.get_education()
		},
		methods: {
			changeHandler(e) {
				const {
					columnIndex, //当前改变值的列下标
					value,
					values, // values为当前变化列的数组内容
					indexs, //当前地区值下标
					picker = this.$refs.uPicker
				} = e
				//columnIndex代表第几列，意思是下标为0的列发生变化

				if (columnIndex === 0) {
					picker.setColumnValues(1, this.tongzhao[indexs[0]].map(v => {
						return {
							name: v.name,
							id: v.id
						}
					}))
				}
			},
			confirm(e) {
				console.log('kkkk', e);
				let a = e.value[0].name + e.value[1].name
				let ids = String(e.value[0].id) + String(e.value[1].id)
				this.xueli1 = false
				this.education_experience.education_id = e.value[0].id
				this.education_experience.is_recruit = e.value[1].id
				this.education = e.value[0].name + '·' + e.value[1].name
				// this.get_education()
			},
			resumeDetail() {
				resumeDetail().then(res => {
					res.data.education_experience.forEach((item) => {
						if (item.id == this.id) {
							this.education_experience.education_id = item.education_id
							if(item.is_recruit==1){
								this.education = item.education_name+'·'+'统招'
							}else if(item.is_recruit==0){
								this.education = item.education_name+'·'+'非统招'
							}
							this.education_experience.end_time = item.end_time
							this.education_experience.is_recruit = item.is_recruit
							this.education_experience.major = item.major
							this.education_experience.name = item.name
							this.education_experience.start_time = item.start_time
						}
					})
				})
			},
			dele() {
				this.delec = true
			},
			confirm1() {
				destroy({
					source_type: "education_experience",
					source_id: this.id
				}).then(res => {
					this.$u.toast("删除成功")
					setTimeout(() => {
						uni.navigateBack()
					}, 800)
				})
			},
			close() {
				this.xueli1 = false
				this.dimissionShow = false
				this.entryShow = false
			},
			// confirm(e) {
			// 	this.education_experience.education_id = e.value[0].id
			// 	this.education = e.value[0].name
			// 	this.xueli = false
			// },
			get_education() {
				get_education().then(res => {
					res.data.forEach(item => {
						item.children = [{
							name: '统招',
							id: 1
						}, {
							name: '非统招',
							id: 0
						}]
						res.data.push(item)
					})

					this.xueli = res.data.map(t => {
						return {
							name: t.name,
							id: t.id
						}
					})
					this.tongzhao = res.data.map(t => t.children.map(v => {
						return {
							name: v.name,
							id: v.id
						}
					}))
					let a = []
					let b = []
					this.xueli.map(res => {
						a.push({
							name: res.name,
							id: res.id,
						})
					})
					this.tongzhao[0].map(res => {
						b.push({
							name: res.name,
							id: res.id,
						})
					})
					this.list = [a, b]

				})
			},
			async entryConfirm(e) {
				const timeFormat = uni.$u.timeFormat;
				console.log(e.value);
				let timeValue = await timeFormat(e.value, 'yyyy-mm');
				this.education_experience.start_time = timeValue;
				this.entryShow = false
			},
			async dimissionConfirm(e) {
				const timeFormat = uni.$u.timeFormat;
				let timeValue = await timeFormat(e.value, 'yyyy-mm');
				this.education_experience.end_time = timeValue;
				this.dimissionShow = false
			},
			return1() {
				uni.navigateBack()
			},
			next() {
				if (!this.education_experience.name) {
					this.$u.toast("请填写学校名称")
					return
				}
				if (!this.education) {
					this.$u.toast("请选择学历")
					return
				}
				if (!this.education_experience.major) {
					this.$u.toast("请填写专业名称")
					return
				}
				if (!this.education_experience.start_time) {
					this.$u.toast("请选择上学时间")
					return
				}
				if (!this.education_experience.end_time) {
					this.$u.toast("请选择毕业时间")
					return
				}
				update({
					...this.education_experience,
					source_type: "education_experience",
					source_id: this.id
				}).then(res => {
					uni.navigateBack()
				})
			}

		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F3F3F3;
	}

	.button1 {
		width: 256rpx;
		background: #F3F3F3;
		border-radius: 12rpx;
		margin-right: 24rpx;
		padding: 20rpx 50rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		text-align: center;
		height: 88rpx !important;
		box-sizing: border-box;
	}

	.index-page {
		overflow: hidden;
		height: 100vh;
		background: #fff;

		.mingpianfont {
			height: 50rpx;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 50rpx;
		}

		.explain {
			margin-top: 24rpx;
			width: 528rpx;
			height: 36rpx;
			font-size: 26rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 36rpx;
		}


		//个人信息
		.personal {
			width: 750rpx;
			background: #FFFFFF;
			border-radius: 28rpx 28rpx 0rpx 0rpx;
			margin-top: -40rpx;
			position: relative;
			z-index: 99;
			padding: 40rpx 32rpx 0;
			box-sizing: border-box;
			height: 100%;

			.body-input {
				height: 170rpx;
				border-education_experience: 2rpx solid #F4F4F4;

				.input-title {
					font-size: 26rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #888888;
					margin-bottom: 20rpx;
					margin-top: 30rpx;
					box-sizing: border-box;
				}

				.input-style {
					font-size: 32rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #CACACA;
				}
			}

			.bottom {
				position: fixed;
				bottom: 0;
				width: 682rpx;
				padding-bottom: 10rpx;
			}

			.button {
				flex: 1;
				height: 88rpx !important;
				background: #0C66C2;
				border-radius: 12rpx;
				font-size: 32rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 88rpx;
				margin: 10rpx 0 0rpx 0;
				justify-content: center;
				display: flex;
			}
		}

		.index-item {
			// width: 702rpx;
			// background: #FFFFFF;
			// border-radius: 20rpx;
			// margin: 20rpx auto;
			// padding: 0 20rpx 24rpx 10rpx;

			.item-down {
				text:first-child {
					font-size: 22rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #666666;
				}

				text:last-child {
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #666666;
				}
			}

			.item-gongsi {
				margin-bottom: 16rpx;

				.text2 {
					font-size: 24rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #666666;
				}

				.logo {
					width: 42rpx;
					height: 42rpx;
					border-radius: 10rpx;
					margin-right: 16rpx;
				}

				.text1 {
					max-width: 192rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #444444;
					margin-right: 12rpx;
				}
			}

			.item-label {
				margin-bottom: 20rpx;

				text {
					margin-right: 16rpx;
					line-height: 46rpx;
					background: #F7F7F7;
					border-radius: 4rpx;
					padding: 0 14rpx;
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #5F5F5F;
				}
			}

			.item-top {
				height: 88rpx;

				.text1 {
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
					margin-right: 16rpx;
				}

				.text2 {
					width: 50rpx;
					line-height: 32rpx;
					background: rgba(255, 83, 53, 0.1);
					border-radius: 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FF5335;
					margin-right: 12rpx;
				}

				.text3 {
					width: 90rpx;
					line-height: 32rpx;
					background: #FFF2E8;
					border-radius: 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #FF8620;
					margin-right: 12rpx;
				}

				.text4 {
					line-height: 32rpx;
					background: #E6EFF8;
					border-radius: 4rpx;
					padding: 0 4rpx;
					text-align: center;
					font-size: 20rpx;
					font-family: SFPro-Regular, SFPro;
					font-weight: 400;
					color: #0C66C2;
				}

				.text5 {
					font-size: 32rpx;
					font-family: JDZhengHT-Regular, JDZhengHT;
					font-weight: 400;
					color: #0C66C2;
				}
			}
		}

		.index-navbar {
			position: sticky;
			top: 0;
			left: 0;
			width: 750rpx;
			z-index: 10;

			.header-down {
				height: 92rpx;
				padding: 20rpx 24rpx;
				box-sizing: border-box;

				.font {
					font-size: 40rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}

				.right-item {
					padding: 0 16rpx;
					height: 52rpx;
					background: #F3F3F3;
					border-radius: 4rpx;
					margin-left: 20rpx;

					.text {
						margin-right: 4rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
				}

				.down-left {
					.text {
						margin-right: 4rpx;
						font-size: 26rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #222222;
					}
				}
			}

			.index-bg {
				position: absolute;
				top: 0;
				left: 0;
				z-index: -1;
				width: 750rpx;
				height: 392rpx;
			}
		}

		.index-header {
			flex: 1;
			padding: 0 32rpx;
			height: 50rpx;

			.index-search {
				width: 200rpx;
				height: 64rpx;
				background: #FFFFFF;
				border-radius: 20rpx;
				padding: 0 28rpx;

				.text1 {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					margin-left: 16rpx;
				}
			}

			.index-tabs {
				text:first-child {
					font-size: 36rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #222222;
				}

				text:last-child {
					width: 76rpx;
					height: 12rpx;
					background: linear-gradient(270deg, #208EFF 0%, rgba(28, 159, 227, 0) 100%);
					margin-top: -20rpx;
					border-radius: 100rpx;
				}
			}
		}
	}

	::v-deep .u-navbar__content__left {
		padding: 0 !important;
	}

	::v-deep .u-subsection {
		width: 312rpx !important;
	}
</style>