<template>
  <div class="app-container">
    <el-card style="height: 850px;padding: 0">
      <el-tabs
        v-model="PartType"
        type="border-card"
        style="height: 850px;padding: 0"
        @tab-click="handleTabClick">
        <el-tab-pane label="采购入库" name="采购入库">
          <div style="margin-top: 7px; margin-bottom: 7px">
            <el-select
              v-model="supplierSelectionValue"
              style="width:230px"
              placeholder="选择供应商"
              size="small"
              filterable
              clearable
              @change="handleSupplierChange">
              <el-option
                v-for="item in supplierSelection"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-select
              v-model="contractStateValue"
              style="width:180px;margin-left: 10px"
              placeholder="选择合同"
              size="small"
              filterable
              clearable
              @change="searchTable1()">
              <el-option
                v-for="item in contractState"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-button
              type="primary"
              icon="el-icon-s-home"
              style="margin-left: 10px"
              plain
              size="small"
              @click="submitInStorage">入库
            </el-button>
          <el-badge :value="tableDataRKDMerged ? tableDataRKDMerged.length : 0" class="item">
            <el-button
              type="primary"
              icon="el-icon-s-home"
              style="margin-left: 10px"
              plain
              size="small"
              @click="showRKDDialog">入库单
            </el-button>
          </el-badge>
            <!-- <el-button
              type="primary"
              icon="el-icon-check"
              style="margin-left: 10px"
              plain
              size="small"
              @click="selectInStockableRows">勾选当前页可入库项
            </el-button> -->
            <el-button
              type="primary"
              icon="el-icon-printer"
              style="margin-left: 630px"
              plain
              size="small"
              @click="Pronters()">批量打印
            </el-button>
          </div>
          <div>
            <el-table
              v-loading="loading"
              ref="table"
              :data="tableData1"
              highlight-current-row
              border
              stripe
              size="small"
              style="width: 1301px"
              height="740px"
              @selection-change="handleSelectionChange">
              <el-table-column :selectable="selectable" type="selection" align="center" width="50px"/>
              <el-table-column label="供应商" align="center" show-overflow-tooltip width="150px">
                <template slot-scope="scope">
                  {{ scope.row.供应商 }}
                </template>
              </el-table-column>
              <el-table-column label="采购合同号" align="center" show-overflow-tooltip width="150px">
                <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-column
                :width="setColumnWidth('图号或型号')"
                label="图号型号"
                prop="图号型号"
                align="center"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.图号或型号 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('单位')" label="单位" align="center">
                <template slot-scope="scope">
                  {{ scope.row.单位 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('备注')" label="备注" align="center">
                <template slot-scope="scope">
                  {{ scope.row.备注 }}
                </template>
              </el-table-column>
              <el-table-column width="120px" label="库位" align="center">
                <template slot-scope="scope">
                  <el-select v-if="scope.row._editing" v-model="scope.row.货位流水号" style="width:100%" placeholder="选择库位" size="mini" filterable clearable @change="onLocateChange(scope.row)">
                    <el-option
                      v-for="item in scope.row.locateName"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"/>
                  </el-select>
                  <span v-else>{{ scope.row.货位名称 }}</span>
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('数量')" label="采购数" prop="采购数" align="center">
                <template slot-scope="scope">
                  {{ scope.row.采购数 ? Number(scope.row.采购数).toFixed(2) : '' }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('数量')" label="已到数" prop="已到数" align="center">
                <template slot-scope="scope">
                  {{ scope.row.已到数 ? Number(scope.row.已到数).toFixed(2) : '' }}
                </template>
              </el-table-column>
              <el-table-column width="140px" label="本次到货数" prop="本次到货数" align="center">
                <template slot-scope="scope">
                  <el-input-number
                    v-model=" scope.row.本次到货数"
                    :min="0"
                    :max="scope.row.等待入库数量 ? scope.row.等待入库数量 : scope.row.采购数"
                    size="mini"
                    style="margin: 0;width: 100%"/>
                </template>
              </el-table-column>
              <el-table-column width="170px" label="批次编码" align="center">
                <template slot-scope="scope">
                  {{ scope.row.批次编码 }}
                </template>
              </el-table-column>
              <el-table-column width="120px" label="打印条码数" prop="打印条码数" align="center">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.打印条码数" :min="1" size="mini" style="margin: 0;width: 100%"/>
                </template>
              </el-table-column>
              <el-table-column width="140px" label="操作" align="center" show-overflow-tooltip fixed="right">
                <template slot-scope="scope">
                  <el-button type="text" size="small" @click="toggleRowEdit(scope.row)">{{ scope.row._editing ? '完成' : '库位' }}</el-button>
                  <el-button type="text" icon="el-icon-printer" size="small" @click="Pronter(scope.row)"/>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
        <!--<el-tab-pane label="退料入库" name="退料入库">
          <div style="margin-top: 7px; margin-bottom: 7px">
            <el-input v-model="materialNameTypeValue" style="width:200px" placeholder="物料名称规格型号" size="small" clearable @keyup.enter.native="pageSize=40;pageCurrent=1;searchTable2()"/>
            <el-button type="primary" style="margin-left: 10px" plain size="small" @click="submitInStorage1">入库</el-button>
          </div>
          <div style="margin-top: 20px">
            <el-table
              v-loading="loading"
              ref="table1"
              :data="tableData2"
              highlight-current-row
              show-summary
              border
              stripe
              size="small"
              style="width: 711px"
              height="580px"
              @selection-change="handleSelectionChange1">
              <el-table-column :selectable="selectable1" type="selection" align="center" width="50px"/>
              <el-table-column width="150px" label="物料名称" align="center" show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.物料名称 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('图号型号')" label="图号型号" align="center" prop="图号型号" show-overflow-tooltip>
                <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="1" size="mini" style="margin: 0;width: 100%"/>
                </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="80px" label="库位" align="center">
                <template slot-scope="scope">
                  {{ scope.row.货位名称 }}
                </template>
              </el-table-column>
              <el-table-column label="退件人" align="center">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.退件人" style="width:100%" placeholder="选择人员" size="mini" filterable clearable>
                    <el-option
                      v-for="item in peopleList"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"/>
                  </el-select>
                </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-tab-pane>-->
        <el-tab-pane label="自制件入库" name="自制件入库">
          <div style="margin-top: 7px; margin-bottom: 7px">
            <el-select
              v-model="orderSelectionValue"
              style="width:200px"
              placeholder="选择订单号"
              size="small"
              filterable
              clearable
              @change="searchTable3(),getnumberSelection()">
              <el-option
                v-for="item in orderSelection"
                :key="item.index"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-input
              v-model="numberSelectionValue"
              style="width: 200px"
              size="small"
              clearable
              placeholder="零件名称/图号"
              @keyup.enter.native="searchTable3()"/>
            <!--<el-select v-model="numberSelectionValue" style="width:200px;margin-left: 10px" placeholder="选择零件名称/图号" size="small" filterable clearable @change="searchTable3()">
              <el-option
                v-for="item in numberSelection"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                &lt;!&ndash;                <b style="float: left">{{ item.label }}</b>&ndash;&gt;
                &lt;!&ndash;                <b style="float: right; color: #8492a6; font-size: 13px">&nbsp;&nbsp;{{ item.name }}</b>&ndash;&gt;
              </el-option>
            </el-select>-->
            <el-button
              type="primary"
              icon="el-icon-s-home"
              style="margin-left: 10px"
              plain
              size="small"
              @click="submitInStorage2">入库
            </el-button>
            <!-- 修改人:Ld 修改时间:2026-07-14 09:05:57; 自制件入库增加入库单入口，按自制件类型加载待入库单 -->
            <el-badge :value="selfMadeRKDCount" class="item">
              <el-button
                type="primary"
                icon="el-icon-s-home"
                style="margin-left: 10px"
                plain
                size="small"
                @click="showSelfMadeRKDDialog">入库单
              </el-button>
            </el-badge>
          </div>
          <div>
            <el-table
              v-loading="loading"
              ref="table2"
              :data="tableData3"
              highlight-current-row
              border
              stripe
              size="small"
              style="width: 1471px"
              height="700px"
              @selection-change="handleSelectionChange2"
              @sort-change="sortChange">
              <el-table-column :selectable="selectable2" type="selection" align="center" width="50px"/>
              <el-table-column
                width="90px"
                label="类型"
                align="center"
                show-overflow-tooltip
                sortable="类型"
                prop="类型">
                <template slot-scope="scope">
                  {{ scope.row.类型 }}
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('零件名称')"
                label="名称"
                align="center"
                sortable="零件名称"
                prop="零件名称">
                <template slot-scope="scope">
                  {{ scope.row.零件名称 }}
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('图号或型号')"
                label="图号"
                align="center"
                sortable="零件图号"
                prop="零件图号">
                <template slot-scope="scope">
                  {{ scope.row.零件图号 }}
                </template>
              </el-table-column>
              <el-table-column width="120px" label="库位" align="center">
                <template slot-scope="scope">
                  <el-select v-if="scope.row._editing" v-model="scope.row.货位流水号" style="width:100%" placeholder="选择库位" size="mini" filterable clearable @change="onLocateChange(scope.row)">
                    <el-option
                      v-for="item in scope.row.locateName"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"/>
                  </el-select>
                  <span v-else>{{ scope.row.货位名称 }}</span>
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('数量')"
                label="加工数"
                align="center"
                prop="批次数量"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.批次数量 ? Number(scope.row.批次数量).toFixed(2) : '' }}
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('数量')"
                label="完成数"
                align="center"
                prop="完成数量"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.完成数量 ? Number(scope.row.完成数量).toFixed(2) : '' }}
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('数量')"
                label="已入库"
                align="center"
                prop="入库数量"
                show-overflow-tooltip>
                <template slot-scope="scope">
                  {{ scope.row.入库数量 ? Number(scope.row.入库数量).toFixed(2) : '' }}
                </template>
              </el-table-column>
              <el-table-column width="150px" label="本次入库" prop="本次入库" align="center">
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.本次入库"
                    :max="Number(scope.row.最大值)"
                    :min="1"
                    size="mini"
                    style="margin: 0;width: 100%"/>
                </template>
              </el-table-column>
              <el-table-column
                :width="setColumnWidth('订单号')"
                label="订单号"
                align="center"
                sortable="订单号"
                prop="订单号">
                <template slot-scope="scope">
                  {{ scope.row.订单号 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('产品名称')" label="产品部件名称" align="center">
                <template slot-scope="scope">
                  {{ scope.row.产品名称 }}
                </template>
              </el-table-column>
              <el-table-column width="137px" label="批次编码" align="center">
                <template slot-scope="scope">
                  {{ scope.row.批次编码 }}
                </template>
              </el-table-column>
              <el-table-column width="150px" label="打印条码数" prop="打印条码数" align="center">
                <template slot-scope="scope">
                  <el-input-number v-model="scope.row.打印条码数" :min="1" size="mini" style="margin: 0;width: 100%"/>
                </template>
              </el-table-column>
              <el-table-column width="100px" label="操作" align="center">
                <template slot-scope="scope">
                  <el-button type="text" size="small" @click="toggleRowEdit(scope.row)">{{ scope.row._editing ? '完成' : '编辑' }}</el-button>
                  <el-button type="text" icon="el-icon-printer" size="small" @click="Pronter1(scope.row)"/>
                </template>
              </el-table-column>
            </el-table>
            <div class="block" style="margin-top: 10px;">
              <el-pagination
                :current-page="pageCurrent1"
                :page-sizes="[10, 20, 30, 40, 100]"
                :page-size="pageSize1"
                :total="total1"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChanges1"
                @current-change="handleCurrentChanges1"/>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="外协到货" name="外协到货">
          <div style="margin-top: 7px; margin-bottom: 7px">
            <el-select
              v-model="selectTheOutsourcingManufacturersValue"
              style="width:150px"
              placeholder="选择外协厂家"
              size="small"
              filterable
              clearable
              @change="searchTable10();getTransferNotes()">
              <el-option
                v-for="item in selectTheOutsourcingManufacturers"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-select
              v-model="selectTheDialListValue"
              style="width:150px"
              placeholder="选择调拨单"
              size="small"
              filterable
              clearable
              @change="searchTable10()">
              <el-option
                v-for="item in transferNotes"
                :key="item.value"
                :label="item.label"
                :value="item.value"/>
            </el-select>
            <el-button
              type="primary"
              icon="el-icon-s-home"
              style="margin-left: 10px"
              plain
              size="small"
              @click="submitInStorage3">入库/入库单
            </el-button>
          </div>
          <div>
            <el-table
              :data="tableData30"
              highlight-current-row
              border
              stripe
              size="small"
              style="width: 1161px"
              height="740px"
              @selection-change="handleSelectionChange3">
              <el-table-column :selectable="selectable3" type="selection" align="center" width="50px"/>
              <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>
                <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>
                <template slot-scope="scope">
                  {{ scope.row.工件名称 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('图号或型号')" label="图号" align="center">
                <template slot-scope="scope">
                  {{ scope.row.图号 }}
                </template>
              </el-table-column>
              <el-table-column :width="setColumnWidth('工序')" label="工序" align="center">
                <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" prop="调拨数量">
                <template slot-scope="scope">
                  {{ scope.row.调拨数量 ? Number(scope.row.调拨数量).toFixed(2) : '' }}
                </template>
              </el-table-column>
              <el-table-column width="150px" label="到货数量" prop="到货数量" align="center">
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.到货数量"
                    :max="scope.row.调拨数量-scope.row.已到货数量"
                    :min="1"
                    size="mini"
                    style="margin: 0;width: 100%"/>
                </template>
              </el-table-column>
              <el-table-column label="已到数" align="center" prop="已到货数量">
                <template slot-scope="scope">
                  {{ scope.row.已到货数量 ? Number(scope.row.已到货数量).toFixed(2) : '' }}
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <el-dialog v-el-drag-dialog :visible.sync="dialogFormVisibleRKD" title="入库单" center width="700px">
      <el-table :data="tableDataRKDMerged" border stripe size="small" height="400px">
        <el-table-column prop="入库单号" label="入库单号" align="center" show-overflow-tooltip/>
        <el-table-column v-if="rkdDialogType === '采购'" prop="采购合同号" label="采购合同" align="center" show-overflow-tooltip/>
        <el-table-column v-if="rkdDialogType === '采购'" prop="供应商名称" label="供应商" align="center" show-overflow-tooltip/>
        <!-- 修改人:Ld 修改时间:2026-07-14 09:05:57; 自制件入库单弹窗显示订单信息 -->
        <el-table-column v-if="rkdDialogType === '自制'" prop="订单号" label="订单号" align="center" show-overflow-tooltip/>
        <el-table-column v-if="rkdDialogType === '自制'" prop="类型" label="类型" align="center" show-overflow-tooltip/>
        <el-table-column prop="到货数" label="到货数" align="center" show-overflow-tooltip/>
        <el-table-column label="操作" align="center" width="80px">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="selectRKDRow(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-card v-show="false">
      <div style="width:900px;margin-left: 350px">
        <el-card>
          <div id="WGBLD" style="width: 880px;margin: 0 auto">
            <div style="width: 260px;margin: 0 auto 20px">
              <!--              调整这一个即可解决 打印出来表头布局中的问题-->
              <h3>浙江景耀数控采购入库单</h3>
            </div>
            <div style="margin: 0 0 20px">
              <span style="float: left;margin-left: 10px;font-size: 14px">供应商：{{ supplierSelectionName }}</span>
              <span style="float: right; font-size: 14px;margin-right: 10px">采购单号：{{ contractNumber }}</span>
              <span style="float: right;margin-right: 60px;font-size: 14px; width: 130px">日期：{{ NowTime }}</span>
            </div>
            <table cellspacing="0px" align="center" border="1 solid black" width="100%">
              <tr id="tablehead12" style="height: 35px">
                <td colspan="3" style="text-align: center;width: 15%;font-size: 16px">物料编码</td>
                <td colspan="4" style="text-align: center;width: 20%;font-size: 16px">物料名称</td>
                <td colspan="4" style="text-align: center;width: 22%;font-size: 16px">规格型号</td>
                <td colspan="2" style="text-align: center;width: 12%;font-size: 16px">库位</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: 16px">数量</td>
                <td colspan="5" style="text-align: center;width: 19%;font-size: 16px">采购备注</td>
              </tr>
              <tr v-for="(list, index) in returns" :key="index" style="height: 35px">
                <td colspan="3" style="text-align: center;width: 15%;font-size: 16px">{{ list.物料编码 }}</td>
                <td colspan="4" style="text-align: center;width: 20%;font-size: 16px">{{ list.物料名称 }}</td>
                <td colspan="4" style="text-align: center;width: 22%;font-size: 16px">{{ list.规格型号 }}</td>
                <td colspan="2" style="text-align: center;width: 12%;font-size: 16px">{{ list.库位 }}</td>
                <td colspan="1" style="text-align: center;width: 6%;font-size: 16px">{{ list.单位 }}</td>
                <td colspan="1" style="text-align: center;width: 6%;font-size: 16px">{{ list.数量 }}</td>
                <td colspan="5" style="text-align: center;width: 19%;font-size: 16px">{{ list.采购备注 }}</td>
              </tr>
              <tr style="height: 35px">
                <td colspan="3" style="text-align: center;width: 15%;font-size: 16px">合计</td>
                <td colspan="17" style="text-align: center;width: 85%">
                  <div>
                    <span style="float: right;margin-right: 24%;font-size: 16px">{{ Number(totalAmount) }}</span>
                  </div>
                </td>
              </tr>
            </table>
            <div style="margin-top: 20px"><span style="margin-left: 10px;font-size: 16px">审核：</span><span
              style="margin-left: 15%;font-size: 16px">记账：</span><span
                style="margin-left: 15%;font-size: 16px">验收：</span><span
                  style="margin-left: 15%;font-size: 16px">保管：</span><span
                    style="margin-left: 15%;font-size: 16px">制单：</span></div>
          </div>
        </el-card>
      </div>
    </el-card>
    <el-card v-show="false">
      <div style="width:900px;margin-left: 350px">
        <el-card>
          <div id="WGBLD1" style="width: 880px;margin: 0 auto">
            <div style="width: 117px;margin: 0 auto 20px">
              <!--              调整这一个即可解决 打印出来表头布局中的问题-->
              <h3>仓库调拨单</h3>
            </div>
            <div style="margin-bottom: 10px">
              <span style="float: left;margin-left: 10px;font-size: 16px">日期：{{ NowTime }}</span><span
                style="float: right;font-size: 16px;margin-right: 20px">编号：{{ supplierSelectionName4 }}</span>
            </div>
            <table cellspacing="0px" align="center" border="1 solid black" width="100%">
              <tr style="height: 35px">
                <td colspan="3" style="text-align: center;width: 14%;font-size: 16px">物料编码</td>
                <td colspan="4" style="text-align: center;width: 20%;font-size: 16px">物料名称</td>
                <td colspan="4" style="text-align: center;width: 20%;font-size: 16px">规格型号</td>
                <td colspan="2" style="text-align: center;width: 10%;font-size: 16px">调出仓库</td>
                <td colspan="3" style="text-align: center;width: 14%;font-size: 16px">调入仓库</td>
                <td colspan="1" style="text-align: center;width: 5%;font-size: 16px">单位</td>
                <td colspan="1" style="text-align: center;width: 5%;font-size: 16px">数量</td>
                <td colspan="2" style="text-align: center;width: 8%;font-size: 16px">备注</td>
              </tr>
              <tr v-for="(list, index) in returns1" :key="index" style="height: 35px">
                <td colspan="3" style="text-align: center;width: 14%;font-size: 16px">{{ list.物料编码 }}</td>
                <td colspan="4" style="text-align: center;width: 20%;font-size: 16px">{{ list.物料名称 }}</td>
                <td colspan="4" style="text-align: center;width: 20%;font-size: 16px">{{ list.规格型号 }}</td>
                <td colspan="2" style="text-align: center;width: 10%;font-size: 16px">{{ list.调出仓库 }}</td>
                <td colspan="3" style="text-align: center;width: 14%;font-size: 16px">{{ list.调入仓库 }}</td>
                <td colspan="1" style="text-align: center;width: 5%;font-size: 16px">{{ list.单位 }}</td>
                <td colspan="1" style="text-align: center;width: 5%;font-size: 16px">{{ list.数量 }}</td>
                <td colspan="2" style="text-align: center;width: 5%;font-size: 16px">{{ list.备注 }}</td>
              </tr>
              <tr style="height: 35px">
                <td colspan="3" style="text-align: center;width: 15%;font-size: 16px">合计</td>
                <td colspan="17" style="text-align: center;width: 85%">
                  <div>
                    <span style="float: right;margin-right: 7%;font-size: 16px">{{ Number(totalAmount1) }}</span>
                  </div>
                </td>
              </tr>
            </table>
            <div style="margin-top: 20px"><span style="margin-left: 10px;font-size: 16px">审核：</span><span
              style="margin-left: 15%;font-size: 16px">记账：</span><span
                style="margin-left: 15%;font-size: 16px">验收：</span><span
                  style="margin-left: 15%;font-size: 16px">保管：</span><span
                    style="margin-left: 15%;font-size: 16px">制单：</span></div>
          </div>
        </el-card>
      </div>
    </el-card>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { wsuri } from '@/utils/request'
import { getNowDAY } from '../../../utils'
import $ from 'jquery'

export default {
  data() {
    return {
      returns: [],
      returns1: [],
      NowTime: getNowDAY(),
      totalAmount: '',
      totalAmount1: '',
      supplierSelectionValue: '', // 选择供应商名称
      supplierSelectionName: '', // 选择供应商名称
      supplierSelection: [], // 选择供应商数组
      orderSelectionValue: '', // 选择订单号
      orderSelection: [], // 选择订单号数组
      numberSelectionValue: '', // 零件名称
      numberSelection: [], // 零件名称数组
      locateNumber: '', // 选择库位
      locateName: [], // 选择库位数组
      selectTheOutsourcingManufacturersValue: '', // 选择外协厂家
      selectTheOutsourcingManufacturers: [], // 选择外协厂家数组
      selectTheDialListValue: '', // 选择调拨单
      transferNotes: [], // 选择调拨单数组
      supplierSelectionName4: '',
      peopleList: [],
      materialNameTypeValue: '', // 物料名称规格型号
      PartType: '采购入库',
      multipleSelection: [],
      multipleSelection_variable: [],
      multipleSelection1: [],
      multipleSelection_variable1: [],
      multipleSelection2: [],
      multipleSelection_variable2: [],
      multipleSelection3: [],
      multipleSelection_variable3: [],
      dateRange: '', // 提交日期
      contractStateValue: '', // 合同状态
      contractNumber: '', // 合同状态
      contractState: [], // 合同状态数组
      loading: false, // 数据加载
      total: 0, // 分页总数
      total1: 0, // 分页总数
      tableData1: [], // 合同信息表
      tableData2: [], // 合同信息表
      tableData3: [], // 合同信息表
      tableData30: [], // 合同信息表
      dialogFormVisibleRKD: false,
      rkdDialogType: '采购', // 修改人:Ld 修改时间:2026-07-14 09:05:57; 区分采购/自制件入库单弹窗
      tableDataRKD: [],
      pageCurrent: 1, // 分页当前页
      pageSize: 30, // 分页每页显示条数
      pageCurrent1: 1, // 分页当前页
      pageSize1: 30, // 分页每页显示条数
      orderName: '', // 排序列名
      order: '' // 排序方式
    }
  },
  computed: {
    ...mapGetters([
      'id',
      'token'
    ]),
    tableDataRKDMerged() {
      var map = {}
      var result = []
      for (var i = 0; i < this.tableDataRKD.length; i++) {
        var row = this.tableDataRKD[i]
        var key = row.入库单号
        if (map[key] !== undefined) {
          result[map[key]].到货数 = Number(result[map[key]].到货数 || 0) + Number(row.到货数 || 0)
        } else {
          map[key] = result.length
          result.push(Object.assign({}, row, { 到货数: Number(row.到货数 || 0) }))
        }
      }
      return result
    },
    selfMadeRKDCount() {
      // 修改人:Ld 修改时间:2026-07-14 09:05:57; 统计自制件待入库单数量用于按钮角标
      var count = 0
      for (var i = 0; i < this.tableDataRKD.length; i++) {
        if (this.tableDataRKD[i].类型 === '自制') {
          count++
        }
      }
      return this.rkdDialogType === '自制' ? this.tableDataRKDMerged.length : count
    }
  },
  updated() {
    if (this.$refs['']) {
      this.$nextTick(() => {
        this.$refs['table'].doLayout()
        this.$refs['table1'].doLayout()
        this.$refs['table2'].doLayout()
      })
    }
  },
  created() {
    this.getSupplierSelection()
    this.getPeople()
    this.getSelectTheOutsourcingManufacturers()
    this.initWebpack()
    this.getorderSelection()
    this.loadRKDCounter()
    this.getLocateName()
    // this.searchTable1()
  },
  methods: {
    loadRKDCounter() {
      // 修改人:Ld 修改时间:2026-07-14 09:05:57; 默认加载采购入库单数量，避免采购页混入自制件入库单
      this.loadRKDData('采购', false)
    },
    loadRKDData(type, showDialog) {
      // 修改人:Ld 修改时间:2026-07-14 09:05:57; 按采购/自制类型统一加载入库单数据
      var param = []
      param[0] = ['类型_check', 1]
      param[1] = ['类型', type]
      var Data = this.CreateData('11', '仓储管理_入库单_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableDataRKD = response.data.filter(item => item.是否入库 === 0 || item.是否入库 === false)
        if (showDialog) {
          this.dialogFormVisibleRKD = true
        }
      })
    },
    handleSupplierChange() {
      this.contractStateValue = ''
      this.contractNumber = ''
      this.contractState = []
      if (!this.supplierSelectionValue) {
        this.supplierSelectionName = ''
        this.tableData1 = []
        this.multipleSelection = []
        this.returns = []
        this.totalAmount = ''
        this.$nextTick(() => {
          if (this.$refs.table) {
            this.$refs.table.clearSelection()
          }
        })
        return
      }
      this.getContractState()
      this.searchTable1()
      this.onChangeSupplierSelection()
    },
    onChangeSupplierSelection() {
      let obj = {}
      obj = this.supplierSelection.find((item) => {
        return item.value === this.supplierSelectionValue
      })
      this.supplierSelectionName = obj ? obj.label : ''
    },
    showRKDDialog() {
      this.rkdDialogType = '采购'
      this.loadRKDData('采购', true)
    },
    showSelfMadeRKDDialog() {
      // 修改人:Ld 修改时间:2026-07-14 09:05:57; 自制件入库页打开自制件入库单列表
      this.rkdDialogType = '自制'
      this.loadRKDData('自制', true)
    },
    selectRKDRow(row) {
      if (this.rkdDialogType === '自制') {
        this.orderSelectionValue = Number(row.订单流水号) || row.订单流水号
        this.numberSelectionValue = ''
        this.getnumberSelection()
        this.searchTable3()
        this.dialogFormVisibleRKD = false
        return
      }
      this.supplierSelectionValue = row.供应商流水号
      this.getContractState()
      this.$nextTick(() => {
        this.contractStateValue = row.采购合同流水号
        this.searchTable1()
        this.orderSelectionValue = row.供应商
      })
      this.dialogFormVisibleRKD = false
    },
    handleTabClick() {
      // 修改人:Ld 修改时间:2026-07-14 09:05:57; 切换页签时刷新对应类型的入库单数量
      this.pageCurrent = 1
      this.pageCurrent1 = 1
      this.rkdDialogType = this.PartType === '自制件入库' ? '自制' : '采购'
      this.loadRKDData(this.rkdDialogType, false)
    },
    exportTable() {
      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()
    },
    exportTable1() {
      const htmlNode = $('#WGBLD1').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()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      this.totalAmount = 0
      this.returns = []
      if (this.multipleSelection.length !== 0) {
        console.log('选中的数据', this.multipleSelection)
        for (let i = 0; i < this.multipleSelection.length; i++) {
          this.totalAmount = this.totalAmount + Number(this.multipleSelection[i].本次到货数)
          this.returns.push({
            物料编码: this.multipleSelection[i].物料编码,
            物料名称: this.multipleSelection[i].物料名称,
            规格型号: this.multipleSelection[i].图号或型号,
            单位: this.multipleSelection[i].单位,
            数量: this.multipleSelection[i].本次到货数,
            采购备注: this.multipleSelection[i].备注,
            库位: this.multipleSelection[i].货位名称
          })
        }
      }
    },
    handleSelectionChange3(val) {
      this.multipleSelection3 = val
      this.returns1 = []
      if (this.multipleSelection3.length !== 0) {
        console.log('选中的数据', this.multipleSelection3)
        for (let i = 0; i < this.multipleSelection3.length; i++) {
          this.totalAmount1 = this.totalAmount1 + Number(this.multipleSelection3[i].到货数量)
          this.returns1.push({
            物料编码: this.multipleSelection3[i].物料编码,
            物料名称: this.multipleSelection3[i].工件名称,
            规格型号: this.multipleSelection3[i].图号,
            调入仓库: '精工车间',
            调出仓库: this.multipleSelection3[i].外协厂家,
            单位: this.multipleSelection3[i].单位,
            数量: this.multipleSelection3[i].到货数量,
            备注: this.multipleSelection3[i].备注
          })
        }
      }
    },
    // 以上新增
    // 初始化websocket
    initWebpack() {
      this.websock = new WebSocket(wsuri)// 这里面的this都指向vue
      this.websock.onopen = this.websocketopen
      this.websock.onclose = this.websocketclose
      this.websock.onerror = this.websocketerror
    },
    Pronter(row) {
      let sendMessage
      sendMessage = 'TOCS??JY_Warehouse?PDA~'
      sendMessage = sendMessage + row.打印条码数 + this.getWord(row.打印条码数, row.物料名称, row.批次编码, row.货位名称)
      this.websock.send(sendMessage)
    },
    Pronter1(row) {
      let sendMessage
      sendMessage = 'TOCS??JY_Warehouse?PDA~'
      sendMessage = sendMessage + row.打印条码数 + this.getWord(row.打印条码数, row.零件名称, row.批次编码, row.货位名称)
      this.websock.send(sendMessage)
    },
    Pronters() {
      let sendMessage, word, number
      sendMessage = 'TOCS??JY_Warehouse?PDA~'
      word = ''
      number = 0
      for (let i = 0; i < this.multipleSelection.length; i++) {
        word = word + this.getWord(this.multipleSelection[i].打印条码数, this.multipleSelection[i].零件名称, this.multipleSelection[i].批次编码, this.multipleSelection[i].货位名称)
        number = number + Number(this.multipleSelection[i].打印条码数)
      }
      sendMessage = sendMessage + number + word
      this.websock.send(sendMessage)
    },
    getWord(number, name, val, location) {
      let word
      word = ''
      for (let i = 0; i < number; i++) {
        word = word + '~JY_Batch|BarCode^Code2^' + val + '|TEXT^TEXT0^' + location + '|TEXT^TEXT1^' + name + '|TEXT^TEXT2^' + val
      }
      return word
    },
    // 打开
    websocketopen() {
      console.log('WebSocket连接成功')
    },
    // 数据接收
    websocketonmessage(msg) {
      this.partNumberP = msg.data.split('|')[3]
      this.partNumber = this.partNumberP.slice(1)
      this.getscantable(this.partNumber)
    },
    // 关闭
    websocketclose() {
      console.log('WebSocket关闭')
    },
    // 失败
    websocketerror() {
      console.log('WebSocket连接失败')
    },
    // 订单查询
    getorderSelection() {
      var param = []
      var Data = this.CreateData('11', '自制件_订单信息_列表_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.orderSelection.push({
            label: response.data[i].订单号,
            value: response.data[i].订单流水号
          })
        }
      })
    },
    // 零件图号查询
    getnumberSelection() {
      this.numberSelectionValue = ''
      this.numberSelection = []
      if (this.orderSelectionValue) {
        var param = []
        param[0] = ['订单流水号', this.orderSelectionValue]
        var Data = this.CreateData('11', '物料入库_自制件入库_零件图号_查询数据', param)
        this.ExecDatabase(Data).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.numberSelection.push({
              label: response.data[i].零件,
              // name: response.data[i].零件名称,
              value: response.data[i].工艺计划流水号
            })
            // console.log(response.data[i].零件名称)
          }
        })
      }
    },
    getPeople() {
      var param = []
      var Data = this.CreateData('11', '人员名单_查询数据', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.peopleList.push({
            label: response.data[i].姓名,
            value: response.data[i].人员编号
          })
        }
      })
    },
    getSupplierSelection() {
      this.supplierSelectionValue = ''
      this.supplierSelection = []
      var param = []
      var Data = this.CreateData('11', '供应商_入库查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.supplierSelection.push({
            label: response.data[i].供应商名称,
            value: response.data[i].供应商流水号
          })
        }
      })
    },
    getSelectTheOutsourcingManufacturers() {
      var param = []
      var Data = this.CreateData('11', '外协厂家_到货查询', param)
      this.ExecDatabase(Data).then(response => {
        for (let i = 0; i < response.data.length; i++) {
          this.selectTheOutsourcingManufacturers.push({
            label: response.data[i].外协厂家,
            value: response.data[i].外协厂家流水号
          })
        }
      })
    },
    getTransferNotes() {
      this.transferNotes = []
      this.selectTheDialListValue = ''
      if (this.selectTheOutsourcingManufacturersValue) {
        var param = []
        param[0] = ['外协厂家流水号', this.selectTheOutsourcingManufacturersValue]
        var Data = this.CreateData('11', '仓储管理_外协调拨单列表_查询', param)
        this.ExecDatabase(Data).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.transferNotes.push({
              label: response.data[i].调拨单号,
              value: response.data[i].外协调拨单流水号
            })
          }
        })
      }
    },
    getContractState() {
      this.contractStateValue = ''
      this.contractState = []
      if (this.supplierSelectionValue) {
        let supplierSelectionValue_check
        this.supplierSelectionValue ? supplierSelectionValue_check = 1 : supplierSelectionValue_check = 0
        var param = []
        param[0] = ['供应商流水号_check', supplierSelectionValue_check]
        param[1] = ['供应商流水号', this.supplierSelectionValue]
        var Data = this.CreateData('11', '仓储管理_采购入库合同_查询', param)
        this.ExecDatabase(Data).then(response => {
          for (let i = 0; i < response.data.length; i++) {
            this.contractState.push({
              label: response.data[i].采购合同编号,
              value: response.data[i].采购合同流水号
            })
          }
          if (response.data.length === 0) {
            this.getSupplierSelection()
          }
        })
      }
    },
    getLocateName() {
      var param = []
      var Data = this.CreateData('11', '仓储管理_库位_查询', param)
      return this.ExecDatabase(Data).then(response => {
        this.locateName = []
        for (let i = 0; i < response.data.length; i++) {
          this.locateName.push({
            label: response.data[i].货位名称,
            name: response.data[i].货位名称,
            value: String(response.data[i].货位流水号)
          })
        }
      })
    },
    onLocateChange(row) {
      var locateName = row.locateName || []
      var obj = locateName.find(function(item) {
        return item.value === row.货位流水号
      })
      this.$set(row, 'selectedLocate', obj || null)
    },
    confirmLocateChange(row) {
      var locate = row.selectedLocate
      if (!locate && row.货位流水号 !== null && row.货位流水号 !== undefined && row.货位流水号 !== '') {
        locate = this.getLocateItemByValue(row.locateName, row.货位流水号)
      }
      this.$set(row, '货位名称', locate ? locate.name : '')
      this.$set(row, '货位流水号', locate ? String(locate.value) : '')
      this.updateSelectedLocate(row)
    },
    getLocateItemByValue(locateName, value) {
      var list = locateName || []
      for (let i = 0; i < list.length; i++) {
        if (String(list[i].value) === String(value)) {
          return list[i]
        }
      }
      return null
    },
    syncLocateValueByName(row) {
      var locateName = row.locateName || []
      for (let i = 0; i < locateName.length; i++) {
        if (locateName[i].name === row.货位名称) {
          this.$set(row, '货位流水号', String(locateName[i].value))
          return
        }
      }
    },
    updateSelectedLocate(row) {
      for (let i = 0; i < this.multipleSelection.length; i++) {
        if (this.multipleSelection[i] === row) {
          this.multipleSelection[i].货位流水号 = row.货位流水号
          this.multipleSelection[i].货位名称 = row.货位名称
        }
      }
      for (let i = 0; i < this.multipleSelection2.length; i++) {
        if (this.multipleSelection2[i] === row) {
          this.multipleSelection2[i].货位流水号 = row.货位流水号
          this.multipleSelection2[i].货位名称 = row.货位名称
        }
      }
      this.refreshReturnsLocate(row)
    },
    refreshReturnsLocate(row) {
      for (let i = 0; i < this.returns.length; i++) {
        if (this.returns[i].物料编码 === row.物料编码 && this.returns[i].物料名称 === row.物料名称 && this.returns[i].规格型号 === row.图号或型号) {
          this.returns[i].库位 = row.货位名称
        }
      }
    },
    getInventoryLocateName(row) {
      var materialName = row.物料名称 || row.零件名称 || ''
      var specificationsModel = row.图号或型号 || row.零件图号 || ''
      let materialName_check, specificationsModel_check
      materialName ? materialName_check = 1 : materialName_check = 0
      specificationsModel ? specificationsModel_check = 1 : specificationsModel_check = 0
      var param = []
      param[0] = ['物料名称_check', materialName_check]
      param[1] = ['物料名称', materialName]
      param[2] = ['图号或型号_check', specificationsModel_check]
      param[3] = ['图号或型号', specificationsModel]
      param[4] = ['库位_check', 0]
      param[5] = ['库位', '']
      param[6] = ['排序名称', '']
      param[7] = ['排序方式', '']
      var Data = this.CreateData('11', '仓储管理_库存盘点_查询', param)
      this.ExecDatabase(Data).then(response => {
        var locateName = []
        var data = response.data.rows || response.data
        for (let i = 0; i < data.length; i++) {
          var inventory = data[i].库存 || data[i].货位存量 || 0
          if (Number(inventory) > 0) {
            locateName.push({
              label: data[i].货位名称 + '（库存：' + inventory + '）',
              name: data[i].货位名称,
              value: String(data[i].货位流水号)
            })
          }
        }
        if (locateName.length > 0) {
          this.$set(row, 'locateName', locateName)
          this.$set(row, 'locateSource', 'inventory')
        } else {
          var setAllLocate = function() {
            this.$set(row, 'locateName', this.locateName.slice())
            this.$set(row, 'locateSource', 'all')
          }.bind(this)
          if (this.locateName.length === 0) {
            this.getLocateName().then(setAllLocate)
          } else {
            setAllLocate()
          }
        }
      })
    },
    getData() {
      if (this.PartType === '采购入库') {
        this.searchTable1()
      } else if (this.PartType === '退料入库') {
        this.searchTable2()
      } else if (this.PartType === '自制件入库') {
        this.searchTable3()
      } else if (this.PartType === '外协到货') {
        this.searchTable10()
      }
    },
    searchTable10() {
      let selectTheDialListValue_check
      this.selectTheDialListValue ? selectTheDialListValue_check = 1 : selectTheDialListValue_check = 0
      var param = []
      param[0] = ['外协厂家流水号', this.selectTheOutsourcingManufacturersValue]
      param[1] = ['外协调拨单流水号', this.selectTheDialListValue]
      param[2] = ['外协调拨单_check', selectTheDialListValue_check]
      var Data = this.CreateData('11', '仓储管理_外协到货_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData30 = response.data
      })
    },
    searchTable1() {
      if (!this.supplierSelectionValue) {
        this.tableData1 = []
        this.multipleSelection = []
        this.returns = []
        this.totalAmount = ''
        this.$nextTick(() => {
          if (this.$refs.table) {
            this.$refs.table.clearSelection()
          }
        })
        return
      }
      for (let i = 0; i < this.contractState.length; i++) {
        if (this.contractStateValue === this.contractState[i].value) {
          this.contractNumber = this.contractState[i].label
        }
      }
      let contractStateValue_check
      this.contractStateValue ? contractStateValue_check = 1 : contractStateValue_check = 0
      var param = []
      param[0] = ['供应商流水号', this.supplierSelectionValue]
      param[1] = ['采购合同流水号_check', contractStateValue_check]
      param[2] = ['采购合同流水号', this.contractStateValue]
      var Data = this.CreateData('11', '仓储管理_采购入库合同明细_查询', param)
      this.ExecDatabase(Data).then(response => {
        this.tableData1 = response.data
        console.log('采购件入库', response.data)
        for (let i = 0; i < this.tableData1.length; i++) {
          var row = this.tableData1[i]
          if (row.货位流水号 !== null && row.货位流水号 !== undefined && row.货位流水号 !== '') {
            row.货位流水号 = String(row.货位流水号)
          }
          this.$set(row, 'locateName', [])
          this.$set(row, 'selectedLocate', null)
          this.$set(row, '_editing', false)
        }
        if (this.tableData1.length === 0) {
          this.getSummaries()
        }
      })
    },
    selectable(row) {
      return (Number(row.采购数) !== Number(row.已到数)) && Number(row.本次到货数) !== 0
    },
    selectInStockableRows() {
      if (!this.$refs.table) return
      this.$refs.table.clearSelection()
      this.$nextTick(function() {
        this.tableData1.forEach(function(row) {
          if ((Number(row.采购数) !== Number(row.已到数)) && Number(row.本次到货数) !== 0) {
            this.$refs.table.toggleRowSelection(row, true)
          }
        }.bind(this))
      }.bind(this))
    },
    toggleRowEdit(row) {
      if (row._editing) {
        this.confirmLocateChange(row)
        this.$set(row, '_editing', false)
      } else {
        this.$set(row, '_editing', true)
        this.getInventoryLocateName(row)
      }
    },
    submitInStorage() {
      // this.exportTable()
      if (!this.multipleSelection || this.multipleSelection.length === 0) {
        this.$message.warning('请先选择物料')
        return
      }

      const firstContractNo = this.multipleSelection[0]['采购合同流水号']
      const hasDifferent = this.multipleSelection.some(item => item['采购合同流水号'] !== firstContractNo)

      if (hasDifferent) {
        this.$message.warning('只能选择一个合同的物料')
        return
      }
      console.log(this.multipleSelection)
      // if (this.contractStateValue) {
      if (this.multipleSelection.length !== 0) {
        const materialGroup = []
        const numberGroup = []
        const partGroup = []
        const purchaseGroup = []
        const locateGroup = []
        const isPurchaseGroup = []
        const batchGroup = []
        const batchCodeGroup = []
        this.multipleSelection_variable = this.multipleSelection
        this.multipleSelection = []
        for (let i = 0; i < this.multipleSelection_variable.length; i++) {
          this.syncLocateValueByName(this.multipleSelection_variable[i])
          if (!this.multipleSelection_variable[i].货位流水号 && this.multipleSelection_variable[i].货位流水号 !== 0) {
            this.$message.warning('存在未绑定货位的物料')
            return
          }
          materialGroup[i] = this.multipleSelection_variable[i].物料流水号
          numberGroup[i] = this.multipleSelection_variable[i].本次到货数
          partGroup[i] = this.multipleSelection_variable[i].标准件和外购件流水号
          purchaseGroup[i] = this.multipleSelection_variable[i].采购合同明细流水号
          locateGroup[i] = this.multipleSelection_variable[i].货位流水号
          isPurchaseGroup[i] = this.multipleSelection_variable[i].采购类型
          batchGroup[i] = this.multipleSelection_variable[i].批号
          batchCodeGroup[i] = this.multipleSelection_variable[i].批次编码
        }
        var param = []
        param[0] = ['物料流水号组', materialGroup]
        param[1] = ['实际到货数量组', numberGroup]
        param[2] = ['标准件和外购件流水号组', partGroup]
        param[3] = ['采购合同明细流水号组', purchaseGroup]
        param[4] = ['入库人员流水号', this.id]
        param[5] = ['货位流水号组', locateGroup]
        param[6] = ['是否采购组', isPurchaseGroup]
        param[7] = ['批号组', batchGroup]
        param[8] = ['批次编码组', batchCodeGroup]
        var Data = this.CreateData('12', '仓储管理_采购件入库_循环执行', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('入库成功')
            this.exportTable()
            this.searchTable1()
          } else {
            this.$message.success('入库失败')
          }
        })
      } else {
        this.$message.warning('请选择物料')
      }
      // } else {
      //   this.$message.warning('请先选择合同')
      // }
    },
    searchTable2() {
      let materialNameTypeValue_check
      this.materialNameTypeValue ? materialNameTypeValue_check = 1 : materialNameTypeValue_check = 0
      var param = []
      param[0] = ['物料名称_check', materialNameTypeValue_check]
      param[1] = ['物料名称', this.materialNameTypeValue]
      var Data = this.CreateData('11', '仓储管理_退料入库明细_查询', param, this.pageSize, this.pageCurrent)
      this.ExecDatabase(Data).then(response => {
        this.tableData2 = response.data.rows
        this.total = response.data.total
      })
    },
    handleSelectionChange1(val) {
      this.multipleSelection1 = val
    },
    selectable1(row) {
      return row.退件人
    },
    // submitInStorage1() {
    //   if (this.multipleSelection1.length !== 0) {
    //     const materialGroup = []
    //     const numberGroup = []
    //     const peopleGroup = []
    //     const typeGroup = []
    //     const locateGroup = []
    //     this.multipleSelection_variable1 = this.multipleSelection1
    //     this.multipleSelection1 = []
    //     for (let i = 0; i < this.multipleSelection_variable1.length; i++) {
    //       materialGroup[i] = this.multipleSelection_variable1[i].物料流水号
    //       numberGroup[i] = this.multipleSelection_variable1[i].入库数
    //       peopleGroup[i] = this.multipleSelection_variable1[i].退件人
    //       typeGroup[i] = this.multipleSelection_variable1[i].类型
    //       locateGroup[i] = this.multipleSelection_variable[i].货位流水号
    //     }
    //     var param = []
    //     param[0] = ['物料流水号组', materialGroup]
    //     param[1] = ['实际到货数量组', numberGroup]
    //     param[2] = ['退件人组', peopleGroup]
    //     param[3] = ['类型组', typeGroup]
    //     param[4] = ['入库人员流水号', this.id]
    //     param[5] = ['货位流水号', locateGroup]
    //     var Data = this.CreateData('12', '仓储管理_退料入库_循环执行', param)
    //     this.ExecDatabase(Data).then(response => {
    //       if (response.data[0].result === '1') {
    //         this.$message.success('入库成功')
    //         this.searchTable2()
    //       } else {
    //         this.$message.success('入库失败')
    //       }
    //     })
    //   } else {
    //     this.$message.warning('请选择物料')
    //   }
    // },
    searchTable3() {
      let orderSelectionValue_check, numberSelectionValue_check
      this.orderSelectionValue ? orderSelectionValue_check = 1 : orderSelectionValue_check = 0
      this.numberSelectionValue ? numberSelectionValue_check = 1 : numberSelectionValue_check = 0
      var param = []
      param[0] = ['排序名称', this.orderName]
      param[1] = ['排序方式', this.order]
      param[2] = ['订单号_check', orderSelectionValue_check]
      param[3] = ['订单号', this.orderSelectionValue]
      param[4] = ['零件图号_check', numberSelectionValue_check]
      param[5] = ['零件图号', this.numberSelectionValue]
      var Data = this.CreateData('11', '仓储管理_自制件入库_查询', param, this.pageSize1, this.pageCurrent1)
      this.ExecDatabase(Data).then(response => {
        this.tableData3 = response.data.rows
        this.total1 = response.data.total
        for (let i = 0; i < this.tableData3.length; i++) {
          var row = this.tableData3[i]
          if (row.货位流水号 !== null && row.货位流水号 !== undefined && row.货位流水号 !== '') {
            row.货位流水号 = String(row.货位流水号)
          }
          this.$set(row, 'locateName', [])
          this.$set(row, 'selectedLocate', null)
          this.$set(row, '_editing', false)
        }
      })
    },
    selectable2(row) {
      return Number(row.完成数量) > Number(row.入库数量)
    },
    handleSelectionChange2(val) {
      this.multipleSelection2 = val
    },
    submitInStorage2() {
      if (this.multipleSelection2.length !== 0) {
        const materialGroup = []
        const numberGroup = []
        const processGroup = []
        const typeGroup = []
        const locateGroup = []
        const batchGroup = []
        const batchCodeGroup = []
        this.multipleSelection_variable2 = this.multipleSelection2
        this.multipleSelection2 = []
        for (let i = 0; i < this.multipleSelection_variable2.length; i++) {
          this.syncLocateValueByName(this.multipleSelection_variable2[i])
          if (!this.multipleSelection_variable2[i].货位流水号 && this.multipleSelection_variable2[i].货位流水号 !== 0) {
            this.$message.warning('存在未绑定货位的物料')
            return
          }
          materialGroup[i] = this.multipleSelection_variable2[i].物料流水号
          numberGroup[i] = this.multipleSelection_variable2[i].本次入库
          processGroup[i] = this.multipleSelection_variable2[i].工艺计划流水号
          typeGroup[i] = this.multipleSelection_variable2[i].类型
          locateGroup[i] = this.multipleSelection_variable2[i].货位流水号
          batchGroup[i] = this.multipleSelection_variable2[i].批号
          batchCodeGroup[i] = this.multipleSelection_variable2[i].批次编码
        }
        var param = []
        param[0] = ['物料流水号组', materialGroup]
        param[1] = ['实际到货数量组', numberGroup]
        param[2] = ['工艺计划流水号组', processGroup]
        param[3] = ['入库人员流水号', this.id]
        param[4] = ['货位流水号组', locateGroup]
        param[5] = ['类型组', typeGroup]
        param[6] = ['批号组', batchGroup]
        var Data = this.CreateData('12', '仓储管理_自制件入库_循环执行', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('入库成功')
            this.searchTable3()
          } else {
            this.$message.success('入库失败')
          }
        })
      } else {
        this.$message.warning('请选择物料')
      }
    },
    selectable3(row) {
      return row.到货数量 > 0 && row.到货数量 !== undefined
    },
    submitInStorage3() {
      if (this.multipleSelection3.length !== 0) {
        const numberGroup = []
        const partGroup = []
        this.multipleSelection_variable3 = this.multipleSelection3
        this.multipleSelection3 = []
        this.supplierSelectionName4 = this.multipleSelection_variable3[0].调拨单号
        for (let i = 0; i < this.multipleSelection_variable3.length; i++) {
          numberGroup[i] = this.multipleSelection_variable3[i].到货数量
          partGroup[i] = this.multipleSelection_variable3[i].外协调拨单明细流水号
        }
        var param = []
        param[0] = ['外协调拨单明细流水号组', partGroup]
        param[1] = ['到货数量组', numberGroup]
        param[2] = ['操作人', this.id]
        var Data = this.CreateData('12', '仓储管理_外协调拨明细_到货', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.exportTable1()
            this.$message.success('入库成功')
            this.searchTable10()
          } else {
            this.$message.error('入库失败')
          }
        })
      } else {
        this.$message.warning('请选择工件')
      }
    },
    sortChange(column) {
      if (column.prop === '类型') {
        this.orderName = 1
      } else if (column.prop === '零件名称') {
        this.orderName = 2
      } else if (column.prop === '零件图号') {
        this.orderName = 3
      } else if (column.prop === '订单号') {
        this.orderName = 3
      } else {
        this.orderName = 0
      }
      if (column.order === 'ascending') {
        this.order = 1
      } else if (column.order === 'descending') {
        this.order = 2
      } else {
        this.order = ''
      }
      this.searchTable3()
    },
    handleSizeChanges(val) {
      this.pageCurrent = 1
      this.pageSize = val
      this.searchTable2()
    },
    handleCurrentChanges(val) {
      this.pageCurrent = val
      this.searchTable2()
    },
    handleSizeChanges1(val) {
      this.pageCurrent1 = 1
      this.pageSize1 = val
      this.searchTable3()
    },
    handleCurrentChanges1(val) {
      this.pageCurrent1 = val
      this.searchTable3()
    },
    // 表格统计1
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        } else if (index === 6) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 7) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 8) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index]
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 10) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index]
          } else {
            sums[index] = 'N/A'
          }
        }
      })
      return sums
    },
    // 表格统计2
    getSummaries1(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        } else if (index === 5) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 6) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 7) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 8) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index]
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 12) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index]
          } else {
            sums[index] = 'N/A'
          }
        }
      })
      return sums
    },
    // 表格统计3
    getSummaries2(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        } else if (index === 8) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 9) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index]
          } else {
            sums[index] = 'N/A'
          }
        } else if (index === 10) {
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(2)
          } else {
            sums[index] = 'N/A'
          }
        }
      })
      return sums
    }
  }
}
</script>
<style scoped lang="scss">
/deep/ .el-card__body {
  padding: 0px !important;
}

/deep/ .el-tabs--border-card > .el-tabs__content {
  padding: 0px !important;
}
</style>
