MrShi
10 小时以前 b806c4ad52a661a1e5f0695650ec1a7e42f01633
admin/src/components/business/OperaManualRefund.vue
@@ -5,6 +5,7 @@
    :visible.sync="visible"
    :confirm-working="submitting"
    :confirm-text="'确认退款'"
    :withFooter="refundForm.manualRefund !== 1"
    @confirm="handleSubmit"
  >
    <el-form ref="refundForm" :model="refundForm" v-if="orderInfo && orderInfo.order">
@@ -46,16 +47,16 @@
      <!-- 退款表单 -->
      <el-form-item label="退款金额" prop="refundAmount" label-suffix=":*" :rules="[{ required: true, message: '请输入退款金额', trigger: 'blur' }, { validator: this.validateRefundAmount, trigger: 'blur' }]">
          <el-input v-model.number="refundForm.refundAmount" placeholder="请输入退款金额" suffix-icon="el-icon-yuan"></el-input>
          <el-input v-model="refundForm.refundAmount" placeholder="请输入退款金额" suffix-icon="el-icon-yuan"></el-input>
        </el-form-item>
      <el-form-item label="寄件门店扣费">
        <el-input v-model.number="refundForm.depositShopFee" placeholder="请输入寄件门店扣费" suffix-icon="el-icon-yuan"></el-input>
      <el-form-item label="寄件门店扣费" prop="depositShopFee" :rules="[{ validator: this.validateDecimal, trigger: 'blur' }]">
        <el-input v-model="refundForm.depositShopFee" placeholder="请输入寄件门店扣费" suffix-icon="el-icon-yuan"></el-input>
      </el-form-item>
      <el-form-item label="收件门店扣费" v-if="orderInfo.type === 1 && orderInfo.shopId">
        <el-input v-model.number="refundForm.takeShopFee" placeholder="请输入收件门店扣费" suffix-icon="el-icon-yuan"></el-input>
      <el-form-item label="收件门店扣费" prop="takeShopFee" v-if="orderInfo.type === 1 && orderInfo.shopId" :rules="[{ validator: this.validateDecimal, trigger: 'blur' }]">
        <el-input v-model="refundForm.takeShopFee" placeholder="请输入收件门店扣费" suffix-icon="el-icon-yuan"></el-input>
      </el-form-item>
      <el-form-item label="配送司机扣费" v-if="orderInfo.type === 1">
        <el-input v-model.number="refundForm.driverFee" placeholder="请输入配送司机扣费" suffix-icon="el-icon-yuan"></el-input>
      <el-form-item label="配送司机扣费" prop="driverFee" v-if="orderInfo.type === 1" :rules="[{ validator: this.validateDecimal, trigger: 'blur' }]">
        <el-input v-model="refundForm.driverFee" placeholder="请输入配送司机扣费" suffix-icon="el-icon-yuan"></el-input>
      </el-form-item>
      <el-form-item label="备注说明">
        <el-input v-model="refundForm.remark" type="textarea" :rows="4" placeholder="请输入备注说明"></el-input>
@@ -68,7 +69,7 @@
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { getById } from '@/api/business/orderManagement'
import { manualRefund } from '@/api/business/orders'
import { manualRefund, manualRefundDetail } from '@/api/business/orders'
export default {
  name: 'OperaManualRefund',
@@ -85,13 +86,25 @@
        depositShopFee: null,
        takeShopFee: null,
        driverFee: null,
        remark: ''
        remark: '',
        manualRefund: null
      }
    }
  },
  methods: {
    validateRefundAmount(rule, value, callback) {
      let refundAmount = (((this.orderInfo.order.payAmount||0) - (this.orderInfo.order.refundAmount ||0)) / 100)
      // 验证最多两位小数
      if (value !== null && value !== '' && value !== undefined) {
        const str = String(value)
        if (str.includes('.')) {
          const decimal = str.split('.')[1]
          if (decimal.length > 2) {
            callback(new Error('最多支持两位小数'))
            return
          }
        }
      }
      // 退款金额必须大于0
      if (Number(value) <= 0) {
        callback(new Error('退款金额必须大于0'))
@@ -102,21 +115,46 @@
      if (Number(value) > refundAmount) {
        callback(new Error('退款金额不能超过可退金额'))
      }
      // 计算总扣费金额
      // const depositShopFee = this.refundForm.depositShopFee || 0
      // const takeShopFee = this.refundForm.takeShopFee || 0
      // const driverFee = this.refundForm.driverFee || 0
      // const totalFee = depositShopFee + takeShopFee + driverFee
      // 退款金额必须大于等于总扣费金额
      // if (value < totalFee) {
      //   callback(new Error('退款金额必须大于等于各项扣费总和'))
      // }
      
      callback()
    },
    validateDecimal(rule, value, callback) {
      if (value !== null && value !== '' && value !== undefined) {
        const str = String(value)
        if (str.includes('.')) {
          const decimal = str.split('.')[1]
          if (decimal.length > 2) {
            callback(new Error('最多支持两位小数'))
          } else {
            callback()
          }
        } else {
          callback()
        }
      } else {
        callback()
      }
    },
      open (row) {
      this.orderId = row.id
      if (row.manualRefund === 1) {
        this.refundForm.manualRefund = row.manualRefund
        manualRefundDetail(row.id)
          .then(res => {
            this.refundForm.refundAmount = ((res.refundAmount || 0) / 100).toFixed(2)
            this.refundForm.depositShopFee = ((res.depositShopDeduct || 0) / 100).toFixed(2)
            this.refundForm.takeShopFee = ((res.takeShopDeduct || 0) / 100).toFixed(2)
            this.refundForm.driverFee = ((res.driverDeduct || 0) / 100).toFixed(2)
            this.refundForm.remark = res.refundRemark
          })
      } else {
        this.refundForm.manualRefund = null
        this.refundForm.refundAmount = ''
        this.refundForm.depositShopFee = ''
        this.refundForm.takeShopFee = ''
        this.refundForm.driverFee = ''
        this.refundForm.remark = ''
      }
      this.orderInfo = null
      this.visible = true
      this.getOrderDetail()