<template>
  <div class="page">
    <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">
            <div class="more_title" @click="toMore(0)">查看更多</div>
            <el-icon size="24"><ArrowRight /></el-icon>
          </div>
        </div>
        <div class="right_2">
          <vue3-seamless-scroll :list="list" :hover="true" :step="0.5" :limit-scroll-num="3" :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 v-if="item.type == '0'" class="image" :src="new_1" fit="fill" />
                    <el-image v-else-if="item.type == '1'" class="image" :src="new_2" fit="fill" />
                    <el-image v-else class="image" :src="new_2" fit="fill" />
                  </template>
                </el-image>
                <div v-else>
                  <el-image v-if="item.type == '0'" class="image" :src="new_1" fit="fill" />
                  <el-image v-else-if="item.type == '1'" class="image" :src="new_2" fit="fill" />
                  <el-image class="image" v-else :src="new_3" fit="fill" />
                </div>
              </div>
              <div class="right">
                <div class="new_title textOne">
                  {{ item.title || '暂无标题' }}
                </div>
                <div class="new_content textMore">{{ removeHtmlStyle(item.content) || '暂无内容' }}</div>
              </div>
            </div>
          </vue3-seamless-scroll>
        </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>
        <div class="title_brief">产学研用协同创新数字化平台</div>
        <!-- <el-image class="image" :src="right" fit="fill" /> -->
      </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="list_left">
              <el-image class="image" :src="icon" fit="fill" />
            </div>
            <div class="list_right">
              <div class="other_1">
                <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="more">
        <div class="more_title" @click="toMore(2)">查看更多</div>
        <el-icon size="24"><ArrowRight /></el-icon>
      </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>
        <div class="title_brief">产学研用协同创新数字化平台</div>
        <!-- <el-image class="image" :src="right" fit="fill" /> -->
      </div>
      <div class="four_1">
        <div class="list" v-for="(item, index) in incubatorList" :key="index">
          <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="content">
            <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>
      <div class="more">
        <div class="more_title" @click="toMore(1)">查看更多</div>
        <el-icon size="24"><ArrowRight /></el-icon>
      </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.file)" 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 { get } from 'lodash-es'
import { useNumberAnimation } from '@/utils/animation'

// 图片引入
import icon from '/images/icon.png'
import new_1 from '/images/new_1.png'
import new_2 from '/images/new_2.png'
import new_3 from '/images/new_3.png'
import friend from '/images/friend.jpeg'
import baseLogo from '/images/base.jpg'
// 用户信息
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') {
    if (item.jump_type == '1') window.open(item.route, '_blank')
    else 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 toFriend = (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 {
    text-align: center;
    margin: 30px 0 50px;
    .image {
      margin: 0 10px;
      vertical-align: middle;
      border-style: none;
    }
    .title_center {
      font-size: $global-font-size-40;
      font-weight: 600;
    }
    .title_brief {
      margin: 15px 0 0 0;
      font-size: $global-font-size-24;
      color: #999;
    }
  }
  .one {
    max-width: 1700px;
    margin: 30px auto 0;
    height: 680px;
    display: flex;
    justify-content: space-between;
    .one_left {
      width: 50%;
      .image {
        height: 100%;
        width: 100%;
      }
    }
    .one_right {
      width: 48%;
      padding: 0 0 0 10px;
      .right_1 {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin: 0 0 10px 0;

        .right_left {
          font-size: $global-font-size-28;
          .tab {
            margin: 0 30px 0 0;
            cursor: pointer;
          }
          .active {
            font-size: 40px;
          }
        }
        .right_right {
          display: flex;
          align-items: center;
          font-size: 24px;
          cursor: default;
        }
      }
      .right_2 {
        height: 630px;
        overflow: hidden;
        .list {
          display: flex;
          border-bottom: 1px solid #979797;
          padding: 30px 0;
          .left {
            width: 200px;
            margin: 0 10px 0 0;
            .image {
              width: 200px;
              height: 150px;
            }
          }
          .right {
            width: 700px;
            .new_title {
              font-size: $global-font-size-24;
              font-weight: 600;
              color: #5f5f5f;
              cursor: default;
              margin: 0 0 10px 0;
            }
            .new_title:hover {
              color: #006cff;
            }
            .new_content {
              margin: 14px 0 0 0;
              color: #9ea6b3;
              font-size: $global-font-size-20;
            }
          }
        }
      }
    }
  }
  .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: 21px;
          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 {
    margin: 20px 0;
    background: #f1f6f9;
    background-image: url(/images/con1-bg.png);
    background-size: 100% 100%;
    padding: 10px 0 0 0;

    .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;
          display: flex;
          .list_left {
            margin: 0 10px 0 0;
          }
          .list_right {
            width: 320px;
            .other_1 {
              display: flex;
              align-items: center;
              margin: 0 0 20px 0;
              .name {
                font-family: PingFangSC-Medium;
                font-size: 20px;
                font-weight: 600;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 1;
                -webkit-box-orient: vertical;
              }
            }
            .other_2 {
              margin: 0 0 10px 0;
              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;
        }
      }
    }
    .more {
      padding: 0 0 30px 0;
      max-width: 1700px;
      margin: 0 auto;
      text-align: center;
      display: flex;
      align-items: center;
      justify-content: center;
      .more_title {
        font-size: 24px;
        cursor: default;
      }
    }
  }
  .four {
    .four_1 {
      max-width: 1700px;
      margin: 0 auto 10px;
      display: flex;
      .list {
        width: 400px;
        margin: 0 30px 0 0;
        box-shadow: 0px 2px 10px 1px rgba(0, 0, 0, 0.12);
        .image {
          width: 100%;
          height: 280px;
        }
        .content {
          margin: 20px 30px 30px;
          .name {
            font-weight: bold;
            font-size: 22px;
            margin-bottom: 14px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
          }
          .other_1 {
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            font-size: 16px;
            line-height: 21px;
            font-weight: 600;
            margin-bottom: 10px;
            span {
              font-weight: 400;
            }
          }
          .button {
            text-align: center;
            button {
              width: 200px;
              height: 40px;
              line-height: 36px;
              text-align: center;
              color: #fff;
              font-size: 16px;
              background: linear-gradient(to bottom, #009fff, #0077ff);
              margin: 40px auto 0px;
              display: block;
              border-radius: 30px;
              border: none;
            }
          }
        }
      }
      .list:last-child {
        margin: 0;
      }
    }
    .more {
      padding: 30px 0;
      max-width: 1700px;
      margin: 0 auto;
      text-align: center;
      display: flex;
      align-items: center;
      justify-content: center;
      .more_title {
        font-size: 24px;
        cursor: default;
      }
    }
    .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>
