<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><span style="color:#666666">信息列表</span></a>
          </el-breadcrumb-item>
        </el-breadcrumb>
      </el-col>
    </el-row>
    <el-row> </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 :underline="false" @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: {
    parent_id() {
      return this.$route.params.parent_id;
    },
    news_type() {
      return this.$route.query.news_type;
    },
  },
  watch: {
    parent_id: 'search',
  },
  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, parent_id: this.parent_id, news_type: this.news_type };
      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>
