<template>
  <div id="data-view">
    <dv-full-screen-container>
      <div class="main-header">
        <div class="mh-left">
          <img src="../../../assets/images/logo.png" alt="" />
        </div>
        <div class="mh-middle">成品包装线生产看板</div>
        <div class="mh-right">{{currentDateTime}}
        </div>
      </div>

      <dv-border-box-1 class="main-container">
        <div class="mc-top">
          <Top-Left-Cmp :data="valueForTopLeftCmp"/>
          <Top-Middle-Cmp :data="valueForTopMiddleCmp" />
          <Top-right-Cmp />
        </div>
        <div class="mc-bottom">
          <BottomRightTable1  :tableData="BottomRightTableValue"/>
        </div>

<!--        <div class="mc-bottom">-->
<!--          <BottomRightTable1 v-for="index in 4" :key="index+4" :tableIndex="index" :tableData="BottomRightTable2Value"/>-->
<!--        </div>-->
      </dv-border-box-1>

    </dv-full-screen-container>
  </div>
</template>

<script>

import { finishProductBoard } from "@/api/kanban/finishproduct";
import TopLeftCmp from './TopLeftCmp'
import TopMiddleCmp from './TopMiddleCmp'
import TopRightCmp from './TopRightCmp'


import BottomRightTable1 from './BottomRightTable1'



export default {
  name: 'DataView',
  components: {
    TopLeftCmp,
    TopMiddleCmp,
    TopRightCmp,
    BottomRightTable1,
  },
  data () {
    return {
      currentDateTime: null,
      // 在这里定义要传递的值
      valueForTopLeftCmp: {
        sumplanquantity: 0,
        sumFinshQuantity: 0,
      },
      valueForTopMiddleCmp:[],
      BottomRightTableValue:[],

    };
  },
  methods: {
    getCurrentTime() {
      const currentDate = new Date();
      const year = currentDate.getFullYear();
      const month = (currentDate.getMonth() + 1).toString().padStart(2, '0');
      const day = currentDate.getDate().toString().padStart(2, '0');
      const hours = currentDate.getHours().toString().padStart(2, '0');
      const minutes = currentDate.getMinutes().toString().padStart(2, '0');
      const seconds = currentDate.getSeconds().toString().padStart(2, '0');

      this.currentDateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    async finishProductBoard() {
      try {
        const response = await finishProductBoard({ factory: 1000 });
        console.log(response.data);
        this.valueForTopLeftCmp.sumplanquantity = response.data.sumplanquantity ?? 0;;
        this.valueForTopLeftCmp.sumFinshQuantity = response.data.sumFinshQuantity ?? 0;;
        this.valueForTopMiddleCmp=response.data.daySenvenProductionList;
        this.BottomRightTableValue = response.data.ProductionInProgress;


      } catch (error) {
        console.error('Error fetching data:', error);
      }
    }

  },
  mounted() {
    this.getCurrentTime();
    // 如果你想每秒更新一次时间，可以使用定时器
    setInterval(() => {
      this.getCurrentTime();
    }, 1000);
    this.finishProductBoard(); // 手动调用一次以确保数据加载
    setInterval(() => {
      this.finishProductBoard();
    }, 20000);
  }
}
</script>

<style lang="less">
#data-view {
  width: 100%;
  height: 100%;
  background-color: #030409;
  color: #fff;

  #dv-full-screen-container {
    background-image: url("../../../assets/images/bg-finishproduct.png");
    background-size: 100% 100%;
    box-shadow: 0 0 3px blue;
    display: flex;
    flex-direction: column;
  }

  .main-header {
    height: 80px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;

    .mh-left {
      margin-top: 10px;
    }

    .mh-middle {
      font-size: 30px;
    }

    .mh-left, .mh-right {
      width: 200px;
    }
  }

  .main-container {
    height: calc(~"100% - 80px");
    margin-left:0px;
    .mc-top, .mc-bottom ,mc-bottom-1 {
      box-sizing: border-box;
      padding: 30px;
      display: flex;

    }

    .mc-top {
      height: 40%;
    }

    .mc-bottom-1, .mc-bottom-2 {
      height: 100%;
    }

    .top-left-cmp, .bottom-left-container {
      width: 32%;
    }

    .top-middle-cmp, .top-right-cmp {
      width: 34%;
    }

    .bottom-left-container {
      position: relative;

      .border-box-content {
        display: flex;
      }

      .mcb-decoration-1, .mcb-decoration-2 {
        position: absolute;
        left: 50%;
        margin-left: -2px;
      }

      .mcb-decoration-1 {
        top: 5%;
        transform: rotate(180deg);
      }

      .mcb-decoration-2 {
        top: 50%;
      }

      .bottom-left-chart-1, .bottom-left-chart-2 {
        width: 50%;
        height: 100%;
      }
    }

    .bottom-right-container {
      width: 68%;
      padding-left: 30px;
      box-sizing: border-box;
      display: flex;
    }
  }
}
</style>
