<template>
  <!-- 入库报工 报工列表 -->

  <div>
    <div class="top_fixed">
      <div
        style="display: flex; align-items: center; margin-right: 10px"
        v-if="List.length > 1"
      >
        <div class="rx-bc">
          <div class="name">批量报工时间：</div>
        </div>
        <el-date-picker
          v-model="executorTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择日期"
          @change="handleCreate"
        >
        </el-date-picker>
      </div>
      <el-button type="primary" size="mini" @click="save">一键报工</el-button>
    </div>

    <div class="warehousing_box">
      <div v-for="(item, index) in List" :key="index" class="card_box">
        <div class="title_box rx-bc">
          <div class="name">工单信息</div>
        </div>

        <workOrderBom :item="item" v-if="item"></workOrderBom>

        <!-- 报工时间 -->
        <div>
          <div class="title_box rx-bc">
            <div class="name">报工时间</div>
          </div>
          报工时间：
          <el-date-picker
            v-model="item.workReportInfo.executorTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择日期"
            style="margin-right: 25px; width: 190px"
          >
          </el-date-picker>
          执行人：
          <el-select
            v-model="teamId"
            placeholder="请选择班组"
            filterable
            style="width: 120px"
            @change="checkTeamList(teamId)"
          >
            <el-option
              v-for="item in teamList"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="executorIdList"
            placeholder="请选择执行人"
            filterable
            multiple
            @change="changeId"
          >
            <div class="checkboxWrapper">
              <el-checkbox v-model="checked" @change="checkChange">
                全选
              </el-checkbox>
            </div>
            <el-option
              v-for="item in teamUserList"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
          </el-select>
        </div>

        <div>
          <jobDdBom
            :item="item"
            ref="jobRef"
            :notFormed="item.notFormedList"
            :warehouseList="warehouseList"
          ></jobDdBom>
        </div>

        <div v-if="clientEnvironmentId == 3">
          <div class="item">
            <div>
              <div class="text">仓库</div>
              <div class="select-type">
                <el-select
                  v-model="warehouseId"
                  filterable
                  clearable
                  placeholder="请选择仓库"
                  size="mini"
                  class="content_num"
                >
                  <el-option
                    v-for="item in warehouseList"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </div>
            </div>

            <!-- <div>
              <div class="text">入库规格</div>
              <div class="select-type">
                <el-select
                  v-model="inWarehouseSpecType"
                  filterable
                  clearable
                  placeholder="请选择入库规格"
                  size="mini"
                  class="content_num select-warehousing"
                  disabled
                >
                  <el-option
                    v-for="item in WarehouseSpecTypeList"
                    :key="item.value"
                    :label="item.text"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </div>
            </div> -->
          </div>
          <!-- <div style="margin-top: 6px">
            <el-select
              v-model="item.warehouseId"
              filterable
              clearable
              placeholder="请选择仓库"
              size="mini"
              class="content_num"
            >
              <el-option
                v-for="item in warehouseList"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              ></el-option>
            </el-select>
          </div> -->

          <!-- <div v-for="(it, idx) in item.toWarehouseList" :key="idx"> -->
          <batchSemiProductJobBom
            :list="item.semiProductList"
            :item="item"
            :singleReport="item.singleReport"
            :storeType="storeType"
            :equipmentList="item.equipmentList"
            :isChoose="isChoose"
            :isEngrave="isEngrave"
            :isDisposal="isDisposal"
          >
          </batchSemiProductJobBom>
          <!-- </div> -->
        </div>

        <!-- <div v-else-if="clientEnvironmentId == 3 && item.singleReport == 1">
          <div class="item">
            <div>
              <div class="text">仓库</div>
              <div class="select-type">
                <el-select
                  v-model="warehouseId"
                  filterable
                  clearable
                  placeholder="请选择仓库"
                  size="mini"
                  class="content_num"
                >
                  <el-option
                    v-for="item in warehouseList"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </div>
            </div>

            <div>
              <div class="text">入库规格</div>
              <div class="select-type">
                <el-select
                  v-model="inWarehouseSpecType"
                  filterable
                  clearable
                  placeholder="请选择入库规格"
                  size="mini"
                  class="content_num select-warehousing"
                  disabled
                >
                  <el-option
                    v-for="item in WarehouseSpecTypeList"
                    :key="item.value"
                    :label="item.text"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </div>
            </div>
          </div>

          <batchSemiProductJobBom
            :list="item.semiProductList"
            :item="item"
            :singleReport="item.singleReport"
            :storeType="storeType"
            :equipmentList="item.equipmentList"
            :isChoose="isChoose"
            :isEngrave="isEngrave"
            :isDisposal="isDisposal"
          >
          </batchSemiProductJobBom>
        </div> -->

        <!-- 单独报工 -->
        <div
          v-else-if="
            item.currentTaskDiagram.type == 5 &&
            item.singleReport == 1 &&
            clientEnvironmentId != 3 &&
            item.semiProductList
          "
        >
          <!-- <div v-if="item.toWarehouseList && item.toWarehouseList.length > 0"> -->
          <div class="item">
            <div>
              <div class="text">仓库</div>
              <div class="select-type">
                <el-select
                  v-model="warehouseId"
                  filterable
                  clearable
                  placeholder="请选择仓库"
                  size="mini"
                  class="content_num"
                >
                  <el-option
                    v-for="item in warehouseList"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </div>
            </div>

            <!-- <div>
              <div class="text">入库规格</div>
              <div class="select-type">
                <el-select
                  v-model="inWarehouseSpecType"
                  filterable
                  clearable
                  placeholder="请选择入库规格"
                  size="mini"
                  class="content_num select-warehousing"
                  disabled
                >
                  <el-option
                    v-for="item in WarehouseSpecTypeList"
                    :key="item.value"
                    :label="item.text"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </div>
            </div> -->
          </div>

          <!-- <div v-for="(it, idx) in item.toWarehouseList" :key="idx"> -->
          <!-- <packingTgBom
                :list="it.extInfo.pickOutInList"
                :singleReport="item.singleReport"
                :item="item"
                :equipmentList="item.equipmentList"
                :isWarehousing="true"
              ></packingTgBom> -->
          <!-- </div> -->
          <batchSemiProductJobBom
            :list="item.semiProductList"
            :item="item"
            :singleReport="item.singleReport"
            :storeType="storeType"
            :equipmentList="item.equipmentList"
            :isChoose="isChoose"
            :isEngrave="isEngrave"
            :isDisposal="isDisposal"
          >
          </batchSemiProductJobBom>
          <!-- </div> -->
        </div>

        <!-- {{ item.currentTaskDiagram.type }} {{ item.singleReport }}
 {{ clientEnvironmentId != 2 && item && item.currentTaskDiagram.type == 5 && clientEnvironmentId != 3 && item.singleReport == 1 }} -->
        <!-- <div
          v-if="
            clientEnvironmentId != 2 &&
            item &&
            item.currentTaskDiagram.type == 5 &&
            clientEnvironmentId != 3 &&
            item.singleReport !== 1
          "
        >
          <div style="margin-top: 6px">
            <el-select
              v-model="item.warehouseId"
              filterable
              clearable
              placeholder="请选择仓库"
              size="mini"
              class="content_num"
            >
              <el-option
                v-for="item in warehouseList"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              ></el-option>
            </el-select>
          </div> -->

        <div
          v-if="
            item.product &&
            item.currentTaskDiagram.type == 5 &&
            clientEnvironmentId != 3 &&
            item.singleReport !== 1
          "
        >
          <div class="item">
            <div>
              <div class="text">仓库</div>
              <div class="select-type">
                <el-select
                  v-model="warehouseId"
                  filterable
                  clearable
                  placeholder="请选择仓库"
                  size="mini"
                  class="content_num"
                >
                  <el-option
                    v-for="item in warehouseList"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </div>
            </div>

            <!-- <div>
              <div class="text">入库规格</div>
              <div class="select-type">
                <el-select
                  v-model="inWarehouseSpecType"
                  filterable
                  clearable
                  placeholder="请选择入库规格"
                  size="mini"
                  class="content_num select-warehousing"
                  disabled
                >
                  <el-option
                    v-for="item in WarehouseSpecTypeList"
                    :key="item.value"
                    :label="item.text"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </div>
            </div> -->
          </div>
          <!-- <div style="margin-top: 6px">
            <el-select
              v-model="warehouseId"
              filterable
              clearable
              placeholder="请选择仓库"
              size="mini"
              class="content_num"
            >
              <el-option
                v-for="item in warehouseList"
                :key="item.id"
                :value="item.id"
                :label="item.name"
              ></el-option>
            </el-select>
          </div> -->

          <!-- 批量报工 -->
          <!-- <div
            class="list_box"
            v-for="(d, index) in item.toWarehouseList"
            :key="index"
          > -->
          <!-- <div class="time" style="margin-bottom: 10rpx"
              >打包时间： {{ d.createTime }}</div
            > -->
          <!-- <packagingGroupingTwx
              ref="packagingGroupingRef"
              :objData="d.extInfo"
              :workOrderId="item.workOrderId"
              :taskId="item.currentTaskDiagram.taskId"
            >
            </packagingGroupingTwx> -->

          <!-- :list="objData.product" :item="objData" :isDetails="true"
            :singleReport="objData.singleReport"
            :equipmentList="objData.equipmentList" -->

          <batchSemiProductJobBom
            :list="item.product"
            :item="item"
            :singleReport="item.singleReport"
            :storeType="storeType"
            :equipmentList="item.equipmentList"
            :isChoose="isChoose"
            :isEngrave="isEngrave"
            :isDisposal="isDisposal"
          >
          </batchSemiProductJobBom>
          <!-- </div> -->
        </div>

        <!-- <div v-if="clientEnvironmentId == 2">
          <div class="item">
            <div>
              <div class="text">仓库</div>
              <div class="select-type">
                <el-select
                  v-model="warehouseId"
                  filterable
                  clearable
                  placeholder="请选择仓库"
                  size="mini"
                  class="content_num"
                >
                  <el-option
                    v-for="item in warehouseList"
                    :key="item.id"
                    :value="item.id"
                    :label="item.name"
                  ></el-option>
                </el-select>
              </div>
            </div>

            <div>
              <div class="text">入库规格</div>
              <div class="select-type">
                <el-select
                  v-model="inWarehouseSpecType"
                  filterable
                  clearable
                  placeholder="请选择入库规格"
                  size="mini"
                  class="content_num select-warehousing"
                  disabled
                >
                  <el-option
                    v-for="item in WarehouseSpecTypeList"
                    :key="item.value"
                    :label="item.text"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </div>
            </div>
          </div>
        </div> -->

        <!-- item.currentTaskDiagram.type == 4 ? item.pickOutInList : item.semiProductList -->

        <!-- <div v-else>
          <el-empty :image-size="30" description="暂无数据"></el-empty>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script>
  import workOrderBom from '../feeding/components/workOrderBom.vue';
  import packingTgBom from '../jobBooking/components/packingTgBom.vue';
  import semiProductJobBomQT from '../jobBooking/components/semiProductJobBomQT.vue';
  import packagingGroupingTwx from '../jobBooking/components/packagingGroupingTwx.vue';
  import batchSemiProductJobBom from '../jobBooking/components/batchSemiProductJobBom.vue';
  import { getWarehouseList } from '@/api/produce/index.js';
  import { listByIdsReport } from '@/api/produce/job';
  import {
    listPcToWarehouseTG,
    listPCToWarehouse
  } from '@/api/produce/workOrder';

  import { jobSave } from '@/api/produce/workOrder';
  // import jobDdBom from './components/jobDdBom.vue';
  import jobDdBom from './components/newJobDdBom.vue';
  import { parameterGetByCode } from '@/api/system/dictionary-data';
  import { getTeam } from '@/api/produce/job.js';

  export default {
    components: {
      workOrderBom,
      semiProductJobBomQT,
      packagingGroupingTwx,
      packingTgBom,
      jobDdBom,
      batchSemiProductJobBom
    },
    props: {
      workListIds: {
        type: Array,
        default() {
          return [];
        }
      }
    },
    data() {
      return {
        isLoad: false,
        List: [],

        idsList: [],
        warehouseList: [],
        inWarehouseSpecType: '2',
        WarehouseSpecTypeList: [
          {
            text: '按计量入库',
            value: '1'
          },
          {
            text: '最小包装入库',
            value: '2'
          },
          {
            text: '内包装入库',
            value: '3'
          },
          {
            text: '外包装入库',
            value: '4'
          }
        ],
        storeType: 'store',
        warehouseId: null,
        inWarehouseType: null,
        isChoose: false,
        isEngrave: false,
        isDisposal: false,
        loading: null,
        executorTime: '',
        teamList: [],
        teamAllList: [],
        teamUserList: [],
        executorIdList: [],
        teamId: '',
        checked: false
      };
    },

    computed: {
      taskObj() {
        return this.$store.state.user.taskObj;
      },

      clientEnvironmentId() {
        return this.$store.state.user.info.clientEnvironmentId;
      }
    },

    watch: {
      workListIds: {
        handler(val) {
          this.getList(val);
        },
        deep: true,
        immediate: true
      }
    },

    created() {
      this.getWarehouseListFn();
      this.getChooseEngrave();
    },

    mounted() {
      if (localStorage.getItem('singleUserInfo') == '1') {
        const data = JSON.parse(localStorage.getItem('chooseUserInfo'));
        this.getTeamList(data.teamId);
      } else {
        this.getTeamList(this.$store.state.user.info.teamId);
      }
      // this.getTeamList(this.$store.state.user.info.teamId);
    },

    methods: {
      getList(ids) {
        this.idsList = ids || [];
        let param = {
          ids: ids,
          taskId: this.taskObj.id,
          type: 0
        };
        this.isLoad = false;

        console.log(param, 'idsidsidsids');

        listByIdsReport(param)
          .then((res) => {
            if (res[0].workOrderType == 1) {
              this.inWarehouseType = 1;
            } else if (res[0].workOrderType == 2) {
              this.inWarehouseType = 8; //  "1入库类型1生产入库2半成品入库"
            }
            this.List = res.map((obj) => {
              obj.workReportInfo = {
                formingNum: null,
                formingWeight: null,
                formedNum: null,
                formedWeight: null,
                taskId: '',
                executorTime: null
              };

              obj.notFormedList = [
                {
                  notFormedNum: null,
                  notFormedWeight: null,
                  weightUnit: res.weightUnit,
                  unit: res.unit,
                  warehouseId: null // 处置 仓库id
                }
              ];

              if (obj.semiProductList.length != 0) {
                // 预制体报工
                obj.workReportInfo.formedNum = obj.semiProductList.length;
                let numCot = 0;
                let notFormedNum = 0;
                if (obj.semiProductList.length > 0) {
                  obj.semiProductList.map((fitem) => {
                    if (
                      !fitem.extInfo.isQualified ||
                      fitem.extInfo.isQualified == 1
                    ) {
                      numCot = numCot + fitem.feedQuantity || 1;
                    } else {
                      notFormedNum = notFormedNum + fitem.feedQuantity;
                    }
                  });
                  obj.workReportInfo.formedNum = numCot;
                  obj.workReportInfo.notFormedNum = notFormedNum;
                }
              } else if (obj.product.length != 0) {
                const formedNum = obj.product.reduce((acc, pro) => {
                  return pro.feedQuantity &&
                    (!pro.extInfo.isQualified || pro.extInfo.isQualified == 1)
                    ? acc + Number(pro.feedQuantity)
                    : acc;
                }, 0);

                const notFormedNum = obj.product.reduce((acc, pro) => {
                  return pro.feedQuantity && pro.extInfo.isQualified == 2
                    ? acc + Number(pro.feedQuantity)
                    : acc;
                }, 0);

                obj.workReportInfo.formedNum = formedNum;

                obj.workReportInfo.notFormedNum = notFormedNum;
              }

              return {
                ...obj
              };
            });
            this.List.forEach((item) => {
              if (item.semiProductList && item.semiProductList.length != 0) {
                item.semiProductList.forEach((it) => {
                  it.extInfo.taskId = '';
                  it.extInfo.taskName = '';
                });
              } else if (item.product && item.product.length != 0) {
                item.product.forEach((it) => {
                  it.extInfo.taskId = '';
                  it.extInfo.taskName = '';
                });
              }
            });

            console.log(this.List, 'listList');
          })
          .finally(() => {
            this.isLoad = true;

            if (this.clientEnvironmentId == 3) {
              this.getTgWarehouse();
            } else {
              this.getQtWarehouse();
            }
          });
      },

      async getChooseEngrave() {
        await parameterGetByCode({
          code: 'choose_engrave'
        }).then((res) => {
          this.isChoose = res.value == '1' ? true : false;
        });

        await parameterGetByCode({
          code: 'batch_update_engrave'
        }).then((res) => {
          this.isEngrave = res.value == '1' ? true : false;
        });

        await parameterGetByCode({
          code: 'batch_disposal'
        }).then((res) => {
          this.isDisposal = res.value == '1' ? true : false;
        });

        await parameterGetByCode({
          code: 'default_executor'
        }).then((res) => {
          this.isDefaultExecutor = res.value == '1' ? true : false;

          if (this.isDefaultExecutor) {
            this.setDefaultIdList();
          }
        });
      },

      setDefaultIdList() {
        if (this.teamList.length != 0) {
          this.teamId = this.teamList[0].id;
          const index = this.teamList.findIndex(
            (item) => item.id == this.teamId
          );
          this.teamUserList = this.teamAllList[index];

          if (this.teamUserList) {
            const res = this.teamUserList.find(
              (it) => it.id == this.$store.state.user.info.userId
            );

            this.executorIdList.push(res.id);
          }
          // const res = this.teamUserList.find(
          //   (it) => it.id == this.$store.state.user.info.userId
          // );

          // this.executorIdList.push(res.id);
        }
      },

      async getTeamList(id) {
        const ids = id.split(',');
        this.teamList = [];
        this.teamUserList = [];
        const list = ids.map((item) => getTeam(item));

        const dataList = await Promise.all(list);

        dataList.forEach((item) => {
          this.teamList.push({
            name: item.name,
            id: item.id
          });

          this.teamAllList.push(item.userVOList);
        });
      },

      changeId() {
        if (this.executorIdList.length == this.teamUserList.length) {
          this.checked = true;
        } else {
          this.checked = false;
        }
      },

      checkTeamList(id) {
        this.executorIdList = [];
        const index = this.teamList.findIndex((item) => item.id == id);
        this.teamUserList = this.teamAllList[index];
      },

      checkChange() {
        if (this.checked) {
          this.executorIdList = [];
          this.executorIdList = this.teamUserList.map((item) => item.id);
        } else {
          this.executorIdList = [];
        }
      },

      getTgWarehouse() {
        const param = {
          workOrderIds: this.idsList,
          taskId: this.taskObj.id
        };

        listPcToWarehouseTG(param).then((res) => {
          // 创建一个映射，以便快速查找
          const workOrderMap = new Map(res.map((it) => [it.workOrderId, it]));

          // 更新List中的每个项目
          // this.List.forEach((item,index) => {
          //   if (workOrderMap.has(item.workOrderId)) {
          //     // 直接从映射中获取数据，避免嵌套循环
          //     this.$set(item, 'toWarehouseList', [
          //       JSON.parse(JSON.stringify(workOrderMap.get(item.workOrderId)))
          //     ]);

          //   } else {
          //     this.$set(item, 'toWarehouseList', []);
          //   }

          // });

          this.List.forEach((item, index) => {
            let arr = [];
            res.map((titem) => {
              if (item.workOrderId == titem.workOrderId) {
                arr.push(titem);
              }
              this.$set(item, 'toWarehouseList', arr);
            });
          });
        });
      },

      getQtWarehouse() {
        const param = {
          workOrderIds: this.idsList,
          taskId: this.taskObj.id
        };

        console.log(123456);

        listPCToWarehouse(param).then((res) => {
          // 创建一个映射，以便快速查找
          const workOrderMap = new Map(res.map((it) => [it.workOrderId, it]));

          console.log(workOrderMap, '99');
          // 更新List中的每个项目
          // this.List.map((item) => {
          //   if (workOrderMap.has(item.workOrderId)) {
          //     console.log(1);
          //     // 直接从映射中获取数据，避免嵌套循环
          //     this.$set(item, 'toWarehouseList', [
          //       JSON.parse(JSON.stringify(workOrderMap.get(item.workOrderId)))
          //     ]);

          //   } else {

          //     this.$set(item, 'toWarehouseList', []);

          //   }

          // });
          this.List.forEach((item, index) => {
            let arr = [];
            res.map((titem) => {
              if (item.workOrderId == titem.workOrderId) {
                arr.push(titem);
              }
              this.$set(item, 'toWarehouseList', arr);
            });
          });

          console.log(this.List, '6666666666');
        });
      },

      getWarehouseListFn() {
        getWarehouseList().then((res) => {
          // this.warehouseList = res.data;
          this.warehouseList = res.data.filter(
            (item) => item.factoryId == this.$store.state.user.info.factoryId
          );
        });
      },

      handleCreate(e) {
        if (e) {
          const list = JSON.parse(JSON.stringify(this.List));
          console.log(list);
          list.map((item) => {
            item.workReportInfo.executorTime = e;
          });
          this.$set(this, 'List', list);
        }
      },

      save() {
        for (let i = 0; i < this.List.length; i++) {
          if (!this.List[i].workReportInfo.executorTime) {
            this.$message.warning('报工时间不能为空');
            return;
          }
        }

        if (this.executorIdList.length == 0) {
          return this.$message.error('执行人不能为空！');
        }

        const executorList = [];

        this.executorIdList.forEach((item) => {
          const data = this.teamUserList.find((it) => it.id == item);
          if (data) {
            executorList.push({
              userId: data.id,
              jobNumber: data.jobNumber,
              name: data.name
            });
          }
        });

        this.List = this.List.map((item) => {
          item.workReportInfo.executorList = executorList;
          return item;
        });

        console.log(this.List, '------------');

        if (this.clientEnvironmentId == 21) {
          if (!this.warehouseId) {
            return this.$message.warning('请选择仓库');
          }

          this.List.forEach((item) => {
            item.warehouseId = this.warehouseId;
          });

          this.loading = this.$loading({
            lock: true,
            text: '加载中',
            background: 'rgba(0, 0, 0, 0.7)'
          });

          jobSave(this.List)
            .then((res) => {
              console.log(res);
              this.$message.success('入库成功');
              this.checked = false;
              this.executorIdList = [];
              this.teamId = '';
              this.loading.close();
              this.getList(this.idsList);
              this.$emit('warehouseSuccess', 'warehouseSuccess');
            })
            .catch((e) => {
              this.loading.close();
            });
        }
        // else if (this.clientEnvironmentId == 2) {
        //   if (!this.warehouseId) {
        //     return this.$message.warning('请选择仓库');
        //   }

        //   const listData = this.List.map((item) => {
        //     let categoryId = '',
        //       rootCategoryLevelId = '';
        //     if (item.product.length) {
        //       categoryId = item.categoryId;
        //       rootCategoryLevelId = item.rootCategoryLevelId;
        //     }

        //     let storageInfo = {
        //       inWarehouseSpecType:
        //         this.clientEnvironmentId !== 3 || this.clientEnvironmentId !== 2
        //           ? Number(this.inWarehouseSpecType)
        //           : '',
        //       warehouseId: this.warehouseId,
        //       inWarehouseType: this.inWarehouseType,
        //       toWarehouseList: this.clientEnvironmentId == 3 ? this.tgList : []
        //     };

        //     if (this.clientEnvironmentId == 2) {
        //       let num = '';
        //       if (item.workReportInfo && item.workReportInfo?.formedNum) {
        //         num = item.workReportInfo.formedNum;
        //       }

        //       storageInfo.packingReportList = [
        //         {
        //           code: item.productCode,
        //           categoryId: categoryId,
        //           workOrderId: item.workOrderId,
        //           rootCategoryLevelId: rootCategoryLevelId,
        //           totalQuantity: num,
        //           quantity: num,
        //           unit: item.unit,
        //           packingNum: 1,
        //           taskId: -1
        //         }
        //       ];
        //       item.storageInfo = storageInfo;
        //     }

        //     return {
        //       ...item
        //     };
        //   });

        //   console.log(listData, 'listData');
        //   this.loading = this.$loading({
        //     lock: true,
        //     text: '加载中',
        //     background: 'rgba(0, 0, 0, 0.7)'
        //   });

        //   jobSave(listData)
        //     .then((res) => {
        //       console.log(res);
        //       this.$message.success('入库成功');
        //       this.loading.close();
        //       this.getList(this.idsList);
        //       this.$emit('warehouseSuccess', 'warehouseSuccess');
        //     })
        //     .catch((e) => {
        //       this.loading.close();
        //     });
        // }
        else if (this.clientEnvironmentId == 3) {
          for (const item of this.List) {
            for (const it of item.semiProductList) {
              const data = it.extInfo;
              if (!data.reportWeight) {
                return this.$message.warning('报工重量不能为空');
              }
            }
          }

          let _arr = [];

          console.log(this.List, 'this.List');

          _arr = this.List.filter((item) => {
            if (item.toWarehouseList && item.toWarehouseList.length > 0) {
              return item.toWarehouseList.length > 0;
            } else {
              return true;
            }
          });

          _arr.forEach((item) => {
            item.warehouseId = this.warehouseId;
          });

          console.log(_arr, '_arr121221');

          let bol = true;
          bol = _arr.every((e, i) => {
            return e.warehouseId;
          });

          if (!bol) {
            this.$message.warning(`仓库不能为空`);
            return false;
          }

          let _arr2 = JSON.parse(JSON.stringify(_arr));

          _arr2.map((m) => {
            m.storageInfo = {
              warehouseId: m.warehouseId,
              toWarehouseList: m.toWarehouseList,
              inWarehouseSpecType: this.inWarehouseSpecType
            };
            delete m.warehouseId;
            delete m.toWarehouseList;
            return {
              ...m
            };
          });

          this.loading = this.$loading({
            lock: true,
            text: '加载中',
            background: 'rgba(0, 0, 0, 0.7)'
          });

          jobSave(_arr2)
            .then((res) => {
              console.log(res);
              this.$message.success('入库成功');
              this.checked = false;
              this.executorIdList = [];
              this.teamId = '';
              this.loading.close();
              this.getList(this.idsList);
              this.$emit('warehouseSuccess', 'warehouseSuccess');
            })
            .catch((e) => {
              this.loading.close();
            });
        } else {
          let _arr = [];

          console.log(this.List, 'this.List');

          this.List.forEach((item) => {
            item.warehouseId = this.warehouseId;
          });

          console.log(_arr, '_arr121221');

          let bol = true;
          bol = this.List.every((e, i) => {
            return e.warehouseId;
          });

          if (!bol) {
            this.$message.warning(`仓库不能为空`);
            return false;
          }

          let _arr2 = JSON.parse(JSON.stringify(this.List));

          _arr2.map((m) => {
            m.storageInfo = {
              warehouseId: m.warehouseId,
              toWarehouseList: m.toWarehouseList,
              inWarehouseSpecType: this.inWarehouseSpecType
            };
            delete m.warehouseId;
            delete m.toWarehouseList;
            return {
              ...m
            };
          });
          this.loading = this.$loading({
            lock: true,
            text: '加载中',
            background: 'rgba(0, 0, 0, 0.7)'
          });

          jobSave(_arr2)
            .then((res) => {
              console.log(res);
              this.$message.success('入库成功');
              this.checked = false;
              this.executorIdList = [];
              this.teamId = '';
              this.loading.close();
              this.getList(this.idsList);
              this.$emit('warehouseSuccess', 'warehouseSuccess');
            })
            .catch((e) => {
              this.loading.close();
            });
        }
      }
    }
  };
