<template>
  <div>
    <el-card :class="props.selectStatus ? 'select-card' : 'box-card'">
      <byTable
        :source="sourceList.data"
        :pagination="sourceList.pagination"
        :config="config"
        :loading="loading"
        :searchConfig="searchConfig"
        highlight-current-row
        :action-list="[
          props.selectStatus
            ? {}
            : {
                text: '操作日志',
                action: () => viewLogs(),
              },
          props.selectStatus
            ? {}
            : {
                text: '复制E10单号',
                action: () => clickCopyWLNCode(),
              },
          props.selectStatus
            ? {}
            : {
                text: '同步订单',
                action: () => clickSynchronousOrder(),
                loading: btnLoading,
              },
        ]"
        @get-list="getList"
        @clickReset="clickReset">
        <template #code="{ item }">
          <div>
            <a style="color: #409eff; cursor: pointer; word-break: break-all" @click="clickCode(item)">{{ item.code }}</a>
          </div>
        </template>
        <template #totalAmount="{ item }">
          <div style="color: #409eff">{{ moneyFormat(item.totalAmount) }}</div>
        </template>
        <template #address="{ item }">
          <div>{{ item.province }}, {{ item.city }}, {{ item.county }}, {{ item.detailedAddress }}</div>
        </template>
      </byTable>
    </el-card>

    <el-dialog title="操作日志" v-if="openLogs" v-model="openLogs" width="50%">
      <byTable
        :source="logsList.data"
        :pagination="logsList.pagination"
        :config="configLogs"
        :loading="loadingLogs"
        highlight-current-row
        @get-list="getLogsList">
      </byTable>
      <template #footer>
        <el-button @click="openLogs = false" size="large">关 闭</el-button>
      </template>
    </el-dialog>

    <el-dialog title="修改税率" v-if="openChangeTaxRate" v-model="openChangeTaxRate" width="500" style="margin-top: 20vh !important">
      <el-form :model="details.data" label-width="120px" ref="taxRate">
        <el-form-item label="税率" prop="taxRate" :rules="[{ required: true, message: '请输入税率', trigger: 'blur' }]">
          <el-input-number
            onmousewheel="return false;"
            v-model="details.data.taxRate"
            placeholder="请输入税率"
            style="width: 100%"
            :controls="false"
            :min="0"
            :precision="2"
            :max="100" />
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="openChangeTaxRate = false" size="large">取 消</el-button>
        <el-button type="primary" @click="submitChangeTaxRate()" size="large" v-preReClick>确 定</el-button>
      </template>
    </el-dialog>

    <el-dialog title="售后类型" v-if="openAfterSale" v-model="openAfterSale" width="300px" style="margin-top: 20vh !important">
      <template #footer>
        <el-button type="primary" @click="applyForAfterSale(1)" size="large" v-preReClick>退 货</el-button>
        <el-button @click="applyForAfterSale(2)" size="large" v-preReClick>换 货</el-button>
      </template>
    </el-dialog>

    <el-dialog title="送货单" v-if="openDeliveryNote" v-model="openDeliveryNote" width="1000px">
      <DeliveryNote :rowData="rowData" @clickCancel="clickCancel"></DeliveryNote>
    </el-dialog>

    <el-dialog title="删除并退料入库" v-if="openDelete" v-model="openDelete" width="1000px">
      <div v-loading="loadingDelete">
        <el-table :data="deleteList" :row-style="{ height: '35px' }" header-row-class-name="tableHeader">
          <el-table-column label="BOM品号" prop="bomSpecCode" width="140" />
          <el-table-column label="BOM品名" prop="bomSpecName" min-width="220" />
          <el-table-column label="仓库名称" prop="warehouseName" width="100" />
          <el-table-column label="出库数量" prop="outQuantity" width="100" />
        </el-table>
      </div>
      <template #footer>
        <el-button @click="openDelete = false" size="large" v-preReClick>取 消</el-button>
        <el-button type="primary" @click="submitDelete()" size="large" v-preReClick>确认删除</el-button>
      </template>
    </el-dialog>

    <el-dialog title="产品包装配置" v-if="openShippingPackage" v-model="openShippingPackage" width="80%" :close-on-press-escape="false" :show-close="false">
      <div style="height: calc(100vh - 184px); overflow-y: auto; overflow-x: hidden" v-loading="loadingPackage">
        <el-form :model="formData.data" :rules="rulesShippingPackage" ref="shippingPackage">
          <div style="font-weight: 700; margin: 20px 0 10px 0">发货包装</div>
          <div style="margin-bottom: 10px">
            <el-button type="primary" size="small" @click="clickExpressPacking()">选择快递物流包材</el-button>
          </div>
          <el-table :data="formData.data.orderPackageBomList" :row-style="{ height: '35px' }" header-row-class-name="tableHeader">
            <el-table-column label="品号" prop="code" width="160" />
            <el-table-column label="品名" prop="name" min-width="220" />
            <el-table-column label="销售单价" prop="internalSellingPrice" width="100" />
            <el-table-column label="数量" width="120">
              <template #default="{ row, $index }">
                <div class="shippingPackage">
                  <el-form-item
                    :prop="'orderPackageBomList.' + $index + '.quantity'"
                    :rules="rulesShippingPackage.quantity"
                    :inline-message="true"
                    style="width: 100%">
                    <el-input-number
                      onmousewheel="return false;"
                      v-model="row.quantity"
                      placeholder="修正数量"
                      style="width: 100%"
                      :controls="false"
                      :min="0"
                      :precision="0" />
                  </el-form-item>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="销售小计" width="120">
              <template #default="{ row }">
                {{ moneyFormat(computePackagingMoney(row, "internalSellingPrice"), 2) }}
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" fixed="right" width="80">
              <template #default="{ $index }">
                <el-button type="danger" @click="clickPackagingDelete($index)" text>删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div style="font-weight: 700; margin: 20px 0 10px 0">外箱不干胶图稿</div>
          <div style="display: flex; width: 100%">
            <div style="width: 80px; line-height: 32px">不干胶图片:</div>
            <div style="width: calc(100% - 80px)">
              <el-image
                fit="scale-down"
                style="width: 148px; height: 148px; margin-right: 10px; cursor: pointer"
                v-if="formData.data.outerBoxSelfAdhesiveStickerFile && formData.data.outerBoxSelfAdhesiveStickerFile.fileUrl"
                :src="formData.data.outerBoxSelfAdhesiveStickerFile.fileUrl"
                @click="openFile(formData.data.outerBoxSelfAdhesiveStickerFile.fileUrl)" />
              <div style="display: flex">
                <el-upload
                  :show-file-list="false"
                  action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
                  :data="uploadAdhesiveData"
                  :before-upload="uploadAdhesiveFile"
                  :on-success="
                    (response, uploadFile) => {
                      return handleAdhesivePackagingSuccess(uploadFile);
                    }
                  "
                  style="width: 100%">
                  <el-button type="primary" text>上传文件</el-button>
                </el-upload>
              </div>
            </div>
          </div>
        </el-form>
      </div>
      <template #footer>
        <el-button @click="openShippingPackage = false" v-preReClick>取 消</el-button>
        <el-button type="primary" @click="clickSaveShippingPackage" v-preReClick>提 交</el-button>
      </template>
    </el-dialog>

    <el-dialog title="选择快递包装" v-if="openExpressPacking" v-model="openExpressPacking" width="90%">
      <SelectBOM :selectStatus="true" :expressStatus="true" @selectBOM="selectExpressPacking"></SelectBOM>
      <template #footer>
        <el-button @click="openExpressPacking = false">关 闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import byTable from "/src/components/byTable/index";
