<template>
  <div class="app-container">
    <el-card style="height: 1850px;padding: 0">
      <el-tabs v-model="PartType" type="border-card">
        <el-tab-pane label="生产领料" name="生产领料">
          <el-row>
            <!--<div style="margin-left: 589px">
              <el-button type="distribution" size="small" icon="el-icon-shopping-cart-2" plain @click="materialOut">出库</el-button>

              &lt;!&ndash;          <el-button type="success" plain icon="el-icon-download" size="small" style="margin-left: 760px" @click="exportExcel()">导出</el-button>&ndash;&gt;
            </div>-->
            <div style="margin-left: 10px">
              <el-input v-model="PickingListName" placeholder="领料单号/领料人" style="width: 170px" size="small" clearable/>
              <el-select v-model="orderNameValue" style="width:200px;margin-right: 0px" placeholder="订单号" size="small" filterable clearable @change="searchTable()">
                <el-option
                  v-for="item in orderNumberType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label"/>
              </el-select>
              <el-button type="primary" size="small" icon="el-icon-search" plain @click="searchTable">查询</el-button>
              <el-button type="success" size="small" icon="el-icon-printer" plain @click="exportTable">打印</el-button>
            </div>
            <el-col style="margin-left: 7px;width: 551px">
              <!--        <el-card>-->
              <div style="margin-top: 10px;">
                <el-table
                  v-loading="loading"
                  :data="ProductionPick"
                  :row-class-name="tableRowClassName"
                  highlight-current-row
                  border
                  size="mini"
                  style="margin-top: 10px"
                  height="750"
                  @row-click="searchTable1">
                  <el-table-column :width="setColumnWidth('领料单号')" label="领料单号" align="center" show-overflow-tooltip prop="">
                    <template slot-scope="scope">
                      {{ scope.row.领料单号 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('领料人')" label="领料人" align="center" show-overflow-tooltip prop="">
                    <template slot-scope="scope">
                      {{ scope.row.领料人 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('订单号')" label="订单号" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.订单号 }}
                    </template>
                  </el-table-column>
                  <el-table-column label="产品/部件" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.产品名称 }}
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <!--            </el-card>-->
            </el-col>

            <el-col style="margin-left: 30px;width: 1011px">
              <!--            <el-card>-->
              <div style="margin-top: 10px">
                <el-table
                  v-loading="loading"
                  ref="table"
                  :data="tableData"
                  :row-class-name="tableRowClassName1"
                  :header-cell-style="{background: '#2283D4',color: 'white'}"
                  highlight-current-row
                  show-summary
                  border
                  size="mini"
                  style="width: 1081px;margin-top: 10px"
                  height="750">
                  <el-table-column :width="setColumnWidth('序号')" label="序号" type="index" align="center"/>
                  <el-table-column label="物料名称" align="center" prop="物料名称">
                    <template slot-scope="scope">
                      {{ scope.row.物料名称 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="130px" label="图号/型号" align="center" prop="图号/型号">
                    <template slot-scope="scope">
                      {{ scope.row.图号或型号 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="70px" label="库位" align="center" prop="单位">
                    <template slot-scope="scope">
                      {{ scope.row.货位名称 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('单位')" label="单位" align="center" prop="单位">
                    <template slot-scope="scope">
                      {{ scope.row.单位 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="120px" label="本次领用" align="center" prop="本次领用">
                    <template slot-scope="scope">
                      <el-input-number
                        v-model="scope.row.本次领用"
                        :min="0"
                        :max="Number(scope.row.申请数)-Number(scope.row.已领数) > Number(scope.row.库存数) ? Number(scope.row.库存数) : Number(scope.row.申请数)-Number(scope.row.已领数)"
                        size="mini"
                        style="width:100%"/>
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('数量')" label="申请数" align="center" show-overflow-tooltip prop="申请数">
                    <template slot-scope="scope">
                      {{ scope.row.申请数 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('数量')" label="已领数" align="center" prop="已领数">
                    <template slot-scope="scope">
                      {{ scope.row.已领数 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('数量')" label="库存数" align="center" show-overflow-tooltip prop="库存数">
                    <template slot-scope="scope">
                      {{ scope.row.库存数 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('数量')" label="批次" align="center" show-overflow-tooltip prop="批次">
                    <template slot-scope="scope">
                      {{ scope.row.批次 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="136px" label="操作" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      <el-popover placement="right" width="535" trigger="click">
                        <el-table :data="gridData" :header-cell-style="{background: '#19466E',color: 'white'}" border highlight-current-row size="mini" show-summary>
                          <el-table-column width="50px" align="center" type="index" label="序号"/>
                          <el-table-column width="150px" align="center" label="批次编号">
                            <template slot-scope="scope">
                              {{ scope.row.批次编号 }}
                            </template>
                          </el-table-column>
                          <el-table-column width="100px" align="center" label="批次库存" prop="货位存量">
                            <template slot-scope="scope">
                              {{ scope.row.货位存量 }}
                            </template>
                          </el-table-column>
                          <el-table-column min-width="140x" label="本次领用" align="center">
                            <template slot-scope="scope">
                              <el-input-number
                                v-model="scope.row.本次领用"
                                :min="0"
                                :max="maxNumber > Number(scope.row.货位存量) ? Number(scope.row.货位存量) : maxNumber"
                                size="mini"
                                style="width:100%"/>
                            </template>
                          </el-table-column>
                          <el-table-column width="66px" label="操作" align="center" show-overflow-tooltip>
                            <template slot-scope="scope">
                              <el-button :disabled="scope.row.本次领用 === 0 || exWarehouse1" type="text" size="mini" @click="confirmDelivery(scope.row)">确认</el-button>
                            </template>
                          </el-table-column>
                        </el-table>
                        <div class="block" style="margin-top: 10px;">
                          <el-pagination
                            :current-page="pageCurrent3"
                            :total="total3"
                            :page-size="pageSize3"
                            layout="total, prev, pager, next"
                            @current-change="handleCurrentChanges3"/>
                        </div>
                        <el-button slot="reference" :disabled="scope.row.库存数 === 0 || Number(scope.row.申请数) <= Number(scope.row.已领数) || exWarehouse" type="text" size="mini" @click="showDelivery(scope.row, scope.$index)">
                          出库
                        </el-button>
                      </el-popover>
                      <el-button :disabled="Number(scope.row.已领数) > 0 || !orderNumber" type="text" size="mini" style="margin-left: 20px" @click="handleReturn(scope.row)">退回</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </el-col>
          </el-row>
          <el-card v-show="false">
            <div style="width:900px;margin-left: 350px">
              <el-card>
                <div id="WGBLD" style="width: 840px;margin: 0 auto">
                  <div style="width: 180px;margin: 0 auto 20px">
                    <!--              调整这一个即可解决 打印出来表头布局中的问题-->
                    <h3>浙江景耀数控出库单</h3>
                  </div>
                  <div style="margin: 0 0 10px">
                    <span style="margin-left: 10px;font-size: 14px">领料单号：{{ PickingNo }}</span>
                    <span style="float: right; font-size: 14px;margin-right: 10px">订单号：{{ orderNumberFloat }}</span>
                  </div>
                  <div style="margin: 0 0 10px">
                    <span style="margin-left: 10px;font-size: 14px">领料人：{{ pickPeople }}</span>
                    <span style="float: right; font-size: 14px;margin-right: 10px">产品部件：{{ productName }}</span>
                  </div>
                  <table cellspacing="0px" align="center" border="1 solid black" width="100%">
                    <tr id="tablehead12" style="height: 35px">
                      <td colspan="4" style="text-align: center;width: 20%;font-size: 14px">物料名称</td>
                      <td colspan="3" style="text-align: center;width: 22%;font-size: 14px">规格型号</td>
                      <td colspan="1" style="text-align: center;width: 12%;font-size: 14px">库位</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 16px">单位</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">申请数</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">已领数</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">库存数</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">批次</td>
                    </tr>
                    <tr v-for="(list, index) in tableData" :key="index" style="height: 35px">
                      <td colspan="4" style="text-align: center;width: 20%;font-size: 14px">{{ list.物料名称 }}</td>
                      <td colspan="3" style="text-align: center;width: 22%;font-size: 14px">{{ list.图号或型号 }}</td>
                      <td colspan="1" style="text-align: center;width: 12%;font-size: 14px">{{ list.货位名称 }}</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">{{ list.单位 }}</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">{{ list.申请数 }}</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">{{ list.已领数 }}</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">{{ list.库存数 }}</td>
                      <td colspan="1" style="text-align: center;width: 6%;font-size: 14px">{{ list.批次 }}</td>
                    </tr>
                    <!--<tr style="height: 35px">
                      <td colspan="3" style="text-align: center;width: 15%;font-size: 14px">合计</td>
                      <td colspan="17" style="text-align: center;width: 85%">
                        <div>
                          <span style="float: right;margin-right: 24%;font-size: 14px">{{ Number(totalAmount) }}</span>
                        </div>
                      </td>
                    </tr>-->
                  </table>
                </div>
              </el-card>
            </div>
          </el-card>
        </el-tab-pane>
        <el-tab-pane label="耗材" name="耗材">
          <el-row>

            <el-col style="margin-left: 7px;width: 971px">
              <div class="grid-content bg-purple">

                <el-input v-model="ConsumableCodeSelect" style="width: 160px" size="small" placeholder="物料编号" clearable @keyup.enter.native="pageCurrent=1;pageSize=20;searchTable2()"/>
                <el-input v-model="ConsumableSelect" style="width: 200px" size="small" placeholder="物料名称/规格/型号" clearable @keyup.enter.native="pageCurrent=1;pageSize=20;searchTable2()"/>

                <el-table v-loading="loading" ref="table1" :data="Consumables" highlight-current-row show-summary border size="mini" style="margin-top: 10px" height="710">
                  <el-table-column :width="setColumnWidth('序号')" label="序号" type="index" align="center"/>
                  <el-table-column min-width="160px" label="物料名称" show-overflow-tooltip align="center" prop="">
                    <template slot-scope="scope">
                      {{ scope.row.物料名称 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="160px" label="图号/型号" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.图号或型号 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('单位')" label="单位" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.单位 }}
                    </template>
                  </el-table-column>
                  <el-table-column :width="setColumnWidth('数量')" label="库存" align="center" show-overflow-tooltip prop="库存">
                    <template slot-scope="scope">
                      {{ scope.row.库存 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="260px" label="备注" align="center" show-overflow-tooltip>
                    <template slot-scope="scope">
                      {{ scope.row.备注 }}
                    </template>
                  </el-table-column>
                  <el-table-column width="171px" label="操作" align="center">
                    <template slot-scope="scope">
                      <el-popover placement="right" width="880px" trigger="click">
                        <el-table :data="gridData1" :header-cell-style="{background: '#19466E',color: 'white'}" border highlight-current-row size="mini" show-summary>
                          <el-table-column width="50px" align="center" type="index" label="序号"/>
                          <el-table-column width="150px" align="center" label="批次编号">
                            <template slot-scope="scope">
                              {{ scope.row.批次编号 }}
                            </template>
                          </el-table-column>
                          <el-table-column width="100px" align="center" label="批次库存" prop="货位存量">
                            <template slot-scope="scope">
                              {{ scope.row.货位存量 }}
                            </template>
                          </el-table-column>
                          <el-table-column width="140x" label="本次领用" align="center">
                            <template slot-scope="scope">
                              <el-input-number
                                v-model="scope.row.本次领用"
                                :min="0"
                                :max="Number(scope.row.货位存量)"
                                size="mini"
                                style="width:100%"/>
                            </template>
                          </el-table-column>
                          <el-table-column width="140x" label="领用人" align="center">
                            <template slot-scope="scope">
                              <el-select v-model="scope.row.领用人" style="width:100%" placeholder="领用人" size="small" filterable clearable>
                                <el-option
                                  v-for="item in takenPerson"
                                  :key="item.value"
                                  :label="item.label"
                                  :value="item.value"/>
                              </el-select>
                            </template>
                          </el-table-column>
                          <el-table-column width="140x" label="备注" align="center">
                            <template slot-scope="scope">
                              <el-input
                                v-model="scope.row.备注"
                                size="mini"
                                style="width:100%"/>
                            </template>
                          </el-table-column>
                          <el-table-column width="70px" label="操作" align="center" show-overflow-tooltip>
                            <template slot-scope="scope">
                              <el-button :disabled="scope.row.本次领用 === 0 || exWarehouse3" type="text" size="mini" @click="Delivery(scope.row)">确认</el-button>
                            </template>
                          </el-table-column>
                        </el-table>
                        <div class="block" style="margin-top: 10px;">
                          <el-pagination
                            :current-page="pageCurrent4"
                            :total="total4"
                            :page-size="pageSize4"
                            layout="total, prev, pager, next"
                            @current-change="handleCurrentChanges4"/>
                        </div>
                        <el-button slot="reference" :disabled="scope.row.库存数 === 0 || exWarehouse2" type="text" size="mini" @click="showDelivery1(scope.row)">
                          出库
                        </el-button>
                      </el-popover>
                      <el-button type="text" size="mini" style="margin-left: 10px" @click="showRemark(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, 100]"
                    :page-size="pageSize"
                    :total="total"
                    layout="total, sizes, prev, pager, next, jumper"
                    @size-change="handleSizeChanges"
                    @current-change="handleCurrentChanges"/>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible2" title="备注" center width="440px">
        <el-form label-position="center" label-width="110px" class="demo-ruleForm">
          <el-form-item label="备注" prop="备注">
            <el-input v-model="remark" style="width:200px" placeholder="备注" size="small" clearable/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="dialogFormVisible2=false">取消</el-button>
          <el-button type="distribution" size="small" @click="submitA()">确定</el-button>
        </div>
      </el-dialog>
      <!--      <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisible" title="物料出库" center width="440px">-->
      <!--        <el-form ref="form" :model="form" :rules="rules" label-position="center" label-width="110px" class="demo-ruleForm">-->
      <!--          <el-row>-->
      <!--            <el-col :span="12">-->
      <!--              <el-form-item label="物料名称" prop="物料名称">-->
      <!--                <el-input-->
      <!--                  v-model="materialName"-->
      <!--                  size="small"-->
      <!--                  readonly-->
      <!--                  style="width:200px"/>-->
      <!--              </el-form-item>-->
      <!--            </el-col>-->
      <!--          </el-row>-->
      <!--          <el-row>-->
      <!--            <el-col :span="12">-->
      <!--              <el-form-item label="领用数量" prop="领用数量">-->
      <!--                <el-input-number-->
      <!--                  v-model="form.领用数量"-->
      <!--                  :min="1"-->
      <!--                  :max="stock"-->
      <!--                  size="small"-->
      <!--                  style="width:200px"/>-->
      <!--              </el-form-item>-->
      <!--            </el-col>-->
      <!--          </el-row>-->
      <!--          <el-row>-->
      <!--            <el-col :span="12">-->
      <!--              <el-form-item label="领用人" prop="领用人">-->
      <!--                <el-select v-model="form.领用人" style="width:200px" placeholder="领用人" size="small" filterable clearable>-->
      <!--                  <el-option-->
      <!--                    v-for="item in takenPerson"-->
      <!--                    :key="item.value"-->
      <!--                    :label="item.label"-->
      <!--                    :value="item.value"/>-->
      <!--                </el-select>-->
      <!--              </el-form-item>-->
      <!--            </el-col>-->
      <!--          </el-row>-->
      <!--        </el-form>-->
      <!--        <div slot="footer" class="dialog-footer">-->
      <!--          <el-button size="small" @click="callOff('form')">取消</el-button>-->
      <!--          <el-button type="distribution" size="small" @click="submit('form')">确定</el-button>-->
      <!--        </div>-->
      <!--      </el-dialog>-->
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import $ from 'jquery'
export default {
  data() {
    return {
      returns: [],
      exWarehouse: false,
      exWarehouse1: false,
      exWarehouse2: false,
      exWarehouse3: false,
      pageCount: 5,
      total3: 0, // 分页总数
      pageCurrent3: 1, // 分页当前页
      pageSize3: 5, // 分页每页显示条数
      total4: 0, // 分页总数
      pageCurrent4: 1, // 分页当前页
      pageSize4: 5, // 分页每页显示条数
      PartType: '生产领料',
      customerNameValue: '', // 买方名称
      customerName: [], // 买方名称数组
      dateRange: '', // 提交日期
      contractStateValue: '', // 合同状态
      materialName: '', // 物料名称
      materialTool: '', // 图号
      pickPeople: '', // 领料人
      orderNumberFloat: '', // 订单号
      productName: '', // 产品
      PickingNo: '', // 领料单号
      unit: '', // 单位
      Location: '', // 库位
      takenPerson: [], // 领用人
      type: '',
      number: '',
      gridData: [],
      gridData1: [],
      maxNumber: 0,
      outIndex: '',
      pickMx: '',
      processValue: '',
      purchaseValue: '',
      productValue: '',
      groupValue: '',
      pickValue: '',
      temporaryValue: '',
      PickingListName: '',
      orderNameValue: '',
      orderNumberType: [],
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      remark: '',
      form: {
        领用数量: '',
        领用人: ''
      },
      rules: {
        领用数量: [{ required: true, message: '请输入领用数量', trigger: 'blur' }],
        领用人: [{ required: true, message: '请选择领用人', trigger: 'change' }]
      },
      materialNumber: '',
      input: '',
      stock: '',
      orderNumber: '',
      pickingList: '',
      isGroup: '',
      pickingPeople: '',
      materialNumber1: '',
      multipleSelection: [],
      multipleSelection_variable: [],
      loading: false, // 数据加载
      loading1: false, // 数据加载
      total: 0, // 分页总数
      ProductionPick: [], // 生产领料
      tableData: [],
      Consumables: [], // 耗材
      pageCurrent: 1, // 分页当前页
      pageSize: 20, // 分页每页显示条数
      orderName: '', // 排序列名
      ConsumableCodeSelect: '', // 耗材物料编号搜索
      ConsumableSelect: '', // 耗材搜索
      order: '' // 排序方式
    }
  },
  computed: {
    ...mapGetters([
      'id',
      'token'
    ])
  },
  updated() {
    this.$nextTick(() => {
      this.$refs['table'].doLayout()
      this.$refs['table1'].doLayout()
    })
  },
  created() {
    this.getCustomer()
    this.searchTable()
    this.searchTable2()
    this.getOrderNumberType()
  },
  methods: {
    getOrderNumberType() {
      // this.orderNumberType = []
      var param = []
      var Data = this.CreateData('11', '领料单_未领订单_列表_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.orderNumberType.push({
            label: response.data[i].订单号,
            value: response.data[i].订单流水号
          })
        }
      })
    },
    showRemark(row) {
      this.materialNumber1 = row.物料流水号
      this.remark = row.备注
      this.dialogFormVisible2 = true
    },
    submitA() {
      var param = []
      param[0] = ['物料流水号', this.materialNumber1]
      param[1] = ['备注', this.remark]
      var Data = this.CreateData('12', '仓储管理_物料备注_修改', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('修改成功')
          this.dialogFormVisible2 = false
          this.searchTable2()
        } else {
          this.$message.error('退回失败')
        }
      })
    },
    exportTable() {
      if (this.pickingList) {
        const htmlNode = $('#WGBLD').html()
        const body = $('body')
        body.children().hide()
        const printNode = $(htmlNode)
        body.append(printNode)
        window.print()
        body.children().not('script').show()
        body.children().not('#app').hide()
        printNode.remove()
      } else {
        this.$message.warning('请选择要打印的领料单')
      }
    },
    getCustomer() {
      var param = []
      var Data = this.CreateData('11', '人员信息_查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.takenPerson.push({
            label: response.data[i].姓名,
            value: response.data[i].人员编号
          })
        }
      })
    },
    // getData() {
    //   if (this.PartType === '生产领料') {
    //     this.searchTable()
    //   } else if (this.PartType === '耗材') {
    //     this.searchTable2()
    //   }
    // },
    searchTable() {
      let check
      this.PickingListName ? check = 1 : check = 0
      var param = []
      param[0] = ['领料单号_check', check]
      param[1] = ['领料单号', this.PickingListName]
      param[2] = ['订单号', this.orderNameValue]
      var Data = this.CreateData('11', '装配管理_未领完领料单_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.ProductionPick = response.data
      })
    },
    searchTable1(row) {
      this.pickingPeople = row.领料人流水号
      this.pickingList = row.领料单流水号
      this.isGroup = row.是否部件
      this.orderNumber = row.订单流水号
      this.PickingNo = row.领料单号
      this.pickPeople = row.领料人
      this.orderNumberFloat = row.订单号
      this.productName = row.产品名称
      var param = []
      param[0] = ['领料单流水号', row.领料单流水号]
      var Data = this.CreateData('11', '装配管理_领料单明细_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData = response.data
      })
    },
    handleReturn(row) {
      this.$confirm('是否退回物料?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['领料单流水号', this.pickingList]
        param[1] = ['领料单明细流水号', row.领料单明细流水号]
        param[2] = ['组件流水号', row.组件流水号]
        param[3] = ['标准件和外购件流水号', row.标准件和外购件流水号]
        param[4] = ['基本件流水号', row.基本件流水号]
        param[5] = ['物料流水号', row.物料流水号]
        param[6] = ['人员编号', this.id]
        var Data = this.CreateData('12', '仓储管理_领料明细_退回', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('退回成功')
            var param = []
            param[0] = ['领料单流水号', this.pickingList]
            var Data = this.CreateData('11', '装配管理_领料单明细_查询', param)
            this.ExecDatabase(Data).then(response => {
              this.tableData = response.data
            })
          } else {
            this.$message.error('退回失败')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    showDelivery(row, index) {
      this.maxNumber = row.本次领用
      this.outIndex = index
      this.pickMx = row.领料单明细流水号
      this.processValue = row.基本件流水号
      this.purchaseValue = row.标准件和外购件流水号
      this.productValue = row.产品流水号
      this.groupValue = row.组件流水号
      this.pickValue = row.领料流水号
      this.temporaryValue = row.临时流水号
      this.materialSerialNumber = row.物料流水号
      var param = []
      param[0] = ['物料流水号', row.物料流水号]
      var Data = this.CreateData('11', '装配管理_领料单明细_批次查询', param, this.pageSize3, this.pageCurrent3)
      this.ExecDatabase(Data).then(response => {
        if (response.data.total === 1) {
          this.exWarehouse = true
          this.confirmDelivery1(response.data.rows)
          console.log(response.data.rows, 2222)
        } else {
          this.gridData = response.data.rows
          this.total3 = response.data.total
        }
      })
    },
    confirmDelivery1(row) {
      this.exWarehouse1 = true
      var param = []
      param[0] = ['物料流水号', row[0].物料流水号]
      param[1] = ['出库数量', this.maxNumber]
      param[2] = ['基本件流水号', this.processValue]
      param[3] = ['标准件和外购件流水号', this.purchaseValue]
      param[4] = ['领料单明细流水号', this.pickMx]
      param[5] = ['产品流水号', this.productValue]
      param[6] = ['组件流水号', this.groupValue]
      param[7] = ['领料流水号', this.pickValue]
      param[8] = ['临时流水号', this.temporaryValue]
      param[9] = ['出库人流水号', this.id]
      param[10] = ['领料人流水号', this.pickingPeople]
      param[11] = ['领料单流水号', this.pickingList]
      param[12] = ['是否部件', this.isGroup]
      param[13] = ['物料与货位流水号', row[0].物料与货位流水号]
      var Data = this.CreateData('12', '仓储管理_物料出库_新', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('出库成功')
          this.exWarehouse = false
          this.exWarehouse1 = false
          this.tableData = []
          var param = []
          param[0] = ['领料单流水号', this.pickingList]
          var Data = this.CreateData('11', '装配管理_领料单明细_查询', param)
          this.ExecDatabase(Data).then(response => {
            this.tableData = response.data
            if (response.data.length === 0) {
              this.searchTable()
            } else {
              this.maxNumber = this.tableData[this.outIndex].本次领用
            }
          })
        } else {
          this.$message.error('出库失败')
          this.exWarehouse = false
          this.exWarehouse1 = false
        }
      })
    },
    confirmDelivery(row) {
      this.exWarehouse1 = true
      var param = []
      param[0] = ['物料流水号', row.物料流水号]
      param[1] = ['出库数量', row.本次领用]
      param[2] = ['基本件流水号', this.processValue]
      param[3] = ['标准件和外购件流水号', this.purchaseValue]
      param[4] = ['领料单明细流水号', this.pickMx]
      param[5] = ['产品流水号', this.productValue]
      param[6] = ['组件流水号', this.groupValue]
      param[7] = ['领料流水号', this.pickValue]
      param[8] = ['临时流水号', this.temporaryValue]
      param[9] = ['出库人流水号', this.id]
      param[10] = ['领料人流水号', this.pickingPeople]
      param[11] = ['领料单流水号', this.pickingList]
      param[12] = ['是否部件', this.isGroup]
      param[13] = ['物料与货位流水号', row.物料与货位流水号]
      var Data = this.CreateData('12', '仓储管理_物料出库_新', param)
      this.ExecDatabase(Data).then(response => {
        if (response.data[0].result === '1') {
          this.$message.success('出库成功')
          this.exWarehouse = false
          this.exWarehouse1 = false
          this.tableData = []
          var param = []
          param[0] = ['领料单流水号', this.pickingList]
          var Data = this.CreateData('11', '装配管理_领料单明细_查询', param)
          this.ExecDatabase(Data).then(response => {
            this.tableData = response.data
            if (response.data.length === 0) {
              this.searchTable()
            } else {
              this.maxNumber = this.tableData[this.outIndex].本次领用
            }
          })
        } else {
          this.$message.error('出库失败')
          this.exWarehouse = false
          this.exWarehouse1 = false
        }
      })
    },
    selectable(row) {
      return row.本次领用 > 0
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    /* materialOut() {
        if (this.multipleSelection.length !== 0) {
          const materialGroup = []
          const numberGroup = []
          const partGroup = []
          const pickNumberGroup = []
          const temporaryGroup = []
          const purchaseGroup = []
          const productGroup = []
          const pickGroup = []
          const groupGroup = []
          this.multipleSelection_variable = this.multipleSelection
          this.multipleSelection = []
          for (let i = 0; i < this.multipleSelection_variable.length; i++) {
            materialGroup[i] = this.multipleSelection_variable[i].物料流水号
            numberGroup[i] = this.multipleSelection_variable[i].本次领用
            partGroup[i] = this.multipleSelection_variable[i].基本件流水号
            pickNumberGroup[i] = this.multipleSelection_variable[i].领料流水号
            temporaryGroup[i] = this.multipleSelection_variable[i].临时流水号
            purchaseGroup[i] = this.multipleSelection_variable[i].标准件和外购件流水号
            productGroup[i] = this.multipleSelection_variable[i].产品流水号
            pickGroup[i] = this.multipleSelection_variable[i].领料单明细流水号
            groupGroup[i] = this.multipleSelection_variable[i].组件流水号
          }
          var param = []
          param[0] = ['物料流水号组', materialGroup]
          param[1] = ['出库数量组', numberGroup]
          param[2] = ['基本件流水号组', partGroup]
          param[3] = ['标准件和外购件流水号组', purchaseGroup]
          param[4] = ['领料单明细流水号组', pickGroup]
          param[5] = ['产品流水号组', productGroup]
          param[6] = ['组件流水号组', groupGroup]
          param[7] = ['领料流水号组', pickNumberGroup]
          param[8] = ['临时流水号组', temporaryGroup]
          param[9] = ['出库人流水号', this.id]
          param[10] = ['领料人流水号', this.pickingPeople]
          param[11] = ['领料单流水号', this.pickingList]
          param[12] = ['是否部件', this.isGroup]
          var Data = this.CreateData('12', '仓储管理_出库', param)
          this.ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('出库成功')
              this.searchTable()
              this.tableData = []
              var param = []
              param[0] = ['领料单流水号', this.pickingList]
              var Data = this.CreateData('11', '装配管理_领料单明细_查询', param)
              this.ExecDatabase(Data).then(response => {
                this.tableData = response.data
              })
            } else {
              this.$message.error('出库失败')
            }
          })
        } else {
          this.$message.warning('请选择物料')
        }
      },*/
    searchTable2() {
      let codeCheck, check
      this.ConsumableCodeSelect ? codeCheck = 1 : codeCheck = 0
      this.ConsumableSelect ? check = 1 : check = 0
      var param = []
      param[0] = ['物料名称_check', check]
      param[1] = ['物料名称', this.ConsumableSelect]
      param[2] = ['物料编码_check', codeCheck]
      param[3] = ['物料编码', this.ConsumableCodeSelect]
      var Data = this.CreateData('11', '仓储管理_耗材出库_查询', param, this.pageSize, this.pageCurrent)
      this.ExecDatabase(Data).then(response => {
        this.Consumables = []
        this.Consumables = response.data.rows
        this.total = response.data.total
      })
    },
    // 加底色
    tableRowClassName1({ row, rowIndex }) {
      if (row.申请数 === row.已领数) {
        return 'gray'
      } else if (Number(row.申请数) - Number(row.已领数) > Number(row.库存数)) {
        return 'red'
      }
    },
    Delivery(row) {
      this.exWarehouse3 = true
      // if (this.$refs['form'] !== undefined) {
      //   this.$refs['form'].resetFields()
      // }
      // this.materialName = row.物料名称
      // this.form.领用数量 = ''
      // this.form.领用人 = ''
      // this.number = row.累计库存流水号
      // this.type = row.类型流水号
      // this.stock = Number(row.库存)
      // this.dialogFormVisible = true
      if (row.领用人 === null || row.领用人 === '' || row.领用人 === undefined) {
        this.$message.error('请选择领用人！！')
        this.exWarehouse3 = false
      } else if (row.本次领用 === 0) {
        this.$message.error('本次领用数不能为空！！')
        this.exWarehouse3 = false
      } else {
        var param = []
        param[0] = ['累计库存流水号', this.number]
        param[1] = ['类型流水号', this.type]
        param[2] = ['领用数量', row.本次领用]
        param[3] = ['领料人流水号', row.领用人]
        param[4] = ['出库人流水号', this.id]
        param[5] = ['物料与货位流水号', row.物料与货位流水号]
        param[6] = ['备注', row.备注]
        var Data = this.CreateData('12', '仓储管理_耗材出库', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('出库成功')
            this.exWarehouse3 = false
            var param = []
            param[0] = ['物料流水号', row.物料流水号]
            var Data = this.CreateData('11', '装配管理_领料单明细_批次查询', param, this.pageSize3, this.pageCurrent3)
            this.ExecDatabase(Data).then(response => {
              this.gridData1 = response.data.rows
              this.total3 = response.data.total
            })
            this.searchTable2()
          } else {
            this.$message.success('出库失败')
            this.exWarehouse3 = false
          }
        })
      }
    },
    // submit(formName) {
    //   this.$refs[formName].validate((valid) => {
    //     if (valid) {
    //       var param = []
    //       param[0] = ['累计库存流水号', this.number]
    //       param[1] = ['类型流水号', this.type]
    //       param[2] = ['领用数量', this.form.领用数量]
    //       param[3] = ['领料人流水号', this.form.领用人]
    //       param[4] = ['出库人流水号', this.id]
    //       param[5] = ['物料与货位流水号', row.物料与货位流水号]
    //       var Data = this.CreateData('12', '仓储管理_耗材出库', param)
    //       this.ExecDatabase(Data).then(response => {
    //         if (response.data[0].result === '1') {
    //           this.$message.success('出库成功')
    //           this.searchTable2()
    //           this.dialogFormVisible = false
    //         } else {
    //           this.$message.success('出库失败')
    //         }
    //       })
    //     }
    //   })
    // },
    callOff(formName) {
      this.form = {}
      this.dialogFormVisible = false
      this.$refs[formName].resetFields()
    },
    tableRowClassName({ row, rowIndex }) {
      if (Number(row.是否部件) === 1) {
        return 'is-group'
      } else if (row.库存状态 === 1) {
        return 'red'
      }
    },
    handleSizeChanges(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable2()
    },
    handleCurrentChanges(val) {
      this.pageCurrent = val
      this.searchTable2()
    },
    handleCurrentChanges3(val) {
      this.pageCurrent3 = val
      this.searchTable3()
    },
    handleCurrentChanges4(val) {
      this.pageCurrent4 = val
      var param = []
      param[0] = ['物料流水号', this.materialNumber]
      var Data = this.CreateData('11', '装配管理_领料单明细_批次查询', param, this.pageSize4, this.pageCurrent4)
      this.ExecDatabase(Data).then(response => {
        this.gridData1 = response.data.rows
        this.total4 = response.data.total
      })
    },
    searchTable3() {
      var param = []
      param[0] = ['物料流水号', this.materialSerialNumber]
      var Data = this.CreateData('11', '装配管理_领料单明细_批次查询', param, this.pageSize3, this.pageCurrent3)
      this.ExecDatabase(Data).then(response => {
        this.gridData = response.data.rows
        this.total3 = response.data.total
      })
    },
    showDelivery1(row) {
      this.exWarehouse2 = true
      this.number = row.累计库存流水号
      this.type = row.类型流水号
      this.materialNumber = row.物料流水号
      var param = []
      param[0] = ['物料流水号', row.物料流水号]
      var Data = this.CreateData('11', '装配管理_领料单明细_批次查询', param, this.pageSize4, this.pageCurrent4)
      this.ExecDatabase(Data).then(response => {
        this.exWarehouse2 = false
        this.gridData1 = response.data.rows
        this.total4 = response.data.total
      })
    }
  }
}
</script>
<style scoped lang="scss">
  /deep/ .el-card__body{
    padding: 0px!important;
  }
  /deep/ .el-table .gray {
    background: #bbbbc1 !important;
  }
  /deep/ .el-table .red {
    background: #e88383 !important;
  }
</style>
<style>
  .el-table .is-group {
    background: #FFF582!important;
  }
</style>
