<!-- 基本信息 -->
<template>
 <el-form label-position="left" ref="form" label-width="120px" :model="form" :size="defaultFormItemSize" :rules="rules">
    <el-row class="title">基本信息</el-row>
    <el-form-item label="知识库名称:" prop="knowledgeName">
      <el-input :disabled="this.isEdit" v-model="form.knowledgeName" class="inputWidth" :size="defaultFormItemSize" ></el-input>
    </el-form-item>
    <el-form-item label="知识库描述:"  prop="knowledgeDescribe">
      <el-input v-model="form.knowledgeDescribe" type="textarea" :rows="4" class="inputWidth" :size="defaultFormItemSize" placeholder="描述这个知识库的内容，详细的描述可以让AI及时访问知识库的内容。如果为空，将影响该知识库在知识问答中被检索到的概率，因此建议尽可能对知识库详细地总结描述。"></el-input>
    </el-form-item>
       <el-row type="flex" justify="end" class="dialog-btn-layer mt20">
      <template>
        <el-button :size="defaultFormItemSize" :plain="true" @click="onCancel()" >取消</el-button>
        <el-button :size="defaultFormItemSize" :plain="true" @click="onSubmit()">下一步</el-button>
    </template>
    </el-row>
  </el-form >
</template>

<script>
import { KnowledgeManage } from '@/api/gptController.js';
export default {
  data () {
    return {
      form: {
        'knowledgeDescribe': undefined,
        'knowledgeName': undefined,
        'knowledgeCode': undefined,
        knowledgeId: undefined
      },
      rules: {
        knowledgeName: [
          { required: true, message: '请填写知识库名称', trigger: 'blur' }
        ]
      }
    };
  },
  props: ['isEdit', 'item'],
  components: {},

  computed: {},

  mounted () {
    this.init()
  },

  methods: {
    init () {
      if (this.isEdit) {
        this.form.knowledgeDescribe = this.item.knowledgeDescribe
        this.form.knowledgeName = this.item.knowledgeName
        this.form.knowledgeCode = this.item.knowledgeCode
        this.form.knowledgeId = this.item?.knowledgeId
      }
    },
    onSubmit () {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            let params = {};
            params.knowledgeManageDto = { ...this.form };

            if (this.isEdit) {
              KnowledgeManage.update(this, params).then(res => {
                resolve(res);
                this.$message.success('编辑成功');
                this.next(res)
              }).catch(e => {
                reject(e);
              });
            } else {
              KnowledgeManage.add(this, params).then(res => {
                resolve(res);
                this.$message.success('添加成功');
                this.next(res)
              }).catch(e => {
                reject(e);
              });
            }
          } else {
            // this.$message.error('请完善必填信息');
            // reject();
          }
        });
      });
    },
    onCancel () {
      this.$parent.onCancel(false)
    },
    next (res) {
      this.$parent.knowledgeName = this.form.knowledgeName
      this.$parent.knowledgeCode = res.data.knowledgeCode;
      this.$parent.active++
    }
  }
}

</script>
<style scoped>
.introduce{
  font-size: 12px;
  color: #909399;
}
.title {
  font-size: 20px;
  margin-bottom: 16px;
}
</style>
