<template>
  <div class="page">
    <div class="title">
      <el-image class="image" :src="left" fit="fill" />
      <div class="title_center">新闻资讯</div>
      <el-image class="image" :src="right" fit="fill" />
    </div>
    <div class="one" data-aos="fade-up" data-aos-duration="1000">
      <div class="one_left">
        <el-carousel height="680px">
          <el-carousel-item v-for="(item, index) in carouselList" :key="index">
            <el-image class="image" :src="getUrl(item)" fit="fill" @click="toRedirect(item)" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="one_right">
        <div class="right_1">
          <div class="right_left">
            <span class="tab" :class="[item.value == active ? 'active' : '']" v-for="(item, index) in newList" :key="index" @click="toActive(item)">{{ item.label }}</span>
          </div>
          <div class="right_right" @click="toMore(0)">查看更多</div>
        </div>
        <div class="right_2">
          <vue3-seamless-scroll :list="list" :hover="true" :step="0.5" :wheel="true" :isWatch="true">
            <div class="list" v-for="(item, index) in list" :key="index" @click="toView(item, '0')">
              <div class="left">
                <el-image class="image" v-if="item.logo && item.logo.length > 0" :src="getFile(item.logo)" fit="fill">
                  <template v-slot:error>
                    <el-image class="image" :src="new_4" fit="fill" />
                  </template>
                </el-image>
                <el-image class="image" v-else :src="new_4" fit="fill" />
              </div>
              <div class="right">
                <div class="new_title textOne">
                  {{ item.title || '暂无标题' }}
                </div>
                <div class="new_content textMore">{{ removeHtmlStyle(item.content) || '暂无内容' }}</div>
                <div class="new_time">{{ moment(item.time).format('YYYY-MM-DD') || '暂无时间' }}</div>
              </div>
            </div>
          </vue3-seamless-scroll>
        </div>
      </div>
    </div>
    <div class="two" data-aos="fade-up" data-aos-duration="1000">
      <div class="title">
        <el-image class="image" :src="left" fit="fill" />
        <div class="title_center">数据展示</div>
        <el-image class="image" :src="right" fit="fill" />
      </div>
      <div class="two_1">
        <div class="twoList" v-for="(item, index) in recordList" :key="index" @click="toSelect(item)">
          <div class="two_num">
            <span>{{ item.num || 0 }}+</span>
            <span>{{ item.unit || '' }}</span>
          </div>
          <div class="two_title">{{ item.name || '暂无名称' }}</div>
        </div>
      </div>
      <div class="two_2">
        <div class="two_title">{{ recordInfo.name }}数据分析</div>
        <div class="two_content">
          <cecharts1 v-if="recordInfo.id == '1'"></cecharts1>
          <secharts1 v-if="recordInfo.id == '2'"></secharts1>
          <decharts1 v-if="recordInfo.id == '3'"></decharts1>
          <pecharts1 v-if="recordInfo.id == '4'"></pecharts1>
          <aecharts1 v-if="recordInfo.id == '5'"></aecharts1>
        </div>
      </div>
    </div>
    <div class="thr" data-aos="fade-up" data-aos-duration="1000">
      <div class="title">
        <el-image class="image" :src="left" fit="fill" />
        <div class="title_center">成果展示</div>
        <el-image class="image" :src="right" fit="fill" />
      </div>
      <div class="more">
        <div class="more_title" @click="toMore(2)">查看更多</div>
      </div>
      <div class="thr_1">
        <div class="w_1700">
          <div class="list" v-for="(item, index) in achieveList" :key="index" @click="toView(item, '2')">
            <div class="other_1">
              <div class="round"></div>
              <div class="name">{{ item.name || '暂无成果名称' }}</div>
            </div>
            <div class="other_2" v-if="user && user.id"><span>技术领域：</span>{{ item.field || '暂无' }}</div>
            <div class="other_2" v-if="user && user.id"><span>负责人：</span>{{ item.person || '暂无' }}</div>
            <div class="other_2" v-if="user && user.id"><span>来源：</span>{{ item.source || '暂无' }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="four" data-aos="fade-up" data-aos-duration="1000">
      <div class="title">
        <el-image class="image" :src="left" fit="fill" />
        <div class="title_center">孵化体系</div>
        <el-image class="image" :src="right" fit="fill" />
      </div>
      <div class="more">
        <div class="more_title" @click="toMore(1)">查看更多</div>
      </div>
      <div class="four_1">
        <div class="list" v-for="(item, index) in incubatorList" :key="index" @mouseover="handleMouseOver(index)" @mouseout="handleMousOut(index)">
          <div class="list_1" :class="[item.hover ? 'menuTrue' : '']">
            <el-image class="image" :src="getFile(item.logo)" fit="fill">
              <template v-slot:error>
                <el-image class="image" :src="baseLogo" fit="fill" />
              </template>
            </el-image>
            <div class="square" :class="`square` + [index]"></div>
            <div class="content" :class="`content` + [index]">
              <div class="name">{{ item.name || '暂无孵化基地名称' }}</div>
              <div class="other_1"><span>负责人姓名：</span>{{ item.person || '暂无' }}</div>
              <div class="other_1"><span>负责人联系电话：</span>{{ item.person_phone || '暂无' }}</div>
              <div class="other_1"><span>地址：</span>{{ getArea(item.area) || '暂无' }}</div>
              <div class="button">
                <button @click="toView(item, '1')">查看详情</button>
              </div>
            </div>
          </div>
          <div class="list_2" :class="[item.hover ? '' : 'menuTrue']">
            <div class="content" :class="`content` + [index]">
              <div class="name">{{ item.name || '暂无孵化基地名称' }}</div>
              <div class="other_1">
                {{ removeHtmlStyle(item.brief) || '暂无简介' }}
              </div>
              <div class="button">
                <button @click="toView(item, '1')">查看详情</button>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="join">
        <div class="join_bg"></div>
        <div class="join_scroll">
          <div class="join_shadow">
            <div class="join_shadow_left"></div>
            <div class="join_shadow_right"></div>
          </div>
          <div class="join_top">
            <div class="join_item" v-for="(item, index) in friendList" :key="index" @click="toFriend(item)">
              <el-image class="image" :src="getFile(item.url)" fit="fill">
                <template v-slot:error>
                  <el-image class="image" :src="friend" fit="fill" />
                </template>
              </el-image>
              <div class="name">{{ item.name }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import moment from 'moment'
import { get } from 'lodash-es'
import { useNumberAnimation } from '@/utils/animation'
// 图片引入
import left from '/images/top-left.png'
import right from '/images/top-right.png'
import new_4 from '/images/new_4.png'
import friend from '/images/friend.jpeg'
import baseLogo from '/images/base.jpg'
// 组件
import cecharts1 from './parts/echarts1.vue'
import secharts1 from './parts/echarts2.vue'
import decharts1 from './parts/echarts3.vue'
import pecharts1 from './parts/echarts4.vue'
import aecharts1 from './parts/echarts5.vue'
// 用户信息
import { UserStore } from '@/store/user'
const userStore = UserStore()
const user = computed(() => userStore.user)

// 路由
const router = useRouter()

const props = defineProps({
  carouselList: { type: Array, default: () => [] },
  friendList: { type: Array, default: () => [] },
  incubatorList: { type: Array, default: () => [] },
  achieveList: { type: Array, default: () => [] },
  recordList: { type: Array, default: () => [] },
  list: { type: Array, default: () => [] }
})

const { carouselList, incubatorList, recordList } = toRefs(props)

const emits = defineEmits(['toActive'])

const active = ref('0')
const recordInfo = ref({})
const newList = ref([
  { value: '0', label: '政策信息' },
  { value: '1', label: '新闻通知' },
  { value: '2', label: '行业动态' }
])

const toActive = async (item) => {
  active.value = item.value
  emits('toActive', item.value)
}
const toRedirect = (data) => {
  const to = get(data, 'to')
  if (to) window.open(to)
}
const getUrl = (item) => {
  if (item) return `${import.meta.env.VITE_APP_HOST}${item.uri}`
}
const getFile = (item) => {
  if (item && item.length > 0) return `${import.meta.env.VITE_APP_HOST}${item[0].uri}`
}
// 查看详情
const toView = (item, type) => {
  if (type == '0') router.push({ path: '/news/detail', query: { id: item.id || item._id } })
  else {
    if (user.value.id) {
      if (type == '1') router.push({ path: '/base/detail', query: { id: item.id || item._id } })
      else router.push({ path: '/achievement/detail', query: { id: item.id || item._id } })
    } else ElMessage({ message: '未登录！', type: 'error' })
  }
}
// 查看更多
const toMore = (type) => {
  if (type == '0') router.push({ path: '/news' })
  if (type == '1') router.push({ path: '/base' })
  if (type == '2') router.push({ path: '/nine' })
}
// 地区
const getArea = (data) => {
  if (data) return data.join('-')
  else return '暂无地区'
}
// 富文本处理
const removeHtmlStyle = (html) => {
  let relStyle = /style\s*?=\s*?([‘"])[\s\S]*?\1/g //去除样式
  let relTag = /<.+?>/g //去除标签
  let relClass = /class\s*?=\s*?([‘"])[\s\S]*?\1/g // 清除类名
  let newHtml = ''
  if (html) {
    newHtml = html.replace(relStyle, '')
    newHtml = newHtml.replace(relTag, '')
    newHtml = newHtml.replace(relClass, '')
  }
  return newHtml
}
const handleMouseOver = (index) => {
  incubatorList.value[index].hover = true
}
const handleMousOut = (index) => {
  incubatorList.value[index].hover = false
}
// 选择数据分析
const toSelect = (item) => {
  recordInfo.value = item
}
// 查看合作伙伴下级
const toFriend = (item) => {
  console.log(item)
  router.push({ path: '/friend/detail', query: { code: item.code } })
}
// 请求
onMounted(() => {
  setTimeout(async () => {
    await Animation()
  }, 2000)
})
// 选择数据分析
const Animation = () => {
  if (recordList.value && recordList.value.length > 0) {
    for (const val of recordList.value) {
      useNumberAnimation({
        from: 0,
        to: val.num,
        duration: 3000,
        onProgress: (v) => {
          if (v) val.num = v.toFixed(0)
        }
      })
    }
  }
}
watch(
  recordList,
  (item) => {
    recordInfo.value = item[0]
  },
  {
    deep: true
  }
)
</script>
<style scoped lang="scss">
.page {
  .title {
    display: flex;
    align-items: end;
    justify-content: center;
    margin: 30px;
    .image {
      margin: 0 10px;
      vertical-align: middle;
      border-style: none;
    }
    .title_center {
      font-size: $global-font-size-28;
      font-weight: 600;
    }
  }
  .one {
    max-width: 1700px;
    margin: 0 auto;
    height: 680px;
    display: flex;
    .one_left {
      width: 65%;
      .image {
        height: 100%;
        width: 100%;
      }
    }
    .one_right {
      width: 35%;
      padding: 0 0 0 10px;
      .right_1 {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .right_left {
          font-size: $global-font-size-20;
          .tab {
            margin: 0 15px 0 0;
            cursor: pointer;
          }
          .active {
            color: #006cff;
            position: relative;
          }
          .active::after {
            position: absolute;
            bottom: -15px;
            left: 50%;
            margin-left: -10px;
            width: 14px;
            height: 8px;
            background: url(/images/icon-downarw.png) no-repeat;
            content: '';
          }
        }
        .right_right {
          font-size: 16px;
          padding: 5px;
          color: #fff;
          background-color: #006cff;
          border-radius: 40px;
          cursor: default;
        }
        .right_right:hover {
          background-color: #475b86;
        }
      }
      .right_2 {
        height: 630px;
        overflow: hidden;
        margin: 20px 0 0 0;
        .list {
          display: flex;
          border-bottom: 1px dashed #e5e5e5;
          .left {
            width: 150px;
            margin: 0 10px 0 0;
            .image {
              width: 150px;
              height: 100px;
            }
          }
          .right {
            width: 750px;
            padding: 10px 0;
            .new_title {
              font-size: $global-font-size-18;
              font-weight: 600;
              color: #2e343c;
              cursor: default;
            }
            .new_title:hover {
              color: #006cff;
            }
            .new_content {
              margin: 10px 0;
            }
            .new_time {
              color: #999;
              font-size: $global-font-size-14;
            }
          }
        }
      }
    }
  }
  .two {
    max-width: 1700px;
    margin: 0 auto 10px;
    .two_1 {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 111px;
      background-image: linear-gradient(0deg, #eeeffb 0, #fff 100%), linear-gradient(#fff, #fff);
      background-blend-mode: normal, normal;
      box-shadow: 0 0 16px 0 rgba(72, 117, 229, 0.5);
      border-radius: 6px;
      .twoList {
        text-align: center;
        width: 340px;
        border-right: 1px solid #d6d9e2;
        cursor: default;
        .two_num {
          color: #1054ee;

          span:first-child {
            font-size: 28px;
            font-family: '微软雅黑';
            line-height: 28px;
            height: 28px;
            overflow: hidden;
            display: inline-block;
            position: relative;
            font-weight: bold;
          }
          span:last-child {
            font-size: 20px;
          }
        }
        .two_title {
          margin: 10px 0 0 0;
          font-size: 18px;
          color: #676767;
        }
      }
    }
    .two_2 {
      margin: 10px 0 0 0;
      .two_title {
        height: 90px;
        line-height: 90px;
        text-align: center;
        font-size: 30px;
        color: #323232;
      }
      .two_content {
        margin: 20px 0 0 0;
      }
    }
  }
  .thr {
    background: #f1f6f9;
    background-image: url(/images/con1-bg.png);
    background-size: 100% 100%;
    padding: 10px 0 0 0;
    .more {
      max-width: 1700px;
      margin: 0 auto 10px;
      display: flex;
      justify-content: flex-end;
      .more_title {
        font-size: 16px;
        padding: 5px;
        color: #fff;
        background-color: #006cff;
        border-radius: 40px;
        cursor: default;
      }
      .more_title:hover {
        background-color: #475b86;
      }
    }
    .thr_1 {
      padding: 10px 0 10px;
      .w_1700 {
        max-width: 1700px;
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        .list {
          margin-bottom: 15px;
          padding-top: 18px;
          width: 413px;
          padding: 20px;
          background-color: #ffffff;
          border-radius: 10px;
          .other_1 {
            display: flex;
            align-items: center;
            margin: 0 0 20px 0;
            .round {
              flex: 0 0 auto;
              margin-right: 6px;
              width: 12px;
              height: 12px;
              border-radius: 50%;
              border: 2.4px solid #2374ff;
            }
            .name {
              font-family: PingFangSC-Medium;
              font-size: 20px;
              font-weight: 500;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 1;
              -webkit-box-orient: vertical;
            }
          }
          .other_2 {
            margin: 0 0 10px 22px;
            font-family: PingFangSC-Medium;
            font-size: 18px;
            font-weight: 500;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
            span {
              color: #7e8288;
            }
          }
        }
        .list:hover {
          box-shadow: 0px 10px 30px #d5eaf3;
        }
      }
    }
  }
  .four {
    .more {
      max-width: 1700px;
      margin: 0 auto 10px;
      display: flex;
      justify-content: flex-end;
      .more_title {
        font-size: 16px;
        padding: 5px;
        color: #fff;
        background-color: #006cff;
        border-radius: 40px;
        cursor: default;
      }
      .more_title:hover {
        background-color: #475b86;
      }
    }
    .four_1 {
      max-width: 1700px;
      margin: 0 auto 10px;
      display: flex;
      justify-content: space-between;
      .list {
        cursor: pointer;
        width: 420px;
        height: 500px;
        position: relative;
        transition: all 0.5s ease-in-out;
        transform-style: preserve-3d;
        .list_1 {
          width: 420px;
          height: 500px;
          .image {
            width: 420px;
            height: 250px;
          }
          .square {
            position: relative;
            width: 0;
            height: 0;
            border-right: 238px solid transparent;
            margin-top: -43px;
            z-index: 1;
          }
          .square0 {
            border-bottom: 40px solid #00a9bb;
          }
          .square1 {
            border-bottom: 40px solid rgb(28, 102, 231);
          }
          .square2 {
            border-bottom: 40px solid rgb(104, 45, 255);
          }
          .square3 {
            border-bottom: 40px solid rgb(28, 102, 231);
          }
          .content {
            padding: 12px 20px;
            height: 250px;
            .name {
              height: 28px;
              line-height: 28px;
              font-family: PingFangSC-Medium;
              font-size: 22px;
              color: #fff;
              font-weight: 500;
              margin-bottom: 12px;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 1;
              -webkit-box-orient: vertical;
            }
            .other_1 {
              color: #fff;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 3;
              -webkit-box-orient: vertical;
              font-size: 16px;
              line-height: 21px;
              font-weight: 400;
              margin-bottom: 10px;
            }
            .button {
              text-align: center;
              button {
                width: 165px;
                height: 40px;
                border: 1px solid #fff;
                line-height: 36px;
                text-align: center;
                color: #fff;
                font-size: 16px;
                background: inherit;
                margin: 65px auto 0px;
                display: block;
              }
            }
          }
          .content0 {
            background-image: linear-gradient(180deg, rgba(0, 181, 182, 0), #00a9bb 0, #0098d2);
          }
          .content1 {
            background-image: linear-gradient(rgba(28, 102, 231, 0) 0%, rgb(28, 102, 231) 0%, rgb(76, 81, 236) 100%);
          }
          .content2 {
            background-image: linear-gradient(179deg, rgba(127, 76, 255, 0) 0%, rgb(104, 45, 255) 0%, rgb(117, 45, 255) 100%);
          }
          .content3 {
            background-image: linear-gradient(rgba(28, 102, 231, 0) 0%, rgb(28, 102, 231) 0%, rgb(76, 81, 236) 100%);
          }
        }
        .list_2 {
          width: 420px;
          height: 500px;
          .content {
            padding: 12px 20px;
            height: 500px;
            .name {
              height: 28px;
              line-height: 28px;
              font-family: PingFangSC-Medium;
              font-size: 24px;
              color: #fff;
              font-weight: 500;
              margin-bottom: 12px;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 1;
              -webkit-box-orient: vertical;
            }
            .other_1 {
              height: 360px;
              color: #fff;
              overflow: hidden;
              text-overflow: ellipsis;
              display: -webkit-box;
              -webkit-line-clamp: 9;
              -webkit-box-orient: vertical;
              font-size: 14px;
              line-height: 21px;
              font-weight: 400;
              margin-bottom: 38px;
            }
            .button {
              text-align: center;
              button {
                width: 165px;
                height: 40px;
                border: 1px solid #fff;
                line-height: 36px;
                text-align: center;
                color: #fff;
                font-size: 16px;
                background: inherit;
                margin: 30px auto 0px;
                display: block;
              }
            }
          }
          .content0 {
            background-image: linear-gradient(180deg, rgba(0, 181, 182, 0), #00a9bb 0, #0098d2);
          }
          .content1 {
            background-image: linear-gradient(rgba(28, 102, 231, 0) 0%, rgb(28, 102, 231) 0%, rgb(76, 81, 236) 100%);
          }
          .content2 {
            background-image: linear-gradient(179deg, rgba(127, 76, 255, 0) 0%, rgb(104, 45, 255) 0%, rgb(117, 45, 255) 100%);
          }
          .content3 {
            background-image: linear-gradient(rgba(28, 102, 231, 0) 0%, rgb(28, 102, 231) 0%, rgb(76, 81, 236) 100%);
          }
        }
        .menuTrue {
          display: none;
          transition: all 0.5s ease-in-out;
          transform-style: preserve-3d;
        }
      }
    }
    .join {
      margin: auto;
      width: 100%;
      position: relative;
      overflow: hidden;
      display: flex;
      padding-top: 48px;
      justify-content: center;
      .join_bg {
        margin: 0 auto;
        max-width: 1700px;
        position: absolute;
        z-index: -100;
        top: 0;
        height: 300px;
        background: linear-gradient(270deg, #7aa4ff 39.53%, #b7fff5 81.34%);
        mix-blend-mode: normal;
        opacity: 0.1;
        filter: blur(67.957px);
      }
      .join_scroll {
        margin: 0 auto;
        max-width: 1920px;
        min-width: 1700px;
        position: relative;
        overflow: hidden;
        .join_shadow {
          margin: 0 auto;
          width: 100%;
          min-width: 1700px;
          position: absolute;
          z-index: 1;
          display: flex;
          justify-content: space-between;
          .join_shadow_left {
            background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0, #fff 43.52%);
            position: absolute;
            z-index: 1;
            width: 552px;
            height: 400px;
            top: 0;
            right: -150px;
            transform: matrix(0, 1, 1, 0, 0, 0);
          }
          .join_shadow_right {
            background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0, #fff 43.52%);
            position: absolute;
            z-index: 1;
            width: 552px;
            height: 400px;
            top: 0;
            transform: rotate(90deg);
            left: -150px;
          }
        }
        .join_top {
          display: flex;
          transform: translate3d(-50%, 0, 0);
          width: -webkit-max-content;
          width: max-content;
          animation: masked-animation 120s linear 1s infinite;
          margin-left: 280px;
          .join_item {
            margin-right: 16px;
            background: #fff;
            opacity: 0.9;
            border: 1px solid #fff;
            border-radius: 4px;
            padding: 20px;
            width: 430px;
            .image {
              margin-bottom: 10px;
              width: 200px;
              height: 140px;
              border-radius: 4px;
            }
            .name {
              font-weight: 600;
              font-size: 16px;
              line-height: 26px;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              cursor: default;
            }
          }
        }
        @keyframes masked-animation {
          0% {
            transform: translateZ(0);
          }
          100% {
            transform: translate3d(-50%, 0, 0);
          }
        }
      }
    }
  }
}
</style>
