<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-blue cur':''" @tap="tabSelect" data-status="0">全部</view>
				<view class="cu-item flex-sub" :class="status==1?'text-blue cur':''" @tap="tabSelect" data-status="1">待修改</view>
				<view class="cu-item flex-sub" :class="status==2?'text-blue cur':''" @tap="tabSelect" data-status="2">待审核</view>
				<view class="cu-item flex-sub" :class="status==3?'text-blue cur':''" @tap="tabSelect" data-status="3">已上架</view>
				<view class="cu-item flex-sub" :class="status==4?'text-blue cur':''" @tap="tabSelect" data-status="4">已停供</view>
				<view class="cu-item flex-sub" :class="status==5?'text-blue cur':''" @tap="tabSelect" data-status="5">已下架</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-supply-item margin-tb-sm">
				<view class="cu-item shadow padding-top-sm padding-bottom">
					<view class="padding-lr padding-bottom-sm flex justify-between align-center">
						<view class="basis-xl text-bold text-lg text-cut"><text v-if="item.mnumber>0"> 男{{item.mnumber}}人，</text><text v-if="item.wnumber>0"> 女{{item.wnumber}}人</text>【{{item.agegroup}}】</view>
						<view class="basis-xs text-cut text-right text-gray text-sm">{{item.updatetime_text}}</view>
					</view>
					<view class="padding-lr padding-bottom-sm text-gray"> 可到岗日期：{{item.candate}} </view>
					<view class="padding-lr padding-bottom-sm text-cut text-bold">
						{{item.province}} {{item.city}} <text class="cuIcon-move margin-lr-xs text-gray"></text> {{item.descity}}
					</view>
					
					<view class="grid solids-top text-center col-2" v-if="item.status==1">
						<view @tap="goSupplyform" :data-supplyid="item.id" class="padding-top"><text class="cuIcon-write padding-right-xs"></text> 编辑 </view>
						<view @tap="statusSupply" :data-supplyid="item.id" :data-status="2" class="padding-top"><text class="cuIcon-pulldown padding-right-xs"></text> 提交审核 </view>
					</view>
					<view class="grid solids-top text-center col-1" v-if="item.status==2">
						<view @tap="goSupplyform" :data-supplyid="item.id" class="padding-top"><text class="cuIcon-write padding-right-xs"></text> 编辑 </view>
					</view>
					<view class="grid solids-top text-center col-4" v-if="item.status==3">
						<view @tap="goSupplyform" :data-supplyid="item.id" class="padding-top"><text class="cuIcon-write padding-right-xs"></text> 编辑 </view>
						<view @tap="statusSupply" :data-supplyid="item.id" :data-status="5" class="padding-top"><text class="cuIcon-pulldown padding-right-xs"></text> 下架 </view>
						<view @tap="updateTime" :data-supplyid="item.id" class="padding-top"><text class="cuIcon-top padding-right-xs"></text> 置顶 </view>
						<view @tap="goSupplyDetail" :data-supplyid="item.id" class="padding-top"><text class="cuIcon-text padding-right-xs"></text> 详情 </view>
					</view>
					<view class="grid solids-top text-center col-3" v-if="item.status==4">
						<view @tap="goSupplyform" :data-supplyid="item.id" class="padding-top"><text class="cuIcon-write padding-right-xs"></text> 编辑 </view>
						<view @tap="statusSupply" :data-supplyid="item.id" :data-status="5" class="padding-top"><text class="cuIcon-pulldown padding-right-xs"></text> 下架 </view>
						<view @tap="goSupplyDetail" :data-supplyid="item.id" class="padding-top"><text class="cuIcon-text padding-right-xs"></text> 详情 </view>
					</view>
					<view class="grid solids-top text-center col-2" v-if="item.status==5">
						<view @tap="goSupplyform" :data-supplyid="item.id" class="padding-top"><text class="cuIcon-write padding-right-xs"></text> 编辑 </view>
						<view @tap="statusSupply" :data-supplyid="item.id" :data-status="4" class="padding-top"><text class="cuIcon-pullup padding-right-xs"></text> 上架 </view>
					</view>
					
				</view>
			</view>
		</block>
		<uni-load-more :status="pstatus"></uni-load-more>
		<view class="padding"></view>
		
	</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: 3,
				userinfo: false,
				workerinfo: false,
				
				param: {},
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			}
		},
		onLoad: function(option) {
			_this = this;
			_this.status = option.status || 3;
			_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;
			}
			_this.getMore();
		},
		onPullDownRefresh: function() {
			_this.pageRefresh();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			goSupplyDetail: function(e) {
				var supplyid = e.currentTarget.dataset.supplyid;
				uni.navigateTo({
				    url: '/pages/supply/detail?supplyid='+supplyid
				});
			},
			
			goSupplyform: function(e) {
				var supplyid = e.currentTarget.dataset.supplyid;
				uni.navigateTo({
				    url: '/pages/supply/supplyform?supplyid='+supplyid
				});
			},
			
			statusSupply: function(e) {
				var supplyid = e.currentTarget.dataset.supplyid;
				var status = e.currentTarget.dataset.status;
				_this.$req.ajax({
					path: "wsupply/statussupply",
					data: {
						supplyid: supplyid,
						userid: _this.userinfo.id,
						workerid: _this.workerinfo.id,
						status: status
					}
				}).then((data) => {
					_this.pageRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			updateTime: function(e) {
				var supplyid = e.currentTarget.dataset.supplyid;
				uni.showModal({
					title: '信息提示',
					content: '每次置顶会扣除'+_this.param.topsupply+'积分，确定要做置顶操作吗？',
					success: function(res) {
						if (res.confirm) {
							_this.$req.ajax({
								path: "wsupply/updatesupply",
								data: {
									supplyid: supplyid,
									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: "wsupply/listsupply",
					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();
			},
		},
	}
</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>
