<template>
  <div class="container">
    <n-form ref="formRef" label-placement="left" :label-width="140" :model="form" :rules="rules" size="large" require-mark-placement="left">
      <n-form-item :label="t('reportPop.phone')+'：'" path="contact">
        <n-input v-model:value="form.contact" type="number" :placeholder="t('reportPop.phonePlaceholder')" />
      </n-form-item>
      <n-form-item :label="t('reportPop.companyName')+'：'" path="companyName">
        <n-input v-model:value="form.companyName" type="text" :placeholder="t('reportPop.companyNamePlaceholder')" />
      </n-form-item>
      <n-form-item :label="t('reportPop.position')+'：'" path="addr">
        <n-input v-model:value="form.addr" type="text" :placeholder="t('reportPop.positionPlaceholder')" />
      </n-form-item>
      <n-form-item :label="t('reportPop.email')+'：'" path="email">
        <n-input v-model:value="form.email" type="text" :placeholder="t('reportPop.emailPlaceholder')" />
      </n-form-item>
    </n-form>
    <n-button class="login-btn" attr-type="button" type="info" color="#18A058" :disabled="submitLoading" @click="handleSure">
      {{ submitLoading ? t('reportPop.submitLoading') : t('reportPop.submit') }}
    </n-button>
  </div>
</template>

<script lang="ts" setup>
import { useI18n } from "#imports";
import { ref, reactive, onMounted } from "vue";
import {
  // NForm,
  // NFormItem,
  // NInput,
  // NButton,
  // FormRules,
  // FormItemRule,
  createDiscreteApi,
} from "naive-ui";
const emit = defineEmits(["closeSginDialog"]);
const props = defineProps({
  info: {
    type: Object,
    default: () => {},
  },
});
const { t } = useI18n();
const formRef = ref();
const submitLoading = ref(false);
const form = reactive({
  contact: "",
  companyName: "",
  addr: "",
  email: "",
});
const rules: FormRules = {
  contact: [
    {
      required: true,
      message: t('reportPop.phoneRequired'),
      trigger: ["input", "blur"],
    },
  ],
};
const handleSure = () => {
  formRef.value?.validate(async (errors: any) => {
    if (!errors) {
      submitLoading.value = true;
      try {
        const { code } = await updateInfo_Api(form);
        if (code === 200) {
          message.message.success(t('reportPop.submitSuccess'));
          emit("closeSginDialog", "success");
        }
      } catch (error) {}
      submitLoading.value = false;
    }
  });
};
// onMounted(() => {
for (let key in form) {
  form[key] = props.info[key];
}
// });
const message = createDiscreteApi(["message"]);
</script>

<style lang="scss" scoped>
.container {
  width: 100%;
  padding: 30px 20px;

  .login-btn {
    display: block;
    width: 50%;
    height: 50px;
    color: #fff;
    font-size: 18px;
    border-radius: 8px;
    margin: 0 auto;

    :deep(.n-button__content) {
      display: block;
    }
  }
}
</style>
