<template>
  <div class="mainView2">
    <!-- <div class="news">
      <img src="../../assets/logo/headline.png" alt="" />
      <el-carousel direction="vertical" :autoplay="true" style="height: 100px">
        <el-carousel-item v-for="item in list1" :key="item">
          <h2 text="xl" justify="center">{{ item }}</h2>
        </el-carousel-item>
      </el-carousel>
    </div> -->
    <div class="top_center">
      <div class="left">
        <el-carousel
          trigger="click"
          :interval="2000"
          :autoplay="true"
          v-if="carouselLoaded"
          class="lun_bo_tu"
        >
          <!-- :outside="false"
        indicator-position="right" -->
          <el-carousel-item v-for="item in HOMElistDEl" :key="item">
            <img
              style="width: 100%; height: 100%"
              :src="item[0]"
              @click="
                openNewWindowArticleDetails(item.id, '/News/imgesDel', item.id)
              "
            />
            <!-- <img src="../../assets/logo/headline.png" alt="" /> -->
            <div class="carousel-text">
              <div class="carousel-text_with">{{ item.newsTitle }}</div>
            </div>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="tong_zhi_gong_gao">
        <div class="title">
          <p
            @mouseenter="mouseenterIactives(1)"
            :class="{ actives: isHovered == 1 ? true : false }"
            @click="openNewWindowinform('message')"
          >
            <img
              class="img_trxt"
              v-if="isHovered == 1"
              src="../../assets/logo/tongZh.png"
              alt=""
            />
            <img
              class="img_trxt"
              v-else
              src="../../assets/logo/tongZi.png"
              alt=""
            />
            通知公告
          </p>
          <p
            @mouseenter="mouseenterIactives(2)"
            :class="{ actives: isHovered == 2 ? true : false }"
          >
            <!--     @click="openNewWindowinform('messageJC')" -->
            <img
              class="img_trxt"
              v-if="isHovered == 2"
              src="../../assets/logo/scH.png"
              alt=""
            />
            <img
              class="img_trxt"
              v-else
              src="../../assets/logo/acC.png"
              alt=""
            />
            市场监测
          </p>
        </div>
        <ul class="lou_ceng">
          <li
            class="list_const"
            v-for="item in newsList"
            :key="item.id"
            @click="
              openNewWindowArticleDetails(item.code, '/News/article', item.id)
            "
          >
            <div class="svg_del">
              <img src="../../assets/logo/rigth.png" alt="" />
            </div>
            <div class="list_txt" v-html="item.title"></div>
            <div class="list_time">
              {{ getDateDEl(item.publishTime) }}
            </div>
          </li>
        </ul>
      </div>
    </div>

    <div class="bottom">
      <div class="b_1">
        <p class="b_1_back">
          <span class="span1">
            <img class="img_trxt_ass" src="../../assets/logo/GWY.png" alt="" />
            国务院信息</span
          >
          <span class="span2" @click="openNewWindowinform('gwy')"
            >更多>
            <!-- <img src="../../assets/logo/rigth.svg" alt="" /> -->
          </span>
        </p>
        <ul>
          <li
            v-for="item in GWYLIST"
            :key="item.id"
            @click="openNewWindow(item.redirectUrl)"
          >
            <div class="svg_del">
              <img src="../../assets/logo/rigth.png" alt="" />
            </div>
            <div class="text1">
              {{ item.title }}
            </div>
            <div class="text_time">{{ getDateDEl(item.publishDate) }}</div>
          </li>
        </ul>
      </div>
      <!--  -->
      <div class="b_1">
        <p class="b_1_back">
          <span class="span1">
            <img class="img_trxt_ass" src="../../assets/logo/QHY.png" alt="" />
            青海要闻</span
          >
          <span class="span2" @click="openNewWindowinform('qhyw')"
            >更多>
            <!-- <img src="../../assets/logo/rigth.svg" alt="" /> -->
          </span>
        </p>
        <ul>
          <li
            v-for="item in QIHlistDEl"
            :key="item.id"
            @click="openNewWindow(item.redirectUrl)"
          >
            <div class="svg_del">
              <img src="../../assets/logo/rigth.png" alt="" />
            </div>
            <div class="text1">
              {{ item.title }}
            </div>
            <div class="text_time">{{ getDateDEl(item.publishDate) }}</div>
          </li>
        </ul>
      </div>
      <!--  -->
      <div class="b_1">
        <p class="b_1_back">
          <span class="span1">
            <img class="img_trxt_ass" src="../../assets/logo/LSJ.png" alt="" />
            行业信息</span
          >
          <span class="span2" @click="openNewWindowinform('lsj')"
            >更多>
            <!-- <img src="../../assets/logo/rigth.svg" alt="" /> -->
          </span>
        </p>
        <ul>
          <li
            v-for="item in LSJUlistDEl"
            :key="item.id"
            @click="openNewWindowArticleDetails(1, '/News/Bureau', item.id)"
          >
            <div class="svg_del">
              <img src="../../assets/logo/rigth.png" alt="" />
            </div>
            <div class="text1">
              {{ item.title }}
            </div>
            <div class="text_time">{{ getDateDEl(item.publishDate) }}</div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, nextTick } from 'vue'
