<template>
  <div class="app-container">
    <div style="width: calc(100% - 190px);margin: 0 auto">
      <el-row :gutter="24">
        <el-col v-for="item in assemblyData" :key="item.id" :span="6">
          <div class="item flex">
            <img :src="baseUrl + item.image" alt="">
            <div>
              <div class="title">{{ item.title }}</div>
              <p>{{ item.description }}</p>

              <el-button type="primary" link @click="openPage(item)">查看详情
                <el-icon>
                  <ArrowRight/>
                </el-icon>
              </el-button>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-dialog
        v-model="dialogTableVisible"
        :title="dialogTitle"
        width="1600"
    >
      <div>
        <iframe v-show="iframeShow" ref="iframe" :src="iframeSrc"
                :style="{ width: iframeWidth + 'px', height: iframeHeight + 'px' }"></iframe>
      </div>
      <!--      <template #footer>-->
      <!--        <div class="dialog-footer">-->
      <!--          <el-button @click="cancel">关闭</el-button>-->
      <!--        </div>-->
      <!--      </template>-->
    </el-dialog>
  </div>
</template>

<script setup name="ComponentServicesList">
import {ref} from 'vue'
import {assemblyList} 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 iframeWidth = ref(1560)
const iframeHeight = ref(800)
const dialogTitle = ref('')

function getAassemblyList() {
  assemblyList().then(res => {
    assemblyData.value = res.data
  })
}

getAassemblyList()

function openPage(data) {
  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
}
</script>
<style scoped lang="scss">
.app-container {
  min-height: 100%;
  padding-top: 30px;
  background-color: #F7F8F9;
}

.item {
  height: 168px;
  //background: #FBFCFE;
  background: url("@/assets/images/assemblyBg.jpg") no-repeat center center / cover;
  border-radius: 15px;
  border: 1px solid #D8D9DB;
  padding: 24px 24px 0 24px;
  margin-bottom: 24px;

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

  p {
    font-weight: 400;
    font-size: 16px;
    color: #626566;
    margin-top: 5px;
    margin-bottom: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    max-height: 100px;
    -webkit-box-orient: vertical;
  }

  img {
    width: 85px;
    height: 85px;
    object-fit: contain;
    margin-right: 30px;
    border-radius: 15px;
  }
}

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

.iframe-container iframe {
  position: absolute;
  top: 0;
  left: 0;
}
</style>
