<template>
	<view class="recruitmentEnter">
		<loadlogo v-if="!loadlogo" />
		<view style="padding: 0upx 0;height: 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>
		<view class="inviteList">
			<view class="invite-item" v-for="(item, index) in inviteList">
				<view  style="padding-top: 40upx;border-top: 1upx solid #EEEEEE;">
					<view class="item-name">{{ item.title }}</view>
					<view class="item-tag" v-if="item.is_top == 1">顶</view>
					<view class="item-salary">{{ item.salary }}</view>
				</view>
				<view class="invite-tags dis-flex">
					<view class="tags-item">
						<view class="dis-il-block items" v-for="(items, indexs) in item.welfare_list" :key="indexs">{{ items }}</view>
					</view>
					<view class="tags-region">{{item.status_text}}</view>
				</view>
				<view class="button-set dis-flex">
					<view class="flex-box set-data">{{ item.release_time }}</view>
					<view class="flex-box set-compile t-c" @click="compile(item, index)" v-if="0 && (item.status == 3 || item.status == 5)">
						<!-- <text class="iconfont icon-bianji" style="font-size: 26upx;color: #333333;"></text> -->
						<text>编辑</text>
					</view>
					<view class="flex-box set-compile t-c" v-if="item.status == 4 && StickyList.length > 0">
						<!-- <text class="iconfont icon-shanchu" style="font-size: 26upx;color: #333333;"></text> -->
						<view  v-if="item.is_top == 0">
							<picker @change="StickyChange($event,item)" :value="StickyIndex" range-key="title" :range="StickyList">
								<view class="uni-input">
									<text>置顶</text>
								</view>
							</picker>
						</view>
						<view v-else>
							<text>置顶中</text>
						</view>
					</view>
					<view class="flex-box set-compile t-c" @click="over(item,index,4)" v-if="item.status == 5 && 0">
						<!-- <text class="iconfont icon-shanchu" style="font-size: 26upx;color: #333333;"></text> -->
						<text>重新打开</text>
					</view>
					<view class="flex-box set-compile t-c" @click="over(item,index,5)" v-if="item.status == 4">
						<!-- <text class="iconfont icon-shanchu" style="font-size: 26upx;color: #333333;"></text> -->
						<text>招聘结束</text>
					</view>
					<view class="flex-box set-compile t-c" @click="deleteWred(item, index)">
						<!-- <text class="iconfont icon-shanchu" style="font-size: 26upx;color: #333333;"></text> -->
						<text>删除</text>
					</view>
					<view class="flex-box set-compile t-r" v-if="item.status == '1'" @click="payment(item, index)">
						<!-- <text class="iconfont icon-shanchu" style="font-size: 26upx;color: #333333;"></text> -->
						<view class="btmn">
							去付款
						</view>
					</view>
					<view class="flex-box set-compile t-r" @click="resumeList(item)" v-if="item.status == 4">
						<text class="iconfont icon-form_fill_light" style="font-size: 26upx;color: #3388FF;"></text>
						<text style="color: #3388FF;">简历列表</text>
					</view>
				</view>
				<view class="c-ff4444 f-24" style="padding-top: 20upx;" v-if="item.status == 3">
					驳回原因：{{item.reason}}
				</view>
			</view>
		</view>
		<load-more :isMore="isMore" :bgc="'#ffffff'"></load-more>
		<view  v-if="loadlogo">
			<screening :check="check" :num="num" @close="close" @checkeda="checkeda" @confirm="confirm" v-bind:moreData.sync="moreData"></screening>
		</view>
		<view class="addBtn" @click="openAdd">招聘发布</view>
		<!-- <TabBars :tabBarAct="0" pageType="15"></TabBars> -->
		<far-bottom></far-bottom>
	</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';
