<template>
<div class="list">
  <el-table
    ref="table"
    stripe
    border
    :max-height="tableMaxHeight"
    :data="list"
    @selection-change="selectionChange"
    @row-click="toCheck"
  >
    <!--<table-column type="selection" fixed align="center"></table-column>-->
    <table-column label="交易ID" prop="tranId">
      <template slot-scope="scope">
        <span class="detail-no" @click.stop="toDetail(scope.$index)">{{scope.row.tranId}}</span>
      </template>
    </table-column>
    <table-column label="交易类型" prop="tranType">
      <template slot-scope="scope">
        <div>{{ $utils.keyMatcher(scope.row.tranType, $keys.inventoryQuery.transaction.tranType).name }}</div>
      </template>
    </table-column>
    <table-column label="单据号" prop="orderNo" :formatter="formatColumn"></table-column>
    <table-column label="单据行号" prop="lineNo" :formatter="formatColumn"></table-column>
    <table-column label="操作人" prop="tranOp" :formatter="formatColumn"></table-column>
    <table-column label="交易时间" prop="tranTime" :formatter="formatColumn"></table-column>
  </el-table>
  <el-pagination
    class="pagination"
    @size-change="sizeChange"
    @current-change="currentChange"
    :current-page="currentNo"
    :page-sizes="[10, 20, 30, 40, 50]"
    :page-size="pageSize"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total"
  ></el-pagination>
</div>
</template>

<script>
export default {
  props: ['list', 'total', 'currentNo', 'pageSize'],
  created () {
  },
  mounted () {
  },

  data () {
    return {
    }
  },
  methods: {
    // 点击表格行
    toCheck (row) {
      this.$refs.table.toggleRowSelection(row)
    },
    // 页码变化
    currentChange (currentNo) {
      const query = { 'page.currentPage': currentNo, 'page.limitCount': this.pageSize }
      this.$emit('getList', query)
    },
    // 每页条数变化
    sizeChange (pageSize) {
      const query = { 'page.limitCount': pageSize, 'page.currentPage': this.currentNo }
      this.$emit('getList', query)
    },
    // 勾选变化
    selectionChange (selection) {
      const selectedIds = selection.map(item => item.holdId).join(',')
      this.$emit('selectionChange', selectedIds)
    },
    // 详情
    toDetail (index) {
      this.$router.push({
        name: 'tranCreator',
        params: {
          list: this.list,
          index,
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.pagination {
  margin-top: 20px;
}
.detail-no {
  color: #0682ea;
  &:hover {
    cursor: pointer;
  }
}
</style>
