<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-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.demand_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.demand_id)">
						<view><text class="text-red text-bold">{{item.demand.zwagall}}</text></view>
						<view><text class="text-red text-bold">{{item.demand.wtype_text}}</text></view>
						<view class="text-red">{{item.demand.ftype_text}}：{{item.demand.fwagall}}</view>
					</view>
					<view class="padding-lr text-cut" @tap="goDetail(item.demand_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="showReport"><text class="cuIcon-edit 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: 0,
				userinfo: false,
				workerinfo: false,
				
				param: {},
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: []
			}
		},
		onLoad: function(option) {
			_this = this;
			_this.status = option.status || 0;
			_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/listSnatch",
					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();
			},
			
			makeTelephone: function(e) {
				var telephone = e.currentTarget.dataset.telephone;
				uni.makePhoneCall({
					phoneNumber: telephone
				});
			},
			
			goDetail: function(id) {
				uni.navigateTo({
					url: '/pages/demand/detail?demandid=' + id
				});
			},
			goShop: function(workerid) {
				uni.navigateTo({
					url: '/pages/worker/shop?workerid=' + workerid
				});
			},
			showReport() {
				uni.showModal({
					title: '信息提示',
					content: '请上PC端查看报备详情',
					showCancel: false
				});
			},
		},
	}
</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>
