<template>
  <a-list :class="$style.home" :data-source="data">
    <a-skeleton active :paragraph="{ rows: 4 }" :loading="loading" />
    <a-list-item slot="renderItem" slot-scope="record, index" :class="$style.items">
      <template>
        <div :class="$style.list">
          <div :class="$style.dates">
            <span style="font-size: 22px">{{ moment(record.finishTime).format('DD') }}</span
            ><br />
            <span>{{ moment(record.finishTime).format('YYYY-MM') }}</span>
          </div>
          <a-list-item-meta :description="''">
            <a
              slot="title"
              :href="getArticleUrl(type, record)"
              target="_blank"
              rel="opener"
              :title="record.title"
            >
              {{ record.title }}
            </a>
          </a-list-item-meta>
        </div>
      </template>
    </a-list-item>
    <a-empty v-if="isempty" :class="$style.emptySize">
      <a-icon slot="image" type="sd-notebook3" />
    </a-empty>
  </a-list>
</template>

<script>
import moment from 'moment'
import homepageService from './homepage-service'
import components from './_import-components/home-tzgg-list-import'
export default {
  name: 'HomeTzggList',
  components,
  props: {
    type: {
      default: '',
      type: String,
    },
    newsId: {
      default: '',
      type: String,
    },
    maxResults: {
      default: 6,
      type: Number,
    },
  },
  data() {
    return {
      loading: false,
      data: [],
      skeletonLoading: true,
      isempty: false,
      moment,
    }
  },
  mounted() {
    this.loading = true
    this.getNewsList({ articleBusinessType: this.type, maxResults: this.maxResults })
  },
  methods: {
    getArticleUrl(type, record) {
      // return `?#/sd-webflow/done-pages/${record.instId}`
      return `?#/iam-audit-home-three?type=${this.newsId}&id=${record.instId}`
    },
    // 降序函数  封装
    Desc(arr, StrKey) {
      var desc = function(x, y) {
        return x[StrKey] < y[StrKey] ? 1 : -1
      }
      return arr.sort(desc)
    },
    getNewsList(params) {
      this.loading = true
      const Num = 0
      const regex = /(<([^>]+)>)/gi
      homepageService.getNews(params).then((res) => {
        this.loading = false
        if (res) {
          if (this.newsId === 'tzgg') {
            if (res.data['03'].length) {
              res.data['03'].forEach((item) => {
                item.finishTime = item.finishdate
                let content = item.inforDescription
                if (content !== null) {
                  content = content.replace(regex, '')
                  content = content.replace(/&nbsp;/g, '')
                  item.content = content
                } else {
                  item.content = ''
                }
              })
              this.data = res.data['03'].splice(0, this.maxResults)
            } else {
              this.isempty = true
            }
          } else if (this.newsId === 'gxjb') {
            if (res.data['05'].length) {
              res.data['05'].forEach((item) => {
                item.finishTime = item.finishdate
                let content = item.inforDescription
                if (content !== null) {
                  content = content.replace(regex, '')
                  content = content.replace(/&nbsp;/g, '')
                  item.content = content
                } else {
                  item.content = ''
                }
              })
              this.data = res.data['05'].splice(0, this.maxResults)
            } else {
              this.isempty = true
            }
          } else {
            if (res.data.length) {
              if (this.type === 'getLawInstitutions') {
                res.data.forEach((item) => {
                  item.title = item.docTitle
                  item.finishTime = moment(item.publishTime).format('YYYY-MM-DD')
                })
              } else {
                res.data.forEach((item) => {
                  item.finishTime = moment(item.lastModifiedTime).format('YYYY-MM-DD')
                })
              }
              this.data = res.data.splice(0, this.maxResults)
            } else {
              this.isempty = true
            }
          }
        } else {
          this.isempty = true
        }
      })
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
$importcolor: #e02020;
$importsize: 28px;
$lineheight: 28px;
$fonsicon-bg: 48px;
$nodata-icon: #d9d9d9;
.home {
  :global(.ant-table-placeholder) {
    border: 0;
  }
  .first-notice {
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    a {
      overflow: hidden;
      font-size: $importsize;
      font-weight: bold;
      color: $importcolor;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .detail {
      max-height: 60px;
      overflow: hidden;
      line-height: $lineheight;
    }
  }
  .items {
    border-bottom: none;
    .list {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      :global(.ant-list-item-meta) {
        display: block;
        flex: inherit;
        width: calc(100% - 100px);
      }
      :global(.ant-badge) {
        display: inline-block;
        max-width: calc(100% - 50px);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        vertical-align: middle;
      }
    }
    .dates {
      min-width: 80px;
      margin-left: 10px;
      text-align: center;
      border: 1px solid #e8e8e8;
      border-radius: 10px;
    }
  }
  :global(.ant-tag) {
    margin-left: 10px;
  }
  :global(.ant-badge-status-primary) {
    background-color: $primary-color;
  }
  :global(.ant-badge-status-dot) {
    width: 10px;
    height: 10px;
  }
  :global(.ant-badge-status-text) {
    font-size: $font-size-lg;
  }
}
.empty-size {
  margin: 10% 0;
  :global(.ant-empty-image) {
    height: 50px;
    i {
      height: 100%;
      font-size: $fonsicon-bg;
      color: $nodata-icon;
    }
  }
}

@media screen and (min-width: 1920px) {
  .items {
    padding: 12px 0;
  }
}
@media screen and (min-width: 1440px) and (max-width: 1599px) {
  .items {
    padding: 10px 0;
  }
}
@media screen and (min-width: 1600px) and (max-width: 1919px) {
  .items {
    padding: 10px 0;
  }
}
@media screen and (min-width: 992px) and (max-width: 1439px) {
  .items {
    padding: 8px 0;
  }
}
</style>
