<!--导出 -->
<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="数据导出记录：">
      <el-table :data="outputList" border style="width: 100%" height="600">
        <el-table-column prop="markFormatType" label="标注格式类型">
        </el-table-column>
        <el-table-column prop="outputContent" label="导出内容">
        </el-table-column>
        <el-table-column prop="fileSize" label="文件大小">
        </el-table-column>
        <el-table-column prop="dataCount" label="数据量">
        </el-table-column>
        <el-table-column prop="createUserId" label="创建人">
        </el-table-column>
        <el-table-column prop="outputStartTime" label="导出开始时间" width="150">
        </el-table-column>
        <el-table-column prop="outputEndTime" label="导出完成时间" width="150">
        </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            {{ OutputStatus.getValue(scope.row.status) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button @click="down(scope.row.downloadUrl)" type="text" size="mini">
              下载
            </el-button>
          </template>
        </el-table-column>

      </el-table>
    </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'
export default {
  data() {
    return {
      outputList: [],
      form: {
        format: 'jsonl'
      }
    }
  },
  props: ['isEdit', 'row'],
  components: {},

  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('下载成功')
      })
      // this.download('/admin/app/datasetVersion/export', params, '下载文件.' + this.form.format, 'get').then(res => {
      //   // resolve(res);
      //   console.log(res);
      //   this.$message.success('下载成功');
      //   this.onCancel(true);
      // }).catch(e => {
      //   // reject(e);
      // });
    },
    down(url) {
      let downDom = document.createElement('a')
      downDom.href = url
      downDom.click()
    },
    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>
