<!-- 基本信息-->
<template>

  <el-form label-position="left" ref="form" label-width="100px" :model="form" :size="defaultFormItemSize" :rules="rules">
    <el-row class="title">基本信息</el-row>
    <el-form-item label="应用名称:" prop="apiManageDto.apiName">
      <el-input v-model="form.apiManageDto.apiName" class="inputWidth" :size="defaultFormItemSize"></el-input>
      <el-row> <span class="introduce">支持中英文、数字、下划线(_)，2-20个字符，不能以下划线为开头</span></el-row>
    </el-form-item>
    <el-form-item label="应用描述:">
      <el-input v-model="form.apiManageDto.remark" type="textarea" class="inputWidth" :rows="5" :size="defaultFormItemSize"></el-input>
    </el-form-item>
    <el-row type="flex" justify="end" class="dialog-btn-layer mt20">
      <el-button :size="defaultFormItemSize" :plain="true" @click="onCancel(false)">取消</el-button>
      <el-button type="primary" :size="defaultFormItemSize" @click="onSubmit">确定</el-button>
    </el-row>
  </el-form>
</template>
<script>
import { ApiManage } from '@/api/gptController.js'
export default {
  data() {
    return {
      taskList: [],
      runNameList: [],
      form: {
        apiManageDto: {
          remark: '',
          apiName: ''
        }
      },
      rules: {
        'apiManageDto.apiName': [{ required: true, message: '请输入应用名称', trigger: 'blur' }]
      }
    }
  },
  props: ['isEdit', 'item'],
  components: {},

  computed: {},

  mounted() {
    this.intFrom()
    this.getTaskList()
    // this.getTuningRun()
  },

  methods: {
    intFrom() {
      this.form = { ...this.form, ...this.item }
      try {
        this.form.templateLabel = JSON.parse(this.item.templateLabel)
      } catch (error) {
        // console.log(error);
      }
    },
    onCancel(isSuccess) {
      if (this.observer != null) {
        this.observer.cancel(isSuccess)
      }
    },
    onSubmit() {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            let params = {}
            params = { ...this.form }

            if (this.isEdit) {
              ApiManage.update(this, params)
                .then((res) => {
                  resolve(res)
                  this.$message.success('编辑成功')
                  this.onCancel(true)
                })
                .catch((e) => {
                  reject(e)
                })
            } else {
              ApiManage.add(this, params)
                .then((res) => {
                  resolve(res)
                  this.$message.success('添加成功')
                  this.onCancel(true)
                })
                .catch((e) => {
                  reject(e)
                })
            }
          } else {
            // reject();
          }
        })
      })
    }
  }
}
</script>
<style scoped>
.inputWidth {
  width: 600px;
}
.title {
  font-size: 20px;
  margin-bottom: 16px;
}
.introduce {
  font-size: 12px;
  color: #909399;
}
</style>
