<template>
  <div class="app-container">
    <el-card style="height: 850px">
      <div style="margin-top: 7px; margin-bottom: 7px">
        <el-input v-model="equipmentNo" placeholder="设备号" size="small" clearable style="width:160px" />
        <el-input v-model="equipmentName" placeholder="设备名" size="small" clearable style="width:160px;margin-left: 10px" />
        <span style="font-size: 13px;color: black;margin-left: 10px">整修时间</span>
        <el-date-picker
          v-model="dateRange"
          size="small"
          type="daterange"
          align="center"
          value-format="yyyy-MM-dd"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          style="width:240px" />
        <el-button type="primary" icon="el-icon-search" size="small" style="margin-left: 15px" plain @click="pageSize = 20;pageCurrent = 1;searchTable()">查询</el-button>
        <el-button type="success" icon="el-icon-download" size="small" style="margin-left: 10px" @click="exportExcel()">导出</el-button>
      </div>
      <el-table :data="tableData" border size="mini" stripe highlight-current-row height="750px" style="width: 100%">
        <el-table-column label="项次" align="center" type="index" width="50px" />
        <el-table-column label="设备号" prop="设备号" align="center" show-overflow-tooltip />
        <el-table-column label="设备名" prop="设备名" align="center" show-overflow-tooltip />
        <el-table-column label="开始时间" prop="整修开始时间" align="center" show-overflow-tooltip />
        <el-table-column label="结束时间" prop="整修结束时间" align="center" show-overflow-tooltip />
        <el-table-column label="工时" prop="工时" align="center" show-overflow-tooltip />
        <el-table-column label="报备人" prop="操作者" align="center" show-overflow-tooltip />
        <el-table-column label="整修状态" prop="整修状态" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.整修状态 === 0 || scope.row.整修状态 === '0'">整修中</span>
            <span v-else-if="scope.row.整修状态 === 1 || scope.row.整修状态 === '1'">整修结束</span>
          </template>
        </el-table-column>
        <el-table-column label="原因" prop="整修原因" align="center" show-overflow-tooltip />
        <el-table-column label="整修方案" prop="整修方案" align="center" show-overflow-tooltip />
      </el-table>
      <div class="block" style="margin-top: 10px">
        <el-pagination
          :current-page="pageCurrent"
          :page-sizes="[20, 50, 100, 200]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      equipmentNo: '',
      equipmentName: '',
      dateRange: '',
      tableData: [],
      total: 0,
      pageCurrent: 1,
      pageSize: 20
    }
  },
  created() {
    this.searchTable()
  },
  methods: {
    searchTable() {
      var param = []
      param[0] = ['设备号', this.equipmentNo]
      param[1] = ['设备名', this.equipmentName]
      param[2] = ['开始时间', this.dateRange ? this.dateRange[0] : '']
      param[3] = ['结束时间', this.dateRange ? this.dateRange[1] : '']
      var Data = this.CreateData('11', '设备管理_整修记录_查询', param, this.pageSize, this.pageCurrent)
      this.ExecDatabase(Data).then(response => {
        this.tableData = response.data.rows
        this.total = response.data.total
      })
    },
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    },
    exportExcel() {
      var param = []
      param[0] = ['设备号', this.equipmentNo]
      param[1] = ['设备名', this.equipmentName]
      param[2] = ['开始时间', this.dateRange ? this.dateRange[0] : '']
      param[3] = ['结束时间', this.dateRange ? this.dateRange[1] : '']
      var Data = this.CreateData('2001', '设备管理_整修记录_查询', param)
      this.exportExcel_NPOI(Data)
    }
  }
}
</script>