</script>

<style scoped lang="scss">
  .top_fixed {
    width: 100%;
    height: 40px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }

  .title_box {
    .name {
      font-size: 14px;
      font-style: normal;
      font-weight: 400;
      color: #157a2c;
      padding-left: 5px;
      position: relative;

      &:before {
        position: absolute;
        content: '';
        left: 0px;
        top: 0px;
        bottom: 0px;
        width: 2px;
        height: 14px;
        background: #157a2c;
        margin: auto;
      }
    }
  }

  .warehousing_box {
    // margin-top: 6px;
    width: 100%;
    height: calc(100vh - 70px - 50px - 80px - 62px);
    overflow-y: scroll;
    overflow-x: hidden;
  }

  .card_box {
    background: #fff;
    padding: 8px;
    border-radius: 2px;
  }

  .content_num {
    --input-background-color: #f0f8f2;
  }
  .item {
    display: flex;
    flex-direction: row;
    border: 1px solid #e3e5e5;
    border-top: 0 solid #e3e5e5;
    align-items: center;

    div {
      display: flex;
      flex-direction: row;
      align-items: center;
      height: 100%;
      .text {
        font-size: 12px;
        width: 100px;
        height: 32px;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #f7f9fa;
      }

      .select-type {
        width: 205px;
        padding: 2px;
        box-sizing: border-box;
      }
    }
  }

  .checkboxWrapper {
    padding: 8px 20px;
    border-bottom: 1px solid #ccc;
  }

  ::v-deep .el-select__tags {
    flex-wrap: nowrap;
    overflow: auto;
  }

  /* 输入框最大宽度*/
  ::v-deep .el-select__tags-text {
    max-width: 90px;
  }

  /* 底部滚动条的高度*/
  ::v-deep .el-select__tags::-webkit-scrollbar {
    height: 2px !important;
  }
</style>
