<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-button size="small" type="primary" icon="el-icon-plus" style="margin: 0 0 0 10px" @click="downLoadCjn()">导出</el-button>
      <el-table
        v-loading="listLoading2"
        :data="tableData1"
        border
        style="width: 100%;"
        height="200"
        @row-click = "searchListDetailt()">
        <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" value-format="yyyy-MM-dd">
            {{ 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>
            <el-button size="small" 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-top: 10px;">
        <el-pagination
          :current-page="PageCurrent2"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          :total="total2"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange2"
          @current-change="handleCurrentChange2"/>
      </div>
      <el-table
        v-loading="listLoading3"
        :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="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="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="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" min-width="200">
          <template slot-scope="scope">
            <el-button :disabled="scope.row.是否出库" size="small" type="primary" icon="el-icon-edit" style="margin: 0 0 10px 10px" @click="editListDetailx(scope.row)">编辑</el-button>
            <el-button :disabled="scope.row.是否出库" size="small" type="danger" icon="el-icon-delete" style="margin: 0 0 10px 10px" @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><br>
    </el-card>
    <el-card>
      <el-table
        v-loading="listLoading"
        :data="tableDataBasic"
        border
        style="width: 100%;"
        height="200">
        <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" 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" align="center">
            {{ 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" min-width="80">
          <template slot-scope="scope" align="center">
            <el-button size="small" type="primary" icon="el-icon-edit" style="margin: 0 0 0 10px" @click="addBasicListDetailinfor(scope.row)">领料</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="PageCurrent"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
      <el-table
        v-loading="listLoading1"
        :data="tableDataPurchase"
        border
        style="width: 100%;"
        height="200">
        <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" 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" 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">
            <el-button size="small" type="primary" icon="el-icon-edit" style="margin: 0 0 0 10px" @click="addListDetailinfor(scope.row)">领料</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="PageCurrent1"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          :total="total1"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange1"
          @current-change="handleCurrentChange1"/>
      </div>
      <el-table
        v-loading="listLoadingx"
        :data="tableDataHouse"
        border
        style="width: 100%;"
        height="200">
        <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" 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" 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">
            <el-button size="small" type="primary" icon="el-icon-edit" style="margin: 0 0 0 10px" @click="addWorkshopDetailinfor(scope.row)">领料</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block" style="margin-top: 10px;">
        <el-pagination
          :current-page="PageCurrentx"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="10"
          :total="totalx"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChangex"
          @current-change="handleCurrentChangex"/>
      </div>
    </el-card>
    <!--基本件领料对话框-->
    <el-dialog :visible.sync="dialogFormVisible1" title="基本件通用件领料" center width="380px">
      <el-form ref="form" :model="form" :rules="rules" label-position="left" class="demo-ruleForm">
        <el-form-item label="出库数量" prop="OutNumber" label-width="100px" size="small">
          <el-input v-model="form.OutNumber" size="small" placeholder="出库数量" style="width: 200px"/>
        </el-form-item>
        <el-form-item label="出库备注" prop="outNote" label-width="100px">
          <el-input v-model="form.outNote" size="small" placeholder="请输入备注" style="width: 200px"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="callOff('form')">取消</el-button>
        <el-button type="primary" @click="addBasicListDetail('form')">确 定</el-button>
      </div>
    </el-dialog>
    <!--外购件领料对话框-->
    <el-dialog :visible.sync="dialogFormVisible" title="外购件标准件领料" center width="380px">
      <el-form ref="form2" :model="form2" :rules="rules2" label-position="left" class="demo-ruleForm">
        <el-form-item label="出库数量" prop="OutNumber" label-width="100px" size="small">
          <el-input v-model="form2.OutNumber" size="small" placeholder="出库数量" 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="callOff('form')">取消</el-button>
        <el-button type="primary" @click="execaddListDetail('form2')">确 定</el-button>
      </div>
    </el-dialog>
    <!--车间采购件领料对话框-->
    <el-dialog :visible.sync="dialogFormVisibleWork" title="车间采购件领料" center width="380px">
      <el-form ref="form3" :model="form3" :rules="rules3" label-position="left" class="demo-ruleForm">
        <el-form-item label="出库数量" prop="OutNumber" label-width="100px" size="small">
          <el-input v-model="form3.OutNumber" size="small" placeholder="出库数量" 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="callOff('form')">取消</el-button>
        <el-button type="primary" @click="addWorkshopListDetail('form3')">确 定</el-button>
      </div>
    </el-dialog>
    <!--编辑领料明细对话框-->
    <el-dialog :visible.sync="dialogFormVisible2" title="领料单明细" center width="380px">
      <el-form ref="form4" :model="form4" :rules="rules4" label-position="left" class="demo-ruleForm">
        <el-form-item label="出库数量" prop="OutNumber" label-width="100px" size="small">
          <el-input v-model="form4.OutNumber" size="small" placeholder="出库数量" 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="callOff('form4')">取消</el-button>
        <el-button type="primary" @click="submitChannge()">确 定</el-button>
      </div>
    </el-dialog>
    <!--领料单-->
    <!--<el-card v-show="card">-->
    <!--<table cellspacing="0px" align="center" id="cjn" width="100%" style="">-->
    <!--<tbody id="1">-->
    <!--<tr>-->
    <!--<td colspan="4" style="text-align: left;font-size: 30px;font-weight: bold">GAOJING</td>-->
    <!--<td colspan="24" style="text-align:center;font-size: 30px;font-weight: bold">领料单</td>-->
    <!--</tr>-->
    <!--<tr class="tbodyHead">-->
    <!--<td colspan="2">领料单号:</td>-->
    <!--<td colspan="6">{{任务单号}}</td>-->
    <!--<td colspan="4">领料日期:</td>-->
    <!--<td colspan="4">{{任务下达日期}}</td>-->
    <!--<td colspan="3">领料人:</td>-->
    <!--<td colspan="9">{{外协厂家}}</td>-->
    <!--</tr>-->
    <!--<tr id="tableHead">-->
    <!--<td style="width: 2%">序号</td>-->
    <!--<td colspan="5">物料型号</td>-->
    <!--<td colspan="2" style="width: 4%">物料名称</td>-->
    <!--<td colspan="2" style="width: 4%">物料规格</td>-->
    <!--<td colspan="9" width="30%">数量</td>-->
    <!--<td colspan="1">项目名称</td>-->
    <!--<td>机床名称</td>-->
    <!--<td>组件名称</td>-->
    <!--<td>备注</td>-->
    <!--</tr>-->
    <!--</tbody>-->
    <!--</table>-->
    <!--</el-card>-->
  </div>
</template>

<script>
import { initProject, searchmachine, searchTeam, searchPurchasePart, searchBasicPart, searchList, addList, dropList, addListDetail, searchListDetail, dropListDetail, editListDetail, searchHoursePart } from '@/api/Inventory/PickingList'
import { mapGetters } from 'vuex'
// import { getExplorer, method5, Cleanup } from '@/vendor/exportExcel'
export default {
  data() {
    return {
      ProjectValue: '',
      Project: [],
      ProjectValue_check: 1,
      MachineValue: null,
      Machine: [],
      MachineValue_check: 0,
      GroupNumValue: null,
      GroupNumValue_check: 0,
      GroupNum: [],
      tableDataBasic: [],
      tableDataPurchase: [],
      tableData1: [],
      tableDataPicking: [], // 领料单明细表格
      listNumber: '',
      pickingListNumber: null, // 领料单编号
      pickingListNumberx: '', // 领料单流水号
      picikingPeople: '', // 领料人流水号
      partProjectNumber: '', // 项目流水号
      partProjectName: '', // 项目名称
      partMachineNumber: '', // 机床流水号
      partMachineName: '', // 机床名称
      partGroupNumber: '', // 分组流水号
      partGroupName: '', // 分组名称
      form: {
        OutNumber: '', // 出库数量
        outNote: '' // 出库备注
      },
      rules: { // 表单验证规则
        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' }]
      },
      partType: '', // 零件类型
      craftplannumber: '', // 工艺计划流水号
      receive: '', // 收件信息ID
      teamPart: '', // 组件零件流水号
      locatenumber: '', // 货位流水号
      listLoading: false,
      listLoading1: false,
      listLoading2: false,
      listLoading3: false,
      PageCurrent: 1,
      PageSize: 10,
      total: null,
      PageCurrent1: 1,
      PageSize1: 10,
      total1: null,
      PageCurrent2: 1,
      PageSize2: 10,
      total2: null,
      PageCurrent3: 1,
      PageSize3: 10,
      total3: null,
      PageCurrentx: 1,
      PageSizex: 10,
      totalx: null,
      materialName: '',
      materialNumber: '',
      materialType: '',
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      card: true,
      pickingListDetail: '',
      tableDataHouse: [],
      listLoadingx: '',
      purchaseDetailNum: '',
      dialogFormVisibleWork: false,
      time: [],
      materialLocate: '',
      enableOut: '',
      pickingListNumber_check: 1,
      outNumber: ''
    }
  },
  computed: {
    ...mapGetters([
      'id'
    ])
  },
  created() {
    this.fetchData()
    this.getpeopleid()
  },
  methods: {
    fetchData() {
      this.getSelect(initProject, ['项目名称', '项目流水号'], 'Project') // 项目名称
    },
    // 获取人员编号
    getpeopleid() {
      this.picikingPeople = this.id
      console.log(this.picikingPeople)
    },
    searchMachine() { // 查询机床
      this.MachineValue = ''
      this.Machine = []
      this.GroupNumValue = ''
      this.GroupNum = []
      if (this.ProjectValue === '') {
        this.ProjectValue_check = 0
      } else {
        this.ProjectValue_check = 1
      }
      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.tableDataPurchase = []
      this.tableDataBasic = []
      if (this.ProjectValue !== null && this.ProjectValue !== '') {
        this.ProjectValue_check = 1
      }
      if (this.MachineValue !== null && this.MachineValue !== '') {
        this.MachineValue_check = 1
      }
      if (this.GroupNumValue !== null && this.GroupNumValue !== '') {
        this.GroupNumValue_check = 1
      }
      this.listLoading = true
      this.listLoading1 = true
      this.listLoadingx = true
      searchPurchasePart(this.PageCurrent, this.PageSize, this.ProjectValue_check, this.ProjectValue, this.MachineValue_check, this.MachineValue, this.GroupNumValue_check, this.GroupNumValue).then(response => {
        console.log(response)
        this.tableDataPurchase = response.data.rows
        this.listLoading = false
        this.total1 = response.data.total
      })
      searchBasicPart(this.PageCurrent1, this.PageSize1, this.ProjectValue_check, this.ProjectValue, this.MachineValue_check, this.MachineValue, this.GroupNumValue_check, this.GroupNumValue).then(response => {
        this.tableDataBasic = response.data.rows
        this.listLoading1 = false
        this.total = response.data.total
        console.log(response)
      })
      searchHoursePart(this.PageCurrentx, this.PageSizex, this.ProjectValue_check, this.ProjectValue, this.MachineValue_check, this.MachineValue, this.GroupNumValue_check, this.GroupNumValue).then(response => {
        this.tableDataHouse = response.data.rows
        this.listLoadingx = false
        this.totalx = response.data.total
        console.log(response)
      })
    },
    handleSizeChange(val) {
      this.PageCurrent1 = 1
      this.PageSize1 = val
      this.searchPartinfo()
    },
    handleCurrentChange(val) {
      this.PageCurrent1 = val
      this.searchPartinfo()
    },
    handleSizeChange1(val) {
      this.PageCurrent = 1
      this.PageSize = val
      this.searchPartinfo()
    },
    handleCurrentChange1(val) {
      this.PageCurrent = val
      this.searchPartinfo()
    },
    handleSizeChangex(val) {
      this.PageCurrentx = 1
      this.PageSizex = val
      this.searchPartinfo()
    },
    handleCurrentChangex(val) {
      this.PageCurrentx = val
      this.searchPartinfo()
    },
    // 查询领料单
    searchListinfor() {
      if (this.pickingListNumber === null) {
        this.pickingListNumber_check = 0
      }
      this.listLoading2 = true
      searchList(this.PageCurrent2, this.PageSize2, this.pickingListNumber_check, this.pickingListNumber).then(response => {
        for (let i = 0; i < response.data.rows.length; i++) {
          response.data.rows[i].领料时间 = response.data.rows[i].领料时间.substring(0, response.data.rows[i].领料时间.length - 8)
        }
        this.tableData1 = response.data.rows
        this.listLoading2 = false
        this.total2 = response.data.total
        console.log(response)
      })
    },
    handleSizeChange2(val) {
      this.PageCurrent2 = 1
      this.PageSize2 = val
      this.searchListinfor()
    },
    handleCurrentChange2(val) {
      this.PageCurrent2 = val
      this.searchListinfor()
    },
    // 查询领料单明细
    searchListDetailt() {
      this.listLoading3 = 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.listLoading3 = false
      })
    },
    // 增加领料单
    addListinfor() {
      addList(this.picikingPeople).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('增加成功')
          this.searchListinfor()
        } else {
          this.$message.error('增加失败')
        }
      })
    },
    // 删除领料单
    dropListinfor(row) {
      this.pickingListNumberx = row.领料单流水号
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        dropList(this.pickingListNumberx).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.searchListinfor()
          } else {
            this.$message.error('数据占用')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 删除领料单明细
    dropListdetail(row) {
      this.pickingListDetail = row.领料单明细流水号
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        dropListDetail(this.pickingListDetail).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
            this.searchListDetailt()
          } else {
            this.$message.error('数据占用')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 选择领料单
    chooseListinfor(row) {
      this.pickingListNumberx = row.领料单流水号
    },
    // 增加基本件领料单明细
    addBasicListDetailinfor(row) {
      this.form = []
      this.partProjectNumber = row.项目流水号
      this.partProjectName = row.项目名称
      this.partMachineNumber = row.机床流水号
      this.partMachineName = row.机床图号
      this.partGroupNumber = row.组件流水号
      this.partGroupName = row.组号
      this.partType = row.零件类型
      this.craftplannumber = row.工艺计划流水号
      this.receive = row.收件信息id
      this.teamPart = row.组件零件流水号
      this.locatenumber = row.货位流水号
      this.materialName = row.零件名称
      this.materialNumber = row.零件图号
      this.dialogFormVisible1 = true
      this.materialName = row.零件名称
      this.materialType = row.零件类型名称
      this.materialNumber = row.零件图号
      this.enableOut = row.可出库数量
      this.purchaseDetailNum = row.采购合同明细流水号
    },
    addBasicListDetail(formName) {
      if (this.pickingListNumberx === '') {
        this.$message.error('请选择领料单')
      } else if (this.form.OutNumber === '' || this.form.OutNumber > this.enableOut) {
        this.$message.error('请正确输入领用数量')
      } else {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            addListDetail(this.pickingListNumberx, this.partProjectNumber, this.partMachineNumber, this.partGroupNumber, this.partProjectName, this.partMachineName, this.partGroupName, this.materialName, this.materialNumber, this.materialType, this.form.OutNumber, this.partType, this.form.outNote, this.craftplannumber, this.receive, this.teamPart, this.purchaseDetailNum, this.locatenumber, 0, this.materialLocate).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('增加成功')
                this.searchPartinfo()
              } else {
                this.$message.error('增加失败')
              }
            })
            this.dialogFormVisible1 = false
            this.searchListinfor()
            this.searchListDetailt()
          }
        })
      }
    },
    // 增加外购件领料单明细
    addListDetailinfor(row) {
      this.form = []
      this.partProjectNumber = row.项目流水号
      this.partProjectName = row.项目名称
      this.partMachineNumber = row.机床流水号
      this.partMachineName = row.机床图号
      this.partGroupNumber = row.组件流水号
      this.partGroupName = row.组号
      this.partType = row.零件类型代码
      this.craftplannumber = row.工艺计划流水号
      this.receive = row.收件信息ID
      this.teamPart = row.组件零件流水号
      this.locatenumber = row.货位流水号
      this.materialName = row.物料名称
      this.materialNumber = row.物料型号
      this.materialType = row.物料规格
      this.dialogFormVisible = true
      this.purchaseDetailNum = row.采购合同明细流水号
      this.materialLocate = row.物料与货位对照流水号
      this.enableOut = row.货位存量 - row.待出库数量
    },
    execaddListDetail(formName) {
      if (this.pickingListNumberx === '') {
        this.$message.error('请选择领料单')
      } else if (this.form2.OutNumber === '' || this.form2.OutNumber > this.enableOut) {
        console.log(this.enableOut)
        this.$message.error('请正确输入领用数量')
      } else {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            addListDetail(this.pickingListNumberx, this.partProjectNumber, this.partMachineNumber, this.partGroupNumber, this.partProjectName, this.partMachineName, this.partGroupName, this.materialName, this.materialType, this.materialNumber, this.form2.OutNumber, this.partType, this.form2.outNote, this.craftplannumber, this.receive, this.teamPart, this.purchaseDetailNum, this.locatenumber, 0, this.materialLocate).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('增加成功')
                this.searchPartinfo()
              } else {
                this.$message.error('增加失败')
              }
            })
          }
        })
        this.dialogFormVisible = false
        this.searchListinfor()
        this.searchListDetailt()
      }
    },
    // 增加车间采购领料单明细
    addWorkshopDetailinfor(row) {
      this.form = []
      this.partProjectNumber = row.项目流水号
      this.partProjectName = row.项目名称
      this.partMachineNumber = row.机床流水号
      this.partMachineName = row.机床图号
      this.partGroupNumber = row.组件流水号
      this.partGroupName = row.组号
      this.partType = row.零件类型
      this.receive = row.收件信息ID
      this.locatenumber = row.货位流水号
      this.materialName = row.物料名称
      this.materialNumber = row.物料型号
      this.materialType = row.物料规格
      this.dialogFormVisibleWork = true
      this.purchaseDetailNum = row.采购合同明细流水号
      this.materialLocate = row.物料与货位对照流水号
      this.enableOut = row.货位存量
      console.log(this.enableOut)
    },
    addWorkshopListDetail(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.pickingListNumberx === '') {
            this.$message.error('请选择领料单')
          } else if (this.form3.OutNumber === '' || this.form3.OutNumber > this.enableOut) {
            this.$message.error('请正确输入领用数量')
          } else {
            addListDetail(this.pickingListNumberx, this.partProjectNumber, this.partMachineNumber, this.partGroupNumber, this.partProjectName, this.partMachineName, this.partGroupName, this.materialName, this.materialType, this.materialNumber, this.form3.OutNumber, this.partType, this.form3.outNote, this.craftplannumber, this.receive, this.teamPart, this.purchaseDetailNum, this.locatenumber, 1, this.materialLocate).then(response => {
              if (response.data[0].result === '1') {
                this.$message.success('增加成功')
                this.searchPartinfo()
              } else {
                this.$message.error('增加失败')
              }
            })
          }
        }
      })
      this.dialogFormVisibleWork = false
      this.searchListinfor()
      this.searchListDetailt()
    },
    // 修改领料单明细
    editListDetailx(row) {
      this.dialogFormVisible2 = true
      this.pickingListDetail = row.领料单明细流水号
      this.form4.OutNumber = row.出库数量
      this.outNumber = row.出库数量
      this.form4.outNote = row.备注
    },
    submitChannge() {
      if (this.form4.OutNumber > this.outNumber) {
        this.$message.error('修改数量须小于领用数量')
      } else {
        editListDetail(this.pickingListDetail, this.form4.OutNumber, this.form4.outNote).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('修改成功')
          } else {
            this.$message.error('修改失败')
          }
        })
        this.dialogFormVisible2 = false
        this.searchListDetailt()
      }
    },
    // 重置表单
    callOff() {
      this.form.DirectNumber = ''
      this.form.DirectNote = ''
      this.dialogFormVisible = false
      this.dialogFormVisible1 = false
      this.dialogFormVisible2 = false
      this.dialogFormVisibleWork = false
      this.form2.OutNumber = ''
      this.form2.outNote = ''
    },
    // 导出状态
    handleDownload() {
      searchListDetail(this.pickingListNumberx).then(response => {
        return response.data
      }).then(data => {
        const a = data
        require.ensure([], () => {
          const { export_json_to_excel } = require('@/vendor/Export2Excel')
          const tHeader = ['物料名称', '物料型号', '物料规格', '项目名称', '机床名称', '组件名称', '领用数量', '备注']
          const filterVal = ['物料名称', '物料型号', '物料规格', '项目名称', '机床名称', '组件名称', '领用数量', '备注']
          const list = a
          const data = this.formatJson(filterVal, list)
          export_json_to_excel(tHeader, data, '领料单')
        })
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => v[j]))
    }
    // downLoadCjn(tableid) {
    //   if (this.List3.length === 0) {
    //     this.$message.warning('暂无数据')
    //   } else {
    //     getExplorer()
    //     method5(tableid)
    //     Cleanup()
    //   }
    // }
  }
}
</script>

<style scoped>

</style>
