"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _uuid = _interopRequireDefault(require("uuid"));

var _tooltip = _interopRequireDefault(require("../tooltip"));

var _dialogUploadType = _interopRequireDefault(require("../dialog-upload-type"));

var _dialogQqDocs = _interopRequireDefault(require("../dialog-qq-docs"));

var _Portals = _interopRequireDefault(require("../../components-v1/portals/Portals"));

var _requestV = require("../../utils/request-v1");

var _toast = _interopRequireDefault(require("../toast"));

var _uploadedPreview = _interopRequireDefault(require("./components/uploadedPreview"));

var _type = require("./type");

var _style = require("./style");

var _imgViewer = _interopRequireDefault(require("../img-viewer"));

var _util = require("./util");

var _getLocale = require("../../utils/getLocale");

var _platform = require("../../utils/platform");

var _utils = require("../dialog-qq-docs/utils");

var _tools = require("../../utils/tools");

var _window$BSGlobal, _window$BSGlobal$Tena, _window$BSGlobal$Tena2;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

// 默认在钉钉环境下禁用
var openTencentDocFile = ((_window$BSGlobal = window.BSGlobal) === null || _window$BSGlobal === void 0 ? void 0 : (_window$BSGlobal$Tena = _window$BSGlobal.TenantAdvancedSetting) === null || _window$BSGlobal$Tena === void 0 ? void 0 : (_window$BSGlobal$Tena2 = _window$BSGlobal$Tena.TenantFunAdvancedSetting) === null || _window$BSGlobal$Tena2 === void 0 ? void 0 : _window$BSGlobal$Tena2.TencentDocFile) && !(0, _platform.isDD)(true);

