<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <div>
          <span style="margin-left: 10px">工位号：</span>
          <el-select v-model="stationNumberValue" clearable filterable placeholder="请选择工位号" size="small"
            style="width: 160px">
            <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="orderNumberValue" clearable placeholder="工单号" size="small" style="width: 160px;" />
          <span style="margin-left: 10px">产品编号：</span>
          <el-input v-model="productNumberValue" clearable placeholder="产品编号" size="small" style="width: 160px;" />
          <span style="margin-left: 10px">产品型号：</span>
          <el-input v-model="productTypeValue" clearable placeholder="产品型号" size="small" style="width: 160px;" />
        </div>
        <div style="margin-top: 10px">
          <span style="margin-left: 10px">物料类型编码：</span>
          <el-input v-model="materialTypeCodeValue" clearable placeholder="物料类型编码" size="small" style="width: 160px;" />
          <span style="margin-left: 10px">物料名称：</span>
          <el-input v-model="materialNameValue" clearable placeholder="物料名称" size="small" style="width: 160px;" />
          <span style="margin-left: 10px">码值：</span>
          <el-input v-model="codeValue" clearable placeholder="码值" size="small" style="width: 200px;" />
          <span style="margin-left: 10px">操作时间：</span>
          <el-date-picker v-model="dateTime" :clearable="false" align="center" end-placeholder="结束日期"
            format="yyyy-MM-dd" range-separator="～" size="small" start-placeholder="开始日期" style="width: 240px;"
            type="daterange" value-format="yyyy-MM-dd" />
        </div>
        <div style="margin-top: 10px">
          <span style="margin-left: 10px">采购订单号：</span>
          <el-input v-model="purchaseOrderNoValue" clearable placeholder="采购订单号" size="small" style="width: 160px;" />
          <span style="margin-left: 10px">采购行号：</span>
          <el-input v-model="purchaseLineNoValue" clearable placeholder="采购行号" size="small" style="width: 100px;" />
          <span style="margin-left: 10px">物料代码：</span>
          <el-input v-model="materialCodeValue" clearable placeholder="物料代码" size="small" style="width: 160px;" />
          <span style="margin-left: 10px">物料批次号：</span>
          <el-input v-model="materialBatchNoValue" clearable placeholder="物料批次号" size="small" style="width: 130px;" />
          <span style="margin-left: 10px">物料流水号：</span>
          <el-input v-model="materialSerialNoValue" clearable placeholder="物料流水号" size="small" style="width: 130px;" />
          <span style="margin-left: 10px">图号：</span>
          <el-input v-model="drawingNoValue" clearable placeholder="图号" size="small" style="width: 160px;" />
          <el-button icon="el-icon-search" plain size="small" style="margin-left: 10px" type="primary"
            @click="pageCurrent = 1; pageSize = 30; selectDate()">查询
          </el-button>
        </div>
        <el-table v-loading="loading" ref="multipleTable" :cell-class-name="tableRowClassName" :data="tableData"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }" border class="main"
          element-loading-background="rgba(0, 0, 0, 0.2)" element-loading-spinner="el-icon-loading"
          element-loading-text="数据加载中" height="620px" size="mini" style="width: 100%; margin-top: 10px"
          tooltip-effect="dark">
          <el-table-column align="center" label="序号" type="index" width="55" />
          <el-table-column align="center" label="工位号" prop="工位号" width="85px" />
          <el-table-column align="center" label="工单号" prop="工单号" min-width="185px" show-overflow-tooltip />
          <el-table-column align="center" label="产品编号" prop="产品编号" min-width="185px" show-overflow-tooltip />
          <el-table-column align="center" label="产品型号" prop="产品型号" width="170px" show-overflow-tooltip />
          <el-table-column align="center" label="物料类型编号" prop="物料类型编号" width="105px" />
          <el-table-column align="center" label="物料名称" prop="物料名称" min-width="120px" show-overflow-tooltip />
          <el-table-column align="center" label="采购订单号" prop="采购订单号" min-width="160px" show-overflow-tooltip />
          <el-table-column align="center" label="采购行号" prop="采购行号" width="90px" />
          <el-table-column align="center" label="物料代码" prop="物料代码" min-width="140px" show-overflow-tooltip />
          <el-table-column align="center" label="物料批次号" prop="物料批次号" width="110px" />
          <el-table-column align="center" label="物料流水号" prop="物料流水号" width="110px" />
          <el-table-column align="center" label="图号" prop="图号" min-width="140px" show-overflow-tooltip />
          <el-table-column align="center" label="码值" prop="码值" min-width="220px" show-overflow-tooltip />
          <el-table-column align="center" label="操作时间" prop="操作时间" width="155px" />
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <el-pagination v-if="!loading" :current-page="pageCurrent" :page-size="pageSize" :page-sizes="[15, 30, 50]"
            :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 {
      stationNumberValue: '',
      stationNumber: [],
      orderNumberValue: '',
      productNumberValue: '',
      productTypeValue: '',
      materialTypeCodeValue: '',
      materialNameValue: '',
      codeValue: '',
      purchaseOrderNoValue: '',
      purchaseLineNoValue: '',
      materialCodeValue: '',
      materialBatchNoValue: '',
      materialSerialNoValue: '',
      drawingNoValue: '',
      dateTime: '',
      loading: false,
      tableData: [],
      total: 0,
      pageSize: 30,
      pageCurrent: 1
    }
  },
  created() {
    const date = new Date()
    const year = date.getFullYear()
    const month = String(date.getMonth() + 1).padStart(2, '0')
    const day = String(date.getDate()).padStart(2, '0')
    const today = `${year}-${month}-${day}`
    this.dateTime = [today, today]
    this.getStationNumber()
  },
  methods: {
    tableRowClassName({ rowIndex }) {
      return rowIndex % 2 === 0 ? 'black' : 'red'
    },
    getStationNumber() {
      var param = []
      var Data = this.CreateData('11', 'MES_计划BOM_工位与名称_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.stationNumber = response.data.map(item => ({
          label: item.工位号,
          value: item.工位号
        }))
      }).then(() => {
        this.selectDate()
      })
    },
    selectDate() {
      this.loading = true
      this.tableData = []
      var param = []
      param[0] = ['工位号', this.stationNumberValue || '']
      param[1] = ['工单号', this.orderNumberValue || '']
      param[2] = ['产品编号', this.productNumberValue || '']
      param[3] = ['产品型号', this.productTypeValue || '']
      param[4] = ['物料类型编码', this.materialTypeCodeValue || '']
      param[5] = ['物料名称', this.materialNameValue || '']
      param[6] = ['码值', this.codeValue || '']
      param[7] = ['采购订单号', this.purchaseOrderNoValue || '']
      param[8] = ['采购行号', this.purchaseLineNoValue || '']
      param[9] = ['物料代码', this.materialCodeValue || '']
      param[10] = ['物料批次号', this.materialBatchNoValue || '']
      param[11] = ['物料流水号', this.materialSerialNoValue || '']
      param[12] = ['图号', this.drawingNoValue || '']
      param[13] = ['开始时间', this.dateTime[0] + ' 00:00:00']
      param[14] = ['结束时间', this.dateTime[1] + ' 23:59:59']
      param[15] = ['PageCurrent', this.pageCurrent]
      param[16] = ['PageSize', this.pageSize]
      param[17] = ['PageCount', '0', 'int', '1']
      param[18] = ['ItemCount', '0', 'int', '1']
      var Data = this.CreateData('11', 'XD_物料记录_分页查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.result && response.data.result.length !== 0) {
          this.tableData = response.data.result
        }
        this.total = parseInt(response.data.output[0].ItemCount) || 0
        this.loading = false
      }).catch(() => {
        this.loading = false
        this.$message.error('查询失败')
      })
    },
    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>
