<template>
  <div class="view-FileUploads">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="文件类型">
        <el-radio-group v-model="form.fileType">
          <el-radio v-for="(radio, index) in filesList" :key="index" :label="radio.value">{{ radio.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="选择文件">
        <el-upload class="upload-demo" ref="uploadEl" action="#" :on-change="handleChange" :on-remove="handleRemove" :before-remove="beforeRemove" multiple :limit="1" :file-list="form.files" :auto-upload="false">
          <el-button size="small" type="primary">选取文件</el-button>
        </el-upload>
      </el-form-item>
    </el-form>
    <div class="view-FileUpload-footer-btn">
      <el-button type="primary" @click="onSubmit">确定</el-button>
    </div>
  </div>
</template>

<script>
import { filesList } from '../index'
export default {
  name: 'FileUpload',
  data() {
    // 这里存放数据
    return {
      filesList: filesList,
      action: process.env.VUE_APP_BASE_API + '/supportMaterial/upload',
      form: {
        fileType: '1',
        files: []
      }
    }
  },
  mounted() {},
  methods: {
    beforeRemove() {},

    handlePreview() {},

    onSuccess(response) {
      const { id } = response.data[0]
      this.form.files.push(response.data)
    },

    handleRemove(file, fileList) {
      const files = this.$refs.uploadEl.uploadFiles
      for (let i = 0; i < files.length; i++) {
        if (files[i]['url'] === file.url) {
          files.splice(i, 1)
          this.form.files.splice(i, 1)
        }
      }
    },
    handleChange(file, fileList) {
      this.form.files = fileList.slice(-3)
    },
    onSubmit() {
      this.$router.push('/fileManagement/knowledgeExtraction')
    }
  }
}
</script>

<style lang="scss">
@import '../index.scss';
</style>
