<template>
  <div>
    <div v-if="!showTool" class="flex-container">
      <!-- 左侧内容 - 自动宽度 -->
      <div class="left-content">
        <div class="dashboard-4grid">
          <div class="grid-item4" @click="handleGoMediaMap">
            <img :src="mediaMap" class="custom-icon" />
            <div class="grid-title grid-item4-margin">媒体地图</div>
            <div class="grid-line"></div>
          </div>
          <div class="grid-item4" @click="handleGoSupplierManage">
            <img :src="supplierManage" class="custom-icon" />
            <div class="grid-title grid-item4-margin">供应商管理</div>
            <div class="grid-line"></div>
          </div>
          <div class="grid-item4" @click="handleGoMediaLibary">
            <img :src="mediaLibary" class="custom-icon" />
            <div class="grid-title grid-item4-margin">媒体库管理</div>
            <div class="grid-line"></div>
          </div>
          <div class="grid-item4" @click="handleGoOutdoorMediaMap">
            <img :src="outdoorMediaMap" class="custom-icon" />
            <div class="grid-title grid-item4-margin">户外媒介数据</div>
            <div class="grid-line"></div>
          </div>
        </div>
        <div class="dashboard-3grid">
          <div class="grid-item3 calibrationPlatform" @click="handleGoCalibrationPlatform">
            <div class="grid-title">校准平台</div>
            <div class="grid-sub-title"><span>去使用</span>></div>
          </div>
          <div class="grid-item3 PPTAnalysisTool" @click="handleGoPPTAnalysisTool">
            <div class="grid-title">PPT分析工具</div>
            <div class="grid-sub-title"><span>去使用</span>></div>
          </div>
          <div class="grid-item3 longitudeConversion" @click="handleGoLongitudeConversion">
            <div class="grid-title">经纬度转换</div>
            <div class="grid-sub-title"><span>去使用</span>></div>
          </div>
        </div>
      </div>

      <!-- 右侧内容 - 固定宽度360px -->
      <div class="right-content">
        <div class="title-container">
          <div class="title-label">
            <img :src="notic_icon" class="custom-icon" />
            <span>系统通知</span>
            <span class="moreText" @click="handleGoNoticeList">更多...</span>
          </div>
        </div>
        <ul class="resource-list" v-if="notices.length > 0">
          <li v-for="(notice, index) in notices" :key="index" class="resource-link" @click="handleGoSupplierManage">
            {{ notice.noticeTitle }}
          </li>
        </ul>
        <div class="no_result" v-else>
          <img :src="no_notice" />
          <div class="no_notice_title">暂无通知</div>
        </div>
      </div>
    </div>
    <geoConvertIndex ref="geoConvertIndexRef" v-if="showGeoConvert" @handleGoBack="handleGeoConvertBack" />
    <pptAnalysisIndex ref="PPTAnalysisIndexRef" v-if="showPPTAnalysis" @handleGoBack="handlePPTAnalysisBack" />
    <calibrationIndex ref="calibrationIndexRef" v-if="showCalibration" @handleGoBack="handleCalibrationBack" />
  </div>
</template>

<script setup name="Index">
import { nextTick, onMounted, ref } from 'vue';
// import { More } from '@element-plus/icons-vue'
import { noticeList } from "@/api/notice"
import mediaMap from '@/assets/images/mediaMap.png'
import supplierManage from '@/assets/images/supplierManage.png'
import mediaLibary from '@/assets/images/mediaLibary.png'
import outdoorMediaMap from '@/assets/images/outdoorMediaMap.png'
import notic_icon from '@/assets/images/notic-icon.png'
import no_notice from '@/assets/images/no_notice.png'
import { useRouter } from 'vue-router'
import { useBackgroundStore } from '@/store/modules/background'
import bigBackgroud from '@/assets/images/bigBackgroud.png'
const bgStore = useBackgroundStore()

import calibrationIndex from './mediaTool/calibrationIndex.vue';
import pptAnalysisIndex from './mediaTool/pptAnalysisIndex.vue';
import geoConvertIndex from './mediaTool/geoConvertIndex.vue';

const showTool = ref(false)
// 校准平台组件
const showCalibration = ref(false)
const calibrationIndexRef = ref(null)
// ppt分析组件
const showPPTAnalysis = ref(false)
const PPTAnalysisIndexRef = ref(null)
// 经纬度转换组件
const showGeoConvert = ref(false)
const geoConvertIndexRef = ref(null)

const router = useRouter()
// 初始化
onMounted(() => {
  bgStore.setBgImage(bigBackgroud)
  getNoticeList()
});
// 通知数据
const notices = ref([]);
// 打开媒体地图
const handleGoMediaMap = () => {
  router.push('/mediaMap')
}

// 打开供应商管理
const handleGoSupplierManage = () => {
  router.push('/supplier')
}

// 打开媒体库管理
const handleGoMediaLibary = () => {
  router.push('/mediaLibrary')
}

// 打开户外媒介数据
const handleGoOutdoorMediaMap = () => {
  router.push('/outdoorMedia')
}

