<template>
  <div class="app-container">
    <el-card>
      <div slot="header">
        <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 10px;" @click="pageCurrent1=1;pageSize1=10;searchTable1()">查询</el-button>
      </div>
      <el-table v-loading="" :data="tableData1" border style="width: 100%;max-height: 600px;" height="440px" size="mini" @row-click="searchTable2">
        <el-table-column label="序号" align="center" width="80" type="index"/>
        <el-table-column label="外协到货单号" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.外协到货单编号 }}
          </template>
        </el-table-column>
        <el-table-column label="外协厂家" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.外协厂家名称 }}
          </template>
        </el-table-column>
        <el-table-column label="操作日期" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.操作日期 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin: 10px 0;">
        <el-pagination
          :current-page="pageCurrent1"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize1"
          :total="total1"
          style="display:inline-block;width:50%"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"/>
      </div>
      <el-table v-loading="" :data="tableData2" show-summary stripe border style="width: 100%;max-height: 600px;" height="600px" size="mini">
        <el-table-column label="序号" align="center" width="80" type="index"/>
        <el-table-column label="零件名称" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" align="center" min-width="120">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件数量" align="center" min-width="120">
          <template slot-scope="scope">
            {{ scope.row.批次数量 }}
          </template>
        </el-table-column>
        <el-table-column label="检验数量" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.检验数量 || 0 }}
          </template>
        </el-table-column>
        <el-table-column label="不合格数量" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.不合格数量 || 0 }}
          </template>
        </el-table-column>
        <el-table-column label="检验时间" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.检验时间 || '—' }}
          </template>
        </el-table-column>
        <el-table-column label="形位" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.形位 }}
          </template>
        </el-table-column>
        <el-table-column label="尺寸" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.尺寸 }}
          </template>
        </el-table-column>
        <el-table-column label="外观" align="center" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.外观 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin: 10px 0;">
        <el-pagination
          :current-page="pageCurrent2"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize2"
          :total="total2"
          style="display:inline-block;width:50%"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange2"
          @current-change="handleCurrentChange2"/>
      </div>
    </el-card>
  </div>
</template>

<script>
import { searchTable1, searchTable2 } from '@/api/Outsourcing/OutsourcingQCSearch'
export default {
  name: 'OutsourcingQCSearch',
  data() {
    return {
      tableData1: [],
      pageCurrent1: 1,
      pageSize1: 10,
      total1: 0,
      tableData2: [],
      pageCurrent2: 1,
      pageSize2: 10,
      total2: 0
    }
  },
  mounted() {
    this.searchTable1()
  },
  methods: {
    // 查询到货单列表
    searchTable1() {
      searchTable1(this.pageCurrent1, this.pageSize1).then(response => {
        console.log(response.data, 1)
        this.tableData1 = response.data.rows
        this.total1 = response.data.total
      })
    },
    handleSizeChange1(val) {
      this.pageSize1 = val
      this.pageCurrent1 = 1
      this.searchTable1()
    },
    handleCurrentChange1(val) {
      this.pageCurrent1 = val
      this.searchTable1()
    },
    searchTable2(row) {
      console.log(row, 2)
      searchTable2(this.pageCurrent2, this.pageSize2, row.外协到货单流水号).then(response => {
        this.tableData2 = response.data.rows
        this.total2 = response.data.total
      })
    },
    handleSizeChange2(val) {
      this.pageSize2 = val
      this.pageCurrent2 = 1
      this.searchTable2()
    },
    handleCurrentChange2(val) {
      this.pageCurrent2 = val
      this.searchTable2()
    }
  }
}
</script>

<style scoped>

</style>
