<template>
  <div class="app-container">
    <el-card>
      <el-row>
        <el-select v-model="machineToolValue" placeholder="机床号" size="small" clearable style="width: 150px;margin: 10px 10px 0px 10px" @change="searchGroupList">
          <el-option
            v-for="item in machineTool"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-select v-model="groupNumberValue" placeholder="组号" size="small" clearable style="width: 100px;margin: 10px 10px 0px 10px">
          <el-option
            v-for="item in groupNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-select v-model="partStateValue" placeholder="零件状态" size="small" clearable style="width: 120px;margin: 10px 10px 0px 10px">
          <el-option
            v-for="item in partState"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <el-input v-model="partNumber" placeholder="零件号" size="small" clearable style="width: 150px;margin: 10px 10px 0px 10px"/>
        <el-button type="success" icon="el-icon-search" size="small" style="margin: 15px 0 0 10px" @click="pageCurrent=1;pageSize=20;total=0;searchData()">查询</el-button>
      </el-row>
    </el-card>
    <el-card>
      <el-table v-loading="loading0" :data="tableData" style="width: 100%" height="550" stripe size="mini" border>
        <el-table-column align="center" label="序号" type="index" width="55px"/>
        <el-table-column align="center" label="机床图号" width="110px">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="组号" width="100px">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件图号" min-width="180px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件名称" min-width="110px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="数量" width="50px">
          <template slot-scope="scope">
            {{ scope.row.批次数量 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="投产时间" width="100px">
          <template slot-scope="scope">
            {{ scope.row.传递时间 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件状态" width="650px">
          <template slot-scope="scope">
            <el-steps :active="scope.row.考核状态" finish-status="success" simple>
              <el-step title="投产" />
              <el-step title="工艺" />
              <el-step title="定额" />
              <el-step title="平衡" />
              <el-step title="完成" />
              <el-step title="入库" />
              <el-step title="出库" />
            </el-steps>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="pageCurrent"
          :page-sizes="[10, 20, 30, 40, 50]"
          :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 { intPartState, searchTable, searchmachine, searchgroup } from '@/api/ManufacturingCenter/StatusQuery'
export default {
  data() {
    return {
      loading0: false,
      entryNameValue: '', // 项目流水号
      entryName: [], // 项目数组
      machineToolValue: '', // 机床图号
      machineTool: [],
      groupNumberValue: '', // 组号
      groupNumber: [],
      partNumber: '', // 零件号
      partStateValue: null, // 零件状态
      partStateValue1: null,
      partState: [], // 零件状态数组
      partTypeValue: null, // 零件类型
      num: null,
      pageCurrent: 1,
      pageSize: 20,
      tableData7: [],
      tableData6: [],
      tableData: [],
      state: null,
      total: null,
      title: '',
      List: [],
      partType: [{
        value: 1,
        label: '自家生产'
      }, {
        value: 2,
        label: '外协生产'
      }]
    }
  },
  created() {
    this.fetchData()
    this.searchData()
  },
  methods: {
    fetchData() {
      intPartState().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.partState.push({
            label: response.data[i].考核状态名称,
            value: response.data[i].考核状态
          })
        }
      })
      searchmachine().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machineTool.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    // 查询组号
    searchGroupList() {
      this.groupNumberValue = ''
      this.groupNumber = []
      if (this.machineToolValue) {
        searchgroup(this.machineToolValue).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.groupNumber.push({
              label: response.data[i].组号,
              value: response.data[i].组件流水号
            })
          }
        })
      }
    },
    searchData() {
      var check1, check2, check3, check4, check5
      if (this.machineToolValue) { check1 = 1 } else { check1 = 0 }
      if (this.groupNumberValue) { check2 = 1 } else { check2 = 0 }
      if (this.partNumber) { check3 = 1 } else { check3 = 0 }
      if (this.partStateValue) { check4 = 1 } else { check4 = 0 }
      if (this.partTypeValue) { check5 = 1 } else { check5 = 0 }
      this.loading0 = true
      searchTable(check1, this.machineToolValue, check2, this.groupNumberValue, check3, this.partNumber, check4, this.partStateValue, check5, this.partTypeValue, this.pageCurrent, this.pageSize).then(response => {
        for (let i = 0; i < response.data.rows.length; i++) {
          response.data.rows[i].考核状态 = parseInt(response.data.rows[i].考核状态) - 2
          if (response.data.rows[i].传递时间 !== undefined || response.data.rows[i].hasOwnProperty('传递时间')) {
            response.data.rows[i].传递时间 = response.data.rows[i].传递时间.split(' ', 2)[0]
          }
        }
        this.loading0 = false
        this.total = response.data.total
        this.tableData = response.data.rows
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.searchData()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.searchData()
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  .el-date-editor{
    width:150px
  }
  span{
    margin: 10px 0 10px 10px;
  }
  .el-card{
    margin: 0px;
  }
  .el-steps--simple {
     padding: 0;
  }
</style>
