<template>
  <div class="app-container">
    <el-card>
      <el-row>
        <span>机床编号:</span>
        <el-select v-model="machineNumberValue" filterable placeholder="机床编号" size="small" style="margin: 3px 0;width: 130px" 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 style="margin-left: 10px">组号:</span>
        <el-select v-model="groupNumberValue" filterable placeholder="组号" size="small" style="width: 130px" clearable>
          <el-option
            v-for="item in groupNumber"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <span style="margin-left: 10px">零件图号:</span>
        <el-input v-model="PartDrawingNumber" filterable placeholder="零件图号" style="width: 130px" size="small" clearable/>
        <span class="demonstration" style="margin-left: 10px">时间区间:</span>
        <el-date-picker
          v-model="startTime"
          value-format="yyyy-MM-dd"
          size="small"
          style="width: 130px"
          type="date"
          placeholder="选择日期"/>
        <span class="demonstration">~</span>
        <el-date-picker
          v-model="endTime"
          value-format="yyyy-MM-dd"
          size="small"
          style="width: 130px"
          type="date"
          placeholder="选择日期"/>
        <el-tooltip :open-delay="1200" effect="dark" content="查询备料出库记录" placement="top">
          <el-button type="success" size="small" icon="el-icon-search" style="margin-left: 15px" @click="total=0;pageSize=20; pageCurrent=1;selecttable()">查询</el-button>
        </el-tooltip>
      </el-row>
    </el-card>
    <el-card>
      <el-table :data="tableData1" border stripe size="mini" highlight-current-row style="width: 100%;margin-top: 3px" height="550px">
        <el-table-column label="项目名称" prop="项目名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column label="机床图号" prop="机床图号" align="center">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" prop="零件图号" align="center">
          <template slot-scope="scope">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" prop="零件名称" align="center">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="出库时间" prop="出库时间" 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 } from '@/api/Assembly/SparePartsOutStockRecord'
// import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      PartDrawingNumber: '',
      startTime: '',
      endTime: '',
      startTime_check: '',
      endTime_check: '',
      machineNumberValue: '',
      machineNumber: [],
      groupNumberValue: '',
      groupNumber: [],
      tableData1: [],
      loading: false,
      total: null, // 总条数
      pageSize: 20, // 每页显示条数
      pageCurrent: 1 // 后台获取页
    }
  },
  created() {

  },
  mounted() {
    this.initProject()
  },
  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].机床流水号
          })
        }
      })
    },
    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.PartDrawingNumber !== '' && this.PartDrawingNumber !== null) { this.check3 = 1 } else { this.check3 = 0 }
      if (this.startTime === '' || this.startTime === null) { this.startTime_check = 0 } else { this.startTime_check = 1 }
      if (this.endTime === '' || this.endTime === null) { this.endTime_check = 0 } else { this.endTime_check = 1 }
      selecttable(this.check1, this.machineNumberValue, this.check2, this.groupNumberValue, this.check3, this.PartDrawingNumber, this.startTime_check, this.startTime, this.endTime_check, this.endTime, 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>
