<template>
  <div class="wrapper">
    <div class="left">
      <div class="box1">
        <div class="box-header">
          <div class="icon"></div>
          <div class="title">{{ "相关实体" }}</div>
          <div class="header-right">
            <el-input
              v-model="searchText"
              placeholder="搜索内容"
              :suffix-icon="Search"
              size="small"
              style="width: 150px"
            />
            <el-select
              v-model="releaseTime"
              placeholder="选择发布时间"
              style="width: 150px"
            >
              <el-option
                v-for="item in releaseTimeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </div>
        </div>
        <div class="tool-box">
          <div class="tool" @click="handleChangeChart(0)">
            <img src="./assets/images/tool1.png" alt="" />
          </div>
          <div class="tool1" @click="handleChangeChart(1)">
            <img src="./assets/images/tool2.png" alt="" />
          </div>
          <div class="tool" @click="handleChangeChart(0)">
            <img src="./assets/images/tool3.png" alt="" />
          </div>
        </div>
        <div class="box1-main" id="graphChart"></div>
        <div class="box1-footer">
          <div class="box1-footer-left">
            <img src="./assets/images/footer-icon1.png" alt="" />
          </div>
          <div class="box1-footer-center">
            {{
              `美国《大而美法案》（OBBBA）通过系统性政策调整，对中国新能源产业链形成多维度冲击，同时倒逼产业链加速重构与技术创新。`
            }}
          </div>
          <div class="box1-footer-right">
            <img src="./assets/images/footer-icon2.png" alt="" />
          </div>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="box2">
        <div class="box-header">
          <div class="icon"></div>
          <div class="title">{{ "数据详情" }}</div>
          <div class="header-right-icon">
            <img src="./assets/images/header-right-icon.png" alt="" />
          </div>
        </div>
        <div class="box2-main">
          <div class="box3">
            <div class="box-in-header">
              <div class="header-in-icon">
                <img src="./assets/images/header-icon1.png" alt="" />
              </div>
              <div class="header-in-title">{{ "科技法案" }}</div>
              <div class="header-in-right">
                <img src="./assets/images/down.png" alt="" />
              </div>
            </div>
            <div class="box3-main">
              <div
                class="box3-item"
                v-for="(item, index) in billList"
                :key="index"
              >
                <div class="box3-item-left">
                  <img :src="item.img" alt="" />
                </div>
                <div class="box3-item-center">
                  <div class="title">{{ item.name }}</div>
                  <div class="time">{{ item.time }}</div>
                </div>
                <div
                  class="box3-item-right"
                  :class="{ tag1: item.status === 1, tag2: item.status === 2 }"
                >
                  {{ item.tag }}
                </div>
              </div>
            </div>
          </div>
          <div class="box4">
            <div class="box-in-header">
              <div class="header-in-icon">
                <img src="./assets/images/header-icon2.png" alt="" />
              </div>
              <div class="header-in-title">{{ "科技政令" }}</div>
              <div class="header-in-right">
                <img src="./assets/images/down.png" alt="" />
              </div>
            </div>
            <div class="box4-main">
              <div
                class="box4-item"
                v-for="(item, index) in decreeList"
                :key="index"
              >
                <div class="box4-item-left">
                  <div class="title">{{ item.title }}</div>
                  <div class="time">{{ item.time }}</div>
                </div>
                <div class="box4-item-right">{{ item.tag }}</div>
              </div>
            </div>
          </div>
          <div class="box5">
            <div class="box-in-header">
              <div class="header-in-icon">
                <img src="./assets/images/header-icon3.png" alt="" />
              </div>
              <div class="header-in-title">{{ "科技智库" }}</div>
              <div class="header-in-right">
                <img src="./assets/images/down.png" alt="" />
              </div>
            </div>
            <div class="box5-main">
              <div
                class="box5-item"
                v-for="(item, index) in policyList"
                :key="index"
              >
                <div class="box5-item-left">
                  <img :src="item.img" alt="" />
                </div>
                <div class="box5-item-center">
                  <div class="title">{{ item.title }}</div>
                  <div class="time">{{ item.time }}</div>
                </div>
                <div class="box5-item-right">
                  <img :src="item.logo" alt="" />
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import * as echarts from "echarts";
import { Search } from "@element-plus/icons-vue";
import getGraphChart from "./utils/graphChart";
import getTreeChart from "./utils/treeChart";

