<template>
	<view class="center">
		<view class="content-money">
			<view class="status_bar"><!-- 这里是状态栏 --></view>
			<view class="money-box">
				<view class="goback-box" @click="toBack">
					<image class="goback" src="../../static/img/fanhui.png" mode=""></image>
				</view>
				<view class="header">会馆场次</view>
			</view>
		</view>
		<swiper class="hallist-bg" autoplay="true" duration="400" interval="5000">
			<swiper-item v-for="(item, index) in images" :key="index" class="carousel-item">
				<image class="swimage" :src="item" />
			</swiper-item>
		</swiper>
		<view class="main" v-for="(item, index) in list" :key="index">
			<view class="mtitle-english">{{ item.show }}</view>
			<view class="mmain flex">
				<view class="mmain-info">
					<view class="mmain-title">
						<image class="mmaint-left" :src="item.time_image" mode=""></image>
						<view class="mmaint-font">{{ item.nickname }}</view>
						<view class="mmaint-time">{{ item.radd_time }}开售</view>
					</view>
					<view class="mmain-time" style="margin-top: 28rpx;">预约时间:{{ item.add_time }}-{{ item.end_time }}
					</view>
					<view class="mmain-time">入场时间:{{ item.radd_time | ahead }}-{{ item.rend_time }}</view>
					<view class="mmain-time flex">
						<view class="mmain-font">距预约结束:</view>

						<view class="lyy-b-jz flex" v-if="item.daotime == 1" style="font-size: 30rpx; color: #d13737;">
							已结束</view>
						<view class="lyy-b-jz flex" v-else>
							<uni-countdowns color="#702400" splitor-color="#faf1e6" background-color="#faf1e6"
								border-color="#faf1e6" :show-day="false" :hour="item.hours" :minute="item.minutes"
								:second="item.seconds" :index="index" @timeover="isTime"></uni-countdowns>
						</view>
					</view>
				</view>
				<view class="mmain-image">
					<image :src="item.image" mode=""></image>
				</view>
			</view>
			<view v-if="item.str == '预约'" class="bottom" @click="open(item)">
				<view class="bottom-font">立即{{ item.str }}</view>
				<image v-if="item.str == '预约'" class="bottom-image" src="../../static/img/jt.png" mode=""></image>
			</view>
			<view class="bottom"  v-else>
				<view class="bottom-font">{{ item.daotime == 1 ? '立即进入' : '您已预约' }}</view>
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup">
				<view class="popup-title">
					<view class="title">
						请选择价格档次
					</view>
					<view class="flex-center">
						<view class="pirice" @click="actionPay=ind" :class="{action:actionPay==ind}" v-for="(item,ind) in price_cate">
							{{item}}
						</view>
					</view>
				</view>
				<view class="btn-box">
					<view class="btn-left" @click="close()">取消</view>
					<view class="btn-right" @click="appointment()">确定</view>
				</view>
			</view>
		</uni-popup>
		<u-tabbar activeColor="#333333" inactive-color='#999999' :list="tabbar"></u-tabbar>
	</view>
</template>

