<template>
	<view>
		<view class="search-box">
			<view class="search">
				<view class="iconfont icon-fadajing"></view>
				<input type="text" placeholder="热门搜索：成都、高薪" v-model="query.keyword" />
				<view class="search-btn" @click="Searchtbrecruit()">搜索</view>
			</view>
		</view>
		<view class="title-screen">
			<view class="title-screen-box">发布时间<image src="../../static/down.png"></image>
			</view>
		</view>
		<!-- 文章数据 -->
		<mescroll-body ref="mescrollRef" @down="downCallback" @up="upCallback" :isUpAutoLoad="true" :down="downOption"
			:up="upOption" :top="0">
			<view class="record-list">
				<view class="list" @click="JobsDetails(item.id)" v-for="item in tbrecruitList">
					<view class="title-date">
						<view class="title">
							<text class="two-omit">{{item.companyName}}-{{item.jop}}</text>
						</view>
						<view class="date">
							<text class="one-omit">{{item.introduce}}</text>
						</view>
						<view>
							<view class="yellow-btn">{{getDifferTime(item.lastModifyTime)}}</view>
						</view>
					</view>
					<view class="integral">
						<text class="integral-btn">{{item.jopName}}</text>
						<view class="integral-num">{{item.pay}}</view>
					</view>
				</view>

			</view>

		</mescroll-body>
		<!-- tabbar -->
		<TabBar :tabBarShow="0"></TabBar>
	</view>
</template>

<script>
	import BASE_URL from '@/common/config.js'
	import TabBar from '../../components/TabBar/TabBar.vue';
	import customHead from "@/components/xy-customhead/xy-customhead.vue";
	// 引入mescroll-mixins.js
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components: {
			TabBar,
			customHead,
		},
		data() {
			return {
				BASE_URL,
				headtitle: '铭钛招聘',
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				// 下拉刷新的配置(可选, 绝大部分情况无需配置)
				downOption: {},
				// 上拉加载的配置(可选, 绝大部分情况无需配置)
				upOption: {

				},
				tbrecruitList: [],
				query: {
					currentPage: 1,
					pageSize: 10,
					keyword: "",
					sidx: "lastModifyTime",
					sort: "desc"
				}
			};
		},
		onReady() {
			uni.hideTabBar();

		},
		onLoad(e) {
			this.query.keyword = e.keyword;
			this.Gettbrecruit();
		},
		methods: {
			orderSort() {
				if (this.query.sort == "asc") {
					this.query.sort = "desc";
				} else {
					this.query.sort = "asc";
				}
				this.Gettbrecruit();
			},
			JobsDetails(id) {
				uni.navigateTo({
					url: '/pages/JobsDetails/JobsDetails?id=' + id
				})
			},
			Searchtbrecruit() {
				this.query.currentPage = 1;
				this.query.pageSize = 10;
				this.tbrecruitList = [];
				this.Gettbrecruit();
			},
			Gettbrecruit() {
				this.API.Gettbrecruit(this.query).then(res => {
					if (this.query.currentPage == 1) {
						this.tbrecruitList = res.data.list;
					} else {
						this.tbrecruitList = this.tbrecruitList.concat(res.data.list);
					}
				});
			},
			getDifferTime(startDate) {
				startDate = this.formatDateTime(startDate);
				let startTime = new Date(Date.parse(startDate.replace(/-/g, "/"))).getTime();
				let endTime = new Date(Date.parse(this.getNowDate().replace(/-/g, "/"))).getTime();
				let dates = Math.abs((startTime - endTime)) / (1000 * 60 * 60 * 24);
				let DayNumber = Math.ceil(dates);
				if (DayNumber <= 7) {
					return DayNumber + "天内发布"
				} else {
					return DayNumber + "天前发布"
				}
			},
			getNowDate() {
				const timeOne = new Date()
				const year = timeOne.getFullYear()
				let month = timeOne.getMonth() + 1
				let day = timeOne.getDate()
				month = month < 10 ? '0' + month : month
				day = day < 10 ? '0' + day : day
				const NOW_MONTHS_AGO = `${year}-${month}-${day}`
				return NOW_MONTHS_AGO
			},
			formatDateTime(value) { // 时间戳转换日期格式方法
				if (value == null) {
					return ''
				} else {
					const date = new Date(value)
					const y = date.getFullYear() // 年
					let MM = date.getMonth() + 1 // 月
					MM = MM < 10 ? ('0' + MM) : MM
					let d = date.getDate() // 日
					d = d < 10 ? ('0' + d) : d
					let h = date.getHours() // 时
					h = h < 10 ? ('0' + h) : h
					let m = date.getMinutes() // 分
					m = m < 10 ? ('0' + m) : m
					let s = date.getSeconds() // 秒
					s = s < 10 ? ('0' + s) : s
					return y + '-' + MM + '-' + d + ' ' + h + ':' + m + ':' + s
				}
			},
			/*下拉刷新的回调, 有三种处理方式:*/
			downCallback() {
				this.mescroll.endSuccess();
				var that = this;
				that.query.currentPage = 1;
				that.query.pageSize = 10;
				this.Gettbrecruit(that.query);
			},
			/*上拉加载的回调*/
			upCallback(page) {
				var that = this;
				setTimeout(() => {
					this.mescroll.endByPage(10, 20);
					that.query.currentPage = that.query.currentPage + 1;
					this.Gettbrecruit(that.query);
				}, 2000)
			},
			/**
			 * 文章点击
			 */
			onArticle(id) {
				uni.navigateTo({
					url: '/pages/ArticleDetails/ArticleDetails?id=' + id,
				})
			}
		}
	}
</script>

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