<template>
  <div class="out-box">
    <el-row :span="24">
      <el-row :span="24">
        <el-col :span="6">
          <p
            style="padding-left: 28px"
            class="order_midden_left_text el-icon-arrow-right"
          >
            单据信息
          </p>
        </el-col>
        <el-col :span="6">
          <p class="order_midden_left_text el-icon-arrow-right">
            &nbsp;出库信息
          </p>
        </el-col>
        <el-col
          v-if="out_detail.deliveryType !== 2 && out_detail.receiveData"
          :span="6"
        >
          <p class="order_midden_left_text el-icon-arrow-right">
            {{ out_detail.deliveryType !== 2 ? "收货信息" : "自提点信息" }}
          </p>
        </el-col>
        <el-col :span="6">
          <p class="order_midden_left_text el-icon-arrow-right">
            &nbsp;其他信息
          </p>
        </el-col>
      </el-row>
      <el-col :span="6">
        <div class="order_midden_left">
          <el-form
            style="margin-top: 10px; padding-left: 46px; font-size: 10px"
          >
            <el-form-item label="单据编号">
              {{ out_detail.no }}
            </el-form-item>
            <el-form-item label="制单人">
              {{ out_detail.operatorName }}
            </el-form-item>
            <el-form-item label="制单时间">
              <span v-if="out_detail.createTime">
                {{ $_common.formatDate(out_detail.createTime) }}
              </span>
            </el-form-item>
            <el-form-item label="出库状态">
              <span v-if="out_detail.auditStatus === 2" class="success-status">
                已出库
              </span>
              <span v-else class="info-status">未出库</span>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="order_midden_left">
          <el-form style="margin-top: 10px" label-width="90px">
            <el-form-item label="客户名称">
              {{ out_detail.customerName }}
            </el-form-item>
            <el-form-item label="客户电话">
              {{ out_detail.customerMobile }}
            </el-form-item>
            <el-form-item label="出库日期">
              {{
                out_detail.auditTime
                  ? $_common.formatDate(out_detail.auditTime)
                  : "--"
              }}
            </el-form-item>
            <el-form-item label="出库类型">
              {{ out_detail.typeName }}
            </el-form-item>
            <el-form-item label="配送方式">
              {{ out_detail.deliveryName }}
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col :span="6">
        <div
          v-if="out_detail.deliveryType !== 2 && out_detail.receiveData"
          class="order_midden_left"
        >
          <el-form label-width="90px">
            <el-form-item label="收货人">
              {{ out_detail.receiveData.realName || "匿名" }}
            </el-form-item>
            <el-form-item label="收货电话">
              {{ out_detail.receiveData.mobile }}
            </el-form-item>
            <el-form-item label="收货地址">
              <span v-if="out_detail.receiveData.area">
                {{ out_detail.receiveData.area.provinceName }}-{{
                  out_detail.receiveData.area.cityName
                }}-{{ out_detail.receiveData.area.districtName }}-{{
                  out_detail.receiveData.address
                }}
              </span>
            </el-form-item>
          </el-form>
        </div>
        <div
          v-if="
            out_detail.deliveryType === 2 &&
            JSON.stringify(out_detail.selfRuleData) !== '[]' &&
            out_detail.selfRuleData.name
          "
          class="order_midden_left"
        >
          <el-form label-width="90px">
            <el-form-item label="自提点">
              {{ out_detail.selfRuleData.name }}
            </el-form-item>
            <el-form-item label="自提点电话">
              {{ out_detail.selfRuleData.mobile }}
            </el-form-item>
            <el-form-item label="营业时间">
              <span
                v-if="
                  out_detail.selfRuleData.startTime &&
                  out_detail.selfRuleData.endTime
                "
              >
                {{ out_detail.selfRuleData.startTime }}-{{
                  out_detail.selfRuleData.endTime
                }}
              </span>
              <span v-else>全天</span>
              <span style="padding-left: 5px">
                {{ out_detail.selfRuleData.day.join(",") }}
              </span>
            </el-form-item>
            <el-form-item label="自提地点">
              {{ out_detail.selfRuleData.provinceName }}-{{
                out_detail.selfRuleData.cityName
              }}-{{ out_detail.selfRuleData.districtName }}-{{
                out_detail.selfRuleData.address
              }}
            </el-form-item>
          </el-form>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="order_midden_right">
          <el-form label-width="80px">
            <el-form-item label="来源编号">
              {{ out_detail.originNo }}
            </el-form-item>
            <el-form-item label="备注信息">
              {{ out_detail.remark || "无" }}
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
    <!--    未分配仓库-->
    <div v-show="unassigned_sku_data.length" class="order_bottom">
      <p class="text">未分配仓库</p>
      <el-table size="small" :data="unassigned_sku_data">
        <el-table-column
          v-if="out_detail.isDistribution === 5"
          prop="warehouseId"
          label="仓库"
          min-width="160"
        >
          <template slot-scope="scope">
            <div
              v-if="
                scope.row.warehouseSelect && scope.row.warehouseSelect.length
              "
            >
              <el-select
                v-model="scope.row.warehouseId"
                style="width: 100%"
                placeholder="请选择"
                @change="unWarehouseChange($event, scope.row, scope.$index)"
              >
                <el-option
                  v-for="(warehouse, a) in scope.row.warehouseSelect"
                  :key="a"
                  :label="warehouse.warehouseName"
                  :value="warehouse.warehouseId"
                  :disabled="
                    scope.row.isPreSale === 4 &&
                    warehouse.warehouseInventoryNum < scope.row.num
                  "
                >
                  <div class="clearfix">
                    <span class="float_left">
                      {{ warehouse.warehouseName }}
                    </span>
                    <span
                      class="float_right"
                      style="color: #8492a6; font-size: 12px; margin-left: 10px"
                    >
                      库存{{
                        $_common.formatNub(warehouse.warehouseInventoryNum)
                      }}
                    </span>
                  </div>
                </el-option>
              </el-select>
            </div>

            <span v-else>无可用仓库</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="materielName"
          label="商品名称"
          min-width="160"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="materielCode"
          label="商品编码"
          min-width="130"
        ></el-table-column>
        <el-table-column prop="skuName" label="规格" min-width="140">
          <template slot-scope="scope">
            {{ scope.row.unitName }};{{ scope.row.skuName }}
          </template>
        </el-table-column>
        <el-table-column prop="num" label="销售量" min-width="100">
          <template slot-scope="scope">
            {{ $_common.formatNub(scope.row.num) }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="$accessCheck($Access.moneyshowstockOutMoneyShow)"
          prop="unitPrice"
          min-width="100"
          label="销售单价"
        >
          <template slot-scope="scope">
            {{ $_common.formattedNumber(scope.row.unitPrice) }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="$accessCheck($Access.moneyshowstockOutMoneyShow)"
          prop="originTotalPrice"
          label="销售总金额"
          min-width="100"
        >
          <template slot-scope="scope">
            ¥{{ $NP.times(Number(scope.row.unitPrice), Number(scope.row.num)) }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 仓库出库数据-->
    <template v-for="(item, index) in out_warehouse_data">
      <div v-if="item.details.length" :key="index" class="order_bottom">
        <p class="text">{{ item.warehouseName }}</p>
        <el-table size="small" :data="item.details">
          <el-table-column prop="warehouseId" label="仓库" min-width="160">
            <template slot-scope="scope">
              <span v-if="out_detail.isDistribution === 4">
                {{ scope.row.warehouseName }}
              </span>
              <el-select
                v-else
                v-model="scope.row.warehouseId"
                style="width: 100%"
                placeholder="请选择仓库"
                @change="
                  warehouseChange($event, index, scope.$index, scope.row)
                "
              >
                <!--不支持负库存的时候，当库存量小于销售量的时候禁用该仓库-->
                <el-option
                  v-for="(warehouse, a) in scope.row.warehouseSelect"
                  :key="a"
                  :label="warehouse.warehouseName"
                  :value="warehouse.warehouseId"
                  :disabled="
                    scope.row.isPreSale === 4 &&
                    warehouse.warehouseInventoryNum < scope.row.num
                  "
                >
                  <div class="clearfix">
                    <span class="float_left">
                      {{ warehouse.warehouseName }}
                    </span>
                    <span
                      class="float_right"
                      style="color: #8492a6; font-size: 12px; margin-left: 10px"
                    >
                      库存{{
                        $_common.formatNub(warehouse.warehouseInventoryNum)
                      }}
                    </span>
                  </div>
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            prop="materielName"
            label="商品名称"
            min-width="160"
            show-overflow-tooltip
          ></el-table-column>
          <el-table-column
            prop="materielCode"
            label="商品编码"
            min-width="130"
          ></el-table-column>
          <el-table-column prop="skuName" label="规格" min-width="140">
            <template slot-scope="scope">
              {{ scope.row.unitName }};{{ scope.row.skuName }}
            </template>
          </el-table-column>
          <el-table-column prop="num" label="应出数量" min-width="100">
            <template slot-scope="scope">
              <span>
                {{ $_common.formatNub(scope.row.total) }}
              </span>
              <span v-if="!!scope.row.extend && scope.row.extend !== 'null'">
                （{{ scope.row.extend.u_1_buy }}{{ scope.row.extend.u_1 }}）
              </span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="enableLocationManagement === 5"
            label="库区库位"
            min-width="100"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.storageLocationName"
                placeholder="库区库位"
              >
                <i
                  slot="suffix"
                  class="el-input__icon el-icon-search"
                  @click="storageShow(scope.row, scope.$index, index)"
                ></i>
              </el-input>
            </template>
          </el-table-column>
          <el-table-column prop="num" min-width="100">
            <template slot="header">
              <span style="color: red">*</span>
              <span>出库数量</span>
            </template>
            <template slot-scope="scope">
              <div>
                <span v-if="out_detail.auditStatus === 2">
                  {{ $_common.formatNub(scope.row.outNum) }}
                </span>
                <el-input
                  v-else
                  v-model="scope.row.num"
                  type="number"
                  style="width: 100%"
                  @blur="saleNumBlur($event, scope.$index, index, scope.row)"
                ></el-input>
              </div>

              <div
                v-if="!!scope.row.extend && scope.row.extend !== 'null'"
                style="padding-top: 5px"
              >
                <span style="margin-right: 10px">其他单位:</span>
                <span v-if="out_detail.auditStatus === 2">
                  {{ $_common.formatNub(scope.row.otherNum) }}
                </span>
                <el-input
                  v-else
                  v-model="scope.row.otherNum"
                  type="number"
                  style="width: calc(100% - 71px)"
                ></el-input>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </template>

    <!--    商品清单-->
    <div class="order_bottom">
      <p class="text">商品清单</p>

      <el-table size="small" :data="out_detail.details">
        <el-table-column
          prop="materielName"
          label="商品名称"
          min-width="160"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="materielCode"
          label="商品编码"
          min-width="140"
        ></el-table-column>
        <el-table-column prop="skuName" label="规格" min-width="140">
          <template slot-scope="scope">
            {{ scope.row.unitName }};{{ scope.row.skuName }}
          </template>
        </el-table-column>
        <el-table-column prop="num" label="销售量" min-width="100">
          <template slot-scope="scope">
            {{ $_common.formatNub(scope.row.total) }}
            <span v-if="!!scope.row.u_1_buy">
              （{{ scope.row.u_1_buy }}{{ scope.row.u_1 }}）
            </span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="out_detail.typeName === '销售出库'"
          prop="num"
          label="出库数量"
          min-width="120"
        >
          <template slot-scope="scope">
            {{ $_common.formatNub(scope.row.outNum) }}
            <p v-if="scope.row.isEq === 5">
              其他单位:{{ $_common.formatNub(scope.row.otherNum) }}
            </p>
          </template>
        </el-table-column>
        <el-table-column
          v-if="$accessCheck($Access.moneyshowstockOutMoneyShow)"
          prop="unitPrice"
          min-width="130"
          label="销售单价"
        >
          <template slot-scope="scope">
            {{ $_common.formattedNumber(scope.row.unitPrice) }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="$accessCheck($Access.moneyshowstockOutMoneyShow)"
          prop="originTotalPrice"
          label="销售总金额"
          min-width="130"
        >
          <template slot-scope="scope">
            ¥{{
              $NP.times(Number(scope.row.unitPrice), Number(scope.row.outNum))
            }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="$accessCheck($Access.moneyshowstockOutMoneyShow)"
          prop="totalPrice"
          label="销售总金额(优惠后)"
          min-width="130"
        >
          <template slot-scope="scope">
            {{ $_common.formattedNumber(scope.row.totalPrice) }}
          </template>
        </el-table-column>
        <el-table-column prop="skuStorage" label="货架编码" min-width="120">
          <template slot-scope="scope">
            {{ scope.row.skuStorage || "--" }}
          </template>
        </el-table-column>
        <el-table-column prop="skuBarCode" label="商品条码" min-width="120">
          <template slot-scope="scope">
            {{ scope.row.skuBarCode || "--" }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <CallInLocation
      v-if="storage_show"
      :is-check="false"
      :is-show="storage_show"
      :warehouse-id="warehouse_id"
      :sku-id="skuId"
      :materiel-id="materielId"
      @confirm="selStorage"
      @cancel="storage_show = false"
    />
  </div>
</template>

<script>
  import CallInLocation from "@/component/common/CallInLocation";
  import { mapGetters } from "vuex";
  import { getSaleOutInfoT, updateSaleOutStatus } from "@/api/Stock";
  export default {
    name: "OutWarehouseInfo",
    components: {
      CallInLocation,
    },
    props: {
      orderType: {
        type: [Number, String],
        default: "",
      },
      orderId: {
        type: [Number, String],
        default: "",
      },
      auditOut: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {
        out_detail: { receiveData: {} },
        out_id: "",
        sku_total: {},
        out_warehouse_copy: [],
        out_warehouse_data: [], // 商品清单，按仓库分
        unassigned_sku_data: [], // 未出库商品
        storage_show: false,
        warehouse_id: "",
        skuId: "",
        itemIndex1: "",
        index1: "",
        materielId: "",
      };
    },
    computed: {
      ...mapGetters({
        enableLocationManagement: "MUser/enableLocationManagement",
      }),
    },
    watch: {
      auditOut() {
        this.updateSaleOutStatus();
      },
    },
    created() {
      this.getSaleOutInfo();
    },
    methods: {
      // 获取出库单详情
      async getSaleOutInfo() {
        const { data } = await getSaleOutInfoT({
          originId: this.orderId,
          source: this.orderType,
        });

        this.out_detail = data;
        this.out_id = data.id;
        this.out_warehouse_copy = this.$_common.deepClone(
          data.outWarehouseData
        );
        // 存一下未修改的原始出库数量
        data.outWarehouseData.forEach((item) => {
          item.details.forEach((goods) => {
            goods.numCopy = Number(goods.num);
            // 抄嘛商品默认为空
            if (goods.extend !== "null" && !!goods.extend) {
              goods.extend = JSON.parse(goods.extend);
              if (!Number(goods.otherNum)) {
                goods.otherNum = this.$NP.divide(
                  goods.numCopy,
                  goods.extend.conversion
                );
              }

              goods.num = "";
            } else {
              goods.num = Number(goods.num);
            }
          });
        });
        this.out_warehouse_data = data.outWarehouseData;
        this.unassigned_sku_data = data.UnassignedSkuData;
        this.sku_total = data.skuTotal;
        this.$emit("getOutDetail", this.out_detail);
      },
      warehouseChange(val, index, rowI, row) {
        // 深拷贝一份商品数据
        const target = this.$_common.deepClone(this.out_warehouse_data);
        // 在要出库的列表中查找当前切换的仓库是否存在
        const wIndex = target.findIndex((item) => item.warehouseId === val);
        if (wIndex > -1) {
          // 当前仓库存在
          // 查找商品是否存在
          const gIndex = target[wIndex].details.findIndex(
            (item) => item.skuId === row.skuId
          );
          if (gIndex > -1) {
            // 商品存在
            // 累加销售量
            target[wIndex].details[gIndex].num = this.$NP.plus(
              target[wIndex].details[gIndex].num,
              row.num
            );
          } else {
            // 商品不存在，添加该商品
            target[wIndex].details.push(row);
          }
        } else {
          // 仓库不存在，添加一项仓库数据
          target.push({
            warehouseId: val,
            warehouseName: row.warehouseSelect.find(
              (item) => item.warehouseId === val
            ).warehouseName,
            details: [row],
          });
        }
        // 把当前这条商品从原来的位置删除
        target[index].details.splice(rowI, 1);
        // 未开启负库存
        if (row.isPreSale === 4) {
          // 查找当前切换仓库数据
          const warehouseData = row.warehouseSelect.find(
            (item) => item.warehouseId === val
          );
          // 查找当前仓库在出库列表的数据
          const targetI = target.findIndex((item) => item.warehouseId === val);
          // 查找当前商品在该仓库下出库列表的数据
          const goodsI = target[targetI].details.findIndex(
            (item) => item.skuId === row.skuId
          );
          // 如果当前数量大于该仓库下的库存，推入到未出库数据中
          if (
            target[targetI].details[goodsI].num >
            warehouseData.warehouseInventoryNum
          ) {
            // 拷贝一份未出库数据
            const unassignedData = this.$_common.deepClone(
              this.unassigned_sku_data
            );
            // 判断当前未出库数据中是否有当前规格的商品
            const unIndex = unassignedData.findIndex(
              (unItem) => unItem.skuId === row.skuId
            );
            // 设置当前未出库商品
            const goods = {
              ...target[targetI].details[goodsI],
              num: this.$NP.minus(
                target[targetI].details[goodsI].num,
                warehouseData.warehouseInventoryNum
              ),
              warehouseId: "",
            };
            // 未出库商品列表有该商品，则替换
            if (unIndex > -1) {
              unassignedData[unIndex] = goods;
            } else {
              // 没有该商品则推入
              unassignedData.push(goods);
            }
            // 给未出库商品列表重新赋值
            this.unassigned_sku_data = unassignedData;
            // 设置当前商品销售量为该仓库的最大库存
            target[targetI].details[goodsI].num =
              warehouseData.warehouseInventoryNum;
          }
        }

        // 给出库数据重新赋值
        this.out_warehouse_data = target;
      },
      // 获取当前合计销售量
      totalNumChange(target, row) {
        // 设置变量num
        let num = 0;
        target.forEach((item) => {
          const goods = item.details.find((item) => item.skuId === row.skuId);
          if (goods) {
            // 加上当前商品销售量
            num = this.$NP.plus(num, goods.num);
          }
        });
        return num;
      },
      // 销售量修改
      saleNumBlur(e, rowI, index, row) {
        const val = e.target.value;
        // 深拷贝一份商品数据
        const target = this.$_common.deepClone(this.out_warehouse_data);

        if (val === "") {
          this.$nextTick(() => {
            target[index].details[rowI].num = "";
          });
          this.out_warehouse_data = target;
          return;
        }
        if (
          target[index].details[rowI].num >
          Number(this.sku_total[target[index].details[rowI].skuId])
        ) {
          target[index].details[rowI].num = Number(
            this.sku_total[target[index].details[rowI].skuId]
          );
          this.out_warehouse_data = target;
          return;
        }
        // 不支持负库存
        if (row.isPreSale === 4) {
          const warehouseData = row.warehouseSelect.find(
            (item) => item.warehouseId === row.warehouseId
          );
          // 输入值大于当前仓库库存数
          if (Number(val) > Number(warehouseData.warehouseInventoryNum)) {
            // 把当前商品的销售量还原
            target[index].details[rowI].num =
              target[index].details[rowI].numCopy;
          }
        }

        // 深拷贝一份未出库商品数据
        const unassignedData = this.$_common.deepClone(
          this.unassigned_sku_data
        );
        // 判断当前未出库数据中是否有当前规格的商品
        const unIndex = unassignedData.findIndex(
          (unItem) => unItem.skuId === row.skuId
        );
        // 设置变量num  获取当前合计销售量
        let num = this.totalNumChange(target, row);
        // 判断当前修改后的合计商品销售量是否大于购买数量，大于就把当前商品的销售量还原
        if (num > this.sku_total[row.skuId]) {
          // 修改后的合计商品销售量大于购买数量，把当前商品的销售量还原
          target[index].details[rowI].num = target[index].details[rowI].numCopy;
        } else if (num === Number(this.sku_total[row.skuId])) {
          // 修改后的合计商品销售量等于购买数量
          // 未出库商品列表有该商品，则删除
          if (unIndex > -1) {
            unassignedData.splice(unIndex, 1);
          }
        } else if (
          this.sku_total[row.skuId] &&
          this.$NP.minus(this.sku_total[row.skuId], num) > 0
        ) {
          // 当前未出库库存大于0
          // 设置当前未出库商品
          const goods = {
            ...this.$_common.deepClone(target[index].details[rowI]),
            num: this.$NP.minus(this.sku_total[row.skuId], num),
            warehouseId: "",
          };
          // 未出库商品列表有该商品，则替换
          if (unIndex > -1) {
            unassignedData[unIndex] = goods;
          } else {
            // 没有该商品则推入
            unassignedData.push(goods);

            // 如果输入数量为0 ，则把对应出库商品清除
            if (num === 0) {
              target[index].details.splice(rowI, 1);
            }
          }
        }
        // 给未出库商品列表重新赋值
        this.unassigned_sku_data = unassignedData;
        // 给出库商品列表重新赋值
        this.out_warehouse_data = target;
      },
      // 未出库数据仓库选择
      unWarehouseChange(val, row, indexUn) {
        // 深拷贝一份商品数据
        const target = this.$_common.deepClone(this.out_warehouse_data);
        // 在出库商品数据中查找选择仓库
        const index = target.findIndex((item) => item.warehouseId === val);
        // 出库商品数据中有该选择的仓库
        if (index > -1) {
          // 找到商品所在下标（位置）
          const goodsI = target[index].details.findIndex(
            (goods) => goods.skuId === row.skuId
          );
          // 该仓库下包含当前商品
          if (goodsI > -1) {
            target[index].details[goodsI].num = this.$NP.plus(
              target[index].details[goodsI].num,
              row.num
            );
          } else {
            // 该仓库下不包含当前商品，把当前商品推到该仓库下面
            target[index].details.push(row);
          }
        } else {
          // 出库商品数据中没有该选择的仓库，添加一项仓库数据
          target.push({
            warehouseId: val,
            warehouseName: row.warehouseSelect.find(
              (item) => item.warehouseId === val
            ).warehouseName,
            details: [row],
          });
        }
        // 把当前这条商品从原来的位置删除
        this.unassigned_sku_data.splice(indexUn, 1);
        this.out_warehouse_data = target;
      },
      async updateSaleOutStatus() {
        let flag = false;
        for (let i in this.out_warehouse_data) {
          for (let j in this.out_warehouse_data[i].details) {
            let item1 = this.out_warehouse_data[i].details[j];
            if (!item1.num) {
              flag = true;
              this.$message.warning(
                "商品" +
                  item1.materielName +
                  "，规格 【" +
                  item1.unitName +
                  "；" +
                  item1.skuName +
                  "】的出库数量不能为空"
              );
              break;
            }
            if (item1.otherNum < 0) {
              flag = true;
              this.$message.warning(
                "商品" +
                  item1.materielName +
                  "，规格 【" +
                  item1.unitName +
                  "；" +
                  item1.skuName +
                  "】的其他数量不能小于0"
              );
              break;
            }
          }
        }
        if (flag) {
          return;
        }
        if (!this.out_warehouse_data || !this.out_warehouse_data.length) {
          this.$message({
            type: "warning",
            message: "请选择出库商品",
          });
          return;
        }
        let isNum = true;
        // 过滤 出去没有商品的
        const outWarehouseData = this.out_warehouse_data.filter(
          (item) => item.details && item.details.length > 0
        );
        if (!outWarehouseData.length) {
          this.$message.warning("请选择要出库的商品");
          return;
        }
        for (let i in outWarehouseData) {
          let item = this.out_warehouse_data[i];
          for (let n in item.details) {
            let ntem = item.details[n];
            if (ntem.num <= 0) {
              isNum = false;
              break;
            }
          }
        }
        if (!isNum) {
          this.$message.warning("销售量必须大于0");
          return;
        }
        this.$confirm("确定要审核该出库单吗？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(async () => {
          try {
            const data = await updateSaleOutStatus({
              id: this.out_detail.id,
              auditName: this.userName,
              UnassignedSkuData: this.unassigned_sku_data,
              outWarehouseData: outWarehouseData,
            });

            this.$message({
              type: "success",
              message: "操作成功!",
            });
            // 审核成功填写货车信息
            if (this.out_detail.deliveryType === 3) {
              this.logistics_show = true;
            }
            await this.getSaleOutInfo();
            this.$emit("auditSuccess");
          } catch {}
        });
      },
      selStorage(e) {
        const target = this.$_common.deepClone(this.out_warehouse_data);
        target[this.index1].details[this.itemIndex1] = {
          ...target[this.index1].details[this.itemIndex1],
          areaId: e[0].areaId,
          areaName: e[0].areaName,
          areaCode: e[0].areaCode,
          storageLocationName: e[0].storageLocationName,
          storageLocationId: e[0].storageLocationId,
          storageLocationCode: e[0].storageLocationCode,
        };
        this.out_warehouse_data = target;
      },
      storageShow(row, itemIndex1, index) {
        this.materielId = row.materielId;
        this.itemIndex1 = itemIndex1;
        this.index1 = index;
        this.warehouse_id = row.warehouseId;
        this.skuId = row.skuId;
        this.storage_show = true;
      },
    },
  };
</script>
<style>
  .out-box .el-form-item--small.el-form-item {
    margin-bottom: 5px;
  }
</style>
<style scoped lang="scss">
  .order_midden_left_text {
    font-weight: bold;
    font-size: 16px;
  }
  .order_midden_left {
    margin-top: 16px;
    width: 95%;
    height: 200px;
    border-right: 1px solid #dee2ee;
  }
  .order_midden_right {
    margin-top: 16px;
  }
  .order_bottom {
    border-top: 16px solid #f6f8f9;
    width: 100%;
    padding-bottom: 24px;
    background-color: #ffffff;
    border-radius: 3px;
    .text {
      font-size: 16px;
      font-weight: 600;
      color: #2d405e;
      line-height: 64px;
      padding: 0px 28px;
    }
    .order_p {
      text-align: right;
      line-height: 58px;
      padding-right: 38px;
      color: #2d405e;
      .order_p_money {
        color: #fa6400;
        margin: 0 3px;
      }
    }
  }
</style>