import { ElMessage, ElMessageBox } from "element-plus";
import { copyText } from "vue3-clipboard";
import { flowStatus } from "/src/utils/flowStatus";
import DeliveryNote from "/src/components/order/deliveryNote/index";
import SelectBOM from "/src/views/group/BOM/management/index";

const { proxy } = getCurrentInstance();
const props = defineProps({
  selectStatus: Boolean,
  departmentId: String,
});
const departmentList = ref([{ dictKey: "0", dictValue: "胜德体育" }]);
const sourceList = ref({
  data: [],
  pagination: {
    total: 0,
    pageNum: 1,
    pageSize: 10,
    departmentId: "",
    code: "",
    wlnCode: "",
    status: "",
    settlementStatus: "",
    exception: "0",
  },
});
const loading = ref(false);
const searchConfig = computed(() => {
  return [
    {
      type: "input",
      prop: "code",
      label: "订单号",
    },
    {
      type: "input",
      prop: "wlnCode",
      label: "E10单号",
    },
    props.departmentId
      ? {}
      : {
          type: "select",
          prop: "departmentId",
          data: departmentList.value,
          label: "事业部",
        },
    props.departmentId
      ? {}
      : {
          type: "select",
          prop: "status",
          dictKey: "order_status",
          label: "订单状态",
        },
    {
      type: "select",
      prop: "settlementStatus",
      label: "结算状态",
      data: proxy.useUserStore().allDict["settlement_status"],
    },
  ];
});
const config = computed(() => {
  return [
    {
      attrs: {
        label: "事业部",
        prop: "departmentName",
        width: 120,
      },
    },
    {
      attrs: {
        label: "订单号",
        slot: "code",
        width: 200,
      },
    },
    {
      attrs: {
        label: "E10单号",
        prop: "wlnCode",
        width: 160,
      },
    },
    {
      attrs: {
        label: "快递单号",
        prop: "expressDeliveryCode",
        width: 140,
      },
    },
    {
      attrs: {
        label: "流程状态",
        prop: "flowStatus",
        width: 120,
      },
      render(val) {
        return proxy.dictKeyValue(val, flowStatus());
      },
    },
    {
      attrs: {
        label: "订单状态",
        prop: "status",
        width: 120,
      },
      render(val, row) {
        if (val == 0 && row.flowStatus !== 2) {
          return "";
        }
        return proxy.dictKeyValue(val, proxy.useUserStore().allDict["order_status"]);
      },
    },
    {
      attrs: {
        label: "结算状态",
        prop: "settlementStatus",
        width: 120,
      },
      render(val) {
        return proxy.dictKeyValue(val, proxy.useUserStore().allDict["settlement_status"]);
      },
    },
    {
      attrs: {
        label: "税率",
        prop: "taxRate",
        width: 80,
      },
      render(val) {
        return val + "%";
      },
    },
    {
      attrs: {
        label: "订单总金额 ¥",
        slot: "totalAmount",
        width: 120,
        align: "right",
      },
    },
    {
      attrs: {
        label: "产品总金额 ¥",
        prop: "productTotalAmount",
        width: 120,
        align: "right",
      },
      render(val) {
        return proxy.moneyFormat(val);
      },
    },
    {
      attrs: {
        label: "定制加工费 ¥",
        prop: "customProcessingFee",
        width: 120,
        align: "right",
      },
      render(val) {
        return proxy.moneyFormat(val);
      },
    },
    {
      attrs: {
        label: "代发费 ¥",
        prop: "lssueFee",
        width: 120,
        align: "right",
      },
      render(val) {
        return proxy.moneyFormat(val);
      },
    },
    {
      attrs: {
        label: "快递包材费 ¥",
        prop: "deliveryMaterialsFee",
        width: 120,
        align: "right",
      },
      render(val) {
        return proxy.moneyFormat(val);
      },
    },
    {
      attrs: {
        label: "包装人工费 ¥",
        prop: "packingLabor",
        width: 120,
        align: "right",
      },
      render(val) {
        return proxy.moneyFormat(val);
      },
    },
    {
      attrs: {
        label: "包材费 ¥",
        prop: "packagingMaterialCost",
        width: 120,
        align: "right",
      },
      render(val) {
        return proxy.moneyFormat(val);
      },
    },
    {
      attrs: {
        label: "管理费 ¥",
        prop: "managementFee",
        width: 120,
        align: "right",
      },
      render(val) {
        return proxy.moneyFormat(val);
      },
    },
    {
      attrs: {
        label: "外箱包装费 ¥",
        prop: "outerBoxPackingFee",
        width: 120,
        align: "right",
      },
      render(val) {
        return proxy.moneyFormat(val);
      },
    },
    {
      attrs: {
        label: "交期",
        prop: "deliveryTime",
        width: 160,
        align: "center",
      },
    },
    {
      attrs: {
        label: "发货时间",
        prop: "shippingTime",
        width: 160,
        align: "center",
      },
    },
    {
      attrs: {
        label: "收货人",
        prop: "consignee",
        width: 140,
      },
    },
    {
      attrs: {
        label: "收货人电话",
        prop: "consigneeNumber",
        width: 140,
      },
    },
    {
      attrs: {
        label: "收货人地址",
        slot: "address",
        width: 400,
      },
    },
    {
      attrs: {
        label: "操作",
        width: 240,
        align: "center",
        fixed: "right",
      },
      renderHTML(row) {
        return [
          props.selectStatus
            ? {
                attrs: {
                  label: "选择",
                  type: "primary",
                  text: true,
                },
                el: "button",
                click() {
                  clickSelect(row);
                },
              }
            : [40, 50].includes(row.status)
            ? {
                attrs: {
                  label: "售后",
                  type: "primary",
                  text: true,
                },
                el: "button",
                click() {
                  clickAfterSale(row);
                },
              }
            : {},
          !props.selectStatus && row.type === 1 && row.status == 40
            ? {
                attrs: {
                  label: "送货单",
                  type: "primary",
                  text: true,
                },
                el: "button",
                click() {
                  clickDeliveryNote(row);
                },
              }
            : {},
          !props.selectStatus && row.status == 20
            ? {
                attrs: {
                  label: "挂起",
                  type: "primary",
                  text: true,
                },
                el: "button",
                click() {
                  clickHangUp(row);
                },
              }
            : {},
          !props.selectStatus && row.status == 60
            ? {
                attrs: {
                  label: "取消挂起",
                  type: "primary",
                  text: true,
                },
                el: "button",
                click() {
                  clickCancelHangUp(row);
                },
              }
            : {},
          !props.selectStatus && row.status && row.status != 0
            ? {
                attrs: {
                  label: "税率",
                  type: "primary",
                  text: true,
                },
                el: "button",
                click() {
                  clickChangeTaxRate(row);
                },
              }
            : {},
          !props.selectStatus && [0, 10, 20].includes(row.status) && proxy.useUserStore().user.userId === "1"
            ? {
                attrs: {
                  label: "删除",
                  type: "danger",
                  text: true,
                },
                el: "button",
                click() {
                  clickDelete(row);
                },
              }
            : {},
          !props.selectStatus && [30, 40].includes(row.status) && proxy.useUserStore().user.userId === "1"
            ? {
                attrs: {
                  label: "删除",
                  type: "danger",
                  text: true,
                },
                el: "button",
                click() {
                  clickDeleteTwo(row);
                },
              }
            : {},
          {
            attrs: {
              label: "修改包装配置",
              type: "primary",
              text: true,
            },
            el: "button",
            click() {
              clickChangePackaging(row);
            },
          },
        ];
      },
    },
  ];
});
const getDemandData = () => {
  proxy.post("/department/page", { pageNum: 1, pageSize: 999 }).then((res) => {
    if (res.rows && res.rows.length > 0) {
      departmentList.value = departmentList.value.concat(
        res.rows.map((item) => {
          return {
            dictKey: item.id,
            dictValue: item.name,
          };
        })
      );
    }
  });
};
getDemandData();
const getList = async (req, status) => {
  if (status) {
    sourceList.value.pagination = {
      pageNum: sourceList.value.pagination.pageNum,
      pageSize: sourceList.value.pagination.pageSize,
      exception: "0",
    };
  } else {
    sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  }
  if (props.selectStatus) {
    sourceList.value.pagination.linkedStatementOfAccount = 0;
  }
  if (props.departmentId) {
    sourceList.value.pagination.departmentId = props.departmentId;
  }
  loading.value = true;
  proxy.post("/orderInfo/page", sourceList.value.pagination).then((res) => {
    sourceList.value.data = res.rows;
    sourceList.value.pagination.total = res.total;
    setTimeout(() => {
      loading.value = false;
    }, 200);
  });
};
getList();
const clickReset = () => {
  getList("", true);
};
const clickCode = (row) => {
  proxy.$router.replace({
    path: "/platform_manage/process/processApproval",
    query: {
      flowKey: "order",
      flowName: "订单详情",
      processType: "20",
      id: row.id,
      flowId: row.flowId,
      random: proxy.random(),
    },
  });
};
const clickDelete = (row) => {
  ElMessageBox.confirm("你是否确认此操作", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      proxy.post("/orderInfo/delete", { id: row.id }).then(() => {
        ElMessage({ message: "删除成功", type: "success" });
        getList();
      });
    })
    .catch(() => {});
};
const openDelete = ref(false);
const loadingDelete = ref(false);
const deleteList = ref([]);
const deleteRow = ref({});
const clickDeleteTwo = (row) => {
  deleteList.value = [];
  loadingDelete.value = true;
  openDelete.value = true;
  deleteRow.value = row;
  proxy.post("/orderInfo/returnBomList", { id: row.id }).then((res) => {
    deleteList.value = res;
    loadingDelete.value = false;
  });
};
const submitDelete = () => {
  ElMessageBox.confirm("你是否确认此操作", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      proxy.post("/orderInfo/deleteAndStore", { id: deleteRow.value.id }).then(() => {
        ElMessage({ message: "删除成功", type: "success" });
        openDelete.value = false;
        getList();
      });
    })
    .catch(() => {});
};
const clickHangUp = (row) => {
  ElMessageBox.confirm("你是否确认此操作", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      proxy.post("/orderInfo/suspendOrder", { id: row.id }).then(() => {
        ElMessage({ message: "操作成功", type: "success" });
        getList();
      });
    })
    .catch(() => {});
};
const clickCancelHangUp = (row) => {
  ElMessageBox.confirm("你是否确认此操作", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      proxy.post("/orderInfo/cancelSuspendOrder", { id: row.id }).then(() => {
        ElMessage({ message: "操作成功", type: "success" });
        getList();
      });
    })
    .catch(() => {});
};
const openLogs = ref(false);
const loadingLogs = ref(false);
const logsList = ref({
  data: [],
  pagination: {
    total: 0,
    pageNum: 1,
    pageSize: 10,
  },
});
const type = ref([
  { dictKey: "10", dictValue: "新增订单" },
  { dictKey: "20", dictValue: "图稿上传" },
  { dictKey: "21", dictValue: "修改税率" },
  { dictKey: "30", dictValue: "删除订单" },
]);
const configLogs = computed(() => {
  return [
    {
      attrs: {
        label: "操作时间",
        prop: "createTime",
        width: 160,
        align: "center",
      },
    },
    {
      attrs: {
        label: "操作人",
        prop: "userName",
        align: "center",
      },
    },
    {
      attrs: {
        label: "订单号",
        prop: "orderCode",
        align: "center",
      },
    },
    {
      attrs: {
        label: "行为",
        prop: "type",
        width: 100,
        align: "center",
      },
      render(val) {
        return proxy.dictKeyValue(val, type.value);
      },
    },
  ];
});
const viewLogs = () => {
  logsList.value.data = [];
  logsList.value.pagination.total = 0;
  openLogs.value = true;
  getLogsList({ pageNum: 1, pageSize: 10 });
};
const getLogsList = async (req) => {
  logsList.value.pagination = { ...logsList.value.pagination, ...req };
  loadingLogs.value = true;
  proxy.post("/orderOperatingLog/page", logsList.value.pagination).then((res) => {
    logsList.value.data = res.rows;
    logsList.value.pagination.total = res.total;
    setTimeout(() => {
      loadingLogs.value = false;
    }, 200);
  });
};
const details = reactive({
  data: {},
});
const openChangeTaxRate = ref(false);
const clickChangeTaxRate = (item) => {
  proxy.post("/orderInfo/detail", { id: item.id }).then((res) => {
    details.data = res;
    openChangeTaxRate.value = true;
  });
};
const submitChangeTaxRate = () => {
  proxy.$refs.taxRate.validate((valid) => {
    if (valid) {
      details.data.updateType = "21";
      proxy.post("/orderInfo/edit", details.data).then(() => {
        ElMessage({ message: "修改完成", type: "success" });
        openChangeTaxRate.value = false;
        getList();
      });
    }
  });
};
const emit = defineEmits(["selectOrder"]);
const clickSelect = (item) => {
  emit("selectOrder", item);
};
const clickCopyWLNCode = () => {
  ElMessage("复制数据中,请稍后");
  proxy.post("/orderInfo/getOrderWlnCodeStr", sourceList.value.pagination).then((res) => {
    copyText(res, undefined, (error) => {
      if (error) {
        ElMessage.error(`复制失败: ${error} ！`);
      } else {
        ElMessage.success(`复制成功！`);
      }
    });
  });
};
const btnLoading = ref(false);
const clickSynchronousOrder = () => {
  btnLoading.value = true;
  proxy.post("/orderHandle/bathSyncOrder", {}).then(
    () => {
      ElMessage.success("同步完成成功");
      btnLoading.value = false;
      getList();
    },
    (err) => {
      ElMessage.error(`同步失败: ${err} ！`);
      btnLoading.value = false;
    }
  );
};
const openAfterSale = ref(false);
const rowData = ref({});
const clickAfterSale = (row) => {
  rowData.value = row;
  openAfterSale.value = true;
};
const applyForAfterSale = (type) => {
  openAfterSale.value = false;
  proxy.$router.replace({
    path: "/order/after-sale/initiate",
    query: {
      orderInfoId: rowData.value.id,
      type: type,
      random: proxy.random(),
    },
  });
};
const openDeliveryNote = ref(false);
const clickDeliveryNote = (row) => {
  rowData.value = row;
  openDeliveryNote.value = true;
};
const clickCancel = (status) => {
  openDeliveryNote.value = false;
  if (status) {
    getList();
  }
};
const formData = reactive({
  data: {
    orderPackageBomList: [],
    outerBoxSelfAdhesiveStickerFile: {},
  },
});
const rulesShippingPackage = ref({
  quantity: [{ required: true, message: "请输入数量", trigger: "blur" }],
});
const openShippingPackage = ref(false);
const loadingPackage = ref(false);
const clickChangePackaging = (row) => {
  loadingPackage.value = true;
  openShippingPackage.value = true;
  proxy.post("/orderInfo/detail", { id: row.id }).then(
    (res) => {
      formData.data = res;
      proxy.post("/fileInfo/getList", { businessIdList: [formData.data.id] }).then((fileObj) => {
        if (fileObj[formData.data.id] && fileObj[formData.data.id].length > 0) {
          let outerBoxSelfAdhesiveStickerFile = fileObj[formData.data.id].filter((item) => item.businessType == "1");
          if (outerBoxSelfAdhesiveStickerFile && outerBoxSelfAdhesiveStickerFile.length > 0) {
            formData.data.outerBoxSelfAdhesiveStickerFile = outerBoxSelfAdhesiveStickerFile[0];
          } else {
            formData.data.outerBoxSelfAdhesiveStickerFile = {};
          }
        }
      });
      loadingPackage.value = false;
    },
    (err) => {
      console.log(err);
      loadingPackage.value = false;
    }
  );
};
const computePackagingMoney = (item, label) => {
  let money = 0;
  if (item.quantity && item[label]) {
    money = Number(Math.round(item.quantity * item[label] * 100) / 100);
  }
  return money;
};
const clickPackagingDelete = (index) => {
  formData.data.orderPackageBomList.splice(index, 1);
};
const openFile = (path) => {
  window.open(path);
};
const uploadAdhesiveData = ref({});
const uploadAdhesiveFile = async (file) => {
  const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
  uploadAdhesiveData.value = res.uploadBody;
  file.id = res.id;
  file.fileName = res.fileName;
  file.fileUrl = res.fileUrl;
  return true;
};
const handleAdhesivePackagingSuccess = (UploadFile) => {
  formData.data.outerBoxSelfAdhesiveStickerFile = {
    id: UploadFile.raw.id,
    fileName: UploadFile.raw.fileName,
    fileUrl: UploadFile.raw.fileUrl,
  };
};
const clickSaveShippingPackage = () => {
  proxy.$refs.shippingPackage.validate((valid) => {
    if (valid) {
      loadingPackage.value = true;
      if (formData.data.orderPackageBomList && formData.data.orderPackageBomList.length > 0) {
        proxy
          .post("/orderInfo/editOrderPackageBom", {
            id: formData.data.id,
            orderPackageBomList: formData.data.orderPackageBomList,
            outerBoxSelfAdhesiveStickerFile: formData.data.outerBoxSelfAdhesiveStickerFile,
          })
          .then(
            () => {
              ElMessage({ message: "提交成功", type: "success" });
              openShippingPackage.value = false;
              getList();
            },
            (err) => {
              console.log(err);
              loadingPackage.value = false;
            }
          );
      } else {
        ElMessageBox.confirm("是否确认无产品发货包装", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            proxy
              .post("/orderInfo/editOrderPackageBom", {
                id: formData.data.id,
                orderPackageBomList: formData.data.orderPackageBomList,
                outerBoxSelfAdhesiveStickerFile: formData.data.outerBoxSelfAdhesiveStickerFile,
              })
              .then(
                () => {
                  ElMessage({ message: "提交成功", type: "success" });
                  openShippingPackage.value = false;
                  getList();
                },
                (err) => {
                  console.log(err);
                  loadingPackage.value = false;
                }
              );
          })
          .catch(() => {});
      }
    }
  });
};
const openExpressPacking = ref(false);
const clickExpressPacking = () => {
  openExpressPacking.value = true;
};
const selectExpressPacking = (data) => {
  if (formData.data.orderPackageBomList && formData.data.orderPackageBomList.length > 0) {
    let list = formData.data.orderPackageBomList.filter((item) => item.bomSpecId === data.id);
    if (list && list.length > 0) {
      return ElMessage("快递物流包材已添加");
    }
    formData.data.orderPackageBomList.push({
      bomSpecId: data.id,
      code: data.code,
      name: data.name,
      internalSellingPrice: data.internalSellingPrice,
      quantity: undefined,
    });
  } else {
    formData.data.orderPackageBomList = [
      {
        bomSpecId: data.id,
        code: data.code,
        name: data.name,
        internalSellingPrice: data.internalSellingPrice,
        quantity: undefined,
      },
    ];
  }
  ElMessage({ message: "添加成功", type: "success" });
};
</script>

<style lang="scss" scoped>
::v-deep(.el-input-number .el-input__inner) {
  text-align: left;
}
:deep(.el-dialog) {
  margin-top: 10px !important;
  margin-bottom: 10px !important;
}
.select-card {
  height: calc(100vh - 184px);
  overflow-y: auto;
  overflow-x: hidden;
}
.shippingPackage {
  .el-form-item {
    margin-bottom: 0;
  }
}
</style>
