<template>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-md-8 col-sm-12 col-sm-12">
                <!--图文信息固定条数展示组件3结束-->
                <div class="twinfo_show_fixrecord_pc_3"><!--使用此组件，请复制此div-->
                    <div class="row">
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="news-picnews">
                                <div class="news-picnews-bd">
                                    <ul>
                                        <el-carousel :interval="5000" arrow="always" :autoplay="true" :loop="true">
                                            <el-carousel-item v-for="(item,index) in newsLeft" :key="index">
                                                <li @click="goDetails(item.articleId)">
                                                    <img :src="item.photo" alt="">
                                                    <span><a href="" @click.prevent>{{item.title}}</a></span>
                                                </li>
                                            </el-carousel-item>
                                        </el-carousel>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
                            <div class="index-title">
                                <span class="sp1">通知公告</span>
                                <span class="sp2"><a href="/infolist?name=通知公告&type=tzgg">更多>></a></span>
                            </div>
                            <div class="news-txtnews">
                                <ul class="news-txtnews-ul">
                                    <li v-if="index < 7" @click="goDetails(item.articleId)"
                                        v-for="(item,index) in newsRight"
                                        :key="index">
                                        <a href="javascript:;" :title="item.title"
                                           @click.prevent>{{item.title}}</a><span>{{item.createDate | format}}</span>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--图文信息固定条数展示组件3结束-->
        </div>
    </div>
</template>

<script type="text/babel">
  import formMixin from '../../../src/mixins/formMixin';
  import lenye_base from 'lenye_base';
  import $ from 'fy-kit';

  export default {
    name: 'Newscasts',
    mixins: [formMixin],
    components: {},
    data() {
      return {
        // 站点数据
        siteData: '',
        // 用户信息
        userData: '',
        // 右边不带图新闻列表里
        newsRight: [],
        // 左边带图新闻列表
        newsLeft: [],
        // 新闻请求数据
        getNewsListData: {
          siteId: '',
          catId: '',
          sorts: 'createDate=0',
          page: 1,
          rows: 10,
          posid: ''
        }
      };
    },
    created() {
      this.siteData = lenye_base.site_data.getsiteData();
      this.getNewsListData.siteId = this.siteData.siteId;
      if (lenye_base.user_data.getuserData()) {
        this.user = lenye_base.user_data.getuserData();
      }
    },
    mounted() {
      this.getNewsListRight();
      this.getNewsListLeft();
    },
    filters: {
      format(val) {
        return $.date.moment(val).format('MM-DD');
      }
    },
    computed: {},
    methods: {
      // 更多
      more() {
        this.$message({
          message: '暂未开通此功能！',
          type: 'warning'
        });
      },
      // 跳转到新闻详情
      goDetails(articleId) {
        window.open('/infodetail?id=' + articleId);
      },
      //请求新闻列表，右边不带图的
      getNewsListRight() {
        const that = this;
        lenye_base.httpPost(lenye_base.base_data.getapiUrl() + lenye_base.api_url.news.queryShowPage, lenye_base.base_data.getformatting({
          catName: '通知公告',
          sorts: 'createDate=0',
          rows: 10
        }), function(data) {
          that.newsRight = data.data;
        });
      },
      // 请求新闻列表，左边带图的
      getNewsListLeft() {
        this.getNewsListData.posid = '1';
        const that = this;
        var obj = {
          url: lenye_base.api_url.news.queryShowPage,
          data: this.getNewsListData,
          Ajax: function(data) {
            that.newsLeft = data.data;
          }
        };
        this.getData(obj);
      },
      // 请求函数
      getData(obj) {
        // 请求的api，格式为 lenye_base.api_url.setting.queryShowPage
        const url = obj.url;
        //请求的数据，类型是对象
        const data = obj.data;
        // 只能是箭头函数
        const Ajax = obj.Ajax;
        lenye_base.httpPost(lenye_base.base_data.getapiUrl() + url, lenye_base.base_data.getformatting(
          data), Ajax);
      }
    }
  };
</script>