<template>
  <div class="app-container">
    <el-card>
      <span>机床号:</span>
      <el-select v-model="Machine" filterable clearable size="small" style="margin-top:10px;width: 220px" placeholder="机床号" @change="getGroup()">
        <el-option
          v-for="item in Machines"
          :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.value2 }}</div>
        </el-option>
      </el-select>
      <span>组号:</span>
      <el-select v-model="Group" size="small" clearable placeholder="组号" style="margin-top:10px;width: 180px;">
        <el-option
          v-for="item in Groups"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <span>零件图号:</span>
      <el-input v-model="number" placeholder="零件号" clearable size="small" style="width: 180px;"/>
      <el-button type="success" class="el-icon-search" size="small" style="margin: 10px 0 0 10px" @click="getTableData();pageCurrent=1;pageSize=10;total = 0">查询</el-button>
    </el-card>

    <el-card>
      <el-table v-loading="listLoading1" :data="tableData1" class="table" border height="650">
        <el-table-column
          label="序号"
          align="center"
          width="50"
          type="index"/>
        <el-table-column align="center" label="零件名称" width="150px">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="零件图号" width="150px">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="入库数量" width="120px">
          <template slot-scope="scope">
            {{ scope.row.入库数量 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="机床图号" width="120px">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="组号" width="120px">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="仓库名称" width="120px">
          <template slot-scope="scope">
            {{ scope.row.仓库名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="货位名称" width="120px">
          <template slot-scope="scope">
            {{ scope.row.货位名称 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="入库时间">
          <template slot-scope="scope">
            {{ scope.row.入库时间 }}
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          v-if="!listLoading1"
          :current-page="pageCurrent"
          :page-sizes="[10, 20, 30, 40]"
          :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 { getMachines, getGroups, getTable } from '@/api/Inventory/StockInquiry'

export default {
  data() {
    return {
      startTime: '',
      endTime: '',
      startTime_check: 0,
      endTime_check: 0,
      liushuihao: '',
      // value2: null,
      radioList: '0',
      length: 0,
      listLoading1: false,
      tableData1: [],
      project: '',
      projects: [],
      Machine: '',
      Machines: [],
      Group: '',
      Groups: [],
      part: '',
      parts: [{
        value: 0,
        label: '全部零件'
      }, {
        value: 1,
        label: '自家生产'
      }, {
        value: 2,
        label: '外协生产'
      }],
      Speed: '',
      Speeds: [{
        value: 5,
        label: '全部'
      }, {
        value: 1,
        label: '拖期'
      }, {
        value: 2,
        label: '即将拖期'
      }, {
        value: 3,
        label: '如期'
      }, {
        value: 4,
        label: '工序外协'
      }],
      number: '',
      checkbox_project: false,
      checkbox_Machine: false,
      checkbox_Group: false,
      checkbox_part: false,
      checkbox_number: false,
      零件图号: [],
      零件名称: [],
      投产数量: [],
      result: [],
      process: [[]],
      planDate: [[]],
      worker: [[]],
      colorCode: [[]],
      realDate: [[]],
      // waixie: [[]],
      total: 0, // 总条数
      pageSize: 10,
      pageCurrent: 1
    }
  },
  created() {
    this.getMachine()
    this.getTableData()
  },
  methods: {
    getMachine() {
      this.Machine = ''
      this.Machines = []
      this.Group = ''
      this.Groups = []
      getMachines().then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.Machines.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号,
            value2: response.data[i].项目名称
          })
        }
      })
    },
    getGroup() {
      this.Group = ''
      this.Groups = []
      getGroups(this.Machine).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.Groups.push({
            label: response.data[i].组号,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    // 按条件查询
    getTableData() {
      this.listLoading1 = true
      if (this.Machine === '') {
        this.checkbox_Machine = 0
      } else {
        this.checkbox_Machine = 1
      }
      if (this.Group === '') {
        this.checkbox_Group = 0
      } else {
        this.checkbox_Group = 1
      }
      if (this.number === '') {
        this.checkbox_number = 0
      } else {
        this.checkbox_number = 1
      }
      this.tableData1 = []
      getTable(this.checkbox_Machine, this.Machine, this.checkbox_Group, this.Group, this.checkbox_number, this.number, this.pageCurrent, this.pageSize).then(response => {
        if (response.data.total === 0) {
          this.listLoading1 = false
        } else {
          // for (let i = 0; i < response.data.rows.length; i++) {
          //   response.data.rows[i].入库时间 = response.data.rows[i].入库时间.split(' ')[0]
          // }
          this.tableData1 = response.data.rows
          this.total = response.data.total
          this.listLoading1 = false
        }
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.getTableData()
    },
    handleCurrentChange(val) {
      this.pageCurrent = val
      this.getTableData()
    }
  }
}
</script>
<style scoped>
</style>
