<template>
	<view class="charts-box">
		<qiun-data-charts :type="echartsData.chartType" :eopts="opts" :chartData="chartData" :ontouch="true"
			:onzoom="true" :echartsH5="true" />
	</view>
</template>

<script>
	export default {
		props: {
			echartsData: Object
		},
		data() {
			return {
				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['line'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
						"#ea7ccc"
					],
					padding: [15, 10, 0, 15],
					enableScroll: true,
					legend: {
						type: 'scroll',
						pageIconSize: 18,
						margin: 20,
						itemGap: 20,
						lineHeight: 20,
						top: 0,
					},
					grid: {
						bottom: '25%',
						top: "50px",
						left: "45px",
						right: "30px"
					},
					xAxis: {
						disableGrid: true,
						scrollShow: false,
						itemCount: 2,
						scrollAlign: 'right',
						// rotateLabel: true,
						// rotateAngle: 10
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2,
					},
					extra: {
						line: {
							type: "straight",
							width: 2,
							activeType: "hollow"
						}
					},
					tooltip: {
						trigger: 'axis',
						axisPointer: {
							type: 'cross',
							label: {
								backgroundColor: '#6a7985'
							}
						}
					},
					dataZoom: [{
							type: 'slider',
							show: true,
							xAxisIndex: [0],
							start: 90,
							end: 100
						},
						{
							type: 'slider',
							show: true,
							yAxisIndex: [0],
							left: '93%',
							start: 60,
							end: 100
						},
						{
							type: 'inside',
							xAxisIndex: [0],
							start: 90,
							end: 100
						},
						{
							type: 'inside',
							yAxisIndex: [0],
							start: 60,
							end: 100
						}
					],
				},
				timeNum: 10
			};
		},
		mounted() {
			this.getEmit();
		},
		methods: {
			getServerData() {
				const chartData = this.echartsData.chartItemList

				const timeData = chartData[0].valueTimeList
				const time = timeData.map(item => {
					return item.substring(0, this.timeNum)
				})
				const series = chartData.map(item => {
					return {
						name: item.describe ? item.describe : item.itemName,
						data: item.valueList
					}
				})
				let res = {
					categories: time,
					series: series
				};
				this.chartData = JSON.parse(JSON.stringify(res));
			},
			getEmit() {
				const {
					bucketType,
					bucketValue
				} = this.echartsData
				let time = null
				switch (bucketType) {
					case 0:
						time = 86400000 * bucketValue
						this.timeNum = 4
						break;
					case 1:
						time = 3600000 * bucketValue
						this.timeNum = 13
						break;
					case 2:
						time = 60000 * bucketValue
						this.timeNum = 16
						break;
					case 3:
						time = 1000 * bucketValue
						this.timeNum = 19
						break;
				}
				this.getServerData()
				this.$emit('linePolling', time, this.echartsData.id)
			}
		}
	};
</script>

<style scoped>
	/* 请根据实际需求修改父元素尺寸，组件自动识别宽高 */
	.charts-box {
		width: 100%;
		height: 540rpx;
	}
</style>