<!--导入 -->
<template>
  <el-form label-position="left" ref="form" label-width="120px" :model="form" :size="defaultFormItemSize" :rules="rules"  v-loading.fullscreen.lock="fullscreenLoading">

    <!-- <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文件:" prop="importFile">

      <el-button @click="clickUp" :size="defaultFormItemSize"  type="primary">上传<i class="el-icon-upload el-icon--right"></i></el-button>
      <input style="display:none" ref="upFile" type="file" accept=".JSONL"  @change="fileinfo($event.target.files)" >

      <div class="itemFile" v-if="form.importFile">{{ form.importFile?.name }}
      <i class="el-icon-circle-close" style="color:#0092FF;cursor: pointer;" @click="clearFile()"></i>
      </div>
    </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 {
      fullscreenLoading: false,
      form: {
        importFile: undefined

      },
      rules: {
        importFile: [{ required: true, message: '请上传文件', trigger: 'blur' }]
      }

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

  computed: {

  },

  mounted () {
    this.intFrom()
  },

  methods: {
    fileinfo (files) {
      console.log(files[0]);
      this.form.importFile = files[0]
      this.$refs.upFile.value = ''
    },
    clickUp () {
      this.$refs.upFile.click()
    },

    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) {
            this.fullscreenLoading = true
            let params = {};
            params = { ...this.form };

            this.upload('/admin/app/datasetVersion/import', params).then(res => {
              resolve(res);
              this.$message.success('上传成功');
              this.onCancel(true);
              this.fullscreenLoading = false
            }).catch(e => {
              this.fullscreenLoading = false
              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();
          }
        });
      });
    },
    clearFile () {
      this.form.importFile = undefined
    }
  }
};
</script>
<style scoped>
.inputWidth {
  width: 600px;
}

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

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