<!--
 * @Author: zhp
 * @Date: 2024-05-10 11:10:54
 * @LastEditTime: 2024-06-05 09:49:46
 * @LastEditors: zhp
 * @Description:
-->

<template>
  <div class="yield-copilot">
    <section class="top flex">
      <right-container class="std-yield" title="标准组件产出" icon="std">
        <std-output v-if="show" :period="period" :than="than" />
      </right-container>
      <db-container class="chip-yield" title="芯片产出" icon="chip2">
        <chip-output v-if="show" :period="period" :than="than" />
      </db-container>
      <left-container class="bipv-yield" title="BIPV产出" icon="bipv">
        <bipv-output v-if="show" :period="period" :than="than" />
      </left-container>
    </section>
    <section class="bottom flex">
      <right-container class="fto-involve" title="FTO投入">
        <fto-invest :period="period" :than="than" />
      </right-container>
      <left-container class="chip-involve" title="芯片投入" icon="chip">
        <chip-invest :period="period" :than="than" />
      </left-container>
    </section>
  </div>
</template>

<script>
import twoContainer from "@/views/copilot/components/twoContainer.vue";
import leftContainer from "@/views/copilot/components/leftContainer.vue";
import rightContainer from "@/views/copilot/components/rightContainer.vue";

import StdOutput from "./components/StdOutput.vue";
import ChipOutput from "./components/ChipOutput.vue";
import FtoInvest from "./components/FtoInvest.vue";
import BipvOutput from "./components/BipvOutput.vue";
import ChipInvest from "./components/ChipInvest.vue";

export default {
  name: "YieldCopilot",
  components: {
    DbContainer: twoContainer,
    leftContainer,
    rightContainer,
    StdOutput,
    ChipOutput,
    BipvOutput,
    FtoInvest,
    ChipInvest,
  },
  props: {
    period: {
      type: String,
      default: "日",
    },
    than: {
      type: String,
      default: "同比",
    },
  },
  data() {
    return {
      show:false,
    };
  },
  watch: {
    period: {
      handler(val) {
        val && this.fetchData(val,this.than);
      },
      immediate: true,
    },
    than: {
      handler(val) {
        console.log(val)
        val && this.fetchData(this.period,val);
      },
      immediate: true,
    },
  },
  methods: {
    fetchData(period = "日", than) {
      // this.$store.commit('copilot/clearState')
      console.log(`产量驾驶舱，获取${period}数据`);
      this.$store.dispatch("copilot/initCopilot", { period, source: "yield", than }).then(() => {
        this.$nextTick(() => {
          this.show = true
        })
      })
    },
  },
};
</script>

<style scoped>
.yield-copilot {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.flex {
  display: flex;
  gap: 16px;
  flex: 1;
}

.top > div,
.bottom > div {
  height: 100%;
}
</style>
