<!-- 数据看板-安全隐患 -->
<template>
	<view class="hazardSources">
		<!-- 计划列表 -->
		<picker @change="bindPickerChange" :value="pickerIndex" :range="pickerList" range-key="planTitle">
			<view class="small-title">
				<view class="small-title-l">{{pickerList[pickerIndex].planTitle}}</view>
				<img class="small-title-r" :src="imagesUrl('commonality/icon_06.png')">
			</view>
		</picker>
		<view class="chart">
			<!-- 图表选项卡 -->
			<view class="chart-t">
				<view class="chart-t-li" :class="chartIndex==index?'color-A':'color-B'" @click="chartClick(index)"
					v-for="(item,index) in chartTitle">{{item}}</view>
			</view>
			<!-- 安全隐患排行-图表 -->
			<view class="chart-b" v-if="chartIndex==0">
				<qiun-data-charts :canvas2d="true" type="column" :opts="opts" :echartsH5="true" :chartData="chartData" />
			</view>
			<!-- 一级指标排行-图表 -->
			<view class="chart-b2" v-if="chartIndex==0">
				<view class="chart-b2-li" v-for="(item,index) in hiddenChartBottom">
					<view class="chart-b2-li-t">
						<text>{{index+1}}</text>
						<text>{{item.name}}</text>
					</view>
					<view class="chart-b2-li-b">{{item.total}}</view>
				</view>
			</view>
			<!-- 暂无法整改-图表 -->
			<view class="chart-b-tow" v-if="chartIndex==1 || chartIndex==2">
				<qiun-data-charts :canvas2d="true" :tapLegend="false" :tooltipShow="false" type="bar" :opts="optsTow"
					:echartsH5="true" :chartData="chartDataTow" />
			</view>
		</view>
		<!-- 选项卡 -->
		<scroll-view scroll-x @scrolltolower="scrollGet" v-if="chartIndex!=0">
			<view class="tabTitle_tow">
				<view class="tabTitle_tow_li" @tap="tabClickTow(item,index)" :key="index" v-for="(item,index) in tabTextTow">
					<view :class="{on:curTabTow==index}" class="tabTitle_tow_text">{{item}}</view>
					<view :class="{on:curTabTow==index}" class="tabTitle_tow_across"></view>
				</view>
			</view>
		</scroll-view>
		<!--安全隐患排行 -->
		<view class="table" v-if="chartIndex==0">
			<uni-card>
				<view style="height: 200px">
					<zb-table :columns="column" :stripe="false" :border="false" :data="dataList"></zb-table>
				</view>
			</uni-card>
		</view>
		<!-- 一级指标排行 -->
		<view class="table-tow" v-if="chartIndex!=0 && curTabTow==0">
			<uni-card>
				<view style="height: 200px">
					<zb-table :columns="column2" :stripe="false" :border="false" :data="dataListTow"></zb-table>
				</view>
			</uni-card>
		</view>
		<!--学院单位 -->
		<view class="table-three" v-if="chartIndex!=0 && curTabTow==1">
			<uni-card>
				<view style="height: 200px">
					<zb-table :columns="column3" :stripe="false" :border="false" :data="dataListThree"></zb-table>
				</view>
			</uni-card>
		</view>
	</view>
