<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?item=' + JSON.stringify(item))">
			<view class="top">
				<view class="title omit">{{ item.title }}</view>
				<view class="salary">{{ item.salary }}¥</view>
			</view>
			<view class="bot bt">
				<view class="address">{{ item.startDate }}至{{ item.endDate }}</view>
				<view class="distance">{{ item.createTime }}</view>
			</view>
			<view class="message _error pd0 pl0" v-if="item.isComplete == 3">
				<view class="msg">驳回原因：{{ item.rejectMsg }}</view>
			</view>
			<view class="flex" v-if="param.role == 0">
				<view class="f br agree" v-if="item.isComplete == 0">进行中...</view>
				<view class="f br agree" v-if="item.isComplete == 1">对方发起任务完成申请</view>
				<view class="f br agree" v-if="item.isComplete == 2">已完成(打款)</view>
				<view class="f br danger" v-if="item.isComplete == 3">申请驳回</view>
			</view>
			<view class="flex" v-if="param.role == 1">
				<view class="f br agree" v-if="item.isComplete == 0">进行中...</view>
				<view class="f br agree" v-if="item.isComplete == 1">确认中...</view>
				<view class="f br agree" v-if="item.isComplete == 2">已完成(打款)</view>
				<view class="f br danger" v-if="item.isComplete == 3">申请驳回</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 },
				{ name: '已完成', isComplete: 2 },
				{ name: '驳回', isComplete: 3 }
			],
			list: [],
			param: { pageNum: 1, pageSize: 10, state: 1, type: 1, isAccept: 1 },
			loadMore: true
		};
	},
	onLoad(e) {
		this.param.role = e.role || 0;
		this.getData();
		uni.$on('task_to_do', (res) => {
			this.refresh();
		});
	},
	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));
						item.role = this.param.role;
						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>
