<template>
  <div class="app-container">
    <el-card>
      <el-row>
        <span>机床编号:</span>
        <el-select v-model="machineNumberValue" filterable placeholder="机床编号" size="small" clearable @change="machineChange()">
          <el-option
            v-for="item in machineNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value">
            <div style="float: left">{{ item.label }}</div>
            <div style="float: right; color: #8492a6; font-size: 13px">{{ item.name }}</div>
          </el-option>
        </el-select>
        <span>组号:</span>
        <el-select v-model="groupNumberValue" filterable placeholder="组号" size="small" clearable>
          <el-option
            v-for="item in groupNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span>质检类型:</span>
        <el-select v-model="QualityTypeValue" filterable placeholder="质检类型" size="small" clearable>
          <el-option
            v-for="item in QualityTypeNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span>零件:</span>
        <el-input v-model="SpareParts" filterable placeholder="请输入零件名称" style="width: 200px" size="small" clearable/>
        <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="selecttable()">查询</el-button>
      </el-row>
    </el-card>
    <el-card>
      <el-table :data="tableData1" border size="mini" highlight-current-row style="width: 100%;margin-top: 15px" height="600px">
        <el-table-column label="项目名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column label="机床图号" align="center">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="机床名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.机床名称 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" align="center">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" align="center">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="质检类型" align="center">
          <template slot-scope="scope">
            {{ scope.row.质检类型 }}
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center">
          <template slot-scope="scope">
            {{ scope.row.数量 }}
          </template>
        </el-table-column>
        <el-table-column label="不合格数量" align="center">
          <template slot-scope="scope">
            {{ scope.row.不合格数量 }}
          </template>
        </el-table-column>
        <el-table-column label="不合格原因" align="center">
          <template slot-scope="scope">
            {{ scope.row.不合格原因 }}
          </template>
        </el-table-column>
        <el-table-column label="处理结果" align="center">
          <template slot-scope="scope">
            {{ scope.row.处理结果 }}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center">
          <template slot-scope="scope">
            {{ scope.row.备注 }}
          </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 { initProject, searchgroup, selecttable, QualityType } from '@/api/Assembly/QualityInspectionInformationInquiry'
// import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      machineNumberValue: '',
      machineNumber: [],
      groupNumberValue: '',
      groupNumber: [],
      QualityTypeNumber: [],
      QualityTypeValue: '',
      tableData1: [],
      SpareParts: '',
      loading: false,
      total: null, // 总条数
      pageSize: 10, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  created() {

  },
  mounted() {
    this.initProject()
    this.QualityType()
  },
  methods: {
    initProject() {
      initProject().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.machineNumber.push({
            label: response.data[i].机床图号,
            name: response.data[i].项目名称,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    QualityType() {
      QualityType().then(response => {
        console.log(response.data)
        for (let i = 0; i < response.data.length; i++) {
          this.QualityTypeNumber.push({
            label: response.data[i].质检类型,
            value: response.data[i].质检类型代码
          })
        }
      })
    },
    machineChange() {
      this.groupNumberValue = ''
      this.groupNumber = []
      searchgroup(this.machineNumberValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.groupNumber.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    selecttable() {
      this.tableData1 = []
      if (this.machineNumberValue !== '' && this.machineNumberValue !== null) { this.check1 = 1 } else { this.check1 = 0 }
      if (this.groupNumberValue !== '' && this.groupNumberValue !== null) { this.check2 = 1 } else { this.check2 = 0 }
      if (this.SpareParts !== '' && this.SpareParts !== null) { this.check3 = 1 } else { this.check3 = 0 }
      if (this.QualityTypeValue !== '' && this.QualityTypeValue !== null) { this.check4 = 1 } else { this.check4 = 0 }
      selecttable(this.check1, this.machineNumberValue, this.check2, this.groupNumberValue, this.check3, this.SpareParts, this.check4, this.QualityTypeValue, this.pageCurrent, this.pageSize).then(response => {
        this.tableData1 = response.data.rows
        this.loading = false
        this.total = response.data.total
      })
    },
    // 分页
    handleSizeChange(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.selecttable()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.selecttable()
    }
  }
}

</script>

<style scoped>

</style>
