<!--文件上传组件-->
<template>
  <div>
    <el-dialog
      :title="title"
      :close-on-click-modal="false"
	  draggable
      width="1400px"
      height="500px"
      @close="close"
      append-to-body
      v-model="visible">
      <UpLoadComponentV2 ref="upLoadComponentV2"></UpLoadComponentV2>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
      <el-button type="primary" icon="el-icon-circle-check" @click="doSubmit()">确定</el-button>
    </span>
    </el-dialog>

  </div>
</template>

<script>
  import UpLoadComponentV2 from './UpLoadComponentV2'
  export default {
    data () {
      return {
        visible: false,
        title: '',
        index: ''
      }
    },
    computed: {
    },
    watch: {
    },
    created () {
    },
    components: {
      UpLoadComponentV2
    },
    mounted () {
    },
    methods: {
      /**
       * 文件上传组件初始化
       * @param auth
       *    auth的值为"view"时,不可上传/编辑文件
       *    auth为其他值时,可上传/编辑文件
       * @param fileList  要显示到文件上传列表中的文件。
       *    注：文件必须要有url属性并且文件的url属性值必须是在oss中的路径值
       *    例：'/attachment-file/xxx/xxx/2022/9/08/xxx.jpg'
       * @param directory  要存放到oss的哪个文件夹下。
       *    注：值为空时，默认存放到"public"文件夹
       * @param maxValue  上传文件允许的最大值，单位：MB
       *    注：值为空时，默认值为300MB
       * @param dividerName  组件中divider的名称
       *    注：值为空时，默认值为‘附件’
       * @param uploadFlag  ‘上传文件’按钮是否禁用
       *    注：值为空时，默认值为false
       *    auth=view&&uploadFlag=false时 ‘上传文件’按钮禁用
       * @param delFlag  ‘删除’按钮是否禁用
       *    注：值为空时，默认值为false
       *    auth=view&&delFlag=false时 ‘删除’按钮禁用
       * @param showDivider  ‘附件‘Divider是否展示
       *    注：值为空时，默认值为true
       *    showDivider=false时 ‘附件‘Divider隐藏
       */
      newUpload (auth, fileList, directory, maxValue, dividerName, uploadFlag, delFlag, showDivider, index) {
        this.index = index
        this.title = '附件'
        this.visible = true
        this.$nextTick(() => {
          this.$refs.upLoadComponentV2.newUpload(auth, fileList, directory, maxValue, dividerName, uploadFlag, delFlag, showDivider)
        })
      },
      doSubmit () {
        if (!this.$refs.upLoadComponentV2.checkProgress()) {
          this.$emit('getUpload', this.$refs.upLoadComponentV2.getDataList(), this.index)
          this.close()
        }
      },
      close () {
        this.$refs.upLoadComponentV2.clearUpload()
        this.visible = false
      }
    }
  }
</script>
