<template>
  <div>
    <div class="mrg-b">
      <!--<drop-filter-->
        <!--:columns="wholeLabels"-->
        <!--:storeKey="storeKey"-->
        <!--:storeLabels="storeLables"-->
        <!--@doFilter="labels => storeLables = labels"-->
      <!--&gt;</drop-filter>-->
      <el-table
        ref="table"
        stripe
        border
        :max-height="tableMaxHeight"
        :data="tableData"
        :filteredLabels="storeLables"
        @selection-change="handleSelectChange"
      >
        <table-column type="selection" fixed align="center"></table-column>
        <table-column label="合同编号" prop="contractNo">
          <template slot-scope="scope">
            <span
              class="blue"
              @click.stop="handleClassify(scope.$index, scope.row,'detail')"
            >{{scope.row.contractNo}}</span>
          </template>
        </table-column>
        <table-column label="合同名称" prop="contractName"></table-column>
        <table-column label="状态" prop="auditStatus">
          <template
            slot-scope="scope"
          >{{ $utils.keyMatcher(scope.row.auditStatus, $keys.charging.auditStatus).name }}</template>
        </table-column>
        <table-column label="合同类型" prop="contractType">
          <template slot-scope="scope">
            {{ $utils.keyMatcher(scope.row.contractType, $keys.charging.contractType).name }}
          </template>
        </table-column>
        <table-column label="客户" prop="customerCode">
          <template slot-scope="scope">
            <p>{{scope.row.customerCode}}</p>
            <p>{{scope.row.ebcuNameCn}}</p>
          </template>
        </table-column>
        <table-column label="有效日期">
          <template slot-scope="scope">
            <p>从：{{scope.row.effectiveDate}}</p>
            <p>到：{{scope.row.expirationDate}}</p>
          </template>
        </table-column>
        <table-column label="合同文件号" prop="fileNo"></table-column>
        <table-column label="备注" prop="remark"></table-column>
        <table-column label="操作" width="100" fixed="right">
          <template slot-scope="scope">
            <el-tooltip content="编辑" placement="top">
              <el-button
                size="mini"
                type="primary"
                icon="el-icon-edit"
                plain
                circle
                @click="handleClassify(scope.$index, scope.row,'edit')"
              ></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button
                size="mini"
                type="danger"
                icon="el-icon-delete"
                plain
                circle
                @click="handleDelete(scope.$index, scope.row)"
              ></el-button>
            </el-tooltip>
          </template>
        </table-column>
      </el-table>
    </div>
    <div>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {

      removeIds: [],
      storeKey: 'contract'
    }
  },
  props: {
    tableData: {
      type: Array,
      default: () => []
    },
    total: Number,
    pageSize: Number,
    currentPage: Number,
  },
  methods: {

    // 每页显示条数
    handleSizeChange (pageSize) {
      const query = { 'page.limitCount': pageSize, 'page.currentPage': this.currentPage }
      this.$emit('getList', query)
    },

    // 当前页码
    handleCurrentChange (currentPage) {
      const query = { 'page.limitCount': this.pageSize, 'page.currentPage': currentPage }
      this.$emit('getList', query)
    },

    getData (url, param) {
      return this.$https.post(url, param)
    },

    handleClassify (index, row, type) {
      if (type === 'edit' && row.auditStatus === '99') return this.$message.warning('已审核不能操作')
      const headUrl = this.$API.charging.contract.query
      const listUrl = this.$API.charging.contract.queryDetail
      const param = { contractNo: row.contractNo, 'page.currentPage': 1, 'page.limitCount': 10 }

      this.$https.all([this.getData(headUrl, param), this.getData(listUrl, param)]).then(res => {
        const head = res[0].rows[0]
        const list = res[1].rows
        this.$emit('handleOpenForm', type, head, list)
      })
    },

    // 删除行
    handleDelete (index, row) {
      const url = this.$API.charging.contract.delList
      this.removeIds.push(row.contractNo)
      const param = { contractNos: JSON.stringify(this.removeIds) }

      this.$confirm('是否删除此条数据？', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$https.post(url, param).then(res => {
          this.$emit('getList')
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    // checkbox勾选
    handleSelectChange (selection) {
      const selectIds = selection.map(item => item.contractNo)
      this.$emit('handleSelectChange', selectIds, selection)
    }
  }
}
</script>
<style lang="scss" scoped>
.mrg-b {
  margin-bottom: 20px;
}
.mrg-l {
  margin-left: 10px;
}
.blue {
  cursor: pointer;
  color: #0682ea;
}
</style>
