<template>
  <div class="app-container">
    <div class="list-box">
      <el-row v-if="informationData.length" :gutter="24">
        <el-col :span="8" v-for="item in informationData" :key="item.id">
          <div class="item" @click="$router.push('/information/informationDetail?id='+item.id)">
            <img :src="item.images" alt="">
            <div class="title">{{ item.title }}</div>
            <div class="flex-align-center flex-space-between">
              <div class="time" style="display: flex; align-items: center;flex: 1;">
                <span class="date">{{ item.day }}/{{ item.month }}</span>
                <span class="year">{{ item.year }}</span>
              </div>
              <el-button link type="primary">
                详情
                <el-icon>
                  <ArrowRight/>
                </el-icon>
              </el-button>
            </div>
          </div>
        </el-col>
      </el-row>
      <el-empty v-else/>
    </div>
  </div>
</template>

<script setup name="InformationList">
import {informationList} from '@/api/home.js'
import {ref} from 'vue'

const baseUrl = import.meta.env.VITE_APP_BASE_API
const informationData = ref([])

function getInformation() {
  informationList().then(res => {
    res.data.forEach(item => {
      item.year = new Date(item.createTime).getFullYear()
      item.month = new Date(item.createTime).getMonth() + 1
      item.month = item.month < 10 ? '0' + item.month : item.month
      item.day = new Date(item.createTime).getDate()
      item.day = item.day < 10 ? '0' + item.day : item.day
      item.description = item.description.replace('<p><br></p>', '')
      item.images = item.images.length !== 0 ? item.images[0] : ''
    })
    informationData.value = res.data
  })
}

getInformation()

</script>

<style scoped lang="scss">
.app-container {
  background-color: #F7F8F9;
  padding: 0 0 90px;
  min-height: 100%;
}

.breadcrumb {
  background-color: #FFFFFF;
  padding-top: 12px;
  padding-bottom: 12px;

  > div {
    width: 1280px;
    margin: 0 auto;
  }

  :deep(.el-breadcrumb__item) {
    &:last-child .el-breadcrumb__inner {
      color: #222222;
    }
  }
}

.form {
  width: 1280px;
  margin: 24px auto 24px auto;
  background: #FFFFFF;
  border-radius: 4px;
  padding: 12px 24px;

  .el-form-item {
    margin-bottom: 0;
  }
}

.list-box {
  width: 1280px;
  margin: 0 auto;
  padding-top: 70px;

  .item {
    margin-bottom: 24px;

    &:hover {
      cursor: pointer;

      .title {
        font-size: 16px !important;
        color: #2E77E3;
      }
    }

    img {
      background: #FFFFFF;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #D6D7D8;
      display: block;
      margin-bottom: 24px;
      width: 100%;
      height: 256px;
    }

    .title {
      font-weight: 700;
      font-size: 16px;
      color: #303233;
      margin-bottom: 16px;
      height: 26px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      max-height: 100px;
      -webkit-box-orient: vertical;
    }

    .date {
      font-family: DIN, system-ui;
      font-weight: 700;
      font-size: 16px;
      color: #2E77E3;
      margin-right: 16px;
    }

    .year {
      font-family: DIN, system-ui;
      font-weight: 400;
      font-size: 16px;
      color: #2E77E3;
    }
  }
}
</style>
