"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _react = _interopRequireWildcard(require("react")),
  _propTypes = _interopRequireDefault(require("prop-types")),
  _amosAntd = require("amos-antd"),
  _amosFramework = require("amos-framework"),
  _rayEventpool = require("ray-eventpool"),
  _stageConf = require("./../ruleStatge/modelConf/stageConf"),
  _topoService = require("./../../../services/topoService"),
  _ruleDesignService = require("./../../../services/ruleDesignService"),
  _monitorRuleService = require("./../../../services/monitorRuleService"),
  _securityService = require("./../../../services/securityService");

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 o, r, n = {},
    a = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (o in e) Object.prototype.hasOwnProperty.call(e, o) && ((r = a ? Object.getOwnPropertyDescriptor(e, o) : null) && (r.get || r.set) ? Object.defineProperty(n, o, r) : n[o] = e[o]);
  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 ownKeys(t, e) {
  var o, r = Object.keys(t);
  return Object.getOwnPropertySymbols && (o = Object.getOwnPropertySymbols(t), e && (o = o.filter(function(e) {
    return Object.getOwnPropertyDescriptor(t, e).enumerable
  })), r.push.apply(r, o)), r
}

function _objectSpread(t) {
  for (var e = 1; e < arguments.length; e++) {
    var o = null != arguments[e] ? arguments[e] : {};
    e % 2 ? ownKeys(Object(o), !0).forEach(function(e) {
      _defineProperty(t, e, o[e])
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(o)) : ownKeys(Object(o)).forEach(function(e) {
      Object.defineProperty(t, e, Object.getOwnPropertyDescriptor(o, e))
    })
  }
  return t
}

function _extends() {
  return (_extends = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var o, r = arguments[t];
      for (o in r) Object.prototype.hasOwnProperty.call(r, o) && (e[o] = r[o])
    }
    return e
  }).apply(this, arguments)
}

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

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

