<!-- 数据看板-设备管控 -->
<template>
	<view class="equipmentControl">
		<view class="statistics">
			<view class="statistics-b">
				<view class="statistics-b-li">
					<view class="statistics-b-li-t color-A">{{totalDeviceNum}}</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">{{newlyAddToday}}</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">{{overdueDeviceNum}}</view>
					<view class="statistics-b-li-b">超期服役设备</view>
				</view>
			</view>
		</view>
		<view class="small-title">
			<view class="small-title-l">超期服役排行TOP5</view>
			<img class="small-title-r" @click="goPage('overdue')" :src="imagesUrl('commonality/icon_wdwg_gd.png')">
		</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="small-title">
			<view class="small-title-l">设备使用寿命</view>
			<img class="small-title-r" @click="goPage('life')" :src="imagesUrl('commonality/icon_wdwg_gd.png')">
		</view>
		<view class="chart-tow">
			<view class="chart-tow-b">
				<qiun-data-charts :canvas2d="true" type="funnel" :opts="optsTow" :echartsH5="true" :chartData="chartDataTow" />
			</view>
		</view>
		<view class="small-title">
			<view class="small-title-l">特种设备与常规冷热设备安全隐患统计</view>
		</view>
		<view class="chart-three">
			<view class="small-title-three">
				<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-three-b">
				<qiun-data-charts :canvas2d="true" type="pie" :opts="optsThree" :echartsH5="true" :chartData="chartDataThree" />
			</view>
		</view>
		<view class="chart-title">
			<view class="chart-title-l">安全检查指标</view>
			<view class="chart-title-r">占比</view>
		</view>
		<view class="list" v-for="(item,index) in dataList" :key="index">
			<view class="list-title">
				<view class="list-title-l">{{item.code}}{{item.name}}</view>
				<view class="list-title-r">{{item.rate}}%</view>
			</view>
			<view class="list-li" v-for="(item2,index2) in item.childList" :key="index2">{{item2.code}}{{item2.name}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {
		reportAppletReportApiDeviceStatGetDeviceStat,
		reportAppletReportBsEquipDangerCheckList,
		reportAppletReportBsEquipDangerList,
		reportAppletReportApiEquipOverdueList,
		reportAppletReportApiEquipLifeList,
	} from '@/pages/api/index.js'
	export default {
		name: "equipmentControl",
		components: {

		},
		data() {
			return {
				opts: {
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 30, 0, 5],
					enableScroll: false,
					legend: {
						show: false,
					},
					xAxis: {
						disabled: true,
						disableGrid: true,
						axisLine: false,
						fontColor: '#fff',
					},
					yAxis: {
						disabled: false,
						disableGrid: true,

						data: [{
							type: 'categories',
							fontColor: '#fff',
						}],
					},
					extra: {
						bar: {
							type: "group",
							width: 12,
							meterBorde: 1,
							meterFillColor: "#FFFFFF",
							activeBgColor: "#000000",
							activeBgOpacity: 0.08,
							linearType: "custom",
							barBorderCircle: true,
							seriesGap: 2,
							categoryGap: 2
						}
					}
				},
				chartData: {},
				optsTow: {
					color: ["#0183FA", "#38F0F0", "#2CCA73", "#FC6E21", "#FF4646", ],
					legend: {
						show: false,
					},
					padding: [15, 95, 10, 0],
					enableScroll: false,
					extra: {
						funnel: {
							type: 'triangle',
							border: false,
							labelAlign: "right",
						}
					}
				},
				chartDataTow: {},
				optsThree: {
					color: ["#10C139", "#FF8400", "#00FFE6", "#0183FA", "#73C0DE", "#3CA272", ],
					legend: {
						show: false,
					},
					padding: [5, 5, 5, 5],
					enableScroll: false,
					extra: {
						pie: {
							offsetAngle: 0,
							labelWidth: 15,
							border: true,
							borderWidth: 3,
							borderColor: "#3E414F",
						}
					}
				},
				chartDataThree: {},
				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 10,
				},
				dataList: [],
				total: 0,
				newlyAddToday: 0,
				overdueDeviceNum: 0,
				totalDeviceNum: 0,
				statisticsType: 1, //1.年度2.季度3.月度
				chartTabListThree: ['年度', '季度', '月度'],
				chartTabIndexThree: 0,
			}
		},
		created() {

		},
		beforeMount() {

		},
		mounted() {
			this.reportAppletReportApiDeviceStatGetDeviceStat();
			this.reportAppletReportBsEquipDangerCheckList();
			this.reportAppletReportBsEquipDangerList();
			this.reportAppletReportApiEquipOverdueList();
			this.reportAppletReportApiEquipLifeList();
		},
		methods: {
			//隐患统计
			async reportAppletReportBsEquipDangerList() {
				let self = this;
				const {
					data
				} = await reportAppletReportBsEquipDangerList({
					dangerType: '1',
					statisticsType: this.statisticsType
				});
				if (data.code == 200) {
					let list = [];
					data.data.subjectList.forEach(function(item, index) {
						if (index < 5) {
							list.push({
								"name": item.subjectName,
								"value": item.dangerNum,
								"textColor": "#fff",
							})
						}

					})

					let res = {
						series: [{
							data: list
						}]
					};
					this.chartDataThree = JSON.parse(JSON.stringify(res));
				}
			},
			//超期服役统计
			async reportAppletReportApiEquipOverdueList() {
				let self = this;
				const {
					data
				} = await reportAppletReportApiEquipOverdueList();
				if (data.code == 200) {
					let list = [];
					let list2 = [];
					data.data.forEach(function(item, index) {
						if(index<5){
							let newName = item.deptName;
							if(newName.length > 6){
								newName = newName.slice(0, 6) + '..';
							}
							list.push(newName)
							// list.push(item.deptName)
							list2.push(item.deviceNum)
						}
					})

					let res = {
						categories: list,
						series: [{
							name: "目标值",
							textColor: '#fff',
							data: list2
						}, ]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}
			},
			//设备使用寿命统计
			async reportAppletReportApiEquipLifeList() {
				let self = this;
				const {
					data
				} = await reportAppletReportApiEquipLifeList();
				if (data.code == 200) {
					let list = [];
					data.data.forEach(function(item, index) {
						list.push({
							"name":item.lifeInterval,
							"value": item.deviceNum,
							"labelText":item.lifeInterval+' '+item.deviceNum+item.unit+' '+item.deviceRate+'%',
							"textColor": "#fff",
						})
					})
			
					let res = {
						series: [{
							data: list
						}]
					};
					this.chartDataTow = JSON.parse(JSON.stringify(res));
				}
			},
			async reportAppletReportApiDeviceStatGetDeviceStat() {
				let self = this;
				const {
					data
				} = await reportAppletReportApiDeviceStatGetDeviceStat();
				if (data.code == 200) {
					this.$set(self, 'newlyAddToday', data.data.newlyAddToday);
					this.$set(self, 'overdueDeviceNum', data.data.overdueDeviceNum);
					this.$set(self, 'totalDeviceNum', data.data.totalDeviceNum)
				}
			},
			//安全检查指标
			async reportAppletReportBsEquipDangerCheckList() {
				let self = this;
				const {
					data
				} = await reportAppletReportBsEquipDangerCheckList();
				if (data.code == 200) {
					this.$set(self, 'dataList', data.data);
				}
			},

			dateClick(index) {
				this.dateIndex = index;
			},
			goPage(type) {
				if (type == 'overdue') {
					uni.navigateTo({
						url: '/pages/views/dataBoard/equipmentControlOverdue?pageType=1'
					});
				} else if (type == 'life') {
					uni.navigateTo({
						url: '/pages/views/dataBoard/equipmentControlOverdue?pageType=2'
					});
				}
			},
			chartTabClickThree(index) {
				this.chartTabIndexThree = index;
				this.statisticsType = index + 1;
				this.reportAppletReportBsEquipDangerList();
			},
		},
	}