import Img1 from "./assets/images/img1.png";
import Img2 from "./assets/images/img2.png";
import Img3 from "./assets/images/img3.png";
import Img4 from "./assets/images/img4.png";
import Img5 from "./assets/images/img5.png";
import Img6 from "./assets/images/img6.png";
import Icon1 from "./assets/images/icon1.png";
import Icon2 from "./assets/images/icon2.png";
import CompanyImg from "./assets/images/symbol.png";

const searchText = ref("");
const releaseTime = ref("近五年");
const releaseTimeList = ref([
  {
    label: "近半年",
    value: "近半年",
  },
  {
    label: "近一年",
    value: "近一年",
  },
  {
    label: "近两年",
    value: "近两年",
  },
  {
    label: "近三年",
    value: "近三年",
  },
  {
    label: "近五年",
    value: "近五年",
  },
]);

const billList = ref([
  {
    name: "大而美法案",
    time: "2025年7月4日",
    tag: "人工智能",
    status: 1,
    img: Img1,
  },
  {
    name: "汽车零部件25%关税实施规则",
    time: "2025年7月4日",
    tag: "能源",
    status: 2,
    img: Img2,
  },
  {
    name: "小额豁免包裹政策调整",
    time: "2025年7月4日",
    tag: "能源",
    status: 2,
    img: Img3,
  },
  {
    name: "NIH预算否决案",
    time: "2025年7月4日",
    tag: "能源",
    status: 2,
    img: Img4,
  },
]);

const decreeList = ref([
  {
    title: "关于进一步延长TikTok执法宽限期的政令发布",
    time: "2025年7月4日",
    tag: "总统政令",
  },
  {
    title: "修改对等关税税率以反映与中华人民共和国",
    time: "2025年7月4日",
    tag: "总统政令",
  },
]);

const policyList = ref([
  {
    title: "中国对AI的转型产业政策",
    time: "2025年7月4日",
    img: Img5,
    logo: Icon1,
  },
  {
    title: "中美对抗、竞争和合作跨越人工智能XXXX",
    time: "2025年7月4日",
    img: Img6,
    logo: Icon2,
  },
]);

// 绘制echarts图表
const setChart = (option, chartId) => {
  let chartDom = document.getElementById(chartId);
  chartDom.removeAttribute("_echarts_instance_");
  let chart = echarts.init(chartDom);
  chart.setOption(option);
  return chart;
};

const nodes = ref([
  {
    id: 0,
    name: "泰丰先行",
    // category: 0,
    symbolSize: 30,
    value: 8,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 1,
    name: "国轩高科",
    // category: 0,
    symbolSize: 30,
    value: 9,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 2,
    name: "智方纳米",
    // category: 2,
    symbolSize: 30,
    value: 7,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 3,
    name: "香百科技",
    // category: 1,
    symbolSize: 30,
    value: 6,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 4,
    name: "格林滨",
    // category: 2,
    symbolSize: 30,
    value: 6,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 5,
    name: "江西紫宸",
    // category: 2,
    symbolSize: 30,
    value: 7,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 6,
    name: "紫江企业",
    // category: 4,
    symbolSize: 30,
    value: 6,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 7,
    name: "大而美法案",
    // category: 4,
    symbolSize: 50,
    value: 5,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 8,
    name: "比亚迪",
    // category: 0,
    symbolSize: 30,
    value: 10,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 9,
    name: "铜陵有色",
    // category: 3,
    symbolSize: 30,
    value: 8,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 10,
    name: "长盛精密",
    // category: 1,
    symbolSize: 30,
    value: 7,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 11,
    name: "天合光能",
    // category: 0,
    symbolSize: 30,
    value: 8,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 12,
    name: "昆仑化学",
    // category: 2,
    symbolSize: 30,
    value: 6,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 13,
    name: "嘉源科技",
    // category: 1,
    symbolSize: 30,
    value: 6,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 14,
    name: "华阳集团",
    // category: 4,
    symbolSize: 30,
    value: 7,
    symbol: `image://${CompanyImg}`,
  },
  {
    id: 15,
    name: "海辰智能",
    // category: 1,
    symbolSize: 30,
    value: 7,
    symbol: `image://${CompanyImg}`,
  },
]);

