<template>
	<view class="main pt0">
		<view class="tab">
			<u-tabs :list="tab" @click="tabClick"></u-tabs>
			<view class="filters" @click="show = true">
				<text class="icon">&#xe68c;</text>
				<text>筛选</text>
			</view>
		</view>
		<view class="item" v-for="(item, index) in list" :key="index" @click="go('/pages/user/resume/application/receive/preview?id=' + item.id)">
			<view class="top">
				<image :src="ip + item.avatar" mode="widthFix" class="avatar"></image>
				<view class="state" style="color: #4caf50" v-if="item.isRead == 1">
					<text class="icon">&#xe614;</text>
					<text>已阅</text>
				</view>
				<view class="state" v-else>
					<text class="icon">&#xe614;</text>
					<text>未读</text>
				</view>
				<view class="con">
					<view class="name">{{ item.name }}</view>
					<text class="desc">{{ item.sex }} · {{ item.age }}岁</text>
				</view>
			</view>
			<view class="flex">
				<view class="f" v-if="item.state == 0">待处理</view>
				<view class="f" v-if="item.state == 1 && item.isAccept == 0">等待对方同意接单</view>
				<view class="f br" v-if="item.state == 1 && item.isAccept == 1">对方同意接单</view>
				<view class="f danger" v-if="item.state == 1 && item.isAccept == 2">对方已拒绝</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>
		<sift v-model="show" @confirm="confirm"></sift>
	</view>
</template>
<script>
export default {
	data() {
		return {
			ip: this.http.ip,
			tab: [
				{ name: '全部', isRead: '' },
				{ name: '已阅', isRead: 1 },
				{ name: '未读', isRead: 0 }
			],
			list: [],
			param: { pageNum: 1, pageSize: 10, type: 1 },
			loadMore: true,
			show: false
		};
	},
	onLoad(e) {
		this.param.positionId = e.id;
		this.getData();
		uni.$on('agreeApplication', (res) => {
			this.refresh();
		});
		setTimeout(() => {
			uni.setNavigationBarTitle({ title: e.title + '(' + e.total + ')' });
		}, 300);
	},
	methods: {
		getData() {
			this.http.request({
				url: '/app/deliver/receive/list',
				data: this.param,
				loading: 'false',
				success: (res) => {
					this.loadMore = res.data.pages > this.param.pageNum ? true : false;
					this.list.push(...res.data.rows);
				}
			});
		},
		go(url) {
			uni.navigateTo({ url: url });
		},
		tabClick(e) {
			this.param.isRead = e.isRead;
			this.refresh();
		},
		confirm(e) {
			Object.assign(this.param, e);
			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">
.item {
	background-color: white;
	border-radius: 7px;
	padding: 15px;
	overflow: hidden;
	margin-bottom: 12px;
	.top {
		overflow: hidden;
		.avatar {
			float: left;
			width: 50px;
			height: 50px;
			border-radius: 50%;
		}
		.state {
			float: right;
			font-size: 14px;
		}
		.con {
			float: left;
			padding-left: 10px;
			.name {
				font-weight: bold;
				padding-bottom: 3px;
			}
			.desc {
				color: $font-c;
				font-size: 14px;
			}
		}
	}
	.flex {
		border-top: 1px solid $line;
		padding-top: 10px;
		font-size: 14px;
		margin-top: 13px;
	}
}
</style>
