<template>
    <div class="container">
        <!--内容-->
        <div class="newsbody">
            <div class="container" id="newsDtails_v">

                <div class="row">
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                        <p class="newsbody-title">{{detailsData.title}}</p>
                    </div>
                </div>
                <div class="row newsbody-info">
                    <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
                        <div class="newsbody-info-p"><span>作者：</span>{{detailsData.author}}</div>
                    </div>
                    <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
                        <div class="newsbody-info-p"><span>文章来源：</span>
                            {{detailsData.siteName}}
                        </div>
                    </div>
                    <div class="col-lg-4 col-md-4 col-sm-12 col-xs-12">
                        <div class="newsbody-info-p"><span>发布时间：</span>
                            {{detailsData.newsPubDate}}
                        </div>
                    </div>
                </div>
                <div class="row newsbody-article">
                    <div>
                        <!--                        <div style="margin-top:10px">-->
                        <!--                            {{detailsData.description}}-->
                        <!--                        </div>-->

                        <div v-html="detailsData.content"></div>
                    </div>
                </div>
                <div class="newsbody-article">
                    <div class="text-left mt-18" v-for="(file,index) in fileUrlsArr" :key="index">
                        <h4>
                            <a :href="file.fileUrls">{{file.fileIdNames}}</a>
                        </h4>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script type="text/babel">
  import formMixin from '../../../src/mixins/formMixin';
  import lenye_base from 'lenye_base';

  export default {
    name: 'NewsDetails',
    mixins: [formMixin],
    components: {},
    data() {
      return {
        siteData: {},
        fileUrlsArr: [],
        userData: {},
        detailsData: {},
        articleId: ''
      };
    },
    created() {
      this.siteData = lenye_base.site_data.getsiteData();
      if (lenye_base.user_data.getuserData()) {
        this.userData = lenye_base.user_data.getuserData();
      }
      this.getId();
    },
    mounted() {
      this.getNewsDetails();
    },
    methods: {
      // 获取新闻id
      getId() {
        this.articleId = lenye_base.getUrlParam("id");
      },
      // 获取新闻详情
      getNewsDetails() {
        const that = this;
        var obj = {
          url: lenye_base.api_url.news.queryById,
          data: {
            articleId: this.articleId
          },
          Ajax: function(data) {
            if (data.success === '1') {
              that.detailsData = data.data;
              console.log('新闻详情', data.data);
              let fileUrlsArr = [];
              if (data.data.fileUrls) {
                let fileUrls = data.data.fileUrls.split(',');
                fileUrls.forEach((a, i) => {
                  a ? fileUrlsArr[i] = {
                    fileUrls: a
                  } : '';
                });
              }
              if (data.data.fileIdNames) {
                let fileUrltext = data.data.fileIdNames.split(',');
                fileUrltext.forEach((a, i) => {
                  a ? fileUrlsArr[i]['fileIdNames'] = a : '';
                });
              }
              that.fileUrlsArr = fileUrlsArr;
            }
          }
        };
        this.getData(obj);
      },
      // 请求函数
      getData(obj) {
        // 请求的api，格式为 lenye_base.api_url.setting.queryShowPage
        const url = obj.url;
        //请求的数据，类型是对象
        const data = obj.data;
        // 只能是匿名函数，要用that保存this，否则匿名函数无论在哪调用this都指向window
        const Ajax = obj.Ajax;
        lenye_base.httpPost(lenye_base.base_data.getapiUrl() + url, lenye_base.base_data.getformatting(
          data), Ajax);
      }
    }
  };
</script>
<style scoped>
</style>
