"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _amosReactRouter = require("amos-react-router"),
  _amosFramework = require("amos-framework"),
  endConf = _interopRequireWildcard(require("amos-processor/lib/config/endconf")),
  _cacheUtils = require("./../../utils/cacheUtils"),
  _navApi = require("./../../services/navApi"),
  _securityService = require("./../../services/securityService"),
  _storageConsts = require("../../consts/storageConsts"),
  _amosTool = require("amos-tool"),
  _consts = _interopRequireDefault(require("amos-processor/lib/config/consts"));

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, n, o = {},
    a = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((n = a ? Object.getOwnPropertyDescriptor(e, r) : null) && (n.get || n.set) ? Object.defineProperty(o, r, n) : o[r] = e[r]);
  return o.default = e, t && t.set(e, o), o
}

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 n = t[r];
    n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n)
  }
}

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 n = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, n ? (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 lsTool = _amosTool.Store.lsTool,
  AmosConfig = endConf.AmosConfig,
  isAutoOpen = AmosConfig.sysConf.isAutoOpenBussiness,
  FormItem = _amosFramework.Form.Item,
  Option = _amosFramework.Select.Option,
  RegionSelect = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var c;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(c = t.call(this, e)), "onClick", function() {
        var n = c.state.reginParams;
        lsTool.remove("selectedRole"), (0, _navApi.regionSelectAction)(n).then(function(e) {
          var t = c.props.location.state,
            r = (n.role || {}).sequenceNbr;
          lsTool.write("selectedRole", r), t ? (_amosReactRouter.browserHistory.push("/main"), lsTool.write(_storageConsts.CONSTS.region_change, {
            refresh: {
              refresh: !0
            }
          })) : _amosReactRouter.browserHistory.push("/main")
        })
      }), _defineProperty(_assertThisInitialized(c), "onSelectChange", function(e, t) {
        var r = c.state.userInfo,
          n = r.companys,
          o = void 0 === n ? [] : n,
          a = r.companyDepartments,
          i = void 0 === a ? {} : a,
          s = r.orgRoles,
          n = void 0 === s ? {} : s,
          a = c.state.reginParams,
          r = c.state,
          s = r.departments,
          s = void 0 === s ? [] : s,
          r = r.roles,
          r = void 0 === r ? [] : r;
        "company" === e && (a.company = o.find(function(e) {
          return e.sequenceNbr === t
        }), s = i[t], r = n[t]), "department" === e && (a.department = s.find(function(e) {
          return e.sequenceNbr === t
        }), r = n[t]), "role" === e && (a.role = r.find(function(e) {
          return e.sequenceNbr === t
        })), c.setState({
          reginParams: a,
          departments: s,
          roles: r
        })
      }), _defineProperty(_assertThisInitialized(c), "getCurrentUser", function() {
        (0, _securityService.getCurrentUser)().then(function(e) {
          var t = c.state.reginParams,
            r = e.companys,
            n = void 0 === r ? [] : r,
            o = e.companyDepartments,
            r = void 0 === o ? {} : o,
            o = e.orgRoles,
            o = void 0 === o ? {} : o;
          lsTool.write(_consts.default.userId, e.userId), lsTool.write(_consts.default.company, JSON.stringify(n)), lsTool.write(_consts.default.userName, e.userName), lsTool.write(_consts.default.nickName, e.realName), 1 === n.length ? 1 === (n = r[(r = n[0]).sequenceNbr] || []).length && 1 === (o[r.sequenceNbr] || o[n[0].sequenceNbr] || []).length ? (t.company = r, t.department = n[0], t.role = o[r.sequenceNbr] ? o[r.sequenceNbr][0] : o[n[0].sequenceNbr] ? o[n[0].sequenceNbr][0] : {}, c.setState({
            reginParams: t
          }, function() {
            return c.onClick()
          })) : 0 === n.length && 1 === (o[r.sequenceNbr] || []).length ? (t.company = r, t.department = {}, t.role = o[r.sequenceNbr][0], c.setState({
            reginParams: t
          }, function() {
            return c.onClick()
          })) : c.setState({
            userInfo: e
          }) : c.setState({
            userInfo: e
          })
        })
      }), _defineProperty(_assertThisInitialized(c), "renderItem", function(e) {
        var t = e.userId,
          r = e.companys,
          n = void 0 === r ? [] : r,
          o = c.state,
          e = o.departments,
          r = void 0 === e ? [] : e,
          e = o.roles,
          o = void 0 === e ? [] : e,
          e = r.filter(function(e) {
            return null != e && void 0 !== e
          }),
          r = {
            wrapperCol: {
              xs: {
                span: 24
              },
              sm: {
                span: 24
              },
              className: "colspan"
            }
          };
        return _react.default.createElement("div", {
          key: t,
          className: "region-item"
        }, _react.default.createElement(_amosFramework.Form, {
          className: "region-form"
        }, _react.default.createElement(FormItem, r, _react.default.createElement(_amosFramework.Select, {
          className: "form-item",
          data: n,
          renderOption: function(e) {
            return _react.default.createElement(Option, {
              value: e.sequenceNbr
            }, e.companyName)
          },
          defaultOption: _react.default.createElement(Option, null, "请选择公司"),
          onChange: function(e) {
            return c.onSelectChange("company", e)
          }
        })), _react.default.createElement(FormItem, r, _react.default.createElement(_amosFramework.Select, {
          className: "form-item",
          data: e,
          renderOption: function(e) {
            return _react.default.createElement(Option, {
              value: e.sequenceNbr
            }, e.departmentName)
          },
          defaultOption: _react.default.createElement(Option, null, "请选择部门"),
          onChange: function(e) {
            return c.onSelectChange("department", e)
          }
        })), _react.default.createElement(FormItem, r, _react.default.createElement(_amosFramework.Select, {
          className: "form-item",
          data: o,
          renderOption: function(e) {
            return _react.default.createElement(Option, {
              value: e.sequenceNbr
            }, e.roleName)
          },
          defaultOption: _react.default.createElement(Option, null, "请选择角色"),
          onChange: function(e) {
            return c.onSelectChange("role", e)
          }
        })), _react.default.createElement(FormItem, r, _react.default.createElement("img", {
          src: "",
          alt: ""
        })), _react.default.createElement(FormItem, null, _react.default.createElement(_amosFramework.Button, {
          className: "regoin-button",
          onClick: c.onClick
        }, "确定"))))
      }), c.state = {
        userInfo: {},
        reginParams: {}
      }, c
    }
    return _createClass(r, [{
      key: "componentDidMount",
      value: function() {
        this.getCurrentUser()
      }
    }, {
      key: "render",
      value: function() {
        var e = this.state.userInfo;
        return 0 < Object.keys(e).length ? _react.default.createElement("div", {
          className: "region-select"
        }, this.renderItem(e)) : null
      }
    }]), r
  }();
RegionSelect.displayName = "RegionSelect", RegionSelect.propTypes = {
  location: _propTypes.default.object
};
var _default = RegionSelect;
exports.default = RegionSelect, module.exports = exports.default;
