<style lang="scss">
	.app-bg{
		position: absolute;
		image{width: 100vw;height: 55vw;}
		.bg-info{
			width: 100vw;
			height: 55vw;
			position: absolute;
			top: 0;
			.tip{
				background: rgba(253, 59, 57, 0.4);
				border-radius: 14px;
				font-size: 16px;
				padding: 10rpx 20rpx;
				    color: #fff;
			}
		}
	}
	
	.tb-top {
		.sreach{
			background: #fff;
			border-radius: 32rpx;
			padding: 16rpx 32rpx;
			.icon{
				width: 46rpx;
				height: 46rpx;
			}
			input{
				width: calc(100% - 46rpx - 16rpx - 50px);
				font-size: 16px;
			}
			.search-btn{
				font-size: 14px;
				color: #FF4C4C;
			}
		}
		.order{
			width: 140rpx;
			background: #fd3b39;
			border-radius: 14px;
			font-size: 16px;
			color: #fff;
			margin-right: 10px;
		}
		
	}
	
	
	.app-body{
		position: relative;
		z-index: 9;
		padding: 0px 30rpx;
		.goods-list{
			margin: 10px 0;
			.item{
				background: #fff;
				position: relative;
				width: calc(50% - 10rpx);
				margin-right: 10rpx;
				margin-bottom: 20rpx;
				border-radius: 10rpx;
				&:nth-child(2n) {
					margin-left: 10rpx;
					margin-right:0;
				}
				.buy-out{
					    position: absolute;
					    top: 0;
					    left: 0;
					    right: 0;
					    z-index: 2;
						image{	width: 86px;
					    height: 74px;}
				}
				.img {
					width: 100%;
					height: calc(50vw - 20rpx);
					border-radius: 10rpx 10rpx 0 0;
				}
				.info{
					padding: 20rpx;
					.title{
						font-size: 16px;
						color: #303133;
						padding: 10rpx 0;
					}
					.price{
						font-size: 22px;
						color: red;
						font-weight: 500;
						text{
							font-size: 12px;
						}
					}
				}
				
			}
		}
		.pager{
			padding: 20rpx 0;
			width: 100%;
			.next{
				width: calc(50% - 40rpx);
				background-color: #fd3b39;
				margin-right: 10rpx;
				&:nth-child(2n){
					margin-left: 10rpx;
					margin-right: 0;
				}
				color: #fff;
				text-align: center;
				padding: 5px 0px;
				border-radius: 28px;
				&.not{
					background: #ccc;
					color: #fff;
				}
			}
		}
	
		.countdown{
			margin-top: 11px;
			font-size: 18px;
			text-align: center;
		}
		.countdown-time{
			margin-top: 11px;
			font-size: 22px;
			text-align: center;
			color: #fd3b39;
		}
	}
	
</style>
<template>
	<view>
		<view class="app-bg">
			<image src="/static/img/hall_bg.png"></image>
			<view class="bg-info fx-h fx-bc fx-ac">
				<view class="tip">{{ data.nickname }}馆长：{{ data.gz_name || "" }}</view>
			</view>
		</view>
		<uni-nav-bar color="#fff" :border="false" statusBar backgroundColor="transparent" left-icon="left" @clickLeft="utils.navigateBack()" fixed :title="data.nickname || '加载中..'"></uni-nav-bar>
		
		<view class="app-body" v-if="isType == 2">
			<view style="height: calc(55vw - 30px);"></view>
			<view class="tb-top fx-r">
				<view @tap="tapOpen" data-url="order/order" class="order fx-h fx-bc fx-ac">
					<view class="text">订单</view>
				</view>
				<view class="sreach fx-r fx-bc fx-ac fx-g1">
					<image class="icon" src="/static/img/tb-seach.png"></image>
					<input type="text" confirm-type="search"  v-model="keyword" @confirm="tapInput" placeholder="请输入搜索挂售商品" placeholder-style="color: #B3B3B3;" />
					<view class="fx-g1"></view>
					<view class="search-btn" @tap="tapInput" v-if="keyword != ''">搜索</view>
				</view>
			</view>
			
			<view class="goods-list fx-r">
				<view class="item" v-for="item in listData" @tap="tapItem(item)">
					<view class="buy-out" v-if="item.is_buy == 1">
						<image src="/static/img/sOut1.png"></image>
					</view>
					<image class="img" mode="aspectFill" :src="item.image"></image>
					<view class="info">
						<view class="title">{{ item.name }}</view>
						<view class="fx-r">
							<view class="price"><text>￥</text>{{ item.hanging_price }}</view>
							<view class="fx-g1"></view>
							<view v-if="item.is_buy == 1" style="color: #787878;font-size: 14px;">已售完</view>
						</view>
					</view>
					
				</view>
				
				
			</view>
			<view class="pager fx-r fx-bc fx-ac">
				<view class="next"  @tap="tapPve()" :class="page.page == 1 ? 'not' : ''">上一页</view>
				<view class="next"  @tap="tapNext()" :class="page.isFoot ? 'not' : ''">下一页</view>
			</view>
			
		</view>	
		
		<view class="app-body fx-h fx-bc fx-ac" v-if="isType == 1">
			<view style="height: calc(55vw - 30px);"></view>
			<image src="/static/img/hall_djs.png" style="width: 50vw;height: 69vw;"></image>
			<view class="countdown">客官请稍后，请{{ utils.date('H:i:s',data.radd_time) }}入场</view>
			<view class="countdown-time">入场倒计时：{{ utils.countdown(countdownTime) }}</view>
		</view>
		
		<view class="app-body fx-h fx-bc fx-ac" v-if="isType == 3">
			<view style="height: calc(55vw - 30px);"></view>
			<image src="/static/img/hall_djs.png" style="width: 50vw;height: 69vw;"></image>
			<view class="countdown-time">{{ error }}</view>
		</view>
		
	</view>	
