<!-- 创建数据集 -->
<template>

  <el-form label-position="left" ref="form" label-width="100px" :rules="rules" :model="form" :size="defaultFormItemSize">
    <el-row class="title">基本信息</el-row>
    <el-form-item label="数据集名称:" prop="datasetName">
      <el-input v-model="form.datasetName" class="inputWidth" :size="defaultFormItemSize"></el-input>
    </el-form-item>
    <el-form-item label="数据类型:">
      <el-radio v-for="item in DataType.getList()" :key="item.id" v-model="form.dataType" :label="item.id">{{item.name}}</el-radio>

    </el-form-item>
    <el-form-item label="数据集版本:">
      {{ 'V1' }}
    </el-form-item>
    <el-form-item label="标注类型:">
      <el-radio v-for="item in LabelType.getList()" :key="item.id" v-model="form.dimensionType" :label="item.id"  @change="isText">{{item.name}}</el-radio>
  
    </el-form-item>

    <el-form-item label="标注模版:" v-if="form.dimensionType===0">
      <el-radio v-for="item in MarkTemplate.getList()" :key="item.id" v-model="form.template" :label="item.id">{{item.name}}</el-radio>
    </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 { MyDataSet } from '@/api/gptController.js';
export default {
  data () {
    return {
      form: {
        'dataType': 0,
        'datasetName': '',
        'deletedFlag': 0,
        'dimensionType': 0,
        'template': 0
      },
      rules: {
        datasetName: [{required: true, message: '数据集名称不能为空', trigger: 'blur'}]
      }
    };
  },
  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.datasetManageDto = { ...this.form };

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