<template>
  <div id="index">
    <el-row>
      <el-col :span="1"><i class="el-icon-s-home"></i></el-col>
      <el-col :span="23" style="margin-top:0.3rem">
        <el-breadcrumb separator=">">
          <el-breadcrumb-item :to="{ path: '/' }"><span style="color:#666666">网站首页</span></el-breadcrumb-item>
          <el-breadcrumb-item>
            <a href="info/list"><span style="color:#666666">新闻列表</span></a>
          </el-breadcrumb-item>
        </el-breadcrumb>
      </el-col>
    </el-row>
    <el-row>
      <!-- <el-col :span="24" style="margin-top: 1rem; width:50%">
        <el-input size="mini" placeholder="请输入标题" v-model="input3">
          <el-button slot="append" icon="el-icon-search"></el-button>
        </el-input>
      </el-col> -->
    </el-row>
    <el-row
      style="border-bottom-style:dashed; border-width:1px;border-color:#666666;font-size: small; padding: 0.5rem 0;"
      v-for="(item, index) in list"
      :key="index"
    >
      <el-col style="padding-top: 0.5rem;" :span="21">
        <el-link @click="$router.push({ path: '/info/detail', query: { id: item.id } })">{{ item.title }}</el-link>
      </el-col>
      <el-col :span="3" style="color:#999999; padding-top: 0.7rem;">
        <span style="padding: 0.5rem 0;">{{ item.meta && item.meta.createdAt ? new Date(item.meta.createdAt).toLocaleDateString() : '' || '' }}</span>
      </el-col>
    </el-row>
    <el-row style="margin-top:1rem;">
      <el-pagination @current-change="search" :current-page="currentPage" :page-size="$limit" layout="total, prev, pager, next, jumper" :total="totalRow">
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
import { mapActions, mapState } from 'vuex';
export default {
  name: 'index',
  props: {},

  components: {},
  data: () => ({
    input3: '',
    list: [],
    searchInfo: {},
    totalRow: 0,
    currentPage: 1,
    activeMenu: '1',
  }),
  created() {
    this.search();
  },
  computed: {},
  methods: {
    ...mapActions(['newsOperation']),
    async search(page) {
      let skip = 0;
      if (page) {
        skip = (page - 1) * this.$limit;
      }
      let newData = { skip: skip, limit: this.$limit, ...this.searchInfo };
      let result = await this.newsOperation({ type: 'list', data: { site: this.$site, ...newData } });
      if (`${result.errcode}` === '0') {
        //给this=>vue的实例下在中的list属性，赋予result。data的值
        this.$set(this, 'list', result.data);
        this.$set(this, `totalRow`, result.total);
      } else {
        this.$message.error(result.errmsg ? result.errmsg : 'error');
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
