<template>
	<view class="page">
		<view class="main">
			<view class="top">
				<view class="postCon" v-show="isAdmin"
					@click="toPostCon()">
					人才发布
				</view>
			</view>
			<!-- 搜索 -->
			<view class="search-head" style="margin-bottom: 40rpx;">
				<view class="search">
					<image src="../../static/fdj1.png"></image>
					<text></text>
					<input type="text" v-model="keyword" placeholder="搜索关键词" />
				</view>
				<view class="btn" @click="searchEvt">
					<text>搜索</text>
				</view>
			</view>
			<!-- <view class="titleall-box">
				<view class="talen-title"><text class="talen-line"></text>热门职位</view>
				<view class="title-screen">
					<scroll-view scroll-x="true" class="scrollview-box">
						<view class="title-screen-box">
							<view>德阳<image src="../../static/down.png"></image>
							</view>
						</view>
						<view class="title-screen-box">
							<view>发布时间<image src="../../static/down.png"></image>
							</view>
						</view>
						<view class="title-screen-box">
							<view>工作类型<image src="../../static/down.png"></image>
							</view>
						</view>
					</scroll-view>
				</view>
			</view> -->
			<!-- @down="downCallback"
			@up="upCallback"
			:down="downOption"
			:up="upOption" 
			:top="0"
			-->
			<view class="" v-if="!show" style="padding: 30rpx; font-size: 24rpx;">
				暂无数据
			</view>
			<view v-else>
				<view class="article-data">
					<view class="article-list">
						<view class="list" v-for="(item,index) in talentList" @click="onArticle(item.id)" :key="index">
							<view class="item">
								<view class="title">
									<text class="two-omit">{{item.name}}</text>
								</view>
								<view class="find-collect">
									<view class="find">
										<text>{{item.gender}},{{item.age}},{{item.politicalOutlook}},{{item.education}}</text>
									</view>
								</view>
								<view>
									<view class="find-time">{{item.createTime}}</view>
								</view>
							</view>
							<view class="thumb">
								<view class="thumb-icon">{{item.graduationInstitution}}</view>
								<!-- <view>3000-5000/月</view> -->
							</view>
						</view>
					</view>
				</view>
			</view>

			
		</view>
	</view>
</template>

<script>
	import request from '@/utils/request.js'
	import utils from '../../service/utils';
	export default {
		data() {
			return {
				talentList: [],
				show:false,
				keyword:'',
				userCode:{},
				isAdmin:false
			}
		},
		onShow() {
			this.getUser()
			this.getTalentList()
			// #ifdef APP-PLUS
			this.getTalentList()
			// #endif
		},
		methods: {
			// 获取用户信息判断是否有人才推荐的ID,权限判断authority = 529868097192985861
			getUser() {
				if (uni.getStorageSync('user')) {
					let userCode = uni.getStorageSync("user")
					console.log(userCode)
					let authorityID = userCode.permissionList
					this.isAdmin = authorityID.some(it => it.modelId === '529868097192985861')
					console.log('是否有人才推介权限',this.isAdmin)
					console.log('用户已登录！')
				} 
				// else {
				// 	uni.showToast({
				// 		title: '请登录',
				// 		icon: 'none'
				// 	})
				// 	setTimeout(() => {
				// 		uni.reLaunch({
				// 			url: '/pages/login/index'
				// 		})
				// 	})
				// }
			},
			// 获取人才列表
			getTalentList() {
				this.API.getRecommendList().then(res => {
					if(res.code === 600){
						// console.log(res)
						uni.showToast({
							icon:'error',
							title:'登录过期，请重新登录'
						})
					}
					if (res.code === 200) {
						this.talentList = res.data.list.map(it => {
							return {
								...it,
								createTime: utils.formatTime(it.creatorTime)
							}
						})
						if(this.talentList.length > 0){
							this.show = true
						}
					}
					console.log(this.talentList)
				})
			},
			onArticle(item) {
				uni.navigateTo({
					url: `/pages/recommend/recommendInfo/recommendInfo?data=${JSON.stringify(item)}`
				})
			},
			// 跳转到发布人才招聘
			toPostTalent(){
				uni.navigateTo({
					url:'/pages/postTalent/postTalent'
				})
			},
			// 搜索功能
			searchEvt(){
				this.API.getRecommendList({keyword:this.keyword}).then(res => {
					console.log(res)
					if (res.code === 200) {
						this.talentList = res.data.list.map(it => {
							return {
								...it,
								// createTime: utils.formatTime(it.createTime)
								createTime:utils.formatTime(it.creatorTime)
							}
						})
						if(this.talentList.length > 0){
							this.show = true
						}
					}
					console.log(this.talentList)
				})
			},
			// 跳转到人才发布页面
			// toPost(item){
			// 	uni.navigateTo({
			// 		url:`/pages/recommend/postRecommend/postRecommend?data=${JSON.stringify(item)}`
			// 	})
				
			// },
			toPostCon(item){
				uni.navigateTo({
					url:`/pages/recommend/postRecommend/postRecommend`
				})
			},
		}
	};
</script>

<style scoped lang="scss">
	@import 'talent.scss';
</style>