<template>
  <div class="app-container">
    <el-card>
      <span style="margin: 5px">领料单编号</span>
      <el-input v-model="pickingListNumber" clearable size="small" style="width:200px" />
      <el-button size="small" type="success" icon="el-icon-search" style="margin: 0 0 0 10px" @click="searchListinfor()">查询</el-button>
      <el-table
        v-loading="listLoading"
        :data="tableData1"
        border
        style="width: 100%;"
        height="200">
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50"/>
        <el-table-column label="领料单编号" align="center" min-width="200">
          <template slot-scope="scope">
            {{ scope.row.领料单编号 }}
          </template>
        </el-table-column>
        <el-table-column label="领料时间" align="center" min-width="200">
          <template slot-scope="scope">
            {{ scope.row.领料时间 }}
          </template>
        </el-table-column>
        <el-table-column label="领料人" align="center" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.姓名 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" min-width="200px">
          <template slot-scope="scope" align="center">
            <el-button size="small" type="primary" icon="el-icon-edit" style="margin: 0 0 0 10px" @click="chooseListinfor(scope.row)">选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-table
        v-loading="listLoading1"
        :data="tableDataPicking"
        border
        style="width: 100%;"
        height="200">
        <el-table-column
          label="序号"
          align="center"
          type="index"
          width="50"/>
        <el-table-column label="项目名称" align="center" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column label="机床图号" align="center" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" align="center" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="领用数量" align="center" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="货位" align="center" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.货位流水号 }}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.备注 }}
          </template>
        </el-table-column>
        <el-table-column label="零件类型" align="center" min-width="130">
          <template slot-scope="scope">
            {{ scope.row.类型名称 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" min-width="80">
          <template slot-scope="scope">
            <el-button :disabled="scope.row.是否出库" size="small" type="primary" icon="el-icon-back" style="margin: 0 0 0 0px" @click="partOut(scope.row)">出库</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { searchList, searchListDetail, PurchasePart, BasicPart, WorkShopPart, ListDetailOut } from '@/api/Inventory/PartOut'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      ProjectValue: ' ',
      Project: [],
      ProjectValue_check: 1,
      MachineValue: ' ',
      Machine: [],
      MachineValue_check: 1,
      GroupNumValue: ' ',
      GroupNumValue_check: 1,
      GroupNum: [],
      tableDataBasic: [],
      tableDataPurchase: [],
      tableData1: [],
      tableDataPicking: [], // 领料单明细表格
      listNumber: '',
      pickingListNumber: null, // 领料单编号
      pickingListNumber_check: 1,
      pickingListNumberx: '', // 领料单流水号
      picikingPeople: '', // 领料人流水号
      partProjectNumber: '', // 项目流水号
      partProjectName: '', // 项目名称
      partMachineNumber: '', // 机床流水号
      partMachineName: '', // 机床名称
      partGroupNumber: '', // 分组流水号
      partGroupName: '', // 分组名称
      OutNumber: '', // 出库数量
      outNote: '', // 出库备注
      getpicikingPeople: '', // 领料人
      listLoading: '',
      listLoading1: ''
    }
  },
  computed: {
    ...mapGetters([
      'id'
    ])
  },
  created() {
    this.getpeopleid()
  },
  methods: {
    // 获取人员编号
    getpeopleid() {
      this.picikingPeople = this.id
      console.log(this.picikingPeople)
    },
    // 查询领料单
    searchListinfor() {
      if (this.pickingListNumber === null) {
        this.pickingListNumber_check = 0
      }
      this.listLoading = true
      searchList(this.pickingListNumber_check, this.pickingListNumber).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          response.data[i].领料时间 = response.data[i].领料时间.substring(0, response.data[i].领料时间.length - 8)
        }
        this.tableData1 = response.data
        this.listLoading = false
      })
    },
    // 查询领料单明细
    searchListDetailt() {
      this.listLoading1 = true
      searchListDetail(this.pickingListNumberx).then(response => {
        const data = response.data
        for (let i = 0; i < data.length; i++) {
          data[i].是否出库 === '1' ? data[i].是否禁用 = true : data[i].是否禁用 = false
        }
        this.tableDataPicking = data
        this.listLoading1 = false
      })
    },
    // 选择领料单
    chooseListinfor(row) {
      this.pickingListNumberx = row.领料单流水号
      this.getpicikingPeople = row.领料人流水号
      console.log(this.pickingListNumberx)
      this.searchListDetailt()
    },
    // 出库
    partOut(row) {
      console.log(row)
      if (row.车间外购 === 1) {
        WorkShopPart(row.采购合同明细流水号, this.getpicikingPeople, row.出库数量, row.货位流水号, row.备注).then(response => {
          if (response.data[0].result === '1') {
            ListDetailOut(row.领料单明细流水号)
            this.$message.success('出库成功')
          } else { this.$message.error('出库失败') }
        })
      } else if (row.零件类型 === 1 || row.零件类型 === 2) {
        PurchasePart(row.组件零件流水号, this.getpicikingPeople, row.出库数量, row.货位流水号, row.备注).then(response => {
          if (response.data[0].result === '1') {
            ListDetailOut(row.领料单明细流水号)
            this.$message.success('出库成功')
          } else { this.$message.error('出库失败') }
        })
      } else {
        BasicPart(row.工艺计划流水号, row.出库数量, row.收件信息ID, row.备注).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('出库成功')
            ListDetailOut(row.领料单明细流水号)
          } else { this.$message.error('增加失败') }
        })
      }
      this.searchListDetailt()
    }
  }
}
</script>

<style scoped>

</style>