</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {
		securityCheckPlanPlantList,
		reportAppStatisticsDangerSort,
		securityCheckDangerNotHazardOneCollect,
		securityCheckDangerHazardOneCollect,
	} from '@/pages/api/index.js'
	export default {
		name: "hazardSources",
		components: {

		},
		data() {
			return {
				chartType: 3,
				chartTitle: ['安全隐患排行', '一级指标排行', '暂无法整改'],
				chartIndex: 0,
				opts: {
					color: ["#149F12", "#FF0000", "#FF9D25", ],
					padding: [15, 15, 4, 5],
					enableScroll: false,
					legend: {
						position: 'top',
						fontColor: '#fff',
					},
					xAxis: {
						disableGrid: true,
						disabled: true,
						axisLine: false,
					},
					yAxis: {
						disableGrid: true,
						data: [{
							disabled: true,
						}]
					},
					extra: {
						column: {
							type: "group",
							width: 14,
							linearType: "opacity",
							linearOpacity: 0.6,
						}
					}
				},
				optsTow: {
					rotate: false,
					rotateLock: false,
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
					padding: [15, 20, 15, 0],
					dataLabel: true,
					enableScroll: false,
					fontColor: '#ffffff',
					legend: {
						show: false,
					},
					xAxis: {
						disabled: true,
						disableGrid: true,
						axisLine: false,
						fontColor: '#fff',
					},
					yAxis: {},
					extra: {
						bar: {
							type: "group",
							width: 15,
							meterBorde: 1,
							meterFillColor: "#FFFFFF",
							activeBgColor: "#000000",
							activeBgOpacity: 0.08,
							linearType: "custom",
							barBorderCircle: true,
							seriesGap: 2,
							categoryGap: 2
						}
					}
				},
				chartData: {},
				chartDataTow: {},
				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 10,
				},
				column: [{
						type: 'index',
						label: '排行',
						fixed: true,
						width: 60,
						align: 'center',
					},
					{
						name: 'deptSortName',
						label: '学院单位',
						fixed: true,
						width: 80,
						align: 'center',
					},
					{
						name: 'totalNum',
						label: '总隐患',
						align: 'center',
					},
					{
						name: 'rectifyNum',
						label: '已整改',
						align: 'center',
					},
					{
						name: 'notRectifyNum',
						label: '未整改',
						align: 'center',
					},
					{
						name: 'tempNum',
						label: '暂无法整改',
						align: 'center',
					},

				],
				column2: [{
						type: 'index',
						label: '序号',
						fixed: true,
						width: 60,
						align: 'center',
					},
					{
						name: 'name',
						label: '一级指标',
						fixed: true,
						width: 80,
						align: 'center',
					},
					{
						name: 'num',
						label: '隐患数',
						align: 'center',
					},
					{
						name: 'ratio',
						label: '占比',
						align: 'center',
					},

				],
				column3: [{
						type: 'index',
						label: '排行',
						fixed: true,
						width: 60,
						align: 'center',
					},
					{
						name: 'deptSortName',
						label: '学院单位',
						fixed: true,
						width: 80,
						align: 'center',
					},
					{
						name: 'hazardNum',
						label: '总隐患',
						align: 'center',
					},
				],
				dataList: [],
				dataListTow: [],
				dataListThree: [],
				total: 0,
				tabTextTow: ['一级指标', '学院单位'],
				curTabTow: 0,
				pickerList: [],
				pickerIndex: 0,
				hiddenChartBottom: [],

			}
		},
		created() {

		},
		beforeMount() {

		},
		mounted() {
			this.securityCheckPlanPlantList();

		},
		methods: {
			scrollGet() {

			},
			bindPickerChange(data) {
				console.log(data)
				this.pickerIndex = data.detail.value;
				if (this.chartIndex == 0) {
					//安全隐患排行
					this.reportAppStatisticsDangerSort(this.pickerList[this.pickerIndex].planId)
				} else if (this.chartIndex == 1) {
					//一级指标排行
					this.dataListTow = [];
					this.dataListThree = [];
					this.chartDataTow = {};
					this.securityCheckDangerHazardOneCollect(this.pickerList[this.pickerIndex].planId)
				} else if (this.chartIndex == 2) {
					//暂无法整改
					this.dataListTow = [];
					this.dataListThree = [];
					this.chartDataTow = {};
					this.securityCheckDangerNotHazardOneCollect(this.pickerList[this.pickerIndex].planId)
				}
			},
			chartClick(index) {
				this.chartIndex = index;
				this.curTabTow = 0;
				if (this.chartIndex == 0) {
					//安全隐患排行
					this.reportAppStatisticsDangerSort(this.pickerList[this.pickerIndex].planId)
				} else if (this.chartIndex == 1) {
					//一级指标排行
					this.securityCheckDangerHazardOneCollect(this.pickerList[this.pickerIndex].planId)
				} else if (this.chartIndex == 2) {
					//暂无法整改
					this.securityCheckDangerNotHazardOneCollect(this.pickerList[this.pickerIndex].planId)
				}
			},
			//顶部tab点击
			tabClickTow(item, index) {
				this.curTabTow = index;

			},
			//计划标题
			async securityCheckPlanPlantList() {
				let self = this;
				const {
					data
				} = await securityCheckPlanPlantList();
				if (data.code == 200) {
					this.pickerList = data.data
					this.reportAppStatisticsDangerSort(this.pickerList[0].planId)

				}
			},
			//安全隐患列表数据
			async reportAppStatisticsDangerSort(planId) {
				let self = this;
				const {
					data
				} = await reportAppStatisticsDangerSort({
					'type': '-1',
					'planId': planId
				});
				if (data.code == 200) {
					this.dataList = data.data;
					if (data.data[0]) {
						let name = [];
						let list = [];
						let list2 = [];
						let list3 = [];
						let num = 0;
						self.hiddenChartBottom = [];
						data.data.forEach(function(item, index) {
							if (index < 3) {
								name.push(item.deptSortName)
								list.push(item.rectifyNum)
								list2.push(item.notRectifyNum)
								list3.push(item.tempNum)
								num = item.rectifyNum + item.notRectifyNum + item.tempNum
								self.hiddenChartBottom.push({
									'name': item.deptSortName,
									'total': num
								})
							}
						})
						let res = {
							categories: name,
							series: [{
									name: "已整改",
									textColor: '#fff',
									data: list

								},
								{
									name: "未整改",
									textColor: '#fff',
									data: list2
								},
								{
									name: "暂无法整改",
									textColor: '#fff',
									data: list3
								}
							]
						};
						this.chartData = JSON.parse(JSON.stringify(res));
					} else {
						let res = {
							categories: ['无数据'],
							series: [{
									name: "已整改",
									textColor: '#fff',
									data: [0]

								},
								{
									name: "未整改",
									textColor: '#fff',
									data: [0]
								},
								{
									name: "暂无法整改",
									textColor: '#fff',
									data: [0]
								}
							]
						};
						this.chartData = JSON.parse(JSON.stringify(res));
					}
				}
			},

			//一级指标
			async securityCheckDangerHazardOneCollect(planId) {
				let self = this;
				const {
					data
				} = await securityCheckDangerHazardOneCollect({
					'type': '-1',
					'planId': planId
				});
				if (data.code == 200) {
					//列表
					this.$set(this, 'dataListTow', data.data.head);
					this.$set(this, 'dataListThree', data.data.list);
					let column3 = [{
							type: 'index',
							label: '排行',
							fixed: true,
							width: 60,
							align: 'center',
						},
						{
							name: 'deptSortName',
							label: '学院单位',
							fixed: true,
							width: 80,
							align: 'center',
						},
						{
							name: 'hazardNum',
							label: '总隐患',
							align: 'center',
						},
					]
					if (data.data.head[0]) {
						let name = [];
						let list = [];
						data.data.head.forEach(function(item, index) {
							if (index < 5) {
								column3.push({
									name: item.code,
									label: item.name,
									align: 'center',
								})
								let newName = item.name;
								if(newName.length > 6){
									newName = newName.slice(0, 6) + '..';
								}
								name.push(newName)
								// name.push(item.name)
								list.push(item.num)
							}
						})
						//图表
						let res = {
							categories: name,
							series: [{
								name: "",
								data: list
							}, ]
						};
						this.chartDataTow = JSON.parse(JSON.stringify(res));

					} else {

						//图表
						let res = {
							categories: ['无数据'],
							series: [{
								name: "",
								data: [0]
							}]
						};
						this.chartDataTow = JSON.parse(JSON.stringify(res));
					}
					this.column3 = JSON.parse(JSON.stringify(column3));

				}
			},
			//暂无法整改
			async securityCheckDangerNotHazardOneCollect(planId) {
				let self = this;
				let obj = {
					rectifyStatus: 4,
					planId: planId
				};
				const {
					data
				} = await securityCheckDangerNotHazardOneCollect(obj);
				if (data.code == 200) {
					//列表
					this.$set(this, 'dataListTow', data.data.head);
					this.$set(this, 'dataListThree', data.data.list);
					let column3 = [{
							type: 'index',
							label: '排行',
							fixed: true,
							width: 60,
							align: 'center',
						},
						{
							name: 'deptSortName',
							label: '学院单位',
							fixed: true,
							width: 80,
							align: 'center',
						},
						{
							name: 'hazardNum',
							label: '总隐患',
							align: 'center',
						},
					]
					if (data.data.head[0]) {
						let name = [];
						let list = [];
						data.data.head.forEach(function(item, index) {
							if (index < 5) {
								column3.push({
									name: item.code,
									label: item.name,
									align: 'center',
								})
								let newName = item.name;
								if(newName.length > 6){
									newName = newName.slice(0, 6) + '..';
								}
								name.push(newName)
								// name.push(item.name)
								list.push(item.num)
							}
						})
						//图表
						let res = {
							categories: name,
							series: [{
								name: "",
								data: list
							}, ]
						};
						this.chartDataTow = JSON.parse(JSON.stringify(res));

					} else {

						//图表
						let res = {
							categories: ['无数据'],
							series: [{
								name: "",
								data: [0]
							}]
						};
						this.chartDataTow = JSON.parse(JSON.stringify(res));
					}
					this.column3 = JSON.parse(JSON.stringify(column3));

				}
			},
		},
	}
