<template>
	<view>
		<view class="tab">
			<u-tabs :list="tab" :current="current" @click="click"></u-tabs>
		</view>
		<view class="cmain">
			<view class="position">
				<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item)">
					<view class="top">
						<view class="title omit">{{ item.title }}</view>
						<view class="op" v-if="item.status != 0 && item.state == 0" style="color: #ccc">
							<text class="icon">&#xe622;</text>
							<text>审核中</text>
						</view>
						<view class="op" v-if="item.status != 0 && item.state == 1" style="color: #07cb4c">
							<text class="icon">&#xe622;</text>
							<text>开放中</text>
						</view>
						<view class="op" v-if="item.status != 0 && item.state == 2" style="color: #ccc">
							<text class="icon">&#xe622;</text>
							<text>审核不通过</text>
						</view>
						<view class="op" v-if="item.status == 0 || item.state == 3" style="color: #ccc">
							<text class="icon">&#xe622;</text>
							<text>已关闭</text>
						</view>
						<view class="clear"></view>
					</view>
					<view class="con">
						<view class="desc">
							<text class="tag">{{ item.experience == '不限' ? '经验不限' : item.experience }}</text>
							<text class="tag">{{ item.education == '不限' ? '学历不限' : item.education }}</text>
							<text class="tag">{{ item.salary }}</text>
							<view class="clear"></view>
						</view>
						<view class="clear"></view>
					</view>
				</view>
				<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
				<u-empty v-if="!loadMore && list.length == 0"></u-empty>
			</view>
		</view>
		<u-action-sheet round="20" :actions="actions" @select="selectClick" cancelText="取消" :show="show" @close="show = false"></u-action-sheet>
		<view class="mfooter">
			<button class="btn" @click="show = true">
				<text class="icon">&#xe7c4;</text>
				<text>发布职位</text>
			</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			user: this.getUser(),
			tab: [{ name: '全职' }, { name: '兼职' }],
			list: [],
			param: { pageNum: 1, pageSize: 10, types: '全职', orderByColumn: 'createTime', isAsc: 'desc' },
			loadMore: true,
			show: false,
			current: 0,
			actions: [
				{ name: '全职', type: 0 },
				{ name: '兼职', type: 1 }
			]
		};
	},
	onLoad(e) {
		this.getData();
		uni.$on('position', (res) => {
			this.refresh();
		});
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/position/manage/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					res.data.rows.forEach((item) => {
						item.createTime = uni.$u.timeFrom(Date.parse(item.createTime));
						this.list.push(item);
					});
				}
			});
		},
		select(item) {
			this.param.types = item;
			this.refresh();
		},
		detail(item) {
			uni.navigateTo({ url: '/app/position/manage/push?id=' + item.id });
		},
		selectClick(e) {
			uni.navigateTo({ url: '/pages/job/position/manage/push?type=' + e.type });
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param.pageNum = 1;
			this.list = [];
			this.getData();
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param.pageNum++;
			this.getData();
		}
	}
};
</script>

<style lang="scss"></style>
