<template>
	<view >
		<loadlogo v-if="!loadlogo" />
		<far-bottom></far-bottom>
		<view class="curriculumVitae" >
			<view :style="{padding:!pageId?'20upx 0':'0',height:!pageId?'auto':'0',overflow: 'hidden'}" class="dis-flex">
				<view  style="flex: 0.8;">
					<!-- <filtertab :requestType="'7'" :isPageScroll="'1'" @selectAreaid="selectAreaid" @selectClassid="selectClassid" @getmore="getmore" @getResumeList="getResumeList"
					 @selectClassTwoid="selectClassTwoid" @getcityWork="getcityWork" @selectOrders="selectOrders" :cate_one="cate_one" :cate_two="cate_two" :title="title"></filtertab> -->
				</view>
				<view class="f-26" style="flex: 0.2;line-height: 75upx;padding-left: 20upx;" @click="openclass">
					<text>更多</text>
					<text class="iconfont icon-unfold" style="padding-left: 10upx;vertical-align: top;"></text>
				</view>
			</view>
			<v-tabs
			:lineScale="0.3" 
			:lineRadius="'100rpx'" 
			:lineHeight="'6rpx'" 
			:fontSize="'28rpx'" 
			:paddingItem="'20rpx'" 
			:activeColor="'#FCDB36'" 
			:lineColor="'#FCDB36'"
			v-model="sort" 
			:scroll="false"
			field="name"
			@change="vtabschange"
			:tabs="tabBarSetList">
			</v-tabs>
			 <view class="curriculum-list" v-if="inviteList.length > 0">
			 	<view class="curriculum-item" v-for="(item,index) in inviteList" :key="index" @click="lookResume(item)">
			 		<view class="item-personal">
			 			<view class="personal-img dis-il-block">
			 				<image class="img" :src="item.avatar" mode=""></image>
							<view class="gender" v-if="item.gender_text == '女'"><image style="width: 100%;height: 100%;vertical-align: top;" :src="imgfixUrls + 'inviteImg/nvxing.png'" mode=""></image></view>
							<view class="gender" style="background-color: #007AFF;" v-else><image style="width: 100%;height: 100%;vertical-align: top;" :src="imgfixUrls + 'inviteImg/nanxing.png'" mode=""></image></view>
			 			</view>
						<view class="personal-data dis-il-block">
							<view class="data-name">
								{{item.name}}
							</view>
							<view class="data-item">
								{{item.age}}岁 · {{item.experience}} · {{item.education}}
							</view>
						</view>
						<view class="data-salary" v-if="!pageId || checked == 1">
							{{item.salary}}
						</view>
						<view class="data-salary" v-else>
							{{item.status == 0?'未查看':item.status == 1?'已查看':item.status == 2?'已邀请':'已完成'}}
						</view>
			 		</view>
					<view class="item-tags dis-flex">
						<view  style="flex: 0.1;">
							
						</view>
						<view class="tags-box dis-flex" style="flex: 0.9;">
							<view style="flex: 0.8;">
								<view class="tags-item" v-for="(item,index) in item.expect_position_list" :key="index">
									{{item}}
								</view>
							</view>
							<view class="f-24 col-9" style="flex: 0.2;line-height: 58upx;">
								{{item.region}}
							</view>
						</view>
					</view>
					<view class="dis-flex date-and-button" v-if="pageId && checked == 0">
						<view class="date">
							{{item.work_status_text || item.create_time_text}}
						</view>
						<view class="button t-r">
							<view class="delete dis-il-block" @click.stop="deleteWork(item)">
								删除
							</view>
							<view class="invitation dis-il-block" @click.stop="accomplish(item)" v-if="item.status == 2">
								面试完成
							</view>
							<view class="invitation dis-il-block" @click.stop="interview(item)" v-else-if="item.status != 3">
								邀请面试
							</view>
						</view>
					</view>
			 	</view>
				<load-more :isMore="isMore" :bgc="'#ffffff'"></load-more>
			 </view>
			 <nonemores v-if="inviteList.length == 0"></nonemores>
			 
			 <view  v-if="loadlogo">
			 	 <screening :check="check" :num="num" @close="close" @checkeda="checkeda" @confirm="confirm" v-bind:moreData.sync="moreData"></screening>
			 </view>
			<TabBars :tabBarAct="0" pageType="15"></TabBars>
			<PopManager :show="isShow" type="center" @clickmask="closes">
				<view class="b-f invitePop">
					<view class="invitePop-title f-w">
						邀请面试
						<text class="iconfont icon-close" style="float: right;vertical-align: top;font-size: 30upx;" @click="closes"></text>
					</view>
					<view class="f-26 dis-flex" style="padding: 30upx 0;" @click="visiblec = true">
						<view class="flex-box">
							面试时间
						</view>
						<view :class="time?'f-26':'f-26 col-9'">
							{{time || '请选择面试时间	'}}
						</view>
					</view>
					<view class="f-26 dis-flex" style="padding: 0upx 0 30upx;">
						<view style="flex: 0.3;">
							面试地点
						</view>
						<view style="flex: 0.7;">
							<input v-if="isShow" type="text" class="t-r f-26" placeholder-style="color: #999999;" placeholder="请输入面试地址" v-model="site" />
						</view>
					</view>
					<view class="f-26 dis-flex" style="padding: 0upx 0 30upx;">
						<view style="flex: 0.3;">
							面试职位
						</view>
						<view style="flex: 0.7;" @click="visible = true">
							<view :class="selectorItem?'f-26 t-r':'f-26 col-9 t-r'">
								{{selectorItem || '请选择面试职位'}}
							</view>
						</view>
					</view>
					<view class="abBox" @click="invitationLetter">
						确定
					</view>
				</view>
			</PopManager>
			<w-picker
				:visible.sync="visiblec"
				mode="date"
				startYear="1970"
				endYear="2100"
				:value="time"
				fields="minute"
				@confirm="onConfirmdete($event, 'region')"
				ref="date"
			></w-picker>
			<w-picker
			:visible.sync="visible"
			mode="selector"
			:value="selectorItem"
			default-type="title"
			:default-props="defaultProps"
			:options="selectorList"
			@confirm="onConfirm($event,'selector')"
			ref="selector"></w-picker>
		</view>
	</view>
	
