<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <span style="margin-left: 10px">工位号：</span>
        <el-select
          v-model="stationNumberValue"
          placeholder="工位号"
          filterable
          clearable
          size="small"
          style="width: 120px">
          <el-option
            v-for="item in stationNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            size="mini"/>
        </el-select>
        <span style="margin-left: 10px">产品编号：</span>
        <el-input v-model="vin" placeholder="请输入产品编号" clearable size="small" style="width: 240px;"/>
        <span style="margin-left: 10px">生产日期：</span>
        <el-date-picker
          :clearable = "false"
          v-model="dateTime"
          size="small"
          type="daterange"
          align="center"
          style="width: 240px;"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          range-separator="～"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
        <el-button type="primary" plain size="small" icon="el-icon-search" style="margin-left: 5px" @click="pageCurrent = 1,pageSize = 15,selectDate()">查询</el-button>
        <!--        <el-button type="info" size="small" icon="el-icon-download" @click="exportExcel()">Excel</el-button>-->

        <el-table
          v-loading="loading"
          ref="multipleTable"
          :data="tableData"
          :header-cell-style="{background:'#eef1f6',color:'#606266'}"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
          class="main"
          tooltip-effect="dark"
          height="640px"
          style="width: 100%;max-height: 700px"
          border
          size="mini">
          <!--        <el-table-column :selectable="selectable" type="selection" width="45" align="center"/>-->
          <el-table-column type="index" width="60" label="序号" align="center"/>
          <el-table-column align="center" width="120px" label="工位号">
            <template slot-scope="scope">
              {{ scope.row.工位号 }}
            </template>
          </el-table-column>
          <el-table-column align="center" width="200px" label="产品编号">
            <template slot-scope="scope">
              {{ scope.row.发动机号 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="返修原因">
            <template slot-scope="scope">
              {{ scope.row.返修原因 }}
            </template>
          </el-table-column>
          <el-table-column align="center" width="150px" label="开始时间">
            <template slot-scope="scope">
              {{ scope.row.返修时间 }}
            </template>
          </el-table-column>
          <el-table-column align="center" width="150px" label="结束时间">
            <template slot-scope="scope">
              {{ scope.row.结束时间 }}
            </template>
          </el-table-column>
          <el-table-column align="center" width="150px" label="返修时长(m)">
            <template slot-scope="scope">
              {{ scope.row.返修时长 }}
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination
            v-if="!loading"
            :current-page="pageCurrent"
            :page-sizes="[15, 30, 40]"
            :page-size="pageSize"
            :total="total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getNowTime2 } from '../../../utils/tool'

export default {
  data() {
    return {
      vin: '',
      traceabilityCodeArr: [], // 精确追溯码数组
      traceabilityCode: '', // 精确追溯码
      assemblyNumber: [], // 总成编号
      assemblyNumberValue: '', // 总成编号
      orderNumberValue: '', // 订单号
      orderNumber: [], // 订单号
      stationNumberValue: '', // 工位号
      stationNumber: [], // 工位号
      measuringPosition: [], // 测量位置
      measuringPositionValue: '', // 测量位置
      measuringProject: [], // 测量项目
      measuringProjectValue: '', // 测量项目
      engineTypeValue: '', // 机型
      engineType: [], // 机型
      batchBarcode: [], // 批次条码
      batchBarcodeValue: '', // 批次条码
      partName: [], // 零件名称
      partNameValue: '', // 零件名称
      isQualified: [
        {
          label: '合格',
          value: 1
        }, {
          label: '不合格',
          value: 2
        }, {
          label: '全部',
          value: 0
        }
      ], // 是否合格
      isQualifiedValue: 1, // 是否合格
      dateTime: '', // 时间
      loading: false, // 时间
      tableData: [], // 时间
      date: new Date(),
      timer: '',
      total: 0, // 总条数
      pageList: 30, // 每页显示条数
      pageSize: 30, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  created() {
    this.dateTime = [getNowTime2(), getNowTime2()]
    this.getStationNumber()
  },
  mounted() {
  },
  methods: {
    getStationNumber() {
      this.stationNumber = []
      var param = []
      var Data = this.CreateData('11', 'MES_计划BOM_工位与名称_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.stationNumber.push({
            label: response.data[i].工位号,
            value: response.data[i].工位号
          })
        }
      })
    },
    selectDate() {
      this.tableData = []
      var param = []
      param[0] = ['开始日期', this.dateTime[0]]
      param[1] = ['结束日期', this.dateTime[1]]
      param[2] = ['工位号', this.stationNumberValue]
      param[3] = ['产品编号', this.vin]
      param[4] = ['PageCurrent', this.pageCurrent]
      param[5] = ['PageSize', this.pageSize]
      param[6] = ['PageCount', '1111', 'int', '1']
      param[7] = ['ItemCount', '1111', 'int', '1']
      var Data = this.CreateData('11', 'CATL_工位在线返修_记录_查询_分页', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.result.length !== 0) {
          this.tableData = response.data.result
        } else {
          this.$message.error('暂无数据')
        }
        this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    exportExcel() {
      if (this.tableData.length !== 0) {
        var param = []
        param[0] = ['testBeginTime', this.dateTime[0] + ' 00:00:00']
        param[1] = ['testEndTime', this.dateTime[1] + ' 23:59:59']
        param[2] = ['vin', this.vin]
        var Data = this.CreateData('2001', 'CATL_充电数据_查询_导出', param)
        this.exportExcel_NPOI(Data)
      } else {
        this.$message.warning('暂无数据')
      }
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.selectDate()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.selectDate()
    }
  }
}
</script>

<style scoped>
.topCard{
  margin: 5px;
}
.topDiv{
  margin-bottom: 10px;
}
</style>