var Upload = /*#__PURE__*/function (_PureComponent) {
  _inherits(Upload, _PureComponent);

  var _super = _createSuper(Upload);

  function Upload(props) {
    var _this;

    _classCallCheck(this, Upload);

    _this = _super.call(this, props);

    _this.onFileInputChange = function (e) {
      var onChange = _this.props.onChange;
      var fileInput = _this.refs.fileInput;

      _this.setState({
        dialogUploadTypeVidible: false
      });

      if (onChange) onChange(e); // @ts-ignore

      var selectFiles = fileInput.files; // 选择的文件
      // @ts-ignore

      if (!fileInput.value) return; // 未选择文件或选择文件超出个数限制时

      _this.dealSelectFiles(Array.from(selectFiles));

      if (fileInput) {
        // @ts-ignore
        fileInput.value = '';
      }
    };

    _this.dealSelectFiles = function (uploadSelectFilesObj) {
      var _this$state = _this.state,
          uploadSuccessFiles = _this$state.uploadSuccessFiles,
          selectFiles = _this$state.selectFiles;
      var _this$props = _this.props,
          action = _this$props.action,
          fileNumLimit = _this$props.fileNumLimit,
          fileSizeLimit = _this$props.fileSizeLimit,
          filesTotal = _this$props.filesTotal;
      var uploadSelectFilesLen = uploadSelectFilesObj.length; // 选中上传的文件数量

      var uploadSuccessFilesLen = uploadSuccessFiles.length; // 已上传成功的文件数量

      var allFilesTotal = uploadSuccessFilesLen + uploadSelectFilesLen; // 把文件字节流保存，用来文件重传用

      uploadSelectFilesObj.forEach(function (ele) {
        if (!selectFiles[ele.name]) {
          selectFiles[ele.name] = ele;
        }
      });

      _this.setState({
        selectFiles: selectFiles
      });

      if (filesTotal && allFilesTotal > filesTotal) {
        _toast["default"].Error("\u6700\u591A\u53EF\u4E0A\u4F20 ".concat(filesTotal, " \u4E2A\u6587\u4EF6"), {
          canClose: false
        });

        uploadSelectFilesObj = uploadSelectFilesObj.slice(0, filesTotal - uploadSuccessFilesLen);
      }

      if (fileNumLimit && uploadSelectFilesObj.length > fileNumLimit) {
        _toast["default"].Error("\u5355\u6B21\u6700\u591A\u53EF\u4E0A\u4F20 ".concat(fileNumLimit, " \u4E2A\u6587\u4EF6"), {
          canClose: false
        });

        uploadSelectFilesObj = uploadSelectFilesObj.slice(0, fileNumLimit);
      }

      if (!uploadSelectFilesObj.length) return;
      var uploadSelectFilesSize = uploadSelectFilesObj.map(function (item) {
        return item.size;
      }).reduce(function (total, num) {
        return total + num;
      }); // 上传文件的大小

      if (uploadSelectFilesSize > fileNumLimit * fileSizeLimit * 1024 * 1024) return _toast["default"].Error("\u5355\u6B21\u6700\u591A\u53EF\u4E0A\u4F20 ".concat(fileNumLimit, " \u4E2A\u6587\u4EF6\uFF0C\u6BCF\u4E2A\u4E0D\u8D85\u8FC7 ").concat(fileSizeLimit, "M")); // 文件大小超出限制

      var uploadStartFiles = []; // 开始上传的文件

      uploadSelectFilesObj.forEach(function (element, index) {
        var formData = new FormData(); // FormData 对象

        var uploadStartFile = null;
        var timestamp = new Date().getTime(); // 给每个文件加一个时间戳

        var uploadFileType = element.name.substring(element.name.lastIndexOf('.') + 1);
        uploadStartFile = {
          FileName: element.name,
          FileType: (0, _type._dealAttachmentType)(uploadFileType).FileType,
          FileSize: element.size,
          FileLastModified: element.lastModified,
          IsImage: (0, _type._dealAttachmentType)(uploadFileType).IsImage,
          percentComplete: 0,
          uploadStatus: 1,
          // 开始上传
          IsSuccess: false,
          uid: (0, _uuid["default"])(),
          _smallImageUrl: '',
          _bigImageUrl: '',
          MediaType: '',
          UserId: 0,
          MaxDocCount: 0,
          DfsPath: '',
          ClientUrl: '',
          SmallImageUrl: '',
          BigImageUrl: '',
          DownloadUrl: '',
          Msg: '',
          AllowUploadAttachmentSize: 50,
          Deleteable: true,
          requestXHR: new XMLHttpRequest() // 在这创建是为了取消用

        };
        var sameFile = uploadSuccessFiles.find(function (file) {
          return _this.isSameFile(file, uploadStartFile) && file.uploadStatus !== 4;
        });

        if (sameFile) {
          return;
        }

        uploadStartFiles.push(uploadStartFile);

        _this._dealUploadStart(uploadStartFiles); // 处理开始上传的文件


        formData.append('file', element);
        var url = action || (0, _requestV.getApiUrl)("Upload/PostFiles?format=json&timestamp=".concat(timestamp));

        _this._dealUploadXHRRequest(formData, url, uploadStartFile);
      });
    };

    _this._dealUploadXHRRequest = function (formData, url, uploadStartFile) {
      if (uploadStartFile.FileSize > _this.props.fileSizeLimit * 1024 * 1024) {
        setTimeout(function () {
          _this._dealUploadSuccess(_objectSpread(_objectSpread({}, uploadStartFile), {
            Msg: '上传失败，文件过大',
            IsImage: false,
            uploadStatus: 5
          }));
        }, 300);
        return;
      }

      var xhr = uploadStartFile.requestXHR; // xhr.onreadystatechange = () => {
      //   if (xhr.readyState == 4 && xhr.status == 200) {
      //     const result = { ...JSON.parse(xhr.responseText).Result[0] }; // 上传成功接口返回数据
      //     result.percentComplete = 100;
      //     result.IsSuccess = !!result.IsSuccess;
      //     result.uploadStatus = result.IsSuccess ? 3 : 4; // 3上传成功；4上传失败
      //     this._dealUploadSuccess({ ...uploadStartFile, ...result });
      //   }
      // };
      // // 进度条部分
      // xhr.upload.onprogress = (evt) => {
      //   const uploadSuccessFiles = [...this.state.uploadSuccessFiles];
      //   if (evt.lengthComputable) {
      //     uploadSuccessFiles.forEach((item: UploadResultObj) => {
      //       if (this.isSameFile(item, uploadStartFile)) {
      //         item.uploadStatus = 2; // 上传中
      //         item.percentComplete = Math.round((evt.loaded * 100) / evt.total);
      //       }
      //     });
      //     this.setState({ uploadSuccessFiles });
      //   }
      // };

      xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
          var result = Object.assign({}, _objectSpread({}, JSON.parse(xhr.responseText).Result[0])); // 上传成功接口返回数据

          result.percentComplete = 100;
          result.IsSuccess = !!result.IsSuccess;
          result.uploadStatus = result.IsSuccess ? 3 : 4; // 3上传成功；4上传失败

          _this._dealUploadSuccess(_objectSpread(_objectSpread({}, uploadStartFile), result));
        }
      }; //进度条部分


      xhr.upload.onprogress = function (evt) {
        var uploadSuccessFiles = JSON.parse(JSON.stringify(_this.state.uploadSuccessFiles));

        if (evt.lengthComputable) {
          uploadSuccessFiles.forEach(function (item) {
            if (_this.isSameFile(item, uploadStartFile)) {
              item.uploadStatus = 2; // 上传中

              item.percentComplete = Math.round(evt.loaded * 100 / evt.total);
            }
          });

          _this.setState({
            uploadSuccessFiles: uploadSuccessFiles
          });
        }
      };

      xhr.upload.onerror = function (evt) {
        var uploadSuccessFiles = _toConsumableArray(_this.state.uploadSuccessFiles);

        uploadSuccessFiles.forEach(function (item) {
          if (_this.isSameFile(item, uploadStartFile)) {
            item.uploadStatus = 4; // 上传失败

            item.percentComplete = Math.round(evt.loaded * 100 / evt.total);
            item.Msg = '网络异常，请重新上传';
          }
        });

        _this.setState({
          uploadSuccessFiles: uploadSuccessFiles
        });
      };

      xhr.open('POST', url, true);
      xhr.send(formData); // 开始上传，发送form数据
    };

    _this._dealUploadStart = function (uploadStartFiles) {
      var uploadSuccessFiles = [];

      var uploadedFiles = _toConsumableArray(_this.state.uploadSuccessFiles); // 处理重传文件,直接展开会导致同样的文件展示两个


      var uploadFilesConcatArr = uploadedFiles;
      var isReloadFile = uploadFilesConcatArr.filter(function (item) {
        return _this.isSameFile(item, uploadStartFiles[0]);
      });

      if (!isReloadFile || isReloadFile.length === 0) {
        uploadFilesConcatArr = [].concat(_toConsumableArray(uploadedFiles), _toConsumableArray(uploadStartFiles));
      }

      uploadFilesConcatArr.forEach(function (item) {
        var res = uploadSuccessFiles.filter(function (v) {
          return _this.isSameFile(item, v);
        });
        uploadSuccessFiles.forEach(function (element) {
          if (_this.isSameFile(item, element)) {
            element = item;
          }
        });

        if (res.length === 0) {
          uploadSuccessFiles.push(item);
        }
      });

      _this.setState({
        uploadSuccessFiles: uploadSuccessFiles
      });
    };

    _this._dealUploadSuccess = function (uploadSuccessFile) {
      var _this$props2 = _this.props,
          onSubmit = _this$props2.onSubmit,
          onUploadSuccess = _this$props2.onUploadSuccess;

      var uploadSuccessFiles = _toConsumableArray(_this.state.uploadSuccessFiles);

      var uploadSuccessFilesFormat = uploadSuccessFiles.map(function (element) {
        return _this.isSameFile(uploadSuccessFile, element) ? uploadSuccessFile : element;
      });
      var uploadSuccessFilesPath = uploadSuccessFilesFormat.map(function (item) {
        return item.DfsPath;
      }); // 获取文件上传后返回的路径

      onSubmit(uploadSuccessFilesPath); // 将上传完成的文件路径传递给父组件

      if (onUploadSuccess) onUploadSuccess(uploadSuccessFilesFormat);

      _this.setState({
        uploadSuccessFiles: uploadSuccessFilesFormat,
        attachmentPreviewUrl: (0, _util.getPreviewImgs)(uploadSuccessFilesFormat)
      });
    };

    _this.isImg = function (fileType) {
      if (/^(jpg|png|gif|jpeg|image|JPG|PNG|GIF|JPEG)$/.test(fileType)) {
        return true;
      }

      return false;
    };

    _this.getImgIndex = function (index) {
      var newIndex = 0;
      var uploadSuccessFiles = _this.state.uploadSuccessFiles;

      for (var i = 0; i < index; i++) {
        if (_this.isImg(uploadSuccessFiles[i].FileType)) {
          newIndex++;
        }
      }

      return newIndex;
    };

    _this.handlerUploadPreviewOptions = function (index, options) {
      var _this$props3 = _this.props,
          onSubmit = _this$props3.onSubmit,
          onDelete = _this$props3.onDelete;

      if (options === 'cancel') {
        var reUploadFileInfo = _this.state.uploadSuccessFiles[index];
        reUploadFileInfo.requestXHR.abort();
      }

      if (options === 'delete' || options === 'cancel') {
        var uploadResultFiles = _toConsumableArray(_this.state.uploadSuccessFiles);

        var deleteFiles = uploadResultFiles[index];
        onDelete && onDelete(deleteFiles.documentId ? deleteFiles.documentId : deleteFiles.DfsPath);
        uploadResultFiles.splice(index, 1);

        var _uploadSuccessFilesPath = uploadResultFiles.map(function (item) {
          return item.DfsPath;
        });

        onSubmit(_uploadSuccessFilesPath, options);

        _this.setState({
          uploadSuccessFiles: uploadResultFiles
        });
      } else if (options === 'preview') {
        var _uploadResultFiles = _toConsumableArray(_this.state.uploadSuccessFiles);

        var currentFiles = _uploadResultFiles[index];

        if (currentFiles.SmallImageUrl) {
          var imgIndex = _this.getImgIndex(index);

          _this.refs.imgViewerRef.show(imgIndex);
        } else if (currentFiles.ClientUrl) {
          (0, _tools.openUrl)(currentFiles.ClientUrl);
        }
      } else if (options === 'reupload') {
        var _reUploadFileInfo = _this.state.uploadSuccessFiles[index];
        var reUploadFile = _this.state.selectFiles[_reUploadFileInfo.FileName];

        _this.dealSelectFiles([reUploadFile]);
      }
    };

    _this.isSameFile = function (item, element) {
      return item.FileName === element.FileName && item.FileSize === element.FileSize && item.FileLastModified === element.FileLastModified;
    };

    _this.renderUploadList = function (list) {
      var _this$props4 = _this.props,
          attachmentPreviewBox = _this$props4.attachmentPreviewBox,
          _this$props4$showFile = _this$props4.showFileList,
          showFileList = _this$props4$showFile === void 0 ? true : _this$props4$showFile;
      var attachmentPreviewUrl = _this.state.attachmentPreviewUrl;
      if (!list.length || !showFileList) return '';
      return /*#__PURE__*/_react["default"].createElement(_Portals["default"], {
        domNode: attachmentPreviewBox,
        className: "uploadFile__preview__list"
      }, /*#__PURE__*/_react["default"].createElement(_imgViewer["default"], {
        data: attachmentPreviewUrl,
        ref: "imgViewerRef",
        showDownload: false
      }), list.map(function (item, index) {
        return /*#__PURE__*/_react["default"].createElement(_uploadedPreview["default"], {
          uploadResultItem: item,
          index: index,
          key: item.uid,
          className: "uploaded__preview",
          onSubmit: function onSubmit(index, options) {
            _this.handlerUploadPreviewOptions(index, options);
          }
        });
      }));
    };

    _this.handleButtonClick = function (e) {
      e.nativeEvent.stopImmediatePropagation();

      if (openTencentDocFile) {
        _this.setState({
          dialogUploadTypeVidible: true
        });

        return;
      }

      if (_this.refs.fileInput) {
        // @ts-ignore
        _this.refs.fileInput.click();
      }
    };

    _this.hideDialogQQDocsVidible = function () {
      _this.setState({
        dialogQQDocsVidible: false
      });
    };

    _this.hideDialogUploadTypeVidible = function () {
      _this.setState({
        dialogUploadTypeVidible: false
      });
    };

    _this.onSelectLocalFife = function () {
      if (_this.refs.fileInput) {
        // @ts-ignore
        _this.refs.fileInput.click();
      }
    };

    _this.onShowDialogQQDocs = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
      var data;
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return (0, _utils.checkTencentAuth)({});

            case 2:
              data = _context.sent;

              if (data) {
                _context.next = 5;
                break;
              }

              return _context.abrupt("return");

            case 5:
              // 设置默认的文档数据，避免在弹窗内部再查询一次
              _this.setState({
                defaultQQDocsData: data,
                dialogQQDocsVidible: true
              });

            case 6:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));

    _this.qqDocsFormat = function (qqDocsList) {
      return qqDocsList.map(function (element) {
        var uploadStartFile = {
          FileName: element.title,
          FileType: element.type,
          FileSize: element.size,
          FileLastModified: element.lastModified,
          IsImage: false,
          percentComplete: 0,
          uploadStatus: 3,
          // 开始上传
          IsSuccess: true,
          uid: (0, _uuid["default"])(),
          _smallImageUrl: '',
          _bigImageUrl: '',
          MediaType: '',
          UserId: 0,
          MaxDocCount: 0,
          DfsPath: "".concat(element.url, "|").concat(element.type, "|").concat(element.title, "|tencentdoc"),
          ClientUrl: element.url,
          SmallImageUrl: '',
          BigImageUrl: '',
          DownloadUrl: '',
          Msg: '',
          AllowUploadAttachmentSize: 50,
          Deleteable: true,
          requestXHR: new XMLHttpRequest() // 在这创建是为了取消用

        };
        return uploadStartFile;
      });
    };

    _this.onSelectQQDocsFileHandler = function (checkedDocsList) {
      var uploadSuccessFiles = _this.state.uploadSuccessFiles;
      var onSubmit = _this.props.onSubmit;

      var newFileList = _this.qqDocsFormat(checkedDocsList);

      var newUploadSuccessFiles = [].concat(_toConsumableArray(uploadSuccessFiles), _toConsumableArray(newFileList));

      _this.setState({
        uploadSuccessFiles: newUploadSuccessFiles
      });

      _this.setState({
        dialogQQDocsVidible: false,
        dialogUploadTypeVidible: false
      });

      onSubmit(newUploadSuccessFiles.map(function (item) {
        return item.DfsPath;
      }));
    };

    _this.state = {
      uploadSuccessFiles: props.attachments || [],
      attachmentPreviewUrl: props.attachments ? (0, _util.getPreviewImgs)(props.attachments) : [],
      selectFiles: {},
      dialogUploadTypeVidible: false,
      dialogQQDocsVidible: false
    };
    return _this;
  }

  _createClass(Upload, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var attachments = this.props.attachments;
      this.setState({
        uploadSuccessFiles: attachments || [],
        attachmentPreviewUrl: attachments ? (0, _util.getPreviewImgs)(attachments) : []
      });
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      if (this.props.submitStatus === 2 && nextProps.submitStatus == 1) {
        this.setState({
          uploadSuccessFiles: [],
          attachmentPreviewUrl: []
        });
      } else {
        this.setState({
          // uploadSuccessFiles: nextProps.attachments || [],
          attachmentPreviewUrl: nextProps.attachments ? (0, _util.getPreviewImgs)(nextProps.attachments) : []
        });
      }

      if (nextProps.dragFilesList && nextProps.dragFilesList.length) {
        this.dealSelectFiles(nextProps.dragFilesList);
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props5 = this.props,
          children = _this$props5.children,
          className = _this$props5.className,
          style = _this$props5.style,
          _this$props5$attachme = _this$props5.attachmentTipText,
          attachmentTipText = _this$props5$attachme === void 0 ? (0, _getLocale.getLocale)('OKR_MyO_KRP_Draganddropu') : _this$props5$attachme,
          _this$props5$disableT = _this$props5.disableTooltip,
          disableTooltip = _this$props5$disableT === void 0 ? false : _this$props5$disableT,
          fileNumLimit = _this$props5.fileNumLimit;
      var _this$state2 = this.state,
          uploadSuccessFiles = _this$state2.uploadSuccessFiles,
          dialogUploadTypeVidible = _this$state2.dialogUploadTypeVidible,
          dialogQQDocsVidible = _this$state2.dialogQQDocsVidible,
          defaultQQDocsData = _this$state2.defaultQQDocsData;

      var uploadFormContainer = /*#__PURE__*/_react["default"].createElement(_style.UploadFormContainer, {
        className: className,
        style: style,
        onMouseUp: function onMouseUp(e) {
          return _this2.handleButtonClick(e);
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        ref: "uploader-trigger",
        style: {
          cursor: 'pointer'
        }
      }, children), /*#__PURE__*/_react["default"].createElement("input", {
        type: "file",
        ref: "fileInput",
        className: "upload_file_input",
        multiple: this.props.multiple,
        style: {
          display: 'none'
        },
        onChange: this.onFileInputChange
      }));

      return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_dialogUploadType["default"], {
        onSelectLocal: this.onSelectLocalFife,
        onSelectQQDocs: this.onShowDialogQQDocs,
        visible: dialogUploadTypeVidible,
        onClose: this.hideDialogUploadTypeVidible
      }), /*#__PURE__*/_react["default"].createElement(_dialogQqDocs["default"], {
        fileNumLimit: fileNumLimit,
        defaultQQDocsData: defaultQQDocsData,
        visible: dialogQQDocsVidible,
        onClose: this.hideDialogQQDocsVidible,
        onSubmit: this.onSelectQQDocsFileHandler
      }), disableTooltip ? uploadFormContainer : /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
        getTooltipContainer: function getTooltipContainer() {
          return document.body;
        },
        overlay: /*#__PURE__*/_react["default"].createElement("p", {
          dangerouslySetInnerHTML: {
            __html: attachmentTipText
          }
        })
      }, uploadFormContainer), this.renderUploadList(uploadSuccessFiles));
    }
  }]);

  return Upload;
}(_react.PureComponent);

Upload.Preview = _uploadedPreview["default"];
Upload.defaultProps = {
  fileNumLimit: 20,
  fileSizeLimit: 50,
  filesTotal: 50,
  multiple: true,
  attachmentPreviewBox: 'MBlog__attachmentViewBox'
};
var _default = Upload;
exports["default"] = _default;