</template>

<script>
	import App from '@/common/js/app.js';
	import filtertab from '@/components/template/filtertab.vue';
	import workList from '@/components/template/workList.vue';
	import screening from '@/components/template/screening.vue';
	import loadMore from '@/components/template/loadmore.vue';
	import Loadlogo from '@/components/template/loadlogo.vue';
	import TabBars from '@/components/template/tabBar.vue';
	import PopManager from '@/components/template/PopManager';
	import wPicker from '@/components/w-picker/w-picker.vue';
	import vTabs from '@/components/v-tabs/v-tabs.vue';
	import nonemores from '@/components/template/nonemores.vue';
	export default{
		data(){
			return{
				cate_one:'',
				cate_two:'',
				title:'',
				check:false,
				isShow:false,
				resumeID:['','',''],
				inviteList:[],
				moreData:{},
				page:1,
				page_index:10,
				loadlogo:false,
				num:0,
				Areaid:'',
				ordersId:'',
				datas:{},
				isMore:true,
				total:1,
				pageId:'',
				job_type:null,
				time:'',
				visiblec:false,
				visible:false,
				site:'',
				selectorItem:'',
				selectorItemId:'',
				defaultProps:{"label":"title","value":"id"},
				selectorList:[],
				recruitment_type:'',
				userInfoId:'',
				userId:'',
				release_sid:'',
				AreaidAt:'',
				pagenum:false,
				tabBarSetList:[
					{name:'已投递简历',id:1},
					{name:'推荐简历',id:2}
				],
				sort:'',
				pid:'',
				checked:0
			}
		},
		components:{
			filtertab,
			workList,
			screening,
			loadMore,
			Loadlogo,
			TabBars,
			PopManager,
			wPicker,
			vTabs,
			nonemores
		},
		onLoad(e) {
			// debugger
			if(e.sid && e.sid != 'null'){
				this.release_sid = e.sid;
				this.recruitment_type = 2;
				// debugger
			}else{
				this.recruitment_type = 1;
			}
			this.userInfoId = uni.getStorageSync('userinfo').mid;
			if(e.id){
				this.pageId = e.id;
			}
			if(e.pid){
				this.pid = e.pid;
			}
			if(e.job_type){
				this.job_type = e.job_type
			};
			if(!this.pagenum){
				this.confirm()
			}
			// this.getResumeList(this.resumeID);
			// 初始化从地区选择器默认选择完毕发送请求，不从onload
		},
		onShow() {
			if(!this.pagenum){
				this.pagenum = true;
				return
			}
			this.confirm(false,true,1)
		},
		onReachBottom() {
			if(this.total < this.page) return
			this.isMore = false;
			this.page++;
			this.confirm(false,true)
		},
		methods:{
			vtabschange(e){
				console.log(e);
				this.checked = e;
				this.page = 1;
				this.confirm();
			},
			accomplish(item){
				App._post_form(
					`&p=recruit&do=interviewEnd`,
					{id:item.submit_id},
					res => {
						console.log(res)
						// debugger
						uni.showToast({
							title:res.message
						});
						this.confirm(false,true,1);
						this.loadlogo = true;
					},
					false,
					() => {
						
					}
				);
			},
			onConfirm(e){
				console.log(e);
				this.selectorItem = e.result;
				this.selectorItemId = e.value;
			},
			onConfirmdete(e) {
				console.log(e);
				this.time = e.result;
				// let date = new Date(e.value).getTime();
				// console.log(e, date);
			},
			invitationLetter(){
				if(!this.time){
					uni.showToast({
						icon:'none',
						title:'请选择面试时间'
					});
					return
				}else if(!this.site){
					uni.showToast({
						icon:'none',
						title:'请填写面试地址'
					});
					return
				}else if(!this.selectorItemId){
					uni.showToast({
						icon:'none',
						title:'请选择面试职位'
					});
					return
				}
				let data = {
					resume_id:this.userId,
					recruit_id:this.selectorItemId,
					interview_time:this.getDataTime(this.time),
					interview_area:this.site
				}
				App._post_form(
					`&p=recruit&do=inviteAnInterview`,
					data,
					res => {
						console.log(res)
						// debugger
						this.isShow = false;
						uni.showToast({
							title:res.message
						});
						this.confirm(false,true,1);
						this.loadlogo = true;
					},
					false,
					() => {
						
					}
				);
			},
			// 时间转时间戳
			getDataTime(timeValue) {
				let ontime;
				ontime = timeValue.replace(/-/g, '/');
				let date = new Date(ontime);
				let time = date.getTime() / 1000;
				return time;
			},
			closes(){
				this.isShow = false
				this.time = '';
				this.site = '';
			},
			interview(item){
				this.userId = item.id;
				let data = {
					status:4,
					recruitment_type:this.recruitment_type,
					release_mid:this.recruitment_type==1?this.userInfoId:'',
					release_sid:this.recruitment_type==2?this.release_sid:'',
					}
				App._post_form(
					`&p=recruit&do=homeList`,
					data,
					res => {
						console.log(res)
						this.selectorList = res.data;
						this.selectorList.map(item=>{
							if(item.id == this.pageId){
								this.selectorItem = item.title;
								this.selectorItemId = item.id;
								// debugger
							}
						})
						if(this.selectorList.length == 0){
							App.showError(
								`您尚无招聘中的岗位,是否前往添加?`,
								data => {
									if (data.confirm) {
										App.navigationTo({
											url: `pages/subPages2/hirePlatform/postRecruitment/postRecruitment`
										});
										return
									}
								},
								true
							);
						}else{
							this.isShow = true;
						}
						// this.selectorItem = res.data[0].title;
						this.loadlogo = true;
					},
					false,
					() => {
						
						
					}
				);
			},
			deleteWork(item){
				App.showError(
					`确认删除${item.name}的求职简历?`,
					data => {
						if (data.confirm) {
							App._post_form(
								`&p=recruit&do=deleteSubmit`,
								{id:item.submit_id},
								res => {
									console.log(res);
									this.inviteList.map((items,index)=>{
										if(items.id == item.id){
											this.inviteList.splice(index,1);
										}
									});
								},
								false,
								() => {
									// this.loadlogo = true;
								}
							);
						}
					},
					true
				);
			},
			lookResume(item){
				App.navigationTo({
					url: "pages/subPages2/hirePlatform/resume/resume?id=" + item.id + `&flag=${this.recruitment_type}&pageId=${this.pageId}&sid=${this.release_sid}`
				});
			},
			getcityWork(id){
				this.num = 1;
				if(this.num != 0){
					this.AreaidAt = id;
					this.confirm();
				}
				
			},
			confirm(datas,flag,page){
				console.log(datas);
				if(this.pageId && this.checked == 0){
					let data = {
						page:page || this.page,
						page_index:this.page_index,
					}
					App._post_form(
						`&p=recruit&do=submitResumeList&id=${this.pageId}`,
						data,
						res => {
							if(flag){
								if(page == 1){
									this.inviteList = [];
								}
								this.inviteList = this.inviteList.concat(res.data.list);
								let pages = page + 1;
								if(Number(pages) > Number(this.page)){
									return
								}else if(page){
									this.confirm(false,true,pages);
								}
							}else{
								this.inviteList = res.data.list;
							}
							this.isMore = true;
						},
						false,
						() => {
							this.loadlogo = true;
						}
					);
				}else{
					if(datas){
						this.datas = datas;
					}
					let indata = {
						position_id:this.pid,
						is_total:1,
						recruit_id:this.pageId,
						page:page || this.page,
						page_index:this.page_index,
					}
					let data = Object.assign(indata ,this.datas);
					App._post_form(
						`&p=recruit&do=resumeList`,
						data,
						res => {
							if(flag){
								if(page == 1){
									this.inviteList = [];
								}
								this.inviteList = this.inviteList.concat(res.data.list);
								let pages = page + 1;
								if(Number(pages) > Number(this.page)){
									return
								}else if(page){
									this.confirm(false,true,pages);
								}
							}else{
								this.inviteList = res.data.list;
							}
							this.inviteList.map(item=>{
								item.open = false;
							});
							this.total = res.data.total;
							this.check = false;
							this.isMore = true;
						},
						false,
						() => {
							this.loadlogo = true;
						}
					);
				}
				
			},
			checkeda(index,key){
				console.log(index,key);
				this.moreData[key].map(item=>{
					item.checked = false
				});
				this.moreData[key][index].checked = true;
				let obj = Object.assign({},this.moreData);
				console.log(obj);
				this.moreData = {...obj}
				this.loadlogo = !this.loadlogo;
				this.loadlogo = !this.loadlogo;
			},
			getmore(data){
				data.top.map((item,index)=>{
					if(index > 2){
						this.moreData[item.subscript] = data[item.subscript];
					}
				});
				this.moreData.top = data.top;
				for(let key in this.moreData){
						this.moreData[key].map((item,index)=>{
								item.checked = false;
								if(key == 'job_type' && item.val == this.job_type){
									item.checked = true;
								}
						})
				}
			},
			getResumeList(ids){
				this.resumeID = ids;
				if(this.num != 0){
					this.confirm();
					console.log('职位');
				}
				
				// App._post_form(
				// 	`&p=recruit&do=resumeList`,
				// 	{},
				// 	res => {
				// 		this.inviteList = res.data;
				// 		this.inviteList.map(item=>{
				// 			item.open = false;
				// 		})
				// 	},
				// 	false,
				// 	() => {
						
				// 	}
				// );
			},
			close(){
				console.log(this.moreData);
				for(let key in this.moreData){
						this.moreData[key].map((item,index)=>{
				
								item.checked = false;
						})
				}
				this.check = !this.check;
			},
			openclass(){
				
				this.check = !this.check;
			},
			clickcheck(){
				this.check = !this.check;
			},
			selectOrders(data){
				
				this.ordersId = data.val;
				if(this.num != 0){
					this.confirm();
					console.log('排序');
				}
				console.log(data)
				
			},
			selectAreaid(data){
				this.num = 1;
				console.log('地区');
				this.Areaid = data.id;
				this.confirm();
				console.log(data)
			},
			selectClassid(data){
				console.log(data)
			},
			selectClassTwoid(data){
				console.log(data)
			}
		}
	}