function _createClass(e, t, o) {
  return t && _defineProperties(e.prototype, t), o && _defineProperties(e, o), 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(o) {
  var r = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(o);
    return _possibleConstructorReturn(this, r ? (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, o) {
  return t in e ? Object.defineProperty(e, t, {
    value: o,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = o, e
}
var Option = _amosAntd.Select.Option,
  FormItem = _amosFramework.Form.Item,
  formItemLayout = {
    labelCol: {
      xs: {
        span: 24
      },
      sm: {
        span: 6,
        offset: 0
      },
      className: "colspanlab"
    },
    wrapperCol: {
      xs: {
        span: 24
      },
      sm: {
        span: 17,
        offset: 0
      },
      className: "colspan"
    }
  },
  DataSourceConfig = function() {
    _inherits(o, _react.Component);
    var t = _createSuper(o);

    function o(e) {
      var d;
      _classCallCheck(this, o), _defineProperty(_assertThisInitialized(d = t.call(this, e)), "onInput", function(e, t) {
        var o = d.state.form;
        o[e] = t.target.value, d.setState({
          form: o,
          isEdited: !0
        })
      }), _defineProperty(_assertThisInitialized(d), "onSelect", function(e, t) {
        var o = d.state.form;
        o[e] = t, "userType" === e || ("company" === e ? (o.device = void 0, o.view = void 0, d.getSubviewByOrgCode(t)) : "view" === e && "datanodeDevice" === d.props.config.nodeType && (o.device = void 0, d.getEgpBySubviewID(t))), d.setState({
          form: o,
          isEdited: !0
        })
      }), _defineProperty(_assertThisInitialized(d), "getNodeConfig", function(o) {
        (0, _ruleDesignService.fetchNodeConfigAction)(o.id).then(function(e) {
          d.setState({
            nodeConfig: e
          });
          var t = d.state.form;
          t.itemName = e.label, "datanodeDevice" === o.nodeType ? e.configInfo ? (t.view = e.configInfo.view, t.device = e.configInfo.eqpId, t.company = e.configInfo.orgCode, t.itemName = e.configInfo.name, d.getSubviewByOrgCode(t.company), d.getEgpBySubviewID(t.view)) : (t.view = void 0, t.device = void 0, t.company = void 0, t.itemName = o.label) : "datanodeView" === o.nodeType ? e.configInfo ? (t.view = e.configInfo.view, t.company = e.configInfo.orgCode, t.viewName = e.configInfo.name, d.getSubviewByOrgCode(t.company)) : (t.view = void 0, t.company = void 0, t.viewName = o.label) : "datanodeTask" === o.nodeType ? (e.configInfo ? (t.task = e.configInfo.monitorRuleId, t.taskName = e.configInfo.name) : (t.task = void 0, t.taskName = o.label), d.getAllTaskData()) : "datanodeCurrentUser" === o.nodeType && (t.userName = o.label), d.setState({
            form: t
          })
        })
      }), _defineProperty(_assertThisInitialized(d), "getSubviewByUserID", function() {
        (0, _topoService.subViewListAction)().then(function(e) {
          d.setState({
            treeData: e
          })
        })
      }), _defineProperty(_assertThisInitialized(d), "getSubviewByOrgCode", function(e) {
        (0, _topoService.fetchCompanyById)(e).then(function(e) {
          e && (0, _topoService.subviewByOrgCodeAction)(e.compCode).then(function(e) {
            var t = [];
            e.map(function(e) {
              return t.push(_react.default.createElement(Option, {
                key: e.id,
                value: "".concat(e.id)
              }, e.name))
            }), d.setState({
              viewOption: t
            })
          })
        })
      }), _defineProperty(_assertThisInitialized(d), "getEgpBySubviewID", function(e) {
        e && (0, _topoService.fetchSubEgpListAction)(e).then(function(e) {
          var t = [];
          e.map(function(e) {
            return t.push(_react.default.createElement(Option, {
              key: e.id,
              value: e.id
            }, e.name))
          }), d.setState({
            deviceOption: t
          })
        })
      }), _defineProperty(_assertThisInitialized(d), "getAllTaskData", function() {
        (0, _monitorRuleService.getTaskDataAction)().then(function(e) {
          var t = [];
          e.content.map(function(e) {
            return t.push(_react.default.createElement(Option, {
              key: e.id,
              value: e.id
            }, e.name))
          }), d.setState({
            taskOption: t
          })
        })
      }), _defineProperty(_assertThisInitialized(d), "getFormByType", function() {
        var t = {
            itemName: [{
              required: !0,
              message: "请输入活动名称"
            }, {
              min: 1,
              max: 150,
              message: "长度范围：0-150！"
            }],
            subUser: [{
              required: !0,
              message: "不能为空！"
            }, {
              validator: d.checkSelect
            }],
            company: [{
              required: !0,
              message: "不能为空！"
            }, {
              validator: d.checkSelect
            }],
            view: [{
              required: !0,
              message: "不能为空！"
            }, {
              validator: d.checkSelect
            }],
            device: [{
              required: !0,
              message: "不能为空！"
            }, {
              validator: d.checkSelect
            }],
            task: [{
              required: !0,
              message: "不能为空！"
            }, {
              validator: d.checkSelect
            }]
          },
          e = d.props.config,
          o = d.state,
          r = o.form,
          n = o.treeData,
          a = o.deviceOption,
          i = o.nodeConfig,
          c = o.viewOption,
          o = o.taskOption,
          l = [];
        return "datanodeDevice" !== e.nodeType || !n || void 0 === a && null !== i.configInfo ? "datanodeCurrentUser" === e.nodeType ? (0, _securityService.getCurrentUser)().then(function(e) {
          l.push(_react.default.createElement(_amosFramework.Form, {
            className: "config-form",
            ref: function(e) {
              return d.form = e
            },
            model: r,
            rules: t
          }, _react.default.createElement(FormItem, _extends({
            label: _react.default.createElement("span", null, "节点名称"),
            field: "userName"
          }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
            placeholder: "输入内容",
            value: r.userName,
            disabled: !0,
            style: {
              width: "100%"
            },
            onChange: function(e) {
              return d.onInput("userName", e)
            }
          })), _react.default.createElement(FormItem, _extends({
            label: "用户名"
          }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
            placeholder: "输入内容",
            defaultValue: e.userName,
            disabled: !0,
            style: {
              width: "100%"
            }
          }))))
        }) : "datanodeTask" === e.nodeType ? l.push(_react.default.createElement(_amosFramework.Form, {
          className: "config-form",
          ref: function(e) {
            return d.form = e
          },
          model: r,
          rules: t
        }, _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "节点名称"),
          field: "taskName"
        }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
          placeholder: "输入内容",
          value: r.taskName,
          style: {
            width: "100%"
          },
          onChange: function(e) {
            return d.onInput("taskName", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: "用户类型",
          field: "userType"
        }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "100%"
          },
          dropdownStyle: {
            width: "100%"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return d.onSelect("userType", e)
          },
          placeholder: "选择输入内容",
          value: "0"
        }, _react.default.createElement(Option, {
          key: "0",
          value: "0"
        }, "当前用户"))), _react.default.createElement(FormItem, _extends({
          label: "任务",
          field: "task"
        }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "100%"
          },
          dropdownStyle: {
            width: "100%"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return d.onSelect("task", e)
          },
          placeholder: "选择输入内容",
          defaultValue: r.task,
          value: r.task
        }, o)))) : "datanodeView" === e.nodeType && l.push(_react.default.createElement(_amosFramework.Form, {
          className: "config-form",
          ref: function(e) {
            return d.form = e
          },
          model: r,
          rules: t
        }, _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "节点名称"),
          field: "viewName"
        }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
          placeholder: "输入内容",
          value: r.viewName,
          style: {
            width: "100%"
          },
          onChange: function(e) {
            return d.onInput("viewName", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: "用户类型",
          field: "userType"
        }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "100%"
          },
          dropdownStyle: {
            width: "100%"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return d.onSelect("userType", e)
          },
          placeholder: "选择输入内容",
          value: "0"
        }, _react.default.createElement(Option, {
          key: "0",
          value: "0"
        }, "当前用户"))), _react.default.createElement(FormItem, _extends({
          label: "公司",
          field: "company"
        }, formItemLayout), _react.default.createElement(_amosAntd.TreeSelect, {
          dropdownMatchSelectWidth: !0,
          style: {
            width: "calc(20rem + 15px)"
          },
          value: r.company,
          dropdownStyle: {
            maxHeight: 160,
            overflow: "auto",
            width: "calc(20rem + 15px)"
          },
          treeData: n,
          placeholder: "选择公司",
          treeDefaultExpandAll: !0,
          onChange: function(e) {
            return d.onSelect("company", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: "视图",
          field: "view"
        }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "100%"
          },
          dropdownStyle: {
            width: "100%"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return d.onSelect("view", e)
          },
          placeholder: "选择输入内容",
          defaultValue: r.view,
          value: r.view
        }, c)))) : l.push(_react.default.createElement(_amosFramework.Form, {
          className: "config-form",
          ref: function(e) {
            return d.form = e
          },
          model: r,
          rules: t
        }, _react.default.createElement(FormItem, _extends({
          label: _react.default.createElement("span", null, "节点名称"),
          field: "itemName"
        }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
          placeholder: "输入内容",
          value: r.itemName,
          style: {
            width: "100%"
          },
          onChange: function(e) {
            return d.onInput("itemName", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: "用户类型",
          field: "userType"
        }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "100%"
          },
          dropdownStyle: {
            width: "100%"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return d.onSelect("userType", e)
          },
          placeholder: "选择输入内容",
          value: "0"
        }, _react.default.createElement(Option, {
          key: "0",
          value: "0"
        }, "当前用户"))), _react.default.createElement(FormItem, _extends({
          label: "公司",
          field: "company"
        }, formItemLayout), _react.default.createElement(_amosAntd.TreeSelect, {
          dropdownMatchSelectWidth: !0,
          style: {
            width: "calc(20rem + 15px)"
          },
          value: r.company,
          dropdownStyle: {
            maxHeight: 160,
            overflow: "auto",
            width: "calc(20rem + 15px)"
          },
          treeData: n,
          placeholder: "选择公司",
          treeDefaultExpandAll: !0,
          onChange: function(e) {
            return d.onSelect("company", e)
          }
        })), _react.default.createElement(FormItem, _extends({
          label: "视图",
          field: "view"
        }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "100%"
          },
          dropdownStyle: {
            width: "100%"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return d.onSelect("view", e)
          },
          placeholder: "选择输入内容",
          defaultValue: r.view,
          value: r.view
        }, c)), _react.default.createElement(FormItem, _extends({
          label: "设备",
          field: "device"
        }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "100%"
          },
          dropdownStyle: {
            width: "100%"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return d.onSelect("device", e)
          },
          placeholder: "选择输入内容",
          defaultValue: r.device,
          value: r.device
        }, a)))), l
      }), _defineProperty(_assertThisInitialized(d), "handleSubmit", function(e) {
        e.preventDefault(), d.form.validate(function(e, t) {
          return console.log("返回内容:", t, e), !!e && void d.saveConfig()
        })
      }), _defineProperty(_assertThisInitialized(d), "checkSelect", function(e, t, o) {
        "0" === t ? o("请选择！") : o()
      }), _defineProperty(_assertThisInitialized(d), "saveConfig", function() {
        var t, e, o = d.props.config,
          r = d.state,
          n = r.form,
          r = r.nodeConfig;
        "datanodeDevice" === o.nodeType ? (t = {
          nodeId: o.id,
          nodeType: o.nodeType,
          label: void 0 === n.itemName ? r.label : n.itemName
        }, e = {
          user_type: "0",
          view: (void 0 === n.view ? r.configInfo : n).view,
          eqpId: void 0 === n.device ? r.configInfo.eqpId : n.device,
          orgCode: void 0 === n.company ? r.configInfo.orgCode : n.company
        }) : "datanodeTask" === o.nodeType ? (t = {
          nodeId: o.id,
          nodeType: o.nodeType,
          label: void 0 === n.taskName ? r.label : n.taskName
        }, e = {
          user_type: "0",
          monitorRuleId: void 0 === n.task ? r.configInfo.monitorRuleId : n.task
        }) : "datanodeView" === o.nodeType && (t = {
          nodeId: o.id,
          nodeType: o.nodeType,
          label: void 0 === n.viewName ? r.label : n.viewName
        }, e = {
          user_type: "0",
          view: (void 0 === n.view ? r.configInfo : n).view,
          orgCode: void 0 === n.company ? r.configInfo.orgCode : n.company
        }), t = _objectSpread(_objectSpread({}, t), {}, {
          configInfo: e
        }), (0, _ruleDesignService.updateNode)(t).then(function(e) {
          _rayEventpool.PubSub.publish(_stageConf.ELE_UPDATE_TOPIC.trigger, {
            label: t.label,
            nodeId: o.id
          }), _amosFramework.message.success("保存成功")
        })
      }), _defineProperty(_assertThisInitialized(d), "removeItem", function(e, t) {
        t && (_rayEventpool.PubSub.publish(_stageConf.ELE_DEL_TOPIC.trigger, {
          eleId: t
        }), d.props.closeTriggerDesigner())
      });
      e = d.props.config;
      return d.state = {
        nodeConfig: {},
        form: {
          isSubUser: !1,
          treeData: [],
          deviceOption: [],
          viewOption: [],
          taskOption: [],
          itemName: e.label,
          viewName: e.label,
          taskName: e.label,
          isEdited: !1
        }
      }, d
    }
    return _createClass(o, [{
      key: "componentWillMount",
      value: function() {}
    }, {
      key: "componentDidMount",
      value: function() {
        var n = this;
        this.getSubviewByUserID(), this.getNodeConfig(this.props.config), this.pubsub_update = _rayEventpool.PubSub.subscribe(_stageConf.ELE_UPDATE_TOPIC.eleUpdate, function(e, t) {
          var o = t.label,
            r = t.nodeId,
            t = n.props.config;
          r === t.id && (r = n.state.form, "datanodeDevice" === t.nodeType ? r.itemName = o : "datanodeView" === t.nodeType ? r.viewName = o : "datanodeTask" === t.nodeType && (r.taskName = o), n.setState({
            form: r
          }))
        })
      }
    }, {
      key: "componentWillReceiveProps",
      value: function(e) {
        this.props.config.id !== e.config.id && this.getNodeConfig(e.config)
      }
    }, {
      key: "componentWillUnmount",
      value: function() {
        _rayEventpool.PubSub.unsubscribe(this.pubsub_update)
      }
    }, {
      key: "render",
      value: function() {
        var e = this.props,
          t = e.closeTriggerDesigner,
          e = (e.config, this.state.isEdited);
        return _react.default.createElement("div", {
          className: "data-source-root"
        }, _react.default.createElement("div", {
          className: "head-root"
        }, _react.default.createElement("div", {
          className: "head-one"
        }, "节点编辑"), _react.default.createElement("div", {
          className: "head-two"
        }, e ? _react.default.createElement("div", {
          className: "head-two-four",
          onClick: this.handleSubmit
        }, "保存") : "", _react.default.createElement("div", {
          className: "head-two-three",
          onClick: t
        }, "取消"))), _react.default.createElement("div", {
          className: "content-panel"
        }, this.getFormByType()))
      }
    }]), o
  }();
DataSourceConfig.displayName = "DataSourceConfig", DataSourceConfig.propTypes = {
  config: _propTypes.default.object,
  closeTriggerDesigner: _propTypes.default.func
}, DataSourceConfig.defaultProps = {};
var _default = DataSourceConfig;
exports.default = DataSourceConfig, module.exports = exports.default;
