<template>
	<view>
		<!-- 轮播 -->
		<view v-if="banner_list.length > 0" class="padding-horizontal-main padding-top-main">
			<view style=" height: 150px; padding:10rpx;">
				<u-swiper :list="banner_list" keyName="ad_pic" showTitle :autoplay="false" circular @click="navtopage">
				</u-swiper>
			</view>

		</view>

		<view v-if="livedata.length > 0">
			<view class="padding-horizontal-main">
				<!-- 导航 -->
				<view class="spacing-nav-title">
					<text class="text-wrapper">最新直播</text>
					<navigator url="/pagesC/pages/weixinliveplayer/search/search" hover-class="none"
						class="arrow-right padding-right-xxxl cr-gray fr">
						更多
						<u-icon name="arrow-right" color="#888" size="15"></u-icon>
					</navigator>
				</view>

				<!-- 数据列表 -->
				<view class="data-list">
					<view @click="godetail(item.roomid)" v-for="(item, index) in livedata" :key="index"
						class="item padding-main border-radius-main bg-white oh pr spacing-mb">
						<view class="navigator" hover-class="none">
							<image class="fl radius" :src="item.share_img" mode="aspectFit"></image>
							<view class="base fl">
								<view class="single-text text-size">{{item.name}}</view>
								<view class="margin-top-xl oh">
									<view class="start_time">开播时间</view>
									<view class="time">
										<view class="fl cr-green text-base">{{item.start_time}}</view>
										<view class="fl cr-red text-base">{{item.end_time}}</view>
									</view>
								</view>
							</view>
							<view v-if="item.live_status==102" :class="'status pa status-' + item.live_status">未开始
							</view>
							<view v-if="item.live_status==101" :class="'status pa status-' + item.live_status">直播中
							</view>
							<view v-if="item.live_status==103" :class="'status pa status-' + item.live_status">已结束
							</view>
							<view v-if="item.live_status==105" :class="'status pa status-' + item.live_status">暂停中
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore line :status="status"></u-loadmore>
		</view>
		<view v-else>
			<u-empty text="暂时无直播" mode="list"></u-empty>
		</view>
	</view>
</template>
<script>
	const app = getApp();
	import componentNoData from "@/pagesC/components/no-data/no-data";
	import mineApi from '@/api/mine/index.js'
	export default {
		data() {
			return {
				p: 1,
				status: 'loadmore',
				data_list_loding_status: 1,
				data_bottom_line_status: false,
				data_list_loding_msg: '',
				data_list: [],
				data_base: null,
				banner_list: [
					'https://d1.shopxo.vip/static/upload/images/plugins_weixinliveplayer/2020/04/17/1587131065524716.jpg'
				],
				// 自定义分享信息
				share_info: {},
				livedata: []
			}
		},

		components: {
			componentNoData,
		},
		props: {},

		onShow() {

		},
		onLoad() {
			this.init();
			this.getimgs()
		},

		// 下拉刷新
		onPullDownRefresh() {
			this.livedata = []
			this.p = 1
			this.init();
		},
		//上拉加载
		onReachBottom() {
			let that = this
			that.p++
			mineApi.room_list({
				p: that.p
			}).then(res => {
				if (res.status == 1) {
					res.data.forEach(el => {
						that.livedata.push(el)
					})
					if (res.data.length == 10) {
						that.status = 'loadmore'
					} else {
						that.status = 'nomore'
					}
				} else {
					that.status = 'nomore'
					that.p--
				}
			})
		},

		methods: {
			godetail(id) {
				// #ifdef APP-PLUS || H5
				uni.showModal({
					title: '提示',
					content: '请到小程序中观看',
					success: res => {
						
					}
				})
				// #endif
				// #ifdef MP-WEIXIN
				var params = encodeURIComponent(JSON.stringify({
					type: 'detail'
				}));
				uni.navigateTo({
					url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${id}&custom_params=${params}`
				})
				// #endif

			},
			getimgs() {
				mineApi.roomimgs().then(res => {
					if (res.status == 1) {
						this.banner_list = res.data
					}
				})
			},
			init() {
				// 获取数据
				let that = this
				mineApi.room_list().then(res => {
					console.log(res, "直播间")
					if (res.status == 1) {
						res.data.forEach(el => {
							that.livedata.push(el)
						})
						if (res.data.length == 10) {
							that.status = 'loadmore'
						} else {
							that.status = 'nomore'
						}
					} else {
						that.status = 'nomore'
					}
					setTimeout(() => {
						uni.stopPullDownRefresh()
					}, 2000)
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.padding-horizontal-main {
		.spacing-nav-title {
			padding: 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.text-wrapper {
				font-size: 36rpx;
				color: #333;
			}

			.arrow-right {
				color: #888 !important;
				display: flex;
			}
		}
	}

	/**
	* 数据列表
	*/
	.data-list {
		overflow: scroll;

		.item {
			background-color: #fff;
			margin: 0 20rpx;
			border-radius: 20rpx;
			margin-top: 20rpx;
			box-shadow: 2px 4px 12px rgba(0, 0, 0, 0.08);

			.navigator {
				display: flex;
				justify-content: space-evenly;
				align-items: center;
				padding: 15rpx;
				position: relative;

				image {
					width: 160rpx;
					height: 160rpx !important;
					border-radius: 10rpx !important;
				}

				.base {
					width: calc(100% - 190rpx);
					text-align: left;
					padding: 0 10rpx 0 20rpx;

					.text-size {
						font-size: 32rpx !important;
					}

					.margin-top-xl {
						display: flex;
						justify-content: flex-start;
						align-items: center;
						margin-top: 20rpx;

						.start_time {
							width: 60rpx;
							background: #7ad2ff;
							line-height: 30rpx;
							font-size: 26rpx !important;
							padding: 10rpx;
							color: #fff;
							text-align: center;
							border-radius: 10rpx !important
						}

						.time {
							font-size: 26rpx !important;
							margin-left: 10rpx;

							view {
								padding: 10rpx;
							}
						}
					}
				}

				.status {
					font-size: 26rpx;
					position: absolute;
					bottom: 20rpx;
					right: 20rpx;
				}
			}
		}
	}

	.data-list .item .base .status {
		right: 20rpx;
		bottom: 20rpx;
		color: #999;
	}

	.data-list .ite .status-102 {
		color: #0e90d2;
	}

	.data-list .item .status-101 {
		color: #5eb95e;
	}

	.data-list .item .status-103 {
		color: #F37B1D;
	}

	.data-list .item .status-105 {
		color: #888;
	}
</style>