const links = ref([
  { source: 0, target: 7 },
  { source: 1, target: 7 },
  { source: 1, target: 7 },
  { source: 8, target: 7 },
  { source: 8, target: 7 },
  { source: 2, target: 7 },
  { source: 2, target: 7 },
  { source: 3, target: 7 },
  { source: 3, target: 7 },
  { source: 3, target: 7 },
  { source: 4, target: 7 },
  { source: 4, target: 7 },
  { source: 5, target: 7 },
  { source: 6, target: 7 },
  { source: 9, target: 7 },
  { source: 10, target: 7 },
  { source: 11, target: 7 },
  { source: 12, target: 7 },
  { source: 13, target: 7 },
  { source: 14, target: 7 },
  { source: 15, target: 7 },
  // { source: 0, target: 1, value: 1 },
  // { source: 1, target: 8, value: 2 },
  // { source: 1, target: 2, value: 1 },
  // { source: 8, target: 11, value: 1 },
  // { source: 8, target: 9, value: 1 },
  // { source: 2, target: 5, value: 1 },
  // { source: 2, target: 12, value: 1 },
  // { source: 3, target: 10, value: 1 },
  // { source: 3, target: 15, value: 1 },
  // { source: 3, target: 13, value: 1 },
  // { source: 4, target: 5, value: 1 },
  // { source: 4, target: 12, value: 1 },
  // { source: 5, target: 6, value: 1 },
  // { source: 6, target: 14, value: 1 },
  // { source: 7, target: 14, value: 1 },
  // { source: 9, target: 10, value: 1 },
  // { source: 10, target: 15, value: 1 },
  // { source: 11, target: 13, value: 1 },
  // { source: 12, target: 14, value: 1 },
]);

const treeData = ref([
  {
    id: 7,
    name: "大而美法案",
    // category: 4,
    symbolSize: 50,
    value: 5,
    symbol: `image://${CompanyImg}`,
    children: [
      {
        id: 0,
        name: "泰丰先行",
        // category: 0,
        symbolSize: 30,
        value: 8,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 1,
        name: "国轩高科",
        // category: 0,
        symbolSize: 30,
        value: 9,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 2,
        name: "智方纳米",
        // category: 2,
        symbolSize: 30,
        value: 7,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 3,
        name: "香百科技",
        // category: 1,
        symbolSize: 30,
        value: 6,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 4,
        name: "格林滨",
        // category: 2,
        symbolSize: 30,
        value: 6,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 5,
        name: "江西紫宸",
        // category: 2,
        symbolSize: 30,
        value: 7,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 6,
        name: "紫江企业",
        // category: 4,
        symbolSize: 30,
        value: 6,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 8,
        name: "比亚迪",
        // category: 0,
        symbolSize: 30,
        value: 10,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 9,
        name: "铜陵有色",
        // category: 3,
        symbolSize: 30,
        value: 8,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 10,
        name: "长盛精密",
        // category: 1,
        symbolSize: 30,
        value: 7,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 11,
        name: "天合光能",
        // category: 0,
        symbolSize: 30,
        value: 8,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 12,
        name: "昆仑化学",
        // category: 2,
        symbolSize: 30,
        value: 6,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 13,
        name: "嘉源科技",
        // category: 1,
        symbolSize: 30,
        value: 6,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 14,
        name: "华阳集团",
        // category: 4,
        symbolSize: 30,
        value: 7,
        symbol: `image://${CompanyImg}`,
      },
      {
        id: 15,
        name: "海辰智能",
        // category: 1,
        symbolSize: 30,
        value: 7,
        symbol: `image://${CompanyImg}`,
      },
    ],
  },
]);

const handleChangeChart = (index) => {
  if (index === 0) {
    let graphChart = getGraphChart(nodes.value, links.value);
    setChart(graphChart, "graphChart");
  } else if (index === 1) {
    let treeChart = getTreeChart(treeData.value);
    setChart(treeChart, "graphChart");
  }
};

