<template>
	<view class="content">
		<image src="../../static/img/wh-bg.png" mode="" class="to-bg"></image>
		<view class="top-tit">
			{{state}}
		</view>
		<view class="top-time" v-if="status != 1">
			{{showTime}}
		</view>
		<view class="top-time" v-if="status == 1">
			{{stopTimeH + ':' + stopTimeM + ':' + stopTimeS}}
		</view>

		<view class="center-btn flex" @click="navto('/pages/user/myWholesale')">
			<image src="../../static/icon/pf-logo.png" mode="" class="center-logo"></image>
			<view class="center-tit">
				<view class="tit-top">
					批发订单
				</view>
				<view class="">
					查看我购买的批发订单
				</view>
			</view>
			<image src="../../static/img/img74.png" mode="" class="look-more"></image>
		</view>
		<scroll-view scroll-y="true" class="swiper-box" :style="{'height': height}">
			<!-- <empty v-if="loadingType == 'noMore' && list.length === 0"></empty> -->
			<view class="good-wrap">

				<view class="good" v-for="item in list" @click="gotoDetail(item)">
					<image :src="item.whole.image" mode="" class="goo-img"></image>
					<view class="good-tit clamp">
						{{item.whole.title}}
					</view>
					<view class="good-price flex">
						<view class="new-price">
							¥{{item.price}}
						</view>
						<!-- <view class="old-price">
								¥{{item.}}
							</view> -->
					</view>
				</view>
			</view>
			<uni-load-more :status="loadingType" v-if="loadingType == 'loading'"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import {
		timeComputed
	} from '@/utils/rocessor.js'
	import {
		getWholeList
	} from '@/api/whole.js'

	import uniCountdown from '@/components/uni-countdown/uni-countdown.vue';
	import empty from '@/components/empty';

	export default {
		components: {
			empty,
			uniCountdown
		},
		data() {
			return {
				height: '',
				list: [],
				page: 1,
				limit: 10,
				loadingType: 'loading',
				loaded: false,
				bin: '',
				stop: '',
				status: '',
				state: '',
				stopTimeH: '',
				stopTimeM: '',
				stopTimeS: '',
				timer: '',
				wid: ''
			}
		},
		onReady(res) {
			var obj = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.swiper-box').boundingClientRect();
					query.exec(function(res) {
						obj.height = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', obj.height);
					});
				},
				fail: res => {}
			});
		},
		onLoad(opt) {
			let obj = this
			obj.bin = decodeURI(opt.bin)
			obj.stop = opt.stp
			obj.status = opt.status
			obj.state = opt.state
			obj.wid = opt.wid

			obj.getWholeList()
			console.log(obj.bin, obj.stop, obj.status)
		},
		onShow() {
			let obj = this
			if (obj.status == 1) {
				if (obj.timer) {
					clearTimeout(obj.timer)
				}
				this.getSyTime()
			}
		},
		computed: {
			showTime() {
				let obj = this
				console.log(obj.status, obj.state, 'obj.status++++++++')
				if (obj.status == 1) {
					return ''
				}
				if (obj.status == 0) {
					return ''
				}
				if (obj.status == 2) {
					return obj.bin
				}
			}
		},
		methods: {
			gotoDetail(item) {
				let obj = this
				obj.navto('/pages/product/realyWhole?id=' + item.id + '&time=' + item.time_id)
				// if(obj.status == 1 ) {
				// 	obj.navto('/pages/product/wholesaleDetail?id=' + item.id)
				// }
				// if(obj.status == 0) {
				// 	obj.$api.msg('今日该场次已结束')
				// }
				// if(obj.status == 2) {
				// 	obj.$api.msg('今日该场次未开始，请稍后')
				// }
			},
			navto(url) {
				uni.navigateTo({
					url: url
				})
			},
			// 获取剩余时间
			getSyTime() {
				let obj = this
				let stopTime = timeComputed(obj.stop * 1000)
				console.log(stopTime, 'stopTime')
				obj.stopTimeH = stopTime.hours
				obj.stopTimeM = stopTime.minutes >= 10 ? stopTime.minutes : ('0' + stopTime.minutes)
				obj.stopTimeS = stopTime.seconds >= 10 ? stopTime.seconds : ('0' + stopTime.seconds)
				if (stopTime.hours == 0 && stopTime.minutes == 0 && stopTime.seconds == 0) {
					obj.status = 0
				}
				if (!obj.timer) {
					if (obj.status == 1) {
						obj.timer = setTimeout(this.getSyTime, 1000)
					}

				} else {
					clearTimeout(obj.timer)
					if (obj.status == 1) {
						obj.timer = setTimeout(this.getSyTime, 1000)
					}
				}

				// console.log(obj.stopTimeH + ':' + obj.stopTimeM + ':' + obj.stopTimeS)
			},
			getWholeList() {
				let obj = this
				// obj.loadingType == 'loading'
				getWholeList({}, obj.wid).then(({
					data
				}) => {
					obj.list = data.data
					// if()
					obj.loadingType = 'noMore'
					console.log(obj.loadingType)
					console.log(obj.list, 'obj.list+++++')
				})
			}
		}
	}
</script>

<style lang="scss">
	.to-bg {
		width: 750rpx;
		height: 427rpx;
		background-color: #fff;
	}

	.top-tit {
		position: absolute;
		top: 170rpx;
		left: 0;
		right: 0;
		margin: auto;
		text-align: center;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.top-time {
		position: absolute;
		top: 240rpx;
		left: 0;
		right: 0;
		margin: auto;
		font-size: 83rpx;
		text-align: center;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
	}

	.center-btn {
		padding: 20rpx 32rpx;
		background-color: #fff;
		margin-bottom: 20rpx;

		.center-logo {
			width: 83rpx;
			height: 106rpx;
			flex-shrink: 0;
			background-color: #eee;
		}

		.center-tit {
			padding-left: 30rpx;
			flex-grow: 1;
			font-size: 24rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #999999;
			line-height: 1.5;

			.tit-top {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}
		}

		.look-more {
			width: 16rpx;
			height: 30rpx;
			flex-shrink: 0;
		}
	}

	.swiper-box {
		// background-color: red;
		// position: relative;
	}

	.good-wrap {
		display: flex;
		// padding: 0 0 20rpx 20rpx;
		padding-left: 20rpx;
		flex-wrap: wrap;
	}

	.good {
		width: 345rpx;
		height: 480rpx;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 10rpx;

		.goo-img {
			width: 345rpx;
			height: 345rpx;
			border-radius: 10rpx 10rpx 0 0;
			// background-color: #bfa;
		}

		.good-tit {
			padding: 15rpx 20rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
			line-height: 35rpx;
		}

		.good-price {
			padding-left: 20rpx;
			justify-content: flex-start;

			.new-price {
				font-size: 36rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #FF4C4C;
			}

			.old-price {
				padding-left: 8rpx;
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: bold;
				text-decoration: line-through;
				color: #999999;

			}
		}
	}
</style>
