"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"), _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 _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 = {}, o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var n in e) if ("default" !== n && Object.prototype.hasOwnProperty.call(e, n)) {
    var i = o ? 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 ownKeys(e, t) {
  var a = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var r = Object.getOwnPropertySymbols(e);
    t && (r = r.filter((function(t) {
      return Object.getOwnPropertyDescriptor(e, t).enumerable;
    }))), a.push.apply(a, r);
  }
  return a;
}

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

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var a, r = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var o = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, o);
    } 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 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(e) {
  (0, _inherits2.default)(a, e);
  var t = _createSuper(a);
  function a(e) {
    var r;
    (0, _classCallCheck2.default)(this, a), r = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(r), "onInput", (function(e, t) {
      var a = r.state.form;
      a[e] = t.target.value, r.setState({
        form: a,
        isEdited: !0
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onSelect", (function(e, t) {
      var a = r.state.form;
      a[e] = t, "userType" === e || ("company" === e ? (a.device = void 0, a.view = void 0, 
      r.getSubviewByOrgCode(t)) : "view" === e && "datanodeDevice" === r.props.config.nodeType && (a.device = void 0, 
      r.getEgpBySubviewID(t))), r.setState({
        form: a,
        isEdited: !0
      });
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getNodeConfig", (function(e) {
      (0, _ruleDesignService.fetchNodeConfigAction)(e.id).then((function(t) {
        r.setState({
          nodeConfig: t
        });
        var a = r.state.form;
        a.itemName = t.label, "datanodeDevice" === e.nodeType ? t.configInfo ? (a.view = t.configInfo.view, 
        a.device = t.configInfo.eqpId, a.company = t.configInfo.orgCode, a.itemName = t.configInfo.name, 
        r.getSubviewByOrgCode(a.company), r.getEgpBySubviewID(a.view)) : (a.view = void 0, 
        a.device = void 0, a.company = void 0, a.itemName = e.label) : "datanodeView" === e.nodeType ? t.configInfo ? (a.view = t.configInfo.view, 
        a.company = t.configInfo.orgCode, a.viewName = t.configInfo.name, r.getSubviewByOrgCode(a.company)) : (a.view = void 0, 
        a.company = void 0, a.viewName = e.label) : "datanodeTask" === e.nodeType ? (t.configInfo ? (a.task = t.configInfo.monitorRuleId, 
        a.taskName = t.configInfo.name) : (a.task = void 0, a.taskName = e.label), r.getAllTaskData()) : "datanodeCurrentUser" === e.nodeType && (a.userName = e.label), 
        r.setState({
          form: a
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getSubviewByUserID", (function() {
      (0, _topoService.subViewListAction)().then((function(e) {
        r.setState({
          treeData: e
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "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));
          })), r.setState({
            viewOption: t
          });
        }));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "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));
        })), r.setState({
          deviceOption: t
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "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));
        })), r.setState({
          taskOption: t
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getFormByType", (function() {
      var e = {
        itemName: [ {
          required: !0,
          message: "请输入活动名称"
        }, {
          min: 1,
          max: 150,
          message: "长度范围：0-150！"
        } ],
        subUser: [ {
          required: !0,
          message: "不能为空！"
        }, {
          validator: r.checkSelect
        } ],
        company: [ {
          required: !0,
          message: "不能为空！"
        }, {
          validator: r.checkSelect
        } ],
        view: [ {
          required: !0,
          message: "不能为空！"
        }, {
          validator: r.checkSelect
        } ],
        device: [ {
          required: !0,
          message: "不能为空！"
        }, {
          validator: r.checkSelect
        } ],
        task: [ {
          required: !0,
          message: "不能为空！"
        }, {
          validator: r.checkSelect
        } ]
      }, t = r.props.config, a = r.state, o = a.form, n = a.treeData, i = a.deviceOption, l = a.nodeConfig, d = a.viewOption, c = a.taskOption, u = [];
      return "datanodeDevice" !== t.nodeType || !n || void 0 === i && null !== l.configInfo ? "datanodeCurrentUser" === t.nodeType ? (0, 
      _securityService.getCurrentUser)().then((function(t) {
        u.push(_react.default.createElement(_amosFramework.Form, {
          className: "config-form",
          ref: function(e) {
            return r.form = e;
          },
          model: o,
          rules: e
        }, _react.default.createElement(FormItem, (0, _extends2.default)({
          label: _react.default.createElement("span", null, "节点名称"),
          field: "userName"
        }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
          placeholder: "输入内容",
          value: o.userName,
          disabled: !0,
          style: {
            width: "100%"
          },
          onChange: function(e) {
            return r.onInput("userName", e);
          }
        })), _react.default.createElement(FormItem, (0, _extends2.default)({
          label: "用户名"
        }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
          placeholder: "输入内容",
          defaultValue: t.userName,
          disabled: !0,
          style: {
            width: "100%"
          }
        }))));
      })) : "datanodeTask" === t.nodeType ? u.push(_react.default.createElement(_amosFramework.Form, {
        className: "config-form",
        ref: function(e) {
          return r.form = e;
        },
        model: o,
        rules: e
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: _react.default.createElement("span", null, "节点名称"),
        field: "taskName"
      }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
        placeholder: "输入内容",
        value: o.taskName,
        style: {
          width: "100%"
        },
        onChange: function(e) {
          return r.onInput("taskName", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "用户类型",
        field: "userType"
      }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "100%"
        },
        dropdownStyle: {
          width: "100%"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(e) {
          return r.onSelect("userType", e);
        },
        placeholder: "选择输入内容",
        value: "0"
      }, _react.default.createElement(Option, {
        key: "0",
        value: "0"
      }, "当前用户"))), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "任务",
        field: "task"
      }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "100%"
        },
        dropdownStyle: {
          width: "100%"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(e) {
          return r.onSelect("task", e);
        },
        placeholder: "选择输入内容",
        defaultValue: o.task,
        value: o.task
      }, c)))) : "datanodeView" === t.nodeType && u.push(_react.default.createElement(_amosFramework.Form, {
        className: "config-form",
        ref: function(e) {
          return r.form = e;
        },
        model: o,
        rules: e
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: _react.default.createElement("span", null, "节点名称"),
        field: "viewName"
      }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
        placeholder: "输入内容",
        value: o.viewName,
        style: {
          width: "100%"
        },
        onChange: function(e) {
          return r.onInput("viewName", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "用户类型",
        field: "userType"
      }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "100%"
        },
        dropdownStyle: {
          width: "100%"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(e) {
          return r.onSelect("userType", e);
        },
        placeholder: "选择输入内容",
        value: "0"
      }, _react.default.createElement(Option, {
        key: "0",
        value: "0"
      }, "当前用户"))), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "公司",
        field: "company"
      }, formItemLayout), _react.default.createElement(_amosAntd.TreeSelect, {
        dropdownMatchSelectWidth: !0,
        style: {
          width: "calc(20rem + 15px)"
        },
        value: o.company,
        dropdownStyle: {
          maxHeight: 160,
          overflow: "auto",
          width: "calc(20rem + 15px)"
        },
        treeData: n,
        placeholder: "选择公司",
        treeDefaultExpandAll: !0,
        onChange: function(e) {
          return r.onSelect("company", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "视图",
        field: "view"
      }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "100%"
        },
        dropdownStyle: {
          width: "100%"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(e) {
          return r.onSelect("view", e);
        },
        placeholder: "选择输入内容",
        defaultValue: o.view,
        value: o.view
      }, d)))) : u.push(_react.default.createElement(_amosFramework.Form, {
        className: "config-form",
        ref: function(e) {
          return r.form = e;
        },
        model: o,
        rules: e
      }, _react.default.createElement(FormItem, (0, _extends2.default)({
        label: _react.default.createElement("span", null, "节点名称"),
        field: "itemName"
      }, formItemLayout), _react.default.createElement(_amosFramework.Input, {
        placeholder: "输入内容",
        value: o.itemName,
        style: {
          width: "100%"
        },
        onChange: function(e) {
          return r.onInput("itemName", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "用户类型",
        field: "userType"
      }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "100%"
        },
        dropdownStyle: {
          width: "100%"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(e) {
          return r.onSelect("userType", e);
        },
        placeholder: "选择输入内容",
        value: "0"
      }, _react.default.createElement(Option, {
        key: "0",
        value: "0"
      }, "当前用户"))), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "公司",
        field: "company"
      }, formItemLayout), _react.default.createElement(_amosAntd.TreeSelect, {
        dropdownMatchSelectWidth: !0,
        style: {
          width: "calc(20rem + 15px)"
        },
        value: o.company,
        dropdownStyle: {
          maxHeight: 160,
          overflow: "auto",
          width: "calc(20rem + 15px)"
        },
        treeData: n,
        placeholder: "选择公司",
        treeDefaultExpandAll: !0,
        onChange: function(e) {
          return r.onSelect("company", e);
        }
      })), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "视图",
        field: "view"
      }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "100%"
        },
        dropdownStyle: {
          width: "100%"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(e) {
          return r.onSelect("view", e);
        },
        placeholder: "选择输入内容",
        defaultValue: o.view,
        value: o.view
      }, d)), _react.default.createElement(FormItem, (0, _extends2.default)({
        label: "设备",
        field: "device"
      }, formItemLayout), _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "100%"
        },
        dropdownStyle: {
          width: "100%"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(e) {
          return r.onSelect("device", e);
        },
        placeholder: "选择输入内容",
        defaultValue: o.device,
        value: o.device
      }, i)))), u;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleSubmit", (function(e) {
      e.preventDefault(), r.form.validate((function(e, t) {
        if (console.log("返回内容:", t, e), !e) return !1;
        r.saveConfig();
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "checkSelect", (function(e, t, a) {
      "0" === t ? a("请选择！") : a();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "saveConfig", (function() {
      var e, t, a = r.props.config, o = r.state, n = o.form, i = o.nodeConfig;
      "datanodeDevice" === a.nodeType ? (e = {
        nodeId: a.id,
        nodeType: a.nodeType,
        label: void 0 === n.itemName ? i.label : n.itemName
      }, t = {
        user_type: "0",
        view: void 0 === n.view ? i.configInfo.view : n.view,
        eqpId: void 0 === n.device ? i.configInfo.eqpId : n.device,
        orgCode: void 0 === n.company ? i.configInfo.orgCode : n.company
      }) : "datanodeTask" === a.nodeType ? (e = {
        nodeId: a.id,
        nodeType: a.nodeType,
        label: void 0 === n.taskName ? i.label : n.taskName
      }, t = {
        user_type: "0",
        monitorRuleId: void 0 === n.task ? i.configInfo.monitorRuleId : n.task
      }) : "datanodeView" === a.nodeType && (e = {
        nodeId: a.id,
        nodeType: a.nodeType,
        label: void 0 === n.viewName ? i.label : n.viewName
      }, t = {
        user_type: "0",
        view: void 0 === n.view ? i.configInfo.view : n.view,
        orgCode: void 0 === n.company ? i.configInfo.orgCode : n.company
      }), e = _objectSpread(_objectSpread({}, e), {}, {
        configInfo: t
      }), (0, _ruleDesignService.updateNode)(e).then((function(t) {
        _rayEventpool.PubSub.publish(_stageConf.ELE_UPDATE_TOPIC.trigger, {
          label: e.label,
          nodeId: a.id
        }), _amosFramework.message.success("保存成功");
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "removeItem", (function(e, t) {
      t && (_rayEventpool.PubSub.publish(_stageConf.ELE_DEL_TOPIC.trigger, {
        eleId: t
      }), r.props.closeTriggerDesigner());
    }));
    var o = r.props.config;
    return r.state = {
      nodeConfig: {},
      form: {
        isSubUser: !1,
        treeData: [],
        deviceOption: [],
        viewOption: [],
        taskOption: [],
        itemName: o.label,
        viewName: o.label,
        taskName: o.label,
        isEdited: !1
      }
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentWillMount",
    value: function() {}
  }, {
    key: "componentDidMount",
    value: function() {
      var e = this;
      this.getSubviewByUserID(), this.getNodeConfig(this.props.config), this.pubsub_update = _rayEventpool.PubSub.subscribe(_stageConf.ELE_UPDATE_TOPIC.eleUpdate, (function(t, a) {
        var r = a.label, o = a.nodeId, n = e.props.config;
        if (o === n.id) {
          var i = e.state.form;
          "datanodeDevice" === n.nodeType ? i.itemName = r : "datanodeView" === n.nodeType ? i.viewName = r : "datanodeTask" === n.nodeType && (i.taskName = r), 
          e.setState({
            form: i
          });
        }
      }));
    }
  }, {
    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, a = (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"
      }, a ? _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()));
    }
  } ]), a;
}(_react.Component);

DataSourceConfig.displayName = "DataSourceConfig", DataSourceConfig.propTypes = {
  config: _propTypes.default.object,
  closeTriggerDesigner: _propTypes.default.func
}, DataSourceConfig.defaultProps = {};

var _default = DataSourceConfig;

exports.default = _default;