<template>
	<view class="serchWork">
		<!-- 插件为招聘时进入简历搜索页面 -->
		<view class="input-title dis-flex">
			<view class="input-seach">
				<input style="font-size: 28upx;" @confirm="seacha" v-model="seachContent" placeholder="请搜索职位关键词" type="text" value="" />
			</view>
			<view class="cancel" @click="goOut">
				取消
			</view>
		</view>
		<view class="seach-history" v-if="inviteListShow">
			<view class="dis-flex">
				<view class="flex-box f-36 t-l f-w">
					历史搜索
				</view>
				<view class="flex-box f-28 t-r col-9 iconfont icon-delete" @click="deleteSeach">
					
				</view>
			</view>
			<view class="history-content" v-if="seachList.length > 0">
				<view class="history-item" v-for="(item,index) in seachList" @click="seachText(item)">
					{{item}}
				</view>
			</view>
			<view class="p-top-20 f-26 col-9" v-else>
				暂无搜索记录
			</view>
		</view>
		<view v-else>
			<work-List :flag="false" :inviteList="inviteList"></work-List>
			<load-more :isMore="isMore" :bgc="'#ffffff'"></load-more>
		</view>
		<far-bottom></far-bottom>
	</view>
</template>

<script>
	import App from '@/common/js/app.js';
	import workList from '@/components/template/workList.vue';
	import loadMore from '@/components/template/loadmore.vue';
	import Loadlogo from '@/components/template/loadlogo.vue';
	export default{
		data(){
			return{
				inviteList:[],
				isMore:true,
				loadlogo:false,
				page:1,
				pageIndex:10,
				seachContent:'',
				total:1,
				inviteListShow:true,
				seachList:[]
			}
		},
		onLoad() {
			let seachList = uni.getStorageSync('workSeachList');
			if(seachList){
				this.seachList = seachList;
			}
		},
		components:{
			workList,
			loadMore,
			Loadlogo
		},
		onReachBottom() {
			if(this.total == this.page) return
			this.isMore = false;
			this.page++;
			this.seach(true)
		},
		methods:{
			deleteSeach(){
				this.seachList = [];
				uni.clearStorageSync('workSeachList')
			},
			seachText(item){
				this.seachContent = item;
			},
			goOut(){
				uni.navigateBack({
					delta:1
				})
			},
			seacha(){
				this.page = 1;
				this.seach();
			},
			seach(flag){
				let _this = this;
				let data = {
					page:this.page,
					pageIndex:this.pageIndex,
					is_total:1,
					title:this.seachContent
				}
				App._post_form(
					`&p=recruit&do=homeList`,
					data,
					res => {
						if(flag == true){
							this.inviteList = this.inviteList.concat(res.data.list);
						}else{
							this.inviteList = res.data.list;
						}
						if(_this.seachContent && _this.seachContent != ' '){
							this.seachList.unshift(this.seachContent);
							this.seachList = [...new Set(this.seachList)];
							uni.setStorageSync('workSeachList',this.seachList);
						}
						this.total = res.data.total;
						this.isMore = true;
						this.inviteListShow = false;
						this.loadlogo = true;
					},
					false,
					() => {
						this.loadlogo = true;
					}
				);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.serchWork{
		.input-title{
			padding: 30upx;
			.input-seach{
				border-radius: 60upx;
				background-color: #EEEEEE;
				padding: 10upx 40upx;
				flex: 0.85;
			}
			.cancel{
				font-size: 32upx;
				flex: 0.15;
				line-height: 58upx;
				text-align: right;
				color: #666666;
			}
		}
		.seach-history{
			padding: 30upx;
			.history-content{
				padding: 30upx 0;
				.history-item{
					background-color: #EEEEEE;
					padding: 8upx 20upx;
					border-radius: 5upx;
					display: inline-block;
					font-size: 22upx;
					margin-right: 20upx;
					margin-bottom: 20upx;
				}
			}
		}
	}
</style>
<style>
	page{
		background-color: #FFFFFF;
	}
</style>
