"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"), _typeof = require("@babel/runtime/helpers/typeof");

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")), _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")), _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")), _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")), _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")), _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")), _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")), _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _react = _interopRequireWildcard(require("react")), _propTypes = _interopRequireDefault(require("prop-types")), _processor = require("./../../common/utils/processor"), _amosAntd = require("amos-antd"), _amosFramework = require("amos-framework"), _validate = require("./../../common/utils/validate");

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

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

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var a, r = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var l = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, l);
    } else a = r.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, a);
  };
}

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

var FormItem = _amosAntd.Form.Item, Option = _amosFramework.Select.Option, RadioGroup = _amosAntd.Radio.Group, userNameText = "用户名", nameText = "姓名", statusText = "用户状态", companyIdText = "所属单位", departmentIdText = "所属部门", roleIdText = "角色", emailText = "Email", mobileText = "手机", telephoneText = "固定电话", statusOptions = [ {
  name: "enable",
  value: 0,
  text: "启用"
}, {
  name: "disable",
  value: 1,
  text: "禁用"
} ], nameErrorText = "用户名不能为空！", otherNameErrorText = "姓名不能为空！", companyErrorText = "所属单位不能为空！", roleErrorText = "角色不能为空！", dataToTree = function e() {
  var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
  t.map((function(t) {
    t.label = t.text, t.key = t.id, t.value = t.id, t.children && e(t.children);
  }));
}, UserAddEdit = function(e) {
  (0, _inherits2.default)(a, e);
  var t = _createSuper(a);
  function a(e) {
    var r;
    return (0, _classCallCheck2.default)(this, a), r = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(r), "getRole", (function() {
      r.props.getAllRoleAction();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getOrgData", (function(e) {
      var t = e.company;
      t && r.getDepartment(t.id);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getDepartment", (function(e) {
      r.props.getDepartmentByCompanyAction(e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkId", (function(e, t, a) {
      t && !_processor.AmosValidate.isNum(t) ? a("ID只能是数字格式的！") : a();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkMobile", (function(e, t, a) {
      t && !_processor.AmosValidate.isMobile(t) ? a("请输入正确的手机号格式！") : a();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkTelephone", (function(e, t, a) {
      t && !_processor.AmosValidate.isPhone(t) ? a("请输入正确的固定电话格式！") : a();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkEmail", (function(e, t, a) {
      t && (!_processor.AmosValidate.isEmail(t) || t.length > 25) ? a("请输入正确的邮箱格式！") : a();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkPassword", (function(e, t, a) {
      t && !_processor.AmosValidate.isPassword(t) ? a("请输入正确的密码格式！") : a();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkRePassword", (function(e, t, a) {
      var l = r.props.parentform.getFieldValue;
      t && t !== l("password") ? a("两次输入密码不一致！") : a();
    })), r.state = {
      companyList: [],
      selectDepartment: "",
      reset: !1
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentWillReceiveProps",
    value: function(e) {
      var t = this, a = e.user;
      this.props.user && this.props.user.id == a.id || (this.getOrgData(a), this.props.setHandleReset((function() {
        t.setState({
          reset: !1
        });
      })));
    }
  }, {
    key: "componentDidMount",
    value: function() {
      var e = this;
      this.getRole(), this.props.superiorUnitAction(), this.props.setHandleReset((function() {
        e.setState({
          reset: !1
        });
      }));
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.props, a = t.user, r = t.parentform, l = t.submit, n = t.isEdit, i = t.departmentTreeData, o = t.allRole, s = t.superiorCompanyList, u = a.userName, d = a.enabled, c = a.company, p = a.department, m = a.role, f = a.mobile, _ = a.email, h = a.name, y = a.telephone, b = c && c.id ? c.id + "" : null, E = p ? p.id : null, T = m ? m.id : null, x = r.getFieldProps, v = x("userName", {
        initialValue: "" == u ? void 0 : u,
        rules: [ {
          required: !0,
          message: nameErrorText
        }, {
          validator: (0, _validate.textLengthValidate)(255, 2)
        } ]
      }), g = x("name", {
        initialValue: "" == h ? void 0 : h,
        rules: [ {
          required: !0,
          message: otherNameErrorText
        }, {
          validator: (0, _validate.textLengthValidate)(255, 2)
        } ]
      }), R = (x("mobile", {
        initialValue: "" == f ? null : f,
        rules: [ {
          validator: this.checkMobile
        } ]
      }), x("telephone", {
        initialValue: "" == y ? null : y,
        rules: [ {
          validator: this.checkTelephone
        } ]
      }), x("email", {
        initialValue: "" == _ ? null : _,
        rules: [ {
          validator: this.checkEmail
        } ]
      }), x("companyId", {
        initialValue: b,
        rules: [ {
          required: !0,
          message: companyErrorText
        } ],
        onChange: function(t) {
          e.getDepartment(t), e.setState({
            reset: !0
          }), r.resetFields([ "departmentId" ]);
        }
      })), w = x("departmentId", {
        initialValue: this.state.reset ? void 0 : "number" == typeof E ? "" + E : null
      }), A = x("roleId", {
        initialValue: T ? T + "" : void 0,
        rules: [ {
          required: !0,
          message: roleErrorText
        } ]
      }), I = x("enabled", {
        initialValue: d ? statusOptions[0].name : statusOptions[1].name
      }), q = x("password", {
        initialValue: null,
        rules: [ {
          required: n,
          message: "请输入密码"
        }, {
          validator: this.checkPassword
        } ]
      }), C = x("rePassword", {
        initialValue: null,
        rules: [ {
          required: n,
          message: "请输入确认密码"
        }, {
          validator: this.checkRePassword
        } ]
      }), P = {
        labelCol: {
          span: 7
        },
        wrapperCol: {
          span: 16
        }
      };
      return _react.default.createElement("div", {
        className: "user-add-edit amos-grid-from"
      }, _react.default.createElement(_amosAntd.Form, {
        inline: !0,
        onSubmit: l
      }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: userNameText
      }, P), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, v, {
        style: {
          width: 240
        }
      })))), _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: nameText
      }, P), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, g, {
        style: {
          width: 240
        }
      }))))), _react.default.createElement("hr", null), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: companyIdText
      }, P), _react.default.createElement(_amosAntd.TreeSelect, (0, _extends2.default)({
        instanceId: "user-company",
        showSearch: !0,
        className: "amos-grid-form-select",
        style: {
          width: 240
        },
        dropdownStyle: {
          maxHeight: 250,
          overflow: "auto"
        },
        treeData: s,
        placeholder: "所有单位",
        notFoundContent: "无匹配结果",
        treeDefaultExpandAll: !0,
        treeNodeFilterProp: "title"
      }, R)))), _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: departmentIdText
      }, P), _react.default.createElement(_amosAntd.TreeSelect, (0, _extends2.default)({
        instanceId: "user-department"
      }, w, {
        allowClear: !0,
        showSearch: !0,
        optionFilterProp: "children",
        treeNodeFilterProp: "title",
        dropdownStyle: {
          maxHeight: 300,
          overflow: "auto"
        },
        style: {
          width: 240
        },
        treeData: i,
        notFoundContent: "无匹配结果"
      }))))), n ? _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "密码"
      }, P), _react.default.createElement(_amosAntd.Input, {
        className: "amos-grid-form-input",
        style: {
          width: 0,
          height: 0,
          padding: 0,
          border: 0,
          position: "absolute"
        }
      }), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input",
        type: "password"
      }, q, {
        style: {
          width: 240
        }
      })))), _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "确认密码"
      }, P), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input",
        type: "password"
      }, C, {
        style: {
          width: 240
        }
      }))))) : null, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: roleIdText
      }, P), _react.default.createElement(_amosFramework.Select, (0, _extends2.default)({
        instanceId: "user-role",
        className: "amos-grid-form-select",
        showSearch: !0,
        optionFilterProp: "children"
      }, A, {
        style: {
          width: 240,
          height: "32px"
        }
      }), o.map((function(e) {
        return _react.default.createElement(Option, {
          key: "".concat(e.id, "option"),
          value: e.id + ""
        }, e.name);
      })))))), _react.default.createElement("hr", null), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(FormItem, (0, 
      _extends2.default)({
        label: statusText
      }, {
        labelCol: {
          span: 3
        },
        wrapperCol: {
          span: 16
        }
      }), _react.default.createElement(RadioGroup, (0, _extends2.default)({}, I, {
        style: {
          width: 240
        }
      }), statusOptions.map((function(e) {
        return _react.default.createElement(_amosAntd.Radio, {
          key: "".concat(e.name, "Radio"),
          value: e.name
        }, e.text);
      })))))));
    }
  } ]), a;
}(_react.Component);

UserAddEdit.displayName = "UserAddEdit", UserAddEdit.propTypes = {
  user: _propTypes.default.object,
  submit: _propTypes.default.func,
  cancel: _propTypes.default.func,
  getDepartmentByCompanyAction: _propTypes.default.func,
  parentform: _propTypes.default.any,
  superiorUnitAction: _propTypes.default.func,
  allRole: _propTypes.default.array,
  superiorCompanyList: _propTypes.default.any,
  getAllRoleAction: _propTypes.default.func,
  departmentTreeData: _propTypes.default.array,
  isEdit: _propTypes.default.bool
}, UserAddEdit.defaultProps = {
  departmentTreeData: [],
  allRole: [],
  superiorCompanyList: [],
  user: {
    identificationId: "",
    userName: "",
    enabled: !0,
    company: "",
    department: {},
    role: {},
    mobile: "",
    password: "",
    email: ""
  }
};

var _default = UserAddEdit;

exports.default = _default;