<template>
	<div class="political-outlook">
		<div class="content">
			<div class="top-statistics">
				<div class="statistics-item" v-for="(item,index) in topDangerList" :key="index">
					<span class="title">{{item.weekBetweenStr}}</span>
					<span class="statistics-item-content">安全隐患数量：{{ item.dangerNum }}</span>
					<span class="statistics-item-content">未整改隐患次数：{{ item.rectificationNum }}</span>
					<span class="statistics-item-content">重大隐患次数：{{ item.greatFaultLevelNum }}</span>
					<span class="statistics-item-content">未销项隐患次数：{{ item.notCloseNum }}</span>
					<span class="statistics-item-content">一般隐患次数：{{ item.generalRiskNum }}</span>
				</div>
			</div>
			<div class="top-search">
				<div class="search-item">
					<span>状态</span>
					<el-select
						placeholder="请选择"
						size="small"
						v-model="searchForm.status"
						:clearable="true"
						style="width: 150px"
						@change="conditionSearch"
					>
						<el-option v-for="(item, index) in statusList" :key="index" :label="item.name" :value="item.value" />
					</el-select>
				</div>
				<div class="search-item">
					<span>问题等级</span>
					<el-select
						class="m-2"
						placeholder="请选择"
						size="small"
						v-model="searchForm.level"
						:clearable="true"
						style="width: 150px"
						@change="conditionSearch"
					>
						<el-option v-for="(item, index) in levelListData" :key="index" :label="item.name" :value="item.value" />
					</el-select>
				</div>
				<div class="search-item">
					<span>检查人</span>
					<el-select
						class="m-2"
						placeholder="请选择"
						size="small"
						v-model="searchForm.inspectManId"
						:clearable="true"
						style="width: 150px"
						@change="conditionSearch"
					>
						<el-option v-for="(item, index) in inspectBySnList" :key="index" :label="item.realName" :value="item.userId" />
					</el-select>
				</div>
				<div class="search-item">
					<span>整改人</span>
					<el-select
						class="m-2"
						placeholder="请选择"
						size="small"
						v-model="searchForm.changeId"
						:clearable="true"
						style="width: 150px"
						@change="conditionSearch"
					>
						<el-option v-for="(item, index) in inspectList" :key="index" :label="item.realName" :value="item.userId" />
					</el-select>
				</div>
				<div class="search-item">
					<span>分包单位</span>
					<el-select
						class="m-2"
						placeholder="请选择"
						size="small"
						v-model="searchForm.enterpriseId"
						:clearable="true"
						style="width: 150px"
						@change="conditionSearch"
					>
						<el-option v-for="(item, index) in enterpriseListData" :key="index" :label="item.enterpriseName" :value="item.id" />
					</el-select>
				</div>
				<!-- <el-button @click="getMemberCountList('search')">查询</el-button> -->
			</div>
			<div class="table-one">
				<div class="tabList">
					<div>序号</div>
					<div>状态</div>
					<div>问题等级</div>
					<div>隐患部位</div>
					<div>隐患描述及要求</div>
					<div>整改时限</div>
					<div>检查人</div>
					<div style="width: 15%;">检查时间</div>
					<div>整改人</div>
					<div>分包单位</div>
				</div>
				<el-scrollbar class="listBox" ref="refScrollbar">
					<div v-for="(item, index) in partyMemberList" class="listStyle" :key="item.id">
						<div>{{index + 1}}</div>
						<div>{{item.status?textFilter(item.status):''}}</div>
						<div>{{item.level?levelListData[item.level - 1].name:''}}</div>
						<div>{{item.regionName}}</div>
						<div>
							<el-tooltip class="box-item" effect="dark" :content="item.dangerItemContent" placement="top-start">
								<span>{{item.dangerItemContent}}</span>
							</el-tooltip>
						</div>
						<div>
							<el-tooltip class="box-item" effect="dark" :content="item.changeLimitTime" placement="top-start">
								<span>{{item.changeLimitTime}}</span>
							</el-tooltip>
						</div>
						<div>{{item.inspectManName}}</div>
						<div style="width: 15%;">{{item.inspectTime}}</div>
						<div>{{item.changeName}}</div>
						<div>{{item.enterpriseName}}</div>
					</div>
					<div class="notoDta" v-if="partyMemberList.length == 0">
						<img src="@/assets/images/noData.png" alt="" />
						<p>暂无数据</p>
					</div>
				</el-scrollbar>
			</div>
		</div>
	</div>
</template>

