signRefundDialog.vue 4.67 KB
<!-- 标记退款 -->
<template>
  <d2-dialog title="退款备注"
             :is-visible="signRefundVisible"
             class="accountDailog"
             @closeDialog="handleClose"
             @confirmDialog="handleAddConfirm">
    <el-form ref="refundForm"
             :model="infoForm"
             :rules="formRules"
             :label-width="isPartialRefund ? '100px': '0'">
      <template v-if="isPartialRefund">
        <el-form-item prop="refundType"
                      label="退款明细:">
          <el-radio-group v-model="infoForm.refundType"
                          @change="changeType">
            <el-radio label="1">
              退全款
            </el-radio>
            <el-radio label="2">
              退部分款
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item prop="refundAmount"
                      label="退款金额:">
          <el-input style="width: 432px;"
                    :disabled="infoForm.refundType == '1'"
                    placeholder="请输入退款金额"
                    @input="refoundAmountInput"
                    v-model="infoForm.refundAmount"></el-input>
        </el-form-item>
      </template>
      <el-form-item prop="remark"
                    :label="isPartialRefund ? '备注:' : ''">
        <el-input v-clear-emoij
                  type="textarea"
                  :rows="5"
                  placeholder="请备注客户退款的原因,有助于您的售后"
                  maxlength="200"
                  show-word-limit
                  v-model="infoForm.remark" />
      </el-form-item>
    </el-form>
  </d2-dialog>
</template>

<script>
// import { getMerchantPageSearch } from '@api/publicAccount'
import { markAsRefunded } from '@api/order'
import { deepClone } from '@/common/util'
import { limitPrice } from '@/common/format'
export default {
  name: 'SignRefundDialog',
  data() {
    var checkRefundAmount = (rule, value, callback) => {
      if (this.infoForm?.refundType == '2') {
        if (value == 0) {
          callback('退款金额要大于0')
        } else if (+value >= this.detail?.totalPrice) {
          callback('退款金额只能小于订单总金额')
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    return {
      userInfo: this.$store.state.d2admin.user.info,
      infoForm: {
        remark: '',
        refundType: '1',
        refundAmount: ''
      },
      formRules: {
        remark: [{ required: true, message: '请输入备注信息', trigger: 'change' }],
        refundAmount: [
          { required: true, message: '请输入退款金额', trigger: 'blur' },
          {
            validator: checkRefundAmount, trigger: 'blur'
          }
        ]
      },
      reg: {
        priceReg: /^\d[\d\.]*$/
      }
    }
  },

  props: {
    signRefundVisible: {
      type: Boolean,
      default: false
    },
    detail: {
      type: Object,
      default: null
    },
    isPartialRefund: {
      type: Boolean,
      default: false
    }
  },

  watch: {
  },

  created() {
  },
  components: {},

  mounted() {
    console.log(this.detail)
    this.changeType(this.infoForm.refundType)
  },

  methods: {
    // 切换退款类型
    changeType(value) {
      // 退全款带入订单总金额
      if (value == 1) this.infoForm.refundAmount = this.detail?.totalPrice
      else this.infoForm.refundAmount = ''
    },
    // 退款金额输入框
    refoundAmountInput(newValue) {
      if (newValue < 0 || !this.reg.priceReg.test(newValue)) {
        newValue = ''
      }
      var oldValue = newValue
      this.$set(this.infoForm, 'refundAmount', limitPrice(newValue, oldValue, 15, 2))
    },
    handleAddConfirm() {
      this.$refs.refundForm.validate(valid => {
        if (valid) {
          var infoForm = deepClone(this.infoForm)
          var params = {}
          params.refundRemark = infoForm.remark
          params.orderCode = this.detail.orderCode
          if (this.isPartialRefund) { // 精品升级
            params.refundType = infoForm.refundType
            params.refundAmount = infoForm.refundAmount
          } else { // 会员权益 默认退全款
            params.refundType = 1
            params.refundAmount = this.detail.totalPrice
          }
          markAsRefunded(params).then(res => {
            this.notice.okTips('操作成功')
            this.handleClose(true)
          })
        }
      })
    },

    handleClose(flag) {
      this.$emit('dialogClose', flag)
    }
  }
}
</script>
<style scoped>
.accountDailog .el-dialog {
  margin-top: 20vh !important;
  min-width: 700px;
}

.accountDailog .el-select-dropdown__item {
  width: 395px !important;
}
</style>