<template>
  <div class="app-container custom-main-w ">
    <div style="margin: 0 auto;padding: 0 84px;'">
      <!--      内容过滤器-->
      <!--      <el-tabs v-model="tabActive" @tab-change="tabChange">-->
      <!--        <el-tab-pane-->
      <!--            v-for="i in assemblyTypes"-->
      <!--            :key="i.value"-->
      <!--            :label="i.name"-->
      <!--            :name="i.value">-->
      <!--        </el-tab-pane>-->
      <!--      </el-tabs>-->

      <el-row :gutter="24">
        <el-col v-for="(item,index) in assemblyData" :key="item.id" :span="6">
          <div class="item flex">
            <img :src="item.image" alt=""/>
            <div>
              <div class="title">{{ item.title }}</div>
              <p v-html="item.description"></p>

              <el-button round @click="openPage(item,index)">点击试用</el-button>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-dialog
        v-model="dialogTableVisible"
        style="width: 80% !important;"
        :title="dialogTitle"
        @close="handleDialogClose"
    >
      <div>
        <iframe v-show="iframeShow" ref="iframe" :src="iframeSrc" width="100%" height="700px"></iframe>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="ComponentServicesList">
import {ref} from 'vue'
import {assemblyList} from '@/api/home.js'
import {assemblyType} from "../../api/home.js";

const baseUrl = import.meta.env.VITE_APP_BASE_API
const assemblyData = ref([])
const iframeSrc = ref('')
const iframeShow = ref(false)
const dialogTableVisible = ref(false)
const dialogTitle = ref('')
const indexNum = ref(0)
const assemblyTypes = ref([])
const tabActive = ref("0")

function getAassemblyList() {
  assemblyList().then(res => {
    const validData = res.data;
    validData.forEach(item => {
      // 处理images数组，只取第一张图片
      if (Array.isArray(item.images) && item.images.length > 0) {
        item.image = item.images[0];
      } else {
        item.image = ''; // 如果没有图片，设置为空字符串
      }
    });
    assemblyData.value = validData;
  })
}

function openPage(data, index) {
  indexNum.value = index
  dialogTitle.value = data.title
  iframeSrc.value = data.url
  dialogTableVisible.value = true
  iframeShow.value = true
  // window.open(data.url)
}

function cancel() {
  dialogTableVisible.value = false
  iframeShow.value = false
}

// 关闭弹窗
function handleDialogClose() {
  iframeSrc.value = null
}

getAassemblyList()
</script>
<style scoped lang="scss">
.app-container {
  min-height: 100%;
  padding-top: 70px;
  //background-color: #F7F8F9;
}

.flex {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.item {
  //height: 168px;
  //background: #FBFCFE;
  //background: url("@/assets/images/assemblyBg.jpg") no-repeat center center / cover;
  background: #ffffff;
  border-radius: 10px;
  padding: 30px 26px 40px 40px;
  margin-bottom: 40px;
  text-align: center;

  .title {
    font-weight: bold;
    font-size: 20px;
    line-height: 36px;
    height: 36px;
    color: #303233;
  }

  p {
    font-weight: 400;
    font-size: 16px;
    color: rgb(102, 102, 102);
    line-height: 24px;
    margin-top: 9px;
    margin-bottom: 30px;
    height: 48px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  img {
    width: 70px;
    height: 70px;
    object-fit: contain;
    //margin-right: 30px;
    border-radius: 15px;
    margin: 0 auto 15px;
  }
}

.iframe-container {
  position: absolute;
  top: 10%;
  left: 6%;
}

.iframe-container iframe {
  position: absolute;
  top: 0;
  left: 0;
}

:deep(.el-dialog__body) {
  padding-top: unset !important;
}

.el-tabs {
  --el-border-color-light: #2E77E3;
  --el-tabs-header-height: 48px;

  :deep(.el-tabs__content) {
    overflow: visible
  }

  :deep(.el-tabs__active-bar) {
    display: none;
  }

  :deep(.el-tabs__item) {
    --el-font-size-base: 16px;
    padding-left: 24px !important;
    padding-right: 24px !important;

    &.is-active {
      color: #ffffff;
      background-color: #2E77E3;
    }
  }
}

.el-button {
  height: 40px;
  line-height: 38px;
  width: 140px;
  border: 1px solid rgb(31, 74, 175);
  border-radius: 10px;
  color: rgb(31, 74, 175);
}
</style>