<script>
	import uniCountdowns from '@/components/uni-countdown/uni-countdowns.vue';
	import {
		pay_list
	} from '../../api/wallet.js';
	import {
		article
	} from '@/api/user.js';
	import {
		getUserInfo,
		rate,
		details
	} from '@/api/user.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import {
		auction_list,
		subscribe,
		advance
	} from '@/api/hall.js';
	import {
		timeComputed
	} from '@/utils/rocessor.js';
	import {
		tabbar1
	} from '@/utils/tabbar.js';
	export default {
		components: {
			uniCountdowns
		},
		data() {
			return {
				actionPay:0,
				tabbar: tabbar1,
				images: [], //轮播图
				name: '', //馆名字
				peoplename: '', //馆长名字
				id: '', //预约会场id
				price_cate: [],
				page: 1,
				limit: 10,
				loadingType: 'more',
				list: [],
				aliData: {},
				bankData: {},
				wx: {},
			};
		},
		filters: {
			ahead(provider) {
				let time = provider.split(':');
				console.log(time);
				if (time[1] * 1 - 6 < 0) {
					time[1] = time[1] * 1 + 54;
					if (time[0] * 1 == 0) {
						time[0] = '23';
					} else {
						time[0] = time[0] * 1 - 1;
					}
				} else {
					time[1] = time[1] * 1 - 6;
					if (time[1] < 10) {
						time[1] = '0' + time[1];
					}
				}
				return time[0] + ':' + time[1] + ':' + time[2];
			}
		},
		onLoad(option) {
			this.name = option.name;
			this.peoplename = option.peoplename;
		},
		onShow() {
			this.list = [];
			this.page = 1;
			this.limit = 10;
			this.loadingType = 'more';
			pay_list({}).then(({
				data
			}) => {
				this.wx = data.wx;
				this.aliData = data.zfb;
				this.bankData = data.bank;
			});
			this.loadData();
		},
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
		},
		methods: {
			...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
			loadData() {
				const obj = this;
				if (obj.loadingType == 'nomore' || obj.loadingType == 'loading') {
					return;
				}
				obj.loadingType = 'loading';
				auction_list({
					page: obj.page,
					limit: obj.limit,
				}).then(({
					data
				}) => {
					obj.images = data.slider_image;
					console.log(data);
					data.data.forEach(e => {
						let now_time = timeComputed(e.time);
						this.price_cate = data.price_cate;
						console.log(e.time, now_time);
						e.hours = now_time.hours;
						e.minutes = now_time.minutes;
						e.seconds = now_time.seconds;
						if (now_time.hours < 0 || now_time.minutes < 0 || now_time.seconds < 0) {
							e.daotime = 1;
						} else {
							e.daotime = 0;
						}
						let jcsj = e.radd_time.split(':');
						if (jcsj[0] * 1 >= 8 && jcsj[0] * 1 < 12) {
							e.time_image = '../../static/img/morningicon.png';
							e.show = 'MORNING SHOWS';
						} else if (jcsj[0] * 1 >= 12 && jcsj[0] * 1 < 18) {
							e.show = 'AFTERNOON SHOWS';
							e.time_image = '../../static/img/afternoonicon.png';
						} else {
							e.time_image = '../../static/img/eveningicon.png';
							e.show = 'EVENING SHOWS';
						}
					});
					obj.list = obj.list.concat(data.data);
					if (data.data.length == obj.limit) {
						obj.loadingType = 'more';
						obj.page++;
					} else {
						obj.loadingType = 'nomore';
					}
				});
			},
			open(item) {
				if (this.wx == '' && this.aliData == '' && this.bankData == '') {
					uni.showModal({
						title: '提示',
						content: '您未填写收款信息无法参与，是否前去填写收款信息？',
						success: function(res) {
							if (res.confirm) {
								uni.navigateTo({
									url: '/pages/collection/collection'
								});
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
					return;
				}
				this.id = item.id;
				this.$refs.popup.open();
				// 场次是否已经预约sta=1未预约
			},
			goDetails(e) {
				console.log(e, '123456');
				uni.navigateTo({
					url: '/pages/index/messageInfo?id=' + this.article[e].id
				});
			},
			close() {
				this.id = '';
				this.$refs.popup.close();
			},
			navTo(url) {
				uni.navigateTo({
					url
				});
			},
			toBack() {
				uni.navigateBack({});
			},
			appointment() {
				subscribe({
						id: this.id,
						price: this.price_cate[this.actionPay]
					})
					.then(({
						data
					}) => {
						this.$api.msg('预约成功');
						console.log(data);
						this.$refs.popup.close();
						this.page = 1;
						this.limit = 10;
						this.loadingType = 'more';
						this.list = [];
						this.loadData();
						this.updata();
					})
					.catch(e => {
						this.$refs.popup.close();
						console.log(e);
					});
			},
			updata() {
				getUserInfo({})
					.then(({
						data
					}) => {
						this.setUserInfo(data);
					})
					.catch(e => {
						console.log(e);
					});
			},
			isTime(index) {
				console.log(index, '123');
				this.list[index].daotime = 1;
			}
		}
	};
</script>

<style lang="scss">
	page,
	.center {
		height: auto;
		min-height: 100%;
		background: #f2f5f4;
	}

	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}

	.money-box {
		color:$font-color-dark;
		text-align: center;
		position: relative;

		.header {
			width: 100%;
			height: 80rpx;
			font-size: 32rpx;
			font-weight: 700;
			z-index: 99;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.goback-box {
			position: absolute;
			left: 18rpx;
			top: 0;
			height: 80rpx;
			display: flex;
			align-items: center;
		}

		.goback {
			z-index: 100;
			width: 34rpx;
			height: 34rpx;
		}

		.money_bg {
			width: 100%;
			height: 382rpx;
			display: block;
		}
	}

	.shingle-mmain {
		position: relative;
		z-index: 2;
		margin: -90rpx auto 0;
		width: 690rpx;
		height: 176rpx;
		background: #ffffff;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;
		background-color: #ffffff;

		.smmain-item {
			width: 33%;
			display: flex;
			flex-direction: column;
			align-items: center;

			.red {
				color: #fd3b39 !important;
			}

			.smitem-top {
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: bolder;
				color: #0c1732;
			}

			.smitem-bottom {
				margin-top: 10rpx;
				font-size: 30rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #0c1732;
			}

			.people {
				justify-content: center;

				.peopleitem {
					width: 24rpx;
					height: 34rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}
			}
		}

		.shu {
			width: 2rpx;
			height: 70rpx;
			background: #dcdcdc;
		}
	}

	.main {
		margin: 30rpx auto 0;
		padding: 50rpx 50rpx 36rpx 50rpx;
		width: 690rpx;
		background: #ffffff;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;

		.mtitle-english {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #9ea6ba;
		}

		.mmain {
			margin-top: 24rpx;

			.mmain-info {
				.mmain-title {
					display: flex;
					justify-content: flex-start;
					align-items: center;

					.mmaint-left {
						width: 52rpx;
						height: 40rpx;
					}

					.mmaint-font {
						margin-left: 10rpx;
						font-size: 32rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #0c1732;
					}

					.mmaint-time {
						margin-left: 20rpx;
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #0c1732;
					}
				}

				.mmain-time {
					justify-content: flex-start;
					margin-top: 10rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #0c1732;

					.lyy-b-jz {
						margin-left: 10rpx;
					}
				}
			}

			.mmain-image {
				padding-top: 14rpx;
				width: 182rpx;
				height: 182rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.bottom {
			margin: 0 auto;
			margin-top: 32rpx;
			width: 440rpx;
			height: 80rpx;
			background: linear-gradient(90deg, #C38E4F, #ECC697);
			border-radius: 20rpx;
			display: flex;
			justify-content: center;
			align-items: center;

			.bottom-font {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
			}

			.bottom-image {
				margin-left: 12rpx;
				width: 24rpx;
				height: 22rpx;
			}
		}
	}

	.popup {
		width: 582rpx;
		background: #ffffff;
		border-radius: 20rpx;
		// padding: 118rpx 20rpx 30rpx;

		.popup-title {
			padding: 30rpx;
			text-align: center;
			.title {
				font-size: $font-lg;
				padding-bottom: 30rpx;
			}

			.pirice {
				font-weight: bold;
				line-height: 70rpx;
				min-width: 140rpx;
				height: 70rpx;
				border: 1px solid #9ea6ba;
				&.action{
					 color: #FFF;
					 background-color: $u-type-primary;
					 border-color: $u-type-primary;
				}
			}
		}

		.btn-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-top: 1px solid $border-color-light;
			font-size: 34rpx;
			text-align: center;
			font-weight: 500;
			line-height: 78rpx;

			.btn-left,
			.btn-right {
				flex-grow: 1;
				height: 78rpx;
			}

			.btn-left {
				color: $font-color-dark;
			}

			.btn-right {
				background: $u-type-primary;
				color: #ffffff;
			}
		}
	}

	.message {
		justify-content: space-around;
		margin: 20rpx auto 0;
		padding: 16rpx 40rpx 16rpx 50rpx;
		width: 690rpx;
		background: #ffffff;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;

		.message-left {
			width: 52rpx;
			height: 52rpx;
			flex-shrink: 0;
		}

		.message-font {
			margin: 0 40rpx;
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #0c1732;
		}

		.message-right {
			width: 18rpx;
			height: 30rpx;
		}
	}

	.hallist-bg {
		position: relative;
		z-index: 10;
		margin: 0 auto;
		width: 702rpx;
		height: 300rpx;
		border-radius: 14rpx;
		overflow: hidden;
		image {
			width: 100%;
			height: 100%;
		}
	}

	.navbar {
		display: flex;
		align-items: center;
		justify-content: space-around;
		width: 700rpx;
		background: #ffffff;
		box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;
		margin: 40rpx auto 0;
		padding: 40rpx 0 50rpx;

		.vvv {
			width: 2rpx;
			height: 74rpx;
			background: #dcdcdc;
		}

		.navbar-item {
			display: flex;
			flex-direction: column;
			align-items: center;

			.navbar-font {
				margin-bottom: 10rpx;
				display: flex;
				justify-content: center;
				align-items: center;

				image {
					margin-right: 10rpx;
					width: 40rpx;
					height: 40rpx;
				}

				.font {
					font-size: 30rpx;
					font-weight: bold;
					color: #0c1732;
				}
			}

			.navbar-num {
				font-size: 34rpx;
				font-weight: bold;
				color: #0c1732;
			}
		}
	}

	.regulation {
		width: 650rpx;
		padding: 30rpx;
		background: #ffffff;
		border-radius: 20rpx;
		position: relative;

		.regulation_close {
			position: absolute;
			width: 44rpx;
			height: 44rpx;
			top: 30rpx;
			right: 30rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.regulation_name {
			padding: 40rpx 0;
			text-align: center;
			font-size: 30rpx;
			font-weight: bold;
		}

		.scroll-view {
			height: 735rpx;
		}

		.regulation_btn {
			margin: 20rpx auto 0;
			width: 496rpx;
			height: 78rpx;
			background: #dc262b;
			border-radius: 10rpx;
			font-size: 34rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			text-align: center;
			line-height: 78rpx;
		}
	}
</style>