<template>
	<div class="screen-body">
		<div class="screen-body-col col-side">
			<div class="side-echarts1" v-for="(e,ex) in echartsList.slice(0,2)">
				<echartsTitle :orderData="e" :hierarchy="1">
					{{$i18n.locale === 'zh-CN'?e.targetName:e.targetNameEn}}({{e.targetUnit}})
				</echartsTitle>
				<!-- <div class="more" @click="handleMore(e)">所有企业</div> -->
				<div :id="'pieChart'+ex" class="full" refs=""></div>
			</div>
		</div>
		<div class="screen-body-col col-side">
			<div class="side-echarts1" v-for="(e,ex) in echartsList.slice(2,4)">
				<echartsTitle :orderData="e" :hierarchy="1">
					{{$i18n.locale === 'zh-CN'?e.targetName:e.targetNameEn}}({{e.targetUnit}})
				</echartsTitle>
				<!-- <div class="more" @click="handleMore(e)">所有企业</div> -->
				<div :id="'pieChart'+(2+ex)" class="full" refs=""></div>
			</div>
		</div>
		<div class="screen-body-col col-side">
			<div class="side-echarts1" v-for="(e,ex) in echartsList.slice(4)">
				<echartsTitle :orderData="e" :hierarchy="1">
					{{$i18n.locale === 'zh-CN'?e.targetName:e.targetNameEn}}({{e.targetUnit}})
				</echartsTitle>
				<!-- <div class="more" @click="handleMore(e)">所有企业</div> -->
				<div :id="'pieChart'+(4+ex)" class="full" refs=""></div>
			</div>
		</div>
	</div>
