<template>
  <!--  退货单详情-->
  <div class="LookWareOrder">
    <div class="btn-top-div">
      <el-button
        v-if="
          return_detail.auditStatus === 1 &&
          $accessCheck($Access.ReturnWarehousingOrderUpdateOrderReturn)
        "
        type="primary"
        size="small"
        @click="updateAuditStatus"
      >
        审核通过
      </el-button>
      <el-button type="primary" size="small" @click="openUrl">
        打印退货单
      </el-button>
    </div>
    <div style="background: #ffffff; padding: 0 10px; margin-bottom: 10px">
      <el-tabs v-model="activeName" @tab-click="switchTabs">
        <el-tab-pane label="退货单详情" name="one"></el-tab-pane>
        <el-tab-pane
          v-if="
            parseInt(return_detail.auditStatus) === 2 &&
            $accessCheck($Access.InventoryInGetInventoryInInfo)
          "
          label="入库详情"
          name="two"
        ></el-tab-pane>
      </el-tabs>
    </div>
    <el-row style="padding-bottom: 13px">
      <el-col :span="24">
        <p
          style="padding-left: 20px"
          class="order_midden_left_text el-icon-arrow-right"
        >
          退货单信息
        </p>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">订单编号</span>
        <span class="form_right">{{ return_detail.no }}</span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">源订单号</span>
        <span class="form_right">{{ return_detail.originNo }}</span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">创建时间</span>
        <span class="form_right">
          {{ $_common.formatDate(return_detail.createTime) }}
        </span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">客户名称</span>
        <span class="form_right">
          {{ return_detail.customerName }}
        </span>
      </el-col>
      <!--<el-col class="form" :span="6">
        <span class="form_left">客户类型</span>
        <span class="form_right">
          {{ return_detail.customerTypeName }}
        </span>
      </el-col>-->
      <el-col class="form" :span="6">
        <span class="form_left">所属店铺</span>
        <span class="form_right">
          {{ return_detail.shopName }}
        </span>
      </el-col>
      <el-col class="form" :span="6" style="padding-left: 54px">
        <span class="form_left">联系人</span>
        <span class="form_right">
          {{ return_detail.realName }}
        </span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">联系电话</span>
        <span class="form_right">
          {{ return_detail.mobile }}
        </span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">联系地址</span>
        <span v-if="return_detail.area" class="form_right">
          {{ return_detail.area.provinceName }}{{ return_detail.area.cityName
          }}{{ return_detail.area.districtName }}{{ return_detail.address }}
        </span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">入库状态</span>
        <span class="form_right">
          <span v-if="return_detail.inStatus === 4" class="warning-status">
            未入库
          </span>
          <span v-else class="success-status">已入库</span>
        </span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">审核状态</span>
        <span class="form_right">
          <span v-if="return_detail.auditStatus === 1" class="warning-status">
            待审核
          </span>
          <span v-if="return_detail.auditStatus === 2" class="success-status">
            已审核
          </span>
          <span v-if="return_detail.auditStatus === 3" class="info-status">
            已驳回
          </span>
        </span>
      </el-col>
      <el-col class="form" :span="6" style="padding-left: 54px">
        <span class="form_left">审核人</span>
        <span class="form_right">
          {{ return_detail.auditStatus === 1 ? "--" : return_detail.auditName }}
        </span>
      </el-col>
      <el-col class="form" :span="6" style="padding-left: 54px">
        <span class="form_left">制单人</span>
        <span class="form_right">
          {{ return_detail.operatorName }}
        </span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">退货说明</span>
        <span class="form_right">
          {{ return_detail.remark || "无" }}
        </span>
      </el-col>
      <el-col class="form" :span="6">
        <span class="form_left">审核时间</span>
        <span class="form_right">
          {{
            return_detail.auditStatus === 1
              ? "--"
              : $_common.formatDate(return_detail.auditTime)
          }}
        </span>
      </el-col>
      <el-col v-if="return_detail.auditStatus === 3" class="form" :span="6">
        <span class="form_left">驳回原因</span>
        <span class="form_right">
          {{ return_detail.auditFailReason || "无" }}
        </span>
      </el-col>
    </el-row>
    <div v-show="activeName === 'one'" class="order_bottom">
      <p class="text">商品清单</p>
      <el-table :data="goods_list" show-summary :summary-method="getSummaries">
        <el-table-column label="#" width="60" type="index"></el-table-column>
        <el-table-column
          prop="goodsCode"
          label="编码"
          min-width="140"
        ></el-table-column>
        <el-table-column
          prop="goodsName"
          label="商品名称"
          min-width="180"
        ></el-table-column>
        <el-table-column label="规格" min-width="140">
          <template slot-scope="scope">
            {{ scope.row.unitName }}; {{ scope.row.skuName }}
          </template>
        </el-table-column>
        <el-table-column prop="saleNum" label="销售数量" min-width="100">
          <template slot-scope="scope">
            {{ $_common.formatNub(scope.row.saleNum) }}
          </template>
        </el-table-column>
        <el-table-column prop="num" label="退货数量" min-width="110">
          <template slot-scope="scope">
            {{ $_common.formatNub(scope.row.num) }}
            <span v-if="scope.row.isEq === 5">
              （{{ $_common.formatNub(scope.row.otherNum) }}）
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="returnUnitPrice"
          label="退货单价"
          min-width="100"
        >
          <template slot-scope="scope">
            {{ $_common.formattedNumber(scope.row.returnUnitPrice) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="returnTotalPrice"
          label="小计金额"
          min-width="100"
        >
          <template slot-scope="scope">
            {{ $_common.formattedNumber(scope.row.returnTotalPrice) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="skuBarCode"
          label="商品条码"
          min-width="100"
        ></el-table-column>
        <el-table-column
          prop="storage"
          label="货架编码"
          min-width="100"
        ></el-table-column>
      </el-table>
    </div>
    <div v-show="activeName === 'two'" style="margin-top: 20px">
      <div class="order_bottom">
        <div class="clearfix">
          <p class="text float_left">入库信息</p>
          <div
            v-if="
              inWarehouse_data.auditStatus !== 2 &&
              $accessCheck($Access.PurchaseOrderUpdateAuditStatus)
            "
            class="float_right"
            style="margin: 20px 20px 0 0"
          >
            <el-button
              size="mini"
              type="primary"
              @click="updatePurchaseInStatus"
            >
              入库审核
            </el-button>
          </div>
        </div>
        <el-row style="padding-bottom: 13px">
          <el-col class="form" :span="6">
            <span class="form_left">入库单号</span>
            <span class="form_right">{{ inWarehouse_data.no }}</span>
          </el-col>
          <el-col class="form" :span="6">
            <span class="form_left">制单人员</span>
            <span class="form_right">
              {{ inWarehouse_data.operatorName }}
            </span>
          </el-col>
          <el-col class="form" :span="6">
            <span class="form_left">制单时间</span>
            <span class="form_right">
              {{ $_common.formatDate(inWarehouse_data.createTime) }}
            </span>
          </el-col>
          <el-col class="form" :span="6">
            <span class="form_left">审核状态</span>
            <span class="form_right">
              <span
                v-if="inWarehouse_data.auditStatus === 1"
                class="warning-status"
              >
                待审核
              </span>
              <span
                v-if="inWarehouse_data.auditStatus === 2"
                class="success-status"
              >
                已审核
              </span>
              <span
                v-if="inWarehouse_data.auditStatus === 3"
                class="info-status"
              >
                已驳回
              </span>
            </span>
          </el-col>
          <el-col class="form" :span="6">
            <span class="form_left">审核人员</span>
            <span class="form_right">
              {{
                parseInt(inWarehouse_data.auditStatus) === 1
                  ? "--"
                  : inWarehouse_data.auditName
              }}
            </span>
          </el-col>
          <el-col class="form" :span="6">
            <span class="form_left">审核时间</span>
            <span class="form_right">
              {{
                parseInt(inWarehouse_data.auditStatus) === 1
                  ? "--"
                  : $_common.formatDate(inWarehouse_data.auditTime)
              }}
            </span>
          </el-col>
          <el-col class="form" :span="6">
            <span class="form_left">入库类型</span>
            <span class="form_right">
              {{ inWarehouse_data.typeName }}
            </span>
          </el-col>
          <el-col class="form" :span="6">
            <span class="form_left">入库门店</span>
            <span class="form_right">
              {{ inWarehouse_data.shopName }}
            </span>
          </el-col>
          <el-col
            v-if="inWarehouse_data.auditStatus === 2"
            class="form"
            :span="24"
          >
            <span class="form_left">入库说明</span>
            <span class="form_right">
              {{ inWarehouse_data.remark || "无" }}
            </span>
          </el-col>
        </el-row>
      </div>
      <div class="order_bottom">
        <p class="text">商品清单</p>
        <el-table :data="inWarehouse_data.details">
          <el-table-column label="#" width="60" type="index"></el-table-column>
          <el-table-column
            min-width="140"
            prop="materielName"
            label="商品名称"
          ></el-table-column>
          <el-table-column
            min-width="140"
            prop="materielCode"
            label="商品编码"
          ></el-table-column>
          <el-table-column min-width="140" prop="unitName" label="规格">
            <template slot-scope="scope">
              {{ scope.row.unitName }}; {{ scope.row.skuName }}
            </template>
          </el-table-column>
          <el-table-column
            :label="inWarehouse_data.type === 3 ? '采购数量' : '数量'"
            min-width="120"
            prop="num"
          >
            <template slot-scope="scope">
              {{ $_common.formatNub(scope.row.num) }}
            </template>
          </el-table-column>

          <el-table-column
            prop="unitPrice"
            :label="
              inWarehouse_data.type === 3
                ? '采购成本'
                : inWarehouse_data.type === 12
                ? '调拨成本'
                : '退货成本'
                ? '采购成本'
                : '退货单价'
            "
            min-width="140"
          >
            <template slot-scope="scope">
              {{ $_common.formattedNumber(scope.row.unitPrice) }}
            </template>
          </el-table-column>
          <el-table-column
            prop="totalPrice"
            :label="
              inWarehouse_data.type === 3
                ? '采购总成本'
                : inWarehouse_data.type === 12
                ? '调拨总成本'
                : '退货总成本'
                ? '采购总成本'
                : '退货总金额'
            "
            min-width="140"
          >
            <template slot-scope="scope">
              {{ $_common.formattedNumber(scope.row.totalPrice) }}
            </template>
          </el-table-column>
          <el-table-column min-width="120" prop="inNum" label="入库数量">
            <template slot-scope="scope">
              <span v-if="inWarehouse_data.auditStatus === 2">
                {{ $_common.formatNub(scope.row.inNum) }}
              </span>
              <el-input-number
                v-else
                v-model="scope.row.inNum"
                size="small"
                style="width: 100%"
                :min="1"
                :controls="false"
                @blur="inNumBlur(scope.$index)"
              ></el-input-number>
            </template>
          </el-table-column>
          <el-table-column min-width="120" prop="otherNum" label="其他单位">
            <template slot-scope="scope">
              <span v-if="inWarehouse_data.auditStatus === 2">
                {{
                  scope.row.isEq === 5
                    ? $_common.formatNub(scope.row.otherNum)
                    : "--"
                }}
              </span>
              <el-input-number
                v-else-if="scope.row.isEq === 5"
                v-model="scope.row.otherNum"
                style="width: 100%"
                :min="0"
                :controls="false"
              ></el-input-number>
              <span v-else>--</span>
            </template>
          </el-table-column>
          <el-table-column
            :label="inWarehouse_data.type === 3 ? '入库成本' : '入库单价'"
            prop="unitPrice"
            min-width="140"
          >
            <template slot-scope="scope">
              {{ $_common.formattedNumber(scope.row.inCost) }}
            </template>
          </el-table-column>

          <el-table-column
            prop="totalPrice"
            :label="inWarehouse_data.type === 3 ? '入库总成本' : '入库总金额'"
            min-width="140"
          >
            <template slot-scope="scope">
              {{ $_common.formattedNumber(scope.row.inCostTotal) }}
            </template>
          </el-table-column>
          <!--          <el-table-column min-width="120" prop="num" label="入库数量">-->
          <!--            <template slot-scope="scope">-->
          <!--              {{ $_common.formatNub(scope.row.num) }}-->
          <!--            </template>-->
          <!--          </el-table-column>-->
          <el-table-column
            v-if="shelfLifeSetUp === 5"
            prop="num"
            label="生产日期"
            min-width="140"
          >
            <template slot-scope="scope">
              <div
                v-if="inWarehouse_data.auditStatus !== 2"
                style="cursor: pointer"
                @click="openTimeShow(scope.row)"
              >
                <el-input
                  :value="
                    $_common.formatDate(scope.row.productionData, 'yyyy-MM-dd')
                  "
                  readonly
                  placeholder="请选择生产日期"
                  suffix-icon="el-icon-date"
                ></el-input>
              </div>
              <div v-else>
                {{
                  $_common.formatDate(scope.row.productionData, "yyyy-MM-dd")
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            v-if="enableLocationManagement === 5"
            label="库区库位"
            min-width="160"
          >
            <template slot-scope="scope">
              <div
                v-if="inWarehouse_data.auditStatus !== 2"
                style="cursor: pointer"
              >
                <el-input
                  v-model="scope.row.storageLocationName"
                  placeholder="库区库位"
                  style="width: 150px"
                >
                  <i
                    slot="suffix"
                    class="el-input__icon el-icon-search"
                    @click="storageShow(scope.row, scope.$index)"
                  ></i>
                </el-input>
              </div>
              <div v-else>{{ scope.row.storageLocationName || "--" }}</div>
            </template>
          </el-table-column>
          <el-table-column
            min-width="140"
            prop="barCode"
            label="商品条码"
          ></el-table-column>
          <el-table-column
            min-width="140"
            prop="storage"
            label="货架编码"
          ></el-table-column>
        </el-table>
      </div>
      <div v-if="inWarehouse_data.auditStatus !== 2" class="order_bottom">
        <p class="text">备注说明</p>
        <div style="margin-bottom: 10px">
          <el-input
            v-model="inWarehouse_data.remark"
            :readonly="inWarehouse_data.auditStatus === 2"
            type="textarea"
            placeholder="备注说明"
          ></el-input>
        </div>
      </div>
      <div v-if="inWarehouse_data.auditStatus !== 2" class="order_bottom">
        <p class="text">分摊</p>
        <div style="margin-left: 30px; padding-bottom: 40px">
          <el-form :inline="true">
            <el-form-item label="分摊方式:">
              <el-select
                v-model="inWarehouse_data.costAllocationType"
                :disabled="inWarehouse_data.auditStatus === 2"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="费用金额:">
              <el-input-number
                v-model="inWarehouse_data.costAllocation"
                :disabled="inWarehouse_data.auditStatus === 2"
                size="small"
                :controls="false"
                :min="0"
                placeholder="请输入费用金额"
              ></el-input-number>
            </el-form-item>
            <el-button
              type="primary"
              :disabled="inWarehouse_data.auditStatus === 2"
              :loading="loading"
              @click="countPurchaseCost"
            >
              确定分摊
            </el-button>
            <el-button
              type="warning"
              :disabled="inWarehouse_data.auditStatus === 2"
              @click="delCountPurchaseCost"
            >
              取消分摊
            </el-button>
          </el-form>
        </div>
      </div>
    </div>
    <div v-show="activeName === 'three'">
      <el-table style="width: 98%; margin: 20px auto 0" :data="orderLog">
        <el-table-column prop="userName" label="操作人"></el-table-column>
        <el-table-column prop="actionType" label="操作类型"></el-table-column>
        <el-table-column prop="createTime" label="操作时间">
          <template slot-scope="scope">
            {{ $_common.formatDate(scope.row.createTime) }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--    选择生产日期-->
    <ProductionData
      v-if="time_show"
      :show="time_show"
      :goods-data="batch_goods"
      @cancel="time_show = false"
      @confirm="timeEditConfirm"
    ></ProductionData>
    <!--    选择库位-->
    <StorageLocation
      v-if="storage_show"
      :is-check="false"
      :is-show="storage_show"
      :warehouse-id="warehouse_id"
      @confirm="selStorage"
      @cancel="storage_show = false"
    />
  </div>
</template>

<script>
  import { getOrderOut, auditOrderOut } from "@/api/Order";
  import {
    countPurchaseCost,
    getPurchaseInInfoT,
    updatePurchaseInStatus,
  } from "@/api/Stock";
  import ProductionData from "@/views/stock/component/ProductionData";
  import StorageLocation from "@/component/common/StorageLocation";
  import { mapGetters } from "vuex";
  export default {
    name: "LookWareOrder",
    components: {
      ProductionData,
      StorageLocation,
    },
    data() {
      return {
        activeName: "one",
        goods_list: [],
        inWarehouse_data: {
          details: [],
        },
        orderLog: [],
        return_detail: {},
        orderout_id: "",
        batch_goods: {},
        time_show: false,
        index: "",
        storage_show: false,
        warehouse_id: "",
        options: [
          { value: 4, label: "按数量" },
          { value: 5, label: "按金额" },
        ],
        loading: false,
        details: [],
      };
    },
    computed: {
      ...mapGetters({
        enableLocationManagement: "MUser/enableLocationManagement",
      }),
    },
    async created() {
      this.orderout_id = this.$route.params.id;
      await this.getOrderOut();
      if (
        parseInt(this.return_detail.auditStatus) === 2 &&
        this.$accessCheck(this.$Access.InventoryInGetInventoryInInfo)
      ) {
        await this.getPurchaseInInfo();
      }
    },
    methods: {
      // 入库数量失去焦点
      inNumBlur(index) {
        const list = this.$_common.deepClone(this.inWarehouse_data.details);
        list[index].inCostTotal = this.$NP.times(
          list[index].inCost,
          list[index].inNum
        );
        this.inWarehouse_data.details = list;
      },
      //  详情接口
      async getOrderOut() {
        const data = await getOrderOut(this.orderout_id);
        this.return_detail = data.data;
        this.goods_list = data.data.details.map((item) => {
          return {
            ...item,
            saleNum: item.extend.saleNum,
          };
        });
      },
      // 获取入库单详情
      async getPurchaseInInfo() {
        const { data } = await getPurchaseInInfoT({
          originId: this.return_detail.originId,
          source: this.return_detail.type,
        });

        this.inWarehouse_data = {
          ...data,
          details: data.details.map((item) => {
            let inNum = 0;
            if (data.auditStatus === 2) {
              inNum = item.inNum;
            } else {
              inNum = Number(item.inNum)
                ? Number(item.inNum)
                : Number(item.num);
            }
            return {
              ...item,
              productionData: item.productionData
                ? item.productionData * 1000
                : new Date().getTime(),
              inNum: inNum,
              inCost: Number(item.inCost) || item.unitPrice,
              inCostTotal:
                Number(item.inCostTotal) ||
                this.$NP.times(inNum, item.unitPrice),
              areaId: item.areaId || "",
              areaName: item.areaName || "",
              areaCode: item.areaCode || "",
              storageLocationId: item.storageLocationId || "",
              storageLocationName: item.storageLocationName || "",
              storageLocationCode: item.storageLocationCode || "",
            };
          }),
        };
        console.log(this.inWarehouse_data);
      },
      // 合计
      getSummaries(param) {
        return this.$_common.getSummaries(param, [
          "销售数量",
          "退货数量",
          "小计金额",
        ]);
      },
      // 打印
      openUrl() {
        let routeData = this.$router.resolve({
          path: `/ReturnOrderPrinting/${this.return_detail.id}`,
        });
        window.open(routeData.href, "_blank");
      },
      //  审核
      async updateAuditStatus() {
        this.$confirm("确定要审核通过该退货单吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(async () => {
          const data = await auditOrderOut(this.return_detail.id, {
            auditName: this.userName,
          });

          this.$message({
            type: "success",
            message: "审核成功",
          });
          await this.getOrderOut();
          if (this.$accessCheck(this.$Access.InventoryInGetInventoryInInfo)) {
            this.activeName = "two";
            await this.getPurchaseInInfo();
          }
        });
      },
      switchTabs() {},
      // 入库单审核
      updatePurchaseInStatus() {
        // 开启保质期设置，进行保质期验证
        if (this.shelfLifeSetUp === 5) {
          let gindex = 0;
          let gdate = false;
          for (let i in this.inWarehouse_data.details) {
            let item = this.inWarehouse_data.details[i];
            if (!item.productionData) {
              gindex = i;
              gdate = true;
              break;
            }
          }
          if (gdate) {
            this.$message.warning(`请选择第${Number(gindex) + 1}行的生产日期`);
            return;
          }
        }
        // 判断商品入库数量是否大于采购数量
        let numobj = {};
        for (let i in this.inWarehouse_data.details) {
          let item = this.inWarehouse_data.details[i];
          if (!numobj[item.skuId]) {
            numobj[item.skuId] = {
              inNum: item.inNum,
              num: Number(item.num),
              materielName: item.materielName,
              skuName: item.unitName + ";" + item.skuName,
            };
          } else {
            numobj[item.skuId].inNum += item.inNum;
          }
        }
        const ismore = Object.values(numobj).some(
          (item) => item.inNum > item.num
        );
        let tip = "确定要审核该入库单吗？";
        if (ismore) {
          tip = "商品的入库数量大于了采购数量，确定要入库吗？";
        }
        this.$confirm(tip, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(async () => {
          // let params = {
          //   id: this.inWarehouse_data.id,
          //   auditName: this.userName,
          // };
          // // 开启保质期设置，进行保质期验证
          // if (this.shelfLifeSetUp === 5) {
          //   const isTime = this.inWarehouse_data.details.every(
          //     (item) => item.productionData > 0
          //   );
          //   if (!isTime) {
          //     this.$message.warning("请选择生产日期");
          //     return;
          //   }
          //
          //   let productionData = this.inWarehouse_data.details.map((item) => {
          //     return {
          //       id: item.id,
          //       productionData: parseInt(item.productionData / 1000),
          //     };
          //   });
          //   params.details = productionData;
          // }
          let details = this.inWarehouse_data.details.map((item) => {
            // 开启保质期设置，进行保质期验证
            if (this.shelfLifeSetUp === 5) {
              item.productionData = parseInt(item.productionData / 1000);
            }
            return item;
          });
          let params = {
            id: this.inWarehouse_data.id,
            auditName: this.userName,
            remark: this.inWarehouse_data.remark,
            details: details,
            costAllocationType: this.inWarehouse_data.costAllocationType,
            costAllocation: Number(this.inWarehouse_data.costAllocation),
          };
          const data = await updatePurchaseInStatus(params);
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          await this.getPurchaseInInfo();
        });
      },
      openTimeShow(row) {
        this.batch_goods = row;
        this.time_show = true;
      },
      // 分批次入库
      timeEditConfirm(arr) {
        if (!arr.length) {
          return;
        }
        const index = this.inWarehouse_data.details.findIndex(
          (item) =>
            item.skuId === arr[0].skuId &&
            item.materielCode === arr[0].materielCode
        );
        if (index > -1) {
          if (this.inWarehouse_data.details[index].id) {
            arr[0].id = this.inWarehouse_data.details[index].id;
          }
          this.inWarehouse_data.details.splice(index, 1);
        }

        this.inWarehouse_data.details = this.inWarehouse_data.details.concat(
          arr
        );
      },
      storageShow(row, index) {
        this.index = index;
        this.storage_show = true;
        this.warehouse_id = this.inWarehouse_data.warehouseId;
      },
      selStorage(e) {
        const target = this.$_common.deepClone(this.inWarehouse_data.details);
        target[this.index] = {
          ...target[this.index],
          areaId: e[0].areaId,
          areaName: e[0].areaName,
          areaCode: e[0].areaCode,
          storageLocationId: e[0].id,
          storageLocationName: e[0].name,
          storageLocationCode: e[0].code,
        };
        this.inWarehouse_data.details = target;
        console.log(this.inWarehouse_data.details);
      },
      //确定分摊
      async countPurchaseCost() {
        if (!this.inWarehouse_data.costAllocationType) {
          this.$message.warning("请先选择分摊方式");
          return;
        }
        if (!Number(this.inWarehouse_data.costAllocation)) {
          this.$message.warning("费用金额须大于0");
          return;
        }
        this.details = this.inWarehouse_data.details;
        console.log(this.details);
        this.skuData = this.inWarehouse_data.details.map((item) => {
          return {
            skuId: item.skuId,
            num: Number(item.inNum),
            cost: Number(item.unitPrice),
            money: Number(item.inCostTotal),
          };
        });
        this.loading = true;
        try {
          const { data } = await countPurchaseCost({
            money: this.inWarehouse_data.costAllocation,
            type: this.inWarehouse_data.costAllocationType,
            skuData: this.skuData,
          });
          this.inWarehouse_data.details = this.inWarehouse_data.details.map(
            (item) => {
              item.inCost = data[item.skuId].cost;
              item.inCostTotal = data[item.skuId].money;
              return item;
            }
          );
          this.loading = false;
        } catch {
          this.loading = false;
        }
      },
      //取消分摊
      delCountPurchaseCost() {
        this.inWarehouse_data.costAllocation = "";
        this.inWarehouse_data.costAllocationType = "";
        this.inWarehouse_data.details = this.inWarehouse_data.details.map(
          (item) => {
            item.inCost = item.unitPrice;
            item.inCostTotal = item.totalPrice;
            return item;
          }
        );
      },
    },
  };
</script>

<style scoped lang="scss">
  .order_bottom {
    border-top: 16px solid #f6f8f9;
    width: 100%;
    background-color: #ffffff;
    border-radius: 3px;
    .text {
      font-size: 16px;
      font-weight: 600;
      color: #2d405e;
      line-height: 64px;
      padding: 0px 24px;
    }
  }
  .order_midden_left_text {
    font-weight: bold;
    font-size: 16px;
    margin: 0 0 27px 0;
  }
  .form {
    padding-left: 40px;
    font-size: 14px;
    margin-bottom: 19px;
    .form_left {
      margin-right: 32px;
      color: #62738e;
      font-weight: 400;
    }
    .form_right {
      color: #2d405e;
      font-weight: 500;
    }
  }
  .LookWareOrder {
    background-color: #fff;
    position: relative;
  }
  .btn-top-div {
    position: absolute;
    right: 10px;
    top: 16px;
    z-index: 999;
  }
  .de_label {
    width: 90px;
    display: inline-block;
    text-align: right;
  }
</style>

<style>
  .LookWareOrder .el-tabs__item {
    font-size: 16px !important;
    height: 60px !important;
    line-height: 60px !important;
  }
  .LookWareOrder .el-tabs__nav {
    margin-left: 24px;
  }
  .LookWareOrder .is-active {
    font-weight: 700;
  }
</style>