</script>
<style lang="stylus" scoped>
	.hazardSources {
		height: 100%;
		width: 100%;
		background: #363744;

		.small-title {
			width: 750rpx;
			height: 80rpx;
			background: #3E414F;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 0 20rpx 0 30rpx;
			box-sizing: border-box;
			margin-top: 2rpx;

			.small-title-l {
				flex: 1;
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 42rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

			.small-title-r {
				width: 14rpx;
				height: 8rpx;
			}

		}


		.chart {
			width: 690rpx;
			height: 520rpx;
			background: #3E414F;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin: 20rpx 30rpx 0;
			overflow: hidden;

			.chart-t {
				width: 570rpx;
				height: 50rpx;
				display: flex;
				justify-content: flex-start;
				border: 1rpx solid #52545F;
				border-radius: 10rpx;
				margin: 30rpx 0 0 72rpx;

				.chart-t-li {
					width: 190rpx;
					font-weight: 400;
					font-size: 28rpx;

					line-height: 50rpx;
					text-align: center;
					background: none;
				}

				.chart-t-li:nth-of-type(1) {
					border-right: 1rpx solid #52545F;
				}

				.chart-t-li:nth-of-type(2) {
					border-right: 1rpx solid #52545F;
				}

				.color-A {
					color: #FFFFFF;
					background: #52545F;
				}

				.color-B {
					color: #999999;
					background: none;
				}
			}

			.chart-b {
				width: 630rpx;
				height: 334rpx;
				margin-left: 30rpx;
			}

			.chart-b2 {
				width: 630rpx;
				margin: 0 30rpx;
				height: 106rx;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				.chart-b2-li {
					flex: 1;

					.chart-b2-li-t {
						margin-top: 10rpx;
						text-align: center;

						>text:nth-of-type(1) {
							display: inline-block;
							width: 24rpx;
							height: 24rpx;
							background: #FF0000;
							border-radius: 6rpx 6rpx 6rpx 6rpx;
							margin-right: 10rpx;
							font-weight: 400;
							font-size: 22rpx;
							color: #FFFFFF;
							line-height: 24rpx;
							text-align: center;
						}

						>text:nth-of-type(2) {
							font-weight: 400;
							font-size: 24rpx;
							color: #FFFFFF;
							line-height: 34rpx;
						}
					}

					.chart-b2-li-b {
						margin-top: 10rpx;
						font-weight: 400;
						font-size: 24rpx;
						color: #FFFFFF;
						line-height: 34rpx;
						text-align: center;
					}
				}
			}

			.chart-b-tow {
				width: 630rpx;
				height: 440rpx;
				margin-left: 30rpx;
			}
		}

		.tabTitle_tow {
			width: 750rpx;
			height: 80rpx;
			white-space: nowrap;
			display: inline-flex;
			background: #3E414F;
			margin-top: 20rpx;
			padding-left: 35rpx;

			.tabTitle_tow_li {
				position: relative;
				width: 152rpx;
				height: 80rpx;
				text-align center;
				padding-top: 18rpx;
				box-sizing: border-box;

				.tabTitle_tow_text {
					display: inline-block;
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
					line-height: 46rpx;
					position: relative;

					&.on {
						color: #0183FA;
					}
				}

				.tabTitle_tow_across {
					width: 50rpx;
					height: 4rpx;
					background: #0183FA;
					border-radius: 2rpx;
					margin:6rpx auto 0;
					display none;

					&.on {
						display block;
					}
				}

			}
		}

		.table {
			width: 690rpx;
			margin-top: 20rpx;
			margin-left: 30rpx;
			border-radius: 20rpx 20rpx 0 0;
			overflow: hidden;

		}

		.sortOne {
			display: inline-block;
			width: 40rpx;
			height: 40rpx;
			padding: 4rpx;
			box-sizing: border-box;
			background: rgba(255, 0, 0, 0.2);
			font-weight: 400;
			font-size: 28rpx;
			color: #FF0000;
			line-height: 40rpx;
			text-align: center;
			border-radius: 20rpx;
		}

		.sortTow {
			display: inline-block;
			width: 40rpx;
			height: 40rpx;
			padding: 4rpx;
			box-sizing: border-box;
			background: rgba(255, 153, 0, 0.2);
			font-weight: 400;
			font-size: 28rpx;
			color: #FF9900;
			line-height: 40rpx;
			text-align: center;
			border-radius: 20rpx;
		}

		.sortThree {
			display: inline-block;
			width: 40rpx;
			height: 40rpx;
			padding: 4rpx;
			box-sizing: border-box;
			background: rgba(255, 242, 0, 0.2);
			font-weight: 400;
			font-size: 28rpx;
			color: #FFF200;
			line-height: 40rpx;
			text-align: center;
			border-radius: 20rpx;
		}

		.sortFive {
			display: inline-block;
			width: 40rpx;
			height: 40rpx;
			padding: 4rpx;
			box-sizing: border-box;
			background: rgba(1, 131, 250, 0.2);
			font-weight: 400;
			font-size: 28rpx;
			color: #0183FA;
			line-height: 40rpx;
			text-align: center;
			border-radius: 20rpx;
		}

		.table-tow {
			width: 690rpx;
			margin: 20rpx 0 0 30rpx;

			.table-border {
				width: auto;
				overflow: auto;

				.table-th {
					width: 690rpx;
					padding: 0 30rpx;
					box-sizing: border-box;
					background: rgba(162, 162, 162, 0.2);
					border-radius: 20rpx 20rpx 0rpx 0rpx;

					.table-th-li {
						height: 80rpx;
						display: flex;
						justify-content: flex-start;

						>view {
							font-weight: 400;
							font-size: 30rpx;
							color: #FFFFFF;
							line-height: 80rpx;
							text-align: center;
							margin-right: 38rpx;
							width: 120rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						>view:nth-of-type(1) {
							width: 64rpx;
							text-align: left;
							margin-right: 0;
						}

						>view:nth-of-type(2) {
							width: 270rpx;
						}

						>view:last-child {
							margin-right: 0;

						}
					}

				}


				.table-tb {
					width: 690rpx;
					background: #3E414F;
					padding: 0 30rpx;
					box-sizing: border-box;

					.table-tb-li {
						height: 80rpx;
						border-bottom: 1rpx dashed rgba(216, 216, 216, 0.2);
						display: flex;
						justify-content: flex-start;

						>view {
							font-weight: 400;
							font-size: 28rpx;
							color: #FFFFFF;
							line-height: 80rpx;
							text-align: center;
							margin-right: 38rpx;
							width: 120rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;

						}

						>view:nth-of-type(1) {
							width: 64rpx;
							text-align: left;
							margin-right: 0;
						}

						>view:nth-of-type(2) {
							width: 270rpx;
						}

						>view:last-child {
							margin-right: 0;

						}
					}


				}
			}


		}

		.table-three {
			width: 720rpx;
			margin: 20rpx 0 0 30rpx;

			.table-border {
				width: auto;
				overflow: auto;

				.table-th {
					width: 1510rpx;
					padding: 0 30rpx;
					box-sizing: border-box;
					background: rgba(162, 162, 162, 0.2);
					border-radius: 20rpx 20rpx 0rpx 0rpx;

					.table-th-li {
						height: 80rpx;
						display: flex;
						justify-content: flex-start;

						>view {
							font-weight: 400;
							font-size: 30rpx;
							color: #FFFFFF;
							line-height: 80rpx;
							text-align: center;
							margin-right: 38rpx;
							width: 120rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}

						>view:nth-of-type(1) {
							width: 116rpx;
							text-align: left;
							margin-right: 0;
						}

						>view:nth-of-type(2) {
							width: 168rpx;
						}

						>view:last-child {
							margin-right: 0;
							width: 228rpx;
						}
					}

				}


				.table-tb {
					width: 1510rpx;
					background: #3E414F;
					padding: 0 30rpx;
					box-sizing: border-box;

					.table-tb-li {
						height: 80rpx;
						border-bottom: 1rpx dashed rgba(216, 216, 216, 0.2);
						display: flex;
						justify-content: flex-start;

						>view {
							font-weight: 400;
							font-size: 28rpx;
							color: #FFFFFF;
							line-height: 80rpx;
							text-align: center;
							margin-right: 38rpx;
							width: 120rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;

						}

						>view:nth-of-type(1) {
							width: 116rpx;
							text-align: left;
							margin-right: 0;
						}

						>view:nth-of-type(2) {
							width: 168rpx;
						}

						>view:last-child {
							margin-right: 0;
							width: 228rpx;
						}
					}


				}
			}


		}

	}
</style>