<template>
	<!-- 页面容器 -->
	<view class="container">
		<!-- 有数据时显示列表 -->
		<view class="list-box" v-for="(item, index) in dataList" :key="index">
			<view class="list-item" @click="handleItemClick(item)">
				<view class="item-content">
					<text class="item-title">{{ item.cbfbm }}</text>
				</view>
				<view class="item-arrow">{{ item.cbfmc }}</view>
			</view>
		</view>

		<!-- 无数据时显示空状态 -->
		<view class="empty" v-if="dataList.length === 0">
			暂无承包方需审核信息
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		getFbfquerCbflist
	} from '@/api/cgbList.js';
	import {
		onLoad
	} from '@dcloudio/uni-app';
	
	const typeData = ref(null)
	// 响应式数据
	const dataList = ref([]);
	// 存储上级传参
	let groupInfo = {};

	/**
	 * @description 根据类型获取列表数据
	 * @param {Object} params 请求参数
	 */
	const getListData = async (params) => {
		try {
			const res = await getFbfquerCbflist(params);
			dataList.value = res.data || [];
		} catch (err) {
			console.error('获取列表失败：', err);
			dataList.value = [];
		}
	};

	/**
	 * @description 列表项点击跳转
	 */
	const handleItemClick = (item) => {
		uni.navigateTo({
			url: `/pages/investigator/Households/currentDetails?groupInfo=${encodeURIComponent(JSON.stringify(item))}&typedifference=${typeData.value}&type=Auditing`
		});
	};

	onLoad(async (options) => {
		typeData.value = options.type;
		let requestParams = {};

		// 根据类型配置请求参数
		if (options.type === 'investigator') {
			// 调查员：只传 status=2
			requestParams = {
				status: 2,
				fbfbm: ''
			};
		} else if (options.type === 'official') {
			// 官方：传 status=1 + fbfbm
			try {
				groupInfo = JSON.parse(decodeURIComponent(options.groupInfo));
				requestParams = {
					status: 1,
					fbfbm: groupInfo.fbfbm || ''
				};
			} catch (e) {
				console.error('参数解析失败：', e);
				requestParams = {
					status: 1
				};
			}
		}

		// 统一调用接口
		await getListData(requestParams);
	});
</script>

<style scoped lang="scss">
	.container {
		width: 100vw;
		min-height: 100vh;
		background-color: #f5f5f5;
		padding: 20rpx;
		box-sizing: border-box;
	}

	.list-box {
		background-color: #fff;
		border-radius: 16rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
		margin-bottom: 20rpx;
	}

	.list-item {
		display: flex;
		align-items: center;
		padding: 30rpx;
		border-bottom: 1rpx solid #f0f0f0;

		&:last-child {
			border-bottom: none;
		}

		&:active {
			background-color: #f7f7f7;
		}
	}

	.item-content {
		flex: 1;
	}

	.item-title {
		font-size: 32rpx;
		color: #333;
		font-weight: 500;
	}

	.item-arrow {
		font-size: 32rpx;
		color: #999;
	}

	/* 空数据样式 */
	.empty {
		text-align: center;
		padding: 100rpx 0;
		font-size: 30rpx;
		color: #999;
	}
</style>