<template>
  <div class="xtjc-left-side">
    <!-- 预报A -->
    <predictionA
      v-if="prediction.predictionAData.name.length > 0"
      :predictionData="prediction.predictionAData"
      :title="pageTitle"
      :nodeId="'predictionA'"
    />

    <!-- 预报B -->
    <predictionA
      v-if="prediction.predictionBData.name.length > 0"
      :predictionData="prediction.predictionBData"
      :title="pageTitle2"
      :nodeId="'predictionB'"
    />
  </div>
</template>

<script lang="ts" setup>
import { reactive, onMounted } from 'vue';
import predictionA from './components/predictionA.vue';
import eventBus from '/@/utils/eventBus';
let pageTitle = reactive({
  titleText: '雨洪对照图',
  pageTitle: '',
  lat:null,
  lng:null
});
let prediction = reactive({
  predictionAData: {
    name: [],
    qf: [],
    qs: [],
    rain: [],
  },
  predictionBData: {
    name: [],
    qf: [],
    qs: [],
    rain: [],
  },
});
function setPredictionAData(data) {
  prediction.predictionAData = {
    name: [],
    qf: [],
    qs: [],
    rain: [],
  };
  pageTitle.pageTitle = data[0].st_name;
  pageTitle.lat = data[0].lat;
  pageTitle.lng = data[0].lng;
  let dataList = data[0].detail;
  dataList.forEach((element) => {
    prediction.predictionAData.name.push(element.time);
    prediction.predictionAData.qf.push(element.qf);
    prediction.predictionAData.qs.push(element.qs);
    prediction.predictionAData.rain.push(element.rain);
  });
}
let name2 = '';
function setPredictionBData(data) {
  prediction.predictionBData = {
    name: [],
    qf: [],
    qs: [],
    rain: [],
  };
  pageTitle2.pageTitle = data[1].st_name;
  pageTitle2.lat = data[1].lat;
  pageTitle2.lng = data[1].lng;
  let dataList = data[1].detail;
  dataList.forEach((element) => {
    prediction.predictionBData.name.push(element.time);
    prediction.predictionBData.qf.push(element.qf);
    prediction.predictionBData.qs.push(element.qs);
    prediction.predictionBData.rain.push(element.rain);
  });
}

let pageTitle2 = reactive({
  titleText: '雨洪对照图',
  pageTitle: '',
  lat:null,
  lng:null
});
eventBus.on('stormFlood', (e) => {
  setPredictionAData(e);
  setPredictionBData(e);
});
</script>
<style lang="less" scoped>
.xtjc-left-side {
  // position: fixed;
  position: absolute;
  left: 20px;
  top: 90px;
  z-index: 3;
  width: 430px;
  // height: calc(100% - 135px);
  // overflow-y: auto;
  // overflow-x: hidden;
}

.xtjc-left-side {
  animation-name: move;
  animation-duration: 0.5s;
  animation-fill-mode: forwards;
}

@keyframes move {
  0% {
    left: -400px;
  }

  100% {
    left: 20px;
  }
}
</style>
