<template>
  <div class="ele-body warehouseAdd">
    <el-card shadoe="never">
      <header>
        <span class="title">{{ titleObj.code }} {{ titleObj.name }}</span>
        <div>
          <el-button @click="$router.go(-1)">返回</el-button>
          <el-button type="primary" @click="submit" :loading="loading"
            >保存</el-button
          >
        </div>
      </header>
      <div
        class="ele-bg-primary"
        style="width: 100%; height: 2px; margin-top: 15px"
      ></div>

      <div class="area">
        <div class="mt20 reservoirArea">
          <span>库区</span>
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="small"
            @click="addArea"
            >添加库区
          </el-button>
        </div>
        <div class="mt10">
          <el-form
            :model="areaForm"
            ref="areaFormName"
            class="areaForm"
            :rules="areaRules"
          >
            <el-table
              ref="multipleTable"
              :data="areaForm.warehouseAreasSaveList"
              tooltip-effect="dark"
              style="width: 100%"
              stripe
              :header-cell-style="{ background: '#EEEEEE', border: 'none' }"
            >
              <el-table-column label="库区编号" prop="code" min-width="120">
                <template slot-scope="{ row, $index }">
                  <el-form-item
                    :prop="'warehouseAreasSaveList.' + $index + '.code'"
                    :rules="areaRules.code"
                    v-if="row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      clearable
                      v-model="row.code"
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ row.code }}</span>
                </template>
              </el-table-column>
              <el-table-column label="库区名称" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="'warehouseAreasSaveList.' + scope.$index + '.name'"
                    :rules="areaRules.name"
                    v-if="scope.row.isEdit"
                    id="reservoirAreaRef"
                  >
                    <el-input
                      placeholder="请输入"
                      clearable
                      v-model="scope.row.name"
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.name }}</span>
                </template>
              </el-table-column>
              <el-table-column label="库区类型" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'warehouseAreasSaveList.' +
                      scope.$index +
                      '.extInfo[0].areaType'
                    "
                    :rules="areaRules.areaType"
                    id="reservoirAreaRef"
                    v-if="scope.row.isEdit"
                  >
                    <el-select
                      filterable
                      v-model="scope.row.extInfo[0].areaType"
                      placeholder="请选择"
                      clearable
                    >
                      <el-option
                        v-for="(item, idx) in warehouseDefinition_areaType"
                        :key="idx"
                        :value="item.code"
                        :label="item.label"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <span v-else>{{
                    scope.row.extInfo[0].areaType
                      | filterAreaType(warehouseDefinition_areaType)
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column label="库区属性" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'warehouseAreasSaveList.' +
                      scope.$index +
                      '.extInfo[0].attribute'
                    "
                    :rules="areaRules.attribute"
                    v-if="scope.row.isEdit"
                  >
                    <el-select
                      filterable
                      v-model="scope.row.extInfo[0].attribute"
                      placeholder="请选择"
                      clearable
                    >
                      <el-option
                        v-for="(item, idx) in warehouseDefinition_areaAttribute"
                        :key="idx"
                        :value="item.code"
                        :label="item.label"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <span v-else>{{
                    scope.row.extInfo[0].attribute
                      | filterAreaType(warehouseDefinition_areaAttribute)
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column label="库区位置" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'warehouseAreasSaveList.' +
                      scope.$index +
                      '.extInfo[0].address'
                    "
                    :rules="areaRules.address"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      clearable
                      v-model="scope.row.extInfo[0].address"
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].address }}</span>
                </template>
              </el-table-column>
              <el-table-column label="库区长(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'warehouseAreasSaveList.' +
                      scope.$index +
                      '.extInfo[0].areaLength'
                    "
                    :rules="areaRules.areaLength"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      clearable
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].areaLength"
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].areaLength }}</span>
                </template>
              </el-table-column>
              <el-table-column label="库区宽(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'warehouseAreasSaveList.' +
                      scope.$index +
                      '.extInfo[0].areaWidth'
                    "
                    :rules="areaRules.areaWidth"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      clearable
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].areaWidth"
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].areaWidth }}</span>
                </template>
              </el-table-column>
              <el-table-column label="库区高(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'warehouseAreasSaveList.' +
                      scope.$index +
                      '.extInfo[0].areaHigh'
                    "
                    :rules="areaRules.areaHigh"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].areaHigh"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].areaHigh }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货架数量" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'warehouseAreasSaveList.' + scope.$index + '.subCount'
                    "
                    :rules="areaRules.subCount"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      @input="
                        (value) =>
                          (scope.row.subCount = value.replace(
                            /^(0+)|[^\d]+/g,
                            ''
                          ))
                      "
                      v-model.number="scope.row.subCount"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.subCount }}</span>
                </template>
              </el-table-column>

              <!-- <el-table-column label="库区条码">
              <template slot-scope="scope">
                <el-form-item
                  :prop="
                    'warehouseAreasSaveList.' + scope.$index + 'areaBarcode'
                  "
                  v-if="scope.row.isEdit"
                >
                  <el-input
                    placeholder="自动生成"
                    disabled
                    v-model="scope.row.areaBarcode"
                  ></el-input>
                </el-form-item>
                <span v-else>{{ scope.row.areaBarcode }}</span>
              </template>
            </el-table-column> -->
              <el-table-column label="备注" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="'warehouseAreasSaveList.' + scope.$index + 'remark'"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="textarea"
                      clearable
                      :rows="1"
                      v-model="scope.row.remark"
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.remark }}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" fixed="right" width="150">
                <template slot-scope="{ row, $index }">
                  <el-button
                    type="text"
                    v-if="row.isEdit"
                    @click="saveArea($index)"
                    >保存</el-button
                  >

                  <el-button type="text" v-else @click="addShelf(row, $index)"
                    >添加货架</el-button
                  >
                  <el-button type="text" @click="remove1($index, row)"
                    >删除库区</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-form>
        </div>
      </div>
      <!-- <div
      class="area"
      v-if="
        areaForm.areaGoodsshelvesList &&
        areaForm.areaGoodsshelvesList.length !== 0
      "
    > -->
      <div class="area">
        <div class="mt20 reservoirArea">
          <span>货架</span>
        </div>
        <div class="mt10">
          <el-form :model="areaForm" ref="areaCoodsForm" class="areaForm">
            <el-table
              ref="multipleTable"
              :data="areaForm.areaGoodsshelvesList"
              tooltip-effect="dark"
              style="width: 100%"
              stripe
              :header-cell-style="{ background: '#EEEEEE', border: 'none' }"
            >
              <el-table-column
                label="库区编号"
                prop="reservoirAreaCode"
              ></el-table-column>
              <el-table-column label="货架编号" prop="code" min-width="120">
                <template slot-scope="{ row, $index }">
                  <el-form-item
                    :prop="'areaGoodsshelvesList.' + $index + '.code'"
                    :rules="areaCoodsRules.code"
                    v-if="row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      clearable
                      v-model="row.code"
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ row.code }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货架行数" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'areaGoodsshelvesList.' +
                      scope.$index +
                      '.extInfo[0].line'
                    "
                    :rules="areaCoodsRules.line"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @input="
                        (value) =>
                          (scope.row.extInfo[0].line = value.replace(
                            /^(0+)|[^\d]+/g,
                            ''
                          ))
                      "
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].line"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].line }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货架列数" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'areaGoodsshelvesList.' +
                      scope.$index +
                      '.extInfo[0].column'
                    "
                    :rules="areaCoodsRules.column"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @input="
                        (value) =>
                          (scope.row.extInfo[0].column = value.replace(
                            /^(0+)|[^\d]+/g,
                            ''
                          ))
                      "
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].column"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].column }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货架长(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'areaGoodsshelvesList.' +
                      scope.$index +
                      '.extInfo[0].areaLength'
                    "
                    :rules="areaCoodsRules.areaLength"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].areaLength"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].areaLength }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货架宽(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'areaGoodsshelvesList.' +
                      scope.$index +
                      '.extInfo[0].areaWidth'
                    "
                    :rules="areaCoodsRules.areaWidth"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].areaWidth"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].areaWidth }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货架高(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'areaGoodsshelvesList.' +
                      scope.$index +
                      '.extInfo[0].areaHigh'
                    "
                    :rules="areaCoodsRules.areaHigh"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].areaHigh"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].areaHigh }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货位数量" prop="" min-width="120">
                <template slot-scope="{ row }">
                  {{ setNUm(row) }}
                </template>
              </el-table-column>
              <el-table-column
                label="是否规则"
                prop="isRegular"
                min-width="120"
              >
                <template slot-scope="{ row }">
                  <el-select
                    filterable
                    v-model="row.extInfo[0].isRegular"
                    v-if="row.isEdit"
                  >
                    <el-option
                      v-for="item in warehouseDefinition_isRegular"
                      :key="item.code"
                      :value="item.code"
                      :label="item.label"
                    ></el-option>
                  </el-select>
                  <template v-else>
                    {{
                      row.extInfo[0].isRegular
                        | filterAreaType(warehouseDefinition_isRegular)
                    }}
                  </template>
                </template>
              </el-table-column>
              <!-- <el-table-column
              label="货架条码"
              prop="goodsshelvesBarcode"
            ></el-table-column> -->
              <el-table-column label="备注" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="'areaGoodsshelvesList.' + scope.$index + '.remark'"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      v-model="scope.row.remark"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.remark }}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" fixed="right" min-width="120">
                <template slot-scope="{ $index, row }">
                  <el-button
                    type="text"
                    v-if="row.isEdit"
                    @click="saveGoods($index, row)"
                    >保存</el-button
                  >
                  <el-button type="text" @click="removeGoods1($index, row)"
                    >删除货架</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-form>
        </div>
      </div>

      <!-- <div
      class="area"
      v-if="
        areaForm.allocationReqList && areaForm.allocationReqList.length !== 0
      "
    > -->
      <div class="area">
        <div class="mt20 reservoirArea">
          <span>货位</span>
          <!-- <el-button type="primary" @click="reuse">复用</el-button> -->
        </div>
        <div class="mt10">
          <el-form :model="areaForm" ref="allocationForm" class="areaForm">
            <el-table
              ref="multipleTable"
              :data="areaForm.allocationReqList"
              tooltip-effect="dark"
              style="width: 100%"
              stripe
              :header-cell-style="{ background: '#EEEEEE', border: 'none' }"
            >
              <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
              <el-table-column label="货架编号" prop="goodsShelvesCode">
                <template slot-scope="{ row }">
                  {{ row.warehouseAreaCode + '-' + row.warehouseAreaGoodsCode }}
                </template>
              </el-table-column>
              <el-table-column
                label="货位编号"
                prop="goodsAllocationCode"
                min-width="120"
              >
                <template slot-scope="{ row, $index }">
                  <el-form-item
                    :prop="
                      'allocationReqList.' + $index + '.goodsAllocationCode'
                    "
                    :rules="areaLocationRules.goodsAllocationCode"
                    v-if="row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      clearable
                      v-model="row.goodsAllocationCode"
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ row.goodsAllocationCode }}</span>
                </template></el-table-column
              >
              <el-table-column label="货位长(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'allocationReqList.' +
                      scope.$index +
                      '.extInfo[0].goodsAllocationLength'
                    "
                    :rules="areaLocationRules.allocationReq"
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      @blur="onBlur(scope.row)"
                      v-model.number="
                        scope.row.extInfo[0].goodsAllocationLength
                      "
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{
                    scope.row.extInfo[0].goodsAllocationLength
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货位宽(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'allocationReqList.' +
                      scope.$index +
                      '.extInfo[0].goodsAllocationWide'
                    "
                    v-if="scope.row.isEdit"
                    :rules="areaLocationRules.allocationReq"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].goodsAllocationWide"
                      @blur="onBlur(scope.row)"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{
                    scope.row.extInfo[0].goodsAllocationWide
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column label="货位高(cm)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'allocationReqList.' +
                      scope.$index +
                      '.extInfo[0].goodsAllocationHigh'
                    "
                    v-if="scope.row.isEdit"
                    :rules="areaLocationRules.allocationReq"
                  >
                    <el-input
                      placeholder="请输入"
                      @blur="onBlur(scope.row)"
                      type="number"
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].goodsAllocationHigh"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{
                    scope.row.extInfo[0].goodsAllocationHigh
                  }}</span>
                </template>
              </el-table-column>
              <el-table-column label="限重(kg)" min-width="120">
                <template slot-scope="scope">
                  <!-- :rules="areaLocationRules.weightLimit"
                    :prop="
                      'allocationReqList.' +
                      scope.$index +
                      '.extInfo[0].weightLimit'
                    " -->
                  <el-form-item v-if="scope.row.isEdit">
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].weightLimit"
                      clearable
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].weightLimit }}</span>
                </template>
              </el-table-column>
              <el-table-column label="基本货位容积(cm³)" min-width="120">
                <template slot-scope="scope">
                  <el-form-item
                    :prop="
                      'allocationReqList.' +
                      scope.$index +
                      '.extInfo[0].volumeUnit'
                    "
                    v-if="scope.row.isEdit"
                  >
                    <el-input
                      placeholder="请输入"
                      type="number"
                      @mousewheel.native.prevent
                      v-model.number="scope.row.extInfo[0].volumeUnit"
                      disabled
                    ></el-input>
                  </el-form-item>
                  <span v-else>{{ scope.row.extInfo[0].volumeUnit }}</span>
                </template>
              </el-table-column>
              <!-- <el-table-column
              label="货位条码"
              prop="allocationBarcode"
            ></el-table-column> -->
            </el-table>
          </el-form>
        </div>
      </div>
    </el-card>
    <!-- 规则货架编号 -->
    <el-dialog title="规则货架编号" :visible.sync="hjCodeFalg" width="20%">
      <el-form :model="hjForm">
        <el-form-item label="规则类型" label-width="100px">
          <el-radio-group v-model="hjForm.type">
            <el-radio :label="1">字母</el-radio>
            <el-radio :label="2">字母+数字</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="规则名称定义" label-width="100px">
          <el-input v-model="hjForm.code" @input="handleInput"></el-input>
          <span style="color: #dab8b8">注：只可输入大写A-Z</span>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="hjCodeFalg = false">取 消</el-button>
        <el-button @click="handleMine" type="primary">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  // import selectTree from '@/components/selectTree';
  import warehouseDefinition from '@/api/warehouseManagement/warehouseDefinition';

  import {
    warehouseDefinition_areaType,
    warehouseDefinition_areaAttribute,
    warehouseDefinition_isRegular,
    useDictLabelFilter
  } from '@/utils/dict/index';
  import { assignObject } from 'ele-admin/es/utils/core';

  // import { throttle } from 'lodash';
  export default {
    // components: { selectTree },
    filters: {
      filterAreaType: useDictLabelFilter
    },
    data() {
      // const msg = throttle(
      //   () => this.$message.error('货架总体积不能大于库区体积！'),
      //   500
      // );

      const allocationReqValidator = (column, value, callback) => {
        if (!value) {
          callback(new Error('不能为空！'));
        } else {
          // 货位体积限制
          const index = +column.field.split('.')[1];
          const row = this.areaForm.allocationReqList[index];

          const parent = this.areaForm.areaGoodsshelvesList.find(
            (t) => t.code === row.code
          );

          let sameParentSavedSum = this.areaForm.allocationReqList
            .filter((t) => t.goodsShelvesCode === row.code)
            .reduce((sum, item) => {
              if (!item.isEdit) {
                sum +=
                  item.extInfo[0].goodsAllocationLength *
                  item.extInfo[0].goodsAllocationWide *
                  item.extInfo[0].goodsAllocationHigh;
              }
              return sum;
            }, 0);

          if (parent) {
            const max =
              parent.extInfo[0].areaLength *
              parent.extInfo[0].areaWidth *
              parent.extInfo[0].areaHigh;

            if (
              max - sameParentSavedSum <
              row.extInfo[0].goodsAllocationLength *
                row.extInfo[0].goodsAllocationWide *
                row.extInfo[0].goodsAllocationHigh
            ) {
              msg();
              callback(new Error('货架总体积不能大于库区体积！'));
              return;
            }
          }
          callback();
        }
      };

      return {
        warehouseDefinition_isRegular,
        warehouseDefinition_areaType,
        warehouseDefinition_areaAttribute,
        loading: false,
        hjCodeFalg: false,
        hjCodeIndex: 0,
        hjForm: { code: '', type: 1 },
        areaForm: {
          warehouseAreasSaveList: [], //库区
          areaGoodsshelvesList: [], //货架
          allocationReqList: [] //货位
        },
        areaCoodsRules: {
          code: {
            required: true,
            message: '请输入货架编号',
            trigger: 'blur'
          },
          line: {
            required: true,
            message: '请输入货架行',
            trigger: 'blur'
          },
          column: {
            required: true,
            message: '请输入货架列',
            trigger: 'blur'
          },
          areaLength: {
            required: true,
            message: '请输入货架长',
            trigger: 'blur'
          },
          areaWidth: {
            required: true,
            message: '请输入货架宽',
            trigger: 'blur'
          },
          areaHigh: {
            required: true,
            message: '请输入货架高',
            trigger: 'blur'
          }
        },
        areaLocationRules: {
          code: {
            required: true,
            message: '请输入货位编号',
            trigger: 'blur'
          },
          weightLimit: {
            required: true,
            message: '请输入货位限重',
            trigger: 'blur'
          },
          allocationReq: {
            required: true,
            validator: allocationReqValidator,
            trigger: 'blur'
          }
        },
        isPageEdit: false,
        areaRules: {
          code: { required: true, message: '请输入库区编号', trigger: 'blur' },
          name: { required: true, message: '请输入库区名称', trigger: 'blur' },
          areaType: {
            required: true,
            message: '请选择库区类型',
            trigger: 'change'
          },
          attribute: {
            required: true,
            message: '请选择库区属性',
            trigger: 'change'
          },
          address: {
            required: true,
            message: '请输入库区位置',
            trigger: 'blur'
          },
          areaLength: {
            required: true,
            message: '请输入库区长',
            trigger: 'blur'
          },
          areaWidth: {
            required: true,
            message: '请输入库区宽',
            trigger: 'blur'
          },
          areaHigh: {
            required: true,
            message: '请输入库区高',
            trigger: 'blur'
          },
          subCount: {
            required: true,
            message: '请输入货架数量',
            trigger: 'blur'
          }
        },
        areaDisabled: true,
        addressDisabled: true,
        ownerNameDisabled: true,
        areaList: [],
        inventoryList: [
          { value: '1', name: '物料库' },
          { value: '2', name: '产品库' },
          { value: '3', name: '设备库' }
        ],
        statusList: [
          { value: '0', name: '失效' },
          { value: '1', name: '生效' }
        ],
        formData: {
          code: '',
          name: '',
          inventoryType: '',
          factoryId: '',
          enabled: '',
          remarks: ''
        },
        factoryList: [], //所属工厂
        staffList: [],
        multipleSelection: [],
        shelfObj: {},
        longWidthHeightBol: false,
        savedWarehouse: [],
        savedShelves: [],
        titleObj: {},
        warehouseVO: {}
      };
    },
    computed: {},
    created() {
      const { query } = this.$route;
      this.titleObj.code = query.code;
      this.titleObj.name = query.name;
      this.formData.id = query.id;
      this.getDetail(query.id);
    },
    methods: {
      handleInput(event) {
        // 只允许输入 A-Z 的大写字母
        let filteredValue = this.hjForm.code.replace(/[^A-Z]/g, '');
        this.hjForm.code = filteredValue;
      },
      setNUm(row) {
        let result = Number.isNaN(row.extInfo[0].line * row.extInfo[0].column)
          ? ''
          : row.extInfo[0].line * row.extInfo[0].column;
        row.subCount = result;
        return result;
      },
      handleHouse(obj) {
        const {
          warehouseAreasSaveList,
          areaGoodsshelvesList,
          allocationReqList
        } = obj;
        let kqArr = [];
        for (const key in warehouseAreasSaveList) {
          kqArr.push({
            name: warehouseAreasSaveList[key].name,
            code: warehouseAreasSaveList[key].code,
            extInfo: [
              {
                areaType: warehouseAreasSaveList[key].type,
                attribute: warehouseAreasSaveList[key].attribute,
                address: warehouseAreasSaveList[key].address,
                areaLength: warehouseAreasSaveList[key].areaLength,
                areaWidth: warehouseAreasSaveList[key].areaWide,
                areaHigh: warehouseAreasSaveList[key].areaHigh
              }
            ],
            subCount: warehouseAreasSaveList[key].num,
            remark: warehouseAreasSaveList[key].areaRemark
          });
        }
        let hjArr = [];
        for (const key in areaGoodsshelvesList) {
          hjArr.push({
            ...areaGoodsshelvesList[key],
            reservoirAreaCode: areaGoodsshelvesList[key].warehouseAreaCode,
            code: areaGoodsshelvesList[key].goodsshelvesCode,
            extInfo: [
              {
                line: areaGoodsshelvesList[key].goodsshelvesLine,
                column: areaGoodsshelvesList[key].goodsshelvesColumn,
                areaLength: areaGoodsshelvesList[key].goodsshelvesLength,
                areaWidth: areaGoodsshelvesList[key].goodsshelvesWide,
                areaHigh: areaGoodsshelvesList[key].goodsshelvesHigh,
                isRegular: areaGoodsshelvesList[key].isRegular
              }
            ],
            remark: areaGoodsshelvesList[key].goodsshelvesRemark
          });
        }
        let hwArr = [];
        for (const key in allocationReqList) {
          hwArr.push({
            ...allocationReqList[key],
            reservoirAreaCode: allocationReqList[key].warehouseAreaCode,
            goodsShelvesCode: allocationReqList[key].goodsAllocationCode,
            code: allocationReqList[key].warehouseAreaCode,
            extInfo: [
              {
                goodsAllocationLength:
                  allocationReqList[key].goodsAllocationLength,
                goodsAllocationWide: allocationReqList[key].goodsAllocationWide,
                goodsAllocationHigh: allocationReqList[key].goodsAllocationHigh,
                weightLimit: allocationReqList[key].weightLimit,
                volumeUnit: allocationReqList[key].volumeUnit
              }
            ]
          });
        }
        return { kq: kqArr, hj: hjArr, hw: hwArr };
      },
      async getDetail(id) {
        const res = await warehouseDefinition.warehouseDetail(id);
        this.warehouseVO = res.warehouseVO; //仓库基本信息
        const { kq, hj, hw } = this.handleHouse(res);
        // console.log(this.handleHouse(res));
        this.areaForm = {
          warehouseAreasSaveList: kq || [], //库区
          areaGoodsshelvesList: hj || [], //货架
          allocationReqList: hw || [] //货位
        };
        console.log('===', this.areaForm);
        this.formData = res;
        //已保存库区货位 ，删除时判断
        this.savedWarehouse = this.areaForm.warehouseAreasSaveList.length
          ? this.areaForm.warehouseAreasSaveList.map((i) => i.id)
          : [];
        this.savedShelves = this.areaForm.areaGoodsshelvesList.length
          ? this.areaForm.areaGoodsshelvesList.map((i) => i.id)
          : [];
      },
      checkVolume() {
        console.log(this.areaForm);
        let falg = true;
        let warehouseAreasSaveList = this.areaForm.warehouseAreasSaveList.map(
          (item) => {
            return {
              id: item.code,
              volumu:
                item.extInfo[0].areaHigh *
                item.extInfo[0].areaLength *
                item.extInfo[0].areaWidth
            };
          }
        );

        let areaGoodsshelvesList = this.areaForm.areaGoodsshelvesList.map(
          (item) => {
            return {
              id: item.reservoirAreaCode,
              volumu:
                item.extInfo[0].areaHigh *
                item.extInfo[0].areaLength *
                item.extInfo[0].areaWidth
            };
          }
        );
        warehouseAreasSaveList.forEach((item) => {
          let arr = areaGoodsshelvesList.filter((it) => it.id == item.id);
          let num = arr.reduce((val, it) => val + it.volumu, 0);
          if (num > item.volumu) {
            falg = false;
          }
        });
        return falg;
      },
      editInfo(index) {
        let obj = this.areaForm.warehouseAreasSaveList[index];
        if (obj.isEdit) {
          this.$set(
            this.areaForm.warehouseAreasSaveList[index],
            'isEdit',
            false
          );
        } else {
          this.$set(
            this.areaForm.warehouseAreasSaveList[index],
            'isEdit',
            true
          );
        }
      },
      addShelf(row, index) {
        this.$prompt('请输入', '添加货架数', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /[1-9]\d*/,
          inputErrorMessage: '请输入正整数'
        })
          .then(({ value }) => {
            row.subCount = +row.subCount + +value;
            let obj = this.areaForm.warehouseAreasSaveList[index];

            const pre =
              this.areaForm.areaGoodsshelvesList[
                this.areaForm.areaGoodsshelvesList.length - 1
              ];
            let preCode = 0;
            if (pre) {
              preCode = +(pre.code?.substr(1) || 0);
            }
            for (var i = 0; i < value; i++) {
              this.areaForm.areaGoodsshelvesList.push({
                reservoirAreaCode: obj.code,
                warehouseId: this.formData.id,
                code: ``,
                type: 2,
                extInfo: [
                  {
                    line: '',
                    column: '',
                    areaLength: '',
                    areaWidth: '',
                    areaHigh: '',
                    isRegular: 1
                  }
                ],
                subCount: '',
                remark: '',
                isEdit: true
              });
            }
          })
          .catch(() => {});
        // let obj = this.areaForm.warehouseAreasSaveList[index],
        //   list = this.areaForm.areaGoodsshelvesList.filter(
        //     item => item.reservoirAreaCode === obj.code
        //   )
        // if (obj.id) {
        //   if (list.length == obj.num)
        //     return this.$message.error('添加货架数量达到上限')
        //   let num = obj.num - list.length
        //   for (var i = 0; i < num; i++) {
        //     this.areaForm.areaGoodsshelvesList.push({
        //       reservoirAreaCode: obj.code,
        //       warehouseAreaId: obj.id,
        //       warehouseAreaName: obj.name,
        //       code: `C${pushZero(
        //         this.areaForm.areaGoodsshelvesList.length + 1
        //       )}`,
        //
        //       goodsshelvesColumn: '',
        //
        //
        //       // goodsshelvesBarcode: '',
        //       remark: '',
        //       warehouseName: this.formData.name,
        //       isEdit: true
        //     })
        //   }
        // } else {
        //   this.saveArea(index)
        // }
      },
      onBlur(item, name, name1) {
        // name当前货位的长宽高,name1货架的长宽高

        if (
          item.extInfo[0].goodsAllocationHigh &&
          item.extInfo[0].goodsAllocationLength &&
          item.extInfo[0].goodsAllocationWide
        ) {
          item.extInfo[0].volumeUnit =
            item.extInfo[0].goodsAllocationHigh *
            item.extInfo[0].goodsAllocationLength *
            item.extInfo[0].goodsAllocationWide;
        }
      },
      saveGoods(index, row) {
        // 需要校验的字段 areaGoodsshelvesList
        let list = Object.keys(this.areaCoodsRules),
          obj = this.areaForm.areaGoodsshelvesList[index],
          flag = true;

        list.forEach((item) => {
          this.$refs.areaCoodsForm.validateField(
            'areaGoodsshelvesList.' + index + '.' + item,
            (valid) => {
              if (valid) {
                flag = false;
              }
            }
          );
        });

        // 库区体积限制
        const parent = this.areaForm.warehouseAreasSaveList.find(
          (t) => t.code === row.reservoirAreaCode
        );

        if (
          this.areaForm.areaGoodsshelvesList.filter(
            (item) =>
              item.code === row.code &&
              row.reservoirAreaCode === item.reservoirAreaCode
          ).length > 1
        ) {
          return this.$message.error('货架编号不能重复！');
        }
        const savedSum = this.areaForm.areaGoodsshelvesList
          .filter((t) => t.reservoirAreaCode === row.reservoirAreaCode)
          .reduce((sum, item) => {
            if (!item.isEdit) {
              sum +=
                item.extInfo[0].areaLength *
                item.extInfo[0].areaWidth *
                item.extInfo[0].areaHigh;
            }
            return sum;
          }, 0);
        if (parent) {
          const max =
            parent.extInfo[0].areaLength *
            parent.extInfo[0].areaWidth *
            parent.extInfo[0].areaHigh;

          if (
            max - savedSum <
            row.extInfo[0].areaLength *
              row.extInfo[0].areaWidth *
              row.extInfo[0].areaHigh
          ) {
            return this.$message.error('货架总体积不能大于库区体积！');
          }
        }

        if (flag) {
          this.$set(obj, 'isEdit', false);
          this.shelfObj = obj; //储存货架对象
          let num = obj.extInfo[0].line * obj.extInfo[0].column;

          this.areaIndex = index;
          this.generateAllocation(num, obj);
        }
      },
      generateAllocation(num, obj) {
        console.log(obj);
        const pre =
          this.areaForm.allocationReqList[
            this.areaForm.allocationReqList.length - 1
          ];

        for (var i = 0; i < num; i++) {
          this.areaForm.allocationReqList.push({
            warehouseAreaCode: obj.reservoirAreaCode,
            warehouseAreaGoodsCode: obj.code,
            goodsAllocationCode: obj.code + '-' + (i + 1),
            // allocationBarcode: '',
            code: obj.code + '-' + (i + 1),

            extInfo: [
              {
                goodsAllocationWide: Number(obj.extInfo[0].areaWidth),
                goodsAllocationHigh: Number(
                  obj.extInfo[0].areaHigh / Number(obj.extInfo[0].line)
                ).toFixed(0),
                goodsAllocationLength: Number(
                  obj.extInfo[0].areaLength / Number(obj.extInfo[0].column)
                ).toFixed(0),
                weightLimit: '',
                volumeUnit:
                  Number(
                    obj.extInfo[0].areaLength / Number(obj.extInfo[0].column)
                  ).toFixed(0) *
                  Number(
                    obj.extInfo[0].areaHigh / Number(obj.extInfo[0].line)
                  ).toFixed(0) *
                  Number(obj.extInfo[0].areaWidth)
              }
            ],
            goodsShelvesCode: obj.code,
            reservoirAreaCode: obj.reservoirAreaCode,
            warehouseId: this.formData.id, //?

            type: 3,
            isEdit: true
          });
        }
      },
      saveArea(index) {
        this.hjForm = { code: '', type: 1 };
        if (
          this.areaForm.warehouseAreasSaveList.filter(
            (item) =>
              item.code === this.areaForm.warehouseAreasSaveList[index].code
          ).length > 1
        ) {
          return this.$message.error('库区编号不能重复！');
        }
        this.hjCodeIndex = index;
        this.hjCodeFalg = true;
      },
      handleMine() {
        const index = this.hjCodeIndex;
        const ruleName = this.hjForm.code;
        // console.log('名称', ruleName + index + 1);
        this.$refs.areaFormName.validate((val) => {
          if (val) {
            this.$set(
              this.areaForm.warehouseAreasSaveList[index],
              'isEdit',
              false
            );

            let obj = this.areaForm.warehouseAreasSaveList[index];
            let num = this.areaForm.warehouseAreasSaveList[index].subCount;

            const pre =
              this.areaForm.areaGoodsshelvesList[
                this.areaForm.areaGoodsshelvesList.length - 1
              ];
            let preCode = 0;
            if (pre) {
              preCode = +(pre.code?.substr(1) || 0);
            }
            let codeEng = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
            let currentLetterIndex = 0;

            if (ruleName.length > 0) {
              // 计算初始索引
              let multiplier = Math.pow(codeEng.length, ruleName.length - 1);
              for (let i = 0; i < ruleName.length; i++) {
                currentLetterIndex +=
                  (codeEng.indexOf(ruleName[i]) + 1) * multiplier;
                multiplier /= codeEng.length;
              }
            }

            for (let i = 0; i < num; i++) {
              let currentLetter = '';

              // 获取当前字母
              let index = currentLetterIndex;
              let dividend = codeEng.length;
              let remainder;
              let quotient;
              let code = '';

              while (index > 0) {
                remainder = index % dividend;
                quotient = Math.floor(index / dividend);

                if (remainder === 0) {
                  remainder = codeEng.length;
                  quotient--;
                }

                code = codeEng[remainder - 1] + code;
                index = quotient;
              }

              let obj1111 = {
                reservoirAreaCode: obj.code,
                warehouseId: this.formData.id,
                code: this.hjForm.type === 1 ? code : ruleName + (i + 1),
                type: 2,
                extInfo: [
                  {
                    line: '',
                    column: '',
                    areaLength: '',
                    areaWidth: '',
                    areaHigh: '',
                    isRegular: 1
                  }
                ],
                subCount: '',
                remark: '',
                isEdit: true
              };

              this.areaForm.areaGoodsshelvesList.push(obj1111);

              currentLetterIndex++; // 自增索引
            }

            this.hjCodeFalg = false;
            console.log('sasa===qqqq', this.areaForm.areaGoodsshelvesList);
          }
        });
      },
      async removeGoods(idx, { id, code, reservoirAreaCode }) {
        if (
          this.areaForm.areaGoodsshelvesList.filter(
            (item) => item.reservoirAreaCode === reservoirAreaCode
          ).length === 1
        ) {
          return this.$message.error('至少保留一个货架！');
        }
        if (this.savedShelves.includes(id)) {
          let list = this.areaForm.allocationReqList
            .filter((item) => item.goodsShelvesCode === code)
            .map((i) => i.id);

          const res = await existGoods(list);

          if (res?.success && res.data) {
            return this.$message.error('此货架下货位有关联货物，无法删除！');
          }
        }

        this.areaForm.allocationReqList =
          this.areaForm.allocationReqList.filter(
            (item) =>
              item.goodsShelvesCode !== code ||
              reservoirAreaCode !== item.reservoirAreaCode
          );
        let areasIndex = this.areaForm.warehouseAreasSaveList.findIndex(
          (item) =>
            item.code ===
            this.areaForm.areaGoodsshelvesList[idx].reservoirAreaCode
        );
        this.areaForm.areaGoodsshelvesList.splice(idx, 1);
        if (
          this.areaForm.warehouseAreasSaveList[areasIndex].subCount - 1 <=
          0
        ) {
          this.areaForm.warehouseAreasSaveList.splice(areasIndex, 1);
        } else {
          this.$set(
            this.areaForm.warehouseAreasSaveList[areasIndex],
            'num',
            this.areaForm.warehouseAreasSaveList[areasIndex].subCount - 1
          );
        }
      },
      removeGoods1(idx, { id, code, reservoirAreaCode }) {
        //  warehouseAreasSaveList: res.reservoirAreaList || [], //库区
        // areaGoodsshelvesList: res.goodsShelvesList || [], //货架
        // allocationReqList: res.goodsAllocationList || [] //货位
        if (
          this.areaForm.areaGoodsshelvesList.filter(
            (item) => item.reservoirAreaCode === reservoirAreaCode
          ).length === 1
        ) {
          return this.$message.error('至少保留一个货架！');
        }

        this.$confirm(`是否删除这个货架？`).then(async () => {
          if (id) {
            const res = await warehouseDefinition.isDelete(id);
            if (res == 1) {
              this.areaForm.areaGoodsshelvesList =
                this.areaForm.areaGoodsshelvesList.filter(
                  (item) => item.code !== code
                );
              this.areaForm.allocationReqList =
                this.areaForm.allocationReqList.filter(
                  (item) => item.goodsShelvesCode !== code
                );
              this.$message.warning('已在本地删除，保存之后生效！');
            } else {
              this.$message.warning('此数据可能有关联数据，暂时无法删除！');
            }
          } else {
            this.areaForm.areaGoodsshelvesList =
              this.areaForm.areaGoodsshelvesList.filter(
                (item) => item.code !== code
              );
            this.areaForm.allocationReqList =
              this.areaForm.allocationReqList.filter(
                (item) => item.goodsShelvesCode !== code
              );

            this.$message.success('删除成功！');
          }
        });
      },
      remove1(index, { id, code }) {
        this.$confirm(`是否删除这个库区`)
          .then(async () => {
            if (id) {
              const res = await warehouseDefinition.isDelete(id);
              if (res == 1) {
                this.areaForm.warehouseAreasSaveList.splice(index, 1);
                this.areaForm.areaGoodsshelvesList =
                  this.areaForm.areaGoodsshelvesList.filter(
                    (item) => item.reservoirAreaCode !== code
                  );
                this.areaForm.allocationReqList =
                  this.areaForm.allocationReqList.filter(
                    (item) => item.reservoirAreaCode !== code
                  );
                this.$message.warning('已在本地删除，保存之后生效！');
              } else {
                this.$message.warning('此数据可能有关联数据，暂时无法删除！');
              }
            } else {
              this.areaForm.warehouseAreasSaveList.splice(index, 1);
              this.areaForm.areaGoodsshelvesList =
                this.areaForm.areaGoodsshelvesList.filter(
                  (item) => item.reservoirAreaCode !== code
                );
              this.areaForm.allocationReqList =
                this.areaForm.allocationReqList.filter(
                  (item) => item.reservoirAreaCode !== code
                );
              this.$message.success('删除成功！');
            }
          })
          .catch((err) => {});
      },
      async remove(index, { id, code }) {
        // 判断关联货物
        console.log(this.savedWarehouse, id, this.savedWarehouse.includes(id));
        if (this.savedWarehouse.includes(id)) {
          let list = this.areaForm.areaGoodsshelvesList
            .filter((item) => item.reservoirAreaCode === code)
            .map((i) =>
              this.areaForm.allocationReqList.filter(
                (item) => item.goodsShelvesCode === i.code
              )
            )
            .flat()
            .map((i) => i.id);

          const res = await existGoods(list);

          if (res?.success && res.data) {
            return this.$message.error('此库区下货位有关联货物，无法删除！');
          }
        }
        // 货架code
        let list = [];
        this.areaForm.areaGoodsshelvesList.forEach((item) => {
          if (item.reservoirAreaCode === code) {
            list.push(item.code);
          }
        });
        this.areaForm.areaGoodsshelvesList =
          this.areaForm.areaGoodsshelvesList.filter(
            (item) => item.reservoirAreaCode !== code
          );
        this.areaForm.allocationReqList =
          this.areaForm.allocationReqList.filter(
            (item) =>
              !list.includes(item.goodsShelvesCode) ||
              code !== item.reservoirAreaCode
          );
        this.areaForm.warehouseAreasSaveList.splice(index, 1);
      },
      addArea() {
        const pre =
          this.areaForm.warehouseAreasSaveList[
            this.areaForm.warehouseAreasSaveList.length - 1
          ];
        let preCode = 0;
        if (pre) {
          preCode = +(pre.code?.substr(1) || 0);
        }

        this.areaForm.warehouseAreasSaveList.push({
          code: ``,
          name: '',
          type: 1,
          extInfo: [
            {
              attribute: '',
              address: '',
              areaLength: '',
              areaWidth: '',
              areaHigh: '',
              areaType: ''
            }
          ],
          subCount: '',
          // areaBarcode: '',
          remark: '',
          warehouseId: this.formData.id,
          isEdit: true
        });
      },
      async submit() {
        delete this.formData.goodsAllocationList;
        delete this.formData.goodsShelvesList;
        delete this.formData.reservoirAreaList;

        if (this.areaForm.warehouseAreasSaveList.length === 0) {
          return this.$message.error('请添加库区');
        }
        // ===dakai
        if (
          this.areaForm.warehouseAreasSaveList.length > 0 &&
          this.areaForm.allocationReqList.length === 0
        ) {
          return this.$message.error('请添加货位');
        }
        if (
          this.areaForm.warehouseAreasSaveList.length > 0 &&
          this.areaForm.areaGoodsshelvesList.length === 0
        ) {
          return this.$message.error('请添加货架');
        }
        if (!this.checkVolume()) {
          return this.$message.error('货架总体积不能大于库区体积！');
        }

        // let obj = {};
        // for (const item of this.areaForm.allocationReqList) {
        //   const area = this.areaForm.areaGoodsshelvesList.find((itm) => {
        //     return itm.reservoirAreaCode === item.code;
        //   });

        //   const id = `${
        //     area && area.reservoirAreaCode + '-' + item.goodsShelvesCode
        //   }-${item.code}`;

        //   if (obj[id]) {
        //    
        //   } else {
        //     obj[id] = 1;
        //   }
        // }
        
        let codeS=this.areaForm.allocationReqList?.map(item=>{
          return item.reservoirAreaCode+'_'+item.goodsShelvesCode+'_'+item.goodsAllocationCode
        })
        if(codeS){
          codeS=Array.from(new Set(codeS)) 
        }
        if(codeS?.length!=this.areaForm.allocationReqList?.length){
          return this.$message.error('货位编号不能重复！');
        }
   

        this.$refs.areaFormName.validate(async (valid) => {
          if (valid) {
            this.$refs.areaCoodsForm.validate(async (valid) => {
              if (valid) {
                this.$refs.allocationForm.validate(async (valid) => {
                  if (valid) {
                    // let params = {
                    //   ...this.formData,
                    //   goodsAllocationList: this.areaForm.allocationReqList,
                    //   goodsShelvesList: this.areaForm.areaGoodsshelvesList,
                    //   reservoirAreaList: this.areaForm.warehouseAreasSaveList
                    // };
                    // let arr = [
                    //   ...this.areaForm.allocationReqList, //货位
                    //   ...this.areaForm.areaGoodsshelvesList, //货架
                    //   ...this.areaForm.warehouseAreasSaveList //库区
                    // ];
                    // arr.forEach((item) => {
                    //   if ('isEdit' in item) {
                    //     delete item.isEdit;
                    //   }
                    // });

                    // const arrMap = arr.map((item) => {
                    //   return {
                    //     warehouseId: item.warehouseId,
                    //     code: item.code,
                    //     extInfo: item.extInfo,
                    //     goodsShelvesCode: item.goodsShelvesCode,
                    //     name: item.name,
                    //     remark: item.remark,
                    //     reservoirAreaCode: item.reservoirAreaCode,
                    //     subCount: item.subCount,
                    //     type: item.type
                    //   };
                    // });
                    const newObj = {
                      allocationList: this.areaForm.allocationReqList, //货位
                      areaGoodsshelvesList: this.areaForm.areaGoodsshelvesList, //货架
                      areasList: this.areaForm.warehouseAreasSaveList //库区
                    };
                    // ...this.areaForm.allocationReqList, //货位
                    //   ...this.areaForm.areaGoodsshelvesList, //货架
                    //   ...this.areaForm.warehouseAreasSaveList //库区
                    // console.log('没有处理过的===', newObj);
                    // console.log(
                    //   '处理过的数据===',
                    //   this.handleNewSource(newObj)
                    // );
                    this.loading = true;
                    console.log(this.handleNewSource(newObj));
                    try {
                      let res = await warehouseDefinition.warehouseareaSave(
                        this.handleNewSource(newObj)
                      );

                      if (res.data.code == 0) {
                        this.$message.success('保存成功');
                        this.getDetail(this.$route.query.id);
                        this.$router.push(
                          {
                            path: '/warehouseManagement/warehouseDefinition'
                          },
                          () => {}
                        );
                      }
                    } catch (error) {
                      console.log(error);
                    }
                    this.loading = false;
                  }
                });
              }
            });
          }
        });
      },
      // 货位组装货架编号
      getgoodsShelvesCode(row) {
        let pid = row.parentId;
        const { goodsShelvesCode, reservoirAreaCode } = row;
        const obj = this.areaForm.areaGoodsshelvesList.find((item) => {
          item.id === pid;
        });
        console.log('1', obj && obj.reservoirAreaCode + '-' + goodsShelvesCode);
        console.log('2', this.areaForm.areaGoodsshelvesList);
        return obj && obj.reservoirAreaCode + '-' + goodsShelvesCode;
      },
      //重新处理数据，之前代码不敢动
      handleNewSource(arr) {
        //areasList库区
        //areaGoodsshelvesList货架
        //allocationList货位
        const { areasList, areaGoodsshelvesList, allocationList } = arr;
        let areasListArr = this.objExit(areasList).map((item) => {
          return {
            code: item.code,
            name: item.name,
            type: item.areaType,
            attribute: item.attribute,
            address: item.address,
            areaLength: item.areaLength,
            areaWide: item.areaWidth,
            areaHigh: item.areaHigh,
            num: item.subCount,
            areaRemark: item.remark
          };
        });
        let areaGoodsshelvesListArr = this.objExit(areaGoodsshelvesList).map(
          (item) => {
            return {
              warehouseAreaCode: item.reservoirAreaCode,
              goodsshelvesCode: item.code,
              goodsshelvesLine: item.line,
              goodsshelvesColumn: item.column,
              goodsshelvesLength: item.areaLength,
              goodsshelvesWide: item.areaWidth,
              goodsshelvesHigh: item.areaHigh,
              inUseAllocationNumber: item.subCount,
              isRegular: item.isRegular,
              goodsshelvesRemark: item.remark,
              warehouseAreaGoodsCode: item.code
            };
          }
        );
        let allocationListArr = this.objExit(allocationList).map((item) => {
          return {
            warehouseAreaCode: item.reservoirAreaCode,
            goodsAllocationCode: item.goodsAllocationCode,
            goodsAllocationLength: item.goodsAllocationLength,
            goodsAllocationWide: item.goodsAllocationWide,
            goodsAllocationHigh: item.goodsAllocationHigh,
            weightLimit: item.goodsAllocationHigh,
            inUseAllocationNumber: item.weightLimit,
            volumeUnit: item.volumeUnit,
            warehouseAreaGoodsCode: item.warehouseAreaGoodsCode
          };
        });
        let params = {
          areasList: areasListArr,
          goodsshelvesList: areaGoodsshelvesListArr,
          allocationList: allocationListArr,
          warehousePO: this.warehouseVO
        };
        return params;
      },
      objExit(arr) {
        let newArr = [];
        for (const key in arr) {
          newArr.push({ ...arr[key].extInfo[0], ...arr[key] });
        }
        return newArr;
      }
    }
  };
</script>

<style lang="scss" scoped>
  .p20 {
    padding: 20px;
  }
  .mt20 {
    margin-top: 20px;
  }
  .mt10 {
    margin-top: 10px;
  }
  ::v-deep .el-select {
    width: 100%;
  }
  .el-form-item {
    margin-bottom: 22px;
  }
  .areaForm {
    .el-form-item {
      margin-bottom: 0;
    }
  }
  .warehouseAdd {
    .el-row {
      display: block;
    }
    header {
      display: flex;
      justify-content: space-between;
      .title {
        font-size: 20px;
        color: #333;
        font-weight: bold;
      }
    }
  }
  .reservoirArea {
    display: flex;
    justify-content: space-between;
    span {
      font-size: 14px;
    }
  }
  .center {
    text-align: center;
  }
  .el-select {
    display: block;
  }
  ::v-deep input::-webkit-inner-spin-button {
    -webkit-appearance: none;
  }
</style>
