"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _urlConsts = require("./../../../../consts/urlConsts"),
  _amosAntd = require("amos-antd"),
  _amosFramework = require("amos-framework"),
  _amosIcon = _interopRequireDefault(require("amos-icon")),
  _topoService = require("./../../../../services/topoService");

function _interopRequireDefault(e) {
  return e && e.__esModule ? e : {
    default: e
  }
}

function _getRequireWildcardCache() {
  if ("function" != typeof WeakMap) return null;
  var e = new WeakMap;
  return _getRequireWildcardCache = function() {
    return e
  }, e
}

function _interopRequireWildcard(e) {
  if (e && e.__esModule) return e;
  if (null === e || "object" !== _typeof(e) && "function" != typeof e) return {
    default: e
  };
  var t = _getRequireWildcardCache();
  if (t && t.has(e)) return t.get(e);
  var r, i, n = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((i = o ? Object.getOwnPropertyDescriptor(e, r) : null) && (i.get || i.set) ? Object.defineProperty(n, r, i) : n[r] = e[r]);
  return n.default = e, t && t.set(e, n), n
}

function _typeof(e) {
  return (_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e
  } : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  })(e)
}

function _classCallCheck(e, t) {
  if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function")
}

function _defineProperties(e, t) {
  for (var r = 0; r < t.length; r++) {
    var i = t[r];
    i.enumerable = i.enumerable || !1, i.configurable = !0, "value" in i && (i.writable = !0), Object.defineProperty(e, i.key, i)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), e
}

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

function _setPrototypeOf(e, t) {
  return (_setPrototypeOf = Object.setPrototypeOf || function(e, t) {
    return e.__proto__ = t, e
  })(e, t)
}

function _createSuper(r) {
  var i = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, i ? (e = _getPrototypeOf(this).constructor, Reflect.construct(t, arguments, e)) : t.apply(this, arguments))
  }
}

function _possibleConstructorReturn(e, t) {
  return !t || "object" !== _typeof(t) && "function" != typeof t ? _assertThisInitialized(e) : t
}

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

function _isNativeReflectConstruct() {
  if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
  if (Reflect.construct.sham) return !1;
  if ("function" == typeof Proxy) return !0;
  try {
    return Date.prototype.toString.call(Reflect.construct(Date, [], function() {})), !0
  } catch (e) {
    return !1
  }
}

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

function _defineProperty(e, t, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
var HEXSIZE = 1024,
  UploadMultiPicModal = function() {
    _inherits(i, _react.Component);
    var r = _createSuper(i);

    function i(e) {
      var t;
      return _classCallCheck(this, i), _defineProperty(_assertThisInitialized(t = r.call(this, e)), "onClick", function() {
        t.setState({
          visible: !0
        })
      }), _defineProperty(_assertThisInitialized(t), "fetchImgData", function(e) {
        e && (0, _topoService.fetchOrgImgsAction)(e).then(function(e) {
          t.setState({
            imgFiles: e.imgFiles
          })
        })
      }), _defineProperty(_assertThisInitialized(t), "handCancel", function() {
        t.setState({
          visible: !1
        })
      }), _defineProperty(_assertThisInitialized(t), "handSubmit", function() {
        var e = {
          imgFiles: t.state.imgFiles,
          orgCode: t.props.currentNode.key
        };
        (0, _topoService.editOrgImgAction)(e).then(function(e) {
          _amosFramework.message.success("操作成功"), t.setState({
            visible: !1
          })
        })
      }), _defineProperty(_assertThisInitialized(t), "uploadCompanyPics", function() {
        t.setState({
          visible: !0
        })
      }), _defineProperty(_assertThisInitialized(t), "handleCancel", function() {
        return t.setState({
          previewVisible: !1
        })
      }), _defineProperty(_assertThisInitialized(t), "handlePreview", function(e) {
        t.setState({
          previewImage: e.url || e.thumbUrl,
          previewVisible: !0
        })
      }), _defineProperty(_assertThisInitialized(t), "handleChange", function(e) {
        e = e.fileList;
        t.setState({
          imgFiles: e
        })
      }), _defineProperty(_assertThisInitialized(t), "beforeUpload", function(e) {
        var t = /image\/(gif|jpeg|png|jpg|bmp)$/.test(e.type);
        t || _amosFramework.message.danger("请选择符合格式的图片！（gif|jpeg|png|jpg|bmp）");
        e = e.size / HEXSIZE / HEXSIZE < 4;
        return e || _amosFramework.message.danger("图片最大为 4MB!"), t && e
      }), t.state = {
        visible: !1,
        previewVisible: !1,
        previewImage: "",
        imgFiles: []
      }, t
    }
    return _createClass(i, [{
      key: "componentWillMount",
      value: function() {}
    }, {
      key: "componentDidMount",
      value: function() {
        this.fetchImgData(this.props.currentNode.key)
      }
    }, {
      key: "componentWillReceiveProps",
      value: function(e) {
        this.props.currentNode.key !== e.currentNode.key && this.fetchImgData(e.currentNode.key)
      }
    }, {
      key: "render",
      value: function() {
        var e = this.state,
          t = e.previewVisible,
          r = e.previewImage,
          i = e.imgFiles,
          n = this.props.maxImg,
          o = _react.default.createElement("div", null, _react.default.createElement(_amosIcon.default, {
            type: "plus"
          }), _react.default.createElement("div", {
            className: "ant-upload-text"
          }, "添加图片")),
          e = _urlConsts.OltSerUrl.addDevice;
        return _react.default.createElement("div", {
          className: "upload-img-root"
        }, _react.default.createElement("div", {
          className: "upload-img-icon",
          onClick: this.uploadCompanyPics,
          title: "上传图片"
        }, _react.default.createElement(_amosIcon.default, {
          icon: "file-upload"
        })), _react.default.createElement(_amosAntd.Modal, {
          maskClosable: !1,
          title: "上传图片",
          closable: !0,
          visible: this.state.visible,
          onCancel: this.handCancel,
          onOk: this.handSubmit,
          width: 367
        }, _react.default.createElement("div", {
          className: "upload-pics-content"
        }, _react.default.createElement(_amosAntd.Upload, {
          action: e,
          listType: "picture-card",
          fileList: i,
          onPreview: this.handlePreview,
          onChange: this.handleChange,
          beforeUpload: this.beforeUpload
        }, i.length >= n ? null : o), _react.default.createElement(_amosAntd.Modal, {
          visible: t,
          footer: null,
          onCancel: this.handleCancel
        }, _react.default.createElement("img", {
          alt: "example",
          style: {
            width: "100%"
          },
          src: r
        })))))
      }
    }]), i
  }();
UploadMultiPicModal.displayName = "UploadMultiPicModal", UploadMultiPicModal.propTypes = {
  currentNode: _propTypes.default.object,
  maxImg: _propTypes.default.number
};
var _default = UploadMultiPicModal;
exports.default = UploadMultiPicModal, module.exports = exports.default;
