<template>
  <div class="page-refund-order-info">
    <div class="new-page-title">
      <div class="line" />
      <div class="text">
        {{ $t('order.order.refundProcessing') }}
      </div>
    </div>
    <div
      v-if="platInterveneSts===1 && stillAveTime"
      class="plat-intervene"
    >
      <el-icon :size="14">
        <WarningFilled />
      </el-icon>
      <span>用户申请平台介入售后，请在{{ dataForm.interventionEndTime }}前补充凭证</span>
    </div>
    <div class="order-refund-info">
      <!-- 退单编号 -->
      <div class="refundId">
        <span class="title">{{ $t('order.order.refundId') }}:</span>
        <span class="text">{{ dataForm.refundId }}</span>
      </div>
      <div class="content">
        <div class="order-number">
          <div class="num-cont">
            <div class="state-title">
              <!-- 退款类型 -->
              <div class="item">
                <div class="title">
                  {{ $t('order.order.refundType') }}：
                </div>
                <div class="text">
                  <div v-if="dataForm.refundType === 1">
                    {{ $t("order.order.wholeOrderRefund") }}
                  </div>
                  <div v-if="dataForm.refundType === 2">
                    {{ $t("order.order.singleItemRefund") }}
                  </div>
                </div>
              </div>
              <!-- 退款方式 -->
              <div class="item">
                <div class="title">
                  {{ $t('order.order.refundMethod') }}：
                </div>
                <div class="text">
                  <div v-if="dataForm.applyType === 1">
                    {{ $t("order.order.onlyRefund") }}
                  </div>
                  <div v-if="dataForm.applyType === 2">
                    {{ $t("order.order.refundAndMoney") }}
                  </div>
                </div>
              </div>
              <div
                v-if="dataForm.decisionTime && !dataForm.refundTime"
                class="item"
              >
                <div>
                  {{ $t('order.order.wait') }}{{ dataForm.payType === 1 || dataForm.payType === 3 || dataForm.payType === 4 || dataForm.payType === 5 || dataForm.payType === 8 ? $t('order.order.weixin') : $t('order.order.alipay') }}{{ $t('order.order.refund') }}
                </div>
              </div>
            </div>
            <div class="refund-progress">
              <refund-steps :refund-detail="dataForm" />
            </div>
          </div>
        </div>
        <div class="order-state">
          <div class="state-cont">
            <div class="order-info">
              <div class="order-details refund-record-left">
                <div class="detail-title">
                  <span class="prompt">{{ $t("order.order.refundDetails") }}</span>
                </div>
                <div class="detail-cont">
                  <div class="detail01">
                    <div class="text-width">
                      <div class="text-width-item">
                        <span class="title">{{ $t('order.order.number') }}：</span>
                        <span class="text">{{ dataForm.orderId }}</span>
                      </div>
                      <div
                        v-if="dataForm.actualTotal"
                        class="text-width-item"
                      >
                        <span class="title">{{ $t('order.order.orderActuallyPaid') }}：</span>
                        <span
                          v-if="dataForm.actualTotal"
                          class="text"
                        >
                          {{ onHandlerPrice(dataForm.actualTotal) }}
                          {{ $t("constant.dollar") }}
                        </span>
                        <span
                          v-if="dataForm.actualTotal && dataForm.orderScore"
                          class="text"
                        >+
                        </span>
                        <span
                          v-if="dataForm.orderScore"
                          class="text"
                        >{{ dataForm.orderScore
                        }}{{ $t("order.order.integral") }}</span>
                      </div>
                      <div class="text-width-item">
                        <span class="title">{{ $t('order.order.refundAmount') }}：</span>
                        <span
                          v-if="dataForm.refundAmount"
                          class="text"
                        >{{ onHandlerPrice(dataForm.refundAmount)
                        }}{{ $t("constant.dollar") }}</span>
                        <span
                          v-if="dataForm.refundAmount && dataForm.refundScore"
                          class="text"
                        >+
                        </span>
                        <span
                          v-if="dataForm.refundScore"
                          class="text"
                        >{{ dataForm.refundScore
                        }}{{ $t("order.order.integral") }}</span>
                      </div>
                      <div class="text-width-item">
                        <span class="title">{{ $t('order.order.applicationTime') }}：</span>
                        <span class="text">{{ dataForm.createTime }}</span>
                      </div>
                      <div class="text-width-item">
                        <span class="title">{{ $t('order.order.reasonForReturn') }}：</span>
                        <span class="text">{{ dataForm.buyerReasonValue }}</span>
                      </div>
                      <div class="text-width-item">
                        <span class="title">{{ $t('order.order.refundInstructions') }}：</span>
                        <span class="text">{{ dataForm.buyerDesc }}</span>
                      </div>
                      <div
                        v-if="dataForm.buyerMobile"
                        class="text-width-item"
                      >
                        <span class="title">手机号码：</span>
                        <span>{{ dataForm.buyerMobile }}</span>
                      </div>
                      <div class="text-width-item">
                        <span class="title">{{ $t('order.order.refundCertificate') }}：</span>
                        <div v-if="imgList.length">
                          <el-image
                            v-for="(picItem,picInx) in imgList"
                            :key="picInx"
                            :src="addDomain(picItem)"
                            class="img-box"
                            :preview-src-list="addDomain(imgList)"
                          >
                            <template #error>
                              <img
                                class="img-slot"
                                src="~@/assets/images/def.png"
                              >
                            </template>
                          </el-image>
                        </div>
                        <div v-else>
                          无
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <!-- 退款凭证 -->
              <div class="buyers">
                <div class="refund-record-title detail-title">
                  <span>退款记录</span>
                  <span
                    v-if="platInterveneSts===1 && stillAveTime"
                    class="proof-btn"
                    @click="onAddProof"
                  >
                    <el-icon :size="16">
                      <Memo />
                    </el-icon>
                    <span class="txt">补充凭证</span>
                  </span>
                </div>
                <div class="refund-record">
                  <refundRecord :refund-detail="dataForm" />
                </div>
              </div>
            </div>
            <div
              v-if="dataForm.orderRefundAddr && dataForm.orderRefundAddr.deliveryName"
              class="order-info"
            >
              <div class="order-details">
                <div class="detail-title">
                  <span class="prompt">{{ $t("order.order.logisticsDetails") }}</span>
                </div>
                <div class="detail-cont">
                  <div class="detail01">
                    <div class="text-width">
                      <div class="text-width-item">
                        <span class="title">{{ $t('order.order.logisticsName') }}：</span>
                        <span class="text">{{ dataForm.orderRefundAddr.deliveryName }}</span>
                      </div>
                      <div
                        v-if="dataForm.orderRefundAddr?.deliveryNo"
                        class="text-width-item"
                      >
                        <span class="title">{{ $t('order.order.trackingNumber') }}：</span>
                        <span class="text">{{ dataForm.orderRefundAddr.deliveryNo }}</span>
                      </div>
                      <div
                        v-if="dataForm.orderRefundAddr?.senderRemarks"
                        class="text-width-item"
                      >
                        <span class="title">{{ $t('order.order.compradorMsg') }}：</span>
                        <span class="text">{{ dataForm.orderRefundAddr.senderRemarks }}</span>
                      </div>
                      <div
                        v-if="dataForm.orderRefundAddr?.senderMobile"
                        class="text-width-item"
                      >
                        <span class="title">{{ $t('order.order.buyerPhone') }}：</span>
                        <span>{{ dataForm.orderRefundAddr.senderMobile }}</span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="buyers">
                <div class="detail-title">
                  <!-- 物流凭证 -->
                  <span>{{ $t('order.order.logisticsCertificate') }}</span>
                </div>
                <div class="buyers-info">
                  <div v-if="orderRefundAddrPhotos.length">
                    <el-image
                      v-for="(imgItem,imgInx) in orderRefundAddrPhotos"
                      :key="imgInx"
                      :src="addDomain(imgItem)"
                      class="img-box"
                      :preview-src-list="addDomain(orderRefundAddrPhotos)"
                    >
                      <template #error>
                        <img
                          class="img-slot"
                          src="~@/assets/images/def.png"
                        >
                      </template>
                    </el-image>
                  </div>
                  <div v-else>
                    无
                  </div>
                </div>
              </div>
            </div>
            <div class="item-list">
              <el-table
                :data="dataForm.orderItems"
                header-cell-class-name="table-header"
                row-class-name="table-row"
                :row-style="{ height:'82px'}"
              >
                <el-table-column
                  :label="$t('order.order.refundGoods')"
                  width="400"
                >
                  <template #default="scope">
                    <div class="prod-info">
                      <ImgShow
                        :src="scope.row.supplierPic"
                        :img-style="{width:'100px',height:'100px'}"
                      />
                      <div class="con">
                        <span>{{ scope.row.supplierSpuName }}</span>
                        <span class="sku">{{ scope.row.supplierSkuName || '' }}</span>
                      </div>
                    </div>

                    <!-- 组合 -->
                    <div
                      v-if="scope.row.comboList"
                      class="gift-prod"
                    >
                      <div
                        v-for="(item,index) in scope.row.comboList"
                        :key="index"
                        class="item"
                      >
                        <span class="giveaway-item-name">【组合】{{ item.spuName }}</span>
                        <span class="giveaway-item-sku-count">{{ item.skuName }} ×{{ item.count }}</span>
                      </div>
                    </div>
                    <!-- / 组合 -->
                  </template>
                </el-table-column>
                <el-table-column
                  prop="price"
                  :label="$t('order.order.unitPrice')"
                >
                  <template #default="scope">
                    <span>{{ onHandlerPrice(scope.row.price) }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="count"
                  :label="$t('order.order.quantity')"
                >
                  <template #default="scope">
                    <span v-if="dataForm.refundType === 1">{{
                      scope.row.count
                    }}</span>
                    <span v-if="dataForm.refundType === 2">{{
                      dataForm.refundCount
                    }}</span>
                  </template>
                </el-table-column>
                <el-table-column :label="$t('order.order.prodTotalPrice')">
                  <template #default="scope">
                    <span v-if="dataForm.refundType === 1">{{
                      onHandlerPrice(scope.row.spuTotalAmount)
                    }}</span>

                    <span v-if="dataForm.refundType === 2">{{
                      onBigSpuTotalAmount(scope.row.price, dataForm.refundCount)
                    }}</span>
                  </template>
                </el-table-column>

                <el-table-column
                  prop="actualTotal"
                  :label="$t('order.order.actualAmount')"
                >
                  <template #default="scope">
                    <span v-if="dataForm.refundType === 1">{{
                      onHandlerPrice(scope.row.actualTotal)
                    }}</span>
                    <span v-if="dataForm.refundType === 2">{{
                      onBigActualTotal(scope.row.actualTotal, scope.row.count)
                    }}</span>
                    <el-tag
                      v-if="scope.row.shareReduce > 0"
                      type="danger"
                      effect="dark"
                    >
                      {{ $t("order.order.discount") }}
                    </el-tag>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="actualTotal"
                  :label="$t('order.order.refundPlatformDiscountAmount')"
                  align="center"
                >
                  <template #default="scope">
                    <span>{{
                      onHandlerPrice(dataForm.refundType === 1 ? scope.row.platformShareReduce : dataForm.platformRefundAmount)
                    }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  :key="dataForm.refundAmount"
                  :label="$t('order.order.returnAmount')"
                >
                  <template #default="scope">
                    <span
                      v-if="dataForm.refundAmount"
                      class="totalprice"
                    >{{ onHandlerPrice((dataForm.refundType === 1 ? scope.row.actualTotal : dataForm.refundAmount))
                    }}{{ $t("constant.dollar") }}</span>
                    <span
                      v-if="dataForm.refundAmount && dataForm.refundScore"
                      class="totalprice"
                    >+
                    </span>
                    <span
                      v-if="dataForm.refundScore"
                      class="totalprice"
                    >{{ dataForm.refundType === 1 ? scope.row.refundScore : dataForm.refundScore }}{{ $t("order.order.integral") }}</span>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <!-- 申请审批 -->
            <div
              v-if="dataForm.returnMoneySts === 1"
              class="sellerRemark"
            >
              <div class="remark-title">
                {{ $t("order.order.applyForApproval") }}：
              </div>
              <div class="remark-content">
                <el-radio-group v-model="isAgreeRefund">
                  <el-radio :label="2">
                    {{
                      dataForm.applyType === 1
                        ? $t("order.order.agreeToRefundA")
                        : $t("order.order.agree")
                    }}
                  </el-radio>
                  <el-radio :label="3">
                    {{
                      $t("order.order.disagree")
                    }}
                  </el-radio>
                </el-radio-group>
              </div>
            </div>

            <div
              v-if="dataForm.applyType === 2"
              class="sellerRemark"
            >
              <div
                v-if="dataForm.orderRefundAddr || (dataForm.returnMoneySts === 1 && isAgreeRefund === 2)"
                class="remark-title"
              >
                {{ $t("constant.deliveryAddr") }}：
              </div>
              <div
                v-if="dataForm.returnMoneySts === 1 && isAgreeRefund === 2"
                class="remark-content"
              >
                <el-select
                  v-model="dataForm.supplierRefundAddrId"
                  :placeholder="$t('tip.select')"
                  style="width:100%;max-width: 350px"
                >
                  <el-option
                    v-for="item in addrList"
                    :key="item.supplierRefundAddrId"
                    :label="
                      item.consignee+'，'+item.mobile+'，'+item.province + item.city + item.area + item.addr
                    "
                    :value="item.supplierRefundAddrId"
                  />
                </el-select>
                <!--新建/刷新-->
                <el-button
                  type="primary"
                  link
                  style="margin-left:5px"
                  @click="onRefreshChange"
                >
                  {{ $t('admin.refresh') }}
                </el-button>
                <el-divider direction="vertical" />
                <el-button
                  type="primary"
                  link
                  @click.stop="onAddOrUpdate()"
                >
                  {{ $t('admin.newConstruction') }}
                </el-button>
              </div>
              <div
                v-if="dataForm.orderRefundAddr"
                class="remark-content"
              >
                {{ dataForm.orderRefundAddr.consigneeName+'，'+dataForm.orderRefundAddr.consigneeMobile+'，'+dataForm.orderRefundAddr.consigneeAddr }}
              </div>
            </div>

            <div
              v-if="dataForm.deliveryTime &&
                !dataForm.cancelTime &&
                !dataForm.rejectTime"
              class="sellerRemark"
            >
              <div class="remark-title">
                {{ $t("order.order.returnStatus") }}：
              </div>
              <div class="remark-content">
                <el-radio-group
                  v-model="isReceived"
                  :disabled="dataForm.returnMoneySts !== 3"
                >
                  <el-radio :label="1">
                    {{ $t("order.order.received") }}
                  </el-radio>
                  <el-radio :label="0">
                    {{ $t("order.order.unreceived") }}
                  </el-radio>
                </el-radio-group>
              </div>
            </div>
            <!-- 退货申请应该只有在买家发货时展示 -->
            <div
              v-if="dataForm.returnMoneySts === 3"
              class="sellerRemark"
            >
              <div class="remark-title">
                {{ $t("order.order.returnRequest") }}：
              </div>
              <div class="remark-content">
                <el-radio-group
                  v-model="isAgreeRefund"
                  :disabled="dataForm.returnMoneySts !== 3"
                >
                  <el-radio :label="2">
                    {{ $t("order.order.agreeToRefundA") }}
                  </el-radio>
                  <el-radio :label="3">
                    {{ $t("order.order.refusalToRefund") }}
                  </el-radio>
                </el-radio-group>
              </div>
            </div>

            <div
              v-if="isAgreeRefund === 3"
              class="sellerRemark"
            >
              <div class="input-bar denial-reason">
                <div>
                  <div class="remark-title denial">
                    {{ $t("order.order.denialReason") }}：
                  </div>
                  <el-input
                    v-model="dataForm.rejectMessage"
                    type="textarea"
                    style="width: 100%;outline-style: none;"
                    :rows="6"
                    maxlength="250"
                    show-word-limit
                  />
                </div>
                <div class="right">
                  <div class="remark-title denial">
                    上传凭证：
                  </div>
                  <imgs-upload
                    v-model="dataForm.voucherImgs"
                    :limit="3"
                  />
                  <span class="tips">最多上传3张</span>
                </div>
              </div>
            </div>
            <div
              v-if="dataForm.returnMoneySts === 1"
              class="sellerRemark"
            >
              <div class="input-bar">
                <div class="remark-title">
                  {{ $t('order.order.merchantNotes') }}：
                </div>
                <el-input
                  v-model="dataForm.sellerMsg"
                  type="textarea"
                  style="width: 100%;outline-style: none;"
                  :rows="4"
                  maxlength="250"
                  show-word-limit
                />
              </div>
            </div>

            <div class="btn-bar">
              <!-- 仅退款的时候进行的处理操作 -->
              <el-button
                v-if="dataForm.returnMoneySts === 1"
                type="primary"
                @click="onCheck()"
              >
                {{ $t("order.order.confirmTreatment") }}
              </el-button>
              <!-- 退货退款的时候进行的处理操作 -->
              <el-button
                v-if="dataForm.returnMoneySts === 3"
                type="primary"
                @click="onReturnMoney()"
              >
                {{ $t("order.order.confirmTreatment") }}
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <add-or-update
      v-if="addOrUpdateVisible"
      ref="addOrUpdateRef"
      @refresh-data-list="onGetRefundAddrList()"
    />
    <add-proof
      v-if="addProofVisible"
      ref="addProofRef"
      :refund-detail="dataForm"
      @refresh-data="getRefundOrderInfo"
    />
  </div>
</template>

<script setup>
import addOrUpdate from '@/views/modules/shop/refund-addr/components/add-or-update.vue'
import Big from 'big.js'
import * as api from '@/api/order/order-refund'
import * as shopRefundAddrApi from '@/api/multishop/shop-refund-addr'
import { getIsUploadInvoice } from '@/api/order/order-invoice'
import { ElMessage, ElMessageBox } from 'element-plus'
import refundRecord from './conponents/refund-record/index.vue'
import addProof from './conponents/add-proof/index.vue'
import refundSteps from './conponents/refund-steps/index.vue'

// 计算函数
const dataForm = ref({})

const isAgreeRefund = ref(2)
watch(isAgreeRefund, () => {
  dataForm.value.rejectMessage = ''
})

const route = useRoute()
onMounted(() => {
  if (route.query.refundId) {
    dataForm.value.refundId = route.query.refundId
    getRefundOrderInfo()
  }
})

onBeforeUnmount(() => {
  clearTimeout(intervenEndTimer)
})

// 初始化
const addrList = ref([])
const orderRefundAddrPhotos = ref([])
const isReceived = ref(0)
const imgList = ref([])
const isUploadInvoice = ref(false)
// 平台介入状态 -1.没有介入 1.用户申请介入 2.平台同意介入 3.平台拒绝介入 5.平台同意退款成功
const platInterveneSts = ref(0)
const getRefundOrderInfo = () => {
  isAgreeRefund.value = 2
  if (dataForm.value.refundId) {
    api.info(dataForm.value.refundId).then((data) => {
      dataForm.value = data
      getIsUploadInvoice(data.orderId).then((res) => {
        isUploadInvoice.value = res
      })
      if (dataForm.value.imgUrls !== '') {
        imgList.value = dataForm.value.imgUrls.split(',')
      }
      if (dataForm.value.isReceived) {
        isReceived.value = 1
      } else {
        isReceived.value = 0
      }
      if (dataForm.value.orderRefundAddr && dataForm.value.orderRefundAddr.imgs) {
        const imgUrls = dataForm.value.orderRefundAddr.imgs.split(',')
        orderRefundAddrPhotos.value = addDomain(imgUrls)
      }
      // 申请类型:1,仅退款,2退款退货
      if (data.applyType === 2 && !data.handelTime) {
        onGetRefundAddrList()
      }
      platInterveneSts.value = data.platformInterventionStatus
      if (data.interventionEndTime && platInterveneSts.value === 1) {
        intervenEndTimeCountdown()
      }
    })
  }
}

const addProofRef = ref(null)
const addProofVisible = ref(false)
const onAddProof = () => {
  addProofVisible.value = true
  nextTick(() => {
    addProofRef.value.init()
  })
}

// 平台介入时间添加凭证倒计时
let intervenEndTimer = null
const stillAveTime = ref(false)
const intervenEndTimeCountdown = () => {
  const nowTime = new Date().getTime() // 当前时间
  const endTime = new Date(dataForm.value.interventionEndTime).getTime() // 设置截止时间
  const leftTime = endTime - nowTime // 时间差

  if (leftTime >= 0) {
    stillAveTime.value = true
    // 递归每秒调用countTime方法，显示动态时间效果,
    intervenEndTimer = setTimeout(intervenEndTimeCountdown, 1000)
  } else {
    stillAveTime.value = false
    intervenEndTimer && clearTimeout(intervenEndTimer)
  }
}

/**
 * 加载收货地址模板
 */
const onGetRefundAddrList = () => {
  shopRefundAddrApi.list().then((data) => {
    addrList.value = data
    data.forEach(el => {
      if (el.isDefault === 1) {
        // 设置选中默认地址
        dataForm.value.supplierRefundAddrId = el.supplierRefundAddrId
      }
    })
  })
}

// 新增
const addOrUpdateVisible = ref(false)
const addOrUpdateRef = ref()
const onAddOrUpdate = (id) => {
  addOrUpdateVisible.value = true
  nextTick(() => {
    addOrUpdateRef.value.init(id, true)
  })
}

// 刷新
const onRefreshChange = () => {
  onGetRefundAddrList()
}

/**
 * 仅退款的时候，进行的退款处理操作
 * 提交处理
 */
const onCheck = () => {
  if (validNoEmptySpace(dataForm.value.sellerMsg) || validNoEmptySpace(dataForm.value.rejectMessage)) {
    ElMessage({
      message: '内容不能全为空格',
      type: 'error',
      duration: 1500,
      onClose: () => {
      }
    })
    return
  }
  isAgreeRefund.value === 2 ? onCheckIsLastOrderItem(onHandelReturnMoney) : onHandelReturnMoney()
}

/**
 * 是否为最后一个退款项
 */
const onCheckIsLastOrderItem = (fn) => {
  api.checkIsLastOrderItem(dataForm.value.refundId).then((data) => {
    if (data && dataForm.value.freightAmount) {
      const calcVal = new Big(dataForm.value.freightAmount).minus(dataForm.value.platformFreeFreightAmount).valueOf()
      if (formatPrice(calcVal, 1).toFixed(2) + '' !== '0.00') {
        ElMessageBox.confirm($t('该退款申请项是订单中最后一件商品，同意退款后运费￥[d]会一并退还给用户').replace('[d]', formatPrice(calcVal, 1).toFixed(2) + ' '), $t('table.tips'), {
          confirmButtonText: $t('table.confirm'),
          cancelButtonText: $t('table.cancel'),
          type: 'warning'
        }).then(() => {
          fn()
        }).catch(() => {
        })
      } else {
        fn()
      }
    } else {
      fn()
    }
  })
}

const isProcessing = ref(false)
const onHandelReturnMoney = () => {
  const tempShopRefundAddrId = isAgreeRefund.value === 2 ? dataForm.value.supplierRefundAddrId : undefined
  if (isProcessing.value) {
    return
  }
  if (isAgreeRefund.value === 3) {
    if (dataForm.value.rejectMessage == null || dataForm.value.rejectMessage === '') {
      ElMessage.error('拒绝原因不能为空')
      return
    }
    if (!dataForm.value.voucherImgs) {
      ElMessage({
        message: '请上传凭证',
        type: 'error',
        duration: 1500
      })
      return
    }
  }
  isProcessing.value = true
  isAgreeRefund.value !== 3 && (dataForm.value.voucherImgs = '')
  api.returnAndRefundAudit({
    refundId: dataForm.value.refundId,
    refundSts: isAgreeRefund.value,
    rejectMessage: dataForm.value.rejectMessage,
    sellerMsg: dataForm.value.sellerMsg,
    shopRefundAddrId: tempShopRefundAddrId,
    imgUrls: dataForm.value.voucherImgs // 凭证
  }).then(() => {
    ElMessage({
      message: $t('table.actionSuccess'),
      type: 'success',
      duration: 1500,
      onClose: () => {
      }
    })
    setTimeout(() => {
      onGoBack()
      isProcessing.value = false
    }, 1000)
  }).catch(() => {
    isProcessing.value = false
  })
}

/**
 * 确定退款
 */
const onReturnMoney = () => {
  if (isProcessing.value) {
    return
  }
  if (validNoEmptySpace(dataForm.value.sellerMsg) || validNoEmptySpace(dataForm.value.rejectMessage)) {
    ElMessage({
      message: '内容不能全为空格',
      type: 'error',
      duration: 1500,
      onClose: () => {
      }
    })
    return
  }
  if (isAgreeRefund.value === 3) {
    if (dataForm.value.rejectMessage == null || dataForm.value.rejectMessage === '') {
      ElMessage.error('拒绝原因不能为空')
      return
    }
    if (!dataForm.value.voucherImgs) {
      ElMessage({
        message: '请上传凭证',
        type: 'error',
        duration: 1500
      })
      return
    }
  }
  isProcessing.value = true
  api.returnMoney({
    refundId: dataForm.value.refundId,
    refundSts: isAgreeRefund.value,
    rejectMessage: dataForm.value.rejectMessage,
    sellerMsg: dataForm.value.sellerMsg,
    isReceived: isReceived.value,
    supplierHandleStatus: isAgreeRefund.value === 2 ? 1 : 2,
    imgUrls: dataForm.value.voucherImgs // 凭证
  }).then(() => {
    ElMessage({
      message: $t('table.actionSuccess'),
      type: 'success',
      duration: 1500
    })
    setTimeout(() => {
      onGoBack()
      isProcessing.value = false
    }, 1000)
  }).catch(() => {
    isProcessing.value = false
  })
}

// 精度运算-乘法
const onBigSpuTotalAmount = (a, b) => {
  return new Big(a).times(b).div(100).toFixed(2)
}

// 精度运算-除法
const onBigActualTotal = (a, b) => {
  if (a == null) {
    return ''
  }
  return new Big(a).div(b).times(dataForm.value.refundCount).div(100).toFixed(2)
}

/**
 * 精度运算-过滤
 */
const onHandlerPrice = (val) => {
  if (val == null) {
    return ''
  }
  return new Big(val).div(100).toFixed(2)
}

const router = useRouter()
const onGoBack = () => {
  router.replace('/order/order-manage/refund-order')
}

</script>
<style lang="scss" scoped>
@use './index.scss';
</style>
