<!-- 数据看板-危险源 -->
<template>
	<view class="hazardSources">
		<view class="statistics">
			<view class="statistics-t">
				<view class="statistics-t-l">危险源总数：</view>
				<view class="statistics-t-r">{{hazardTotal}}</view>
			</view>
			<view class="statistics-b">
				<view class="statistics-b-li">
					<view class="statistics-b-li-t color-A">{{newHazard}}</view>
					<view class="statistics-b-li-b">今日新增数</view>
				</view>
				<view class="line"></view>
				<view class="statistics-b-li">
					<view class="statistics-b-li-t color-B">{{hazardChemicals}}</view>
					<view class="statistics-b-li-b">危险品数</view>
				</view>
				<view class="line"></view>
				<view class="statistics-b-li">
					<view class="statistics-b-li-t color-C">{{deviceNum}}</view>
					<view class="statistics-b-li-b">冷热设备数</view>
				</view>
			</view>
		</view>
		<view class="small-title">
			<view class="small-title-l">危险源总数排行TOP5 </view>
		</view>
		<view class="chart">
			<view class="chart-b">
				<qiun-data-charts :tapLegend="false" :tooltipShow="false" :canvas2d="true" type="bar" :opts="opts" :echartsH5="true" :chartData="chartData" />
			</view>
		</view>
		<view class="table">
			<uni-card>
				<view style="height: 200px">
					<zb-table :columns="column" :stripe="false" :border="false" :data="dataList"></zb-table>
				</view>
			</uni-card>

		</view>
	</view>
</template>

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

		},
		data() {
			return {
				opts: {
					color: ["#FF8C00", "#0183FA", ],
					// color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
					padding: [0, 30, 10, 0],
					enableScroll: false,
					legend: {
						position: 'top',
						legendShape: 'square',
						fontColor: '#fff',
					},
					xAxis: {
						disabled: true,
						disableGrid: true,
						axisLine: false,
						fontColor: '#fff',
					},
					yAxis: {
						disabled: false,
						disableGrid: true,
						data: [{
							type: 'categories',
							fontColor: '#fff',
						}],
					},
					extra: {
						bar: {
							type: "group",
							width: 10,
							meterBorde: 1,
							meterFillColor: "#FFFFFF",
							activeBgColor: "#000000",
							activeBgOpacity: 0.08,
							linearType: "none",
							barBorderCircle: true,
							seriesGap: 2,
							categoryGap: 2
						}
					}
				},
				chartData: {},
				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 10,
				},
				hazardTotal: 0,
				newHazard: 0,
				hazardChemicals: 0,
				deviceNum: 0,
				column: [{
						type: 'index',
						label: '排行',
						fixed: true,
						width: 60,
						align: 'center',
					},
					{
						name: 'deptSortName',
						label: '学院单位',
						fixed: true,
						width: 80,
						align: 'center',
					},
					{
						name: 'total',
						label: '总数',
						align: 'center',
					},
					{
						name: 'chemical',
						label: '危化品数',
						align: 'center',
					},
					{
						name: 'coolHotdevice',
						label: '冷热设备数',
						align: 'center',
					},
				],
				dataList: [],
				total: 0,
			}
		},
		created() {

		},
		beforeMount() {

		},
		mounted() {
			this.reportAppStatisticsHazardTotalSort();
		},
		methods: {
			dateClick(index) {
				this.dateIndex = index;
			},
			//危化品
			async reportAppStatisticsHazardTotalSort() {
				let self = this;
				const {
					data
				} = await reportAppStatisticsHazardTotalSort();
				if (data.code == 200) {
					this.$set(self, 'hazardTotal', data.data.hazardTotal);
					this.$set(self, 'newHazard', data.data.newHazard);
					this.$set(self, 'hazardChemicals', data.data.hazardChemicals);
					this.$set(self, 'deviceNum', data.data.deviceNum);
					//列表
					this.dataList = data.data.hazardTotalSortSubs;
					//图表
					if (data.data.hazardTotalSortSubs[0]) {
						let name = [];
						let list = [];
						let list2 = [];
						data.data.hazardTotalSortSubs.forEach(function(item, index) {
							if (index < 5) {
								let newName = item.deptSortName;
								if(newName.length > 6){
									newName = newName.slice(0, 6) + '..';
								}
								// name.push(item.deptSortName)
								name.push(newName)
								list.push(item.chemical)
								list2.push(item.coolHotdevice)
							}
						})
						let res = {
							categories: name,
							series: [{
									name: "危险品",
									textColor: "#FFFFFF",
									data: list
								},
								{
									name: "冷热设备与特种设备",
									textColor: "#FFFFFF",
									data: list2
								}
							]
						};
						this.chartData = JSON.parse(JSON.stringify(res));
					}

				}
			},

		},
	}
</script>

<style lang="stylus" scoped>
	.hazardSources {
		height: 100%;
		width: 100%;
		background: #363744;
		padding: 20rpx 30rpx 36rpx;
		box-sizing: border-box;

		.small-title {
			display: flex;
			justify-content: space-between;

			.small-title-l {
				font-weight: 400;
				font-size: 32rpx;
				color: #FFFFFF;
				line-height: 45rpx;
				text-align: left;
				margin: 28rpx 0;
			}

			.small-title-r {
				width: 15rpx;
				height: 18rpx;
			}

		}

		.chart {
			width: 690rpx;
			height: 560rpx;
			background: #3E414F;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			padding: 34rpx 30rpx 26rpx;
			box-sizing: border-box;

			.chart-b {
				width: 630rpx;
				height: 500rpx;
			}
		}

		.statistics {
			width: 690rpx;
			height: 241rpx;
			background: #3E414F;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin-top: 20rpx;

			.statistics-t {
				height: 100rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 1rpx solid #52545F;
				padding: 0 42rpx 0 38rpx;
				box-sizing: border-box;

				.statistics-t-l {
					font-weight: 400;
					font-size: 32rpx;
					color: #FFFFFF;
					line-height: 45rpx;
				}

				.statistics-t-r {
					font-weight: 400;
					font-size: 36rpx;
					color: #FFFFFF;
					line-height: 50rpx;
				}
			}

			.statistics-b {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.statistics-b-li {
					flex: 1;
					text-align: center;

					.statistics-b-li-t {
						font-weight: 400;
						font-size: 36rpx;
						line-height: 50rpx;
						margin-top: 28rpx;
					}

					.statistics-b-li-b {
						font-weight: 400;
						font-size: 28rpx;
						color: #FFFFFF;
						line-height: 39rpx;
						margin-top: 9rpx;
					}
				}

				.line {
					width: 2rpx;
					height: 30rpx;
					background: #D8D8D8;
				}

				.color-A {
					color: #FF8C00;
				}

				.color-B {
					color: #26C736;
				}

				.color-C {
					color: #FF0000;
				}
			}
		}

		.table {
			width: 690rpx;
			margin-top: 20rpx;
			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;
			}
		}
	}
</style>