<template>
	<view class="content">


		<mescroll-body bottom="0" ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback"
			:down="downOption" :up="upOption">
			<!-- <view class="list">
				<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"></image>
					<view class="info">
						<text>{{item.liveName}}</text>
					</view>
				</view>
			</view> -->

			<view class="list">
				<view class="left">
					<view class="label">
						<view class="">9/11</view>
						<view class="">20:00开播</view>
					</view>
					<image src="https://cdn.his.cdwjyyh.com/images/img.png"></image>
				</view>
				<view class="right">
					<view class="title">秋季常见问题儿科专家直播</view>
					<view class="shop-item">
						<image class="shop-img" src="https://cdn.his.cdwjyyh.com/images/img.png"></image>
						<text class="shop">芳华悦选旗舰店</text>
					</view>
					<view class="trailer-button">
						<image class="icon" src="https://cdn.his.cdwjyyh.com/images/img.png"></image>
						<text class="txt">245人已预约</text>
						<view class="button">预约</view>
					</view>
				</view>
			</view>

		</mescroll-body>
	</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 {

				list: [],
				downOption: {
					offset: 80,
					use: true,
					auto: false
				},
				upOption: {
					use: true,
					auto: true,
					page: {
						num: 0,
						size: 10
					}
				},
				mescroll: null,
			}
		},
		onLoad() {
			// if (!uni.getStorageSync("AppToken")) {
			// 	uni.navigateTo({
			// 		url: '/pages/auth/login'
			// 	});
			// }
		},
		onUnload() {

		},
		methods: {
			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({
					// &immediate=true
					url: `./living?liveId=${item.liveId}`
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #111;
		min-height: 100vh;
		padding: 24rpx;

		.list {
			display: flex;
			justify-content: space-between;
			.left{
				width: 280rpx;
				height: 220rpx;
				background: #F29696;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				position: relative;
				overflow: hidden;
				.label{
					position: absolute;
					left: 16rpx;
					top: 16rpx;
				}
			}
			.right{
				.title{
					font-weight: 500;
					font-size: 32rpx;
					color: #333333;
				}
					
				.shop-item{
					.shop-img{
						width: 32rpx;
						height: 32rpx;
						background: #02B176;
						margin-right: 12rpx;
					}
					.shop{
						font-size: 24rpx;
						color: #666666;
					}
				}
				.trailer-button{
					display: flex;
					justify-content: space-between;
					align-items: center;
					.button{
						display: flex;
									justify-content: space-between;
					}
				}
			}
		}
	}
</style>