<template>
<view class="liveStyle" :style="{ height: contentHeight }">
    <u-empty v-if="g.length == 0" text="暂无相关直播列表" mode="list"></u-empty>

    <template
      v-if="g.length > 0"
    >
		<view style="
					height: calc(100vh - 50px);
					width: calc(100vw - 20px);
					margin-left: 10px;
					overflow: hidden;
					padding-top: 10px;
				  ">
			<scroll-view
			  :scroll-y="true"
			  :enable-back-to-top="true"
			  :enable-flex="true"
			  @scrolltolower="lower"
			  :style="{ height: '100%' ,}"
			>
			  <view class="u-good-list" >
				<u-row gutter="20">
				  <u-col span="6" v-for="(cx, ci) in g" :key="ci" >
					<view class="good" @click="clickHandler(cx)">
					  <view class="good-img">
						<image
						  mode="aspectFill"
						  :src="cx.cover_img"
						  style="width: 100%; height: 100%;"
						/>
						<!-- 播放按钮 -->
						<view class="livebtn" v-if='cx.live_status==103'></view>
						<u-icon name="play-circle-o" v-if='cx.live_status==103' color="#fff" size="100" style='position: absolute;left: 50%;top:50%;margin-left: -50rpx;margin-top: -50rpx;'></u-icon>
					  </view>
					  <view class="good-name">{{ cx.name }}</view>
					  <view class="good-info">
						<u-avatar :src="cx.anchor_img" size="30" ></u-avatar>
							  <Text style="font-size: 12px;margin-left: 5px;">{{cx.anchor_name}}</Text>		
					  </view>
					  
					  
					  
					  <!-- 直播的状态 -->
					  <view class="liveState">
						  <view style="width: 6px;height: 6px;border-radius: 3px;background: #f5f5f5;"></view>
						  <Text class='liveState_text' v-if='cx.live_status==101'>直播中</Text>
						  <Text class='liveState_text' v-if='cx.live_status==102'>未开始</Text>
						  <Text class='liveState_text' v-if='cx.live_status==103'>已结束</Text>
						  <Text class='liveState_text' v-if='cx.live_status==104'>禁播</Text>
						  <Text class='liveState_text' v-if='cx.live_status==105'>暂停</Text>
						  <Text class='liveState_text' v-if='cx.live_status==106'>异常</Text>
						  <Text class='liveState_text' v-if='cx.live_status==107'>已过期</Text>
					  </view>
					</view>
				  </u-col>
				</u-row>
			  </view>
					 <u-loadmore
					   :status="status"
					   :load-text="loadText"
					   :font-size="24"
					   :margin-top="20"
					   :margin-bottom="20"
					   bg-color="#f3f4f6"
					 />
					 
			</scroll-view>
		</view>
      
	 
    </template>
	
	<tabbars></tabbars>
  </view>
</template>

<script>
import tabbars from '@/components/tabbar/index';
export default {
	components: {
		tabbars
	},
  data() {
    return {
      mc: "",
      secondary: "",
      pageTitle: "直播列表",
	  contentHeight: 0,
	  g:[],
      msg:{
      		pageIndex: 1,
      		pageSize:10,
      },
      page_count: 1,
      status: "loadmore",
      loadText: {
        loadmore: "轻轻上拉，加载更多",
        loading: "努力加载中",
        nomore: "没有更多了",
      },
    };
  },
  onLoad(option) {
    this.mc = this.$uiConfig.mainColor;
    this.secondary = this.$uiConfig.secondary;
	let c = this.$uiConfig.is_bang ? 80 : 52;
	this.contentHeight = this.$utils.calcContentHeight(c-40) + "px";
    this.initPage();
	uni.showNavigationBarLoading();
	this.init();
    
  },
  methods: {
    initPage() {
      let currentPages = getCurrentPages();
      let u = "/" + currentPages[currentPages.length - 1].route;
      let pages = uni.getStorageSync("basedata")
        ? uni.getStorageSync("basedata").bar_title
        : [];
      pages.forEach((x) => {
        if (x.value == u) {
          this.pageTitle = x.new_name ? x.new_name : x.name;
        }
      });
      uni.setNavigationBarTitle({
        title: this.pageTitle,
      });
    },
	clickHandler(cx){
		wx.navigateTo({
		    url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${cx.roomid}`
		})
	},
    init() {
		uni.showLoading({
		    title: '加载中'
		});
		this.request2(
			{
				url: '/api/LiveHouse/GetLiveHouseList',
				data: this.msg
			},
			res => {
				uni.hideLoading();
				uni.hideNavigationBarLoading();
				if(res.resultCode==1){
					this.g = this.g.concat(res.data.pageData);
					 this.page_count = res.data.pageCount;
					 if (this.page_count == 1) {
					   this.status = "nomore";
					 }
				}
			}
		);
    },
	lower(e) {
		
		 if (this.msg.pageIndex < this.page_count) {
			this.msg.pageIndex++;
			this.status = "loading";
			this.init();
		 } else {
			this.status = "nomore";
		 }
	},
  },
};
</script>

<style>
	.liveStyle{
		background: #f3f4f6;
	}
	
	.liveStyle .u-good-list .good {
	  background: #fff;
	  border-radius: 10px;
	  overflow: hidden;
	  margin-bottom: 10px;
	  position: relative;
	}
	.liveStyle .u-good-list .good .good-img {
	  width: calc(50vw);
	  height: calc(50vw);
	  display: block;
	  position: relative;
	}
	.liveStyle .u-good-list .good .good-name {
	  overflow: hidden;
	  text-overflow: ellipsis;
	  display: -webkit-box;
	  -webkit-line-clamp: 2;
	  -webkit-box-orient: vertical;
	  margin-bottom: 3px;
	  font-size: 13px;
	  margin: 7px 10px;
	  height: 36px;
	}
	.liveStyle .u-good-list .good .good-info {
	  display: flex;
	  margin: 7px 10px;
	  margin-top: 0;
	  flex-direction: row;
	  align-items: center;
	  
	}
	.liveStyle .u-good-list .liveState{
		width: 100px;
		height: 30px;
		position: absolute;
		left: 0;
		top:0;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		background: #666666;
		opacity: 0.9;
		border-bottom-right-radius: 10px;
		border-top-left-radius: 10px;
	}
	.liveStyle .u-good-list .liveState .liveState_text{
		color: #f5f5f5;
		font-size: 14px;
		margin-left: 5px;
	}
	.liveStyle .livebtn{
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background: #999999;
		opacity: 0.3;

	}
</style>
