<template>
	<view class="personal">
		<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="job_experience.company_name"></u--input>
		</view>
		<view class="body-input u-flex-col u-row-center" @click="tohangye">
			<text class="input-title">公司行业</text>
			<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="industry"></u--input>
		</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="job_experience.department"></u--input>
		</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="job_experience.job_name"></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" style="margin-top: 20rpx;">
				<view class="" @click="entryShow = true">
					<u--input :disabled="true" disabledColor="#fff" customStyle="padding:0 !important" type="text"
						placeholder="入职时间" border placeholderClass='input-style'
						v-model="job_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="job_experience.end_time"></u--input>
				</view>
			</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="job_experience.level_reason"></u--input>
		</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="job_experience.work_content"></u--input>
		</view>
		<view class="body-input u-flex-col u-row-center">
			<view class="">选填内容</view>
			<text class="input-title">下属人数</text>
			<u--input disabledColor="#fff" customStyle="padding:0 !important" type="text" placeholder="请填写(选填)" border
				placeholderClass='input-style' v-model="job_experience.underling_count"></u--input>
		</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="job_experience.report_to"></u--input>
		</view>
		<view class="u-flex u-row-between">
			<view class="button1" @click="dele" v-if="key==2">
				删除
			</view>
			<view class="button" @click="next">
				保存
			</view>
		</view>
		<u-datetime-picker title="入职时间" :minDate="minDate1" @confirm="entryConfirm" :show="entryShow" mode="year-month"
			@cancel='entryShow = false'></u-datetime-picker>
		<u-datetime-picker title="离职时间" :minDate="minDate" @confirm="dimissionConfirm" :show="dimissionShow" mode="year-month"
			@cancel='dimissionShow = false'></u-datetime-picker>
		<u-modal :showCancelButton="true" :show="delec" :title="title" :content='content' @confirm="confirm"
			@cancel="delec = false"></u-modal>
	</view>
</template>

<script setup>
	import {
		get_category_industry,
		update,
		resumeDetail,
		destroy
	} from "@/units/inquire.js"
	export default {
		data() {
			return {
				delec:false,
				title:"您确定要删除该工作经历吗？",
				entryShow: false,
				dimissionShow: false,
				industryShow: false,
				minDate: "",
				minDate1: "",
				id: "",
				key:1,
				industry: "", //公司行业名称
				industry_first: "",
				job_experience: {
					industry_id: "", //公司行业id
					company_name: "", //公司名称
					start_time: "", //在职时间
					end_time: "", //离职时间
					department: "", //所属部门
					job_name: "", //工作名称
					level_reason: "", //离职原因
					work_content: "", //工作内容
					underling_count: "",
					report_to: ""
				}
			}
		},
		onLoad(opsition) {
			this.id = opsition.id
			this.key = opsition.key
			if (opsition.key == 1) {
				uni.setNavigationBarTitle({
					title: "添加工作经历"
				})
			} else {
				this.resumeDetail()
				uni.setNavigationBarTitle({
					title: "编辑工作经历"
				})
			}
			this.minDate = Number(new Date('2000-01-01'));
			this.minDate1 = Number(new Date('1980-01-01'));
		},
		methods: {
			resumeDetail(){
				resumeDetail().then(res=>{
					console.log(res);
					res.data.job_experience.forEach((item)=>{
						if(item.id == this.id){
							this.job_experience.company_name = item.company_name
							this.job_experience.department = item.department
							this.job_experience.end_time = item.end_time
							this.job_experience.industry_id = item.industry_id
							this.industry = item.industry_name
							this.job_experience.job_name = item.job_name
							this.job_experience.level_reason = item.level_reason
							this.job_experience.report_to = item.report_to
							this.job_experience.start_time = item.start_time
							this.job_experience.underling_count = item.underling_count
							this.job_experience.work_content = item.work_content
						}
					})
				})
			},
			dele() {
				this.delec = true
			},
			getdata(item) {
				console.log(item);
			},
			tohangye() {
				uni.navigateTo({
					url: "../pagesA/change-hangye1",
					events: {
						changehangye: (res) => {
							this.industry_first = res[0].id
							this.job_experience.industry_id = res[1].id
							this.industry = res[1].name
						}
					}
				})
			},
			async entryConfirm(e) {
				const timeFormat = uni.$u.timeFormat;
				console.log(e.value);
				let timeValue = await timeFormat(e.value, 'yyyy-mm');
				this.job_experience.start_time = timeValue;
				this.entryShow = false
			},
			async dimissionConfirm(e) {
				const timeFormat = uni.$u.timeFormat;
				let timeValue = await timeFormat(e.value, 'yyyy-mm');
				this.job_experience.end_time = timeValue;
				this.dimissionShow = false
			},
			return1() {
				uni.navigateBack()
			},
			confirm() {
				destroy({
					source_type: "job_experience",
					source_id: this.id
				}).then(res => {
					this.$u.toast("删除成功")
					setTimeout(() => {
						uni.navigateBack()
					}, 800)
				})
			},
			next() {
				if (!this.job_experience.company_name) {
					this.$u.toast("请填写公司名称")
					return
				}
				if (!this.industry) {
					this.$u.toast("请选择您的公司行业")
					return
				}
				if (!this.job_experience.department) {
					this.$u.toast("请填写您的所属部门")
					return
				}
				if (!this.job_experience.job_name) {
					this.$u.toast("请填写您的职业名称")
					return
				}
				if (!this.job_experience.start_time) {
					this.$u.toast("请选择入职时间")
					return
				}
				if (!this.job_experience.end_time) {
					this.$u.toast("请选择离职时间")
					return
				}
				if (!this.job_experience.level_reason) {
					this.$u.toast("请填写离职原因")
					return
				}
				if (!this.job_experience.work_content) {
					this.$u.toast("请填写工作内容")
					return
				}
				update({
					...this.job_experience,
					source_type: "job_experience",
					source_id: this.id
				}).then(res => {
					uni.navigateBack()
				})
			}
		}
	}
</script>


<style lang="scss">
	.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;
	}

	.btn {
		background: #0C66C2;
		border-radius: 16rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		width: 310rpx;
		height: 84rpx;
		line-height: 84rpx;
		text-align: center;
		margin-top: 24rpx;
	}

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

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

		.titleb {
			font-size: 26rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #777777;
			margin-top: 20rpx;
		}

		.body-input {
			height: 150rpx;
			border-bottom: 2rpx solid #F4F4F4;

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

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

		.button {
			width: 686rpx;
			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;
			text-align: center;
		}
	}
</style>