<template>
  <div class="app-container mes-admin-page">
    <el-card class="topCard">
      <div class="topDiv queryToolbar">
        <!--<div>-->
        <!--  <span style="margin-left: 10px">制造编号：</span>-->
        <!--  <el-input v-model="workCode" placeholder="制造编号" clearable size="small" style="width: 150px; margin-left: 5px"/>-->
        <!--  <span style="margin-left: 10px">项目名称：</span>-->
        <!--  <el-input v-model="projectName" placeholder="项目名称" clearable size="small" style="width: 150px; margin-left: 5px"/>-->
        <!--  <span style="margin-left: 10px">间隔号：</span>-->
        <!--  <el-input v-model="splitCode" placeholder="制造编号" clearable size="small" style="width: 150px; margin-left: 5px"/>-->
        <!--  <span style="margin-left: 10px">DS/ES编号：</span>-->
        <!--  <el-input v-model="unitCode" placeholder="DS/ES编号" clearable size="small" style="width: 150px; margin-left: 5px"/>-->
        <!--</div>-->
        <div style="margin-top: 10px">
          <span style="margin-left: 10px">{{ $t('inquiryTransitInformation.stationNumberLabel') }}</span>
          <el-select
            v-model="stationNumberValue"
            clearable
            filterable
            :placeholder="$t('inquiryTransitInformation.stationNumber')"
            size="small"
            style="width: 250px">
            <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"-->
          <!--            clearable-->
          <!--            filterable-->
          <!--            placeholder="请选择工位号"-->
          <!--            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-input v-model="assemblyNumberValue" placeholder="产品编号" clearable size="small" style="width: 200px; margin-left: 5px"/>-->
          <!--          <el-select v-model="assemblyNumberValue" placeholder="请选择总成编号" allow-create filterable clearable size="small" style="width: 240px; margin-left: 13px">-->
          <!--            <el-option-->
          <!--              v-for="item in assemblyNumber"-->
          <!--              :key="item.ID"-->
          <!--              :label="item.label"-->
          <!--              :value="item.value"-->
          <!--              size="mini"/>-->
          <!--          </el-select>-->
          <span style="margin-left: 10px">{{ $t('inquiryTransitInformation.orderNumberLabel') }}</span>
          <el-input v-model="orderNumberValue" :placeholder="$t('inquiryTransitInformation.orderNumber')" clearable size="small" style="width: 150px; margin-left: 5px"/>
          <span style="margin-left: 10px">{{ $t('inquiryTransitInformation.productModelLabel') }}</span>
          <el-select v-model="engineTypeValue" :placeholder="$t('inquiryTransitInformation.selectProductModel')" filterable clearable size="small" style="width: 150px">
            <el-option
              v-for="item in engineType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
              size="mini"/>
          </el-select>

          <!--          <el-select-->
          <!--            v-model="orderNumberValue"-->
          <!--            clearable-->
          <!--            filterable-->
          <!--            placeholder="请选择订单"-->
          <!--            size="small"-->
          <!--            style="width: 200px"-->
          <!--            @change="getAssemblyNumber()">-->
          <!--            <el-option-->
          <!--              v-for="item in orderNumber"-->
          <!--              :key="item.value"-->
          <!--              :label="item.label"-->
          <!--              :value="item.value"-->
          <!--              size="mini"/>-->
          <!--          </el-select>-->
          <span style="margin-left: 10px">{{ $t('inquiryTransitInformation.productionTimeLabel') }}</span>
          <el-date-picker
            v-model="dateTime"
            :clearable="false"
            align="center"
            :end-placeholder="$t('inquiryTransitInformation.endDate')"
            format="yyyy-MM-dd"
            :range-separator="$t('inquiryTransitInformation.dateRangeSeparator')"
            size="small"
            :start-placeholder="$t('inquiryTransitInformation.startDate')"
            style="width: 240px;"
            type="daterange"
            value-format="yyyy-MM-dd"/>
          <el-button
            icon="el-icon-search"
            plain
            size="small"
            style="margin-left: 5px"
            type="primary"
            @click="selectDate()">{{ $t('inquiryTransitInformation.search') }}
          </el-button>
          <el-button icon="el-icon-download" size="small" type="info" @click="exportExcel()">Excel</el-button>
        </div>

        <div class="tablePanel">
          <el-table
            v-loading="loading"
            ref="multipleTable"
            :cell-class-name="tableRowClassName"
            :data="tableData"
            :header-cell-style="{background:'#eef1f6',color:'#606266'}"
            border
            class="main transitTable"
            element-loading-background="rgba(0, 0, 0, 0.2)"
            element-loading-spinner="el-icon-loading"
            :element-loading-text="$t('inquiryTransitInformation.loadingData')"
            height="600px"
            size="mini"
            style="width: 100%"
            tooltip-effect="dark">
            <!--        <el-table-column :selectable="selectable" type="selection" width="45" align="center"/>-->
            <el-table-column align="center" :label="$t('inquiryTransitInformation.sequence')" type="index" width="60"/>
            <el-table-column align="center" :label="$t('inquiryTransitInformation.stationNumber')" width="120">
              <template slot-scope="scope">
                {{ scope.row.工位号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" :label="$t('inquiryTransitInformation.orderNumber')" width="120">
              <template slot-scope="scope">
                {{ scope.row.订单号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" :label="$t('inquiryTransitInformation.productNumber')">
              <template slot-scope="scope">
                {{ scope.row.发动机号 }}
              </template>
            </el-table-column>
            <el-table-column align="center" :label="$t('inquiryTransitInformation.productModel')" width="120">
              <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="项目名称">-->
            <!--  <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="DS/ES编号">-->
            <!--  <template slot-scope="scope">-->
            <!--    {{ scope.row.单元号 }}-->
            <!--  </template>-->
            <!--</el-table-column>-->
            <el-table-column align="center" :label="$t('inquiryTransitInformation.arrivalTime')" width="150">
              <template slot-scope="scope">
                {{ scope.row.到达时间 }}
              </template>
            </el-table-column>
            <el-table-column align="center" :label="$t('inquiryTransitInformation.departureTime')" width="150">
              <template slot-scope="scope">
                {{ scope.row.离开时间 }}
              </template>
            </el-table-column>
            <el-table-column align="center" :label="$t('inquiryTransitInformation.onlineTimeSeconds')" width="100">
              <template slot-scope="scope">
                {{ scope.row.在线时间 }}
              </template>
            </el-table-column>
            <el-table-column align="center" :label="$t('inquiryTransitInformation.isQualified')" width="80px">
              <template slot-scope="scope">
                {{ scope.row.是否合格 }}
              </template>
            </el-table-column>
  <!--          <el-table-column align="center" label="是否报工" width="80px">-->
  <!--            <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>
        </div>
        <div class="block paginationWrap">
          <el-pagination
            v-if="!loading"
            :current-page="pageCurrent"
            :page-size="pageSize"
            :page-sizes="[15, 30, 40]"
            :total="total"
            layout="total, sizes, prev, pager, next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"/>
        </div>
      </div>
    </el-card>
  </div>
</template>

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

export default {
  data() {
    return {
      traceabilityCodeArr: [], // 精确追溯码数组
      traceabilityCode: '', // 精确追溯码
      assemblyNumber: [], // 总成编号
      assemblyNumberValue: '', // 总成编号
      orderNumberValue: '', // 订单号
      orderNumber: [], // 订单号
      stationNumberValue: '', // 工位号
      stationNumber: [], // 工位号
      stationNumberValueN: '', // 工位号N
      stationNumberN: [], // 工位号N
      measuringPosition: [], // 测量位置
      measuringPositionValue: '', // 测量位置
      measuringProject: [], // 测量项目
      measuringProjectValue: '', // 测量项目
      engineTypeValue: '', // 机型
      engineType: [], // 机型
      batchBarcode: [], // 批次条码
      batchBarcodeValue: '', // 批次条码
      workCode: '', // 制造编号
      projectName: '', // 项目名称
      splitCode: '', // 间隔号
      unitCode: '', // 单元号
      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 = [getNowShotTime(), getNowShotTime()]
    this.getStationNumber()
    this.getEngineType()
    this.getStationNumberN()
  },
  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].工位号}】${response.data[i].工位名称}`,
            value: response.data[i].工位号
          })
        }
      })
    },
    // 初始化获取产品型号
    getEngineType() {
      this.engineType = []
      var param = []
      var Data = this.CreateData('11', 'MES_基本变量_机型代码_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.length) this.engineTypeValue = response.data[0].发动机机型标志
        for (let i = 0; i < response.data.length; i++) {
          this.engineType.push({
            label: response.data[i].发动机型号 + '-' + 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 orderNumberValue_check, stationNumberValue_check, stationNumberValueN_check, assemblyNumberValue_check,
        workCodeValue_check, projectNameValue_check, splitCodeValue_check, unitCodeValue_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 = '')
      this.workCode ? workCodeValue_check = 1 : (workCodeValue_check = 0, this.workCode = '')
      this.projectName ? projectNameValue_check = 1 : (projectNameValue_check = 0, this.projectName = '')
      this.splitCode ? splitCodeValue_check = 1 : (splitCodeValue_check = 0, this.splitCode = '')
      this.unitCode ? unitCodeValue_check = 1 : (unitCodeValue_check = 0, this.unitCode = '')
      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] = ['发动机号_ischeck', assemblyNumberValue_check]
      param[5] = ['发动机号', this.assemblyNumberValue]
      param[6] = ['工位号_ischeck', stationNumberValue_check]
      param[7] = ['工位号', this.stationNumberValue]
      param[8] = ['订单号_ischeck', orderNumberValue_check]
      param[9] = ['订单号', this.orderNumberValue]
      param[10] = ['制造编号', this.workCode]
      param[11] = ['制造编号_ischeck', workCodeValue_check]
      param[12] = ['项目名称', this.projectName]
      param[13] = ['项目名称_ischeck', projectNameValue_check]
      param[14] = ['间隔号', this.splitCode]
      param[15] = ['间隔号_ischeck', splitCodeValue_check]
      param[16] = ['单元号', this.unitCode]
      param[17] = ['单元号_ischeck', unitCodeValue_check]
      param[18] = ['PageCurrent', this.pageCurrent]
      param[19] = ['PageSize', this.pageSize]
      param[20] = ['PageCount', '1111', 'int', '1']
      param[21] = ['ItemCount', '1111', 'int', '1']
      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(this.$t('inquiryTransitInformation.noData'))
      }
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.selectDate()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.selectDate()
    }
  }
}
</script>

<style scoped>
.topCard {
  margin: 5px;
}

::v-deep .topCard > .el-card__body {
  display: block !important;
  width: 100%;
}

.topDiv {
  //margin-bottom: 10px;
}

.queryToolbar {
  //align-items: flex-end;
}

.contentStack {
  display: block;
  width: 100%;
  clear: both;
}

.tablePanel {
  display: block;
  width: 100%;
  padding-top: 4px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.5) 0%, rgba(243,247,251,0.94) 100%);
  overflow-x: auto;
}

.transitTable {
  width: 100% !important;
  max-width: 100%;
}

.paginationWrap {
  display: block;
  width: 100%;
}

::v-deep .queryToolbar .el-button {
  margin-bottom: 2px;
}
</style>
