<!--导入 -->
<template>
  <el-form label-position="left" ref="form" label-width="120px" :model="form" :size="defaultFormItemSize">

    <!-- <el-form-item label="数据标注状态:">
      <el-radio v-for="item in DataAnnotationState.getList()" :key="item.id" v-model="form.dimensionType"
        :label="item.id">{{ item.name }}</el-radio>
    </el-form-item>
    <el-form-item label="导入格式:">
      <el-radio v-for="item in ImportFormat.getList()" :key="item.id" v-model="form.dimensionType"
        :label="item.id">{{ item.name }}</el-radio>
    </el-form-item> -->
    <el-form-item label="上传jsonl文件:">
      <input type="file" accept="application/json" @change="fileinfo($event.target.files)">
    </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 { DatasetVersion } from '@/api/gptController.js';
export default {
  data () {
    return {
      form: {
        importFile: ''

      }

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

  computed: {

  },

  mounted () {
    this.intFrom()
  },

  methods: {
    fileinfo (files) {
      this.form.importFile = files[0]
      console.log(this.form.importFile);
    },
    intFrom () {
      this.form = { ...this.form, datasetId: this.row.datasetId, versionId: this.row.versionId }
    },
    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 };
            console.log(this.fetchUpload);
            this.upload('/admin/app/datasetVersion/import', params).then(res => {
              resolve(res);
              this.$message.success('上传成功');
              this.onCancel(true);
            }).catch(e => {
              reject(e);
            });
            // if (this.isEdit) {
            //   DatasetVersion.importFile(this, params).then(res => {
            //     resolve(res);
            //     this.$message.success('编辑成功');
            //     this.onCancel(true);
            //   }).catch(e => {
            //     reject(e);
            //   });
            // } else {
            //   DatasetVersion.importFile(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>