</template>
<script>
	import {
		mapState
	} from 'vuex'
	import * as echarts from 'echarts'
	import dictUtils from '@/components/dict/DictSelectUtils.js'
	import operationTheme from '@/api/bigScrenn/operationTheme.js'
	import echartsTitle from '@/views/BigScrenn/fundTheme/components/echartsTitle.vue'
	import fundTheme from '@/api/bigScrenn/fundTheme.js'
	export default {
		components: {
			echartsTitle,
		},
		props: {
			poolCode: {
				type: Array
			},
		},
		data() {
			return {
				currentKey: 'fundTheme',
				tabActive: 0,
				echartsList: [], //所有echarts数据
				tabList: [{
						name: "宏观数据",
						value: 0
					},
					{
						name: "运行板块",
						value: 1
					},
					{
						name: "销售板块",
						value: 2
					},
				],
				dataList: [],
				staLatList: [],
				leftList: [], //左边echarts
				rightList: [], //右边echarts
				centerList: [],
				leftData: [], //左边
				rightData: [], //右边
				rateData: {},
				options: [{
					value: '选项1',
					label: '1'
				}],
				value: '',
				options1: [{
					value: '选项1',
					label: '2'
				}],
				value1: '',
				tjwdList: [],
				enterpriseCode: ''
			}
		},
		created() {
			this.tjwdList = this.$i18n.locale === 'zh-CN' ? dictUtils.getDictItemsFromCache('tjwd') : dictUtils
				.getDictItemsFromCache('tjwd_en')
			this.getData(2)

		},
		mounted() {
			this.$root.$on('resize', () => {
				this.resize(500)
			})
		},
		watch: {
			poolCode(val, value) {
				this.enterpriseCode = JSON.parse(JSON.stringify(this.poolCode)).pop()
				this.getData()
			}
		},
		methods: {
			clickTab(val) {
				this.tabActive = val
			},


			arraySort(property) {
				return function(a, b) {
					var value1 = a[property]
					var value2 = b[property]
					return value1 - value2
				}
			},
			getData(val) {
				// let enterpriseCode = JSON.parse(JSON.stringify(val)).pop()
				this.dataList = []
				this.echartsList = []
				this.leftList = []
				this.rightList = []
				fundTheme.oneLevelData({
					enterpriseCode: this.enterpriseCode
				}, res => {
					if (res.value.length > 0) {
						this.echartsList = res.value
					}
					this.echartsList.sort(this.arraySort('sn'))
					console.log(this.echartsList.slice(0, 2));
					this.$nextTick(() => {
						this.echartsList.forEach((c, cx) => {
							this.dateEcharts(c, cx)
						})
					})
				})
			},

			//更多企业
			handleMore(val) {
				this.$refs.echartsDialog.add(val, 2)
			},
			dateEcharts(c, cx) {
				let chartDom = echarts.init(document.getElementById(`pieChart${cx}`))
				let arr = []
				let xLabel = [];
				c.resultData.forEach(r => {
					xLabel.push(r.year)
				})
				if (c.staLat && c.staLat.split(',').length > 1) {
					this.tjwdList.forEach(s => {
						c.staLat.split(',').forEach(t => {
							if (s.value == t) {
								let datalist = []
								if (t == 1) {
									c.resultData.forEach(r => {
										datalist.push(r.actual)
									})
								} else if (t == 2) {
									c.resultData.forEach(r => {
										datalist.push(r.budget)
									})
								} else if (t == 3) {
									c.resultData.forEach(r => {
										datalist.push(r.actual)
									})
								} else if (t == 4) {
									c.resultData.forEach(r => {
										datalist.push(r.budget)
									})
								} else if (t == 5) {
									c.resultData.forEach(r => {
										datalist.push(r.actual)
									})
								} else if (t == 6) {
									c.resultData.forEach(r => {
										datalist.push(r.actual)
									})
								}
								if (t == 3) {
									arr.push({
										name: s.name,
										type: 'bar',
										symbol: 'circle', // 默认是空心圆（中间是白色的），改成实心圆
										smooth: true,
										lineStyle: {
											normal: {
												width: 3,
											},
										},
										itemStyle: {
											normal: {
												label: {
													show: false, //开启显示
													color: '#fff',
													position: 'top', //在上方显示
													formatter: function(res) {
														if (res.value) {
															return res.value
														} else {
															return 0
														}
													},
												},
											},

										},
										symbolSize: 8, //设定实心点的大小
										data: datalist

									}, )
								} else {
									arr.push({
										name: s.name,
										type: 'line',
										symbol: 'circle', // 默认是空心圆（中间是白色的），改成实心圆
										smooth: true,
										lineStyle: {
											normal: {
												width: 3,
												// color: '#518EF5', // 线条颜色
											},
										},
										itemStyle: {
											normal: {
												// color: '#518EF5', //拐点颜色
												// borderColor: '#fff600',//拐点边框颜色
												// borderWidth: 13//拐点边框大小
												label: {
													show: false, //开启显示
													color: '#fff',
													position: 'top', //在上方显示
													formatter: function(res) {
														if (res.value) {
															return res.value
														} else {
															return 0
														}
													},
												},
											},

										},
										symbolSize: 8, //设定实心点的大小
										data: datalist
										// c.resultData.forEach(r => {
										// 	if (t == 1) {
										// 		console.log(r);
										// 		return [...r.actual]
										// 	} else {
										// 		// arrData.push()
										// 		return [...r.budget]
										// 	}
										// }),
									}, )
								}
							}
						})
					})
				} else {
					this.tjwdList.forEach(s => {
						let data1list = []
						if (c.staLat == 1) {
							c.resultData.forEach(r => {
								data1list.push(r.actual)
							})
						} else if (c.staLat == 2) {
							c.resultData.forEach(r => {
								data1list.push(r.budget)
							})
						} else if (c.staLat == 3) {
							c.resultData.forEach(r => {
								data1list.push(r.actual)
							})
						} else if (c.staLat == 4) {
							c.resultData.forEach(r => {
								data1list.push(r.budget)
							})
						} else if (c.staLat == 5) {
							c.resultData.forEach(r => {
								data1list.push(r.actual)
							})
						} else if (c.staLat == 6) {
							c.resultData.forEach(r => {
								data1list.push(r.actual)
							})
						}
						if (s.value == c.staLat) {
							arr.push({
								name: s.name,
								type: 'line',
								symbol: 'circle', // 默认是空心圆（中间是白色的），改成实心圆
								smooth: true,
								lineStyle: {
									normal: {
										width: 3,
										// color: '#518EF5', // 线条颜色
									},
								},
								itemStyle: {
									normal: {
										// color: '#518EF5', //拐点颜色
										// borderColor: '#fff600',//拐点边框颜色
										// borderWidth: 13//拐点边框大小
										label: {
											show: false, //开启显示
											color: '#fff',
											position: 'top', //在上方显示
											formatter: function(res) {
												if (res.value) {
													return res.value
												} else {
													return 0
												}
											},
										},
									},

								},
								symbolSize: 8, //设定实心点的大小
								data: data1list
							}, )
						}
					})
				}
				let option = {
					backgroundColor: '',
					tooltip: {
						trigger: 'axis',
						// 自定义tooltip内容
						formatter: (item) => {
							let str =
								`<div style="text-align:center;font-weight:700;font-size:16px">${item[0].name}</div>`
							let index = 0 // 命名一个索引，用于匹配增减值、增减率
							let leftClass =
								`<span style="display: inline-block; width: ${this.$i18n.locale === 'zh-CN'?'100px':'150px'}; text-align: left;">`
							let rightClass =
								'<span style="display: inline-block; width: 80px; text-align: right;">'
							item.forEach(it => {
								str +=
									`${ leftClass + it.seriesName}:</span>${ rightClass + it.value}</span></br>`
								index = it.dataIndex
							})
							if (c.resultData[index].differenceValue !== undefined) {
								str = str +
									`${leftClass}${this.$i18n.locale === 'zh-CN'?'增减值':'Value of increase or decrease'}:</span>${rightClass + c.resultData[index].differenceValue}</span></br>`
								if (c.resultData[index].differenceRate !== undefined) {
									str = str +
										`${leftClass}${this.$i18n.locale === 'zh-CN'?'增减率':'Rate of increase and decrease'}:</span>${rightClass + c.resultData[index].differenceRate}</span>`
								}
							}
							return str
						}

					},
					legend: {
						show: true,
						textStyle: {
							color: '#fff',
							fontSize: 14,
							padding: [0, 8, 0, 8]
						}
					},
					grid: {
						top: '18%',
						left: '14%',
						right: '5%',
						bottom: '15%',
					},
					xAxis: [{
						type: 'category',

						axisLabel: {
							textStyle: {
								color: '#FFFFFF',
								fontSize: 12,
							},
						},
						splitLine: {
							show: false,
							lineStyle: {
								color: '#233653',
							},
						},
						axisTick: {
							show: false,
						},
						data: xLabel,
					}, ],
					yAxis: [{
						// name: c.targetUnit,
						nameTextStyle: {
							color: "#fff",
							fontSize: 12,
							padding: [0, 60, 0, 0]
						},
						type: 'value',
						splitLine: {
							show: true,
							lineStyle: {
								color: '#1160a0',
								type: 'dashed'
							},
						},
						axisLabel: {
							interval: 0, //标签设置为全部显示
							formatter: function(params) {
								const units = ['', '万', '百万', '亿', '万亿'];
								let unitIndex = 0;
								if (params < 0) {
									params = Math.abs(params)
									while (params >= 10000 && unitIndex < units.length - 1) {
										params /= 10000;
										unitIndex++;
									}
									params = (0 - params)

								} else {
									while (params >= 10000 && unitIndex < units.length - 1) {
										params /= 10000;
										unitIndex++;
									}

								}
								const formattedNumber = params

								return formattedNumber + units[unitIndex];
							},
							textStyle: {
								color: '#fff',
								fontSize: 14
							}
						},
						axisTick: {
							show: false,
						},
						triggerEvent: true

					}, ],
					series: arr
				}
				option && chartDom.setOption(option)

			},

		}
	}