</template>


<script>
	let intervalId = 0;
	import {mapState,mapMutations } from 'vuex'
	export default {
		...mapState(['user','lbs']),
	    data() {
	        return {
				keyword : "",
				data : [],
				h5Foot : 0,
				isType : 0,
				countdownTime : 0,
				isLoadPro : false,
				error : "",
				listData : [],
				page:{
					page:1,
					isLoad:false,
					isFoot:false
				},
				id : 0
	        }
	    },
		/**
		 * 跳转的值
		 * @param {Object} option
		 */
		onLoad(option){
			this.id = option.id || 0;
			intervalId = setInterval(this.interval,1000);
			this.initView();
			uni.$on('rushBuy',this.rushBuy);
		},
		
		onShow() {
			if(this.isLoadPro) this.onShowIn();
		},
		
		onUnload() {
			uni.$off('rushBuy',this.rushBuy);
			clearInterval(intervalId);
		},
		
		
	    methods: {
			/**
			 * 是倒计时状态
			 */
			initView:function(){
				uni.showLoading({ title: '提交数据..' });
				this
					.request
					.post("auctionItem",{id : this.id})
					.then(res => {
						uni.hideLoading();
						if (res.code == 200) {
							this.data = res.data;
							this.interval();
						} else {
							this.isType = 3;
							this.error = res.msg;
						}
					})
					.catch(err => {
						this.utils.Tip("加载失败，重新点击尝试！" + JSON.stringify(error));
						uni.hideLoading();
					});
				
			},
			
			interval:function(){
				if(this.isLoadPro) return;
				if(this.data.radd_time == null) return;
				let time = this.utils.strtotime() - this.data.radd_time;
				if(time >= 0) {
					this.isType = 2;
					this.isLoadPro = true;
					this.getData();
					}  else {
					this.isType = 1;
					this.countdownTime = Math.abs(time);
				}
			},
			
			onShowIn:function(){
				if(this.data.radd_time == null) return;
				let time = this.utils.strtotime() - this.data.radd_time;
				if(time >= 0) {
					this.isType = 2;
					this.isLoadPro = true;
					this.getData();
				}
			},
			
			/**
			 * 打开详情
			 */
			tapItem:function(item){
				if(item.is_buy == 1) {
					this.utils.Tip("已售完了");
					return;
				}
				
				uni.navigateTo({
					url:"proItem?id=" + item.id + "&auction_id=" + this.id
				})
				
			},
			
			rushBuy:function(data) {
				let id = data.id;
				for(let i in this.listData) {
					if(this.listData[i].id == id) {
						this.$set(this.listData[i],'is_buy',1);
					}
				}
			},
			
			/**
			 * 输入
			 */
			tapInput:function(ev){
				this.page = {page:1,isLoad:false,isFoot:false};
				this.getData(true);
			},
			/**
			 *  下拉加载
			 */
			loadMoreData:function(){
				
				if(this.page.isFoot || this.page.isLoad) {
					return;
				}
				this.page.page ++;
				this.getData();
			},
			/**
			   * 获取get数据
			*/
			getData:function(isPull = false){
					if (this.page.isLoad) return;
					this.page.isLoad = true;
					uni.showLoading({	title: '获取数据中..'});
					var post = {};
					if(this.keyword != "") {
						post.keyword = this.keyword;
					}
					post.page = this.page.page;
					post.auction_id = this.id;
					this
						.request
						.post("auctionPro",post)
						.then(res => {
							uni.hideLoading();
							this.listData = res.data.list;
							
							this.page.isLoad = false;
							//是否到底
							if (res.data.list.length != res.data.pageSize) {
								this.page.isFoot = true;
							} else {
								this.page.isFoot = false;
							}
							
						})
						.catch(res=>{
							console.log(res);
							uni.hideLoading();
							uni.showModal({title: '系统提示',content: '加载失败，重新点击尝试！',showCancel: false});
						});
				},
			
			tapPve:function(){
				if(this.page.page > 1) {
					this.page.page = this.page.page - 1;
					this.getData();
				}
				
			},
			
			tapNext:function(){
				if(!this.page.isFoot) {
					this.page.page++;
					this.getData();
				} else {
					this.utils.Tip("没有下一页了");
				}
				 
			},
			
			/**
			 * 打开其他页面
			 * @param {Object} ev
			 */
			tapOpen: function(ev) {
				let url = ev.currentTarget.dataset.url
				uni.navigateTo({
					url: url
				});
			},	
			/**
			 * 返回上一页
			 */	
			tapBack: function () {
			    uni.navigateBack({ delta: 1 });
			},
	    }
	}
</script>


