<template>
  <Dialog v-model="visible" show-footer diaTitle="新增参数类型" :width="400" @close="closeFun">
    <template #default>
      <el-form :model="formData" labelWidth="auto">
        <el-form-item label="参数库名称" prop="parameterLibraryName">
          <el-input v-model="formData.parameterLibraryName" disabled></el-input>
        </el-form-item>
        <el-form-item label="分类名称" prop="parameterLibraryCategoryName">
          <el-input v-model="formData.parameterLibraryCategoryName"></el-input>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="closeFun">取消</el-button>
        <el-button type="primary" @click="onConfirmFun">确定</el-button>
      </div>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import Dialog from '@/components/common/dialog/index.vue';
import { ElMessage } from 'element-plus';

const emits = defineEmits(['close', 'createFun']);
const props = defineProps(['libInfo']);
const visible = ref(true);
const formData = ref({
  parameterLibraryCategoryName: '',
  parameterLibraryName: '',
});

const closeFun = () => {
  emits('close');
};

const onConfirmFun = () => {
  if (!formData.value.parameterLibraryCategoryName) {
    ElMessage.warning('请输入参数类型名称！');
    return;
  } else {
    emits('createFun', {
      parameterLibraryCategoryName: formData.value.parameterLibraryCategoryName,
      parameterLibraryId: props.libInfo.id,
    });
  }
};

onMounted(() => {
  if (props.libInfo) {
    formData.value.parameterLibraryName = props.libInfo.name;
  }
});
</script>

<style lang="scss" scoped>
.upload {
  width: 100%;
}
.dialog-footer {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