</script>

<style lang="scss" scoped>
	@font-face {
		font-family: 'YouSheBiaoTiHei';
		src: url(~@/assets/fonts/YouSheBiaoTiHei-2.ttf);
	}

	@keyframes rotateImage {
		from {
			transform: rotate(0deg)
		}

		to {
			transform: rotate(360deg)
		}
	}

	@keyframes breath {
		from {
			opacity: 0.1;
		}

		50% {
			opacity: 1;
		}

		to {
			opacity: 0.1;
		}
	}

	@-webkit-keyframes breath {
		from {
			opacity: 0.1;
		}

		50% {
			opacity: 1;
		}

		to {
			opacity: 0.1;
		}
	}

	.full {
		margin-top: 20px;
		height: calc(100% - 60px);
	}

	.full2 {
		margin-top: 55px;
		height: calc(100% - 60px);
	}

	.tab {
		width: 550px;
		height: 56px;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: space-evenly;

		.item {
			width: 134px;
			height: 40px;
			line-height: 40px;
			border-radius: 10px;
			background: linear-gradient(180deg, rgba(27, 154, 182, 1) 0%, rgba(18, 89, 132, 1) 100%);

			color: #fff;
			font-size: 16px;
			text-align: center;

		}

		.item-active {
			width: 134px;
			height: 40px;
			line-height: 40px;
			border-radius: 10px;
			background: linear-gradient(180deg, rgba(230, 129, 83, 1) 0%, rgba(74, 47, 31, 1) 100%);
			color: #fff;
			font-size: 16px;
			text-align: center;
		}
	}

	.screen-body {
		display: flex;
		justify-content: space-between;
		width: 100%;
		height: calc(100% - 108px);
		padding: 0 5px;
		box-sizing: border-box;

		.screen-body-col {
			width: 100%;
		}

		.col-side {
			width: 32%;
			height: 100%;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.side-echarts {
				position: relative;
				width: 100%;
				height: 32%;
				// background: url('~@/assets/img/echarts-bg.png') center / 100% 100% no-repeat;

			}

			.side-echarts1 {
				position: relative;
				width: 100%;
				height: 49%;
				// background: url('~@/assets/img/bg-2.png') center / 100% 100% no-repeat;
			}

			.more {
				position: absolute;
				align: right;
				top: 23px;
				right: 10px;
				width: 113px;
				height: 31px;
				cursor: pointer;
				line-height: 30px;
				text-align: center;
				font-size: 14px;
				font-family: Microsoft YaHei;
				font-weight: 300;
				color: #FFFFFF;
				background: url('~@/assets/img/more.png') center / 100% 100% no-repeat;
			}

			.more2 {
				position: absolute;
				align: right;
				top: 36px;
				right: 10px;
				width: 113px;
				height: 31px;
				line-height: 30px;
				text-align: center;
				font-size: 14px;
				font-family: Microsoft YaHei;
				font-weight: 300;
				color: #FFFFFF;
				background: url('~@/assets/img/more.png') center / 100% 100% no-repeat;
			}

			.active {
				color: #CCCCCC;
			}

			.side-echart2 {
				position: relative;
				background: url('~@/assets/img/echarts-bg2.png') center / 100% 100% no-repeat;

				.title2 {
					font-family: YouSheBiaoTiHei;
					font-weight: 400;
					color: #FFFFFF;
					line-height: 38px;
					position: relative;
					display: flex;

					div:nth-child(1) {
						font-size: 22px !important;
						width: 150px;
						position: absolute;
						left: 60px;
						text-align: center;
					}

					div:nth-child(2) {
						font-size: 22px !important;
						position: absolute;
						width: 110px;
						right: 100px;
						text-align: center;
					}
				}
			}
		}

	}

	.axis-tip {
		display: none;
		position: absolute;
		padding: 5px 5px;
		font-size: 12px;
		line-height: 18px;
		color: #575757;
		background: #ffffff;
		box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.2);
		border-radius: 4px;
	}


	//下拉框
	/deep/.el-select-dropdown {
		border: none;
		background-color: rgba(1, 28, 82, 0.8);
	}

	//输入框
	/deep/ .el-input {
		height: 35px !important;
	}

	/deep/ .el-input__inner {
		height: 35px !important;
		color: #eee;
		border-color: #00fff6;
		background-color: rgba(1, 28, 82, 0.8);
	}

	//聚焦时的样式
	.el-select .el-input.is-focus .el-input__inner {
		border-color: #0B61AA;
		background-color: rgba(1, 28, 82, 0.8);
		color: #00D3E9;
	}

	//下拉框选中
	.el-select-dropdown__item {
		color: #eee;
	}

	//鼠标经过下拉框
	.el-select-dropdown__item.hover,
	.el-select-dropdown__item:hover {
		color: #00D3E9;
		background-color: #0F3360;
	}
</style>