</script>

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

		.statistics {
			width: 750rpx;
			height: 120rpx;
			background: #3E414F;

			.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: 10rpx;

					}

					.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: #FF0000;
				}

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

		.small-title {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin: 0 30rpx;

			.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: 476rpx;
			background: #3E414F;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin: 0 30rpx;

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

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

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

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

		}

		.small-title-three {
			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;
				}

			}
		}

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

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

		.chart-title {
			width: 689rpx;
			height: 80rpx;
			background: rgba(162, 162, 162, 0.2);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			padding: 0 70rpx 0 38rpx;
			box-sizing: border-box;
			margin: 0 30rpx;
			display: flex;
			justify-content: space-between;

			.chart-title-l {
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 80rpx;
			}

			.chart-title-r {
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 80rpx;
			}
		}

		.list {
			margin: 0 30rpx;
			padding: 0 30rpx;
			box-sizing: border-box;

			.list-title {
				height: 80rpx;
				display: flex;
				justify-content: space-between;
				border-bottom: 1rpx dashed rgba(216, 216, 216, 0.2);
				padding: 0 38rpx 0 10rpx;
				box-sizing: border-box;

				.list-title-l {
					font-weight: 400;
					font-size: 28rpx;
					color: #FFFFFF;
					line-height: 80rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}

				.list-title-r {
					font-weight: 400;
					font-size: 28rpx;
					color: #0183FA;
					line-height: 80rpx;
				}
			}

			.list-li {
				min-height: 80rpx;
				display: flex;
				justify-content: space-between;
				padding: 0 38rpx 0 10rpx;
				box-sizing: border-box;
				font-weight: 400;
				font-size: 28rpx;
				color: #999999;
				line-height: 40rpx;
				text-align: left;
				padding: 20rpx 0;
				box-sizing: border-box;
			}
		}
	}
</style>
