<template>
	<view class="main">
		<view class="item_job" v-for="(item, index) in list" :key="index" @click="go('/pages/job/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="address omit">{{ item.address }}</view>
				<view class="distance">{{ item.createTime }}</view>
			</view>
			<view class="flex">
				<view class="f danger" @click.stop="del(item)">删除</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 {
			list: [],
			param: { pageNum: 1, pageSize: 10 },
			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 });
		},
		del(item) {
			uni.showModal({
				title: '提示',
				content: '确定删除该职位投递，删除后企业HR将无法看到你的简历',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/app/deliver/remove/' + item.id,
							success: (res) => {
								uni.showToast({ title: '删除成功' });
								this.list.splice(this.list.indexOf(item), 1);
							}
						});
					}
				}
			});
		},
		//刷新数据
		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>