export default {
	data() {
		return {
			cate_one: '',
			cate_two: '',
			title: '',
			check: false,
			resumeID: ['', '', ''],
			inviteList: [],
			moreData: {},
			page: 1,
			page_index: 10,
			loadlogo: false,
			num: 0,
			Areaid: '',
			ordersId: '',
			datas: {},
			isMore: true,
			total: 1,
			sid: null,
			userinfo: {},
			StickyList: [],
			StickyIndex:0
			
		};
	},
	components: {
		filtertab,
		workList,
		screening,
		loadMore,
		Loadlogo,
		TabBars
	},
	onLoad(e) {
		if (e.sid) {
			this.sid = e.sid;
		}
		this.userinfo = uni.getStorageSync('userinfo');
		this.getStickyList();
		// this.getResumeList(this.resumeID);
		// 初始化从地区选择器默认选择完毕发送请求，不从onload
	},
	onShow() {
		this.confirm(null, false,1);
	},
	onReachBottom() {
		if (this.total < this.page) return; //上拉加载
		this.isMore = false;
		this.page++;
		this.confirm(false, true);
	},
	methods: {
		over(item,index,type){  //招聘状态开关
			
			let datas = {
				id:item.id,
				status:type
			}
			App.showError(
				`是否${type == 5?'结束该岗位招聘':'重新打开该岗位招聘'}?`,
				data => {
					if (data.confirm) {
						App._post_form(
							`&p=recruit&do=recruitChangeStatus`,
							datas,
							res => {
								console.log(res);
								uni.showToast({
									title:res.message
								})
								this.confirm(null, false,1);
							},
							false,
							() => {}
						);
					}
				},
				true
			);
			
		},
		StickyChange(e,item){
			let data = {
				type:'post',
				recruit_id:item.id,
				top_day:this.StickyList[e.detail.value].day,
				top_price:this.StickyList[e.detail.value].price
			}
			App._post_form(
				`&p=recruit&do=recruitTop`,
				data,
				res => {
					console.log(res);
					App.navigationTo({
						url:'pages/mainPages/payment/payment?orderid='+res.data.orderid+`&plugin=${res.data.type}`
					})
				},
				false,
				() => {}
			);
		},
		getStickyList() {
			App._post_form(
				`&p=recruit&do=recruitTop`,
				{},
				res => {
					this.StickyList = res.data;
					this.StickyList.map(item => {
						item.title = `${item.day}天/${item.price}元`;
					});
				},
				false,
				() => {}
			);
		},
		openAdd() {
			App.navigationTo({
				url: 'pages/subPages2/hirePlatform/postRecruitment/postRecruitment' + '?sid=' + this.sid
			});
		},
		resumeList(item) {
			App.navigationTo({
				url: 'pages/subPages2/hirePlatform/curriculumVitae/curriculumVitae?id=' + item.id + '&sid=' + this.sid + '&pid=' + item.position_id
			});
		},
		compile(item, index) {
			App.navigationTo({
				url: 'pages/subPages2/hirePlatform/postRecruitment/postRecruitment?id=' + item.id 
			});
		},
		Sticky(item, index) {},
		payment(item, index){
			if(item.status == '1'){
				App.navigationTo({
					url:'pages/mainPages/payment/payment?orderid='+item.order_id+`&plugin=${item.order_plugin}`
				})
			}
		},
		deleteWred(item, index) {
			App.showError(
				`确定删除该职位?`,
				data => {
					if (data.confirm) {
						App._post_form(
							`&p=recruit&do=deleteRecruit&id=${item.id}`,
							{},
							res => {
								this.confirm(null, false, 1);
							},
							false,
							() => {}
						);
					}
				},
				true
			);
		},
		getcityWork(id) {
			this.num = 1;
			if (this.num != 0) {
				// this.AreaidAt = id;
				this.confirm();
			}
		},
		confirm(datas, flag, page) {
			// debugger
			console.log(datas);
			if (datas) {
				this.datas = datas;
			}
			let indata = {
				industry_pid: this.resumeID[0],
				industry_id: this.resumeID[1],
				position_id: this.resumeID[2],
				sort: this.ordersId,
				recruitment_type: this.sid ? 2 : 1,
				release_sid: this.sid ? this.sid : '',
				release_mid: this.sid ? '' : this.userinfo.mid,
				// area_id:this.Areaid,
				is_total: 1,
				page: page || this.page,
				page_index: this.page_index,
				is_private:1
			};
			let data = Object.assign(indata, this.datas);
			App._post_form(
				`&p=recruit&do=homeList`,
				data,
				res => {
					if (flag) {
						this.inviteList = this.inviteList.concat(res.data.list);
					} else {
						this.inviteList = res.data.list;
					}
					this.inviteList.map(item => {
						item.open = false;
					});
					console.log(this.inviteList, res.data.list);
					this.total = res.data.total;
					this.check = false;
					this.isMore = true;
					this.loadlogo = true;
					let pageis = page;
					if (pageis) {
						if (pageis > this.page) return;
						pageis++;
						this.confirm(null, true, pageis);
					}
				},
				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;
				});
			}
		},
		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(flag = false) {
			console.log(flag);
			if (!flag) {
				for (let key in this.moreData) {
					this.moreData[key].map((item, index) => {
						item.checked = false;
					});
				}
			} else {
				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>
.inviteList {
	padding-bottom: 240upx;
	.invite-item {
		padding: 0upx 30upx 40upx;
		.item-name {
			display: inline-block;
			font-size: 32upx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
		}
		.item-tag {
			display: inline-block;
			background: #f1c426;
			border-radius: 4upx;
			font-size: 22upx;
			padding: 2upx 6upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			margin-left: 20upx;
		}
		.item-salary {
			display: inline-block;
			font-size: 32upx;
			font-family: DINPro;
			font-weight: 500;
			color: #ff4444;
			float: right;
		}
	}
	.invite-tags {
		padding-top: 30upx;
		.tags-item {
			flex: 0.85;
			height: 70upx;
			overflow: hidden;
			.items {
				font-size: 24upx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #666666;
				background: #f4f4f4;
				border-radius: 4upx;
				padding: 10upx 20upx;
				display: inline-block;
				margin: 0 20upx 20upx 0;
			}
		}
		.tags-region {
			flex: 0.15;
			font-size: 26upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
			text-align: right;
			line-height: 52upx;
		}
	}
	.button-set {
		padding-top: 10upx;
		.set-data {
			font-size: 26upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
		}
		.set-compile {
			font-size: 26upx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
			position: relative;
			.btmn{
				position: absolute;
				right: 0;
				top: -16upx;
				width: 150upx;
				height: 60upx;
				line-height: 60upx;
				border-radius: 60upx;
				background-color: #FF4444;
				color: #FFFFFF;
				font-size: 28upx;
				text-align: center;
			}
		}
	}
}
.addBtn {
	padding: 15upx 50upx;
	background-color: #3388ff;
	color: #ffffff;
	font-size: 30upx;
	border-radius: 60upx;
	position: fixed;
	bottom: 200upx;
	left: 50%;
	transform: translateX(-50%);
}
</style>
