<template>
  <!-- 退款 -->
  <el-dialog :visible.sync="showRefund" title="退款" width="400px" @open="onOpen">
    <el-form :model="form" :rules="rules">
      <el-form-item label="退款金额" prop="amount">
        <el-input-number v-model="form.amount" placeholder="请输入退款金额" /> 元
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitRefund" :loading="loading">确 定</el-button>
      <el-button @click="showRefund = false" >取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { refund } from '@/api/system/refund'

export default {
  name: "RefundDialog",
  props: {
    show: {
      type: Boolean,
      default: false
    },
    payId: {
      type: String,
      default: null,
    },
    amount: {
      type: Number,
      default: null
    }
  },
  computed: {
    showRefund: {
      get() {
        return this.show;
      },
      set(val) {
        this.$emit('update:show', val);
      }
    },
  },
  data() {
    return {
      loading: false,
      form: {},
      // 表单
      rules: {
        amount: [
          { required: true, type: 'number', message: "退款金额不能为空", trigger: "blur" }
        ]
      },
    }
  },
  created() {
    this.reset();
  },
  methods: {
    onOpen() {
      this.reset();
    },
    reset() {
      this.form = {
        payId: this.payId,
        amount: this.amount,
      }
    },
    submitRefund() {
      this.loading = true;
      console.log("111111111111111-----{}",JSON.stringify(this.form))
      refund(this.form).then(res => {
        if (res.code === 200) {
          this.$message.success("操作成功");
          this.showRefund = false;
          this.$emit('success');
        }
      }).finally(() => {
        this.loading = false;
      })
    },
  }
}

</script>