import { useRouter } from 'vue-router'
import {
  getlist,
  GWYlist,
  QIHlist,
  LSJUlist,
  HOMElist,
} from '@/api/Important.js'
import uils from '@/utils/utils'

const image = [
  'http://fgw.qinghai.gov.cn/xwzx/tpxw/202405/W020240521292028040228.jpg',
  'http://fgw.qinghai.gov.cn/xwzx/tpxw/202405/W020240522288952018363.png',
  'http://fgw.qinghai.gov.cn/xwzx/tpxw/202404/W020240430360807536242.jpg',
  'http://fgw.qinghai.gov.cn/xwzx/tpxw/202405/W020240521292028040228.jpg',
]
function openNewWindowArticleDetails(data, path, v) {
  if (!data) return
  let href = router.resolve({
    path: path,
    query: { code: data, id: v },
  }).href
  window.open(href, '_blank')
}
function openNewWindow(data) {
  window.open(data, '_blank')
}
function openNewWindowinform(path, data) {
  let href = router.resolve({
    path: '/News/' + path,
    query: { key: data },
  }).href
  window.open(href, '_blank')
}

const tpe1 = ref([])

const tpe2 = ref([
  {
    announcementContent: '没数据呀',
    updateTime: '123',
    title: 'title',
  },
])

onMounted(() => {
  del()
  GWYlistpage()
  QIHlistpage()
  QIHlistpage()
  LSJUlistpage()
  HOMElistpage()
})
const newsList = ref([])
const isHovered = ref(1)
const router = useRouter()
const mouseenterIactives = (v) => {
  isHovered.value = v
  newsList.value = []
  if (v == 1) {
    newsList.value = tpe1.value
  } else {
    newsList.value = tpe2.value
  }
}
//公告
const del = async () => {
  const { data } = await getlist({ size: 8, current: 1, status: 2 })
  tpe1.value = []
  newsList.value = []
  tpe1.value = data.records.map((v) => {
    return {
      code: 3,
      ...v,
    }
  })
  newsList.value = tpe1.value
}
const getDateDEl = (v) => {
  const formattedDate = uils.getDate('YYYY-MM-DD', v)
  return formattedDate
}

//国务院
const GWYLIST = ref([])
const GWYlistpage = async () => {
  const { data } = await GWYlist({ size: 10, current: 1, status: 2 })
  GWYLIST.value = data.records
  // title redirectUrl createTime
}
//青海要闻
// QIHlist
const QIHlistDEl = ref([])
const QIHlistpage = async () => {
  const { data } = await QIHlist({ size: 10, current: 1, status: 2 })
  QIHlistDEl.value = data.records
  // title redirectUrl createTime
}
// LSJUlist 粮食局
const LSJUlistDEl = ref([])
const LSJUlistpage = async () => {
  const { data } = await LSJUlist({ size: 10, current: 1, status: 2 })
  LSJUlistDEl.value = data.records
  // title redirectUrl createTime
}
// 首页轮播
const carouselLoaded = ref(false)
const HOMElistDEl = ref([])
const HOMElistpage = async () => {
  HOMElistDEl.value = []
  const { data } = await HOMElist({ size: 10, current: 1, status: 2 })
  HOMElistDEl.value = data.records.map((item) => {
    return {
      id: item.id,
      ...(item.newsImages || '').split(',').filter((v) => v),
      ...item,
    }
  })
  console.log(HOMElistDEl.value)
  nextTick(() => {
    carouselLoaded.value = true
  })
  // console.log('data', HOMElistDEl.value)
}
</script>

<style lang="less" scoped>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
  width: 100px;
}