<script lang="ts" setup>
import { ref, onMounted } from "vue";
import { GlobalStore } from "@/stores";
import { getCompanyDataList, getMemberInfoList } from "@/api/modules/labor";
import { getQualityStatisticsNumDataApi, getProjectEnterpriseApi, getSystemUserApi,getSystemUserBySnApi, getInspectionRecordApi } from "@/api/modules/agjtCommandApi";
const store = GlobalStore();
const props = defineProps(["tip"]);
const BASEURL = import.meta.env.VITE_API_URL;
const inspectList = ref([] as any);
const inspectBySnList = ref([] as any);
const enterpriseListData = ref([] as any);
const levelListData = ref([
	{ name: "一级", value: 1 },
	{ name: "二级", value: 2 },
	{ name: "三级", value: 3 },
	{ name: "四级", value: 4 }
])
const statusList = ref([
	// { name: "无需整改", value: 1 },
	{ name: "待整改", value: 2 },
	{ name: "待复查", value: 3 },
	{ name: "待核验", value: 4 },
	{ name: "合格", value: 5 },
	{ name: "已撤回", value: 6 },
	{ name: "超期未关闭", value: 7 },
]);
let pageNo = ref(1 as any);
let moreScroll = ref(true as any);
const refScrollbar = ref(null as any); // 绑定到滚动的盒子上
const searchForm = ref({
	status: '',
	inspectManId: '',
	changeId: '',
	enterpriseId: '',
	level: ''
});
const topDangerList = ref([] as any)
const partyMemberList = ref({} as any);
// 文本处理
const textFilter = (val:any) => {
	let findItem:any = statusList.value.find(item => {
		return item.value == val;
	})
	return findItem.name
}
// 条件查询
const conditionSearch = async () => {
	getMemberCountList('search')
}
// 获取检查人
const getSystemUserBySn = async () => {
	let data = {
		sn: store.sn,
		queryType: "projectLevelAndChildren",
	};
	const res: any = await getSystemUserBySnApi(data);
	if (res.code == 200) {
		inspectBySnList.value = res.result;
	}
};
// 获取整改人
const getSystemUserFn = async () => {
	let data = {
		projectSn: store.sn
	};
	const res: any = await getSystemUserApi(data);
	if (res.code == 200) {
		inspectList.value = res.result;
	}
};
// 获取分包单位
const getDivisionUnitFn = async () => {
	let data = {
		projectSn: store.sn,
        pageNo: 1,
        pageSize: 999
	};
	const res: any = await getProjectEnterpriseApi(data);
	if (res.code == 200) {
		enterpriseListData.value = res.result.records;
	}
};
// 获取顶部数据
const getQualityStatisticsNumDataFn = async () => {
	let data = {
		projectSn: store.sn,
		isStatsByWeek: 1
	};
	const res: any = await getQualityStatisticsNumDataApi(data);
	if (res.code == 200) {
		topDangerList.value = res.result || []
	}
};

//获取企业列表
const getCompanyList = async () => {
	let data = {
		projectSn: store.sn,
		enterpriseName: "",
		userEnterpriseId: store.userInfo?.userEnterpriseId
	};
	const res: any = await getCompanyDataList(data);
	if (res.code == 200) {
		enterpriseListData.value = res.result;
	}
};
//获取数据
const getMemberCountList = async (tip:any) => {
	let requestData:any = {
		projectSn: store.sn,
		...searchForm.value,
		pageNo: tip == 'search'?1:pageNo.value,
		pageSize: 100,
		recordType: 1,
	}
	if(props.tip == '实时'){
		requestData.presence = 1;
	} else if(props.tip == '日累积') {
		requestData.attendance = 1;
	} else {
		requestData.inserviceType = 1;
	}
	const res: any = await getInspectionRecordApi(requestData);
	if(tip == 'more'){
		partyMemberList.value = partyMemberList.value.concat(res.result.page.records);
	} else {
		partyMemberList.value = res.result.page.records;
	}
	// 为图片拼接IP
	// partyMemberList.value.map((item:any) => {
	// 	item.fieldAcquisitionUrl = BASEURL + '/image/' + item.fieldAcquisitionUrl
	// })
	if (res.result.pages == pageNo.value) {
		moreScroll.value = false;
	} else {
		pageNo.value = pageNo.value + 1;
	}
};

onMounted(async () => {
	await getCompanyList();
	await getDivisionUnitFn();
	await getSystemUserBySn();
	await getSystemUserFn();
	await getQualityStatisticsNumDataFn();
	await getMemberCountList('search');
	refScrollbar.value.wrapRef.addEventListener("scroll", (e: any) => {
		const scrollTop = e.target.scrollTop;
		const scrollHeight = e.target.scrollHeight;
		const clientHeight = e.target.clientHeight;
		// 向上加载更多
		if (scrollTop >= scrollHeight - clientHeight - 1) {
			if (moreScroll.value) {
				getMemberCountList("more");
			}
		}
	});
});
</script>

