<template>
  <div class="es-flow-file">
    <es-upload
      ref="upload"
      v-bind="attrs"
      :param="param"
      :before-remove="delFile"
      :auto-upload="true"
      :ownId="ownId"
      :code="code"
      :disabled="disabled"
      :deleted="deleted"
      :on-success="successFile"
    >
    </es-upload>
  </div>
</template>

<script>
import { delAdjunct } from 'eoss-ui/src/config/api.js';
import util from 'eoss-ui/src/utils/util';
export default {
  name: 'FileList',
  data() {
    return {
      attrs: {
        //autoUpload: false,
        preview: true,
        download: true,
        dragSort: true
      },
      param: {
        userName: util.getStorage('userName')
      }
    };
  },
  props: {
    ownId: {
      type: String,
      default: ''
    },
    code: {
      type: String,
      default: ''
    },
    fileUrl: {
      type: String,
      default: ''
    },
    deleted: {
      type: Boolean,
      default: true
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  mounted() {},
  methods: {
    successFile(response, file, fileList) {
      this.$emit('changeFileNum', fileList.length);
      this.$emit('change-file-num', fileList.length);
    },
    //删除附件
    delFile(file, fileList) {
      let userName =
        file.userName ||
        (file.response && file.response.userName) ||
        util.getStorage('userName');
      let params = {
        url:util.getStorage('dochubConfig')? JSON.parse(util.getStorage('dochubConfig')).deleteDocumentUrl : delAdjunct,
        params: { userName, id: file.adjunctId || file.response.adjunctId,ownId:this.ownId,businessId:this.ownId,bucketCode:this.code,documentId: file.adjunctId || file.response.adjunctId}
      };
      util
        .ajax(params)
        .then((res) => {
          const { rCode, msg } = res;
          if (rCode == 0) {
            this.$message.success('删除成功');
            this.$emit('changeFileNum', fileList.length);
            this.$emit('change-fFile-num', fileList.length);
          } else {
            this.$message.error(msg || '系统错误，请联系管理员！');
          }
        })
        .catch((err) => {
          if (err.message && err.message !== 'canceled') {
            this.$message.error(err.message);
          }
        });
    }
  }
};
</script>

<style></style>