onMounted(() => {
  let graphChart = getGraphChart(nodes.value, links.value);
  setChart(graphChart, "graphChart");

  // let treeChart = getTreeChart(treeData.value);
  // setChart(treeChart, "graphChart");
});
</script>

<style lang="scss" scoped>
.wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  padding: 16px 160px;
  justify-content: space-between;
  .box-header {
    height: 45px;
    display: flex;
    position: relative;
    .icon {
      margin-top: 18px;
      width: 8px;
      height: 20px;
      border-radius: 0 4px 4px 0;
      background: var(--color-main-active);
    }
    .title {
      margin-left: 14px;
      margin-top: 14px;
      height: 26px;
      color: var(--color-main-active);
      font-family: Microsoft YaHei;
      font-size: 20px;
      font-weight: 700;
      line-height: 26px;
    }
    .header-right {
      display: flex;
      position: absolute;
      right: 17px;
      top: 14px;
      width: 312px;
      justify-content: space-between;
    }
    .header-right-icon {
      position: absolute;
      top: 14px;
      right: 12px;
      width: 28px;
      height: 28px;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .box-in-header {
    width: 484px;
    height: 48px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(234, 236, 238, 1);
    border-radius: 2px;
    background: rgba(247, 248, 249, 1);
    display: flex;
    align-items: center;
    position: relative;
    .header-in-icon {
      width: 23px;
      height: 21px;
      margin-left: 20px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .header-in-title {
      margin-left: 15px;
      height: 24px;
      color: var(--color-main-active);
      font-family: Microsoft YaHei;
      font-size: 18px;
      font-weight: 700;
      line-height: 24px;
    }
    .header-in-right {
      position: absolute;
      top: 12px;
      right: 16px;
      width: 12px;
      height: 8px;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .left {
    width: 1068px;
    height: 847px;
    border-radius: 4px;
    box-shadow: 0px 0px 15px 0px rgba(60, 87, 126, 0.2);
    background: rgba(255, 255, 255, 1);
    .box1 {
      position: relative;
      .tool-box {
        position: absolute;
        left: 21px;
        top: 59px;
        width: 96px;
        height: 28px;
        box-sizing: border-box;
        border: 1px solid rgba(234, 236, 238, 1);
        border-radius: 4px;
        background: rgba(255, 255, 255, 1);
        z-index: 9999;
        display: flex;
        align-items: center;
        justify-content: space-around;
        .tool {
          width: 14px;
          height: 14px;
          cursor: pointer;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .tool1 {
          width: 16px;
          height: 16px;
          cursor: pointer;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
      .box1-main {
        width: 1068px;
        height: 730px;
        // background: orange;
      }
      .box1-footer {
        margin: 13px auto;
        display: flex;
        width: 1036px;
        height: 40px;
        box-sizing: border-box;
        border: 1px solid rgba(231, 243, 255, 1);
        border-radius: 4px;
        background: rgba(246, 251, 255, 1);
        padding: 6px 12px;
        align-items: center;
        .box1-footer-left {
          width: 19px;
          height: 20px;
          img {
            width: 100%;
            height: 100%;
          }
        }
        .box1-footer-center {
          margin-left: 13px;
          height: 24px;
          width: 943px;
          color: var(--color-main-active);
          font-family: Microsoft YaHei;
          font-size: 16px;
          font-weight: 400;
          line-height: 24px;
        }
        .box1-footer-right {
          margin-left: 13px;
          width: 24px;
          height: 24px;
          border-radius: 12px;
          background: rgba(231, 243, 255, 1);
          img {
            width: 12px;
            height: 12px;
            margin-top: 6px;
            margin-left: 6px;
          }
        }
      }
    }
  }
  .right {
    width: 520px;
    height: 848px;
    border-radius: 4px;
    box-shadow: 0px 0px 15px 0px rgba(60, 87, 126, 0.2);
    background: rgba(255, 255, 255, 1);
    .box2 {
      .box2-main {
        margin-top: 10px;
        margin-left: 17px;
        .box3 {
          width: 484px;
          height: 320px;
          border: 1px solid rgba(234, 236, 238, 1);
          border-radius: 4px;
          .box3-item {
            width: 445px;
            margin-top: 10px;
            display: flex;
            margin-left: 19px;
            align-items: center;
            position: relative;
            .box3-item-left {
              width: 36px;
              height: 48px;
              box-sizing: border-box;
              border: 1px solid rgba(234, 236, 238, 1);
              border-radius: 2px;
              img {
                width: 100%;
                height: 100%;
              }
            }
            .box3-item-center {
              margin-left: 10px;
              width: 300px;
              .title {
                color: rgba(59, 65, 75, 1);
                font-family: Microsoft YaHei;
                font-size: 16px;
                font-weight: 700;
                line-height: 30px;
              }
              .time {
                height: 24px;
                color: rgba(132, 136, 142, 1);
                font-family: Microsoft YaHei;
                font-size: 16px;
                font-weight: 400;
                line-height: 24px;
              }
            }
            .box3-item-right {
              position: absolute;
              top: 0;
              right: 0;
              height: 22px;
              box-sizing: border-box;
              border-radius: 4px;
              line-height: 22px;
              padding: 0 8px;
              font-family: Microsoft YaHei;
              font-size: 14px;
              font-weight: 400;
            }
            .tag1 {
              background: rgba(230, 255, 251, 1);
              border: 1px solid rgba(135, 232, 222, 1);
              color: rgba(19, 168, 168, 1);
            }
            .tag2 {
              background: var(--tag-btn1-bg-color);
              border: 1px solid var(--tag-btn1-border-color);
              color: var(--tag-btn1-text-color);
            }
          }
        }
        .box4 {
          margin-top: 16px;
          width: 484px;
          height: 190px;
          border: 1px solid rgba(234, 236, 238, 1);
          border-radius: 4px;
          .box4-main {
            height: 140px;
            .box4-item {
              margin-left: 20px;
              margin-top: 11px;
              display: flex;
              width: 444px;
              height: 53px;
              justify-content: space-between;
              .box4-item-left {
                width: 309px;
                .title {
                  height: 24px;
                  color: rgba(59, 65, 75, 1);
                  font-family: Microsoft YaHei;
                  font-size: 18px;
                  font-weight: 700;
                  line-height: 24px;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  white-space: nowrap;
                }
                .time {
                  height: 24px;
                  color: rgba(132, 136, 142, 1);
                  font-family: Microsoft YaHei;
                  font-size: 16px;
                  font-weight: 400;
                  line-height: 24px;
                }
              }
              .box4-item-right {
                height: 24px;
                padding: 0 20px;
                box-sizing: border-box;
                border: 1px solid rgba(186, 224, 255, 1);
                border-radius: 4px;
                background: rgba(230, 244, 255, 1);
                color: rgba(22, 119, 255, 1);
                font-family: Microsoft YaHei;
                font-size: 14px;
                font-weight: 400;
                line-height: 24px;
              }
            }
          }
        }
        .box5 {
          margin-top: 16px;
          width: 484px;
          height: 190px;
          border: 1px solid rgba(234, 236, 238, 1);
          border-radius: 4px;
          .box5-main {
            height: 142px;
            overflow-y: auto;
            .box5-item {
              display: flex;
              width: 480px;
              height: 53px;
              margin-top: 12px;

              .box5-item-left {
                width: 36px;
                height: 48px;
                margin-left: 21px;
                margin-top: 3px;
                img {
                  width: 100%;
                  height: 100%;
                }
              }
              .box5-item-center {
                margin-left: 10px;
                width: 304px;
                .title {
                  margin-top: 2px;
                  height: 24px;
                  color: rgba(59, 65, 75, 1);
                  font-family: Microsoft YaHei;
                  font-size: 18px;
                  font-weight: 700;
                  line-height: 24px;
                  width: 304px;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  white-space: nowrap;
                }
                .time {
                  margin-top: 2px;
                  color: rgba(132, 136, 142, 1);
                  font-family: Microsoft YaHei;
                  font-size: 16px;
                  font-weight: 400;
                  line-height: 24px;
                }
              }
              .box5-item-right {
                margin-left: 82px;
                margin-top: 5px;
                width: 16px;
                height: 16px;
                img {
                  width: 100%;
                  height: 100%;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>