// 打开校准平台
const handleGoCalibrationPlatform = () => {
  showTool.value = true
  showCalibration.value = true
  nextTick(() => {
    calibrationIndexRef.value.initTool()
  })
}

// 关闭校准平台回调
const handleCalibrationBack = () => {
  showTool.value = false
  showCalibration.value = false
}

// 打开PPT分析工具
const handleGoPPTAnalysisTool = () => {
  showTool.value = true
  showPPTAnalysis.value = true
  nextTick(() => {
    PPTAnalysisIndexRef.value.initTool()
  })
}
// 关闭PPT分析回调
const handlePPTAnalysisBack = () => {
  showTool.value = false
  showPPTAnalysis.value = false
}

// 打开经纬度转换工具
const handleGoLongitudeConversion = () => {
  showTool.value = true
  showGeoConvert.value = true
  nextTick(() => {
    geoConvertIndexRef.value.initTool()
  })
}
// 关闭经纬度抓换工具回调
const handleGeoConvertBack = () => {
  showTool.value = false
  showGeoConvert.value = false
}

// 获取通知
const getNoticeList = () => {
  noticeList({ noticeType: 1, status: 0 }).then(res => {
    notices.value = res.rows
  })
}
// 打开通知列表
const handleGoNoticeList = () => {
  router.push('/noticeList')
}
</script>
<style scoped lang="scss">
.flex-container {
  display: flex;
  gap: 30px;
  /* 间距30px */
  width: 1440px;
  height: 520px;
  align-items: center; // 垂直居中 
  box-sizing: border-box;
  /* 包含padding在尺寸计算内 */
  margin: 174px auto;
}

.left-content {
  flex: 1;
  /* 自动分配剩余空间 */
  min-width: 0;
  /* 防止内容溢出 */
}

.right-content {
  width: 360px;
  height: 520px;
  padding: 30px;
  /* 固定宽度360px */
  flex-shrink: 0;
  /* 防止被压缩 */
  background-image: url("../assets/images/system-notic-bg.png");
  background-repeat: no-repeat;
  /* 禁止平铺 */
  background-size: cover;
}

.dashboard-4grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 30px;
}

.dashboard-3grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30px;
  margin-top: 30px;
}

.grid-item4 {
  width: 240px;
  height: 280px;
  border-radius: 6px 6px 6px 6px;
  background: #ffffffdb;
  text-align: center;
  padding: 38px 40px;
  cursor: pointer;
}

.grid-item4-margin {
  margin: 14px auto 16px auto;
}

.grid-item3 {
  width: 330px;
  height: 210px;
  border-radius: 6px 6px 6px 6px;
  background: #ffffffdb;
  padding: 40px 9px 7px 40px;
  cursor: pointer;
}

.grid-title {
  font-family: Microsoft YaHei;
  font-weight: 600;
  font-size: 22px;
  color: #000000;
  letter-spacing: 1px;
}

.grid-sub-title {
  font-family: Microsoft YaHei;
  font-weight: 400;
  font-size: 16px;
  text-align: left;
  color: #6C7B91;
  margin-top: 16px;

  span {
    padding-right: 10px;
  }
}

.grid-line {
  width: 34px;
  height: 3px;
  border-radius: 1.5px 1.5px 1.5px 1.5px;
  background: #467cf6;
  margin: 0 auto;
}

.full-width {
  grid-column: 1 / -1;
}

.notice-item {
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.notice-item:last-child {
  border-bottom: none;
}

.notice-date {
  font-weight: bold;
  margin-bottom: 5px;
}

.calibrationPlatform {
  background-image: url("../assets/images/calibrationPlatform.png");
  background-repeat: no-repeat;
  background-position: right bottom;
}

.PPTAnalysisTool {
  background-image: url("../assets/images/PPTAnalysisTool.png");
  background-repeat: no-repeat;
  background-position: right bottom;
}

.longitudeConversion {
  background-image: url("../assets/images/longitudeConversion.png");
  background-repeat: no-repeat;
  background-position: right bottom;
}

.title-label {
  font-family: Microsoft YaHei;
  font-weight: 700;
  font-size: 18px;
  color: #FFFFFF;

  span {
    padding-left: 10px;
  }
}

.title-container {
  margin-bottom: 20px;
}

.no_result {
  height: 416px;
  text-align: center;
  margin-bottom: 22px;
  padding: 110px 0;
}

.no_notice_title {
  font-family: Microsoft YaHei;
  font-weight: 400;
  font-size: 16px;
  color: #FFFFFF60;
}

.resource-list {
  font-family: Microsoft YaHei;
  font-weight: 400;
  font-size: 16px;
  color: #FFFFFF;
  padding: 0 0 0 18px !important;
  margin: 6px 0px;
  max-height: 416px;
  overflow-y: auto;
}

.resource-link {
  line-height: 28px;
  cursor: pointer;
}

.moreText {
  font-family: Microsoft YaHei;
  font-weight: 400;
  font-size: 16px;
  color: #FFFFFF;
  padding-left: 158px !important;
  cursor: pointer;
}
</style>
