<template>
  <div class="w900">
    <div class="mt20">
      <el-table v-loading="listLoading" :data="list"  highlight-current-row   :show-header="false">
        <el-table-column align="left" label="Id">
          <template slot-scope="{row}">
            <span @click="gotoDetail(row.postId)">{{ row.title }}</span>
          </template>
        </el-table-column>
        <el-table-column align="right" label="">
          <template slot-scope="{row}">
            <span>{{ row.publishTime|dateformat  }}</span>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page"
        :page-size="size"
        layout="total, prev, pager, next"
        class="mt20 tc"
        :total="total">

      </el-pagination>

    </div>

  </div>
</template>

<script>
    import {httpServer} from "@/components/httpServer/httpServer.js";
    import {parseTime} from "@/utils/index.js";
    export default {
    name: 'cert',
    data() {
      return {
        page: 1, //初始页
        size: 10, //    每页的数据
        list: [],
        total: 0,
        type: this.$route.params.type||'政策法规',
        listLoading: true
      }
    },
    filters:{
      dateformat(val){
        return parseTime( +new Date(val), '{y}-{m}-{d}')
      }
    },
    beforeMount() {
      this.getList()
    },
    watch: {
      '$route' (to, from) {
        this.type = to.params.type;
        this.currentPage = 1
        this.getList();
      },
      keyword(res) {
        this.currentPage = 1
        this.getList()
      }
    },
    methods: {
      getList() {
        this.listLoading = true
        let page = this.page
        let type= this.type
        httpServer("Course.getPostList", {page,type }).then( ({data, code}) => {
          let { total, list } = data
          if (!list) list = [];
          this.list = list.map(v => {
            this.$set(v, 'edit', false)
            return v
          })
          this.total = total || 0;
          this.listLoading = false
        })
      },
      gotoDetail( postId ) {
        this.$router.push({
          path: `/main/post/${postId}`
        })
      },
      handleSizeChange: function(size) {
        this.size = size;
      },
      handleCurrentChange: function(currentPage) {
        this.page = currentPage;
        this.getList()
      }
    }
  }
</script>

<style>
  @import url("./post.css");
</style>
