<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">您好，邀请您过来面试。</view>
				<view class="distance">{{ item.createTime }}</view>
			</view>
			<view class="flex">
				<view class="f br agree" @click.stop="agree(item, 1)" v-if="item.isAccept == 0">同意</view>
				<view class="f danger" @click.stop="agree(item, 2)" v-if="item.isAccept == 0">拒绝</view>
				<view class="f danger" v-if="item.isAccept == 2">已拒绝</view>
				<view class="f br agree" v-if="item.isAccept == 1">已同意</view>
				<view class="f br agree" v-if="item.isAccept == 3">面试完成</view>
				<view class="f" @click.stop="navigation(item)" v-if="item.isAccept == 1">导航去面试</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, state: 1, type: 0 },
			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 });
		},
		navigation(item) {
			wx.openLocation({
				latitude: Number(item.latitude),
				longitude: Number(item.longitude),
				scale: 18, // 缩放比例
				success: (res) => {
					console.log('导航成功');
				},
				fail: (res) => {
					console.error('导航失败', res);
				}
			});
		},
		agree(item, isAccept) {
			uni.showModal({
				title: '提示',
				content: isAccept == 1 ? '确定同意去面试' : '确定拒绝该邀请',
				success: (res) => {
					if (res.confirm) {
						this.http.request({
							url: '/app/deliver/agree',
							data: { id: item.id, isAccept: isAccept },
							method: 'POST',
							success: (res) => {
								uni.showToast({ title: '操作成功' });
								item.isAccept = isAccept;
							}
						});
					}
				}
			});
		},
		//刷新数据
		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>
