<template>
	<view>
		
		<view class="cu-list menu">
			<block v-for="(item,index) in plist" :key="index">
				<view class="cu-item arrow" @tap="goLPage('/pages/broker/getorder?id='+item.id)">
					<view class="content padding-tb-sm">
						<view>{{item.demand.title}}</view>
						<view class="text-gray text-sm">招聘工厂：{{item.demand.worker.title}}</view>
						<view class="text-gray text-sm">剩余人数：{{item.snatch_num}}</view>
					</view>
					<view class="action text-gray">{{item.status_text}}</view>
				</view>
			</block>
		</view>
		<uni-load-more :status="pstatus"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				brokerinfo: {},
				
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: [],
				
				followstatus: 0,
				followstatusarr: ['全部','未跟进', '未面试', '面试通过', '面试未通过', '用户放弃', '已入职', '已离职']
			};
		},
		onLoad: function(){
			_this = this;
			_this.brokerinfo = uni.getStorageSync('brokerinfo') || false;
			if (_this.brokerinfo===false){
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.getMore();
		},
		onPullDownRefresh: function() {
			_this.ppage = 1;
			_this.pstatus = 'more';
			_this.plist = [];
			_this.getMore();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			getMore: function() {
				_this.$req.ajax({
					path: "broker/listorder",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						brokerid: _this.brokerinfo.id,
						followstatus: _this.followstatus
					}
				}).then((data) => {
					_this.pstatus = data.pstatus;
					_this.plist = _this.plist.concat(data.plist);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			tabSelect: function(e) {
				_this.followstatus = e.currentTarget.dataset.followstatus;
				_this.pageRefresh();
			},
			
			goLPage: function(pageurl) {
				_this.userinfo = _this.checkLogin("/pages/my/my");
				if (_this.userinfo===false){
					return false;
				}
				uni.navigateTo({
					url: pageurl,
					fail: function(){
						uni.switchTab({
						    url: pageurl
						});
					}
				});
			},
			
			goNavPage: function(pageurl) {
				_this.userinfo = _this.checkLogin("/pages/my/my");
				if (_this.userinfo===false){
					return false;
				}
				uni.redirectTo({
					url: pageurl
				});
			},
		}
	}
</script>

<style>
	.cu-list.menu-avatar .cu-item{ height: 170rpx !important; }
</style>

