<template>
    <BaseDialog
      :dialogVisible="props.visible"
      @close="onclone"
      titleName="注销"
      width="50%"
      @onSubmit="handleSubmit"
      :footerclosed="true"
      :diafooter="true"
    >
      <div class="detailForm-content">
        <el-form
          ref="formRef"
          label-width="120"
          :rules="ruleForm"
          :model="formData"
          class="center-form"
        >
          <el-form-item label="注销时间" prop="changeTime">
            <el-date-picker
              v-model="formData.changeTime"
              type="date"
              placeholder="请选择注销时间"
              size="default"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>
        </el-form>
      </div>
    </BaseDialog>
  </template>
  <script setup lang='ts'>
  import { reactive, ref, onMounted, watch } from "vue";
  import { ElMessage, FormInstance, FormRules } from "element-plus";
  import { domicileCancel } from "@/api/base";
  
  const props = defineProps({
    visible: {
      type: Boolean,
      default: false,
    },
    form: Object,
  });
  const emits = defineEmits(["close"]);
  // 表单
  const formRef = ref<FormInstance>();
  const ruleForm = reactive<FormRules>({
    changeTime: [{ required: true, message: "请选择注销时间", trigger: "blur" }],
  });
  const formData = ref<any>({});
  const domicileId = ref('')
  //保存并退出
  const handleSubmit = () => {
    formRef.value?.validate((valid) => {
      if (valid) {
        let params = {
          changeTime:formData.value.changeTime,
          domicileId:domicileId.value,
        };
        console.log(params,'params===>');
        
        domicileCancel(params).then((res: any) => {
            console.log(res,'res===>');
            
          if (res.code == 1) {
            ElMessage.success({
              message: "操作成功",
              type: "success",
            });
            onclone();
          } else {
            ElMessage.error({
              message: res.message,
              type: "error",
            });
          }
        });
      }
      return false;
    });
  };
  //关闭弹窗
  const onclone = () => {
    formRef.value?.clearValidate();
    formData.value = {};
    emits("close");
  };
  onMounted(() => {
  });
  
  watch(
    () => props.form,
    (val: any) => {
        domicileId.value = val.domicileId;
    }
  );
  </script>
  <style scoped></style>