<template>
	<view class="content">
		<view class="info">
			<image class="info-bg" src="https://cdn.his.cdwjyyh.com/images/live_broadcast_bg.png"></image>
			<view class="status_bar" :style="{height: statusBarHeight}"></view>
			<view class="shop-block">
				<view class="shop">
					<image class="w40 h40" src="https://cdn.his.cdwjyyh.com/images/shopping_car.png"></image>
				</view>
			</view>
			<view class="vedio-block">
				<view class="top">
					<view class="tab-wrapper">
						<!-- 直播 -->
						<view class="tab-item" :class="{ active: activeTab === 0 }" @click="switchTab(0)">
							<text class="tab-text">直播中</text>
							<image class="line" v-if="activeTab === 0" src="https://cdn.his.cdwjyyh.com/images/header_tabs_icon.png"
								alt="" />
						</view>
						<!-- 直播预告-->
						<view class="tab-item" :class="{ active: activeTab === 1 }" @click="switchTab(1)">
							<text class="tab-text">直播预告</text>
							<image class="line" v-if="activeTab === 1" src="https://cdn.his.cdwjyyh.com/images/header_tabs_icon.png"
								alt="" />
						</view>
					</view>
				</view>
				<!-- 视频文章列表 -->
				<mescroll-body bottom="0" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
					:down="downOption" :up="upOption">
					<view class="list" v-if="activeTab === 0">
						<view class="list-item" @click="goLive(item)" v-for="(item,index) in list" :key="index">
							<image class="img" v-if="item.liveImgUrl" :src="item.liveImgUrl" mode="widthFix"></image>
							<!-- 重庆 · 优选标签 -->
							<view class="lable">
								<view class="play-lable">
									<image class="icon" src="https://cdn.his.cdwjyyh.com/images/play.gif"></image>
								</view>
								<view class="place-label">
									重庆 · 优选
								</view>
							</view>
							<!-- 直播中标签 -->
							<view class="live-lable" v-if="false">
								<image class="icon" src="https://cdn.his.cdwjyyh.com/images/play.gif"></image>
								<text>直播中</text>
							</view>
							<view class="info-block">
								<view class="title ellipsis2">冰乳绿豆糕 冰冰凉凉谁吃谁迷糊! 谁懂，...冰乳绿豆糕 冰冰凉凉谁吃谁迷糊!</view>
								<view class="item">
									<view class="flex">
										<image class="head" src="https://cdn.his.cdwjyyh.com/images/img.png"></image>
										<text class="name">崔医生</text>
									</view>
									<view class="flex">
										<image class="icon" src="https://cdn.his.cdwjyyh.com/images/watch_number_icon.png"></image>
										<text>141</text>
									</view>
								</view>
							</view>
						</view>
					</view>
					<view class="list" v-if="activeTab === 1">
						<view class="list-item2" @click="goLive(item)" v-for="(item,index) in list" :key="index">
							<view class="img-box">
								<view class="time-block">
									<view class="date">9/11</view>
									<view class="time">20:00开播</view>
								</view>
								<image class="img" v-if="item.liveImgUrl" :src="item.liveImgUrl">
								</image>
							</view>
							<!-- <image class="video-icon" src="https://cdn.his.cdwjyyh.com/images/video_icon.png"></image> -->
							<view class="info-block">
								<view class="title ellipsis2">冰乳绿豆糕 冰冰凉凉谁吃谁迷糊! 谁懂，...冰乳绿豆糕 冰冰凉凉谁吃谁迷糊!冰乳绿豆糕 冰冰凉凉谁吃谁迷糊!
								</view>
								<view class="shop-item">
									<image class="head" src="https://cdn.his.cdwjyyh.com/images/img.png"></image>
									<text class="name">芳华悦选旗舰店</text>
								</view>
								<view class="item">
									<view class="flex">
										<image class="icon" src="https://cdn.his.cdwjyyh.com/images/reservation_icon.png"></image>
										<text class="name">245人已预约</text>
									</view>
									<view class="button">预约</view>
								</view>
							</view>
						</view>
					</view>
				</mescroll-body>
			</view>
		</view>



	</view>
</template>