<style>
.el-select-dropdown{
	width: 180px;
}</style>
<style lang="scss" scoped>

@mixin flex {
	display: flex;
	align-items: center;
}
.political-outlook {
	height: 97%;
	margin: 0 60px;
	.content {
		height: 95%;
		width: 100%;
		margin-top: 10px;
		// background: url("@/assets/images/cardImg.png") no-repeat;
		background-size: 100% 100%;
		padding: 20px 2px;
		.top-statistics{
			width: 60%;
			display: grid;
			grid-template-columns: repeat(2, 1fr);
			grid-gap: 20px;
			color: white;
			margin: 0 auto;
			padding: 20px 0;
			.statistics-item{
				width: 90%;
				// width: 450px;
				// height: 95px;
				padding-bottom: 10px;
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;
				align-items: center;
				position: relative;
				.title{
					position: absolute;
					top: 4%;
					left: 4%;
				}
				&-content{
					display: inline-block;
					width: 50%;
					height: auto;
					text-indent: 1.5em;
				}
				&-content:nth-child(2){
					margin-top: 8%;
				}
				&-content:nth-child(3){
					margin-top: 8%;
				}
			}
			.statistics-item:nth-child(1){
				background: url("@/assets/images/commandScreen/bg6.png") no-repeat;
				background-size: 100% 100%;
			}
			.statistics-item:nth-child(2){
				background: url("@/assets/images/commandScreen/bg2.png") no-repeat;
				background-size: 100% 100%;
			}
			.statistics-item:nth-child(3){
				background: url("@/assets/images/commandScreen/bg4.png") no-repeat;
				background-size: 100% 100%;
			}
			.statistics-item:nth-child(4){
				background: url("@/assets/images/commandScreen/bg1.png") no-repeat;
				background-size: 100% 100%;
			}
			.statistics-item:nth-child(5){
				background: url("@/assets/images/commandScreen/bg3.png") no-repeat;
				background-size: 100% 100%;
			}
			.statistics-item:nth-child(6){
				background: url("@/assets/images/commandScreen/bg5.png") no-repeat;
				background-size: 100% 100%;
			}
		}
		.top-search {
			@include flex;
			justify-content: center;
			margin-bottom: 15px;
			margin-top: 20px;
			.search-item {
				@include flex;
				margin-right: 20px;
				span {
					color: white;
					margin-right: 10px;
				}
			}
		}
		.table-one{
			height: 50%;
			.tabList {
				display: flex;
				// width: 100%;
				height: 10%;
				background: url("@/assets/images/vehicleManagement/ListTitleImg.png") no-repeat;
				background-size: 100% 100%;
				// position: absolute;
				left: 75.5%;
				top: 75%;
				color: #ccc;
				font-size: calc(100vw * 14 / 1920);
				line-height: 30px;
				align-items: center;
				margin-top: 2%;
				div {
					text-align: center;
					width: 10%;
				}
			}
			.listBox {
				height: 69%;
				.listStyle {
					display: flex;
					align-items: center;
					text-align: center;
					color: #fff;
					font-size: 12px;
					margin-bottom: 5px;
					.list-img {
						.el-img {
							width: 30px;
							height: 30px;
							img {
								display: flex;
								align-items: center;
								width: 100%;
								height: 100%;
							}
						}
					}
					div {
						width: 10%;
						white-space: nowrap; //单行
						overflow: hidden;
						text-overflow: ellipsis;
					}
				}
				.listStyle:hover {
					background: #091f3f;
				}
			}
		}
		:deep(){
			.el-tabs__item{
				color: white;
			}
			.el-tabs__item.is-active{
				color: var(--el-color-primary)
			}
		}
	}
}
.notoDta {
	top: 20%;
	width: 20%;
	left: 40%;
	position: absolute;
	text-align: center;
	img {
		width: 40%;
		margin: 5% 30%;
	}
	p {
		color: #fff;
		font-size: calc(100vw * 14 / 1920);
		margin: -6% 37%;
	}
}
// element 组件样式
:deep() {
	.el-date-editor .el-range-input,
	.el-range-separator {
		color: #fff;
	}
	.el-input__wrapper {
		background: #112d59;
	}
	.el-input__inner {
		color: #fff;
	}
	.el-button {
		background-color: #2758c0;
		color: white;
		border-color: transparent;
	}
}
// ::v-deep .el-select .el-input .el-select__caret {
// 	color: #fff;
// }
</style>
