<template>
  <div class="dashboard-factory-all">
    <div id="map-container">
      <div class="databoard">
        <db-header class="db-header"></db-header>
        <div class="db-body">
          <div class="db-left">
            <db-container icon="cube" title="FTO投入">
              <fto-chart />
            </db-container>
            <db-container icon="chip" title="芯片投入">
              <chip-invest-chart />
            </db-container>
          </div>
          <div class="db-right">
            <db-container
              side="right"
              icon="chip2"
              title="芯片产出"
            ></db-container>
            <db-container
              side="right"
              icon="std"
              title="标准组件产出"
            ></db-container>
            <db-container
              side="right"
              icon="stack"
              title="BIPV产出"
            ></db-container>
          </div>
        </div>
      </div>
    </div>
    <company-info
      v-if="visible"
      :info="info"
      :position="hintPosition"
      @close="closeHint"
    />
  </div>
</template>

<script>
import store from "@/store";
import DashboardHeader from "./dashboard/components/Header.vue";
import CompanyInfo from "./dashboard/components/CompanyInfo.vue";
import Container from "./dashboard/components/Container.vue";
import ChartContainer from "./dashboard/components/ChartContainer.vue";
import FtoChart from "./dashboard/charts/Fto.vue";
import ChipInvestChart from './dashboard/charts/ChipInvest.vue';

export default {
  name: "Index",
  components: {
    CompanyInfo,
    DbHeader: DashboardHeader,
    DbContainer: Container,
    ChartContainer,
    FtoChart,
    ChipInvestChart
  },
  data() {
    return {
      visible: false,
      hintPosition: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initPins();

      // 调整 echarts 大小
      window.onresize = () => {};
    });
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      store.dispatch("app/closeSideBar", { withoutAnimation: true });
    });
  },
  methods: {
    initPins() {
      [
        // 佳木斯
        { x: 67, y: 20 },
        // 成都
        { x: 46, y: 56 },
        // 蚌埠1
        { x: 60, y: 52 },
        // 蚌埠2
        { x: 61, y: 53 },
        // 江西 瑞昌
        { x: 60, y: 58 },
        // 湖南 株洲
        { x: 56, y: 60 },
      ].map((loc) => {
        const pin = document.createElement("div");
        pin.className = "pin";
        pin.style.left = `${loc.x}%`;
        pin.style.top = `${loc.y}%`;
        pin.addEventListener("mouseenter", () => {
          this.showHint({ x: loc.x, y: loc.y });
        });
        pin.addEventListener("mouseleave", () => {
          this.closeHint();
        });
        document.getElementById("map-container").appendChild(pin);
      });
    },
    closeHint() {
      this.visible = false;
      this.hintPosition = null;
    },
    showHint(position) {
      this.hintPosition = position;
      this.info = {
        // companyName: "凯盛光伏材料有限公司（本部）",
        companyName: "蚌埠兴科玻璃有限公司",
        // companyName: "成都中建材光电材料有限公司",
        // companyName: "瑞昌中建材光电材料有限公司",
        // companyName: "邯郸中建材光电材料有限公司",
        // companyName: "中建材（株洲）光电材料有限公司",
        // companyName: "佳木斯中建材光电材料有限公司",
        items: [
          { label: "FTO投入", value: "1,200" },
          { label: "芯片产出", value: "2,200" },
          { label: "芯片投入", value: "1,300" },
          { label: "标准组件产出", value: "1,100" },
        ],
      };
      this.$nextTick(() => {
        this.visible = true;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.dashboard-factory-all {
  background: #151516;
  position: fixed;
  top: 0;
  left: 54px;
  height: 100vh;
  width: calc(100vw - 54px);
  z-index: 1000;
  color: #fff;
}

#map-container {
  height: 100%;
  background: url(../assets/bgearth.png) no-repeat 0 0 / 100% 100%;
  position: relative;

  .databoard {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #15151633;
    z-index: 1;
    display: flex;
    flex-direction: column;
  }

  .db-body {
    flex: 1;
    display: flex;
    justify-content: space-between;
  }

  .db-left,
  .db-right {
    // width: 420px;
    width: 24vw;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
  }
}
</style>

<style>
.pin {
  display: inline-block;
  position: absolute;
  z-index: 9998;
  width: 1.702vw;
  height: 1.702vw;
  /* 
  width: 32px;
  height: 32px; 
  */
  background: url(../assets/pinicon.png) no-repeat 0 0 / 100% 100%;
  transition: transform 0.1s linear;
  cursor: pointer;
}

.pin:hover {
  transform: scale(1.2);
}
</style>
