<template>
  <div class="app-container">
    <el-card class="topCard">
      <div class="topDiv">
        <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">图号：</span>
          <el-input v-model="drawingCode" placeholder="图号" clearable size="small" style="width: 150px; margin-left: 5px"/> -->
          <span style="margin-left: 10px">质检项描述：</span>
          <el-input v-model="describe" placeholder="质检项描述" clearable size="small" style="width: 200px; margin-left: 5px"/>
        </div>
        <div style="margin-top: 10px">
          <span style="margin-left: 10px">工位号(起)：</span>
          <el-select v-model="stationNumberValue" clearable filterable placeholder="请选择工位号" size="small" style="width: 150px">
            <el-option v-for="item in stationNumber" :key="item.value" :label="item.label" :value="item.value"/>
          </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"/>
          </el-select>
          <!-- <span style="margin-left: 10px">发动机号：</span>
          <el-input v-model="engineNumber" placeholder="发动机号" clearable size="small" style="width: 150px; margin-left: 5px"/> -->
          <!-- <span style="margin-left: 10px">订单号：</span>
          <el-input v-model="orderNumberValue" placeholder="订单号" clearable size="small" style="width: 150px; margin-left: 5px"/> -->
          <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="开始日期"
            type="daterange"
            value-format="yyyy-MM-dd"
            style="width: 240px;"
          />
          <el-button icon="el-icon-search" plain size="small" style="margin-left: 5px" type="primary" @click="selectDate">查询</el-button>
          <el-button icon="el-icon-download" size="small" type="info" @click="exportExcel">Excel</el-button>
        </div>
        <el-table
          v-loading="loading"
          :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="700px"
          size="mini"
          style="width: 100%;max-height: 650px;margin-top: 10px"
          tooltip-effect="dark"
        >
          <el-table-column align="center" label="序号" type="index" width="60"/>
          <el-table-column align="center" label="工位号" prop="工位号" width="80"/>
          <el-table-column align="center" label="工件编号" prop="工件编号" width="100"/>
          <el-table-column align="center" label="制造编号" prop="制造编号" width="100"/>
          <el-table-column align="center" label="装配编号" prop="装配编号" width="140"/>
          <el-table-column align="center" label="装配名称" prop="装配名称" width="130"/>
          <el-table-column align="center" label="质检项分类" prop="质检项分类" width="100"/>
          <!-- <el-table-column align="center" label="质检项编号" prop="质检项编号" width="100"/> -->
          <!-- <el-table-column align="center" label="质检项序号" prop="质检项序号" width="100"/> -->
          <el-table-column align="center" label="质检项描述" prop="质检项描述" width="180"/>
          <el-table-column align="center" label="符合标准及条例" prop="符合标准及条例" width="160"/>
          <el-table-column align="center" label="检验方法" prop="检验方法" width="100"/>
          <el-table-column align="center" label="检验结果" prop="检验结果" min-width="140"/>
          <el-table-column align="center" label="结果类型" prop="结果类型" width="80"/>
          <!-- <el-table-column align="center" label="结果上限" prop="结果上限" width="100"/>
          <el-table-column align="center" label="结果下限" prop="结果下限" width="100"/>
          <el-table-column align="center" label="结果单位" prop="结果单位" width="80"/>
          <el-table-column align="center" label="工步属性" prop="工步属性" width="100"/> -->
          <!-- <el-table-column align="center" label="发动机型号" prop="发动机型号" width="100"/> -->
          <el-table-column align="center" label="记录时间" prop="操作时间" width="160"/>
          <!-- <el-table-column align="center" label="项目名称" prop="项目名称" width="100"/> -->
          <!-- <el-table-column align="center" label="间隔编号" prop="间隔编号" width="100"/>
          <el-table-column align="center" label="间隔图号" prop="间隔图号" width="100"/> -->
          <!-- <el-table-column align="center" label="产品名称" prop="产品名称" width="100"/> -->
          <el-table-column align="center" label="操作者1" prop="操作者1" width="80"/>
          <el-table-column align="center" label="操作者2" prop="操作者2" width="80"/>
          <el-table-column align="center" label="操作" width="120px">
            <template slot-scope="scope">
              <el-button icon="el-icon-edit" size="mini" type="text" @click="handleEdit(scope.row)">结果修改</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block" style="margin-top: 10px;">
          <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>
