<template>
  <el-dialog v-model="dialogVisible" title="添加多语言类型" width="900px" @closed="closeDialog" @open="openDialog">
    <el-form ref="formRef" :model="formData" :rules="rules">
      <el-row>


        <el-col :span="12">
          <el-form-item :label-width="labelWidth" label="名称" prop="i18n_lang_type_name">
            <el-input v-model='formData.i18n_lang_type_name' type="text" placeholder='请输入名称'></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label-width="labelWidth" label="code码" prop="i18n_lang_type_code">
            <el-input v-model='formData.i18n_lang_type_code' type="text" placeholder='请输入code码'></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label-width="labelWidth" label="排序" prop="i18n_lang_type_sort">
            <el-input-number v-model='formData.i18n_lang_type_sort' controls-position='right' :min='1'></el-input-number>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="handleAddClick(formRef)">添加</el-button>
        <el-button @click="handleResetClick(formRef)">重置</el-button>
        <el-button @click="closeDialog()">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { reactive, ref, watch } from "vue";
import { addI18nLangType } from "~/service/i18n_lang_type";
import { useLoginStore } from "~/store";

// --业务参数



// --业务方法





// --基础参数
const store = useLoginStore();
const headers = {
  Accept: "application/json",
  ...store.headers,
};

const isBtnLod = ref(false);
const formRef = ref();
const labelWidth = 90;
const props = defineProps({
  modelValue: Boolean,
  done: Function,
});
const emits = defineEmits(["update:modelValue"]);
const dialogVisible = ref(props.modelValue);
const formData = reactive({});

const uoloadData = ref({
  dirName: "I18nLangType"
})

watch(props, (v) => {
  dialogVisible.value = v.modelValue;
});

const rules = reactive({
  i18n_lang_type_name: [
    {
      required: true,
      message: '名称不能为空'
    }
  ],
  i18n_lang_type_code: [
    {
      required: true,
      message: 'code码不能为空'
    }
  ],
  // i18n_lang_type_sort: [
  //   {
  //     required: true,
  //     message: '排序不能为空'
  //   }
  // ],

});


// --基础方法

// 打开弹窗时执行
const openDialog = () => {

};

const closeDialog = () => {
  handleResetClick(formRef.value);
  dialogVisible.value = false;
  emits("update:modelValue", false);
};

const handleAddClick = async (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid) => {
    if (!valid) {
      return;
    }
    isBtnLod.value = true;


    const { code } = await addI18nLangType(formData);
    if (code == 0) {
      closeDialog();
      props.done();
    }
    isBtnLod.value = flase;
  });
};

const handleResetClick = async (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
};
</script>

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