<template>
	<view class="content">
		<!-- <view class="tabs hflex acenter jbetween">
			<block v-for="(item,index) in tabs" :key="index">
				<view class="tab_item" :class="tab_active == index?'tab_active':''" @click="changeTab(index)">{{item.name}}</view>
			</block>
		</view> -->
		<!-- <block v-if="tab_active == 0 || tab_active == 1">
			<view class="boxs">
				<news-module :pageList="pageList"></news-module>
			</view>
		</block> -->
		<block v-if="state == -1">
			<view class="box vflex acenter jcenter">
				<view class="img_box vflex acenter jcenter">
					<u-icon name="info-circle-fill" color="#506dff" size="50"></u-icon>
					<view class="text">还未提交应聘信息</view>
				</view>
				<view class="release" @click="release">发布</view>
			</view>
		</block>
		<block v-if="state == 2 || state == 0">
			<view class="box hflex jbetween">
				<view class="">
					<view class="hflex acenter">
						<view class="name">{{base_info.name}}</view>
						<view class="edit_btn" @click="perfect(1)">编辑</view>
					</view>
					<view class="hflex acenter" style="padding-top: 16rpx;">
						<view class="hflex acenter padR-24">
							<image src="/static/images/index/demand/sex.png" class="icon"></image>
							<view class="text_style1">{{base_info.sex}}</view>
						</view>
						<view class="hflex acenter padR-24">
							<image src="/static/images/index/demand/edution.png" class="icon"></image>
							<view class="text_style1">{{base_info.edu}}</view>
						</view>
						<view class="hflex acenter padR-24">
							<image src="/static/images/index/demand/birthday.png" class="icon"></image>
							<view class="text_style1">{{base_info.age}}岁</view>
						</view>
						<view class="hflex acenter padR-24" v-if="base_info.year > 0">
							<image src="/static/images/index/demand/work.png" class="icon"></image>
							<view class="text_style1">{{base_info.year}}年</view>
						</view>
					</view>
					<view class="hflex acenter padT-26">
						<u-icon name="phone-fill" color="#666666" size="14" class="padR-24"></u-icon>
						<view class="text_style1">{{base_info.phone}}</view>
					</view>
					<view class="hflex acenter padT-26">
						<image src="/static/images/index/demand/email.png" class="icon"></image>
						<view class="text_style1">{{base_info.email}}<span style="color: #506dff;" @click="copy(base_info.email)"><span style="padding: 0 5rpx;">|</span>复制</span></view>
					</view>
				</view>
				<image :src="base_info.avatar" mode="aspectFill" class="avatar"></image>
			</view>
			<view class="box"  >
				<view class="hflex acenter jbetween">
					<view class="box_title">求职意向</view>
					<view class="edit_btn" @click="perfect(2)">编辑</view>
				</view>
				<view v-show="JSON.stringify(job_inte) !== '{}'">
					<view class="hflex acenter padT-26">
						<view class="box_title">{{job_inte.post}}</view>
						<view class="box_title">{{job_inte.salary}}</view>
					</view>
					<view class="hflex fwrap padT-26">
						<view class="label">可工作区域</view>
						<view class="text_style1" style="flex: 1;">{{job_inte.work_address}}</view>
					</view>
					<view class="hflex acenter padT-26">
						<view class="label">可工作时间</view>
						<view class="text_style1">{{job_inte.work_time}}</view>
					</view>
					<view class="hflex acenter padT-26">
						<view class="label">工作性质</view>
						<view class="text_style1">{{job_inte.work_nature}}</view>
					</view>
				</view>
			</view>
			<view class="box">
				<view class="hflex acenter jbetween">
					<view class="box_title">工作经历</view>
					<view class="hflex acenter" @click="perfect(3)">
						<u-icon name="plus-circle-fill" color="#555555" size="12"></u-icon>
						<view class="text_style1">添加</view>
					</view>
				</view>
				<block v-for="(item,index) in experience" :key="index">
					<view class="padT-26" @click="editInfo(item.id)">
						<view class="hflex acenter jbetween">
							<view class="box_title">{{item.content.company_name}}</view>
							<u-icon name="arrow-right" color="#555555" size="12"></u-icon>
						</view>
						<view class="hflex acenter padT-26">
							<view class="text_style1 padR-24">{{item.content.on_job_start}}-{{item.content.on_job_end}}</view>
							<view class="text_style1">{{item.content.postion_name}}</view>
						</view>
						<view class="hflex fwrap padT-26 text_style2">工作内容：{{item.content.company_content}}</view>
					</view>
				</block>
			</view>
			<view class="box">
				<view class="hflex acenter jbetween">
					<view class="box_title">专业技能</view>
					<view class="hflex acenter" @click="perfect(4)">
						<u-icon name="plus-circle-fill" color="#555555" size="12"></u-icon>
						<view class="text_style1">添加</view>
					</view>
				</view>
				<view class="hflex acenter fwrap">
					<block v-for="(item,index) in skills" :key="index">
						<view class="hflex acenter jbetween item_box2">
							<view class="text_style1">{{item.content.skill_name}}</view>
							<view class="text_style1">{{item.content.degree}}</view>
							<image src="/static/images/index/demand/detele.png" class="detele" @click="deleteOpen(item.id)"></image>
						</view>
					</block>
				</view>
			</view>
			<view class="box"  >
				<view class="hflex acenter jbetween">
					<view class="box_title">资质证书</view>
					<view class="hflex acenter" @click="perfect(5)">
						<u-icon name="plus-circle-fill" color="#555555" size="12"></u-icon>
						<view class="text_style1">添加</view>
					</view>
				</view>
				<view class="">
					<block v-for="(item,index) in certificate" :key="index">
						<view class="hflex aend item_box3">
							<view class="box_title padR-24">{{item.content.certificate_name}}</view>
							<view class="text_style1">{{item.content.gain_time}}</view>
							<image src="/static/images/index/demand/detele.png" class="detele" @click="deleteSure(item.id)"></image>
						</view>
					</block>
				</view>
			</view>
			<view class="box">
				<view class="box_title" style="padding-bottom: 16rpx;">福利待遇</view>
				<u-input v-model="salary" placeholder="请填写你期望的薪资待遇" border="none"></u-input>
				<view class="line"></view>
				<view class="box_title" style="padding-bottom: 16rpx;">备注</view>
				<u-input v-model="remarks" placeholder="请填写你想要备注的内容" border="none"></u-input>
			</view>
			<view class="box hflex acenter jbetween">
				<view class="text_style3">隐藏该应聘</view>
				<u-switch v-model="application.hidden == 1?true:false" @change="changeHide"></u-switch>
			</view>
			<view class="btn" @click="open">{{state == 0?'立即发布':'立即修改'}}</view>
		</block>
		<block v-if="state == 1">
			<view class="box1 vflex acenter">
				<image src="/static/images/comment/wait.png" class="box1_img"></image>
				<view class="box1_title">审核中</view>
				<view class="box1_subTitle">预计审核时间3个工作日</view>
				<view class="box1_subTitle">请留意当前页面变动</view>
				<view class="btn" @click="toedit">去修改</view>
			</view>
		</block>
		<block v-if="state == 3">
			<view class="box1 vflex acenter">
				<image src="/static/images/comment/wait.png" class="box1_img"></image>
				<view class="box1_title">审核失败</view>
				<view class="box1_subTitle">驳回原因</view>
				<view class="box1_subTitle">{{application.why}}</view>
				<view class="btn" @click="toedit">去修改</view>
			</view>
		</block>
		<u-popup :show="show" mode="bottom" :round="20" @close="close">
			<view class="popup">
				<view class="popup_title vflex acenter jcenter">本人承诺</br>以上所填写的内容真实有效</view>
				<view class="popu_label" style="font-size: 28rpx;font-weight: 500;">请填写以下信息</view>
				<view class="popu_label">身份证号</view>
				<u-input v-model="IDNumber" placeholder="请输入身份证号" border="bottom"></u-input>
				<view class="popu_label">手机号码</view>
				<u-input v-model="phone" placeholder="请输入手机号码" border="bottom"></u-input>
				<view class="popu_label">验证码</view>
				<view class="hflex acenter jbetween">
					<u-input v-model="code" placeholder="请输入验证码" border="none"></u-input>
					<view class="popu_label code" @click="getCode">{{tips}}</view>
					<u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code>
				</view>
				<view class="btn1" @click="publish">立即发布</view>
				<view class="cancel" @click="close">取消</view>
			</view>
		</u-popup>
		<u-popup :show="del_show" mode="center" :round="20" @close="close">
			<view class="popup popup1">
				<view class="popup_title vflex acenter jcenter" style="padding: 80rpx 0;">确定要移除此项专业技能吗？</view>
				<view class="hflex acenter jbetween">
					<view class="btn_close hflex acenter jcenter" @click="close">取消</view>
					<view class="btn_delete hflex acenter jcenter" @click="deleteSure(id)">移除</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import $api from '@/static/js/api.js'
	var that = ''
	export default {
		data() {
			return {
				tabs: [
					{
						name: '知识教学'
					},
					{
						name: '百知文库'
					},
					{
						name: '应聘信息'
					}
				],
				tab_active: 2,
				state: -1,
				salary: '',
				remarks: '',
				base_info: {},
				job_inte: {},
				experience: [],
				skills: [],
				certificate: [],
				is_hide: false,
				show: false,
				IDNumber: '',
				phone: '',
				code: '',
				tips: '',
				seconds: 60,
				del_show: false,
				id: '',
			}
		},
		onLoad() {
			that = this
			that.getState()
		},
		onShow() {
			that.getList()
		},
		methods: {
			getState() {
				$api.req({
					url: '/data/api.auth.Center/myrelease',
					method: 'POST',
					data: {
						type: '3'
					}
				}, function(res) {
					if(res.code == 1) {
						that.state = res.data.audit
					}
				})
			},
			getList() {
				$api.req({
					url: '/data/api.auth.Center/myrelease',
					method: 'POST',
					data: {
						type: '3'
					}
				}, function(res) {
					if(res.code == 1) {
						if(JSON.stringify(res.data !== '{}')) {
							if(res.data.real_name) {
								that.$set(that.base_info,'name',res.data.real_name)
								that.$set(that.base_info,'sex',res.data.sex)
								that.$set(that.base_info,'edu',res.data.schooling)
								that.$set(that.base_info,'age',res.data.age)
								that.$set(that.base_info,'year',res.data.work_year)
								that.$set(that.base_info,'phone',res.data.phone)
								that.$set(that.base_info,'email',res.data.email)
								that.$set(that.base_info,'avatar',res.data.head_img)
								that.base_info.date_birth = res.data.date_birth
								that.base_info.start_working_time = res.data.start_working_time
							}
							
							if(res.data.job_application) {
								that.$set(that.job_inte,'post',res.data.job_application)
								that.$set(that.job_inte,'work_address',res.data.scope_work_area)
								that.$set(that.job_inte,'salary',res.data.monthly_salary)
								that.$set(that.job_inte,'work_time',res.data.working_time)
								that.$set(that.job_inte,'work_nature',res.data.work_nature)
							}
							
							that.experience = res.data.workexperience
							that.skills = res.data.professionalskills
							that.certificate = res.data.certificate
							that.salary = res.data.welfare_benefits
							that.remarks = res.data.remark 
						}
					}
				})
			},
			// 切换tabs
			changeTab(index) {
				that.tab_active = index
			},
			// 发布
			release() {
				$api.jump('/page_index/pages/demand/publish')
			},
			// 显示隐藏招聘
			changeHide(e) {
				console.log(e);
				if(e) {
					that.application.hidden = 1
				} else {
					that.application.hidden = 0
				}
				$api.req({
					url: '/data/api.auth.Center/canhidden',
					method: 'POST',
					data: {
						hidden: that.application.hidden
					}
				}, function(res) {
					if(res.code == 1) {
						$api.info(res.info)
					}
				})
				that.is_hide = e
			},
			// 添加或完善
			perfect(index) {
				$api.jump('/page_index/pages/demand/perfect?index='+index)
			},
			// 修改工作经历
			editInfo(id) {
				$api.jump('/page_index/pages/demand/perfect?index=3&id='+ id)
			},
			// 复制
			copy(value) {
				uni.setClipboardData({
					data: value,
					success: function () {
						$api.info('复制成功')
					}
				});
			},
			// 删除
			deleteSure(id) {
				$api.req({
					url: '/data/api.auth.DemandLabor/delapplyjobchild',
					method: 'POST',
					data: {
						id: id
					}
				}, function(res) {
					if(res.code == 1) {
						$api.info(res.info)
						that.close()
						that.getList()
					}
				})
			},
			// 删除
			deleteOpen (id) {
				that.del_show = true
				that.id = id
			},
			toedit() {
				that.state = 2
			},
			// 发布
			publish() {
				if($api.formCheck(that.IDNumber, 'identity') && $api.formCheck(that.phone, 'mobile') && $api.formCheck(that.code, 'code4')) {
					$api.req({
						url: '/data/api.auth.DemandLabor/subapplyjob',
						method: 'POST',
						data: {
							id_card: that.IDNumber,
							phone2: that.phone,
							code: that.code
						}
					}, function(res) {
						if(res.code == 1) {
							$api.info(res.info)
							that.close()
							that.getList()
							that.getState()
						}
					})
					
				}
			},
			// 打开弹窗
			open() {
				$api.req({
					url: '/data/api.auth.DemandLabor/applyjob',
					method: 'POST',
					data: {
						type: 6,
						welfare_benefits: that.salary,
						remark: that.remarks
					}
				}, function(res) {
					if(res.code == 1) {
						if(that.state == 0) {
							that.show = true
						} else {
							that.getState()
						}
					}
				})
			},
			// 关闭弹窗
			close() {
				that.show = false
				that.del_show = false
			},
			// 验证码文字改变
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if(this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					$api.req({
						url: '/data/api.Login/sendsms',
						data: {
							phone: that.phone,
							type: 4
						}
					}, function(res) {
						uni.hideLoading();
						if(res.code == 1) {
							uni.$u.toast('验证码已发送')
							that.$refs.uCode.start()
						} else {
							uni.$u.toast('验证码发送失败')
						}
					})
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			end() {
				uni.$u.toast('倒计时结束');
			},
			start() {
				uni.$u.toast('倒计时开始');
			}
		},
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 0 30rpx;
		.tabs {
			width: 100%;
			padding: 14rpx 0 25rpx;
			.tab_item {
				width: 33%;
				font-size: 32rpx;
				font-weight: 400;
				color: #222222;
				line-height: 44rpx;
				text-align: center;
			}
			.tab_active {
				color: #222222;
				font-weight: 500;
				position: relative;
			}
			.tab_active::after {
				position: absolute;
				content: "";
				width: 48rpx;
				height: 8rpx;
				background: #506DFF;
				border-radius: 4rpx;
				bottom: -14rpx;
				left: 38%;
			}
		}
		.boxs {
			width: 100%;
			box-sizing: border-box;
			padding: 0 30rpx;
			margin: 24rpx 0 0;
		}
		.box {
			padding: 42rpx 0 26rpx;
			border-top: 1rpx solid #F4F4F4;
			// padding: 0 30rpx;
			.img_box {
				margin: 120rpx 0 0;
				.text {
					padding-top: 20rpx;
					font-size: 32rpx;
					font-weight: 400;
					color: #222222;
					line-height: 44rpx;
				}
			}
			.release {
				margin-top: 112rpx;
				width: 450rpx;
				height: 92rpx;
				background: #506DFF;
				border-radius: 46rpx;
				font-size: 36rpx;
				text-align: center;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 92rpx;
			}
			.box_title {
				font-size: 32rpx;
				font-weight: 500;
				color: #222222;
			}
			.name {
				font-size: 40rpx;
				font-weight: 500;
				color: #222222;
			}
			.edit_btn {
				width: 84rpx;
				height: 36rpx;
				background: #F0F2F6;
				border-radius: 20rpx;
				font-size: 20rpx;
				text-align: center;
				font-weight: 400;
				color: #506DFF;
				line-height: 36rpx;
				margin-left: 16rpx;
			}
			.padT-26 {
				padding-top: 26rpx;
			}
			.padR-24 {
				padding-right: 24rpx;
			}
			.label {
				width: 148rpx;
				font-size: 24rpx;
				font-weight: 400;
				color: #888888;
			}
			.icon {
				width: 28rpx;
				height: 28rpx;
			}
			.text_style1 {
				font-size: 24rpx;
				padding-left: 5rpx;
				font-weight: 400;
				color: #666666;
			}
			.text_style2 {
				font-size: 22rpx;
				font-weight: 400;
				color: #777777;
				line-height: 32rpx;
			}
			.item_box2 {
				background: #F4F4F4;
				border-radius: 26rpx;
				box-sizing: border-box;
				padding: 8rpx 34rpx;
				margin: 20rpx 32rpx 0 0;
				position: relative;
				.detele {
					position: absolute !important;
					right: 1rpx;
					top: 1rpx;
					width: 21rpx;
					height: 21rpx;
				}
			}
			.item_box3 {
				width: 100%;
				background: #F4F4F4;
				border-radius: 26rpx;
				box-sizing: border-box;
				padding: 8rpx 20rpx;
				margin: 20rpx 0 0;
				position: relative;
				.detele {
					position: absolute !important;
					right: 1rpx;
					top: 1rpx;
					width: 21rpx;
					height: 21rpx;
				}
			}
			.avatar {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
			}
			.box_info {
				margin: 42rpx 0 0;
				
				.box_icon {
					width: 56rpx;
					height: 56rpx;
					margin-right: 28rpx;
				}
				.box_subTitle {
					margin-top: 4rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: #777777;
				}
				.box_btn {
					box-sizing: border-box;
					padding: 6rpx 24rpx;
					font-size: 24rpx;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 34rpx;
					background: #506DFF;
					border-radius: 14px;
				}
			}
			.line {
				margin: 20rpx 0;
				width: 100%;
				height: 1rpx;
				background: #F3F3F5;
			}
			.text_style3 {
				font-size: 28rpx;
				font-weight: 400;
				color: #222222;
				line-height: 40rpx;
			}
			
		}
		.btn {
			margin: 100rpx 0 ;
			width: 100%;
			height: 84rpx;
			background: #506DFF;
			border-radius: 42rpx;
			text-align: center;
			font-size: 36rpx;
			font-weight: 500;
			color: #FFFFFF;
			line-height: 84rpx;
		}
		.box1 {
			width: 100%;
			height: 100vh;
			background-color: #fff;
			.box1_img {
				width: 124rpx;
				height: 124rpx;
				margin: 108rpx 0 40rpx;
			}
			.box1_title {
				font-size: 32rpx;
				color: #222;
				margin-bottom: 24rpx;
			}
			.box1_subTitle {
				margin: 12rpx 0;
				font-size: 26rpx;
				color: #595959;
			}
			.btn {
				width: 530rpx;
				height: 88rpx;
				background-color: #506dff;
				color: #fff;
				text-align: center;
				line-height: 88rpx;
				border-radius: 44rpx;
				font-size: 36rpx;
				margin-top: 122rpx;
			}
		}
	.popup {
			background: #FFFFFF;
			border-radius: 40rpx 40rpx 0px 0px;
			width: 100%;
			box-sizing: border-box;
			padding: 30rpx;
			.popup_title {
				width: 100%;
				padding-bottom: 32rpx;
				border-bottom: 1rpx solid #F4F4F4;
				font-size: 36rpx;
				font-weight: 500;
				color: #222222;
				line-height: 50rpx;
			}
			.popu_label {
				font-size: 30rpx;
				font-weight: 400;
				color: #222222;
				padding: 24rpx 0;
			}
			.code {
				color: #506DFF;
			}
			.btn1 {
				margin: 90rpx 0 40rpx;
				width: 100%;
				height: 84rpx;
				background: #506DFF;
				border-radius: 21px;
				text-align: center;
				line-height: 84rpx;
				font-size: 36rpx;
				font-weight: 500;
				color: #FFFFFF;
			}
			.cancel {
				width: 100%;
				text-align: center;
				font-size: 32rpx;
				font-weight: 400;
				color: #777777;
			}
			.u-input {
				padding: 12rpx 0 !important;
			}
			.btn_delete {
				width: 200rpx;
				height: 76rpx;
				background: #506DFF;
				border-radius: 38rpx;
				font-size: 32rpx;
				font-weight: 400;
				color: #FFFFFF;
			}
			.btn_close {
				width: 200rpx;
				height: 76rpx;
				border-radius: 38rpx;
				border: 1px solid #506DFF;
				font-size: 32rpx;
				font-weight: 400;
				color: #506DFF;
			}
		}
	}
</style>