<template>
  <div class="app-container">
    <div class="breadcrumb">
      <div class="flex-justify-end">
        <el-breadcrumb separator="/">
          <el-breadcrumb-item>首页</el-breadcrumb-item>
          <el-breadcrumb-item>活动资讯</el-breadcrumb-item>
        </el-breadcrumb>
      </div>
    </div>

    <div class="form">
      <el-form inline>
        <el-form-item label="资讯类型">
          <el-select v-model="queryParams.category" clearable @change="getInformation">
            <el-option
                v-for="dict in information_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="行业类别">
          <el-select v-model="queryParams.industryCategory" clearable @change="getInformation">
            <el-option
                v-for="dict in industry_category"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
            />
          </el-select>
        </el-form-item>
      </el-form>
    </div>

    <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="baseUrl + item.image" alt="">
            <div class="title">{{ item.title }}</div>
            <div class="flex-align-center flex-space-between">
              <div class="time">
                <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 {proxy} = getCurrentInstance()
const {
  information_status,
  industry_category
} = proxy.useDict('information_status', 'industry_category')

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

function getInformation () {
  informationList(queryParams.value).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>', '')
    })
    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;

  .item {
    margin-bottom: 24px;

    &:hover {
      cursor: pointer;

      .title {
        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: bold;
      font-size: 24px;
      color: #303233;
      margin-bottom: 16px;
      height: 66px;
      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: bold;
      font-size: 32px;
      color: #2E77E3;
      margin-right: 16px;
    }

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