<template>
	<view class="recruitmentList">
		<loadlogo v-if="!loadlogo" />
		<view style="padding: 20upx 0;" class="dis-flex">
			<view  style="flex: 0.8;">
				<filtertab 
				:requestType="'7'" 
				:isPageScroll="'1'" 
				@selectAreaid="selectAreaid" 
				@selectClassid="selectClassid" 
				@getmore="getmore" 
				@getResumeList="getResumeList"
				@selectClassTwoid="selectClassTwoid" 
				@selectOrders="selectOrders" 
				@getcityWork="getcityWork"
				:cate_one="cate_one" 
				:cate_two="cate_two"></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  v-if="loadlogo">
			<!-- <tabs :cc_id="cc_id" :pageType="job_type" @changeChildType="changeChildType"></tabs> -->
			<view style="padding: 0px 30upx;">
				<tabs-c :cc_id="cc_id" :pageType="job_type" @changeChildType="changeChildType"></tabs-c>
			</view>
			<block v-if="job_type!=2">
				<work-List :flag="false" :inviteList="inviteList"></work-List>
			</block>
			<block v-else>
				<part-time-job :flag="false" :inviteList="inviteList"></part-time-job>
			</block>
			<view v-if="!isMore">
				 <load-more :isMore="isMore" :bgc="'#ffffff'"></load-more>
			</view>
			<nonemores v-if="isMore && inviteList.length == 0"></nonemores>
		</view>
		
		<view  >
		 	<screening :check="check" :num="num" @close="close" @checkeda="checkeda" @confirm="confirm" v-bind:moreData.sync="moreData"></screening>
		</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 partTimeJob from '@/components/template/partTimeJob.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 nonemores from '@/components/template/nonemores.vue';
	import tabs from '@/components/template/tabs/tabs.vue';
	import tabsC from '@/components/template/tabs/tabs-copy.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,
				job_type:null,
				cc_id: 0,
				cc_child_id: 0,
				AreaidAt:'',
				pagenum:1
			}
		},
		components:{
			filtertab,
			workList,
			partTimeJob,
			screening,
			loadMore,
			Loadlogo,
			TabBars,
			nonemores,
			tabs,
			tabsC
		},
		onLoad(e) {
			console.log(e, e.job_type, 'p---------')
			if(e.job_type){
				this.job_type = e.job_type;
			};
			if(e.cc_id){
				this.cc_id = e.cc_id;
			};
			this.isMore = false;
			if(this.num != 0) return
			this.pagenum = 4;
			this.confirm();
			// this.getResumeList(this.resumeID); 
			// 初始化从地区选择器默认选择完毕发送请求，不从onload
			// console.log(e.type, '--------');
			let title;
			switch(e.job_type){
				case '1':
				title = '就业招聘';
				break;
				// case '2':
				// title = '学生兼职';
				// break;
				// case '3':
				// title = '实习实践';
				// break;
				case '2,3':
				title = '实习兼职';
				break;
			}
			setTimeout(()=>{
				uni.setNavigationBarTitle({
					title:title
				})
			}, 500)
		},
		onShow() {
			if(this.num != 1) return
			this.pagenum = 4;
			this.confirm();
			console.log(this.num)
			// this.confirm();
		},
		onReachBottom() {
			if(this.total == this.page) return
			if(this.total===0) return;
			// console.log(this.total, this.page);
			this.isMore = false;
			this.page++;
			this.confirm(false,true)
		},
		methods:{
			confirm(datas,flag){
				if(datas != false){
					this.page = 1;
					this.total = 1;//加
				}
				if(this.pagenum < 4){
					this.pagenum++;
					this.loadlogo = true;
					return
				}
				// console.log(JSON.stringify(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,
					area_id:this.AreaidAt,
					is_total:1,
					page:this.page,
					page_index:this.page_index,
					job_type: this.job_type,
					cc_id: this.cc_child_id//子分类id，和大分类id重名注意
				}
				if(!datas || JSON.stringify(datas) == '{}'){
					indata.job_type = this.job_type;
				}else{
					this.page = 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;
					},
					false,
					() => {
						this.loadlogo = true;
					}
				);
			},
			checkeda(index,key,flag){
				console.log(index,key);
				this.moreData[key].map(item=>{
					item.checked = false
				});
				this.moreData[key][index].checked = flag;
				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;
								}
						})
				}
			},
			getcityWork(id){
				this.num = 1;
				if(this.num != 0){
					this.AreaidAt = id;
					this.confirm();
				}
				
			},
			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){
				console.log(this.moreData);
				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)
			},
			changeChildType(e){
				this.cc_child_id = e;
				this.confirm();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.recruitmentList{
		padding-bottom: 150upx;
	}
</style>
