<template>
	<view class=" content ">
		<view class="list">
			<view class="list-item" @click="goLive(item)" v-for="(item,index) in list" :key="index">
				<image :src="item.liveImgUrl"></image>
				<view class="info">
					<text>{{item.liveName}}</text>
				</view>
			</view>

		</view>

	</view>

</template>
<script>
	import {
		liveList
	} from '@/api/list'
	// import { LiveWS } from '@/utils/liveWS'
	// import { login,loginByWeChat,getUserInfo,loginByApple } from '@/api/user'
	export default {
		data() {
			return {
				list: null,
				liveId:null
			}
		},
		onLoad(option) {
			this.getList()
		},
		methods: {
			goLive(item) {
				this.liveId = item.liveId
				console.log("要传的liveId", this.liveId)
				uni.navigateTo({
					url: `/pages/home/living?liveId=${item.liveId}&immediate=true`
					// url: `/pages/home/living?liveId=${encodeURIComponent(JSON.stringify(liveId))}`
				});
			},
			getList() {
				const data = {
					page: 1,
					page_size: 10,
				};
				uni.showLoading({
					title: "处理中..."
				});
				liveList(data)
					.then(res => {
						if (res.code == 200) {
							this.list = res.rows; // 直接赋值给 this.list
							console.log("list>>", this.list); // ✅ 打印已定义的 this.list
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}
					})
					.catch(rej => {
						console.log("请求失败:", JSON.stringify(rej));
					})
					.finally(() => {
						uni.hideLoading();
					});
			}
		}
	}
</script>

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

		.list {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;

			.list-item {
				border-radius: 16rpx;
				width: 340rpx;
				height: 600rpx;
				background-color: #0082f4;
				margin-right: 10rpx;
				margin-bottom: 24rpx;
				overflow: hidden;
				position: relative;

				.info {
					position: absolute;
					left: 20rpx;
					bottom: 14rpx;
					color: #ffffff;
				}

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

			}
		}

	}
</style>
