<template>
  <basic-container>
    <div class="avue-crud" v-loading="reservationloading" element-loading-text="正在处理中...">
      <el-form
        ref="ruleForm"
        :model="form"
        prop="consignee"
        label-width="80px"
        :rules="reservationRules"
      >
        <el-row>
          <el-col :span="10">
            <el-form-item label="收货人:" prop="consignee" label-width="100px">
              <el-input v-model="form.consignee" clearable placeholder="请输入收货人" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="预约时间:" label-width="100px">
              <el-date-picker
                v-model="form.reservationDate"
                type="date"
                clearable
                placeholder="选择日期时间"
                format="YYYY/MM/DD"
                value-format="YYYY-MM-DD"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="收货地址:" prop="deliveryAddress" label-width="100px">
              <el-input v-model="form.deliveryAddress" clearable placeholder="请输入收件地址" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="时&emsp;&emsp;段:" prop="periodOfTime" label-width="100px">
              <el-radio-group v-model="form.periodOfTime" v-for="item in this.periodOfTimeData">
                <el-radio :label="item.dictKey" :value="item.dictKey"
                  >{{ item.dictValue }}&emsp;
                </el-radio>
              </el-radio-group>
              <!--                            :label="item.dictValue"-->
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="收件人电话:" prop="deliveryPhone" label-width="100px">
              <el-input v-model="form.deliveryPhone" placeholder="请输入收件人电话" />
            </el-form-item>
          </el-col>

          <el-col :span="10">
            <el-form-item label="配送类型:" prop="serveType" label-width="100px">
              <!--                            v-for="item in this.deliveryTypeData"-->
              <el-radio-group v-model="form.deliveryType">
                <el-radio :label="'2'" :value="'2'">市配&emsp;</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="代收运费:" prop="replaceFee" label-width="100px">
              <el-input v-model="form.replaceFee" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="配送方式:" prop="serveType" label-width="100px">
              <!--                            v-for="item in this.deliveryWayData"-->
              <el-radio-group v-model="form.deliveryWay">
                <el-radio :label="'10'" :value="'10'">送货&emsp;</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <!--                    <el-col :span="10">-->
          <!--                        <el-form-item label="到付运费:" prop="collectFee" label-width="100px">-->
          <!--                            <el-input type="number" v-model="form.collectFee" :disabled="true"/>-->
          <!--                        </el-form-item>-->
          <!--                    </el-col>-->
          <el-col :span="10">
            <el-form-item label="待收货款:" prop="collectionFee" label-width="100px">
              <el-input type="number" v-model="form.collectionFee" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="加&emsp;&emsp;急:" prop="serveType" label-width="100px">
              <!--                            v-for="item in this.deliveryWayData"-->
              <el-radio-group v-model="form.isUrgent" v-for="item in this.whetherData">
                <el-radio :label="item.dictKey" :value="item.dictKey"
                  >{{ item.dictValue }}&emsp;
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="10">
            <el-form-item label="其他费用:" prop="collectFee" label-width="100px">
              <el-input v-model="form.otherFee" placeholder="请输入其他费用" />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="服务类型:" prop="serveType" label-width="120px">
              <el-checkbox-group v-model="serveType" v-for="item in this.addvalueServeTypeData">
                <el-checkbox :label="item.dictKey" :value="item.dictKey"
                  >{{ item.dictValue }}&emsp;
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="备注:" prop="orderSource" label-width="100px" style="width: 100%">
              <el-input type="textarea" :rows="1" placeholder="请输入内容" v-model="form.remarks">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
        <el-tab-pane name="orderTab" label="订单">
          <el-button class="el-btn-xz" type="primary" link @click="handleAddOrder">新 增</el-button>
          <tablecmt
            class="tablesc"
            :columnList="columnList"
            :tableData="renderOrderData"
            :loading="loading"
            @inputTxt="(value, row) => handleSearchOrder(value, row, 1)"
            @timeCheck="timesc"
            @btnCheck="btnsc"
            @selectCheck="selectsc"
            @selection="list => (selectionList = list)"
          >
            <template #default="slotProps">
              <el-text
                v-if="slotProps.scope.row.resource !== '零担'"
                type="primary"
                link
                icon="el-icon-view"
                @click="viewStockArticlePackage(slotProps.scope.row)"
                >查看包件
              </el-text>
              <!-- <el-text
                v-if="slotProps.scope.row.resource === '零担' || slotProps.scope.row.isZero === '1'"
                type="primary"
                link
                icon="el-icon-view"
                @click="entryNum(slotProps.scope.row)"
                >在库录入
              </el-text> -->
              <el-text
                v-if="slotProps.scope.row.resource === '零担' || slotProps.scope.row.isZero === '1'"
                type="primary"
                link
                icon="el-icon-view"
                @click="entryReservationNum(slotProps.scope.row)"
                >预约录入
              </el-text>
              <el-text
                type="primary"
                link
                icon="el-icon-edit"
                @click="removeStockArticle(slotProps.scope.row)"
                >移除
              </el-text>
            </template>
          </tablecmt>
        </el-tab-pane>

        <el-tab-pane name="InventoryTab" label="库存品">
          <el-button class="el-btn-xz" link @click="handleAddInventory">新 增</el-button>
          <tablecmt
            class="tablesc"
            :columnList="stockcolumnList"
            :tableData="renderInventoryData"
            :loading="loading"
            @inputTxt="(value, row) => handleSearchStock(value, row, 1)"
            @timeCheck="timesc"
            @btnCheck="btnsc"
            @selectCheck="selectsc"
            @selection="list => (selectionInventoryList = list)"
          >
            <template #default="slotProps">
              <!--              <el-text-->
              <!--                      v-if="inventoryShow"-->
              <!--                      type="primary"-->
              <!--                      link-->
              <!--                      icon="el-icon-edit"-->
              <!--                      @click="showStockListEdit(slotProps.scope.row)"-->
              <!--              >查看详情</el-text>-->

              <el-text
                type="primary"
                link
                icon="el-icon-edit"
                @click="removeStockList(slotProps.scope.row)"
                >移除
              </el-text>
            </template>
          </tablecmt>
        </el-tab-pane>
      </el-tabs>

      <div class="submit-container">
        <el-button
          :loading="loadingObj.submitBtnLoading"
          type="primary"
          icon="el-icon-circle-close"
          @click="onSubmit('ruleForm')"
          >提交(配送订单预约)
        </el-button>
        <el-button icon="el-icon-circle-close" @click="back">返 回</el-button>
      </div>

      <!-- 底部站位 -->
      <div class="footer-container"></div>

      <!-- 在库订单信息 -->
      <!-- <template v-if="orderShow"> -->
      <el-dialog
        v-model="orderShow"
        title="在库订单信息"
        class="orderShow"
        width="90%"
        :model="addvalue"
      >
        <el-button type="primary" @click="Batchmodifycustomers">批量修改客户 </el-button>
        <tablecmt
          ref="orderTableNode"
          :columnList="stockArtcolumnList"
          :tableData="stockArticleInfo"
          :checkselect="orderSelectList"
          :loading="loading"
          @inputTxt="inputscStockArtic"
          @timeCheck="timescStockArtic"
          @btnCheck="btnscStockArtic"
          @selectCheck="selectscStockArtic"
          @selection="selectionChange"
        >
          <template #default="slotProps">
            <template v-if="slotProps.scope.column.label === '是否齐套'">
              <el-tag :class="Number(slotProps.scope.row.completeSet) === 2 ? 'green' : 'red'">
                {{ slotProps.scope.row.completeSetName }}
              </el-tag>
            </template>

            <template v-else-if="slotProps.scope.column.label === '操作'">
              <el-text
                type="primary"
                link
                icon="el-icon-edit"
                @click="updateClient(slotProps.scope.row)"
                >修改客户
              </el-text>
            </template>
          </template>
        </tablecmt>

        <div class="flex-c-sb" style="width: 100%">
          <div>勾选数量：{{ orderList.length }}</div>

          <!-- 分页模块 -->
          <el-pagination
            align="right"
            background
            @size-change="sizeOrderChange"
            @current-change="currentOrderChange"
            :current-page="page.currentPage"
            :page-sizes="[30, 50, 80, 120]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.total"
          >
          </el-pagination>
        </div>
        <div class="flex-c-c mt10">
          <el-button type="primary" icon="el-icon-circle-close" @click="onSubmitOrder"
            >提交(订单)
          </el-button>
          <el-button icon="el-icon-circle-close" @click="orderShow = false">返 回</el-button>
        </div>
      </el-dialog>
      <!-- </template> -->

      <!-- 零担品类信息 -->
      <el-dialog v-model="zeroOrderShow" title="零担品类信息" width="50%" :model="zeroOrderData">
        <el-row :gutter="24" class="rows">
          <el-col :xl="4" :lg="7" :md="8" :sm="24">
            <h3>
              <span>在库总数：{{ this.obj.handQuantity }}</span>
            </h3>
          </el-col>
        </el-row>

        <template v-if="zeroOrderData != null">
          <div v-for="(item, index) in zeroOrderData" :key="index">
            <el-row :gutter="24" class="rows">
              <el-col :xl="2" :lg="4" :md="4" :sm="12">
                <span>名称：{{ item.firsts }}</span>
              </el-col>
              <!-- <el-col :xl="4" :lg="7" :md="8" :sm="24">
                <span>总数量：{{ item.quantity }} </span>
              </el-col> -->
              <!-- <el-col :xl="4" :lg="7" :md="8" :sm="24">
                <span>在库数量：{{ item.handQuantity }} </span>
              </el-col> -->
              <el-col :xl="2" :lg="4" :md="8" :sm="24">
                <span>冻结数量：{{ item.deliveryQuantity }} </span>
              </el-col>
              <el-col :xl="4" :lg="7" :md="8" :sm="24">
                <span>出库数量：{{ item.outboundQuantity }} </span>
              </el-col>
              <!-- <el-col :xl="4" :lg="7" :md="8" :sm="24">
                <span
                  >可用数量：{{
                    item.handQuantity - item.deliveryQuantity - item.outboundQuantity
                  }}</span
                >
                                        <span>可用数量：{{(item.quantity)}}</span>
              </el-col> -->

              <el-col :xl="5" :lg="4" :md="4" :sm="12">
                <div class="el_sumS">
                  <span>操作数量：</span>
                  <el-input-number
                    v-if="this.isrReservationEntry"
                    v-model="item.reservationNum"
                    min="0"
                    :max="item.reservationNum"
                    placeholder="请输入预约数量"
                  ></el-input-number>
                  <el-input-number
                    v-else
                    v-model="item.number"
                    min="0"
                    :max="maxSum"
                    placeholder="请输入预约数量"
                  ></el-input-number>
                </div>
              </el-col>
            </el-row>

            <!--                    <el-input-number v-model="item.reservationNum" min="0" :max="item.quantity - item.deliveryQuantity -item.outboundQuantity "  placeholder="请输入预约数量"></el-input-number>-->
          </div>
        </template>
        <el-form-item style="margin-left: 37%; margin-top: 5px">
          <el-button
            v-if="!isrReservationEntry"
            type="primary"
            icon="el-icon-circle-close"
            @click="onSubmitUpdateZeroOrder"
            >修改(零担订单)
          </el-button>
          <el-button type="primary" icon="el-icon-circle-close" @click="onSubmitZeroOrder"
            >提交(零担订单)
          </el-button>
          <el-button icon="el-icon-circle-close" @click="zeroOrderShow = false">返 回</el-button>
        </el-form-item>
      </el-dialog>

      <!-- 库存品信息 -->
      <!-- <template v-if="stockListShow"> -->
      <el-dialog v-model="stockListShow" class="stockListShow" title="库存品信息" width="90%">
        <div v-loading="Inventoryloading" element-loading-text="正在拼命加载中...">
          <tablecmt
            ref="inventoryTableNode"
            :columnList="inventoryInfocolumnList"
            :tableData="inventoryInfo"
            :checkselect="inventorySelectList"
            :loading="loading"
            @inputTxt="inputscInventory"
            @selectCheck="searchStockList"
            @selection="selectionInventoryChange"
          >
            <template #default="slotProps">
              <el-input-number
                v-model="slotProps.scope.row.reservationNum"
                :controls="false"
                :min="0"
                :precision="0"
              />
            </template>
          </tablecmt>
          <!-- 分页行 -->
          <div class="flex-c-sb">
            <div>勾选合计：{{ inventoryList.length }}</div>
            <!-- 分页模块 -->
            <el-pagination
              align="right"
              background
              @size-change="inventorySizeChange"
              @current-change="inventoryCurrentChange"
              :current-page="inventoryPage.pageNum"
              :page-sizes="[30, 50, 80, 120]"
              :page-size="inventoryPage.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="inventoryPage.total"
            >
            </el-pagination>
          </div>
          <div class="flex-c-c mt10">
            <el-button type="primary" icon="el-icon-circle-close" @click="onSubmitInventory"
              >提交(库存品)
            </el-button>
            <el-button icon="el-icon-circle-close" @click="stockListShow = false">返 回</el-button>
          </div>
        </div>
      </el-dialog>
      <!-- </template> -->

      <!-- 包件信息 -->
      <template v-if="isaddvalue">
        <el-dialog v-model="isaddvalue" title="包件信息" width="90%" :model="addvalue">
          <!-- 列表模块 -->
          <!--                :isselectfun="checkPackage"-->
          <tablecmt
            ref="packageTableNode"
            :columnList="columnParcels"
            :tableData="packageData"
            :checkselect="packageDataSec"
            :loading="loading"
            @inputTxt="inputscPackage"
            @selection="selectionPackageChange"
            @select="tableAllSelection"
            @cell-mouse-enter="hove"
          >
            <template #default="slotProps">
              <!-- <el-text
                                          type="primary"
                                          link
                                          icon="el-icon-edit"
                                          @click="removeStockList(slotProps.scope.row)"
                                          >移除</el-text
                                        > -->
            </template>
          </tablecmt>
          <el-form-item style="margin-left: 45%; margin-top: 5px">
            <el-button type="primary" icon="el-icon-circle-close" @click="onSubmitPackage"
              >提交(包件)
            </el-button>
            <el-button icon="el-icon-circle-close" @click="isaddvalue = false">返 回</el-button>
          </el-form-item>
        </el-dialog>
      </template>

      <!-- 客户信息 -->
      <el-dialog v-model="dialogVisible" title="客户信息" width="30%" :model="clientData">
        <el-row :gutter="24" class="rows">
          <el-col :xl="6" :lg="7" :md="8" :sm="24">
            <div class="clientRow">
              <span>商场名称：{{ clientData.mallName }} </span>
            </div>
          </el-col>
        </el-row>
        <el-form :label-position="right" label-width="80px" :model="formLabelAlign">
          <el-form-item label="用户名称:">
            <el-input v-model="clientData.customerName" placeholder="请输入用户名称"></el-input>
          </el-form-item>
          <el-form-item label="用户电话:">
            <el-input
              v-model="clientData.customerTelephone"
              placeholder="请输入用户电话"
            ></el-input>
          </el-form-item>
          <el-form-item label="用户地址:">
            <el-input v-model="clientData.customerAddress" placeholder="请输入用户地址"></el-input>
          </el-form-item>
        </el-form>

        <template #footer>
          <span class="dialog-footer">
            <el-button @click="dialogVisible = false">取消</el-button>
            <el-button type="primary" @click="submitClient"> 确定(修改客户) </el-button>
          </span>
        </template>
      </el-dialog>
    </div>
  </basic-container>
