"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"), _processor = require("../../../utils/processor"), _urlConsts = _interopRequireDefault(require("../../../consts/urlConsts")), _topoService = require("./../../../services/topoService");

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 = {}, i = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (var n in e) if ("default" !== n && Object.prototype.hasOwnProperty.call(e, n)) {
    var o = i ? Object.getOwnPropertyDescriptor(e, n) : null;
    o && (o.get || o.set) ? Object.defineProperty(r, n, o) : 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 i = (0, _getPrototypeOf2.default)(this).constructor;
      a = Reflect.construct(r, arguments, i);
    } 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, TreeNode = _amosAntd.Select.TreeNode, QueryPanel = 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), "onSearch", (function(e) {
      r.props.getHistoryData();
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onSelect", (function(e, t) {
      var a = r.state;
      a[type] = value, value ? (0, _topoService.fetchCompanyById)(value).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: e.id
            }, e.name));
          })), a.device = void 0, a.capacity = void 0, a.view = void 0, r.setState({
            viewOption: t,
            selectedItem: a,
            deviceOption: [],
            capacityOption: []
          }), r.props.setEmptyParam();
        }));
      })) : (a.device = void 0, a.capacity = void 0, a.view = void 0, r.setState({
        selectedItem: a,
        deviceOption: [],
        capacityOption: [],
        viewOption: []
      }), r.props.setEmptyParam());
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "onSelectedChange", (function(e, t) {
      var a = r.state;
      if (a[t] = e, "company" === t) e ? (0, _topoService.fetchCompanyById)(e).then((function(e) {
        e && (0, _topoService.subviewByOrgCodeAction)(e.orgCode).then((function(e) {
          var t = [];
          e.map((function(e) {
            return t.push(_react.default.createElement(Option, {
              key: e.id,
              value: e.id
            }, e.name));
          })), a.device = void 0, a.capacity = void 0, a.view = void 0, r.setState({
            viewOption: t,
            selectedItem: a,
            deviceOption: [],
            capacityOption: []
          }), r.props.setEmptyParam();
        }));
      })) : (a.device = void 0, a.capacity = void 0, a.view = void 0, r.setState({
        selectedItem: a,
        deviceOption: [],
        capacityOption: [],
        viewOption: []
      }), r.props.setEmptyParam()); else if ("view" === t) e ? (0, _topoService.fetchSubEgpListAction)(e).then((function(e) {
        var t = [];
        e.map((function(e) {
          t.push(_react.default.createElement(Option, {
            key: e.id,
            value: "".concat(e.id)
          }, e.name));
        })), a.device = void 0, a.capacity = void 0, r.setState({
          deviceOption: t,
          capacityOption: [],
          selectedItem: a
        }), r.props.setEmptyParam();
      })) : (a.device = void 0, a.capacity = void 0, r.setState({
        capacityOption: [],
        selectedItem: a,
        deviceOption: []
      }), r.props.setEmptyParam()); else if ("device" === t) {
        if (e) {
          var i = "".concat(_urlConsts.default.getDeviceTemplateByEgpId, "/").concat(e);
          _processor.AmosFetch.get(i).then((function(e) {
            if (e.ok) return e.json();
            throw new Error("从服务端获取数据失败！");
          })).then((function(e) {
            if ("SUCCESS" === e.result) {
              var t = e.dataList, i = [];
              t.capabilities.map((function(e) {
                i.push(_react.default.createElement(Option, {
                  key: e.id,
                  value: "".concat(e.id)
                }, e.name));
              })), r.setState({
                capacityOption: i,
                selectedItem: a
              });
            }
          }));
        } else a.capacity = void 0, r.setState({
          selectedItem: a,
          capacityOption: []
        }), r.props.setEmptyParam();
        r.props.setSearchDeviceParam(e);
      } else if ("capacity" === t) r.setState({
        selectedItem: a
      }), r.props.setSearchCapacityParam(e); else if ("start" === t) {
        var n = r.props.setStartTimeParam;
        if (null !== e) n(e.format("YYYY-MM-DD HH:mm:ss")); else n(void 0);
      } else if ("end" === t) {
        var o = r.props.setEndTimeParam;
        if (null !== e) o(e.format("YYYY-MM-DD HH:mm:ss")); else o(void 0);
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "getCompanyByUserID", (function() {
      (0, _topoService.subViewListAction)().then((function(e) {
        console.log(e), r.setState({
          treeData: e
        });
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "renderTreeNodes", (function(e) {
      return e && e.map((function(e) {
        return e.children ? _react.default.createElement(TreeNode, {
          title: e.companyName,
          key: e.orgCode,
          value: e.sequenceNbr,
          dataRef: e
        }, r.renderTreeNodes(e.children)) : _react.default.createElement(TreeNode, (0, _extends2.default)({
          title: e.companyName,
          key: e.orgCode,
          value: e.sequenceNbr
        }, e));
      }));
    })), r.state = {
      treeData: [],
      selectedItem: {},
      deviceOption: [],
      capacityOption: []
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentDidMount",
    value: function() {
      this.getCompanyByUserID();
    }
  }, {
    key: "render",
    value: function() {
      var e = this, t = this.state, a = t.treeData, r = t.deviceOption, i = t.capacityOption, n = t.viewOption, o = t.selectedItem, c = (o.company, 
      o.view), l = o.device, s = o.capacity;
      return _react.default.createElement("div", {
        className: "search-root"
      }, _react.default.createElement("div", {
        className: "company-select"
      }, _react.default.createElement(_amosAntd.TreeSelect, {
        dropdownMatchSelectWidth: !0,
        style: {
          width: 160
        },
        dropdownStyle: {
          maxHeight: 160,
          overflow: "auto"
        },
        placeholder: "选择公司",
        treeDefaultExpandAll: !0,
        onChange: function(t) {
          return e.onSelectedChange(t, "company");
        },
        allowClear: !0
      }, this.renderTreeNodes(a))), _react.default.createElement("div", {
        className: "subgraph-select"
      }, _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "160px"
        },
        dropdownStyle: {
          width: "160px"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(t) {
          return e.onSelectedChange(t, "view");
        },
        placeholder: "选择视图",
        value: c,
        allowClear: !0
      }, n)), _react.default.createElement("div", {
        className: "device-select"
      }, _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "160px"
        },
        dropdownStyle: {
          width: "160px"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(t) {
          return e.onSelectedChange(t, "device");
        },
        placeholder: "选择设备",
        value: l,
        allowClear: !0
      }, r)), _react.default.createElement("div", {
        className: "capacity-select"
      }, _react.default.createElement(_amosAntd.Select, {
        style: {
          width: "160px"
        },
        dropdownStyle: {
          width: "160px"
        },
        dropdownMatchSelectWidth: !0,
        onChange: function(t) {
          return e.onSelectedChange(t, "capacity");
        },
        value: s,
        placeholder: "选择设备能力",
        allowClear: !0
      }, i)), _react.default.createElement("div", {
        className: "starttime-select"
      }, _react.default.createElement(_amosAntd.DatePicker, {
        showTime: !0,
        format: "YYYY-MM-DD HH:mm:ss",
        placeholder: "开始时间",
        onChange: function(t) {
          return e.onSelectedChange(t, "start");
        },
        onOk: this.onStartTime,
        allowClear: !0
      })), _react.default.createElement("div", {
        className: "endtime-select"
      }, _react.default.createElement(_amosAntd.DatePicker, {
        showTime: !0,
        format: "YYYY-MM-DD HH:mm:ss",
        placeholder: "结束时间",
        onChange: function(t) {
          return e.onSelectedChange(t, "end");
        },
        onOk: this.onEndTime,
        allowClear: !0
      })), _react.default.createElement("div", {
        className: "confirm-select"
      }, _react.default.createElement(_amosAntd.Button, {
        type: "primary",
        onClick: this.onSearch
      }, "搜索")));
    }
  } ]), a;
}(_react.Component);

QueryPanel.displayName = "QueryPanel", QueryPanel.propTypes = {
  setSearchDeviceParam: _propTypes.default.func,
  setSearchCapacityParam: _propTypes.default.func,
  setEndTimeParam: _propTypes.default.func,
  setStartTimeParam: _propTypes.default.func,
  setEmptyParam: _propTypes.default.func,
  getHistoryData: _propTypes.default.func
};

var _default = QueryPanel;

exports.default = _default;