<template>
	<view class="container">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" :up="upOption" @down="downCallback" @up="upCallback">			
			<view>
				<view class="list-item" v-for="(item,index) in dataList" :key="index" @click="handleDetail(item)">
					{{item}} 健康报告
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {queryMonthByDeviceId} from "@/api/pages_watch/health.js"
	export default {
		data() {
			return {
				queryParam: {
					deviceId: uni.getStorageSync("deviceId") || 0,
					pageSize: 10,
					pageNum: 1,
				},
				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: []
			}
		},
		methods: {
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调*/
			upCallback(page) {   
				//联网加载数据
				var that = this;
				this.queryParam.pageNum =  page.num
				this.queryParam.pageSize = page.size
				queryMonthByDeviceId(this.queryParam).then(res => {
					if(res.code==0){
						if (page.num == 1) {
							that.dataList = res.rows; 
							
						} else {
							that.dataList = that.dataList.concat(res.rows);
							 
						}
						that.mescroll.endBySize(res.rows.length, res.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
			handleDetail(item) {
				uni.$emit('refreshReport', item);
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		padding: 24rpx;
		padding-bottom: calc(var(--window-bottom) + 24rpx);
		box-sizing: border-box;
		.list-item {
			padding: 30rpx 24rpx;
			margin-bottom: 24rpx;
			border-radius: 16rpx;
			overflow: hidden;
			background-color: #fff;
		}
	}
</style>