<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <div>
          <span style="margin-left: 10px">工件编号：</span>
          <el-input v-model="engineId" placeholder="工件编号" clearable size="small" style="width: 150px; margin-left: 5px"/>
          <span style="margin-left: 10px">订货号：</span>
          <el-input v-model="orderCode" placeholder="订货号" clearable size="small" style="width: 150px; margin-left: 5px"/>
          <span style="margin-left: 10px">订货号ID：</span>
          <el-input v-model="orderCodeId" placeholder="订货号ID" clearable size="small" style="width: 150px; margin-left: 5px"/>
          <span style="margin-left: 10px">机型号：</span>
          <el-input v-model="engineType" placeholder="机型号" clearable size="small" style="width: 150px; margin-left: 5px"/>
          <span style="margin-left: 10px">工单ID：</span>
          <el-input v-model="workOrderId" placeholder="工单ID" clearable size="small" style="width: 150px; margin-left: 5px"/>
          <span style="margin-left: 10px">工单号：</span>
          <el-input v-model="workOrderCode" placeholder="工单号" clearable size="small" style="width: 150px; margin-left: 5px"/>
        </div>
        <div>
          <span style="margin-left: 10px">是否合格：</span>
          <el-select v-model="isOk" placeholder="是否合格" clearable size="small" style="width: 100px">
            <el-option label="合格" value="1" size="mini"/>
            <el-option label="不合格" value="2" size="mini"/>
            <el-option label="全部" value="0" size="mini"/>
          </el-select>
          <span style="margin-left: 10px">开始工位号：</span>
          <el-select
            v-model="stationNumberValue"
            placeholder="请选择工位号"
            filterable
            clearable
            size="small"
            style="width: 150px">
            <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-select
            v-model="stationNumberValueN"
            placeholder="请选择工位号"
            filterable
            clearable
            size="small"
            style="width: 150px">
            <el-option
              v-for="item in stationNumberN"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              size="mini"/>
          </el-select>
          <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="结束日期"
            @change="getOrderNumber();getAssemblyNumber()"/>
          <el-button
            type="primary"
            plain
            size="small"
            icon="el-icon-search"
            style="margin-left: 5px"
            @click="selectDate()">查询
          </el-button>
          <el-button type="info" size="small" icon="el-icon-download" @click="exportExcel()">Excel</el-button>
        </div>
        <el-table
          v-loading="loading"
          ref="multipleTable"
          :data="tableData"
          :header-cell-style="{background:'#eef1f6',color:'#606266'}"
          :cell-class-name="tableRowClassName"
          element-loading-text="数据加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
          class="main"
          tooltip-effect="dark"
          height="960px"
          style="width: 100%;max-height: 73vh"
          border
          size="mini">
          <!--        <el-table-column :selectable="selectable" type="selection" width="45" align="center"/>-->
          <el-table-column type="index" width="50" label="序号" align="center"/>
          <el-table-column align="center" label="工位号" width="90">
            <template slot-scope="scope">
              {{ scope.row.指南工位号 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="线体位置" width="80">
            <template slot-scope="scope">
              {{ scope.row.线体类型 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="工位名称" width="130">
            <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" label="机型代码" width="80">
            <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" label="订货号ID" width="80">
            <template slot-scope="scope">
              {{ scope.row.订货号ID }}
            </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" label="工单ID" width="120">
            <template slot-scope="scope">
              {{ scope.row.工单ID }}
            </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" label="到达时间" width="150">
            <template slot-scope="scope">
              {{ scope.row.到达时间 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="离开时间" width="150">
            <template slot-scope="scope">
              {{ scope.row.离开时间 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="在线时间(s)"  width="90">
            <template slot-scope="scope">
              {{ scope.row.在线时间 }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="是否合格" width="80">
            <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>
export default {
  data() {
    return {
      traceabilityCodeArr: [], // 精确追溯码数组
      traceabilityCode: '', // 精确追溯码
      assemblyNumber: [], // 总成编号
      assemblyNumberValue: '', // 总成编号
      orderNumberValue: '', // 订单号
      orderNumber: [], // 订单号
      stationNumberValue: '', // 工位号
      stationNumber: [], // 工位号
      stationNumberValueN: '', // 工位号N
      stationNumberN: [], // 工位号N
      measuringPosition: [], // 测量位置
      measuringPositionValue: '', // 测量位置
      measuringProject: [], // 测量项目
      measuringProjectValue: '', // 测量项目
      engineTypeValue: '', // 机型
      engineType: [], // 机型
      batchBarcode: [], // 批次条码
      batchBarcodeValue: '', // 批次条码
      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 ,// 后台获取页
      engineId:'',  // 工件编号
      orderCode:'', // 订货号
      orderCodeId:'', // 订货号ID
      engineType:'', // 机型号
      workOrderId:'', // 工单ID
      workOrderCode:'', // 工单号
      isOk:'0'
    }
  },
  created() {
    var year, month, day, audiTime
    this.date = new Date() // 修改数据date
    year = new Date().getFullYear()
    month = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1
    day = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
    audiTime = year + '-' + month + '-' + day
    console.log(audiTime, 'audiTime')
    this.dateTime = [audiTime, audiTime]
    this.getStationNumber()
    this.getStationNumberN()
    this.selectDate()
  },
  mounted() {
    this.getOrderNumber()
    this.getAssemblyNumber()
  },
  methods: {
    // 表格颜色变化
    tableRowClassName({row, rowIndex}) {
      // console.log(row, rowIndex)
      if (rowIndex % 2 === 0) {
        return 'black'
      } else {
        return 'red'
      }
    },
    // 工位号
    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].工位号
          })
        }
      })
    },
    // 工位号N
    getStationNumberN() {
      this.stationNumberN = []
      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.stationNumberN.push({
            label: response.data[i].指南工位号,
            value: response.data[i].工位号
          })
        }
      })
    },
    // 订单号
    getOrderNumber() {
      this.orderNumber = []
      var param = []
      param[0] = ['开始时间', this.dateTime[0] + ' ' + '00:00:00']
      param[1] = ['结束时间', this.dateTime[1] + ' ' + '23:59:59']
      // param[0] = ['开始时间', this.dateTime[0]]
      // param[1] = ['结束时间', this.dateTime[1]]
      var Data = this.CreateData('11', '测量数据发动机在线状态_订单号_查询 ', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.orderNumber.push({
            label: response.data[i].订单号,
            value: response.data[i].订单号
          })
        }
      })
    },
    getAssemblyNumber() {
      this.assemblyNumber = []
      var orderNumberValue_check
      this.orderNumberValue ? orderNumberValue_check = 1 : orderNumberValue_check = 0
      var param = []
      param[0] = ['开始时间', this.dateTime[0] + ' ' + '00:00:00']
      param[1] = ['结束时间', this.dateTime[1] + ' ' + '23:59:59']
      // param[0] = ['开始时间', this.dateTime[0]]
      // param[1] = ['结束时间', this.dateTime[1]]
      param[2] = ['订单号_ischeck', orderNumberValue_check]
      param[3] = ['订单号', this.orderNumberValue]
      var Data = this.CreateData('11', '测量数据发动机在线状态_发动机号_查询 ', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.assemblyNumber.push({
            label: response.data[i].发动机号,
            value: response.data[i].发动机号,
            ID: response.data[i].ID
          })
        }
      })
    },
    selectDate() {
      this.tableData = []
      let  stationNumberValue_check, stationNumberValueN_check,engineId_check,orderCode_check,orderCodeId_check,engineType_check,workOrderId_check,workOrderCode_check,isOk_check
      this.stationNumberValue ? stationNumberValue_check = 1 : (stationNumberValue_check = 0, this.stationNumberValue = '')
      this.stationNumberValueN ? stationNumberValueN_check = 1 : (stationNumberValueN_check = 0, this.stationNumberValueN = '')
      this.engineId ? engineId_check = 1 : (engineId_check = 0, this.engineId = '')
      this.orderCode ? orderCode_check = 1 : (orderCode_check = 0, this.orderCode = '')
      this.orderCodeId ? orderCodeId_check = 1 : (orderCodeId_check = 0, this.orderCodeId = '')
      this.engineType ? engineType_check = 1 : (engineType_check = 0, this.engineType = '')
      this.workOrderId ? workOrderId_check = 1 : (workOrderId_check = 0, this.workOrderId = '')
      this.workOrderCode ? workOrderCode_check = 1 : (workOrderCode_check = 0, this.workOrderCode = '')

      var param = []
      param[0] = ['开始时间', this.dateTime[0] + ' ' + '00:00:00']
      param[1] = ['结束时间', this.dateTime[1] + ' ' + '23:59:59']
      param[2] = ['工位号N_ischeck', stationNumberValueN_check]
      param[3] = ['工位号N', this.stationNumberValueN]
      param[4] = ['工位号_ischeck', stationNumberValue_check]
      param[5] = ['工位号', this.stationNumberValue]
      param[6] = ['PageCurrent', this.pageCurrent]
      param[7] = ['PageSize', this.pageSize]
      param[8] = ['PageCount', '1111', 'int', '1']
      param[9] = ['ItemCount', '1111', 'int', '1']
      param[10] = ['工件编号_ischeck', engineId_check]
      param[11] = ['工件编号', this.engineId]
      param[12] = ['订货号_ischeck', orderCode_check]
      param[13] = ['订货号', this.orderCode]
      param[14] = ['订货号ID_ischeck', orderCodeId_check]
      param[15] = ['订货号ID', this.orderCodeId]
      param[16] = ['机型号_ischeck', engineType_check]
      param[17] = ['机型号', this.engineType]
      param[18] = ['工单ID_ischeck', workOrderId_check]
      param[19] = ['工单ID', this.workOrderId]
      param[20] = ['工单号_ischeck', workOrderCode_check]
      param[21] = ['工单号', this.workOrderCode]
      param[22] = ['是否合格', this.isOk]
      var Data = this.CreateData('11', '质量数据查询_测量数据发动机在线状态_查询_NEW', param)
      this.ExecDatabase(Data).then(response => {
        console.log(response, 66)
        if (response.data.result.length !== 0) {
          this.tableData = response.data.result
        }
        this.total = parseInt(response.data.output[0].ItemCount)
        this.loading = false
      })
    },
    exportExcel() {
      if (this.tableData.length !== 0) {
        let orderNumberValue_check, stationNumberValue_check, stationNumberValueN_check, assemblyNumberValue_check
        this.assemblyNumberValue ? assemblyNumberValue_check = 1 : (assemblyNumberValue_check = 0, this.assemblyNumberValue = '')
        this.stationNumberValue ? stationNumberValue_check = 1 : (stationNumberValue_check = 0, this.stationNumberValue = '')
        this.stationNumberValueN ? stationNumberValueN_check = 1 : (stationNumberValueN_check = 0, this.stationNumberValueN = '')
        this.orderNumberValue ? orderNumberValue_check = 1 : (orderNumberValue_check = 0, this.orderNumberValue = '')
        var param = []
        param[0] = ['开始时间', this.dateTime[0] + ' ' + '00:00:00']
        param[1] = ['结束时间', this.dateTime[1] + ' ' + '23:59:59']
        // param[0] = ['开始时间', this.dateTime[0]]
        // param[1] = ['结束时间', this.dateTime[1]]
        param[2] = ['工位号N_ischeck', stationNumberValueN_check]
        param[3] = ['工位号N', this.stationNumberValueN]
        param[4] = ['发动机号_check', assemblyNumberValue_check]
        param[5] = ['发动机号', this.assemblyNumberValue]
        param[6] = ['工位号_check', stationNumberValue_check]
        param[7] = ['工位号', this.stationNumberValue]
        param[8] = ['订单号_ischeck', orderNumberValue_check]
        param[9] = ['订单号', this.orderNumberValue]
        var Data = this.CreateData('2001', '质量数据查询_测量数据发动机在线状态_报表_NEW新', 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>
