<template>
  <div class="app-container">

    <el-card>
      <span>零件号:</span>
      <el-input v-model="partNum" placeholder="零件号" size="small" clearable style="width:200px"/>
      <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 10px;" @click="PageCurrent=1;PageSize=10;searchTable()">查询</el-button>
    </el-card>

    <el-card>
      <el-table v-loading="loading0" :data="tableData" border style="width: 100%;" height="650" stripe>
        <el-table-column label="机床图号" width="180px" align="center">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" width="100px" align="center">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" width="250px" align="center">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" width="100px" align="center">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="数量" width="100px" align="center">
          <template slot-scope="scope">
            {{ scope.row.批次数量 }}
          </template>
        </el-table-column>
        <!--<el-table-column label="已入库数量" width="100px" align="center">-->
        <!--<template slot-scope="scope">-->
        <!--{{ scope.row.入库数量 }}-->
        <!--</template>-->
        <!--</el-table-column>-->

        <el-table-column label="零件状态" align="center" >
          <template slot-scope="scope">
            <el-steps :active="active[scope.$index]" finish-status="success" simple process-status="finish">
              <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
          v-if="!loading0"
          :current-page="PageCurrent"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import { searchOutHelpState } from '@/api/Outsourcing/OutsourcingStatus'
export default {
  data() {
    return {
      loading0: false,
      partNum: '', // 零件图号
      check: '',
      tableData: [],
      active: [],
      PageCurrent: 1,
      PageSize: 10,
      total: 0
    }
  },
  methods: {
    searchTable() {
      this.loading0 = true
      this.total = 0
      this.tableData = []
      this.active = []
      if (this.partNum !== '') {
        this.check = 1
      } else { this.check = 0 }
      searchOutHelpState(this.PageCurrent, this.PageSize, this.check, this.partNum).then(response => {
        if (response.data.rows.length !== 0) {
          this.total = response.data.total
          this.tableData = response.data.rows
          for (let i = 0; i < response.data.rows.length; i++) {
            this.active.push(parseInt(response.data.rows[i].外协零件状态) + 1)
          }
        } else {
          this.loading0 = false
        }
      }).then(() => {
        this.loading0 = false
      })
    },
    handleSizeChange(val) {
      this.PageCurrent = 1
      this.PageSize = val
      this.searchTable()
    },
    handleCurrentChange(val) {
      this.PageCurrent = val
      this.searchTable()
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  span{
    margin: 10px 0 10px 10px;
  }
</style>
