<template>
	<view>
		
		<block v-for="(item,index) in plist" :key="index">
			<view class="cu-card dynamic no-card solid-bottom echo-comjobs-item padding-top-sm padding-lr-sm radius">
				<view class="cu-item shadow padding-top-sm">
					<view class="padding-lr flex justify-between align-center">
						<view class="basis-lg text-bold text-df text-cut">{{item.worker.title}}</view>
						<view class="basis-sm text-cut text-right text-red text-sm">
							{{item.status_text}}
						</view>
					</view>
					<view class="padding-lr padding-tb-xs flex justify-end">
						<view class="cu-btn bg-green radius" @tap="dealInvite(item.id,2)" v-if="item.status == 1">接受邀请</view>
						<view class="cu-btn bg-red margin-left-sm radius" @tap="dealInvite(item.id,3)" v-if="item.status == 1">拒绝邀请</view>
						<view class="cu-btn bg-blue margin-left-sm radius" @tap="toCompany(item.workerid)">查看公司</view>
					</view>
				</view>
			</view>
		</block>
		<uni-load-more :status="pstatus"></uni-load-more>
		
		</view>
</template>

<script>
	import slFilter from '@/components/sl-filter/sl-filter.vue';
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			slFilter,
			uniLoadMore
		},
		data() {
			return {
				userinfo: {},
				
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: [],
			};
		},
		onLoad: function(option){
			_this = this;
			_this.userinfo = _this.checkLogin("/pages/resume/log");
			_this.getMore();
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			getMore: function() {
				_this.$req.ajax({
					path: "resume/userLog",
					data: {
						userid: _this.userinfo.id
					}
				}).then((data) => {
					_this.pstatus = data.status;
					_this.plist = _this.plist.concat(data.list);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			dealInvite: function(id,status) {
				var text = status == 2 ? '接受' : '拒绝';
				uni.showModal({
					title: '信息提示',
					content: '确定要' + text + '邀请？',
					success: (res) => {
						if(res.confirm) {  
							_this.$req.ajax({
								path: "resume/dealInvite",
								data: {
									id: id,
									status: status,
								}
							}).then((data) => {
								_this.pageRefresh();
							}).catch((err) => {
								uni.showModal({
									title: '信息提示',
									content: err,
									showCancel: false
								});
							});
						} 
					} 
				});
			},
			toCompany: function(workerid) {
				uni.navigateTo({
					url: '/pages/worker/shop?workerid=' + workerid
				});
			}
		}
	}
</script>

<style>
</style>
