<script lang="ts" setup name="countPagetable">
import fixedCombustion from './components/fixedCombustion.vue'
import mobileCombustion from './components/mobileCombustion.vue'
import energyProcessing from './components/energyProcessing.vue'
import Purchaseofheat from './components/Purchaseofheat.vue'
import Purchaseofelectricity from './components/Purchaseofelectricity.vue'
import photovoltaic from './components/photovoltaic.vue'
const fixRef = ref()
const mobileRef = ref()
const energyRef = ref()
const heatRef = ref()
const electricityRef = ref()
const photovoltaicRef = ref()
const saveData = () => {
  // 固定燃烧数据
  const fixData = fixRef.value.tableData
  sessionStorage.setItem('固定燃烧-table', JSON.stringify(fixData))
  // 移动燃烧数据
  const mobileData = mobileRef.value.tableData
  sessionStorage.setItem('移动燃烧-table', JSON.stringify(mobileData))
  // 能源加工转换
  const energyData = energyRef.value.tableData
  sessionStorage.setItem('能源加工转换-table', JSON.stringify(energyData))
  // 购入热力
  const heatData = heatRef.value.tableData
  sessionStorage.setItem('购入热力-table', JSON.stringify(heatData))
  // 购入电力
  const electricityData = electricityRef.value.tableData
  sessionStorage.setItem('购入电力-table', JSON.stringify(electricityData))
  // 光伏
  const photovoltaicData = photovoltaicRef.value.tableData
  sessionStorage.setItem('光伏-table', JSON.stringify(photovoltaicData))
}
const getData = () => {
  // 固定燃烧数据
  const fixData = fixRef.value.sumArr
  const value1 = {
    name: '固定燃烧',
    co: fixData[2],
    ch: fixData[4],
    no: fixData[6],
  }
  sessionStorage.setItem('固定燃烧', JSON.stringify(value1))
  // 移动燃烧数据
  const mobileData = mobileRef.value.sumArr
  const value2 = {
    name: '移动燃烧',
    co: mobileData[2],
    ch: mobileData[4],
    no: mobileData[6],
  }
  sessionStorage.setItem('移动燃烧', JSON.stringify(value2))
  // 能源加工转换
  const energyData = energyRef.value.sumArr
  const value3 = {
    name: '能源加工转换',
    co: 0,
    ch: 0,
    no: 0,
  }
  sessionStorage.setItem('能源加工转换', JSON.stringify(value3))
  // 购入热力
  const heatData = heatRef.value.sumArr
  const value4 = {
    name: '购入热力',
    co: heatData[2] ? heatData[2] : 0,
    ch: heatData[4] ? heatData[4] : 0,
    no: heatData[6] ? heatData[6] : 0,
  }
  sessionStorage.setItem('购入热力', JSON.stringify(value4))
  // 购入电力
  const electricityData = electricityRef.value.sumArr
  const value5 = {
    name: '购入电力',
    co: electricityData[2] ? electricityData[2] : 0,
    ch: electricityData[4] ? electricityData[4] : 0,
    no: electricityData[6] ? electricityData[6] : 0,
  }
  sessionStorage.setItem('购入电力', JSON.stringify(value5))
  // 光伏
  const photovoltaicData = photovoltaicRef.value.sumArr
  const value6 = {
    name: '光伏',
    co: photovoltaicData[4],
    ch: 0,
    no: 0,
  }
  sessionStorage.setItem('光伏', JSON.stringify(value6))
}
defineExpose({
  getData, saveData,
})
</script>

<template>
  <div style="position: relative; left: 12%; width: 85%;">
    <!-- 固定燃烧 -->
    <fixed-combustion ref="fixRef" />
    <!-- 移动燃烧 -->
    <mobile-combustion ref="mobileRef" />
    <!-- 能源加工转换 -->
    <energy-processing ref="energyRef" />
    <!-- 购入热力 -->
    <purchaseofheat ref="heatRef" />
    <!-- 购入电力 -->
    <purchaseofelectricity ref="electricityRef" />
    <!-- 光伏 -->
    <photovoltaic ref="photovoltaicRef" />
  </div>
</template>
