<template>
  <div>
    <div style="width: 1900px;overflow:auto">
      <div style="white-space: nowrap">
        <el-card>
          <el-row>
            <el-select v-model="machineNameValue" placeholder="机床图号" style="width: 150px" size="small" filterable clearable @change="machineChange">
              <el-option
                v-for="item in machineName"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-input v-model="partName" placeholder="零件图号" size="small" clearable style="width:150px"/>
            <el-date-picker
              v-model="outTime"
              type="daterange"
              size="small"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              range-separator="~"
              style="width:240px;margin-left: 10px"
              start-placeholder="开始日期"
              end-placeholder="结束日期"/>
            <el-button type="primary" icon="el-icon-search" size="small" plain style="margin-left: 10px" @click="total=0;pageSize = 20;pageCurrent = 1;searchTable()">查询</el-button>
            <el-tooltip :open-delay="1200" effect="dark" content="只查询加急的零件" placement="top">
              <el-checkbox v-model="all" size="small">加急</el-checkbox>
            </el-tooltip>
            <el-button type="success" icon="el-icon-download" size="small" plain style="margin-left: 10px" @click="exportTable()">导出</el-button>
          </el-row>
        </el-card>
      </div>
    </div>
    <el-card>
      <el-table
        v-loading="loading"
        :data="tableData"
        :row-class-name="tableRowClassName"
        height="570"
        style="width: 960px; margin: 3px 0"
        size="mini"
        border
        highlight-current-row
        element-loading-text="拼命加载中">
        <el-table-column label="机床图号" prop="机床图号" align="center" width="140px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" prop="零件图号" align="center" width="173px" show-overflow-tooltip>
          <!--<el-table-column label="零件图号" prop="零件图号" align="center" width="180" show-overflow-tooltip>-->
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" align="center" width="129" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="规格" align="center" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.规格 }}
          </template>
        </el-table-column>
        <el-table-column label="计划投产" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.投产总数量 }}
          </template>
        </el-table-column>
        <el-table-column label="投产批数" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.最大投产批次 }}
          </template>
        </el-table-column>
        <el-table-column label="批次" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.投产批次 }}
          </template>
        </el-table-column>
        <el-table-column label="投产" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.批次数量 }}
          </template>
        </el-table-column>
        <el-table-column label="投产时间" align="center" width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.投产时间 | formatTime }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          v-if="!loading"
          :current-page="pageCurrent"
          :page-sizes="[10, 20, 30, 40, 100]"
          :page-size="pageSize"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import { searchMachine, searchtable } from '@/api/ManufacturingCenter/ProductionPlanQuery'
export default {
  data() {
    return {
      machineNameValue: '', // 机床图号
      machineName: [],
      partName: '',
      all: false,
      loading: false,
      Data: [],
      tableData: [], // 表格数据
      total: 0, // 总条数
      pageSize: 30, // 每页显示条数
      pageCurrent: 1, // 后台获取页
      outTime: '',
      order: ''
    }
  },
  created() {
    this.projectChange()
  },
  methods: {
    projectChange() {
      this.machineName = []
      this.machineNameValue = ''
      this.GroupNum = []
      this.GroupNumValue = ''
      searchMachine().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machineName.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    machineChange() {
      this.searchTable()
    },
    exportTable() {
      let check7, check8
      if (this.partName !== '' && this.partName !== null) {
        this.partNamecheck = true
      } else {
        this.partNamecheck = false
      }
      this.outTime ? check7 = 1 : (check7 = 0, this.outTime = '')
      this.all === false ? check8 = 0 : check8 = 1
      var param = []
      param[0] = ['机床流水号', this.machineNameValue]
      param[1] = ['零件图号_check', this.partNamecheck]
      param[2] = ['零件图号', this.partName]
      param[3] = ['投产时间_check', check7]
      if (check7 === 0) {
        param[4] = ['开始时间', '']
        param[5] = ['结束时间', '']
      } else {
        param[4] = ['开始时间', this.outTime[0]]
        param[5] = ['结束时间', this.outTime[1]]
      }
      param[6] = ['加急_check', check8]
      var Data = this.CreateData('2001', '报表_生产计划查询', param)
      this.exportExcel_NPOI(Data)
    },
    // 查询表格数据
    searchTable() {
      if (this.machineNameValue || this.partName || this.outTime) {
        this.loading = true
        let check
        this.machineNameValue ? check = 1 : check = 0
        if (this.partName !== '' && this.partName !== null) {
          this.partNamecheck = true
        } else {
          this.partNamecheck = false
        }
        let check7, check8
        this.outTime ? check7 = 1 : (check7 = 0, this.outTime = '')
        this.all === false ? check8 = 0 : check8 = 1
        searchtable(check, this.machineNameValue, this.partNamecheck, this.partName, check7, this.outTime[0], this.outTime[1], check8, this.pageCurrent, this.pageSize).then(response => {
          this.tableData = response.data.rows
          this.total = response.data.total
          this.loading = false
        })
      } else {
        this.$message.warning('请输入筛选条件')
      }
    },
    tableRowClassName({ row }) {
      if (row.是否加急 === '1') {
        return 'UrgentItem'
      }
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchTable()
    }
  }
}

</script>

<style>
  .el-table .UrgentItem{
    background: #FF9797;
  }
</style>

