<template>
	<view>
		<scroll-view scroll-x class="bg-white nav solid-bottom solid-bottom echo-fixed-top">
			<view class="flex text-center">
				<view class="cu-item flex-sub" :class="status==0?'text-red cur':''" @tap="tabSelect" data-status="0">全部</view>
				<view class="cu-item flex-sub" :class="status==1?'text-red cur':''" @tap="tabSelect" data-status="1">审核通过</view>
				<view class="cu-item flex-sub" :class="status==2?'text-red cur':''" @tap="tabSelect" data-status="2">待审核</view>
				<view class="cu-item flex-sub" :class="status==3?'text-red cur':''" @tap="tabSelect" data-status="3">审核不通过</view>
			</view>
		</scroll-view>
		<view class="echo-fixed-top-empty"></view>
		
		
		<block v-for="(item,index) in plist" :key="index">
			<view class="cu-card dynamic no-card solid-bottom echo-comjobs-item margin-tb-sm">
				<view class="cu-item shadow padding-top-sm padding-bottom">
					<view class="padding-lr padding-bottom-xs flex justify-between align-center">
						<view class="basis-xl text-bold text-lg text-cut">
							{{item.title}}
							<text class="text-sm text-red">{{item.num}}名</text>
						</view>
						<view class="basis-xs text-cut text-right text-gray text-sm">{{item.city}}</view>
					</view>
					<view class="padding-lr flex justify-between align-bottom">
						<view><text class="text-red text-bold">工资：{{item.salary}}</text></view>
					</view>
					<view class="padding-lr padding-bottom-sm text-cut">
						<view v-for="(titem,tindex) in item.tags" :key="tindex" class="cu-tag light bg-gray sm">{{titem}}</view>
					</view>
					
					<view class="grid solids-top text-center col-2">
						<view @tap="goOutjob" :data-id="item.id" class="padding-top"><text class="cuIcon-write padding-right-xs"></text> 编辑 </view>
						<view @tap="delOutjob" :data-id="item.id" class="text-red padding-top"><text class="cuIcon-pulldown padding-right-xs"></text> 删除 </view>
					</view>
					
				</view>
			</view>
		</block>
		<uni-load-more :status="pstatus"></uni-load-more>
		<view class="padding"></view>
		<button class="cu-btn bg-themeBtn lg shadow echo-gohome" data-pageurl="/pages/worker/outjobform" @tap="goPage"> 发布招聘 </button>
		
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				isRotate: false,
				status: 0,
				userinfo: false,
				workerinfo: false,
				
				param: {},
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: [],
			
			}
		},
		onLoad: function(option) {
			_this = this;
			_this.userinfo = _this.checkLogin("/pages/my/my");
			_this.workerinfo = uni.getStorageSync('workerinfo') || false;
			if (_this.userinfo === false || _this.workerinfo === false) {
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
		},
		onShow: function() {
			_this.pageRefresh();
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			delOutjob: function(e) {
				var id = e.currentTarget.dataset.id;
				_this.$req.ajax({
					path: "woutjobs/delrecruit",
					data: {
						id: id,
						userid: _this.userinfo.id,
						workerid: _this.workerinfo.id,
					}
				}).then((data) => {
					_this.pageRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			getMore: function() {
				_this.$req.ajax({
					path: "woutjobs/listjobs",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						status: _this.status,
						workerid: _this.workerinfo.id
					}
				}).then((data) => {
					_this.param = data.param;
					_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
					});
				});
			},
			
			tabSelect: function(e) {
				_this.status = e.currentTarget.dataset.status;
				_this.pageRefresh();
			},
			
			goOutjob: function(e) {
				let id = e.currentTarget.dataset.id;
				uni.navigateTo({
					url: '/pages/worker/outjobform?id='+id
				});
			},			
			
			goPage: function(e) {
				var pageurl = e.currentTarget.dataset.pageurl;
				uni.navigateTo({
					url: pageurl,
					fail: function() {
						uni.switchTab({
							url: pageurl
						});
					}
				});
			},
		},
	}
</script>

<style>
	.picmodal{ width: 640rpx; background-color: transparent; }
	.picmodal image{ width: 100%; }
	
	.picmodal .bg-img{ position: relative; }
	.picmodalclose{ position: absolute; top: 0rpx; right: 0rpx; }
</style>
