<template>
	<PageLayout :navbarShow="false">
		<wd-card id="top1">
			<wd-row>
				<wd-col :span="16">
					<wd-datetime-picker type="year-month" v-model="dataValue" label="填报时间" @confirm="getList" id="top1" />
				</wd-col>
				<wd-col :span="8" style="display: flex; justify-content: center;">
					<wd-button @click="clear">重置</wd-button>
				</wd-col>
			</wd-row>
		</wd-card>
		<view v-for="(item, i) in list" :key="i" @click="jump(`./HealthDetails?id=${item.id}`)">
			<wd-card
				:title="item.xm+'的'+item.createTime.substring(0,4)+'年'+item.ksny.substring(5,7)+'月'+'的健康随访填报表'">
				<view class="card-content">
					<view class="meta-info">
						<wd-icon name="usergroup" size="14px" color="#999"></wd-icon>
						<text class="meta-text">{{item.depart_dictText}}</text>
						<!-- <wd-icon name="time" size="14px" color="#999" style="margin-left: auto;"></wd-icon> -->
						<!-- <text class="meta-text">
							{{item.ksny}}</text> -->
					</view>
				</view>
			</wd-card>
		</view>
	</PageLayout>
</template>

<script setup>
	import {
		useMessage,
		useToast
	} from 'wot-design-uni'
	import SelectDept from '@/components/SelectDept/SelectDept'

	import {
		followpersonList,
		addhealthList
	} from '@/api/healthfollow/healthfllow'


	const realname = ref('') //姓名查询
	const list = ref([])
	const total = ref(0)
	const screenHeight = ref(0)
	const screenWidth = ref(0)
	const tableHeight = ref(0)
	const range = ref([]) //日期查询
	const dataValue = ref(Date.now())
	let pageNo = 1
	let pageSize = 10
	let loading = false
	
	const clear = () => {
		dataValue.value = Date.now()
		getpersonList();
	}

//按照时间状态
	const getList = () => {
		const date = new Date(dataValue.value);
		const year = date.getFullYear();
		const month = date.getMonth() + 1;
		let monthdate = '';
		if(month<10){
			monthdate = '0'+month;
		}else{
			monthdate = month;
		}
		let params = {
			
		}
		console.log("res--按时间查询-params-111-",params)
		addhealthList({
			// ...params,
			cxdata:  year + '-' + monthdate,
			pageNo,
			pageSize
		}).then(res => {
			console.log("res--按时间查询-222-",res)
			if (res.success) {
				list.value = res.result.records.map((item, index) => ({
					...item, // 保留原有字段
				}));
				total.value = res.result.total
			}
		})
	}


//无时间限制
	const getpersonList = (e)=> {
		const date = new Date();
		const year = date.getFullYear();
		const month = date.getMonth() + 1;
		let monthdate = '';
		if(month<10){
			monthdate = '0'+month;
		}else{
			monthdate = month;
		}
		let params = {
			// ksny: year + '-' + monthdate +'-01'
		}
		console.log("res--初始化----params-111-",params)
		addhealthList({
				// ...params,
				cxdata:  year + '-' + monthdate,
				pageNo,
				pageSize
			}).then((res) => {
				console.log("res--初始化---222--", res)
				if (res.success) {
					list.value = res.result.records.map((item, index) => ({
						...item, // 保留原有字段
					}));
					total.value = res.result.total
				}
			})
			.catch((err) => {
				console.log(err);
			});
	}


	/*切换页码*/
	const handleChange = ({
		value
	}) => {
		pageNo = value
		getpersonList(1)
	}

	const calculateTableHeight = () => {
		const systemInfo = uni.getSystemInfoSync();
		screenWidth.value = systemInfo.screenWidth;
		screenHeight.value = systemInfo.screenHeight;
		// 获取页面顶部元素高度（导航栏+日期选择器）
		const query = uni.createSelectorQuery();
		query.select('#top1').boundingClientRect(data => {
			const topHeight = data ? data.height : 0;
			const navHeight = 88; // 导航栏高度
			const margin = 20; // 上下边距
			// 计算表格可用高度
			tableHeight.value = screenHeight.value - topHeight - navHeight;
		}).exec();
	}
	
	const jump = (url) => {
		uni.navigateTo({
			url: url
		});
	}


	onMounted(() => {
		getpersonList();
		followpersonList();
		calculateTableHeight();
		// 监听屏幕旋转变化
		uni.onWindowResize(() => {
			calculateTableHeight();
		});
	})
	onReachBottom(() => {
		if (loading) return
		queryLeave(1); //下拉刷新传1
	})
</script>

<style>
</style>