<template>
	<view class="page">
		<view class="main">
			<view class="top">
				<view @click="toPostTalent()">
					<image src="../../static/nav/talent1.png" mode="widthFix"></image>
				</view>
				<view @click="toRecommend()">
					<image src="../../static/nav/talent2.png" mode="widthFix"></image>
				</view>
			</view>
			<!-- 搜索 -->
			<view class="search-head">
				<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)" :key="index">
							<view class="item">
								<view class="title">
									<text class="two-omit">{{item.title}}</text>
								</view>
								<view class="find-collect">
									<view class="find">
										<text>{{item.subTitle}}</text>
									</view>
								</view>
								<view>
									<view class="find-time">{{item.createTime}}</view>
								</view>
							</view>
							<view class="thumb">
								<view class="thumb-icon">{{item.post}}</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:''
			}
		},
		onShow() {
			this.getUser()
			this.getTalentList()
			// #ifdef APP-PLUS
			this.getTalentList()
			// #endif
		},
		methods: {
			// 获取用户信息
			getUser() {
				if (uni.getStorageSync('user')) {
					// this.userCode = uni.getStorageSync('user').data.user.userInfo
					// this.userInfo = this.userCode.userAccount
					// this.userInfo = '123456'
					console.log('用户已登录！')
				} else {
					uni.showToast({
						title: '请登录',
						icon: 'none'
					})
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/index'
						})
					})
				}
			},
			// 获取人才列表
			getTalentList() {
				this.API.getTalentList().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.createTime)
							}
						})
						if(this.talentList.length > 0){
							this.show = true
						}
					}
					console.log(this.talentList)
				})
			},
			onArticle(item) {
				uni.navigateTo({
					url: `/pages/talentDetail/talentDetail?data=${JSON.stringify(item)}`
				})
			},
			// 跳转到发布人才招聘
			toPostTalent(){
				uni.navigateTo({
					url:'/pages/postTalent/postTalent'
				})
			},
			// 搜索功能
			searchEvt(){
				this.API.getTalentList({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)
							}
						})
						if(this.talentList.length > 0){
							this.show = true
						}
					}
					console.log(this.talentList)
				})
			},
			// 跳转到人才推介列表
			toRecommend(){
				uni.navigateTo({
					url:`/pages/recommend/recommend`
				})
			}
		}
	};
</script>

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