export default {
  data() {
    return {
      workCode: '',
      projectName: '',
      splitCode: '',
      drawingCode: '',
      describe: '',
      stationNumberValue: '',
      stationNumber: [],
      stationNumberValueN: '',
      stationNumberN: [],
      engineNumber: '',
      orderNumberValue: '',
      dateTime: '',
      loading: false,
      tableData: [],
      total: 0,
      pageSize: 30,
      pageCurrent: 1
    }
  },
  created() {
    var year, month, day, audiTime
    this.date = new 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
    this.dateTime = [audiTime, audiTime]
    this.getStationNumber()
    this.getStationNumberN()
    this.selectDate()
  },
  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].工位号
          })
        }
      })
    },
    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].工位号
          })
        }
      })
    },
    handleEdit(row) {
      this.$prompt('请输入检验结果', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValue: row.检验结果
      }).then(({ value }) => {
        var param = []
        param[0] = ['ID', row.ID]
        param[1] = ['value', value]
        var Data = this.CreateData('12', '电子看板_工序内容_记录表_修改', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.selectDate()
            this.$message.success('修改成功!')
          } else {
            this.$message.error('修改失败!')
          }
        })
      })
    },
    selectDate() {
      this.tableData = []
      // 组装参数
      const engineNumberCheck = this.engineNumber ? 1 : 0
      const stationNumberCheck = this.stationNumberValue ? 1 : 0
      const stationNumberNCheck = this.stationNumberValueN ? 1 : 0
      const orderNumberCheck = this.orderNumberValue ? 1 : 0
      const workCodeCheck = this.workCode ? 1 : 0
      const projectNameCheck = this.projectName ? 1 : 0
      const splitCodeCheck = this.splitCode ? 1 : 0
      const drawingCodeCheck = this.drawingCode ? 1 : 0
      const describeCheck = this.describe ? 1 : 0
      var param = []
      param.push(['开始时间', this.dateTime[0] + ' 00:00:00'])
      param.push(['结束时间', this.dateTime[1] + ' 23:59:59'])
      param.push(['工位号_ischeck', stationNumberCheck])
      param.push(['工位号', this.stationNumberValue])
      param.push(['工位号N_ischeck', stationNumberNCheck])
      param.push(['工位号N', this.stationNumberValueN])
      param.push(['订单号_ischeck', orderNumberCheck])
      param.push(['订单号', this.orderNumberValue])
      param.push(['编号_ischeck', splitCodeCheck])
      param.push(['编号', this.splitCode])
      param.push(['质检项描述_ischeck', describeCheck])
      param.push(['质检项描述', this.describe])
      param.push(['制造编号_ischeck', workCodeCheck])
      param.push(['制造编号', this.workCode])
      param.push(['PageCurrent', this.pageCurrent])
      param.push(['PageSize', this.pageSize])
      param.push(['PageCount', '1111', 'int', '1'])
      param.push(['ItemCount', '1111', 'int', '1'])
      var Data = this.CreateData('11', '电子看板_工序内容_记录表_视图_查询', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data.result && response.data.result.length !== 0) {
          this.tableData = response.data.result
        }
        if (response.data.output && response.data.output.length > 0) {
          this.total = parseInt(response.data.output[0].ItemCount)
        }
        this.loading = false
      })
    },
    exportExcel() {
      if (this.tableData.length !== 0) {
        const engineNumberCheck = this.engineNumber ? 1 : 0
        const stationNumberCheck = this.stationNumberValue ? 1 : 0
        const stationNumberNCheck = this.stationNumberValueN ? 1 : 0
        const orderNumberCheck = this.orderNumberValue ? 1 : 0
        const workCodeCheck = this.workCode ? 1 : 0
        const projectNameCheck = this.projectName ? 1 : 0
        const splitCodeCheck = this.splitCode ? 1 : 0
        const drawingCodeCheck = this.drawingCode ? 1 : 0
        const describeCheck = this.describe ? 1 : 0
        var param = []
        param.push(['开始时间', this.dateTime[0] + ' 00:00:00'])
        param.push(['结束时间', this.dateTime[1] + ' 23:59:59'])
        param.push(['工位号_ischeck', stationNumberCheck])
        param.push(['工位号', this.stationNumberValue])
        param.push(['工位号N_ischeck', stationNumberNCheck])
        param.push(['工位号N', this.stationNumberValueN])
        param.push(['订单号_ischeck', orderNumberCheck])
        param.push(['订单号', this.orderNumberValue])
        param.push(['编号_ischeck', splitCodeCheck])
        param.push(['编号', this.splitCode])
        param.push(['质检项描述_ischeck', describeCheck])
        param.push(['质检项描述', this.describe])
        param.push(['制造编号_ischeck', workCodeCheck])
        param.push(['制造编号', this.workCode])
        param.push(['PageCurrent', 1])
        param.push(['PageSize', 99999])
        param.push(['PageCount', '1111', 'int', '1'])
        param.push(['ItemCount', '1111', 'int', '1'])
        var Data = this.CreateData('2001', '电子看板_工序内容_记录表_视图_查询', 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>
