<template>
	<view>
		<view class="title">
			<view class="icon">
				<image src="./icon/icon_red.png" mode=""></image>
			</view>
			<view class="text">当前报警</view>
		</view>
		
		<scroll-view scroll-x="true" >
			<view>
				<canvas canvas-id="canvasColumn" id="canvasColumn" @touchstart="touchColumn" style="width: 1400rpx; height:600rpx;"></canvas>
			</view>
		</scroll-view>
		
		
	</view>
</template>

<script>
	import uCharts from '@/components/u-charts/u-charts.js';
	var _self;
	var canvaColumn = null;

	export default {
		data() {
			return {
				cWidth: '',
				cHeight: '',
				pixelRatio: 1,
				serverData: '',
			}
		},
		mounted() {
			_self = this;
			this.cWidth = uni.upx2px(1400);
			this.cHeight = uni.upx2px(600);
			this.getServerData();
		},
		methods: {
			getServerData() {
				
				// let Column = {
				// 	"categories": ["红石湾煤矿", "白芨沟煤矿", "红柳煤矿", "羊场湾一号井", "羊场湾二号井", "灵新煤矿"],
				// 	"series": [{
				// 		"name": "",
				// 		"data": [0,647,386,68,0,1692]
				// 	}]
				// };
				// _self.showColumn("canvasColumn", Column);
				
				
				this.$api.jt_safety_alarm_count({
					
				}).then((res)=>{
					// console.log(res.data.content.data)
					
					let Column = {
						categories: [],
						data:[]
					}
					
					const categories = res.data.content.data
					categories.map(function(item,index){
						//新数组的项，用来盛放每一项中的各个参数，每次清空，这样避免改变sevm的值
						var sevm = {};
						//给每一项中的参数初始化并赋值
						sevm = item.mine_name;
						//将项放进新的数组
						Column.categories[index] = sevm
					})
					
					const data = res.data.content.data
					data.map(function(item, index) {
						//新数组的项，用来盛放每一项中的各个参数，每次清空，这样避免改变sevm的值
						var sevm = {};
						//给每一项中的参数初始化并赋值
						sevm = item.count;
						//将项放进新的数组
						Column.data[index] = sevm
					})
					
									
					// console.log(Column)
									
					_self.showColumn("canvasColumn", Column);
					
				})

			},
			showColumn(canvasId, chartData) {
				canvaColumn = new uCharts({
					$this: _self,
					canvasId: canvasId,
					type: 'column',
					legend: {
						show: false
					},
					fontSize: 11,
					background: '#FFFFFF',
					pixelRatio: _self.pixelRatio,
					animation: true,
					categories: chartData.categories,
					series: [{
						name: '',
						data: chartData.data,
					}],
					xAxis: {
						disableGrid: true,
						rotateLabel: true,
					},
					yAxis: {
						// disabled:true
					},
					dataLabel: false,
					width: _self.cWidth * _self.pixelRatio,
					height: _self.cHeight * _self.pixelRatio,
					extra: {
						column: {
							type: 'group',
							width: _self.cWidth * _self.pixelRatio * 0.45 / chartData.categories.length
						}
					}
				});

			},
			touchColumn(e) {
				canvaColumn.showToolTip(e, {
					format: function(item, category) {
						if (typeof item.data === 'object') {
							return category + ' ' + item.name + ':' + item.data.value
						} else {
							return category + ' ' + item.name + ':' + item.data
						}
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	.title {
		margin-bottom: 60rpx;

		display: flex;
		align-items: center;

		.icon {
			display: flex;
			align-items: center;
			margin-right: 10rpx;
			image{
				width: 30rpx;
				height: 30rpx;
			}
		}

		.text {}
	}
</style>
