<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-table :data="tableData" stripe style="width: 100%;">
        <el-table-column label="标题" prop="TITLE">
          <template slot-scope="scope">
            <router-link :to="`/article/detail/${scope.row.ID}`">{{scope.row.TITLE}}</router-link>
          </template>
        </el-table-column>
        <el-table-column label="分类">
          <template slot-scope="scope">
            {{allData.allCategory[scope.row.CID].CATE_NAME}}
          </template>
        </el-table-column>
        <el-table-column label="创建时间">
          <template slot-scope="scope">
            {{tool.formatDate(scope.row.CREATED_AT)}}
          </template>
        </el-table-column>
      </el-table>
      <div class="white-box-footer">
        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import network from '@/utils/network'
import tool from '@/utils/tool'
import store from '@/utils/vuexStore'
import Pagination from '@/components/Pagination'

export default {
  name: 'article_list',
  components: {Pagination},
  mounted () {
    this.getData()
  },
  data () {
    return {
      allData: null,
      tableData: null,
      loading: true,
      currentPage: 1,
      totalPages: 1,
      totalCount: 1,
      pageSize: 20,
      tool: tool,
    }
  },
  watch: {
    '$route': function () {
      this.getData()
    }
  },
  methods: {
    handleCurrentChange (page) {
      this.getData(page, this.pageSize)
    },
    handleSizeChange (pageSize) {
      this.getData(this.currentPage, pageSize)
    },
    getData (page, pageSize) {
      let obj = this
      network.getPageData(this, `article/list/${this.$route.params.cid}`, page, pageSize, this.filterData, function (response) {
        obj.allData = response
      })
    },
  }
}

</script>

<style scoped>
  .white-box a {
    color: #606266;
  }
</style>