<!--导出 -->
<template>

  <el-form label-position="left" ref="form" label-width="100px" :model="form" :size="defaultFormItemSize">
    <el-form-item label="导出文件格式：">
      <el-select v-model="form.format" placeholder="请选择">
        <el-option v-for="item in ImportFormat.getList()" :key="item.id" :label="item.name" :value="item.symbol">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="数据导出记录：">
      <downList :outputList='outputList' />
    </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="downloadFile">开始导出</el-button>
    </el-row>
  </el-form>
</template>

<script>
import { DatasetVersion } from '@/api/gptController.js'
import downList from '@/components/DownList/index.vue'
export default {
  data() {
    return {
      outputList: [],
      form: {
        format: 'jsonl'
      }
    }
  },
  props: ['isEdit', 'row'],
  components: { downList },

  computed: {},

  mounted() {
    this.getOutputList()
  },

  methods: {
    onCancel(isSuccess) {
      if (this.observer != null) {
        this.observer.cancel(isSuccess)
      }
    },
    downloadFile() {
      let downDom = document.createElement('a')
      let params = { versionId: this.row.versionId, fileType: this.form.format }
      DatasetVersion.startExport(this, params).then((res) => {
        downDom.href = res.data
        downDom.click()
        this.onCancel(true)
        this.$message.success('下载成功')
      })
    },
    getOutputList() {
      let params = { datasetOutputDtoFilter: { versionId: this.row.versionId } }
      DatasetVersion.outputList(this, params).then((res) => {
        this.outputList = res.data.dataList
        console.log(this.outputList)
      })
    }
  }
}
</script>
<style scoped>
.inputWidth {
  width: 600px;
}
.title {
  font-size: 20px;
  margin-bottom: 16px;
}
.introduce {
  font-size: 12px;
  color: #909399;
}
</style>
