<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="`/message/detail/${scope.row.ID}`">{{scope.row.TITLE}}</router-link>
          </template>
        </el-table-column>
        <el-table-column label="已读">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.READED === '1'" type="success">已读</el-tag>
            <el-tag v-else type="warning">未读</el-tag>
          </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: 'message_list',
  components: {Pagination},
  mounted () {
    this.getData()
  },
  data () {
    return {
      allData: null,
      tableData: null,
      loading: true,
      currentPage: 1,
      totalPages: 1,
      totalCount: 1,
      pageSize: 20,
      tool: tool,
    }
  },
  methods: {
    handleCurrentChange (page) {
      this.getData(page, this.pageSize)
    },
    handleSizeChange (pageSize) {
      this.getData(this.currentPage, pageSize)
    },
    getData (page, pageSize) {
      let obj = this
      network.getPageData(this, `message/list`, page, pageSize, this.filterData, function (response) {
        obj.allData = response
      })
    },
  }
}

</script>

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