<script>
	import {
		liveList
	} from '@/api/living.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				activeTab: 0,
				// 状态栏的高度
				statusBarHeight: uni.getStorageSync('menuInfo').statusBarHeight,
				list: [],
				downOption: {
					offset: 80,
					use: true,
					auto: false
				},
				upOption: {
					use: true,
					auto: true,
					page: {
						num: 0,
						size: 10
					}
				},
				mescroll: null,
			}
		},
		onLoad() {
		
		},
		onUnload() {

		},
		methods: {
			switchTab(tab) {
				if (this.activeTab === tab) return;
				this.activeTab = tab;
				this.$emit('change', tab);
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},

			// 下拉刷新回调
			downCallback(mescroll) {
				this.list = [];
				mescroll.resetUpScroll();
			},

			// 上拉加载回调
			upCallback(mescroll) {
				const pageNum = mescroll.num;
				const pageSize = mescroll.size;

				let data = {
					pageSize: pageSize,
					pageNum: pageNum,
				}
				liveList(data).then(res => {
					if (!res) {
						mescroll.endErr();
						return;
					}
					if (res.code == 200) {
						let curPageData = Array.isArray(res.data.list) ? res.data.list : [];
						let totalSize = Number(res.data.total) || 0;
						if (pageNum === 1) {
							this.list = [];
						}
						this.list = this.list.concat(curPageData);

						mescroll.endBySize(curPageData.length, totalSize);
					} else {
						mescroll.endErr();
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				}).catch(err => {
					mescroll.endErr();
				});
			},

			goLive(item) {
				uni.navigateTo({
					url: `./living?liveId=${item.liveId}`
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.ellipsis2 {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
		word-break: break-all;
	}

	.content {
		background: #F5F7FA;
		min-height: 100vh;

		.info {
			width: 100%;
			height: 600rpx;
			position: relative;
			z-index: 0;

			.shop-block {
				display: flex;
				justify-content: flex-end;

				.shop {
					width: 64rpx;
					height: 64rpx;
					padding: 12rpx;
					margin-right: 210rpx;
					border-radius: 32rpx 32rpx 32rpx 32rpx;
					border: 1rpx solid #E9E9E9;
					box-sizing: border-box;
					background: #FFFFFF;

				}
			}

			.info-bg {
				position: absolute;
				z-index: -1;
				width: 100%;
				height: 100%;
			}

			.data-block {
				padding: 0 20rpx;
				margin-top: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.number-block {
					display: flex;

					.item {
						margin-right: 32rpx;
						display: flex;
						flex-direction: column;
						align-items: center;

						.number-item {
							font-family: Roboto, Roboto;
							font-weight: 600;
							font-size: 36rpx;
							color: #FFFFFF;
						}

						.txt-item {
							margin-top: 6rpx;
							font-size: 26rpx;
							color: rgba(255, 255, 255, 0.7);
						}
					}
				}

				.button {
					width: 144rpx;
					height: 56rpx;
					background: #FFFFFF;
					border-radius: 28rpx 28rpx 28rpx 28rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 24rpx;
					color: #02B176;

					.icon {
						width: 24rpx;
						height: 24rpx;
						margin-right: 4rpx;
					}
				}
			}

			.shop-icon {
				display: flex;
				justify-content: flex-end;
				margin: 12rpx 210rpx 0 0;
			}

			//视频
			.vedio-block {
				position: relative;
				z-index: 1;
				padding: 26rpx 0;

				.top {
					display: flex;
				}
				.tab-wrapper {
					display: flex;
					height: 88rpx;
					padding: 0 40rpx;
					position: relative;

					.tab-item {
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;
						position: relative;
						font-size: 32rpx;
						color: #333333;
						margin-right: 44rpx;

						&.active {
							font-weight: 600;
							font-size: 40rpx;
						}

						.tab-text {
							font-size: 32rpx;
							transition: all 0.3s ease;
						}

						.line {
							width: 68rpx;
							height: 28rpx;
							position: absolute;
							top: 44rpx;
							z-index: -1;
						}
					}
				}
				.icon {
					display: flex;
					justify-content: flex-end;
				}

				@keyframes slideIn {
					from {
						opacity: 0;
						transform: translateX(-50%) scaleX(0.5);
					}

					to {
						opacity: 1;
						transform: translateX(-50%) scaleX(1);
					}
				}
				.list {
					padding: 24rpx 24rpx;
					display: flex;
					justify-content: space-between;
					flex-wrap: wrap;

					.list-item {
						width: 342rpx;
						margin-bottom: 18rpx;
						position: relative;
						display: flex;
						flex-direction: column;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						.lable {
							position: absolute;
							left: 16rpx;
							top: 16rpx;
							display: flex;
							text-align: center;
							border-radius: 6rpx 6rpx 6rpx 6rpx;
							overflow: hidden;
							.play-lable {
								width: 40rpx;
								height: 40rpx;
								line-height: 40rpx;
								font-size: 20rpx;
								color: #FFFFFF;
								background: linear-gradient(136deg, #38D97D 0%, #02B176 100%);
								display: flex;
								justify-content: center;
								align-items: center;
								.icon {
									width: 24rpx;
									height: 24rpx;
								}
							}
							.place-label {
								width: 106rpx;
								height: 40rpx;
								background: rgba(0, 0, 0, 0.6);
								line-height: 40rpx;
								font-size: 20rpx;
								color: #FFFFFF;
							}
						}

						.live-lable {
							position: absolute;
							left: 16rpx;
							top: 16rpx;
							display: flex;
							width: 104rpx;
							height: 40rpx;
							background: #FA341E;
							align-items: center;
							justify-content: center;
							border-radius: 6rpx 6rpx 6rpx 6rpx;
							font-size: 20rpx;
							color: #FFFFFF;

							.icon {
								width: 24rpx;
								height: 24rpx;
								margin-right: 4rpx;
							}
						}




						.img {
							width: 100%;
							border-radius: 16rpx 16rpx 0rpx 0rpx;
						}

						

						.info-block {
							border-radius: 0rpx 0rpx 16rpx 16rpx;
							padding: 12rpx 20rpx 20rpx;
							box-sizing: border-box;
							width: 100%;
							background: #FFFFFF;
							display: flex;
							flex-direction: column;

							.title {
								font-weight: 500;
								font-size: 28rpx;
								color: #333333;
								margin-bottom: 20rpx;
							}

							.item {
								display: flex;
								justify-content: space-between;
								align-items: center;
								margin-bottom: 20rpx;

								.flex {
									display: flex;
									align-items: center;
									font-size: 22rpx;
									color: #999999;
								}

								.icon {
									width: 32rpx;
									height: 32rpx;
									margin-right: 4rpx;
								}

								.head {
									width: 32rpx;
									height: 32rpx;
									border-radius: 50%;
									margin-right: 8rpx;
								}

								.name {
									color: #757575;
								}
							}

							text {
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
							}
						}
					}


					.list-item2 {
						width: 100%;
						margin-bottom: 18rpx;
						position: relative;
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-bottom: 20rpx;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						background: #ffffff;
						padding: 24rpx;

						.img-box {
							position: relative;
							width: 280rpx;
							height: 220rpx;
							overflow: hidden;
							flex-shrink: 0;
							border-radius: 16rpx 16rpx 16rpx 16rpx;
							margin-right: 24rpx;

							.time-block {
								position: absolute;
								left: 16rpx;
								top: 16rpx;
								display: flex;
								text-align: center;
								border-radius: 6rpx 6rpx 6rpx 6rpx;
								overflow: hidden;

								.date {
									width: 56rpx;
									height: 40rpx;
									line-height: 40rpx;
									font-size: 20rpx;
									color: #FFFFFF;
									background: #F4A007;
								}

								.time {
									width: 110rpx;
									height: 40rpx;
									background: rgba(0, 0, 0, 0.6);
									line-height: 40rpx;
									font-size: 20rpx;
									color: #FFFFFF;

								}
							}

							.img {
								width: 100%;
								height: 100%;
							}
						}
						.info-block {
							padding: 12rpx 20rpx 20rpx;
							box-sizing: border-box;
							width: 100%;
							display: flex;
							flex-direction: column;

							.title {
								font-weight: 500;
								font-size: 32rpx;
								color: #333333;
								margin-bottom: 12rpx;
							}

							.shop-item {
								display: flex;
								font-size: 24rpx;
								color: #666666;
								align-items: center;
								margin-bottom: 34rpx;


								.icon {
									width: 32rpx;
									height: 32rpx;
									margin-right: 12rpx;
								}

								.head {
									width: 32rpx;
									height: 32rpx;
									border-radius: 50%;
									margin-right: 8rpx;
								}

								.name {
									color: #757575;
								}
							}

							.item {
								display: flex;
								justify-content: space-between;
								align-items: center;
								font-size: 22rpx;
								color: #999999;

								.flex {
									display: flex;
									align-items: center;
								}

								.icon {
									width: 24rpx;
									height: 24rpx;
									margin-right: 8rpx;
								}

								.button {
									width: 136rpx;
									height: 64rpx;
									background: linear-gradient(136deg, #38D97D 0%, #02B176 100%);
									border-radius: 32rpx 32rpx 32rpx 32rpx;
									font-weight: 500;
									font-size: 28rpx;
									color: #FFFFFF;
									text-align: center;
									line-height: 64rpx;
								}

								.name {
									color: #757575;
								}
							}

							text {
								white-space: nowrap;
								overflow: hidden;
								text-overflow: ellipsis;
							}
						}

					}

					.list-item:nth-child(2n) {
						margin-right: 0;
					}
				}
			}

		}




	}
</style>