.carousel-text {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(73, 72, 72, 0.5);
  color: #fff;
  padding: 10px;
  font-size: 16px;
}
.carousel-text_with {
  width: 450px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* 修改指示器样式 */
.lun_bo_tu .el-carousel__indicator ::v-deep(.is-active) button {
  background-color: #409eff;
}
.lun_bo_tu ::v-deep(.el-carousel__indicator) button {
  background-color: #fff;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.lun_bo_tu ::v-deep(.el-carousel__indicators--horizontal) {
  bottom: -2px;
  right: 10% !important;
  transform: translateX(96%);
}
//
.img_trxt {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  margin-bottom: 3px;
}
.img_trxt_ass {
  width: 25px;
  height: 25px;
  vertical-align: middle;
  margin-bottom: 3px;
}

.mainView2 {
  width: 1200px;
  margin: 0 auto;
  // background: #fff;
  .news {
    width: 100%;
    margin: auto;
    height: 100px;
    // background: #3274c3 !important;
    // background-color: rgb(247, 247, 246);
    margin-top: 10px;
    img {
      float: left;
      margin: 20px 0 10px 20px;
    }
    h2 {
      font-size: 30px;
      width: 80%;
      text-align: center;
      margin: auto;
      line-height: 100px;
      color: crimson;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .top_center {
    background: #fff;
    padding: 0 20px;
    // margin-top: 10px;
    padding-top: 20px !important;
    display: flex;
    justify-content: space-between;

    .left {
      width: 580px;
      height: 400px;
      img {
        width: 100%;
        height: 100%;
      }
    }

    .tong_zhi_gong_gao {
      width: 580px;
      height: 380px;
      margin-left: 10px;
      overflow: hidden;

      .title {
        display: flex;
        cursor: pointer;
        justify-content: space-evenly;
        line-height: 40px;
        .actives {
          background-color: #3274c3;
          color: #ffffff;
        }
        p {
          cursor: pointer;
          width: 260px;
          text-align: center;
          background-color: #f2f2f2;
          // border: 1px solid #d1d9ed;
        }
      }

      .title :hover {
        background-color: #3274c3;
      }

      .lou_ceng {
        margin-left: 20px;
        height: 380px;
        .list_const {
          margin: 10px 0;
          display: flex;
          height: 30px;
          cursor: pointer;

          .svg_del {
            margin-right: 10px;

            img {
              width: 5px;
              height: 5px;
              margin-bottom: 3px;
            }
          }

          .list_txt {
            width: 386px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-right: 50px;
          }
        }

        .list_const:hover {
          color: #4b9ae9;

          .list_time {
            color: #4b9ae9 !important;
          }
        }
      }
    }
  }

  .bottom {
    display: flex;
    // margin: 0 20px;
    margin-top: 20px;
    justify-content: space-between;
    // margin-bottom: 50px;

    .b_1 {
      width: 380px;
      height: 450px;
      // border: 1px solid #d1d9ed;
      background: #ffffff;
    }

    .b_1 {
      .b_1_back {
        display: flex;
        justify-content: space-between;
        height: 40px;
        background: #ffffff;
        line-height: 40px;
        border-bottom: 2px #3367b9 solid;

        .span1 {
          padding-left: 20px;
          padding-right: 20px;
          font-weight: 500;
          font-size: 18px;
          color: #ffffff;
          background: #3367b9;
          // border-bottom: 1px solid #3274c3;
          padding-bottom: 1px;
        }

        .span2 {
          // background: url('../../assets/logo/text.svg');
          // background-size: 58px 51px !important;
          // background-repeat: no-repeat;
          cursor: pointer;
          font-size: 16px;
          display: flex;
          align-items: center;
          color: #0e0e0e;
          margin-right: 15px;
          img {
            width: 15px;
            margin-left: 5px;
            margin-right: 5px;
          }
        }
      }
      ul {
        margin-top: 10px;
        margin: 0 10px;
        background: #ffff;
        li {
          cursor: pointer;

          .svg_del {
            // margin-right: 10px;
            img {
              width: 5px;
              height: 5px;
              margin-bottom: 3px;
            }
          }
          display: flex;
          margin-top: 10px;
          height: 30px;
          justify-content: space-between;
        }
        li:hover {
          color: #4b9ae9;
        }
        .text1 {
          width: 220px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .text_time {
          margin-right: 5px;
        }
      }
    }

    .b_2 {
      p {
        display: flex;
        justify-content: space-between;
        line-height: 30px;
        border-bottom: 1px solid;
      }

      ul {
        margin-top: 10px;
      }
    }

    .b_3 {
      p {
        display: flex;
        justify-content: space-between;
        line-height: 30px;
        border-bottom: 1px solid;
      }

      ul {
        margin-top: 10px;
      }
    }
  }
}

.lun_bo_tu ::v-deep(.el-carousel__container) {
  height: 380px !important;
}
</style>
