<!-- 数据看板-首页 -->
<template>
	<view class="labPage">
		<view class="chart">
			<!-- <view class="chart-t">
				<view class="chart-t-li" @click="dateClick(index)" :class="dateIndex==index?'color-A':'color-B'"
					v-for="(item,index) in dateList">
					<view class="chart-t-li-t">{{item.num}}</view>
					<view class="chart-t-li-b">{{item.letterNUm}}</view>
				</view>
			</view> -->
			<view class="chart-b">
				<qiun-data-charts :canvas2d="true" :background="'rgba(0,0,1,0)'" type="line" :opts="opts" :echartsH5="true" :chartData="chartData" :ontouch="true" />
			</view>
		</view>
		<view class="statistics">
			<view class="statistics-t">
				<view class="statistics-t-l">实验室总数：</view>
				<view class="statistics-t-r">{{labTotal}} 间</view>
			</view>
			<view class="statistics-b">
				<view class="statistics-b-li">
					<view class="statistics-b-li-t color-A">{{useTotal}} 间</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">{{availableTotal}} 间</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">{{exceptionalTotal}} 间</view>
					<view class="statistics-b-li-b">异常</view>
				</view>
			</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 {
		reportAppStatisticsLabStateStatistics,
		reportAppStatisticsLabNumberPeople,
		reportAppStatisticsPersonDeviceSafety,
	} from '@/pages/api/index.js'
	export default {
		name: "labPage",
		components: {

		},
		data() {
			return {
				dateList: [{
						num: '1',
						letterNUm: 'Mon',
					},
					{
						num: '2',
						letterNUm: 'Tue',
					},
					{
						num: '3',
						letterNUm: 'Wed',
					},
					{
						num: '4',
						letterNUm: 'Thur',
					},
					{
						num: '5',
						letterNUm: 'Fri',
					},
					{
						num: '6',
						letterNUm: 'Sat',
					},
					{
						num: '7',
						letterNUm: 'Sun',
					},
				],
				dateIndex: 0,


				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 10,
				},
				opts: {
					color: ["#0183FA", "#16BF32", "#FF8C00", "#FF0000", ],
					padding: [0, 0, 0, 0],
					enableScroll: true,
					touchMoveLimit:24,
					legend: {
						show: true,
						fontColor: '#fff',
						position: 'top',
						fontSize: 8,
						margin: 10,
					},
					extra: {
						tooltip: {
							legendShape: 'circle',
						},
					},
					xAxis: {
						disableGrid: true,
						scrollShow: true,
						itemCount: 4,
						fontColor: '#fff',
						
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2,
						data: [{
							axisLine: false,
							fontColor: '#fff',
						}]
					},
				},
				chartData: {},
				column: [{
						name: 'deptSortName',
						label: '学院单位',
						fixed: true,
						width: 80,
						align: 'center',
					},
					{
						name: 'labCount',
						label: '实验人数',
						fixed: true,
						width: 80,
						align: 'center',
					},
					{
						name: 'dutyCount',
						label: '值班人数',
						align: 'center',
					},
					{
						name: 'checkCount',
						label: '检查次数',
						align: 'center',
					},
					{
						name: 'overdueDevice',
						label: '超期设备',
						align: 'center',
					},
				],
				dataList: [],
				total: 0,
				labTotal: 0,
				useTotal: 0,
				availableTotal: 0,
				exceptionalTotal: 0,
			}
		},
		created() {
			this.dateIndex = new Date().getDay() - 1;
			// console.log(this.dateIndex)
		},
		beforeMount() {

		},
		mounted() {
			this.reportAppStatisticsLabNumberPeople();
			this.reportAppStatisticsLabStateStatistics();
			this.getList();
		},
		methods: {

			dateClick(index) {
				//this.dateIndex = index;
			},
			//实验室使用、空闲、异常数量
			async reportAppStatisticsLabNumberPeople() {
				let self = this;
				const {
					data
				} = await reportAppStatisticsLabNumberPeople();
				if (data.code == 200) {
					let date = [];
					let list = []; //实验人数
					let list2 = []; //值日人数
					let list3 = []; //检查次数
					let list4 = []; //超期设备数
					date = data.data.dateList
					// 实验人数
					data.data.experimentList.forEach(function(item) {
						list.push(item.num)
					})
					// 值班
					data.data.dutyList.forEach(function(item) {
						list2.push(item.num)
					})
					// 检查
					data.data.checkList.forEach(function(item) {
						list3.push(item.num)
					})
					// 超期设备
					// data.data.deviceList.forEach(function(item) {
					// 	list4.push(item.num)
					// })
					let res = {
						categories: date,
						series: [{
								name: "实验人数",
								data: list
							},
							{
								name: "值日人数",
								data: list2
							},
							{
								name: "检查次数",
								data: list3
							},
							// {
							// 	name: "超期设备数",
							// 	data: list4
							// }
						]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}
			},
			//实验室使用、空闲、异常数量
			async reportAppStatisticsLabStateStatistics() {
				let self = this;
				const {
					data
				} = await reportAppStatisticsLabStateStatistics();
				if (data.code == 200) {
					this.$set(this, 'labTotal', data.data.labTotal)
					this.$set(this, 'useTotal', data.data.useTotal)
					this.$set(this, 'availableTotal', data.data.availableTotal)
					this.$set(this, 'exceptionalTotal', data.data.exceptionalTotal)
				}
			},
			async getList() {
				let self = this;
				const {
					data
				} = await reportAppStatisticsPersonDeviceSafety();
				if (data.code == 200) {
					this.dataList = data.data;
				}
			},
		},
	}
</script>
<style lang="stylus" scoped>
	.labPage {
		height: 100%;
		width: 100%;
		background: #363744;
		padding: 20rpx 30rpx 36rpx;
		box-sizing: border-box;

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

			.chart-t {
				display: flex;
				justify-content: space-between;

				.chart-t-li {
					width: 76rpx;
					height: 100rpx;

					.chart-t-li-t {
						font-weight: 400;
						font-size: 30rpx;

						line-height: 42rpx;
						text-align: center;
						margin-top: 8rpx;
					}

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

						line-height: 39rpx;
						text-align: center;
						margin-top: 4rpx;
					}
				}

				.color-A {
					background: #0183FA;
					border-radius: 10rpx 10rpx 10rpx 10rpx;

					.chart-t-li-t {
						color: #FFFFFF;
					}

					.chart-t-li-b {
						color: #FFFFFF;
					}
				}

				.color-B {
					background: none;

					.chart-t-li-t {
						color: #FFFFFF;
					}

					.chart-t-li-b {
						color: #FFFFFF;
					}
				}
			}

			.chart-b {
				width: 632rpx;
				height: 444rpx;
				/* margin-top: 34rpx; */
			}
		}

		.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;
		}
	}
</style>
