<template>
  <el-row class="movie-list">
    <el-col :md="18">
      <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
        <el-card class="box-card" v-if="article !== null">
          <div slot="header" class="clearfix">
            <el-row>
              <span v-html="article.title" />
              <span v-if="article.originalUrl !== null">
                <a style="text-decoration-line: none" target="_blank" :href="`${article.originalUrl}`">
                  原始链接
                </a>
              </span>
            </el-row>
            <el-divider />
            <el-row>
              发布于 <span v-html="article.publishAt" />
            </el-row>
            <el-divider />
            <el-row v-if="userAvatar !== null">
              <el-col :md="2">
                <router-link target="_blank" :to="`/user/` + userAvatar.userId">
                  <el-avatar>
                    <el-image :src="userAvatar.avatarUrl" />
                  </el-avatar>
                </router-link>
              </el-col>
              <el-col :md="10">
                <el-row>
                  <span v-html="userAvatar.screenName" />
                </el-row>
                <el-row>
                  <span>-</span>
                </el-row>
              </el-col>
            </el-row>
          </div>
          <div class="text item">
            <el-row>
              <span v-html="article.content" />
            </el-row>
            <el-divider />
            <el-row>
              <span>
                <i :class="collectedIcon" @click="collectItem" />
              </span>
            </el-row>
          </div>
        </el-card>
      </el-row>
    </el-col>
    <el-col :md="6">
      <el-row style="padding-right: 5px; padding-left: 5px; padding-bottom: 5px">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <el-row>
              <span>推荐文章</span>
            </el-row>
          </div>
          <div class="text item">
            <el-row />
          </div>
        </el-card>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
// import { getArticle } from '@/api/article'
// import { getUserInfo } from '@/api/user'
import { getNewsDetail } from '@/api/news'

export default {
  name: 'ArticlePage',
  metaInfo: {
    meta: [
      { name: 'referrer', content: 'no-referrer' }
    ]
  },
  components: {},
  filters: {
    ellipsis(value) {
      if (!value) return ''
      const max = 20
      if (value.length > max) {
        return value.slice(0, max) + '...'
      }
      return value
    }
  },
  data() {
    return {
      article: null,
      userAvatar: null,
      collected: false,
      collectedIcon: 'el-icon-star-off'
    }
  },
  created() {
    const articleId = this.$route.params.articleId
    getNewsDetail(articleId).then(resp => {
      if (resp.code === 0) {
        this.article = resp.data
        document.title = '文章 - ' + this.article.title
        /* getUserInfo(this.article.userId).then(resp => {
          if (resp.code === 0) {
            this.userAvatar = resp.data
          }
        })*/
      }
    })
  },
  methods: {
    collectItem() {
      this.$message.info('暂未实现')
      if (this.collected) {
        console.log('取消收藏')
        this.collected = false
        this.collectedIcon = 'el-icon-star-off'
      } else {
        console.log('收藏')
        this.collected = true
        this.collectedIcon = 'el-icon-star-on'
      }
    }
  }
}
</script>

<style scoped>
/*处于手机屏幕时*/
@media screen and (max-width: 768px) {
  .movie-list {
    padding-top: 5px;
    padding-left: 3px;
    padding-right: 3px;
  }
}

.movie-list {
  padding-top: 5px;
  padding-left: 3px;
  padding-right: 3px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
</style>