</script>

<style>
	page{
		background-color: #ffffff;
	}
</style>
<style lang="scss" scoped>
	.curriculumVitae{
		background-color: #FFFFFF;
		padding-bottom: 100upx;
	}
	.curriculum-list{
		// padding-bottom: 100upx;
		// height: 80vh;
		.curriculum-item{
			padding: 0 30upx 30upx;
			.item-personal{
				padding-top: 30upx;
				border-top: 1upx solid #EEEEEE;
				.personal-img{
					position: relative;
					.img{
						width: 100upx;
						height: 100upx;
						border-radius: 50%;
					}
					.gender {
						background-color: #ff838e;
						padding: 8upx;
						border-radius: 50%;
						width: 16upx;
						height: 16upx;
						position: absolute;
						bottom: 8upx;
						right: 0;
						z-index: 9;
						uni-image {
							width: 16upx;
							height: 16upx;
							vertical-align: top;
						}
					}
				}
				.personal-data{
					padding-left: 30upx;
					.data-name{
						font-size: 32upx;
						height: 32upx;
						line-height: 26upx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #333333;
						// vertical-align: bottom;
						margin-bottom: 30upx;
					}
					.data-item{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #999999;
						// vertical-align: text-top;
					}
				}
				.data-salary{
					font-size: 32upx;
					font-family: DINPro;
					font-weight: 500;
					color: #FF4444;
					float: right;
				}
			}
			.item-tags{
				.tags-box{
					padding:  30upx 0 10upx 64upx;
					.tags-item{
						background: #F4F4F4;
						display: inline-block;
						border-radius: 4upx;
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #666666;
						padding: 10upx 20upx;
						margin-bottom: 20upx;
						margin-right: 20upx;
					}
				}
			}
			.date-and-button{
				.date{
					flex: 0.5;
					font-size: 28upx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #999999;
					height: 68upx;
					line-height: 68upx;
				}
				.button{
					flex: 0.5;
					.delete{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #3388FF;
						border: 1px solid #3388FF;
						border-radius: 4upx;
						padding: 15upx 25upx;
					}
					.invitation{
						font-size: 26upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #FFFFFF;
						background-color: #3388FF;
						border: 1px solid #3388FF;
						border-radius: 4upx;
						padding: 15upx 25upx;
						margin-left: 20upx;
					}
				}
			}
		}
	}
	.invitePop{
		width: 70vw;
		border-radius: 20upx;
		padding: 30upx;
		position: relative;
		.invitePop-title{
			font-size: 26upx;
		}
		.abBox{
			font-size: 30upx;
			color: #FFFFFF;
			padding: 10upx 50upx;
			background-color: #FF4444;
			border-radius: 60upx;
			display: inline-block;
			position: absolute;
			left: 50%;
			bottom: -40%;
			transform: translate(-50%);
		}
	}
</style>
