<template>
	<view class="content">
		<view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts3" class="echarts"></view>

	</view>
</template>

<script>
	//start

	//end


	export default {
		
		
		props:{
			bindData:{
				type:Object,
				default: ''
			}
		},
		
		data() {
			return {
				option: {
					// legend: {
					//         data: ['bar', 'bar2', 'bar3', 'bar4'],
					// 		color: ['#1ECC22', '#0FC6C8','#0D88F0', '#FF1313', '#FF522A' ],
							
					//     },
					grid: {  //aa位置
						top: '2%',
						right: '8%',
						bottom: '1%',
						left: '17%',
						
					},

					color: ['#1ECC22', '#0FC6C8','#0D88F0', '#FF1313', '#FF522A' ],
					xAxis: [{
						show: false
					}],
					yAxis: [{  //aay轴
							axisTick: 'none',
							axisLine: 'none',
							axisLabel: {
								verticalAlign: 'bottom',
								align: 'bottom',
								padding: [0, 0, 8, 5],
								textStyle: {
									color: '#333',
									fontSize:'15'

								}
							},
							data: ['正常','其他','预警','故障','离线'   ],

						},
						{
							//左侧柱状图的Y轴
							axisTick: 'none',
							axisLine: 'none',
							data: [this.bindData.normalCount,this.bindData.otherCount,this.bindData.earlyWarningCount,this.bindData.earlyWarningCount,this.bindData.offlineCount],
							axisLabel: {
								show: true,
								verticalAlign: 'bottom',
								align: 'right',
								padding: [0, 10, 8, 0],
								textStyle: {
									color: '#333',
									fontSize:'15'

								},
								formatter: function(value) {
									return value 
								}

							}
						},

					],
					series: [{
							type: 'bar',
							data: [this.bindData.normalCount, , , , ],
							barWidth: 6,
							itemStyle: {
								normal: {
									barBorderRadius: 6,
								}
							},
							z: 2
						}, {
							type: 'bar',
							data: [ ,this.bindData.otherCount, , , ],
							barWidth: 6,
							itemStyle: {
								normal: {
									barBorderRadius: 6,
								}
							},
							z: 2
						}, {
							type: 'bar',
							data: [ , ,this.bindData.earlyWarningCount, , ],
							barWidth: 6,
							itemStyle: {
								normal: {
									barBorderRadius: 6,
								}
							},
							z: 2
						},
						{
							type: 'bar',
							data: [ , , ,this.bindData.faultCount, ],
							barWidth: 6,
							itemStyle: {
								normal: {
									barBorderRadius: 6,
								}
							},
							z: 2
						},
						{
							type: 'bar',
							data: [ , , , ,this.bindData.offlineCount],
							barWidth: 6,
							itemStyle: {
								normal: {
									barBorderRadius: 6,
								}
							},
							z: 2
						},

						{
							type: 'bar',
							barGap: '-100%',
							data: [1000, 1000, 1000, 1000, 1000],
							barWidth: 6,
							itemStyle: {
								normal: {
									color: 'rgba(0,0,0, 0.15)',
									barBorderRadius: 6,
								}
							},
							z: 0
						},
					]
				}
			}
			
			
		},
		computed: {
					// total:function(){
					// 	 return parseInt(this.bindData.normalCount)+3
					//  },
					// onePersent:function(){
					// 	 return parseInt(1/this.total*100)
					//  },
					 
					 
		},
		onLoad() {
			
			// this.option.series.reverse()

		},
		
		methods: {
			changeOption() {
				const data = this.option.series[0].data
				// 随机更新示例数据
				data.forEach((item, index) => {
					data.splice(index, 1, Math.random() * 40)
				})
			},
			onViewClick(options) {
				console.log(options)
			}
		}
	}
</script>

<script module="echarts" lang="renderjs">
	let myChart
	export default {
		mounted() {
			if (typeof window.echarts === 'function') {
				this.initEcharts()
			} else {
				// 动态引入较大类库避免影响页面展示
				const script = document.createElement('script')
				// view 层的页面运行在 www 根目录，其相对路径相对于 www 计算
				script.src = 'static/echarts.min.js'
				script.onload = this.initEcharts.bind(this)
				document.head.appendChild(script)
			}
		},
		methods: {
			initEcharts() {
				myChart = echarts.init(document.getElementById('echarts3'))
				// 观测更新的数据在 view 层可以直接访问到
				myChart.setOption(this.option)
			},
			updateEcharts(newValue, oldValue, ownerInstance, instance) {
				// 监听 service 层数据变更
				myChart.setOption(newValue)
			},
			onClick(event, ownerInstance) {
				// 调用 service 层的方法
				ownerInstance.callMethod('onViewClick', {
					test: 'test'
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.echarts {
		width: 100%;
		height: 500rpx;
		margin-top: 70rpx;
		/* 	background:pink */
	}
</style>
