<template>
  <normal-table :data="caseList" :query="listQuery" :total="total" :columns="tableColumns" @change="changePage">
    <template slot="btns">
      <el-button v-if="showExport" size="small" class="edit_btn" @click="exportTalbe">导出</el-button>
    </template>
    <template slot="columns">
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click.stop="showDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </template>
  </normal-table>

</template>

<script>
export default {
  name: 'CaseList',
  props: {
    caseList: {
      type: Array,
      default() {
        return []
      }
    },
    listQuery: {
      type: Object,
      default() {
        return {
          offset: 1,
          limit: 10,
          sort: 'caseid',
          order: 'desc',
          queryCondition: {}
        }
      }
    },
    tableColumns: {
      type: Array,
      default() {
        return [
          {
            text: '案卷编号',
            value: 'caseid'
          },
          {
            text: '节点名称',
            value: 'caseStateName'
          },
          {
            text: '信息来源',
            value: 'sourceName'
          },
          {
            text: '案卷类别',
            value: 'eorcName'
          },
          {
            text: '所剩时间',
            value: 'remainingTime'
          },
          {
            text: '案卷描述',
            value: 'description'
          }
        ]
      }
    },
    total: {
      type: Number,
      default: 0
    },
    showExport: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
    }
  },
  methods: {

    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.$emit('changeQuery', this.listQuery)
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.$emit('changeQuery', this.listQuery)
    },
    // 页数发生变化后的操作，可能是页码变化，可能是每页容量变化，此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.$emit('changeQuery', this.listQuery)
    },
    showDetail(row, column, event) {
      console.log('row', row)
      // this.$refs.table.setCurrentRow(row)
      const tabPane = {
        title: '案卷详情',
        name: 'case' + row.caseid,
        // content: 'EditTab',
        closable: true,
        index: row.id
      }
      // console.log('tabPane', tabPane)
      this.$emit('addDetail', tabPane, row)
    },
    exportTalbe() {
      this.$emit('exportTalbe', this.listQuery)
    }
  }
}
</script>

