<template>
  <el-form :model="formData" label-width="120px" ref="ruleForm" :rules="rules" v-loading="loading" class="pr-4">
    <div class="flex flex-row justify-between">
      <div class="w-full">
        <el-form-item label="可退款提现金额" prop="name">
          <el-input v-model="props.primary.price" disabled placeholder="请输入商户名称" />
        </el-form-item>
        <el-form-item label="申请退款金额" prop="price">
          <div class="items-center w-full">
            <el-input style="width:200px;margin:0 5px;" v-model="formData.price" placeholder="请输入金额">
              <template #append>元</template>
            </el-input>
          </div>
        </el-form-item>
      </div>
    </div>
    <div class="flex justify-end">
      <el-button type="primary" @click="submitForm(ruleForm)">{{ $t('system.confirm') }}</el-button>
    </div>
  </el-form>
</template>

<script lang="ts" setup>
import { useCreate } from '@/hook/curd/useCreate';
import { useShow } from '@/hook/curd/useShow';
import type { FormInstance, FormRules } from 'element-plus'
import { orderRefundApply } from '@/api/orders/index'
const ruleForm = ref<FormInstance>()
import { onMounted, ref } from 'vue';
const props = defineProps({
  primary: Object,
});
const formData = ref({})
const rules = reactive({
  price: [
    {
      required: true,
      message: '请输入金额',
      trigger: 'blur'
    },
    { pattern: /^\d+(\.\d{1,2})?$/, message: '金额最多只能有两位小数', trigger: 'blur' },
    { pattern: /^(?!0\d+)\d+(\.\d+)?$/, message: '请输入有效的金额', trigger: 'blur' },
  ],
});
const loading = ref(false)
const applyBank = ref([])

const submitForm = (formEl: FormInstance | undefined) => {
  console.log(formData.value, 'formData.valueformData.value');
  if (!formEl) return;
  formEl
    .validate(valid => {
      if (valid) {
        orderRefundApply(formData.value).then(res => {
          ElMessage.success(res.message)
          emit('close')
          loading.value = false;
        })
      } else {
        loading.value = false;
      }
    })
    .then(() => { });
}

if (props.primary) {
  formData.value.order_id = props.primary.id
  console.log(props.primary, 'props.primaryprops.primary');
}

const emit = defineEmits(['close']);
onMounted(() => {

});
</script>

<style lang="scss" scoped></style>
