<template>
	<view class="main pt0">
		<view class="tab">
			<u-tabs :list="tab" @click="tabClick"></u-tabs>
		</view>
		<view class="item_job" v-for="(item, index) in list" :key="index" @click="go('/pages/user/resume/application/task_detail?id=' + item.positionId)">
			<view class="top">
				<view class="title omit">{{ item.title }}</view>
				<view class="salary">{{ item.salary }}¥</view>
			</view>
			<view class="bot bt">
				<view class="desc">
					<text>完工结算</text>
					<text>{{ item.startDate }}至{{ item.endDate }}</text>
				</view>
				<view class="distance">{{ item.createTime }}</view>
			</view>
			<view class="flex">
				<view class="f br agree" v-if="item.isComplete == 0">进行中...</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>
</template>
<script>
export default {
	data() {
		return {
			tab: [
				{ name: '全部', isComplete: '' },
				{ name: '进行中', isComplete: 0 },
				{ name: '已完成', isComplete: 1 }
			],
			list: [],
			param: { pageNum: 1, pageSize: 10, state: 1, type: 1, isAccept: 1 },
			loadMore: true
		};
	},
	onLoad(e) {
		this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/deliver/user/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);
					});
				}
			});
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		tabClick(e) {
			this.param.isComplete = e.isComplete;
			this.refresh();
		},
		//刷新数据
		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>
