<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==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-demand-item margin-tb-sm">
				<view class="cu-item shadow padding-top-sm">
					<view class="padding-lr padding-bottom-xs flex justify-between align-center" @tap="goDetail(item.id)">
						<view class="basis-xl text-bold text-lg text-cut">{{item.demand.title}}</view>
						<view class="basis-xs text-cut text-right text-gray text-sm">{{item.demand.city}}</view>
					</view>
					<view class="padding-lr flex justify-between align-bottom" @tap="goDetail(item.id)">
						<view v-if="item.demand.wtype==1"><text class="text-red text-bold">{{item.demand.zwagall}}</text></view>
						<view v-if="item.demand.wtype==5"><text class="text-red text-bold">其他</text></view>
						<view v-else><text class="text-red text-bold">{{item.demand.bwagall}}</text></view>
						<view class="text-red">{{item.demand.ftype_text}}:{{item.demand.fwagall}}</view>
					</view>
					<view class="padding-lr text-cut" @tap="goDetail(item.id)">
						<view v-for="(titem,tindex) in item.demand.tags" :key="tindex" class="cu-tag light bg-gray sm">{{titem}}</view>
					</view>
					
					<view class="text-gray padding-lr padding-tb-sm flex align-center justify-between" @tap="goShop(item.demand.workerid)">
						<view class="text-cut basis-xl">
							<view class="cu-capsule margin-right-sm">
								<view class="cu-tag bg-red">
									<text class="cuIcon-safe"></text>
								</view>
								<view class="cu-tag line-red">认证企业</view>
							</view>
							{{item.worker.title}}
						</view>
						<view class="text-gray text-right basis-xs">
							<text class="cuIcon-shop margin-right-xs text-lg"></text>
							进店
						</view>
					</view>
					
					<view class="grid solids-top text-center col-2 padding-tb-sm bg-white">
						<view @tap="delDemandlog" :data-itemlogid="item.id" :data-itemindex="index"><text class="cuIcon-delete padding-right-xs"></text> 删除 </view>
						<view @tap="makeTelephone" :data-telephone="item.demand.telephone"><text class="cuIcon-phone 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: {
			
			delDemandlog: function(e) {
				var itemlogid = e.currentTarget.dataset.itemlogid;
				var itemindex = e.currentTarget.dataset.itemindex;
				uni.showModal({
					title: '信息提示',
					content: '删除后不可恢复,确定要删除吗?',
					success: function(res) {
						if (res.confirm) {
							_this.$req.ajax({
								path: "demand/deldemandlog",
								data: {
									gworkerid: _this.workerinfo.id,
									logid: itemlogid
								}
							}).then((data) => {
								_this.modalName = null;
								_this.plist.splice( itemindex, 1 );
							}).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: "demand/listdemandlog",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						status: _this.status,
						gworkerid: _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();
			},
			
			makeTelephone: function(e) {
				var telephone = e.currentTarget.dataset.telephone;
				uni.makePhoneCall({
					phoneNumber: telephone
				});
			},
			
			goDetail: function(comjobsid) {
				uni.navigateTo({
					url: '/pages/comjobs/detail?comjobsid=' + comjobsid
				});
			},
			goShop: function(workerid) {
				uni.navigateTo({
					url: '/pages/worker/shop?workerid=' + workerid
				});
			},
		},
	}
</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>