<template>
    <a-modal v-model:visible="okVisible" :modal-style="{width:'420px'}" body-class="okmodal" @ok="handleConfirm"
      @cancel="handleClose" >
      <template #title>
        提示
      </template>
      <a-form :model="form" :rules="rules" ref="modalFormRef" size="medium" label-align="left" auto-label-width>
      <a-form-item field="income_tax" label="个人所得税:" >
        <a-input-number :min="0" :style="{width:'200px'}" v-model="form.income_tax" placeholder="请输入个人所得税"  mode="button" class="input-demo" />
      </a-form-item>
    </a-form>
    <template #footer>
      <a-button @click="handleClose"><template #icon><icon-close /></template>取消</a-button>
      <a-button type="primary" @click="handleConfirm"><template #icon><icon-check /></template>确认</a-button>
    </template>

    </a-modal>
</template>
<script setup>
import { reactive, toRefs, getCurrentInstance } from 'vue';
import { Message } from '@arco-design/web-vue';
const { proxy } = getCurrentInstance();
const form = reactive({
    income_tax:null
    });
const props = defineProps({
  // 是否显示
  okVisible: {
    type: Boolean,
    default: false,
  },
  max:{
    type: Number,
    default: 0,
  },
  id:{
    type: String,
    default:'',
  },
  api: {
    type: Function,
  },
});
const emits = defineEmits(['closeChange']);
const {okVisible,id,api,max} = toRefs(props);

// Akiraka 20230210 关闭弹窗
const handleClose = () =>  {
  emits('closeChange',false);
  proxy.$refs.modalFormRef.resetFields();
 // alert(flag)
}
// Akiraka 20230210 删除数据校验
const rules = {
    income_tax:  [
      { required: true, message: '请输入个人所得税' },
      {
        validator: (value, cb) => {
          if (value==0) {
            cb('金额需要大于0');
          }
          if (value>props.max) {
            cb('修改金额不可超出提现金额');
          }
        }
      }
    ]
};
// Akiraka 20230210 确认按钮 => 开始数据检查
const handleConfirm = () => {
  proxy.$refs.modalFormRef.validate(async(valid) => {
    if (!valid) {
      const {code,message}= await api.value(id.value,form);
      if(code==200){
        Message.success("修改成功");
          proxy.$refs.modalFormRef.resetFields();
      }
      emits('closeChange',true);
    }
  })
  }
</script>