<!-- 数据看板-大仪预约 -->
<template>
	<view class="daYiReservation">
		<view class="chart">
			<view class="chart-t">
				<viwe class="chart-t-l">
					<text>设备总数：</text>
					<text>{{deviceTotal}}</text>
				</viwe>
			</view>
			<view class="chart-b">
				<qiun-data-charts :canvas2d="true" :tapLegend="false" :tooltipShow="false" type="ring" :opts="opts" :echartsH5="true"
					:chartData="chartData" />
			</view>
		</view>
		<view class="small-title">
			<view class="small-title-l">预约使用排行TOP10</view>
			<viwe class="chart-tab-tow">
				<view class="chart-tab-li" :class="chartTabIndexTow==index?'tab-A':'tab-B'"
					v-for="(item,index) in chartTabListTow" :key="index" @click="chartTabClickTow(index)">{{item}}
				</view>
			</viwe>
		</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 class="small-title">
			<view class="small-title-l">大仪预约排行</view>
		</view>
		<view class="table-tow">
			<uni-card>
				<view style="height: 200px">
					<zb-table :columns="column2" :stripe="false" :border="false" :data="dataList2"></zb-table>
				</view>
			</uni-card>

		</view>
		<view class="small-title">
			<view class="small-title-l">隐患实验室统计</view>
			<viwe class="chart-tab-tow">
				<view class="chart-tab-li" :class="chartTabIndexThree==index?'tab-A':'tab-B'"
					v-for="(item,index) in chartTabListThree" :key="index" @click="chartTabClickThree(index)">{{item}}
				</view>
			</viwe>
		</view>
		<view class="chart-tow">
			<view class="chart-tow-b">
				<qiun-data-charts :canvas2d="true" :tapLegend="false" :tooltipShow="false" 
				type="bar" :opts="optsTow" :echartsH5="true" :chartData="chartDataTow" />
			</view>
		</view>
	</view>
</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {
		reportAppletReportBsEquipStatusList,
		reportAppletReportApiEquipRankTopList,
		reportAppletReportBsEquipAppointTopList,
		reportAppletReportBsEquipDangerList,
	} from '@/pages/api/index.js'
	export default {
		name: "daYiReservation",
		components: {

		},
		data() {
			return {
				opts: {
					rotate: false,
					rotateLock: false,
					fontColor: '#fff',
					color: ["#10C139", "#FF8400", "#0183FA", "#EE6666", "#73C0DE", "#3CA272", ],
					padding: [5, 10, 5, 10],
					dataLabel: true,
					enableScroll: false,
					legend: {
						show: true,
						position: "right",
						fontColor: '#fff',
					},
					title: {
						name: "",
					},
					subtitle: {
						name: "",
					},
					extra: {
						ring: {
							ringWidth: 15,
							centerColor: '#3E414F',
							activeOpacity: 0.5,
							activeRadius: 20,
							offsetAngle: 0,
							labelWidth: 15,
							border: true,
							borderWidth: 3,
							borderColor: "#3E414F"
						}
					}
				},
				chartData: {},
				optsTow: {
					rotate: false,
					rotateLock: false,
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"],
					padding: [15, 20, 15, 15],
					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
						}
					}
				},
				chartDataTow: {},
				chartTabList: ['日', '月', '年'],
				chartTabIndex: 0,
				chartTabListTow: ['按资费', '按机时', '按样品'],
				chartTabIndexTow: 0,
				chartTabListThree: ['年度', '季度', '月度'],
				chartTabIndexThree: 0,

				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 10,
				},
				column: [{
						type: 'index',
						label: '排行',
						fixed: true,
						width: 60,
						align: 'center',
					},
					{
						name: 'deviceName',
						label: '设备名称',
						fixed: true,
						width: 80,
						align: 'center',
					},
					{
						name: 'useTimeStr',
						label: '使用机时',
						align: 'center',
					},
					{
						name: 'appointFee',
						label: '预约费用',
						align: 'center',
					},
					{
						name: 'testSample',
						label: '测试样品',
						align: 'center',
					},
				],
				column2: [{
						type: 'index',
						label: '排行',
						fixed: true,
						width: 60,
						align: 'center',
					},
					{
						name: 'deviceName',
						label: '设备名称',
						fixed: true,
						width: 80,
						align: 'center',
					},
					{
						name: 'orderDurationStr',
						label: '预约时长',
						align: 'center',
					},
					{
						name: 'orderNum',
						label: '预约次数',
						align: 'center',
					},
				],
				dataList: [],
				dataList2: [],
				total: 0,
				type: 1, //type为1 按费用,2.按照机时,3.按照样品
				deviceTotal: 0,
				statisticsType: 1, //1.年度2.季度3.月度
			}
		},
		created() {

		},
		beforeMount() {

		},
		mounted() {
			this.reportAppletReportBsEquipStatusList()
			this.reportAppletReportApiEquipRankTopList()
			this.reportAppletReportBsEquipAppointTopList()
			this.reportAppletReportBsEquipDangerList()
			//this.getServerDataTow()
		},
		methods: {
			//隐患统计
			async reportAppletReportBsEquipDangerList() {
				let self = this;
				const {
					data
				} = await reportAppletReportBsEquipDangerList({
					dangerType: '3',
					statisticsType: this.statisticsType
				});
				if (data.code == 200) {
					let categories = [];
					let list = [];
					data.data.subjectList.forEach((item, index)=>{
						if (index < 5) {
							if (item.subjectName.length > 6) {
								item.subjectName = item.subjectName.slice(0, 6) + '...';
							}
							categories.push(item.subjectName)
							list.push(item.dangerNum)
						}
					})
					let res = {};
					if(categories[0]){
						res = {
							categories: categories,
							series: [{
								name: "",
								data: list
							}]
						};
					}else{
						res = {
							categories: ['无数据'],
							series: [{
								name: "",
								data: [0]
							}]
						};
					}
					console.log('res',res);
					self.$set(this,'chartDataTow',res);
				}
			},
			//设备总数
			async reportAppletReportBsEquipStatusList() {
				let self = this;
				const {
					data
				} = await reportAppletReportBsEquipStatusList();
				if (data.code == 200) {
					let list = [];
					data.data.forEach(function(item, index) {
						if (index < 6) {
							list.push({
								"name": item.name + ' ' + item.value,
								"value": item.value,
								// "labelShow": false,
							})
							self.deviceTotal += item.value
						}
					})
					let res = {
						series: [{
							data: list
						}]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}
			},
			//预约使用排行TOP10
			async reportAppletReportApiEquipRankTopList() {
				let self = this;
				const {
					data
				} = await reportAppletReportApiEquipRankTopList({
					type: this.type
				});
				if (data.code == 200) {
					data.data.forEach((item)=>{
						// item.useTimeStr = item.useTimeStr.replace("小时", "时");
						// item.useTimeStr = item.useTimeStr.replace("分钟", "'");
						// item.useTimeStr = item.useTimeStr.replace("秒", '"');
						// item.useTimeStr = item.useTimeStr.replace("秒", '"');
						item.appointFee = '¥'+item.appointFee
					})
					this.$set(this, 'dataList', data.data)
				}
			},
			//大仪预约排行
			async reportAppletReportBsEquipAppointTopList() {
				let self = this;
				const {
					data
				} = await reportAppletReportBsEquipAppointTopList();
				if (data.code == 200) {
					// data.data.forEach((item)=>{
					// 	item.orderDuration = item.orderDuration+'';
					// 	if (item.orderDuration.indexOf('.') != -1){
					// 		item.orderDuration = item.orderDuration.replace(".", "时");
					// 		item.orderDuration = item.orderDuration+"'";
					// 	}else{
					// 		item.orderDuration = item.orderDuration+"时";
					// 	}
					// })
					this.$set(this, 'dataList2', data.data)
				}
			},

			getServerDataTow() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						categories: ["测定仪", "色谱仪", "分析仪", "光度计", "离子色谱仪"],
						series: [{
							name: "",
							data: [90, 110, 165, 195, 187]
						}, ]
					};
					this.chartDataTow = JSON.parse(JSON.stringify(res));
				}, 500);
			},
			chartTabClick(index) {
				this.chartTabIndex = index;
			},
			chartTabClickTow(index) {
				this.chartTabIndexTow = index;
				this.type = index + 1;
				this.reportAppletReportApiEquipRankTopList();
			},
			chartTabClickThree(index) {
				this.chartTabIndexThree = index;
				this.statisticsType = index + 1;
				this.reportAppletReportBsEquipDangerList();
			},


		},
	}
