<!-- 创建Prompt模板 -->
<template>

  <el-form label-position="left" ref="form" label-width="80px" :model="form" :size="defaultFormItemSize">
    <el-row class="title">基本信息</el-row>
    <el-form-item label="任务名称:">
      <el-input v-model="form.taskName" class="inputWidth" :size="defaultFormItemSize"></el-input>
    </el-form-item>
    <el-form-item label="任务描述:">
      <el-input v-model="form.taskDescribe" type="textarea" :rows="4" class="inputWidth" :size="defaultFormItemSize"></el-input>
    </el-form-item>

    <el-row class="title">压缩配置</el-row>
    <el-form-item label="选择源模型:">
      <el-select v-model="value" placeholder="请选择">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <el-row> <span class="introduce">启用此功能可能会为您提供更好质量的提示词，但也会花费更长的时间进行优化</span></el-row>

    </el-form-item>
    <el-form-item label="模型创建⽅式:">
      <el-radio v-for="item in ModelCreationMode.getList()" :key="item.id" v-model="form.modelCompressDto.createMethod" :label="item.id">{{  item.name}}</el-radio>
    </el-form-item>
    <el-form-item label="选择已有模型:">
      <el-select v-model="value" placeholder="请选择">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="压缩策略:">
      <el-select v-model="value" placeholder="请选择">
        <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
    </el-form-item>
    <el-row class="title">资源配置</el-row>
    <el-form-item label="压缩任务运⾏环境:">
      <el-radio v-model="radio" label="0">GPU A800 -------- TeslaGPU_A800_80G显存单卡_16核_128G内存</el-radio>

    </el-form-item>
    <el-form-item label="选择计算节点数:">
      <el-input-number v-model="form.epoch" :min="1" label="迭代轮次"  :size="defaultFormItemSize"></el-input-number>
    </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 { BatchOptimizationController } from '@/api/gptController.js';
export default {
  data () {
    return {
      form: {
        'chain': 0,
        'destDatasetId': 0,
        'destDatasetName': '',
        'destDatasetVersion': 0,
        'epoch': 0,
        'failCount': 0,
        'finishTime': '',
        'qualityQptimality': 0,
        'shortenPrompt': 0,
        'sourceDatasetId': 0,
        'sourceDatasetName': '',
        'sourceDatasetVersion': 0,
        'successCount': 0,
        'taskDescribe': '',
        'taskName': '',
        'taskStatus': 0
      }

    };
  },
  props: ['isEdit', 'item'],
  components: {},

  computed: {

  },

  mounted () {
    this.intFrom()
  },

  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.promptOptimizeBatchDto = { ...this.form };

            if (this.isEdit) {
              BatchOptimizationController.update(this, params).then(res => {
                resolve(res);
                this.$message.success('编辑成功');
                this.onCancel(true);
              }).catch(e => {
                reject(e);
              });
            } else {
              BatchOptimizationController.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>
