<template>
	<view>
		<view class="filterbg fixedtop">
			<view class="flex justify-between solids-bottom padding bg-white">
				<view class="text-bold">推荐</view>
				<view class="flex justify-end">
					<view class="cu-tag radius bg-green" data-filterbox="jobintention" @tap="showFilter">{{jobintentionlist.title}}</view>
					<view class="cu-tag radius bg-green" data-filterbox="cate" @tap="showFilter">{{catelist.title}}</view>
				</view>
			</view>
		 
			<view class="filtercon" v-if="filterbox!==null" @click="hideFilter()">
				<view class="padding bg-white" v-if="filterbox=='jobintention'" @click.stop>
					<block v-for="(item,index) in jobintentionlist.data" :key="index">
						<button class="cu-btn margin-lr-xs margin-tb-xs" @click="checkJobintention(item.title,item.value)">{{item.title}}</button>
					</block>
				</view>
				<view class="padding bg-white" v-if="filterbox=='cate'" @click.stop>
					<block v-for="(item,index) in catelist.data" :key="index">
						<button class="cu-btn margin-lr-xs margin-tb-xs" @click="checkCate(item.title,item.value)">{{item.title}}</button>
					</block>
				</view>
				
			</view>
		</view>
		
		<view class="" style="position: relative;margin-top: 100rpx;">
			<block v-for="(item,index) in plist" :key="index">
				<view class="cu-card dynamic no-card echo-comjobs-item radius">
					<view class="cu-item shadow padding-top padding-lr" @tap="goDetail(item.id)">
						<view class="flex">
							<view class="flex-sub flex-direction align-center padding-right">
								<view class="text-bold text-lg text-cut echo-comjobs-item-title">{{item.nickname}}</view>
								<view class="text-gray text-df padding-top-xs">
									<text class="padding-right-xs">{{item.age?item.age+'岁':'年龄未知'}} ·</text>
									<text class="padding-right-xs">{{item.education_text || '学历未知'}} ·</text>
									<text class="padding-right-xs">{{item.worker_text || '经验未知'}} ·</text>
									<text>{{item.jobintention_text || '求职区域未知'}}</text>
								</view>
							</view>
							<view class="round" style="width: 110rpx;position: relative;">
								<image class="round" :src="item.avatar" mode="aspectFit" style="width: 110rpx;height: 110rpx;"></image>
								<text class="round cuIcon-male bg-blue text-sm genderIcon" v-if="item.gender == 1"></text>
								<text class="round cuIcon-female bg-pink text-sm genderIcon" v-else-if="item.gender == 2"></text>
							</view>
						</view>
						
						<!--  <view class="padding-tb-xs text-cut">
							<view v-for="(titem,tindex) in item.com_cate" :key="tindex" class="cu-tag light bg-blue lg echo-tags-item">{{titem}}</view>
						</view>
						<view class="padding-tb-xs text-cut">
							<view v-for="(eitem,eindex) in item.emp_time" :key="eindex" class="cu-tag light bg-red lg echo-tags-item">{{eitem}}</view>
						</view> -->
						<view class="text-cut text-sm flex justify-between align-center padding-bottom-sm solid-bottom">
							<view class="basis-xl text-sm text-cut" style="color: #bfbfbf;">
							</view>
							<view class="basis-xs text-cut text-right text-sm">
								浏览量:{{item.volume}}
							</view>
						</view>
					</view>
				</view>
			</block>
			<uni-load-more :status="pstatus"></uni-load-more>
		</view>
		
		<view class="padding-sm"></view>
		<view class="padding-xl"></view>
		<view class="cu-bar tabbar bg-white foot">
			<view class="action text-gray" @tap="goNavPage('/pages/worker/worker')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/windex.png"></image>
				</view>
				首页
			</view>
			<view class="action text-gray" @tap="goNavPage('/pages/demand/demand')" v-if="workerinfo.wtype==2">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/wdemand.png"></image>
				</view>
				抢单大厅
			</view>
			<!-- #ifndef MP-WEIXIN -->
			<view class="action text-gray videoimg" @tap="goNavPage('/pages/video/video')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/video.png"></image>
				</view>
				录视频
			</view>
			<!-- #endif -->
			<view class="action text-red" @tap="goNavPage('/pages/resume/resume')">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/resumeSelected.png"></image>
				</view>
				简历
			</view>
			<view class="action text-gray" @tap="goNavPage('/pages/supply/supply')" v-if="workerinfo.wtype==2">
				<view class="cuIcon-cu-image">
					<image src="../../static/tabbar/wsupply.png"></image>
				</view>
				共享用工
			</view>
		</view>
	</view>
</template>

<script>
	import slFilter from '@/components/sl-filter/sl-filter.vue';
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			slFilter,
			uniLoadMore
		},
		data() {
			return {
				filterbox: null,
				jobintentionlist: {
					title: "求职意向",
					value: 0,
					data: []
				},
				catelist: {
					title: "岗位",
					value: 0,
					data: []
				},
				workerinfo: {},
				
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: [],
				sex: ['未知','男','女'],
			};
		},
		onLoad: function(option){
			_this = this;
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			_this.$req.ajax({
				path: "resume/searchItem",
			}).then((data) => {
				_this.catelist.data = data.catelist;
				_this.jobintentionlist.data = data.jobintentionlist;
				_this.getMore();
			}).catch((err) => {
				uni.showModal({
					title: '信息提示',
					content: err,
					showCancel: false
				});
			});
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		onShareAppMessage: function(res) {
			return {
				title: "企业招聘",
				path: "/pages/comjobs/comjobs"
		    }
		},
		methods: {
			showFilter: function(e) {
				var nowfilterbox = e.currentTarget.dataset.filterbox;
				if (_this.filterbox == nowfilterbox){
					_this.filterbox = null;
				}else{
					_this.filterbox = nowfilterbox;
				}
				uni.pageScrollTo({
				    scrollTop: 0,
				    duration: 300
				});
			},
			hideFilter: function(e) {
				_this.filterbox = null;
			},
			checkJobintention: function(title,value) {
				_this.jobintentionlist.title = title;
				_this.jobintentionlist.value = value;
				_this.filterbox = null;
				_this.pageRefresh();
			},
			checkCate: function(title,value) {
				_this.catelist.title = title;
				_this.catelist.value = value;
				_this.filterbox = null;
				_this.pageRefresh();
			},
			
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			getMore: function() {
				_this.$req.ajax({
					path: "resume/listResume",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						cateid: _this.catelist.value,
						jobintention: _this.jobintentionlist.value,
					}
				}).then((data) => {
					_this.pstatus = data.pstatus;
					_this.plist = _this.plist.concat(data.plist);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			goDetail: function(id) {
				uni.navigateTo({
					url: '/pages/resume/detail?id=' + id
				});
			},
			result: function(e) {
				_this.cateid = e.cateid;
				_this.jobintention = e.jobintention;
				_this.province = e.province;
				_this.pageRefresh();
			},
			
			goNavPage: function(pageurl) {
				uni.redirectTo({
					url: pageurl
				});
			}
		}
	}
</script>

<style>
	.fixedtop {
		width: 100%;
		height: auto;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 999;
	}
</style>
