<template>
	<view class="content">
		<view class="bg">
			<image src="https://fs-1319721001.cos.ap-chongqing.myqcloud.com/fs/20240229/8e52ab17eabc4534b3ce56026fd5c624.jpg"></image>
		</view>
		<mescroll-body  top="0rpx"  ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="test-list">
				<view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetail(item)">
					<view class="left">
						<view class="title ellipsis2">{{ item.name }}</view>
						<view class="subtitle ellipsis2">{{ item.title }}</view>
						<view class="info-box">
							<view class="people-num"><text class="num">{{item.peopleNum}}W</text>人测过</view>  
							<view class="time">{{item.num}}题 | {{item.time}}分钟</view>
						</view>
					</view>
					<view class="right">
						<image :src="item.img" mode="aspectFill"></image>
					</view>
				</view>
			</view>
		</mescroll-body>
		
	</view>
</template>

<script>
	import {getTestList,getTestDetails} from '@/api/test.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], 
		data() {
			return {
		 
				mescroll:null,
				downOption: {   //下拉刷新
				 	use:true,
					auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
				},
				upOption: {
					onScroll:false,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						pae: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					textNoMore:"已经到底了",
					empty: {
						icon:'https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png',
						tip: '暂无数据'
					}
				},
				dataList: []
			};
		},
		onShow() {
		 
		},
		//发送给朋友
		onShareAppMessage(res) {
			if(this.utils.isLogin()){
				return {
					title: "健康自测",
					path: '/pages_index/testList',
					imageUrl: 'https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20241018/b810f26926904253ae46ea4e93b71dee.png' //分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
				}
			}
			
		},
		//分享到朋友圈
		onShareTimeline(res) {
			if(this.utils.isLogin()){
				return {
					title: "健康自测",
					imageUrl: 'https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20241018/b810f26926904253ae46ea4e93b71dee.png' //分享图标，路径可以是本地文件路径、代码包文件路径或者网络图片路径.支持PNG及JPG。显示图片长宽比是 5:4
				}
			}
			
		},
		methods:{
			  
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data = {
					pageNum: page.num,
					pageSize: page.size
				};
				getTestList(data).then(res => {
					if(res.code==200){
						//设置列表数据
						if (page.num == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			// 查看详情
			showDetail(item) {
				uni.navigateTo({
					url: './testDetails?tempId=' + item.tempId
				})
			}
		}
	}
</script>

<style lang="scss">
	 
	.content{
		position: relative;
		.bg{
			position: absolute;
			width: 100%;
			height: 100%;
			image{
				width: 100%;
				height: 100%;
			}
		}
	}
	.test-list{
		margin-top: 20upx;
		padding: 0 20upx;
		.item{
			width: 100%;
			box-sizing: border-box;
			height: 271upx;
			background: #FFFFFF;
			border: 2px solid rgba(195,154,88,0.35);
			box-shadow: -1px 4px 5px 0px rgba(153,102,51,0.25);
			border-radius: 12px;
			padding: 40upx 30upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 20upx;
			.left{
				flex: 1;
				padding-right: 40upx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				.title{
					font-size: 40rpx;
					font-family: PingFang SC;
					line-height: 48upx;
					font-weight: bold;
					color: #814E1B;
				}
				.subtitle{
					color: #814E1B;
					font-size: 28rpx;
					font-family: PingFang SC;
					margin: 10rpx 0rpx;
				}
				.info-box{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: flex-start;
					.people-num{
						font-size: 24upx;
						font-family: PingFang SC;
						color: #018C39;
						.num{
							font-weight: bold;
							color: #814E1B;
						}
					}
					.time{
						margin-left: 25upx;
						font-size: 24upx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #018C39;
					}
				}
			}
			.right{
				width: 250upx;
				height: 190upx;
				border-radius: 8upx;
				overflow: hidden;
				image{
					width: 100%;
					height: 100%;
				}
			}
		}
	}
</style>
