<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-button size="small" type="primary" icon="el-icon-plus" style="margin: 0 0 0 10px" @click="addListinfor()">创建</el-button>
    </el-card>

    <el-card>
      <el-table v-loading="listLoading0" :data="tableData1" highlight-current-row border style="width: 100%;" size="mini" height="300" @row-click="chooseListinfor">
        <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.领料时间.split(' ')[0] }}
          </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" width="100px">
          <template slot-scope="scope" align="center">
            <el-button size="mini" type="danger" icon="el-icon-delete" style="margin: 0 0 0 10px" @click="dropListinfor(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin: 10px 0;">
        <el-pagination
          :current-page="PageCurrent0"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="PageSize0"
          :total="total0"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange0"
          @current-change="handleCurrentChange0"/>
      </div>
      <el-table :data="tableDataPicking" border style="width: 100%;" size="mini" height="300">
        <el-table-column label="序号" align="center" type="index" width="50"/>
        <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-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="70">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="领用数量" align="center" min-width="70">
          <template slot-scope="scope">
            {{ scope.row.出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="仓库" align="center" min-width="50">
          <template slot-scope="scope">
            {{ scope.row.仓库名称 }}
          </template>
        </el-table-column>
        <el-table-column label="货位" align="center" min-width="50">
          <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" width="100">
          <template slot-scope="scope">
            <el-button :disabled="!!scope.row.是否出库" size="mini" type="danger" icon="el-icon-delete" @click="dropListdetail(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-card>
      <span>项目名称:</span>
      <el-select v-model="ProjectValue" filterable clearable size="small" placeholder="请选择项目名称" style="width: 200px;margin-right:10px" @change="searchMachine()">
        <el-option
          v-for="item in Project"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <span>机床图号:</span>
      <el-select v-model="MachineValue" filterable clearable size="small" placeholder="机床图号" style="width: 200px;margin-right:10px" @change="searchGroupList()">
        <el-option
          v-for="item in Machine"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <span>组号:</span>
      <el-select v-model="GroupNumValue" filterable clearable size="small" placeholder="组号" style="width: 200px">
        <el-option
          v-for="item in GroupNum"
          :key="item.value"
          :label="item.label"
          :value="item.value"/>
      </el-select>
      <el-button size="small" type="success" icon="el-icon-search" style="margin: 0 0 0 10px" @click="searchPartinfo()">查询</el-button>
    </el-card>

    <el-card>
      <h4>自制件</h4>
      <el-table v-loading="listLoading1" :data="tableDataBasic" border style="width: 100%;" size="mini" height="440">
        <el-table-column label="序号" align="center" type="index" width="50"/>
        <el-table-column label="项目名称" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.项目名称 }}
          </template>
        </el-table-column>
        <el-table-column label="机床图号" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" align="center" width="70">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件名称" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.零件名称 }}
          </template>
        </el-table-column>
        <el-table-column label="计划数量" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.批次数量 }}
          </template>
        </el-table-column>
        <el-table-column label="库存数量" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.可出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="待出库数量" align="center" width="90">
          <template slot-scope="scope">
            {{ scope.row.待出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="仓库" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.仓库名称 }}
          </template>
        </el-table-column>
        <el-table-column label="货位" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.货位名称 }}
          </template>
        </el-table-column>
        <el-table-column label="零件图号" align="center" min-width="80">
          <template slot-scope="scope" align="center">
            {{ scope.row.零件图号 }}
          </template>
        </el-table-column>
        <el-table-column label="零件类型" align="center" width="80">
          <template slot-scope="scope" align="center">
            {{ scope.row.零件类型名称 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope" align="center">
            <el-button :disabled="scope.row.是否禁用" size="mini" type="primary" icon="el-icon-edit" style="margin: 0 0 0 10px" @click="addBasicList(scope.row)">领料</el-button>
          </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"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"/>
      </div>
      <hr>
      <h4>采购部采购件</h4>
      <el-table v-loading="listLoading2" :data="tableDataPurchase" border style="width: 100%;" size="mini" height="440">
        <el-table-column label="序号" align="center" type="index" width="50"/>
        <el-table-column label="名称" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.物料名称 }}
          </template>
        </el-table-column>
        <el-table-column label="规格" align="center" min-width="150">
          <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.物料型号 || scope.row.零件图号 || '' }}
          </template>
        </el-table-column>
        <el-table-column label="机床图号" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="采购数量" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.数量 }}
          </template>
        </el-table-column>
        <el-table-column label="仓库名称" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.仓库名称 }}
          </template>
        </el-table-column>
        <el-table-column label="货位名称" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.货位名称 }}
          </template>
        </el-table-column>
        <el-table-column label="货位存量" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.货位存量 }}
          </template>
        </el-table-column>
        <el-table-column label="待出库数量" align="center" width="90">
          <template slot-scope="scope">
            {{ scope.row.待出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="可出库数量" align="center" width="90">
          <template slot-scope="scope">
            {{ scope.row.可出库数量 = scope.row.货位存量 - scope.row.待出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="零件类型" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.类型名称 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope" align="center">
            <el-button :disabled="scope.row.可出库数量===0" size="mini" type="primary" icon="el-icon-edit" @click="addPurchaseList(scope.row)">领料</el-button>
          </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"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"/>
      </div>
      <hr>
      <h4>可领滞货件</h4>
      <el-table v-loading="listLoading3" :data="tableDataBacklog" border style="width: 100%;" size="mini" height="440">
        <el-table-column label="序号" align="center" type="index" width="50"/>
        <el-table-column label="名称" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.物料名称 }}
          </template>
        </el-table-column>
        <el-table-column label="规格" align="center" min-width="150">
          <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.物料型号 || scope.row.零件图号 || '' }}
          </template>
        </el-table-column>
        <el-table-column label="机床图号" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="仓库名称" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.仓库名称 }}
          </template>
        </el-table-column>
        <el-table-column label="货位名称" align="center" width="100">
          <template slot-scope="scope">
            {{ scope.row.货位名称 }}
          </template>
        </el-table-column>
        <el-table-column label="货位存量" align="center" width="120">
          <template slot-scope="scope">
            123123123
            {{ scope.row.数量 }}
          </template>
        </el-table-column>
        <el-table-column label="待出库数量" align="center" width="120">
          <template slot-scope="scope">
            123123123
            {{ scope.row.数量 }}
          </template>
        </el-table-column>
        <el-table-column label="可出库数量" align="center" width="90">
          <template slot-scope="scope">
            {{ scope.row.可出库数量 = scope.row.货位存量 - scope.row.待出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope" align="center">
            <el-button :disabled="scope.row.可出库数量===0" size="mini" type="primary" icon="el-icon-edit" @click="addBacklogList(scope.row)">领料</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin: 10px 0;">
        <el-pagination
          :current-page="PageCurrent3"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="PageSize3"
          :total="total3"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange3"
          @current-change="handleCurrentChange3"/>
      </div>
      <hr>
      <h4>车间采购件</h4>
      <el-table v-loading="listLoading4" :data="tableDataHouse" border size="mini" style="width: 100%;" height="440">
        <el-table-column label="序号" align="center" type="index" width="50"/>
        <el-table-column label="名称" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.物料名称 }}
          </template>
        </el-table-column>
        <el-table-column label="物料规格" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.物料规格 }}
          </template>
        </el-table-column>
        <el-table-column label="物料型号" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.物料型号 }}
          </template>
        </el-table-column>
        <el-table-column label="机床图号" align="center" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.机床图号 }}
          </template>
        </el-table-column>
        <el-table-column label="组号" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.组号 }}
          </template>
        </el-table-column>
        <el-table-column label="采购数量" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.零件数量 }}
          </template>
        </el-table-column>
        <el-table-column label="仓库名称" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.仓库名称 }}
          </template>
        </el-table-column>
        <el-table-column label="货位名称" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.货位名称 }}
          </template>
        </el-table-column>
        <el-table-column label="货位存量" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.货位存量 }}
          </template>
        </el-table-column>
        <el-table-column label="待出库数量" align="center" width="90">
          <template slot-scope="scope">
            {{ scope.row.待出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="可出库数量" align="center" width="90">
          <template slot-scope="scope">
            {{ scope.row.可出库数量 = scope.row.货位存量 - scope.row.待出库数量 }}
          </template>
        </el-table-column>
        <el-table-column label="零件类型" align="center" width="80">
          <template slot-scope="scope">
            {{ scope.row.类型名称 }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope" align="center">
            <el-button :disabled="scope.row.可出库数量===0" size="mini" type="primary" icon="el-icon-edit" @click="addWorkshopList(scope.row)">领料</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin: 10px 0;">
        <el-pagination
          :current-page="PageCurrent4"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="PageSize4"
          :total="total4"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange4"
          @current-change="handleCurrentChange4"/>
      </div>
    </el-card>

    <!--基本件领料对话框-->
    <el-dialog :visible.sync="dialogFormVisible1" title="基本件通用件领料" center width="380px">
      <el-form ref="form1" :model="form1" :rules="rules1" label-position="left">
        <el-form-item label="出库数量" prop="outNumber" label-width="100px" size="small">
          <el-input-number v-model="form1.outNumber" :min="0" :max="enableOut" controls-position="right" style="width: 200px"/>
        </el-form-item>
        <el-form-item label="出库备注" prop="outNote" label-width="100px">
          <el-input v-model="form1.outNote" size="small" placeholder="请输入备注" style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible1=false">取消</el-button>
        <el-button type="primary" @click="submitAddBasicList()">确 定</el-button>
      </div>
    </el-dialog>
    <!--外购件领料对话框-->
    <el-dialog :visible.sync="dialogFormVisible2" title="外购件标准件领料" center width="380px">
      <el-form ref="form2" :model="form2" :rules="rules2" label-position="left" class="demo-ruleForm">
        <el-form-item label="领料单号" label-width="100px" size="small">
          <el-input v-model="pickingListNumber" size="small" placeholder="空" readonly style="width: 200px"/>
        </el-form-item>
        <el-form-item label="出库数量" prop="outNumber" label-width="100px" size="small">
          <el-input-number v-model="form2.outNumber" :min="0" :max="enableOut" controls-position="right" style="width: 200px"/>
        </el-form-item>
        <el-form-item label="出库备注" prop="outNote" label-width="100px">
          <el-input v-model="form2.outNote" size="small" placeholder="请输入备注" style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible2=false">取消</el-button>
        <el-button type="primary" @click="submitAddPurchaseList()">确 定</el-button>
      </div>
    </el-dialog>
    <!--滞货件领料对话框-->
    <el-dialog :visible.sync="dialogFormVisible3" title="滞货件领料" center width="380px">
      <el-form ref="form3" :model="form3" :rules="rules3" label-position="left" class="demo-ruleForm">
        <el-form-item label="领料单号" label-width="100px" size="small">
          <el-input v-model="pickingListNumber" size="small" placeholder="空" readonly style="width: 200px"/>
        </el-form-item>
        <el-form-item label="出库数量" prop="outNumber" label-width="100px" size="small">
          <el-input-number v-model="form3.outNumber" :min="0" :max="enableOut" controls-position="right" style="width: 200px"/>
        </el-form-item>
        <el-form-item label="出库备注" prop="outNote" label-width="100px">
          <el-input v-model="form3.outNote" size="small" placeholder="请输入备注" style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible3=false">取消</el-button>
        <el-button type="primary" @click="submitAddBacklogList()">确 定</el-button>
      </div>
    </el-dialog>
    <!--车间采购件领料对话框-->
    <el-dialog :visible.sync="dialogFormVisible4" title="车间采购件领料" center width="380px">
      <el-form ref="form4" :model="form4" :rules="rules4" label-position="left" class="demo-ruleForm">
        <el-form-item label="领料单号" label-width="100px" size="small">
          <el-input v-model="pickingListNumber" size="small" placeholder="空" readonly style="width: 200px"/>
        </el-form-item>
        <el-form-item label="出库数量" prop="outNumber" label-width="100px" size="small">
          <el-input-number v-model="form4.outNumber" :min="0" :max="enableOut" controls-position="right" style="width: 200px"/>
        </el-form-item>
        <el-form-item label="出库备注" prop="outNote" label-width="100px">
          <el-input v-model="form4.outNote" size="small" placeholder="请输入备注" style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible4=false">取消</el-button>
        <el-button type="primary" @click="submitAddWorkshopList()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { initProject, searchmachine, searchTeam, searchPurchasePart, searchBasicPart, searchList, addList, dropList,
  addListDetail, searchListDetail, dropListDetail, searchHoursePart } from '@/api/Inventory/PickingList'
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      listLoading0: false, // 领料单
      listLoading1: false, // 自制件
      listLoading2: false, // 采购部采购件
      listLoading3: false, // 滞货件
      listLoading4: false, // 车间采购件
      PageCurrent0: 1,
      PageSize0: 10,
      total0: 0,
      PageCurrent1: 1,
      PageSize1: 10,
      total1: 0,
      PageCurrent2: 1,
      PageSize2: 10,
      total2: 0,
      PageCurrent3: 1,
      PageSize3: 10,
      total3: 0,
      PageCurrent4: 1,
      PageSize4: 10,
      total4: 0,
      ProjectValue: '',
      Project: [],
      ProjectValue_check: 0,
      MachineValue: '',
      Machine: [],
      MachineValue_check: 0,
      GroupNumValue: '',
      GroupNum: [],
      GroupNumValue_check: 0,
      tableData1: [], // 领料单
      tableDataPicking: [], // 领料单明细
      tableDataBasic: [], // 自制件
      tableDataPurchase: [], // 采购部采购件
      tableDataBacklog: [], // 滞货件
      tableDataHouse: [], // 车间采购件
      form1: { // 基本件出库
        outNumber: '', // 出库数量
        outNote: '' // 出库备注
      },
      rules1: { // 表单验证规则
        outNumber: [{ required: true, message: '请输入出库数量', trigger: 'blur' }],
        outNote: [{ required: true, message: '请输入出库备注', trigger: 'blur' }]
      },
      form2: { // 外购件出库
        outNumber: '', // 出库数量
        outNote: '' // 出库备注
      },
      rules2: { // 表单验证规则
        outNumber: [{ required: true, message: '请输入出库数量', trigger: 'blur' }],
        outNote: [{ required: true, message: '请输入出库备注', trigger: 'blur' }]
      },
      form3: { // 车间采购出库
        outNumber: '', // 出库数量
        outNote: '' // 出库备注
      },
      rules3: { // 表单验证规则
        outNumber: [{ required: true, message: '请输入出库数量', trigger: 'blur' }],
        outNote: [{ required: true, message: '请输入出库备注', trigger: 'blur' }]
      },
      form4: {
        outNumber: '', // 出库数量
        outNote: '' // 出库备注
      },
      rules4: { // 表单验证规则
        outNumber: [{ required: true, message: '请输入出库数量', trigger: 'blur' }],
        outNote: [{ required: true, message: '请输入出库备注', trigger: 'blur' }]
      },
      dialogFormVisible1: false, // 自制件
      dialogFormVisible2: false, // 采购部采购件
      dialogFormVisible3: false, // 滞货件
      dialogFormVisible4: false, // 车间采购件
      enableOut: '', // 可出库数量
      partPiant: '', // 零件图号
      material: '', // 材料
      outType: '',
      pickingListNumber: null, // 领料单编号
      pickingListNumberx: '', // 领料单流水号
      picikingPeople: '', // 领料人流水号
      partProjectNumber: '', // 项目流水号
      partMachineNumber: '', // 机床流水号
      partGroupNumber: '', // 分组流水号
      receive: '', // 收件信息ID
      locatenumber: '', // 货位流水号
      materialName: '',
      materialNumber: '',
      materialType: '',
      purchaseDetailNum: '', // 采购合同明细流水号
      askPurchaseNumber: '', // 请购单明细流水号
      materialLocate: '',
      partType: '', // 零件类型
      craftplannumber: '' // 工艺计划流水号
    }
  },
  computed: {
    ...mapGetters([
      'id'
    ])
  },
  created() {
    this.fetchData()
    this.searchListinfor()
    this.searchPartinfo()
  },
  methods: {
    // 初始化项目,获取人员编号
    fetchData() {
      this.getSelect(initProject, ['项目名称', '项目流水号'], 'Project') // 项目名称
      this.picikingPeople = this.id
    },
    // 查询领料单
    searchListinfor() {
      let check
      this.pickingListNumber ? check = 1 : check = 0
      this.listLoading0 = true
      searchList(this.PageCurrent0, this.PageSize0, check, this.pickingListNumber).then(response => {
        this.tableData1 = response.data.rows
        this.total0 = response.data.total
        this.listLoading0 = false
      })
    },
    // 领料单分页
    handleSizeChange0(val) {
      this.PageCurrent0 = 1
      this.PageSize0 = val
      this.searchListinfor()
    },
    handleCurrentChange0(val) {
      this.PageCurrent0 = val
      this.searchListinfor()
    },
    // 创建领料单
    addListinfor() {
      this.$confirm('确认创建新的领料单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        addList(this.picikingPeople).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('增加成功')
            this.searchListinfor()
          } else {
            this.$message.error('增加失败')
          }
        })
      }).catch(() => {
        this.$message('已取消操作')
      })
    },
    // 删除领料单
    dropListinfor(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (this.tableDataPicking.length === 0) {
          dropList(row.领料单流水号).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('删除成功')
              this.searchListinfor()
            } else {
              this.$message.error('数据占用')
            }
          })
        } else {
          this.$message.error('数据占用')
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 删除领料单明细
    dropListdetail(row) {
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        dropListDetail(row.领料单明细流水号).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.searchListDetailt()
            this.searchPartinfo()
          } else {
            this.$message.error('数据占用')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 查询机床
    searchMachine() {
      this.MachineValue = ''
      this.Machine = []
      this.GroupNumValue = ''
      this.GroupNum = []
      this.ProjectValue ? this.ProjectValue_check = 1 : this.ProjectValue_check = 0
      searchmachine(this.ProjectValue_check, this.ProjectValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.Machine.push({
            label: response.data[i].机床图号,
            value: response.data[i].机床流水号
          })
        }
      })
    },
    // 查询组号
    searchGroupList() {
      this.GroupNumValue = ''
      this.GroupNum = []
      searchTeam(this.MachineValue).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.GroupNum.push({
            label: response.data[i].组件名称,
            value: response.data[i].组件流水号
          })
        }
      })
    },
    // 根据项目机床分组查零件/物料
    searchPartinfo() {
      this.ProjectValue ? this.ProjectValue_check = 1 : this.ProjectValue_check = 0
      this.MachineValue ? this.MachineValue_check = 1 : this.MachineValue_check = 0
      this.GroupNumValue ? this.GroupNumValue_check = 1 : this.GroupNumValue_check = 0
      this.searchOwnPart() // 自制件
      this.searchPurchasePart() // 采购部采购件
      this.searchBacklogPart() // 滞货件
      this.searchWorkshopPart() // 车间采购件
    },
    // 查询自制件
    searchOwnPart() {
      this.tableDataBasic = []
      this.listLoading1 = true
      searchBasicPart(this.PageCurrent1, this.PageSize1, this.ProjectValue_check, this.ProjectValue, this.MachineValue_check, this.MachineValue, this.GroupNumValue_check, this.GroupNumValue).then(response => {
        const data = response.data.rows
        for (let i = 0; i < data.length; i++) {
          data[i].可出库数量 === '0' ? data[i].是否禁用 = true : data[i].是否禁用 = false
        }
        this.tableDataBasic = response.data.rows
        this.total1 = response.data.total
        this.listLoading1 = false
      })
    },
    // 自制件分页
    handleSizeChange1(val) {
      this.PageCurrent1 = 1
      this.PageSize1 = val
      this.searchOwnPart()
    },
    handleCurrentChange1(val) {
      this.PageCurrent1 = val
      this.searchOwnPart()
    },
    // 查询采购部采购件
    searchPurchasePart() {
      this.tableDataPurchase = []
      this.listLoading2 = true
      searchPurchasePart(this.PageCurrent2, this.PageSize2, this.ProjectValue_check, this.ProjectValue, this.MachineValue_check, this.MachineValue, this.GroupNumValue_check, this.GroupNumValue).then(response => {
        for (let i = 0; i < response.data.rows.length; i++) {
          if (response.data.rows[i].组件零件基本件流水号 === '0') {
            response.data.rows[i].零件类型 = response.data.rows[i].零件类型代码
            response.data.rows[i].类型名称 = response.data.rows[i].外购件类型
          }
        }
        for (let i = 0; i < response.data.rows.length; i++) {
          if (response.data.rows[i].组件零件流水号 === '0') {
            response.data.rows[i].物料名称 = response.data.rows[i].零件名称
            response.data.rows[i].项目名称 = response.data.rows[i].基本件项目名称
            response.data.rows[i].机床图号 = response.data.rows[i].基本件机床图号
            response.data.rows[i].组号 = response.data.rows[i].基本件组号
            response.data.rows[i].项目流水号 = response.data.rows[i].基本件项目流水号
            response.data.rows[i].机床流水号 = response.data.rows[i].基本件机床流水号
            response.data.rows[i].组件流水号 = response.data.rows[i].基本件组件流水号
          }
        }
        this.tableDataPurchase = response.data.rows
        this.listLoading2 = false
        this.total2 = response.data.total
      })
    },
    // 采购部采购件分页
    handleSizeChange2(val) {
      this.PageCurrent2 = 1
      this.PageSize2 = val
      this.searchPurchasePart()
    },
    handleCurrentChange2(val) {
      this.PageCurrent2 = val
      this.searchPurchasePart()
    },
    // 查询滞货件
    searchBacklogPart() {
      this.listLoading3 = true
      this.tableDataBacklog = []
      this.listLoading3 = false
    },
    // 滞货件分页
    handleSizeChange3(val) {
      this.PageCurrent3 = 1
      this.PageSize3 = val
      this.searchBacklogPart()
    },
    handleCurrentChange3(val) {
      this.PageCurrent3 = val
      this.searchBacklogPart()
    },
    // 查询车间采购件
    searchWorkshopPart() {
      this.tableDataHouse = []
      this.listLoading4 = true
      searchHoursePart(this.PageCurrent4, this.PageSize4, this.ProjectValue_check, this.ProjectValue, this.MachineValue_check, this.MachineValue, this.GroupNumValue_check, this.GroupNumValue).then(response => {
        this.tableDataHouse = response.data.rows
        this.total4 = response.data.total
        this.listLoading4 = false
      })
    },
    // 车间采购件分页
    handleSizeChange4(val) {
      this.PageCurrent4 = 1
      this.PageSize4 = val
      this.searchWorkshopPart()
    },
    handleCurrentChange4(val) {
      this.PageCurrent4 = val
      this.searchWorkshopPart()
    },
    // 查询领料单明细
    searchListDetailt() {
      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
      })
    },
    // 选择领料单
    chooseListinfor(row) {
      this.pickingListNumberx = row.领料单流水号
      this.pickingListNumber = row.领料单编号
      this.searchListDetailt()
    },
    // 增加基本件领料单明细
    addBasicList(row) {
      if (this.$refs['form1'] !== undefined) {
        this.$refs['form1'].resetFields()
      }
      this.dialogFormVisible1 = true
      this.form1.outNumber = ''
      this.form1.outNote = ''
      this.partProjectNumber = row.项目流水号
      this.partMachineNumber = row.机床流水号
      this.partGroupNumber = row.组件流水号
      this.partType = row.零件类型
      this.craftplannumber = row.工艺计划流水号
      this.receive = row.收件信息id
      this.purchaseDetailNum = ''
      this.askPurchaseNumber = ''
      this.locatenumber = row.货位流水号
      this.outType = 1
      this.materialLocate = ''
      this.materialName = row.零件名称
      this.materialType = row.零件类型名称
      this.materialNumber = row.零件图号
      this.material = ''
      this.enableOut = Number(row.可出库数量)
    },
    // 提交增加基本件领料单明细
    submitAddBasicList() {
      if (this.pickingListNumberx === '') {
        this.$message.error('请选择领料单')
      } else {
        this.$refs['form1'].validate((valid) => {
          if (valid) {
            addListDetail(this.pickingListNumberx, this.partProjectNumber, this.partMachineNumber, this.partGroupNumber, this.form.outNumber, this.partType, this.form.outNote, this.craftplannumber, this.receive, this.purchaseDetailNum, this.askPurchaseNumber, this.locatenumber, this.outType, this.materialLocate, this.materialName, this.materialType, this.materialNumber, this.materialNumber, this.material).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('增加成功')
                this.searchPartinfo()
                this.searchListinfor()
                this.searchListDetailt()
                this.dialogFormVisible1 = false
              } else {
                this.$message.error('增加失败')
              }
            })
          }
        })
      }
    },
    // 增加外购件领料单明细
    addPurchaseList(row) {
      if (this.$refs['form2'] !== undefined) {
        this.$refs['form2'].resetFields()
      }
      this.dialogFormVisible2 = true
      this.form2.outNumber = ''
      this.form2.outNote = ''
      this.partProjectNumber = row.项目流水号
      this.partMachineNumber = row.机床流水号
      this.partGroupNumber = row.组件流水号
      this.partType = row.零件类型代码
      this.craftplannumber = row.工艺计划流水号
      this.receive = row.收件信息ID
      this.purchaseDetailNum = row.采购合同明细流水号
      this.askPurchaseNumber = ''
      this.locatenumber = row.货位流水号
      this.outType = 2
      this.materialLocate = row.物料与货位对照流水号
      this.materialName = row.物料名称
      this.materialType = row.物料规格
      this.materialNumber = row.物料型号
      this.partPiant = row.零件图号
      this.material = row.材料
      this.enableOut = Number(row.货位存量 - row.待出库数量)
    },
    // 提交增加外购件领料单明细
    submitAddPurchaseList() {
      if (this.pickingListNumberx === '') {
        this.$message.error('请选择领料单')
      } else {
        this.$refs['form2'].validate((valid) => {
          if (valid) {
            addListDetail(this.pickingListNumberx, this.partProjectNumber, this.partMachineNumber, this.partGroupNumber, this.form2.outNumber, this.partType, this.form2.outNote, this.craftplannumber, this.receive, this.purchaseDetailNum, this.askPurchaseNumber, this.locatenumber, this.outType, this.materialLocate, this.materialName, this.materialType, this.materialNumber, this.partPiant, this.material).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('增加成功')
                this.searchPartinfo()
                this.searchListinfor()
                this.searchListDetailt()
                this.dialogFormVisible2 = false
              } else {
                this.$message.error('增加失败')
              }
            })
          }
        })
      }
    },
    // 增加滞货件领料单明细
    addBacklogList(row) {},
    // 提交增加滞货件领料单明细
    submitAddBacklogList() {},
    // 增加车间采购领料单明细
    addWorkshopList(row) {
      if (this.$refs['form2'] !== undefined) {
        this.$refs['form2'].resetFields()
      }
      this.dialogFormVisible4 = true
      this.form4.outNumber = ''
      this.form4.outNote = ''
      this.partProjectNumber = row.项目流水号
      this.partMachineNumber = row.机床流水号
      this.partGroupNumber = row.组件流水号
      this.partType = row.零件类型
      this.craftplannumber = ''
      this.receive = ''
      this.purchaseDetailNum = ''
      this.askPurchaseNumber = row.请购单明细流水号
      this.locatenumber = row.货位流水号
      this.outType = 3
      this.materialName = row.物料名称
      this.materialType = row.物料规格
      this.materialNumber = row.物料型号
      this.partPiant = row.零件图号
      this.material = row.材料
      this.enableOut = Number(row.货位存量)
    },
    // 提交增加车间采购领料单明细
    submitAddWorkshopList() {
      this.$refs['form4'].validate((valid) => {
        if (valid) {
          if (this.pickingListNumberx === '') {
            this.$message.error('请选择领料单')
          } else {
            addListDetail(this.pickingListNumberx, this.partProjectNumber, this.partMachineNumber, this.partGroupNumber, this.form3.outNumber, this.partType, this.form3.outNote, this.craftplannumber, this.receive, this.purchaseDetailNum, this.askPurchaseNumber, this.locatenumber, this.outType, this.materialLocate, this.materialName, this.materialType, this.materialNumber, this.partPiant, this.material).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('增加成功')
                this.searchPartinfo()
                this.searchListinfor()
                this.searchListDetailt()
                this.dialogFormVisible4 = false
              } else {
                this.$message.error('增加失败')
              }
            })
          }
        }
      })
    }
  }
}
</script>

<style scoped>
  .el-card{
    margin-bottom: 15px;
  }
  .el-select{
    width:200px
  }
  .el-input{
    width:200px
  }
  span{
    margin: 10px 0 10px 10px;
  }
</style>
