"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")), _amosAntd = require("amos-antd"), _propTypes = _interopRequireDefault(require("prop-types")), _processor = require("../../utils/processor"), _urlConsts = _interopRequireDefault(require("../../consts/urlConsts")), _amosFramework = require("amos-framework"), _amosTool = require("amos-tool"), _protocolTestView = _interopRequireDefault(require("./protocolTestView")), _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 = {}, n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var l in e) if ("default" !== l && Object.prototype.hasOwnProperty.call(e, l)) {
    var o = n ? Object.getOwnPropertyDescriptor(e, l) : null;
    o && (o.get || o.set) ? Object.defineProperty(r, l, o) : r[l] = e[l];
  }
  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 n = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, n);
    } 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 createForm = _amosAntd.Form.create(), FormItem = _amosAntd.Form.Item, Panel = _amosAntd.Collapse.Panel, RadioGroup = _amosAntd.Radio.Group, TextArea = _amosAntd.Input.TextArea, maxDescLength = 250, AddProtocol = 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), "onChange", (function(e) {
      console.log("radio checked", e.target.value), r.setState({
        radiovalue: e.target.value
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClickDown", (function(e) {
      e.preventDefault(), r.props.form.validateFields((function(e, t) {
        e || (t = (0, _validate.objOfStrPropTrim)(t), r.setState({
          itemInfo: t,
          activeKey: "2",
          btnVisible: !1
        }));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClickUp", (function() {
      r.setState({
        activeKey: "1"
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onClick", (function() {
      var e = _urlConsts.default.protocolSave, t = r.state.itemInfo;
      t.dicIdScriptLang = r.state.radiovalue;
      var a = r.props.form.getFieldValue, n = (0, _amosTool.trim)(a("scriptCode"));
      n && "" !== n ? (r.setState({
        waiting: !0
      }), t.scriptCode = n, _processor.AmosFetch.post(e, {
        data: t
      }).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        "SUCCESS" === e.result ? (_amosFramework.message.success("协议新增成功！"), r.props.updateAddView("2")) : (r.setState({
          waiting: !1
        }), _amosFramework.message.danger("协议新增失败！"));
      }))) : _amosAntd.Modal.info({
        title: "提示",
        content: "代码不能为空！",
        okText: "确定"
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "delBtn", (function() {
      _amosAntd.Modal.confirm({
        title: "删除",
        content: "是否删除所选信息？",
        okText: "确定",
        cancelText: "取消",
        onOk: function() {},
        onCancel: function() {}
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "testBtnFuncOpen", (function() {
      r.setState({
        btnVisible: !0
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "testBtnFuncClose", (function() {
      r.setState({
        btnVisible: !1
      });
    })), r.state = {
      scriptLangData: [],
      radiovalue: 12,
      activeKey: "1",
      interfaceProList: [],
      itemInfo: {},
      waiting: !1
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentDidMount",
    value: function() {
      var e = this;
      _processor.AmosFetch.get(_urlConsts.default.scriptLangType).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(t) {
        if ("SUCCESS" === t.result) {
          var a = [];
          !t || t.dataList.map((function(e) {
            "Groovy" === e.name ? a.push({
              value: e.id,
              label: e.name
            }) : a.push({
              value: e.id,
              label: e.name,
              disabled: !0
            });
          })), e.setState({
            scriptLangData: a
          });
        }
      }));
    }
  }, {
    key: "render",
    value: function() {
      var e = this.state, t = e.itemInfo, a = (e.btnVisible, e.scriptLangData), r = t.name, n = t.version, l = t.descr, o = t.scriptCode, i = this.props.form.getFieldProps, s = {
        labelCol: {
          span: 10
        },
        wrapperCol: {
          span: 4
        }
      }, u = {
        labelCol: {
          span: 7
        },
        wrapperCol: {
          span: 10
        }
      }, c = i("name", {
        initialValue: r,
        rules: [ {
          required: !0,
          message: "名称不能为空！"
        }, {
          validator: (0, _validate.noSpaceLengthValidate)(50, !0, "名称不能为空！")
        } ]
      }), d = i("version", {
        initialValue: n,
        rules: [ {
          required: !0,
          message: "版本不能为空！"
        }, {
          validator: (0, _validate.noSpaceLengthValidate)(20, !0, "版本不能为空！")
        } ]
      }), f = i("descr", {
        initialValue: l,
        rules: [ {
          validator: (0, _validate.noSpaceLengthValidate)(maxDescLength, !1, null)
        } ]
      }), p = i("scriptCode", {
        initialValue: o
      });
      return _react.default.createElement("div", {
        className: "table-container"
      }, _react.default.createElement(_amosAntd.Collapse, {
        activeKey: this.state.activeKey,
        accordion: !0
      }, _react.default.createElement(Panel, {
        header: "新建协议",
        key: "1",
        showArrow: !1
      }, _react.default.createElement("div", {
        style: {
          textAlign: "center"
        }
      }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 24
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        hasFeedback: !0,
        label: "名称"
      }, s), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, c, {
        placeholder: "请输入名称"
      }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 24
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        hasFeedback: !0,
        label: "版本"
      }, s), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, d, {
        placeholder: "请输入版本"
      }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 24
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "描述"
      }, s), _react.default.createElement(_amosAntd.Input, (0, _extends2.default)({
        className: "amos-grid-form-input"
      }, f, {
        placeholder: "请输入描述"
      }))))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Button, {
        onClick: this.onClickDown
      }, "下一步")))), _react.default.createElement(Panel, {
        header: "新建脚本信息",
        key: "2",
        showArrow: !1
      }, _react.default.createElement("div", {
        style: {
          textAlign: "center"
        }
      }, _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 24
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        hasFeedback: !0,
        label: "实现方式"
      }, u, {
        wrapperCol: {
          span: 5,
          offset: 0
        }
      }), _react.default.createElement(RadioGroup, {
        options: a,
        onChange: this.onChange,
        value: this.state.radiovalue
      })))), _react.default.createElement(_amosAntd.Row, null, _react.default.createElement(_amosAntd.Col, {
        span: 24
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        hasFeedback: !0,
        label: "代码"
      }, u), _react.default.createElement(TextArea, (0, _extends2.default)({}, p, {
        autosize: {
          minRows: 8,
          maxRows: 20
        }
      })))))), _react.default.createElement("div", {
        style: {
          height: "2rem"
        }
      }), _react.default.createElement(_amosAntd.Row, {
        type: "flex",
        justify: "center"
      }, _react.default.createElement(_amosAntd.Button, {
        onClick: this.onClickUp
      }, "上一步"), _react.default.createElement("div", {
        style: {
          width: "1.5rem"
        }
      }), _react.default.createElement(_amosAntd.Button, {
        onClick: this.onClick,
        disabled: this.state.waiting
      }, "确定")))));
    }
  } ]), a;
}(_react.Component);

AddProtocol.displayName = "AddProtocol", AddProtocol.propTypes = {
  form: _propTypes.default.any,
  updateAddView: _propTypes.default.func
};

var _default = createForm(AddProtocol);

exports.default = _default;