<!--导入 -->
<template>
  <el-form label-position="left" ref="form" label-width="auto" :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="上传数据集文件:" prop="importFile">
      <el-button @click="clickUp" :size="defaultFormItemSize" type="primary">上传<i class="el-icon-upload el-icon--right"></i></el-button>
      <div class="el-upload__tip">只能上传JSONL,TXT,XLSX,CSV文件
        <el-button type="text">
          <a target="_blank" rel="noopener noreferrer" href="/示例文件.zip">示例下载</a>
        </el-button>
      </div>
      <input style="display:none" ref="upFile" type="file" accept=".JSONL,.txt,.xlsx,.csv" @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="defnpaultFormItemSize" @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) {
      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>
