<template>
  <div class="page" v-loading.body.fullscreen="fullscreenLoading" element-loading-background="rgba(255, 255, 255, 0)">
    <van-sticky class="sticky">
      <div class="header">
        <div class="back">
          <backIcon/>
        </div>
        <!-- 详情 -->
        {{ $t('fund.l51') }}
        <div class="right-box flex">
          <shareIcon />
          <msgIcon />
        </div>
      </div>
    </van-sticky>
    <div v-if="info.id" class="container">
      <div class="title">{{ info.title }}</div>
      <div class="time-box flex">
        <div>{{ info.origin }}</div>
        <div>{{ info.created_at }}</div>
      </div>
      <div class="content" v-html="info.content || info.title"></div>
      <div class="tip">
        <div>
          <!-- 来源: 本文版权归原作者/机构所有 -->
          {{ $t('my.l18') }}
        </div>
        <div>
          <!-- 当前内容仅代表作者观点，与极度证券立场无关。内容仅供投资参考，亦不构成任何投资建议。如对极度证券提供的内容服务有任何疑问或建议，请联系我们。 -->
          {{ $t('my.l19') }}
        </div>
      </div>
    </div>
    <div class="list" v-if="list.length">
      <div class="sub">
        <!-- 推荐阅读 -->
        {{ $t('my.l20') }}
      </div>
      <div class="li" v-for="(item, index) in list" :key="index" @click="checkDetail(item)">
        <div class="title1">{{ item.title }}</div>
        <div class="at">{{ item.created_at }}</div>
      </div>
    </div>
  </div>
</template>
<script>
import { getNews, newsDetail } from "@/api/market";
export default {
  data () {
    return {
      info: {},
      list: []
    }
  },
  watch: {
    '$route'() {
      this.info = {}
      this.newsDetail()
    }
  },
  created () {
    this.newsDetail()
  },
  methods: {
    newsDetail() {
      this.fullscreenLoading = true
      newsDetail({
        id: this.$route.params.id
      }).then(res => {
        this.info = res || {}
        this.getNews()
      }).catch(() => {}).finally(() => {
        this.fullscreenLoading = false;
      })
    },
    getNews() {
      var data = {
        pageNum: 1,
        pageSize: 3,
        language: (this.language == 'zh-CN' || this.language == 'zh-TW') ? 'zh' : this.language
      }
      if (['港股','美股','A股', '沪深'].indexOf(this.info.category) !== -1) {
        data.market = this.info.market
      } else if (this.info.category == '综合'){
        data.market = 'crypto'
      } else {
        data.category = this.info.category
      }
      getNews(data).then(res => {
        if (Array.isArray(res)) {
          this.loading = false;
          this.finished = true;
          return
        }
        this.list = res.list || []
      })
    },
    checkDetail(item) {
      if (item.category != '快讯') {
        this.$router.replace('/news-detail/' + item.id)
      }
    },
  }
}
</script>
<style lang="less" scoped>
.page {
  background-color: #F6FAFE;
}
.sticky {
  background-color: var(--bg-);
}
.header {
  position: relative;
  font-size: 18px;
  font-weight: 600;
  padding: 15px 9px 17px;
  background-color: var(--bg-);
  text-align: center;
  .back {
    position: absolute;
    top: 11px;
    left: 9px;
  }
  .right-box {
    position: absolute;
    top: 11px;
    right: 14px;
    column-gap: 15px;
  }
}
.container {
  padding: 10px 18px 20px;
  background-color: #fff;
}
.title {
  font-size: 20px;
  color: var(--color-1-);
  line-height: 30px;
  font-weight: 600;
  margin-bottom: 9px;
}
.time-box {
  color: #878787;
  margin-bottom: 22px;
  column-gap: 12px;
}
.tip {
  border-top: 1px solid #EFEFEF;
  font-size: 12px;
  color: #9F9F9F;
  line-height: 21px;
  padding-top: 17px;
  margin-top: 17px;
}
.list {
  padding: 19px 18px 10px;
  background-color: #fff;
  margin-top: 5px;
  .li {
    margin-bottom: 15px;
  }
  .sub {
    font-weight: 500;
    color: #1A1A1C;
    line-height: 16px;
    margin-bottom: 11px;
  }
  .title1 {
    font-weight: 600;
    color: #3C3C3C;
    line-height: 20px;
  }
  .at {
    font-size: 10px;
    color: #B8B8B8;
    margin-top: 6px;
  }
}
::v-deep .content {
  word-break: break-all;
  P {
    font-size: 18px;
    color: #3D3C3C;
    line-height: 32px;
    text-indent: 1em;
  }
  img {
    max-width: 100%;
    height: auto !important;
  }
  h1 {
    padding: 10px 0;
    line-height: 1.2em;
  }
}
</style>