</script>

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


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

			.chart-t {
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 50rpx;
				margin-top: 30rpx;
				padding: 0 24rpx 0 42rpx;
				box-sizing: border-box;

				.chart-t-l {
					>text {
						font-weight: 400;
						font-size: 30rpx;
						color: #FFFFFF;
						line-height: 42rpx;
					}

					>text:nth-of-type(1) {
						color: #FFFFFF;
					}

					>text:nth-of-type(2) {
						color: #0183FA;
					}
				}

				.chart-tab {
					width: 120rpx;
					height: 50rpx;
					border-radius: 10rpx;
					overflow: hidden;
					border: 1rpx solid #52545F;
					display: flex;
					justify-content: flex-start;

					.chart-tab-li {
						width: 60rpx;
						font-weight: 400;
						font-size: 28rpx;
						color: #999999;
						line-height: 50rpx;
						text-align: center;
					}

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

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

					.tab-A {
						color: #FFFFFF;
						background: #0183FA;
					}

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

				}
			}

			.chart-b {
				width: 690rpx;
				height: 300rpx;
			}
		}

		.statistics {
			width: 750rpx;
			height: 120rpx;
			background: #3E414F;
			margin-top: 20rpx;

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

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

					.statistics-b-li-t {
						margin-top: 10rpx;

						>text {
							font-weight: 400;
							font-size: 36rpx;
							line-height: 50rpx;
						}

						>text:nth-of-type(1) {
							font-size: 36rpx;
						}

						>text:nth-of-type(2) {
							font-size: 24rpx;
						}

					}

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

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

			.color-A {
				color: #0183FA;
			}

			.color-B {
				color: #05FFE6;
			}

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

		.small-title {
			width: 690rpx;
			height: 50rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin: 24rpx 30rpx;

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

			.chart-tab-tow {
				width: 300rpx;
				height: 50rpx;
				border-radius: 25rpx;
				overflow: hidden;
				border: 1rpx solid #52545F;
				display: flex;
				justify-content: flex-start;

				.chart-tab-li {
					width: 100rpx;
					font-weight: 400;
					font-size: 28rpx;
					color: #999999;
					line-height: 50rpx;
					text-align: center;
				}

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

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

				.tab-A {
					color: #FFFFFF;
					background: #0183FA;
				}

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

			}
		}

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

		}

		.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-top: 20rpx;
			border-radius: 20rpx 20rpx 0 0;
			overflow: hidden;
			margin-left: 30rpx;
		}

		.small-title-tow {
			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-tow-l {
				flex: 1;
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 42rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}

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

		}

		.chart-tow {
			width: 690rpx;
			height: 480rpx;
			background: #3E414F;
			border-radius: 20rpx 20rpx 20rpx 30rpx;
			margin: 26rpx 30rpx 0;

			.chart-tow-b {
				width: 690rpx;
				height: 480rpx;
			}
		}
	}
</style>