<!-- 创建 -->
<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="modelEstimateDto.taskName">
      <el-input v-model="form.modelEstimateDto.taskName" class="inputWidth" :size="defaultFormItemSize" ></el-input>
    </el-form-item>
    <el-form-item label="描述:">
      <el-input v-model="form.modelEstimateDto.taskDescribe" type="textarea" :rows="4" class="inputWidth"
        :size="defaultFormItemSize"></el-input>
    </el-form-item>

    <el-form-item label="参数配置:">
      <parameterConfiguration v-model="form.modelEstimateDto.configuration" />
    </el-form-item>

    <el-row class="title">评估配置</el-row>
    <el-form-item label="待评估模型:" prop="modelEstimateDto.modelVersionId">
      <el-cascader v-model="form.modelEstimateDto.modelVersionId" :options="modelList"
        :props='{ label: "name", value: "id", emitPath: false }'></el-cascader>
    </el-form-item>
    <el-form-item label="评估数据集:" prop="modelEstimateDto.datasetVersionId">
      <el-cascader v-model="form.modelEstimateDto.datasetVersionId" :options="dataList"
        :props='{ label: "name", value: "id", emitPath: false }'></el-cascader>
      <el-row> <span class="introduce">支持选择平台数据服务模块已发布的“文本对话”类型数据集。</span></el-row>
    </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 { ModelEstimate, MyModel, MyDataSet } from '@/api/gptController.js';
// import tableList from '../tableList/index.vue';
// import scoringMode from '../scoringMode/index.vue';
import parameterConfiguration from '../parameterConfiguration/index.vue';
export default {
  data () {
    return {
      modelList: [],
      dataList: [],
      form: {
        'modelEstimateDto': {
          'taskName': undefined,
          'taskDescribe': undefined,
          'modelVersionId': undefined,
          'datasetVersionId': undefined,
          'configuration': undefined
        }
      },
      rules: {
        'modelEstimateDto.taskName': [
          { required: true, message: '请输入任务名称', trigger: 'blur' }
         
        ],
        'modelEstimateDto.modelVersionId': [{ required: true, message: '请选择待评估模型', trigger: 'blur' }],
        'modelEstimateDto.datasetVersionId': [{ required: true, message: '请选择评估数据集', trigger: 'blur' }]
      }

    };
  },
  props: ['item', 'modelVersionId'],
  components: {parameterConfiguration},

  computed: {

  },

  mounted () {
    this.getModelList()
    this.getDataList()
    if (this.isCopy) {
      this.form.modelEstimateDto = {...this.item}
    } else if (this.modelVersionId) {
      this.form.modelEstimateDto.modelVersionId = this.modelVersionId
    }
  },

  methods: {
    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) {
              ModelEstimate.update(this, params).then(res => {
                resolve(res);
                this.$message.success('编辑成功');
                this.onCancel(true);
              }).catch(e => {
                reject(e);
              });
            } else {
              ModelEstimate.add(this, params).then(res => {
                resolve(res);
                this.$message.success('添加成功');
                this.onCancel(true);
              }).catch(e => {
                reject(e);
              });
            }
          } else {
            // reject();
          }
        });
      });
    },
    getModelList () {
      MyModel.listForTree(this, {}).then(res => {
        this.modelList = res.data.map((item) => {
          return { id: item.modelId, name: item.modelName, children: item.modelVersionList === [] ? [] : item.modelVersionList.map((item2) => { return { id: item2.versionId, name: 'V' + item2.modelVersion } }) }
        })
      }).catch(e => {
        console.log(e);
      });
    },
    getDataList () {
      MyDataSet.listForTree(this, {}).then(res => {
        this.dataList = res.data.map((item) => {
          return { id: item.datasetId, name: item.datasetName, children: item.datasetVersionList === [] ? [] : item.datasetVersionList.map((item2) => { return { id: item2.versionId, name: 'V' + item2.datasetVersion } }) }
        })
      }).catch(e => {
        console.log(e);
      });
    }
  }
};
</script>
<style scoped>
.inputWidth {
  width: 600px;
}

.title {
  font-size: 20px;
  margin-bottom: 16px;
}

.introduce {
  font-size: 12px;
  color: #909399;
}
</style>