</template>

<script>
import {
  autonomouslySave,
  update,
  remove,
  getReservationInfo,
  getReservationZeroOrderDetail,
  getReservationPackageListByOrderId,
  cancelReservation,
} from '@/api/distribution/distributionReservation';
import {
  getStockArticleList,
  getPackageListByStockArticleId,
  selectStockArticleInfoList,
  selectUpdateAvailableStockArticle,
  getZeroOrderDetail,
  updateClient,
  $_updateBatchClient,
} from '@/api/distribution/distributionStockArticle';

import { getDetailDelivery } from '@/api/distribution/distributionDelivery';
import { getInventoryList, selectInventoryDetail } from '@/api/distribution/distributionStockList';
import option from '@/option/distribution/distributionStockArticle';
import { mapGetters } from 'vuex';
import { getDictionaryBiz } from '@/api/system/dict';
import dayjs from 'dayjs';
import { entryNum, updateEntryNum } from '@/api/distribution/distributionParcelNumber';
import { setNodeHeight, removeZeroWidth } from '@/utils/util.js';
import { ElMessage, ElMessageBox } from 'element-plus';
import error from '@/error';
export default {
  name: '/distribution/reservation/reservationAddFrom',
  data() {
    return {
      activeName: 'orderTab',
      Inventoryloading: true, //库存品加载
      packageQuery: {},
      reservationloading: false,
      orderRow: {},
      Appointmentquantity: 0, //预约数量
      /** 订单 */
      columnList: [
        {
          prop: '',
          label: '复选框',
          type: 0,
          values: '',
          width: '55',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: '',
          label: '序号',
          type: 12,
          values: '',
          width: '55',
          checkarr: [],
          fixed: true,
          sortable: false,
          head: false,
        },
        {
          prop: 'waybillNumber',
          label: '运单号',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderCode',
          label: '订单自编号',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'serviceNumber',
          label: '服务号',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'mallName',
          label: '商场名称',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'storeName',
          label: '门店名称',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'resource',
          label: '订单来源',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'descriptionGoods',
          label: '货物名称',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'warehouse',
          label: '仓库',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderStatusName',
          label: '订单状态',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'storeTime',
          label: '在库时间',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'totalNumber',
          label: '订单总件数',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          isshowSummary: true,
          head: false,
        },
        {
          prop: 'handQuantity',
          label: '在库件数',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          isshowSummary: true,
          head: false,
        },
        {
          prop: 'reservationNum',
          label: '预约数量',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          isshowSummary: true,
          head: false,
        },
        {
          prop: 'customerName',
          label: '顾客名字',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'customerTelephone',
          label: '顾客电话',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'customerAddress',
          label: '顾客地址',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: '',
          label: '操作',
          type: 6,
          values: '',
          width: '150',
          checkarr: [],
          fixed: 'right',
          hide: true,
        },
      ],
      /** 库存品 */
      stockcolumnList: [
        // {
        //   prop: '',
        //   label: '序号',
        //   type: 0,
        //   values: '',
        //   width: 55,
        //   checkarr: [],
        //   fixed: true,
        // },
        {
          prop: '',
          label: '复选框',
          type: 0,
          values: '',
          width: '55',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: '',
          label: '序号',
          type: 12,
          values: '',
          width: '55',
          checkarr: [],
          fixed: true,
          sortable: false,
          head: false,
        },
        {
          prop: 'incomingBatch',
          label: '入库批次',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        // {
        //   prop: 'serviceTypeName',
        //   label: '服务类型',
        //   type: 1,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: true,
        //   sortable: true,
        //   head: false,
        // },
        {
          prop: 'orderCode',
          label: '订单自编号',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'serviceNumber',
          label: '服务号',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'descriptionGoods',
          label: '物料名称',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: true,
          sortable: true,
        },
        // {
        //   prop: 'warehouse',
        //   label: '入库时间',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'warehouseName',
          label: '仓库名称',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'cargoNumber',
          label: '物料编码',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'marketName',
          label: '商场/客户',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'storeName',
          label: '门店名称',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'brandName',
          label: '品牌',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        // {
        //   prop: 'mallName',
        //   label: '商城名称',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'despatch',
          label: '物流车次',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'quantityStock',
          label: '库存数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          isshowSummary: true,
          sortable: true,
        },
        {
          prop: 'quantityOccupied',
          label: '冻结数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          isshowSummary: true,
          sortable: true,
        },
        /* {
             prop: 'despatch',
             label: '物流发运车次',
             type: 2,
             values: '',
             width: '130',
             checkarr: [],
             fixed: false,
             sortable: true,
           },*/
        // {
        //   prop: 'category',
        //   label: '品分类',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'outboundQuantity',
          label: '出库数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          isshowSummary: true,
          sortable: true,
        },

        // {
        //   prop: 'storeCode',
        //   label: '门店编码',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        // {
        //   prop: 'marketCode',
        //   label: '商场编码',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        // {
        //   prop: 'shoppingMall',
        //   label: '所属商场',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'reservationNum',
          label: '预约数量',
          type: 10,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          isshowSummary: true,
          head: false,
        },
        {
          prop: 'cargoUnit',
          label: '物料单位',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'unpackingQuantity',
          label: '拆包数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          isshowSummary: true,
          sortable: true,
        },
        {
          prop: 'unpackName',
          label: '拆包状态',
          type: 1,
          values: '',
          width: '130',
          checkarr: [
            {
              value: `true`,
              label: '是',
            },
            {
              value: `false`,
              label: '否',
            },
          ],
          fixed: false,
          sortable: true,
        },

        {
          prop: '',
          label: '操作',
          type: 6,
          values: '',
          width: '200',
          checkarr: [],
          fixed: 'right',
          hide: true,
        },
        // 更多列的配置...
      ],
      /** 新增订单 */
      stockArtcolumnList: [
        {
          prop: '',
          label: '序号',
          type: 0,
          values: '',
          width: '55',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'waybillNumber',
          label: '运单号',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderCode',
          label: '订单自编号',
          type: 2,
          values: '',
          width: '260',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'serviceNumber',
          label: '服务号',
          type: 2,
          values: '',
          width: '260',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'mallName',
          label: '商场名称',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'storeName',
          label: '门店名称',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'isZeroName',
          label: '是否零担',
          type: 3,
          values: '',
          width: '150',
          checkarr: [
            { label: '否', value: 0 },
            { label: '是', value: 1 },
          ],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'descriptionGoods',
          label: '货物名称',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'reservationStatusName',
          label: '预约状态',
          type: 3,
          values: '',
          width: '150',
          checkarr: [
            {
              label: '未预约',
              value: '10',
            },
            {
              label: '部分预约',
              value: '20',
            },
          ],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'freezeStatusName',
          label: '冻结状态',
          type: 3,
          values: '',
          width: '150',
          checkarr: [
            {
              label: '未冻结',
              value: '10',
            },
            {
              label: '部分冻结',
              value: '20',
            },
            {
              label: '已冻结',
              value: '30',
            },
          ],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'warehouse',
          label: '仓库',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'warehouseEntryTime',
          label: '入库时间',
          type: 4,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'storeTime',
          label: '在库时间',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'totalNumber',
          label: '订单总件数',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          isshowSummary: true,
          head: false,
        },
        {
          prop: 'handQuantity',
          label: '在库件数',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          isshowSummary: true,
          head: false,
        },
        {
          prop: 'completeSetName',
          label: '是否齐套',
          type: 14,
          values: '',
          width: '150',
          checkarr: [
            {
              label: '未齐套',
              value: '1',
            },
            {
              label: '已齐套',
              value: '2',
            },
          ],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'brand',
          label: '品牌',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'customerName',
          label: '顾客名字',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'customerTelephone',
          label: '顾客电话',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'customerAddress',
          label: '顾客地址',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'allocation',
          label: '库位信息',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'trays',
          label: '托盘信息',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: '',
          label: '操作',
          type: 6,
          values: '',
          width: '200',
          checkarr: [],
          fixed: 'right',
          hide: true,
        },
      ],
      /** 新增库存品 */
      inventoryInfocolumnList: [
        {
          prop: '',
          label: '序号',
          type: 0,
          values: '',
          width: 55,
          checkarr: [],
          fixed: true,
        },
        // {
        //   prop: 'serviceTypeName',
        //   label: '服务类型',
        //   type: 1,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: true,
        //   sortable: true,
        //   head: false,
        // },
        {
          prop: 'orderCode',
          label: '订单自编号',
          type: 2,
          values: '',
          width: '240',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'descriptionGoods',
          label: '物料名称',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: true,
          sortable: true,
        },
        {
          prop: 'cargoNumber',
          label: '物料编码',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: true,
          sortable: true,
        },
        {
          prop: 'serviceNumber',
          label: '服务号',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'incomingBatch',
          label: '入库批次',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        // {
        //   prop: 'warehouse',
        //   label: '入库时间',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'warehouseName',
          label: '仓库名称',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'marketName',
          label: '商场/客户',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: true,
          sortable: true,
        },
        {
          prop: 'storeName',
          label: '门店名称',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'brandName',
          label: '品牌',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        // {
        //   prop: 'mallName',
        //   label: '商城名称',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'despatch',
          label: '物流车次',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'positionCode', //需要新增字段
          label: '货位信息',
          type: 2,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'quantityStock',
          label: '库存数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          isshowSummary: true,
          sortable: true,
        },
        {
          prop: 'quantityOccupied',
          label: '冻结数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          isshowSummary: true,
          sortable: true,
        },
        /* {
             prop: 'despatch',
             label: '物流发运车次',
             type: 2,
             values: '',
             width: '130',
             checkarr: [],
             fixed: false,
             sortable: true,
           },*/
        // {
        //   prop: 'category',
        //   label: '品分类',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'outboundQuantity',
          label: '出库数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          isshowSummary: true,
          sortable: true,
        },

        {
          prop: 'reservationNum',
          label: '预约数量',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          isshowSummary: true,
          head: false,
        },

        // {
        //   prop: 'storeCode',
        //   label: '门店编码',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        // {
        //   prop: 'marketCode',
        //   label: '商场编码',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        // {
        //   prop: 'shoppingMall',
        //   label: '所属商场',
        //   type: 2,
        //   values: '',
        //   width: '130',
        //   checkarr: [],
        //   fixed: false,
        //   sortable: true,
        // },
        {
          prop: 'cargoUnit',
          label: '物料单位',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          sortable: true,
        },
        {
          prop: 'unpackingQuantity',
          label: '拆包数量',
          type: 1,
          values: '',
          width: '130',
          checkarr: [],
          fixed: false,
          isshowSummary: true,
          sortable: true,
        },
        {
          prop: 'unpackName',
          label: '拆包状态',
          type: 1,
          values: '',
          width: '130',
          checkarr: [
            {
              value: `true`,
              label: '是',
            },
            {
              value: `false`,
              label: '否',
            },
          ],
          fixed: false,
          sortable: true,
        },

        // {
        //   prop: '',
        //   label: '操作',
        //   type: 6,
        //   values: '',
        //   width: '200',
        //   checkarr: [],
        //   fixed: 'right',
        //   hide: true,
        // },
        // 更多列的配置...
      ],
      /** 包件信息 */
      columnParcels: [
        {
          prop: '',
          label: '序号',
          type: 0,
          values: '',
          width: '55',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'waybillNumber',
          label: '运单号',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'serviceNumber',
          label: '服务号',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderCode',
          label: '订单自编码',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: true,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderPackageCode',
          label: '包条码',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'warehouse',
          label: '所在仓库',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'sendWarehouseName',
          label: '发站仓',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'firsts',
          label: '一级品',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'second',
          label: '二级品',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'thirdProduct',
          label: '三级品',
          type: 2,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderPackageStatusName',
          label: '包件状态',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderPackageFreezeStatusName',
          label: '冻结状态',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderPackageGroundingStatusName',
          label: '上架状态',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderPackageStockupStatusName',
          label: '备货状态',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'orderPackageReservationStatusName',
          label: '预约状态',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'materialName',
          label: '物料名称',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'quantity',
          label: '数量',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          isshowSummary: true,
          head: false,
        },
        {
          prop: 'goodsAllocation',
          label: '货位信息',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        {
          prop: 'pallet',
          label: '所在托盘',
          type: 1,
          values: '',
          width: '150',
          checkarr: [],
          fixed: false,
          sortable: true,
          head: false,
        },
        // {
        //   prop: 'trainNumber',
        //   label: '客户车次号',
        //   type: 2,
        //   values: '',
        //   width: '150',
        //   checkarr: [],
        //   fixed: true,
        //   sortable: true,
        //   head: false,
        // },
        // {
        //   prop: '',
        //   label: '操作',
        //   type: 6,
        //   values: '',
        //   width: '150',
        //   checkarr: [],
        //   fixed: 'right',
        //   hide: true,
        // },
      ],
      height: 0,
      // 弹框标题
      title: '',
      // 是否展示弹框
      box: false,
      // 是否显示查询
      search: true,
      // 加载中
      loading: true,
      // 是否为查看模式
      view: false,
      // 查询信息
      query: {},
      /** 订单查询  */
      orderQuery: {},
      stockQuery: {},
      // 分页信息
      page: {
        currentPage: 1,
        pageSize: 30,
        total: 40,
      },
      /** 库存品分页信息 */
      inventoryPage: {
        currentPage: 1,
        pageSize: 30,
        total: 0,
      },
      // 表单数据
      form: {},
      // 选择行
      selectionList: [],
      selectionInventoryList: [],
      // 表单配置
      option: option,
      // 表单列表
      data: [],
      //增值服务弹窗
      dialogVisible: false,
      clientData: {},
      textarea: '',
      //增值服务字典列表
      addvalueServeTypeData: [],
      //配送方式字典列表
      deliveryWayData: [],
      whetherData: [],
      //配送类型字典列表
      deliveryTypeData: [],
      //增值服务列表
      addvalueServeType: [],
      obj: {},
      //增值表单输入框对象
      addvalue: {},
      costList: [], //字典
      //增值服务对象
      addvalueObj: {},
      //费用列表
      feeList: [],
      //楼层
      floorList: [],
      //订单行数据
      orderInfo: {},
      //服务类型
      serveType: [],
      //增加订单弹窗
      orderShow: false,
      zeroOrderData: [],
      zeroOrderShow: false,
      //是否是预约录入
      isrReservationEntry: false,
      // zeroPackageNum:0,
      //在库订单信息
      stockArticleInfo: [],
      //库存品信息
      inventoryInfo: [],
      //时段
      periodOfTimeData: [],
      //路由订单编号
      orderIds: '',
      //预约编号
      reservationId: '',
      zeroOrderMax: 0,
      // 商城名称
      marketName: '',
      // 包件复选框列表
      packageDataSec: [],
      /** 库存品数据 */
      inventoryData: [],
      /** 库存品渲染数据 */
      renderInventoryData: [],
      orderData: [],
      renderOrderData: [],
      /** 库存品弹窗是否显示 */
      stockListShow: false,
      isaddvalue: false,
      packageData: [],
      packageList: [],
      inventoryList: [],
      inventorySelectList: [],
      orderList: [],
      orderSelectList: [],
      inventoryTable: [],
      inventoryShow: false,
      reservationRules: {
        consignee: [{ required: true, message: '请填写收货人名称!!!', trigger: 'change' }],
        deliveryAddress: [{ required: true, message: '请填写收货人地址!!!', trigger: 'blur' }],
        deliveryPhone: [{ required: true, message: '请填写收货人电话!!!', trigger: 'change' }],
        // enableStatus: [
        //   { required: true, message: '请选择启用状态!', trigger: 'change' }
        // ],
      },
      obj: {},
      /** loading */
      loadingObj: {
        /** 提交按钮 */
        submitBtnLoading: false,
      },
      /** 页面id 决定是否进行刷新 */
      // pageId: 'add',
    };
  },
  created() {
    console.log('123 :>> ', 123);
    this.fetchData();
    this.onLoad(this.page);
    // this.$watch(
    //   () => this.$route.params,
    //   () => {
    //     this.fetchData();
    //   },
    //   // 组件创建完后获取数据，
    //   // 此时 data 已经被 observed 了
    //   { immediate: true }
    // );
  },
  mounted() {
    this.init();
    this.Copyfrom = JSON.parse(JSON.stringify(this.form));
    this.onLoad(this.page);
    this.getDictionary();

    this.setTableHeight();
  },
  watch: {
    '$route.query.reservationId': {
      handler(newVal, oldVal) {
        if (this.$route.path !== '/distribution/reservation/reservationAddFrom') return;
        // const _id = this.$route.query.reservationId || '';
        // if (_id === this.pageId) return;
        // this.pageId = _id;
        // console.log(newVal, oldVal);
        // this.fetchData();
        // this.onLoad(this.page);
      },
      deep: true,
      immediate: true,
    },
  },
  computed: {
    ...mapGetters(['permission']),
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(',');
    },
    // 最大数量
    maxSum() {
      let max = 0;
      this.zeroOrderData.forEach(item => {
        console.log(item);
        max += item.deliveryQuantity; //冻结数量
      });
      let maxs = this.obj.handQuantity - max;
      return maxs;
    },
  },

  methods: {
    /** 设置表格高度 */
    async setTableHeight() {
      await this.$nextTick();
      const _node = document.querySelectorAll('.tablesc');
      setNodeHeight(_node, '600px');
    },
    handleToggleAllSelection() {
      this.$refs.selecttable.toggleAllSelection();
    },
    fetchData() {
      this.error = this.post = null;
      this.loading = true;
      if (this.$route.query.id) {
        this.orderIds = this.$route.query.id;
      }
      if (this.$route.query.reservationId) {
        this.reservationId = this.$route.query.reservationId;
      }
      this.loading = false;
    },
    init() {
      this.height = this.setPx(document.body.clientHeight - 340);
    },
    tableAllSelection() {},
    handleClick(tab, event) {
      this.query = {};
      this.setTableHeight();
    },
    //查询出所有的市配订单
    async handleAddOrder() {
      this.loading = true;
      this.orderList = [...this.orderData];
      this.query={}
      this.stockArtcolumnList.forEach(item=>{
          item.values=''
        })
      //这里只需要对订单进行正常的搜索即可
      await this.onLoadOrder(this.page);

 
   
      this.loading = false;
      this.orderShow = true;
      this.$nextTick(() => {
        const _node = document.querySelector('.orderShow .maboxhi');
        setNodeHeight(_node, '60vh');

        this.setTableHeight();
      });
    },
    checkOrder(row, index) {
      if (row.freezeStatus === '30' || row.freezeStatusName === '已冻结') {
        return false;
      } else {
        return true;
      }
    },
    async onLoadInventory() {
      try {
        this.Inventoryloading = true; //开启加载效果

        let page = this.inventoryPage;
        let params = {};
        this.query.serviceType = '2';
        if (this.marketName) this.query.marketName = this.marketName;
        console.log('this.query :>> ', this.query);

        const res = await getInventoryList(
          page.currentPage,
          page.pageSize,
          Object.assign(params, this.query)
        );
        const { code, data, msg } = res.data;

        if (code !== 200 || !data) {
          return this.$message.error(msg);
        }

        const _chooseArr = [...this.inventoryList];

        const response = res.data.data;
        response.records.forEach(item => {
          item.reservationNum = '0';
          item.applyNum = item.quantityStock - item.quantityOccupied;
          if (item.unpack) {
            item.unpackName = '是';
          } else {
            item.unpackName = '否';
          }
        });
        this.inventoryPage.total = response.total;
        console.log('res :>> ', res);

        // 过滤掉已选择的数量

        const _inventoryInfo = response.records;
        this.inventoryInfo = _inventoryInfo;

        if (_chooseArr.length !== 0) {
          // 获取ids的映射数组
          const ids = [];
          for (let i = 0; i < _chooseArr.length; i++) {
            ids.push(_chooseArr[i].id);
          }
          console.log('ids :>> ', ids);
          // 赋值给回显勾选的数组
          for (let i = 0; i < _inventoryInfo.length; i++) {
            const value = _inventoryInfo[i];
            // 循环获取符合条件的库存品组成数组
            const _index = ids.indexOf(value.id);
            if (_index !== -1) {
              value.reservationNum = _chooseArr[_index].reservationNum;
              _chooseArr.splice(_index, 1, value);
            }
          }
        }

        await this.$nextTick();
        console.log('this.$refs.inventoryTableNode :>> ', this.$refs.inventoryTableNode);
        setTimeout(() => {
          this.$refs.inventoryTableNode.handleCheckSelect(_chooseArr);
        }, 10);
      } catch (error) {
        console.log('error :>> ', error);
      } finally {
        this.Inventoryloading = false; //开启加载效果
        return null;
      }
    },
    async handleAddInventory() {
      try {
        this.loading = true;
        this.inventoryPage.currentPage = 1;

        this.inventoryList = this.inventoryData;
        // this.selectionClear();
        await this.onLoadInventory();
        this.stockListShow = true;
        await this.$nextTick();
        setNodeHeight(this.$refs.inventoryTableNode.$el, '60vh');
        this.setTableHeight();
      } catch (error) {
        console.log('error :>> ', error);
      } finally {
        this.query = {};
        this.loading = false;
      }
    },
    // 批量修改客户
    Batchmodifycustomers() {
      if (!this.orderList.length) {
        ElMessage({
          message: '请勾选要批量修改的数据',
          type: 'warning',
        });
        return;
      }

      let State = this.orderList.every(item => item.mallName == this.orderList[0].mallName);

      if (!State) {
        ElMessage({
          message: '请勾选商场名称一样的单子',
          type: 'warning',
        });
        return;
      }

      // this.orderList
      this.clientData = {};
      this.clientData.mallName = this.orderList[0].mallName;
      this.dialogVisible = true;
    },
    handleCheckedCitiesChange(value) {
      if (value) {
        this.form.addvalueType = value;
      }
      console.log('>>>>>', this.form);
      if (value.length < 1) {
        this.costList = [];
        this.costListName = [];
      }
      this.deliveryWayData.forEach(i => {
        if (value.includes(i.dictKey)) {
          console.log(i);
          i.pitch = true;
          this.costListName = value;
        }
      });
    },
    textbox(e, index, a) {
      console.log('e,index', e, index, a);
      if (a === 6) {
        this.feeList[index + 1] = e;
        return;
      }
      if (a === 5)
        if (index === 0 && a === 5) {
          this.floorList[index + 1] = e;
          return;
        }
      this.costList[index + 1] = e;

      //费用列表
    },
    //数据字典数据获取
    getDictionary() {
      getDictionaryBiz('addvalue_serve_type').then(res => {
        this.addvalueServeTypeData = res.data.data;
      });
      getDictionaryBiz('delivery_way').then(res => {
        this.deliveryWayData = res.data.data;
      });
      getDictionaryBiz('distribution_type').then(res => {
        this.deliveryTypeData = res.data.data;
      });
      getDictionaryBiz('period_of_time').then(res => {
        this.periodOfTimeData = res.data.data;
      });
      getDictionaryBiz('yes_no').then(res => {
        this.whetherData = res.data.data;
      });
    },
    addvalueServe(row) {
      //查询订单的增值服务，
      this.addvalueServeType = [];
      this.addvalue = {};
      this.dialogVisible = true;
      this.costList = [];
      this.feeList = [];
      this.floorList = [];
      this.orderInfo = row;
    },
    searchHide() {
      this.search = !this.search;
    },
    searchChange() {
      this.onLoad(this.page);
    },
    searchReset() {
      this.query = {};
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },
    entryReservationNum(row) {
      this.obj = row;
      if (this.reservationId) {
        //查询零担计划数量详情
        console.log('order------------>', row.id);
        getReservationZeroOrderDetail(this.reservationId, row.id).then(res => {
          let a = res.data.data;
          a.forEach(item => {
            item.zeroOrderMax =
              item.handQuantity -
              item.deliveryQuantity -
              item.outboundQuantity +
              item.reservationNum;
          });
          this.zeroOrderData = res.data.data;
          // console.log(res.data.data);
        });
      } else {
        getZeroOrderDetail(row.id).then(res => {
          if (res.data.data != null) {
            let a = res.data.data;
            a.forEach(item => {
              item.zeroOrderMax = item.handQuantity - item.deliveryQuantity - item.outboundQuantity;
            });
            this.zeroOrderData = res.data.data;
          }
        });
      }
      this.zeroOrderShow = true;
      this.isrReservationEntry = true;
    },
    entryNum(row) {
      this.obj = row;
      getZeroOrderDetail(row.id).then(res => {
        if (res.data.data != null) {
          this.zeroOrderData = res.data.data;
        }
      });
      this.zeroOrderShow = true;
      this.isrReservationEntry = false;
    },
    async submitClient() {
      if (this.orderList.length) {
        let data = {
          entityList: [],
        };

        this.orderList.forEach(item => {
          const _obj = {};
          _obj.id = item.id;
          _obj.customerName = this.clientData.customerName; //用户名称
          _obj.customerTelephone = this.clientData.customerTelephone; //用户电话
          _obj.customerAddress = this.clientData.customerAddress; //用户地址
          data['entityList'].push(_obj);
        });
        this.loading = true;
        this.dialogVisible = false; //关闭修改谈弹窗
        const res = await $_updateBatchClient(data);
        console.log(res, '修改成功');
        const { code, msg } = res.data;
        if (code !== 200) return;
        this.$message.success(msg);

        this.onLoadOrder(this.page);
        // this.orderList = [];
      } else {
        this.loading = true;
        this.dialogVisible = false; //关闭修改弹出
        console.log('this.client===============>', this.clientData);
        const _obj = {};
        _obj.id = this.clientData.id;
        _obj.customerName = this.clientData.customerName; //用户名称
        _obj.customerTelephone = this.clientData.customerTelephone; //用户电话
        _obj.customerAddress = this.clientData.customerAddress; //用户地址
        const res = await updateClient(_obj);
        this.loading = false;
        const { code, data, msg } = res.data;
        if (code !== 200) return;
        this.$message.success(msg);
        // this.orderList = [];
        this.onLoadOrder(this.page);
      }
    },

    // 选择包件信息
    // selectionPackageChange(list) {
    //   console.log(list,'list22');
    //   console.log('-----------<>', list);
    //   this.packageListInfo=list
    //   console.log(this.packageListInfo,'packageListInfo');
    //   if (this.reservationId) {
    //     this.packageDataSec = list;
    //   } else {
    //     //新增
    //     let a = [];
    //     list.forEach(item => {
    //       if (
    //         item.orderPackageReservationStatus === '10' ||
    //         item.orderPackageReservationStatusName === '未预约'
    //       ) {
    //         a.push(item);
    //       }
    //     });
    //     this.packageDataSec = a;
    //   }
    // },
    // 查看包件
    // 自动选中
    selectMatchingRows(val) {
      console.log(val, '数组');
      console.log(this.packageData);
      const selectedIds = val; // 需要匹配选中的ID
      // const matchedArray = this.packageData.filter(item => selectedIds.includes(item.id));
      // console.log(matchedArray,"处理好的数据");
      this.packageData.forEach(item => {
        if (selectedIds.includes(item.id)) {
          console.log(
            item,
            '包含================================================================>'
          );
          this.selectionPackageChange(item);
        }
      });
    },

    // if (row) {
    //   this.selectionPackageChange(row)
    //   console.log(  this.selectionPackageChange(),'12312312312321函数');
    // }
    async viewStockArticlePackage(row) {
      this.loading = true;
      this.packageList = row.packageList;
      this.obj = row;
      let page = this.page;
      this.packageQuery = {};
      this.orderRow = row;
      console.log('row>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', row);
      await this.getPackageList(row);
      await this.$nextTick();
      setNodeHeight(this.$refs.packageTableNode.$el, '60vh');
      // getPackageListByStockArticleId(page.currentPage, page.pageSize, row.id).then(res => {
      //   console.log('res---------------->', res);
      //   // console.log(res.data.data.records);
      //   if (res.data.data) {
      //     this.packageData = res.data.data.records;
      //     // 新增默认勾选全部
      //     this.packageDataSec = this.packageData;
      //   }
      //   this.isaddvalue = true;
      //   this.loading = false;
      // });
    },

    // 选择包件信息
    // selectionPackageChange(list) {
    //   console.log(list,'list22');
    //   console.log('-----------<>', list);
    //   if (this.reservationId) {
    //     this.packageDataSec = list;
    //   } else {
    //     //新增
    //     let a = [];
    //     list.forEach(item => {
    //       if (
    //         item.orderPackageReservationStatus === '10' ||
    //         item.orderPackageReservationStatusName === '未预约'
    //       ) {
    //         a.push(item);
    //       }
    //     });
    //     this.packageDataSec = a;
    //   }
    // },
    // 全选表格新增

    checkPackage(row, index) {
      //区分编辑还是新增
      //编辑需要对这个预约单下的包件信息均可进行调整
      console.log(row, 'rowrowrowrowrowrow');
      // if (!this.reservationId) {
      //   if (
      //     row.orderPackageReservationStatusName === '已预约' ||
      //     row.orderPackageReservationStatusName === '20'
      //   ) {
      //     return true;
      //   }
      // }
      if (row.orderPackageFreezeStatus === '10' || row.orderPackageFreezeStatusName === '已冻结') {
        return false;
      } else {
        return true;
      }
    },
    //搜索订单
    searchStockArticle() {
      let params = {};
      let page = this.page;
      this.query.typeService = 2;
      this.query.genre = 1;

      this.onLoadOrder(this.page);
    },
    searchStockList() {
      this.inventoryPage.currentPage = 1;
      onLoadInventory();
    },
    stockArticleSearchReset() {
      this.selectionList = [];
      this.query = {};
      this.handleAddOrder();
    },
    stockListSearchReset() {
      this.selectionList = [];
      this.query = {};
      this.handleAddInventory();
    },
    // 提交包件数
    onSubmitPackage() {
      // this.packageListInfo

      if (this.packageDataSec.length === 0) {
        this.$message.warning('请选择包件!!!');
        return;
      }
      this.orderData.forEach(item => {
        if (item.id === this.obj.id) {
          item.packageList = this.packageDataSec;
          item.reservationNum = this.packageDataSec.length;
        }
      });
      // this.Appointmentquantity =  this.packageDataSec.length;//预约数量

      console.log('this.orderData------------>', this.orderData);
      this.isaddvalue = false;
    },
    back() {
      this.$router.back();
      this.$store.commit('DEL_TAG_CURRENT');
    },
    // 最后提交
    async onSubmit(formEl) {
      this.$refs.ruleForm.validate(async valid => {
        if (valid) {
          console.log('submit!');
          try {
            if (this.inventoryData.length) {
              const allQuantitiesAreFalsy = this.inventoryData.every(
                item => item.reservationNum != '0'
              );
              if (!allQuantitiesAreFalsy) {
                ElMessage({
                  message: '请移除预约加数量为0的库存品订单',
                  type: 'warning',
                });
                return;
              }
            }

            // 日期必填
            if (!this.form.reservationDate) {
              this.$message({
                type: 'warning',
                message: '预约时间暂未选择',
              });
              return;
            }

            // 提交按钮
            //新增预约单
            let orderIds = [];
            let inventoryIds = [];
            let inventoryList = [];
            let stockArticleList = [];
            let operation = true;
            this.inventoryData.forEach(item => {
              if (Number(item.reservationNum) === 0 || item.reservationNum > item.quantityStock) {
                this.$message({
                  type: 'warning',
                  message: '存在无效的预约数量',
                });
                operation = false;
                return;
              }
              item.reservationNum = item.reservationNum;
              inventoryIds.push(item.id);
              inventoryList.push(item);
            });
            if (!operation) return;
            orderIds.join(',');
            inventoryIds.join(',');
            this.form.stockArticleIds = orderIds.toString();
            this.form.inventoryIds = inventoryIds.toString();
            this.form.inventoryList = inventoryList;
            console.log('-------------->', this.orderData);
            let order = this.orderData;
            order.forEach(o => {
              if (!o.packageListInfo) {
                o.packageListInfo = o.packageList;
              }
            });
            this.form.stockArticleList = order;
            this.deliveryWayData.forEach(item => {
              if (this.form.deliveryWay === item.dictValue) {
                this.form.deliveryWay = item.dictKey;
              }
            });
            this.deliveryTypeData.forEach(item => {
              if (this.form.deliveryType === item.dictValue) {
                this.form.deliveryType = item.dictKey;
              }
            });
            this.periodOfTimeData.forEach(item => {
              if (this.form.periodOfTime === item.dictValue) {
                this.form.periodOfTime = item.dictKey;
              }
            });
            this.form.serveType = this.serveType.sort().join(',');
            //服务号
            this.orderData.forEach(item => {
              console.log('-------------->item', item);
              if (!item.packageListInfo) {
                item.packageListInfo = item.parcelListVOS;
              }
            });
            console.log('------------------->this.form.inventoryList', this.form.inventoryList);
            console.log(
              '------------------->this.form.stockArticleList',
              this.form.stockArticleList
            );

            if (this.form.inventoryList.length === 0 && this.form.stockArticleList.length === 0) {
              this.$message({
                type: 'warning',
                message: '无效的预约计划!',
              });
              operation = false;
              return;
            }
            if (!operation) return;

            // this.form.stockArticleList = this.packageList;
            console.log('>>>>>>>>', this.form);
            if (this.reservationId) {
              // 判断是否都没有选择包件
              const checkInfoValues = this.form.stockArticleList.every(
                item => !item.packageListInfo || !item.packageListInfo.length
              );
              if (checkInfoValues) {
                ElMessageBox.prompt(
                  '当前所有订单都没有选择包件是否确认"取消本次计划"?',
                  '请填写取消原因',
                  {
                    confirmButtonText: '确认',
                    cancelButtonText: '关闭',
                    inputPattern: /^\S+$/,
                    inputErrorMessage: '请填写取消原因',
                  }
                )
                  .then(value => {
                    let data = {
                      cancelReason: value.value,
                      id: this.$route.query.reservationId,
                    };
                    this.reservationloading = true;
                    cancelReservation(data)
                      .then(res => {
                        console.log(res);
                        if (res.data.code == 200) {
                          ElMessage({
                            message: res.data.msg,
                            type: 'success',
                          });
                          this.$router.push('/distribution/reservation/reservation');
                          this.$store.commit('DEL_TAG_CURRENT');
                        }
                      })
                      .catch(error => {
                        this.reservationloading = false;
                        console.log(error);
                      });
                    console.log(data, '要提交的数据');
                  })
                  .catch(() => {});
              } else {
                for (let i = 0; i < this.form.stockArticleList.length; i++) {
                  if (
                    !this.form.stockArticleList[i].packageListInfo ||
                    !this.form.stockArticleList[i].packageListInfo.length
                  ) {
                    ElMessageBox.confirm(
                      `订单自编号:${this.form.stockArticleList[i].orderCode}没有选择包件是否移除!`,
                      '提示',
                      {
                        confirmButtonText: '确认',
                        cancelButtonText: '取消',
                        type: 'warning',
                      }
                    )
                      .then(() => {
                        this.renderOrderData.splice(i, 1);
                        this.form.stockArticleList.splice(i, 1);
                      })
                      .catch(() => {});
                    return;
                  }
                }
              }
              // 开启提交按钮loading
              this.loadingObj.submitBtnLoading = true;
              this.reservationloading = true; //开启全屏加载
              this.form.id = this.reservationId;

              const res = await update(this.form);
              console.log('res :>> ', res);
              if (res.data.code !== 200) return;
              this.$message({
                type: 'success',
                message: '操作成功!',
              });
              this.back();
            } else {
              // 开启提交按钮loading
              this.loadingObj.submitBtnLoading = true;
              this.reservationloading = true; //开启全屏加载
              this.form.reservationStatus = '20';
              const res = await autonomouslySave(this.form);
              console.log('res :>> ', res);
              if (res.data.code !== 200) return;
              ElMessageBox.confirm('当前预约已完成，是否继续添加预约?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
              })
                .then(() => {
                  this.form = this.Copyfrom;
                  this.Copyfrom = JSON.parse(JSON.stringify(this.form));
                  this.$refs.ruleForm.resetFields(); // 调用重置验证状态的方法
                  this.renderOrderData = []; //订单重置
                  this.serveType = []; //服务类型重置
                  this.renderInventoryData = []; //库存品重置
                  this.orderList = [];
                  this.orderData = [];
                  this.packageListInfo = [];
                  this.stockArticleInfo = [];
                  this.inventoryDat = [];
                  this.inventoryData = [];
                  this.inventoryList = [];
                  delete this.query.marketName;
                  this.marketName = '';
                  (this.activeName = 'orderTab'), console.log(this.orderList, '');
                })
                .catch(() => {
                  this.$message({
                    type: 'success',
                    message: '操作成功!',
                  });
                  this.back();
                });

              // this.$message({
              //   type: 'success',
              //   message: '操作成功!',
              // });
              // this.back();
            }
          } catch (error) {
            console.log('error :>> ', error);
          } finally {
            console.log('123123 :>> ', 123123);
            this.$store.commit('EDIT_REFRESHITEM', { title: 'reservation', status: true });

            // 关闭提交按钮loading
            this.loadingObj.submitBtnLoading = false;
            this.reservationloading = false; //关闭全屏加载
          }
        } else {
          console.log('error submit!');
          return false;
        }
      });
    },
    inputsc() {},
    timesc() {},
    selectsc() {},
    btnsc() {},
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    // 移除包件
    removeStockArticle(row) {
      if (this.inventoryData.length == 0 && this.orderData.length == 1 && this.reservationId) {
        this.$message.warning('如需移除请取消该预约计划!!');
        return;
      }
      this.orderData.forEach((item, index) => {
        if (item.id === row.id) {
          console.log('111 :>> ', 111);
          this.orderData.splice(index, 1);
          const _index = this.renderOrderData.indexOf(item);
          this.renderOrderData.splice(_index, 1);
        }
        console.log(this.orderData, '当前存在的数据');
      });
      console.log('this.renderOrderData :>> ', this.renderOrderData);
      console.log('this.orderData :>> ', this.orderData);
      // 当两个列表没有数据时, 清空限制
      if (this.inventoryData.length === 0 && this.orderData.length === 0) this.marketName = '';
      // 当列表没有数据时, 表单清空
      if (this.orderData.length === 0) {
        this.form.consignee = '';
        this.form.deliveryAddress = '';
        this.form.deliveryPhone = '';
      }
      console.log('>>>>>>>>>>>>>>>row', row);
    },
    removeStockList(row) {
      if (this.inventoryData.length == 1 && this.orderData.length == 0 && this.reservationId) {
        this.$message.warning('如需移除请取消该预约计划!!');
        return;
      }
      this.inventoryData.forEach((item, index) => {
        if (item.id === row.id) {
          this.inventoryData.splice(index, 1);

          const _index = this.renderInventoryData.indexOf(item);
          this.renderInventoryData.splice(_index, 1);
        }
      });
      // 当两个列表没有数据时, 清空限制
      if (this.inventoryData.length === 0 && this.orderData.length === 0) this.marketName = '';
      // 当列表没有数据时, 表单清空
      if (this.inventoryData.length === 0) {
        this.form.consignee = '';
        this.form.deliveryAddress = '';
        this.form.deliveryPhone = '';
      }
      console.log('>>>>>>>>>>>>>>>row', row);
    },
    updateClient(row) {
      console.log('>>>>>>>>>>>>>>>row', row);
      this.dialogVisible = true;
      Object.assign(this.clientData, row);
      console.log('=============>', this.clientData);
    },
    showStockListEdit(row) {
      console.log('>>>>>>>>>>>>>>>row', row);
      //查看库存品详情
      let a = {};
      a.reservationId = this.reservationId;
      a.inventoryId = row.id;
      selectInventoryDetail(1, 20, a).then(res => {
        console.log('------------>', res);
      });
    },
    handleView(row) {
      this.title = '查看';
      this.view = true;
      this.box = true;
      getDetailDelivery(row.id).then(res => {
        this.form = res.data.data;
      });
    },
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
        });
    },
    beforeClose(done) {
      done();
      this.form = {};
      this.view = false;
    },
    selectionChange(list) {
      this.orderList = list;
      console.log('list :>> ', list);
    },
    // 选择包件信息
    selectionPackageChange(list) {
      console.log('掉用了此函数', list);
      console.log(list, 'list22');
      console.log('-----------<>', list);
      this.packageListInfo = list;
      console.log(this.packageListInfo, 'packageListInfo');
      if (this.reservationId) {
        this.packageDataSec = list;
      } else {
        //新增
        let a = [];
        list.forEach(item => {
          if (
            item.orderPackageReservationStatus === '10' ||
            item.orderPackageReservationStatusName === '未预约'
          ) {
            a.push(item);
          }
        });
        this.packageDataSec = a;
      }
    },
    selectionInventoryChange(list) {
      this.inventoryList = list;
    },
    /** 订单搜索 */
    handleSearchOrder(value, row, type) {
      // 输入值后并搜索
      if (type === 1) {
        // 动态设置正则
        const reg = new RegExp('^' + value);

        this.orderQuery[row.prop] = reg;

        if (value === '') delete this.orderQuery[row.prop];
      }

      if (Object.keys(this.orderQuery).length === 0)
        return (this.renderOrderData = [...this.orderData]);

      const _data = this.orderData.filter(value => {
        let _flag = true;
        for (let key in this.orderQuery) {
          if (!this.orderQuery[key].test(value[key])) _flag = false;
          if (!_flag) break;
        }

        return _flag;
      });

      this.renderOrderData = _data;
    },
    /** 库存品搜索 */
    handleSearchStock(value, row, type) {
      // 输入值后并搜索
      if (type === 1) {
        // 动态设置正则
        const reg = new RegExp('^' + value);

        this.stockQuery[row.prop] = reg;

        if (value === '') delete this.stockQuery[row.prop];
      }

      if (Object.keys(this.stockQuery).length === 0)
        return (this.renderInventoryData = [...this.inventoryData]);

      const _data = this.inventoryData.filter(value => {
        let _flag = true;
        for (let key in this.stockQuery) {
          if (!this.stockQuery[key].test(value[key])) _flag = false;
          if (!_flag) break;
        }

        return _flag;
      });

      this.renderInventoryData = _data;
    },
    onSubmitUpdateZeroOrder() {
      console.log('this.obj--------------------->', this.obj);
      console.log('this.zeroOrderData--------------------->', this.zeroOrderData);
      console.log('this.zeroOrderData--------------------->', this.zeroOrderData);

      this.isrReservationEntry = false;
      let a = this.zeroOrderData;
      if (a.length > 1) {
        let b = 0;
        //计算该品类已使用数量

        a.forEach(item => {
          b += item.number;
        });

        let f = a.every(item => {
          console.log('this.number--------------------->', item.number);
          console.log(
            'number--------------------->',
            item.deliveryQuantity + item.outboundQuantity
          );
          if (
            item.number < item.deliveryQuantity + item.outboundQuantity ||
            item.number > item.quantity
          ) {
            return false;
          }
          return true;
        });

        if (b > this.obj.handQuantity) {
          this.$message({
            type: 'error',
            message: '录入数量超过订单在库数量!',
          });
          return;
        }
        if (!f) {
          this.$message({
            type: 'error',
            message: '请检查修改数量!',
          });
          return;
        }
      }
      updateEntryNum(this.zeroOrderData).then(res => {
        if (res) {
          this.$message({
            type: 'success',
            message: '操作成功',
          });
        }
      });
      this.zeroOrderShow = false;
      console.log('-------------->', this.zeroOrderData);
    },
    onSubmitZeroOrder() {
      if (this.isrReservationEntry) {
        //零担预约数量录入
        this.orderData.forEach(item => {
          if (this.obj.id === item.id) {
            item.parcelNumberVOS = this.zeroOrderData;
          }
        });
      } else {
        //在库数量录入
        let a = this.zeroOrderData;
        if (a.length > 0) {
          let n = 0;
          a.forEach(item => {
            n += item.number;
          });
          if (n > this.obj.handQuantity) {
            this.$message({
              type: 'error',
              message: '录入数量超过订单在库数量!',
            });
            return;
          }
          let b = a.every(item => {
            console.log(
              '最大数量-------------->',
              item.handQuantity + item.outboundQuantity + item.deliveryQuantity + item.number
            );
            if (
              item.handQuantity + item.outboundQuantity + item.deliveryQuantity + item.number >
              item.quantity
            ) {
              return false;
            }
            return true;
          });
          console.log('----------------->', b);
          if (!b) {
            this.$message({
              type: 'error',
              message: '请输入正确数量!',
            });
            return;
          }
        }
        entryNum(this.zeroOrderData).then(res => {
          if (res) {
            this.$message({
              type: 'success',
              message: '操作成功',
            });
          }
        });
        console.log('this.zeroOrderData------------->', this.zeroOrderData);
      }

      this.zeroOrderShow = false;
    },
    // 增加库存品
    onSubmitInventory() {
      if (this.inventoryList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      console.log('this.inventoryList :>> ', this.inventoryList);

      // const stockArr = [...this.inventoryData, ...this.inventoryList];
      const _markeName = this.marketName
        ? this.marketName
        : removeZeroWidth(this.inventoryList[0].marketName);

      // 检测商场是否选择统一商场
      let message = '';
      for (let i = 0; i < this.inventoryList.length; i++) {
        const value = this.inventoryList[i];
        if (_markeName !== value.marketName) {
          message = '请选择统一商场!!!';
          break;
        } else if (Number(value.reservationNum) > Number(value.applyNum)) {
          message = '该库存品数量输入有误!!!';
          break;
        }
      }

      if (message) {
        this.$message.warning(message);
        return;
      }

      this.marketName = _markeName;

      this.inventoryData = this.inventoryList;
      this.handleSearchStock();

      this.stockListShow = false;
    },
    /**
     * 增加订单提交
     */
    onSubmitOrder() {
      console.log('orderList-------------》', this.orderList);
      if (this.orderList.length === 0) return this.$message.warning('最少选择一条数据!!!');
      const list = [...this.orderList];
      let _name = removeZeroWidth(list[0].customerName.trim());
      let _address = removeZeroWidth(list[0].customerAddress.trim());
      let _phone = removeZeroWidth(list[0].customerTelephone.trim());
      if (this.marketName === '') this.marketName = removeZeroWidth(list[0].mallName.trim());
      const _markeName = this.marketName
        ? removeZeroWidth(list[0].mallName.trim())
        : this.marketName;

      let message = '';
      // 循环查看数据是否符合要求
      for (let i = 0; i < list.length; i++) {
        const item = list[i];
        if (item.mallName.trim() !== _markeName) {
          message = '请选择统一商场!!!';
          break;
        }

        if (
          removeZeroWidth(item.customerName.trim()) !== _name ||
          removeZeroWidth(item.customerAddress.trim()) !== _address ||
          removeZeroWidth(item.customerTelephone.trim()) !== _phone
        ) {
          console.log('i :>> ', i);
          message = '请选择统一顾客订单!!!';
          break;
        }
      }

      if (message) return this.$message.warning(message);

      // 设置商场名称
      this.marketName = _markeName;

      this.form.consignee = _name;
      this.form.deliveryAddress = _address;
      this.form.deliveryPhone = _phone;

      //这里需要对选择的订单进行筛选
      this.orderData = [...this.orderList];
      this.orderData.forEach(item => {
        item.reservationNum = item.handQuantity;
      });
      this.handleSearchOrder();
      this.orderShow = false;
    },
    selectionClear() {
      this.selectionList = [];
      this.query = {};
      // this.$refs.table.clearSelection();
    },
    currentOrderChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoadOrder(this.page);
    },
    sizeOrderChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoadOrder(this.page);
    },
    onLoadEditOrder(params = {}) {
      this.query.typeService = 2;
      this.query.genre = '1';
      const page = this.page;
      let a = [];
      if (this.orderData) {
        this.orderData.forEach(item => {
          a.push(item.id);
        });
      }
      this.query.orderIds = a.join(',');
      this.query.reservationId = this.reservationId;
      selectUpdateAvailableStockArticle(
        page.currentPage,
        page.pageSize,
        this.reservationId,
        Object.assign(params, this.query)
      ).then(res => {
        console.log('res123123------------>', res);
        const data = res.data.data;
        console.log('data :>> ', data);
        this.stockArticleInfo = data.records;
        this.stockArticleInfo.forEach((item, index) => {
          //检查订单是否冻结
          this.checkOrder(item, index);
          if (this.orderData) {
            this.orderData.forEach(o => {
              if (o.id === item.id) {
                //回显选择的包件信息
                this.$nextTick(() => {
                  this.$refs.orderList.toggleRowSelection(this.stockArticleInfo[index], true);
                });
              }
            });
          } else {
            this.orderList = [];
          }
        });
        this.page.total = data.total;
      });
      // this.query = {};
    },
    inputscStockArtic(index, row) {
      console.log(index, row);
      this.query[row.prop] = index;
      this.onLoadOrder(this.page);
    },
    inputscInventory(index, row) {
      this.inventoryPage.currentPage = 1;
      this.query[row.prop] = index;
      this.onLoadInventory();
    },
    inputscPackage(index, row) {
      console.log('index===========>', index);
      console.log('row=======>', row);
      this.packageQuery[row.prop] = index;
      //编辑过滤

      this.getPackageList(this.orderRow);
    },
    inventorySizeChange(value) {
      console.log('value :>> ', value);
      this.inventoryPage.pageSize = value;
      this.inventoryPage.currentPage = 1;
      this.onLoadInventory();
    },
    inventoryCurrentChange(value) {
      console.log('value :>> ', value);
      this.inventoryPage.currentPage = value;
      this.onLoadInventory();
    },
    /** 新增 */
    async getAddPackageList(row, param) {
      try {
        let page = this.page;
        this.packageQuery.id = row.id;
        //新增
        const res = await getPackageListByStockArticleId(
          page.currentPage,
          page.pageSize,
          Object.assign(param, this.packageQuery)
        );
        console.log('res---------------->', res);
        // console.log(res.data.data.records);
        if (res.data.data) {
          this.packageData = res.data.data.records;
          // 新增默认勾选全部
          this.packageDataSec = this.packageData;
        }
        this.isaddvalue = true;
      } catch (err) {
        console.log('err >>>>', err);
      } finally {
        return null;
      }
    },

    /** 修改 */
    async getEditPackageList(row, param) {
      try {
        console.log('row :>> ', row);
        let page = this.page;
        this.packageQuery.reservationId = this.reservationId;
        this.packageQuery.orderId = row.id;
        this.packageQuery.reservationId = this.reservationId;
        console.log('this.packageQuery :>> ', this.packageQuery);
        const res = await getReservationPackageListByOrderId(
          page.currentPage,
          page.pageSize,
          Object.assign(param, this.packageQuery)
        );

        const { code, data } = res.data;
        if (code !== 200 && data) return;
        console.log('data>>>', data);
        console.log('->>>>>>>>>>>>>>>>>>查看包件', res);

        this.packageData = data.data.packageList;
        let idList = (data.data.reservationPackageList || []).map(v => {
          return v.id;
        });
        this.packageDataSec = this.packageData.filter(val => idList.includes(val.id));

        this.isaddvalue = true;
      } catch (err) {
        console.log('err >>>>', err);
      } finally {
        return null;
      }
    },

    async getPackageList(row, param = {}) {
      this.loading = true;
      console.log('111 :>> ', 111);
      if (this.reservationId) await this.getEditPackageList(row, param);
      else await this.getAddPackageList(row, param);
      this.loading = false;
    },

    timescStockArtic(index, row) {
      console.log(index, row);
      if (!!index) {
        index = dayjs(index).format('YYYY-MM-DD');
      }
      this.query[row.prop] = index;
      if (!index) {
        delete this.query[row.prop];
      }
      this.onLoadOrder(this.page);
    },
    btnscStockArtic(index, row) {
      console.log(index, row);
      this.onLoad(this.page);
    },
    selectscStockArtic(index, row) {
      console.log(index, row);
      // if (row.prop === 'reservationStatusName') {
      //   this.query['reservationStatus'] = index;
      // } else if (row.prop === 'freezeStatusName') {
      //   this.query['freezeStatus'] = index;
      // } else if (row.prop === 'completeSetName') {
      //   this.query['completeSet'] = index;
      // } else {
      //   this.query[row.prop] = index;
      // }
      const _name = row.prop.replace('Name', '');
      this.query[_name] = index;
      if (index === '') delete this.query[_name];
      this.onLoadOrder(this.page);
    },
    async onLoadOrder(page, params = {}) {
      try {
        this.loading = true;
        this.query.typeService = 2;
        this.query.genre = '1';
        if (this.marketName) this.query.mallName = this.marketName;
        // if (this.orderData.length !== 0) {
        //   this.query.orderIds = this.orderData.map(val => val.id).join(',');
        // }
        console.log('--------------query>', this.query);
        const res = await selectStockArticleInfoList(
          page.currentPage,
          page.pageSize,
          Object.assign(params, this.query)
        );
        const {
          code,
          data: { records, total },
        } = res.data;

        if (code !== 200) return;

        console.log('this.orderList', this.orderList);
        const _chooseArr = [...this.orderList];

        this.stockArticleInfo = records;

        for (let i = 0; i < this.stockArticleInfo.length; i++) {
          const value = this.stockArticleInfo[i];

          value.completeSetName = Number(value.completeSet) === 2 ? '已齐套' : '未齐套';
          value.isZeroName = Number(value.isZero) === 1 ? '是' : '否';
        }
        console.log('this.stockArticleInfo :>> ', this.stockArticleInfo);
        // this.stockArticleInfo.forEach((item, index) => {
        //   //检查订单是否冻结
        //   this.checkOrder(item, index);
        // });
        this.page.total = total;

        if (_chooseArr.length !== 0) {
          // 获取ids的映射数组
          const ids = [];
          for (let i = 0; i < _chooseArr.length; i++) {
            ids.push(_chooseArr[i].id);
          }
          console.log('ids :>> ', ids);
          // 赋值给回显勾选的数组
          for (let i = 0; i < records.length; i++) {
            const value = records[i];
            // 循环获取符合条件的库存品组成数组
            const _index = ids.indexOf(value.id);
            if (_index !== -1) _chooseArr.splice(_index, 1, value);
          }
        }

        await this.$nextTick();
        setTimeout(() => {
          this.$refs.orderTableNode.handleCheckSelect(_chooseArr);
        }, 10);
        return null;
      } catch (error) {
        console.log('error :>> ', error);
      } finally {
        this.loading = false;
        return null;
      }
    },
    onLoad() {
      // this.loading = true;
      this.form.deliveryType = '2';
      this.form.deliveryWay = '10';
      this.form.periodOfTime = '3';
      this.form.otherFee = 0;
      this.form.replaceFee = 0;
      this.form.collectionFee = 0;
      this.form.isUrgent = '1';
      // this.form.reservationDate = new Date();

      if (this.orderIds) {
        this.reservationloading = true;
        if (res.data.code !== 200) {
          this.reservationloading = false;
          return;
        }
        getStockArticleList(this.orderIds).then(res => {
          console.log(res.data.data);
          const data = res.data.data;
          let name = '';
          let phone = '';
          let address = '';
          let typeService = '';
          console.log('>>>>>>>>>>>>>', data);
          for (let i = 0; i < data.length; i++) {
            if (i === 0) {
              name = data[0].customerName;
              phone = data[0].customerTelephone;
              address = data[0].customerAddress;
              typeService = data[0].typeService.toString();
              // typeName = data[0].typeName;
            }
          }
          this.form.consignee = name;
          this.form.deliveryPhone = phone;
          this.form.deliveryType = typeService;
          this.form.deliveryAddress = address;
          this.orderData = data;
          this.renderOrderData = [...this.orderData];
          this.reservationloading = false;
        });
      }
      if (this.reservationId) {
        this.reservationloading = true;
        this.inventoryShow = true;
        getReservationInfo(this.reservationId).then(res => {
          if (res.data.code !== 200) {
            this.reservationloading = false;
            return;
          }
          const reservation = res.data.data;
          const stockArticleListInfo = res.data.data.stockArticleList;
          // stockArticleListInfo.forEach(item=>{
          //
          // })
          console.log('reservation>>>>>>>>', reservation);
          // 添加限制的商场名称
          this.marketName = reservation.mallName;
          this.orderData = reservation.stockArticleList;
          this.renderOrderData = [...this.orderData];
          this.inventoryData = reservation.inventoryList;
          this.inventoryData.forEach(item => {
            item.quantityOccupied -= item.reservationNum;
            item.applyNum = item.quantityStock - item.quantityOccupied;
          });
          this.renderInventoryData = [...this.inventoryData];
          this.form.deliveryType = reservation.deliveryType;
          this.form.periodOfTime = reservation.periodOfTime;
          if (reservation.serveType) {
            //过滤字符串中的','
            this.serveType = Array.from(reservation.serveType).filter(s => {
              return s !== ',';
            });
          }
          this.form = reservation;
          this.reservationloading = false;
        });
      } else {
        this.form.deliveryType = '2';
      }
      this.loading = false;
    },
  },
};
</script>

<style lang="scss" scoped>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

input[type='number'] {
  -moz-appearance: textfield;
}
</style>

<style lang="scss" scoped>
.el-btn-xz {
  width: 68px;
  height: 26px;
  border: 1px solid;
  margin-bottom: 8px;
  border-radius: 4px;
}

.clientRow {
  display: block;
  min-height: 1px;
  margin-bottom: 32px;
  font-size: larger;
  margin-left: 24px;
  font-weight: bold;
  width: 2000px;
}

// 提交按钮容器
.submit-container {
  position: fixed;
  bottom: 20px;
  left: 0;
  z-index: 999;
  width: 100%;
  text-align: center;
  box-sizing: border-box;
}

// 底部站位
.footer-container {
  height: 60px;
}
.el_sumS {
  span {
    width: 100px;
  }
  display: flex;
  height: 20px;
  width: 200px;
}
</style>
