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

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 r, a, n = {},
    o = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((a = o ? Object.getOwnPropertyDescriptor(e, r) : null) && (a.get || a.set) ? Object.defineProperty(n, r, a) : n[r] = e[r]);
  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 _extends() {
  return (_extends = Object.assign || function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var r, a = arguments[t];
      for (r in a) Object.prototype.hasOwnProperty.call(a, r) && (e[r] = a[r])
    }
    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 r = 0; r < t.length; r++) {
    var a = t[r];
    a.enumerable = a.enumerable || !1, a.configurable = !0, "value" in a && (a.writable = !0), Object.defineProperty(e, a.key, a)
  }
}

function _createClass(e, t, r) {
  return t && _defineProperties(e.prototype, t), r && _defineProperties(e, r), 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(r) {
  var a = _isNativeReflectConstruct();
  return function() {
    var e, t = _getPrototypeOf(r);
    return _possibleConstructorReturn(this, a ? (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, r) {
  return t in e ? Object.defineProperty(e, t, {
    value: r,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = r, e
}
var Option = _amosAntd.Select.Option,
  TreeNode = _amosAntd.Select.TreeNode,
  QueryPanel = function() {
    _inherits(r, _react.Component);
    var t = _createSuper(r);

    function r(e) {
      var n;
      return _classCallCheck(this, r), _defineProperty(_assertThisInitialized(n = t.call(this, e)), "onSearch", function(e) {
        n.props.getHistoryData()
      }), _defineProperty(_assertThisInitialized(n), "onSelect", function(e, t) {
        var r = n.state;
        r[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))
            }), r.device = void 0, r.capacity = void 0, r.view = void 0, n.setState({
              viewOption: t,
              selectedItem: r,
              deviceOption: [],
              capacityOption: []
            }), n.props.setEmptyParam()
          })
        }) : (r.device = void 0, r.capacity = void 0, r.view = void 0, n.setState({
          selectedItem: r,
          deviceOption: [],
          capacityOption: [],
          viewOption: []
        }), n.props.setEmptyParam())
      }), _defineProperty(_assertThisInitialized(n), "onSelectedChange", function(e, t) {
        var r, a = n.state;
        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, n.setState({
              viewOption: t,
              selectedItem: a,
              deviceOption: [],
              capacityOption: []
            }), n.props.setEmptyParam()
          })
        }) : (a.device = void 0, a.capacity = void 0, a.view = void 0, n.setState({
          selectedItem: a,
          deviceOption: [],
          capacityOption: [],
          viewOption: []
        }), n.props.setEmptyParam()) : "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, n.setState({
            deviceOption: t,
            capacityOption: [],
            selectedItem: a
          }), n.props.setEmptyParam()
        }) : (a.device = void 0, a.capacity = void 0, n.setState({
          capacityOption: [],
          selectedItem: a,
          deviceOption: []
        }), n.props.setEmptyParam()) : "device" === t ? (e ? (r = "".concat(_urlConsts.default.getDeviceTemplateByEgpId, "/").concat(e), _processor.AmosFetch.get(r).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t;
          "SUCCESS" === e.result && (e = e.dataList, t = [], e.capabilities.map(function(e) {
            t.push(_react.default.createElement(Option, {
              key: e.id,
              value: "".concat(e.id)
            }, e.name))
          }), n.setState({
            capacityOption: t,
            selectedItem: a
          }))
        })) : (a.capacity = void 0, n.setState({
          selectedItem: a,
          capacityOption: []
        }), n.props.setEmptyParam()), n.props.setSearchDeviceParam(e)) : "capacity" === t ? (n.setState({
          selectedItem: a
        }), n.props.setSearchCapacityParam(e)) : "start" === t ? (0, n.props.setStartTimeParam)(null !== e ? e.format("YYYY-MM-DD HH:mm:ss") : void 0) : "end" === t && (0, n.props.setEndTimeParam)(null !== e ? e.format("YYYY-MM-DD HH:mm:ss") : void 0)
      }), _defineProperty(_assertThisInitialized(n), "getCompanyByUserID", function() {
        (0, _topoService.subViewListAction)().then(function(e) {
          console.log(e), n.setState({
            treeData: e
          })
        })
      }), _defineProperty(_assertThisInitialized(n), "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
          }, n.renderTreeNodes(e.children)) : _react.default.createElement(TreeNode, _extends({
            title: e.companyName,
            key: e.orgCode,
            value: e.sequenceNbr
          }, e))
        })
      }), n.state = {
        treeData: [],
        selectedItem: {},
        deviceOption: [],
        capacityOption: []
      }, n
    }
    return _createClass(r, [{
      key: "componentDidMount",
      value: function() {
        this.getCompanyByUserID()
      }
    }, {
      key: "render",
      value: function() {
        var t = this,
          e = this.state,
          r = e.treeData,
          a = e.deviceOption,
          n = e.capacityOption,
          o = e.viewOption,
          i = e.selectedItem,
          c = (i.company, i.view),
          e = i.device,
          i = i.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(e) {
            return t.onSelectedChange(e, "company")
          },
          allowClear: !0
        }, this.renderTreeNodes(r))), _react.default.createElement("div", {
          className: "subgraph-select"
        }, _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "160px"
          },
          dropdownStyle: {
            width: "160px"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return t.onSelectedChange(e, "view")
          },
          placeholder: "选择视图",
          value: c,
          allowClear: !0
        }, o)), _react.default.createElement("div", {
          className: "device-select"
        }, _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "160px"
          },
          dropdownStyle: {
            width: "160px"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return t.onSelectedChange(e, "device")
          },
          placeholder: "选择设备",
          value: e,
          allowClear: !0
        }, a)), _react.default.createElement("div", {
          className: "capacity-select"
        }, _react.default.createElement(_amosAntd.Select, {
          style: {
            width: "160px"
          },
          dropdownStyle: {
            width: "160px"
          },
          dropdownMatchSelectWidth: !0,
          onChange: function(e) {
            return t.onSelectedChange(e, "capacity")
          },
          value: i,
          placeholder: "选择设备能力",
          allowClear: !0
        }, n)), _react.default.createElement("div", {
          className: "starttime-select"
        }, _react.default.createElement(_amosAntd.DatePicker, {
          showTime: !0,
          format: "YYYY-MM-DD HH:mm:ss",
          placeholder: "开始时间",
          onChange: function(e) {
            return t.onSelectedChange(e, "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(e) {
            return t.onSelectedChange(e, "end")
          },
          onOk: this.onEndTime,
          allowClear: !0
        })), _react.default.createElement("div", {
          className: "confirm-select"
        }, _react.default.createElement(_amosAntd.Button, {
          type: "primary",
          onClick: this.onSearch
        }, "搜索")))
      }
    }]), r
  }();
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 = QueryPanel, module.exports = exports.default;
