<template>
<div class="list">
  <!--<drop-filter :columns="wholeLabels" :storeKey="storeKey" :storeLabels="storeLables" @doFilter="labels => storeLables = labels"></drop-filter>-->
  <el-table
    ref="table"
    stripe
    border
    :max-height="tableMaxHeight"
    :data="list"
    :filteredLabels="storeLables"
    @selection-change="selectionChange"
    @row-click="toCheck"
  >
    <table-column type="selection" fixed align="center"></table-column>
    <!--<table-column label="冻结ID" prop="holdId">-->
      <!--<template slot-scope="scope">-->
        <!--<span class="detail-no" @click.stop="toDetail(scope.row)">{{scope.row.holdId}}</span>-->
      <!--</template>-->
    <!--</table-column>-->
    <table-column label="车牌号" prop="vehicleNo" ></table-column>
    <table-column label="车辆类型" prop="businessType">
      <template slot-scope="scope">
        <div>{{ $utils.keyMatcher(scope.row.businessType, $keys.warehouseBasic.vehicle.businessType).name }}</div>
      </template>
    </table-column>
    <table-column label="车型" prop="vehicleType" ></table-column>
    <table-column label="驾驶员" prop="driver" ></table-column>
    <table-column label="身份证号" prop="driverIdentity" ></table-column>
    <table-column label="联系电话" prop="driverTel" ></table-column>
    <table-column label="备注" prop="remark" ></table-column>
    <table-column label="操作" width="100" fixed="right">
      <template slot-scope="scope">
        <el-button
          title="编辑"
          size="mini"
          type="success"
          icon="el-icon-edit"
          plain
          circle
          @click.stop="toEdit(scope.row)"
        ></el-button>
        <el-button
          title="删除"
          size="mini"
          type="danger"
          icon="el-icon-delete"
          plain
          circle
          @click.stop="toDelete(scope.row)"
        ></el-button>
      </template>
    </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 {
      storeKey: 'vehicle',
    }
  },
  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.currentPage': this.currentNo, 'page.limitCount': pageSize }
      this.$emit('getList', query)
    },
    // toDetail (row) {
    //   this.$emit('toShowCreator', 'detail', row)
    // },
    // 勾选变化
    selectionChange (selection) {
      const selectedIds = selection.map(item => item.vehicleNo)
      this.$emit('selectionChange', selectedIds)
    },
    // 编辑
    toEdit (row) {
      this.$emit('toShowCreator', 'edit', row)
    },
    // 删除
    toDelete (row) {
      this.$confirm(`是否要删除 ?`)
        .then(() => {
          const url = this.$API.warehouseBasic.vehicle.delete
          const param = {
            vehicleNos: JSON.stringify([row.vehicleNo])
          }
          this.$https.post(url, param)
            .then(() => {
              this.$emit('getList')
            })
        })
        .catch(err => console.log(err))
    },
  },
}
</script>

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