<template>
	<view class="container">
		<view class="safe_content">
			<view>
				<view>
					<view></view>
					<view class="el-statistic">
						<view class="head">
							隐患总数
						</view>
						<view class="con">
							{{safeDetailInfo.dangerNum}}
						</view>

					</view>
				</view>
				<view>
					<view></view>
					<view class="el-statistic">
						<view class="head">
							已整改数
						</view>
						<view class="con">
							{{safeDetailInfo.rectificationDoneNum}}
						</view>

					</view>
				</view>
				<view>
					<view></view>
					<view class="el-statistic">
						<view class="head">
							已逾期数
						</view>
						<view class="con">
							{{safeDetailInfo.overdueNotCloseNum}}
						</view>

					</view>
				</view>
				<view>
					<view></view>
					<view class="el-statistic">
						<view class="head">
							已逾期数
						</view>
						<view class="con">
							{{safeDetailInfo.reviewNum}}
						</view>

					</view>
				</view>
			</view>
			<view>
				<image src="/static/bthgIcon/bg_mass.png" />
				<view class="">
					<view class="safe_content_scroll_title">
						<view>涉及技术专业</view>
						<view>问题占比</view>
						<view>问题数量</view>
					</view>
					<!-- <scroll-view scroll-y>
						
					</scroll-view> -->
					<view class="safe_content_scroll">
						<view v-for="(item, index) in safeProblemList" :key="index">
							<view>{{ item.name }}</view>
							<view>{{ item.percent }}%</view>
							<view>{{ item.count }}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="columnCharts_container">
			<view class="container_title">
				EPC责任单位问题分析
			</view>
			<view class="columnCharts">
				<view class="columnCharts_boxs" v-if="columnChart1.textDataX.length != 0">
					<u-charts canvas-id="columnChart1" chartType="column" :opts="columnChart1" ref="columnChart1"
						:cWidth="cWidth" :cHeight="cHeight" :legends="false" />
					<view class="columnCharts_top">
						问题数量
					</view>
					<view class="columnCharts_right">
						单位名称
					</view>
				</view>
				<view class="no_data" v-if="columnChart1.textDataX.length == 0">
					<image src="/static/bthgIcon/noData.png"></image>
					<view>暂无数据</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import uCharts from '@/components/u-charts/component.vue';
	import { pxToRpx } from "@/utils/tool.js";
	export default {
		components: {
			uCharts,
		},
		data() {
			return {
				projectSn: "",
				cWidth: 0,
				cHeight:0,
				safeDetailInfo: {},
				safeProblemList: [],
				columnChart1: {
					categories: [],
					textDataX:[],
					series: [{
						// name: "温度",
						data: []
					}]
				},
				pieChart1: {
					title: {
						name: "",
						color: '#7cb5ec',
						fontSize: 25,
						offsetY: 0,
					},
					series: [{
							"data": 0,
							color: '#3BA1FF',
							name: '未开始'
						},
						{
							"data": 0,
							color: '#FBC02D',
							name: '进行中'
						}, {
							"data": 0,
							color: '#0CE4D1',
							name: '已完成'
						},
					]
				}
			}
		},
		created() {
			// const that = this;
			// uni.getSystemInfo({
			// 	success: function(res) {
			// 		that.cWidth = res.windowWidth - pxToRpx(28) - pxToRpx(24);
			// 	}
			// });
		},
		mounted() {
			const that = this;
			uni.getSystemInfo({
				success: function(res) {
					console.log(res.windowWidth);
					console.log(11111, res.windowHeight);
					that.cWidth = res.windowWidth - uni.upx2px(96) - uni.upx2px(44);
					that.cHeight = uni.upx2px(450)
				}
			});
			this.projectSn = JSON.parse(uni.getStorageSync('projectDetail')).projectSn;
			this.getHomePageSafeApi();
		},
		onShow() {

		},
		onLoad(options) {

		},
		methods: {
			// 安全管理
			getHomePageSafeApi() {
				const that = this;
				let data = {
					projectSn: this.projectSn,
				};
				console.log(this.projectSn)
				this.sendRequest({
					url: 'xmgl/homePage/countQuality',
					data,
					method: 'post',
					success(res) {
						console.log('安全管理安全隐患统计', res);
						if (res.code == 200) {
							that.safeDetailInfo = res.result;
						}
					}
				})
				this.sendRequest({
					url: 'xmgl/homePage/countQualityResponsibleUnit',
					data,
					method: 'post',
					success(res) {
						console.log('安全管理EPC责任单位统计', res);
						if (res.code == 200) {
							const resultList = res.result;
							that.columnChart1.textDataX = resultList.map(item => item.x);
							that.columnChart1.categories = resultList.map(item => item.x);
							that.columnChart1.series = [{
								// name: "温度",
								data: resultList.map(item => item.y ? item.y : 0)
							}]
							console.log(that.columnChart1)
							if(that.columnChart1.textDataX.length > 0) {
								that.$nextTick(() => {
									that.$refs.columnChart1.changeData('columnChart1', that.columnChart1)
								})
							}
							
							
						}
					}
				})
				this.sendRequest({
					url: 'xmgl/homePage/countQualityTechnology',
					data,
					method: 'post',
					success(res) {
						console.log('安全管理问题分类统计', res);
						if (res.code == 200) {
							that.safeProblemList = res.result.data;
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.no_data {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		text-align: center;
		color: rgba(0, 0, 0, 0.5);
		font-size: 28rpx;
	
		uni-image {
			width: 300rpx;
			height: 300rpx;
			display: block;
			margin: 0 auto;
		}
	}
	.container {
		margin-top: 24rpx;
		// padding: 0 20rpx 20rpx;

		.columnCharts_container {
			padding: 0 32rpx;
			.columnCharts {
				// min-height: 490rpx;
				min-height: 450rpx;
				width: calc(100%);
				background: #FFFFFF;
				box-shadow: 0px 10rpx 20rpx 0px rgba(46, 91, 255, 0.2);
				border-radius: 8rpx;
				border: 2rpx solid rgba(102, 111, 232, 0.08);
				padding: 24rpx;
				margin-top: 20rpx;
				position: relative;
				
				.columnCharts_boxs {
					    display: flex;
					    align-items: flex-end;
					    width: 100%;
				}

				.columnCharts_top {
					position: absolute;
					top: 0;
					left: 18rpx;
					font-size: 24rpx;
				}

				.columnCharts_right {
					position: relative;
					bottom:2.2vh;
					left: 10rpx;
					font-size: 24rpx;
					// width: 104rpx;
					width: 20%;
				}
			}
		}
		.safe_content {
			>view:first-child {
				display: flex;
				height: 140rpx;
				// background-color: #E9F2FF;
				background-color: #FFFFFF;
				// border-radius: 16rpx;
				padding: 0 24rpx;

				>view:nth-child(1) {
					>view:first-child {
						border: 6rpx solid #7caaf9;
					}
				}

				>view:nth-child(2) {
					>view:first-child {
						border: 6rpx solid #98e87a;
					}
				}

				>view:nth-child(3) {
					>view:first-child {
						border: 6rpx solid #f97c7c;
					}
				}

				>view:nth-child(4) {
					>view:first-child {
						border: 6rpx solid #98e87a;
					}
				}

				>view {
					width: 25%;
					display: flex;
					// align-items: center;

					>view:first-child {
						width: 30rpx;
						height: 30rpx;
						background-color: white;
						border-radius: 50%;
						margin-left: 10rpx;
						margin-top: 30rpx;
					}

					.el-statistic {
						flex: 1;
						text-align: left;
						margin-left: 16rpx;
						display: flex;
						flex-direction: column;
						justify-content: center;

						.head {
							color: #666666;
							font-size: 28rpx;
						}

						.con {
							color: #0056a8;
							font-weight: bold;
							justify-content: flex-start;
							font-size: 44rpx;
						}
					}
				}
			}

			>view:last-child {
				margin-top: 40rpx;
				display: flex;
				align-items: center;
				// height: 284rpx;

				// align-items: center;
				>image {
					width: 228rpx;
					height: 160rpx;
				}
				
				>view {
					flex: 1;
					margin-left: 20rpx;
				}
				
				.safe_content_scroll_title {
					width: 100%;
					display: flex;
					font-size: 28rpx;
					color: #707070;
				
					>view:first-child {
						font-size: 28rpx;
						color: #444444;
						position: relative;
						margin: 0 32rpx;
						width: 39%;
						text-align: center;
					}
				
					>view:not(:first-child) {
						// margin: 0 32rpx;
						width: 30%;
						text-align: center;
					}
				
					>view:nth-child(2) {
						// margin-left: 64rpx;
						width: 30%;
						text-align: center;
					}
				}
				

				.safe_content_scroll {
					margin-top: 20rpx;
					// max-height: 284rpx;

					>view:not(:first-child) {
						margin-top: 40rpx;
					}

					>view {
						display: flex;
						font-size: 28rpx;
						color: #707070;
						cursor: pointer;

						>view:first-child {
							font-size: 32rpx;
							color: #444444;
							position: relative;
							margin: 0 32rpx;
							width: 34%;
							text-align: center;
						}

						>view:first-child::after {
							content: '';
							position: absolute;
							left: -30rpx;
							top: 50%;
							transform: translateY(-50%);
							width: 20rpx;
							height: 20rpx;
							border-radius: 50%;
							background-color: #3ba1ff;
						}

						>view:first-child::before {
							content: '';
							position: absolute;
							right: -36rpx;
							top: 50%;
							transform: translateY(-50%);
							width: 4rpx;
							height: 90%;
							background-color: #d9d9d9;
						}

						>view:not(:first-child) {
							// margin: 0 32rpx;
							width: 27%;
							text-align: center;
						}

						>view:nth-child(2) {
							// margin-left: 64rpx;
							width: 27%;
						}
					}
				}
			}


		}

	}

	.container_title {
		font-size: 30rpx;
		font-weight: bold;
		position: relative;
		margin-left: 20rpx;
		margin-bottom: 16rpx;
		margin-top: 32rpx;
		color: #2D8EF3;
	}
	
	.container_title::after {
		content: '';
		position: absolute;
		left: -20rpx;
		top: 50%;
		width: 4rpx;
		height: 80%;
		transform: translateY(-50%);
		background-color: #2D8EF3;
	}
</style>