"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")), _amosAntd = require("amos-antd"), _amosFramework = require("amos-framework"), _processor = require("./../../common/utils/processor"), _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, nameText = "单位名称", superiorText = "上级单位", levelText = "单位级别", describesText = "单位描述", tipErrorText = "上级名称不能为空！", nameErrorText = "单位名称不能为空！", levelErrorText = "单位级别不能为空！", 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);
  }));
}, CompanyAddEdit = 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), "getCompanyLevels", (function() {
      r.props.companyLevelsAction();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "companyLevelChange", (function(e) {
      r.setState({
        level: e
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkMobile", (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();
    })), r.state = {
      level: e.company.companyLevel,
      fireStationLevels: []
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentDidMount",
    value: function() {
      this.getCompanyLevels();
    }
  }, {
    key: "componentWillReceiveProps",
    value: function(e) {
      this.setState({
        level: e.company.companyLevel
      });
    }
  }, {
    key: "render",
    value: function() {
      var e = this.props, t = e.company, a = e.parentform, r = e.submit, l = e.superiorUnitData, n = (e.companyLevels, 
      t.companyName), i = (t.companyLevel, t.description), o = t.parentId, u = t.longitude, s = (t.siteId, 
      t.latitude), d = t.contact, c = t.address, p = t.telephone, m = (t.email, a.getFieldProps), f = m("companyName", {
        initialValue: n,
        rules: [ {
          required: !0,
          message: nameErrorText
        }, {
          validator: (0, _validate.textLengthValidate)(255, 2)
        } ]
      }), _ = m("parentId", {
        initialValue: o ? "".concat(o) : null,
        rules: [ {
          required: "省总队" !== this.state.level,
          message: tipErrorText
        } ]
      }), y = (m("companyLevel", {
        initialValue: null,
        rules: []
      }), m("description", {
        initialValue: i,
        rules: [ {
          validator: (0, _validate.textLengthValidate)(255)
        } ]
      })), h = m("longitude", {
        initialValue: u,
        rules: [ {
          validator: (0, _validate.textValueValidate)(180, -180)
        } ]
      }), v = m("latitude", {
        initialValue: s,
        rules: [ {
          validator: (0, _validate.textValueValidate)(90, -90)
        } ]
      }), b = m("contact", {
        initialValue: d,
        rules: [ {
          validator: (0, _validate.textLengthValidate)(10)
        } ]
      }), E = m("address", {
        initialValue: c,
        rules: [ {
          validator: (0, _validate.textLengthValidate)(50)
        } ]
      }), x = m("telephone", {
        initialValue: p,
        rules: [ {
          validator: this.checkMobile
        } ]
      }), C = (m("email", {
        initialValue: null
      }), {
        labelCol: {
          span: 7
        },
        wrapperCol: {
          span: 16
        }
      });
      return _react.default.createElement("div", {
        className: "company-add-edit amos-grid-from"
      }, _react.default.createElement(_amosAntd.Form, {
        inline: !0,
        onSubmit: r
      }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: nameText
      }, C), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, f, {
        style: {
          width: 240
        }
      })))), _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: superiorText
      }, C), _react.default.createElement(_amosAntd.TreeSelect, (0, _extends2.default)({
        instanceId: "patent-company",
        showSearch: !0,
        className: "amos-grid-form-select",
        style: {
          width: 240
        },
        dropdownStyle: {
          maxHeight: 250,
          overflow: "auto"
        },
        treeData: l,
        placeholder: "上级单位",
        treeDefaultExpandAll: !0,
        treeNodeFilterProp: "title",
        notFoundContent: "无匹配结果"
      }, _))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "经度"
      }, C), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, h, {
        style: {
          width: 240
        }
      })))), _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "纬度"
      }, C), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, v, {
        style: {
          width: 240
        }
      }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "联系人"
      }, C), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, b, {
        style: {
          width: 240
        }
      })))), _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "地址"
      }, C), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, E, {
        style: {
          width: 240
        }
      }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "电话"
      }, C), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, x, {
        style: {
          width: 240
        }
      }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 12
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: describesText
      }, C), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-textarea",
        type: "textarea",
        rows: 3,
        style: {
          width: 240
        }
      }, y)))))));
    }
  } ]), a;
}(_react.Component);

CompanyAddEdit.displayName = "CompanyAddEdit", CompanyAddEdit.propTypes = {
  company: _propTypes.default.object,
  superiorUnitData: _propTypes.default.array,
  superiorUnitEditData: _propTypes.default.array,
  submit: _propTypes.default.func,
  cancel: _propTypes.default.func,
  parentform: _propTypes.default.any,
  companyLevels: _propTypes.default.array,
  companyLevelsAction: _propTypes.default.func
}, CompanyAddEdit.defaultProps = {
  companyLevels: [],
  company: {
    companyName: "",
    companyLevel: "",
    description: ""
  }
};

var _default = CompanyAddEdit;

exports.default = _default;