"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 _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"), _processor = require("../../utils/processor"), _urlConsts = _interopRequireDefault(require("../../consts/urlConsts")), _publicInterface = _interopRequireDefault(require("./publicInterface")), _privateInterface = _interopRequireDefault(require("./privateInterface")), _addInterface = _interopRequireDefault(require("./addInterface")), _PrivateInterfaceDetail = _interopRequireDefault(require("./privateInterface/PrivateInterfaceDetail")), _searchBar = _interopRequireDefault(require("./common/searchBar"));

require("./../common/style/commonTabs.scss"), require("./../common/style/commonStyle.scss");

var _PropTypes = _interopRequireDefault(require("amos-react-router/lib/PropTypes"));

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 u = i ? Object.getOwnPropertyDescriptor(e, n) : null;
    u && (u.get || u.set) ? Object.defineProperty(r, n, u) : 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 TabPane = _amosAntd.Tabs.TabPane, DeviceInterface = 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), "onTabClick", (function(e) {
      "1" === e ? r.requestMethod("0", r.state.criterias, void 0, e) : "2" === e && r.requestMethod("1", r.state.criterias, void 0, e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "requestMethod", (function(e, t, a, i) {
      var n = {
        name: "visibility",
        type: "EQUAL",
        value: e
      }, u = [];
      if (t.length > 0) {
        for (var s = 0; s < t.length; s++) {
          var l = t[s];
          "EQUAL" !== l.type && u.push(l);
        }
        t = u;
      }
      t.push(n), _processor.AmosFetch.post(_urlConsts.default.interfaceDataList, {
        data: t
      }).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(t) {
        "SUCCESS" === t.result ? null !== t.dataList && r.setState({
          dataList: t.dataList
        }) : r.setState({
          dataList: []
        }), a && r.setState({
          carInfo: a
        }), i && r.setState({
          flag: i,
          criterias: [],
          visibility: e,
          activeKey: i
        });
        var n = r.state, u = n.communityDatas, s = n.criterias, l = [], o = [], c = r.state.activeKey;
        "1" === c ? (l.push(_react.default.createElement(_publicInterface.default, {
          key: 1,
          updateAddView: r.updateAddView,
          dataList: t.dataList,
          requestMethod: r.requestMethod,
          criterias: s,
          visibility: "0"
        })), r.setState({
          tabContent: l
        })) : "2" === c && (o.push(_react.default.createElement(_privateInterface.default, {
          key: 2,
          communityDatas: u,
          updateAddView: r.updateAddView,
          dataList: t.dataList,
          requestMethod: r.requestMethod,
          criterias: s,
          visibility: "1"
        })), r.setState({
          privateTabContent: o
        }));
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "updateAddView", (function(e, t) {
      if ("2" === e) r.requestMethod(r.state.visibility, r.state.criterias, t); else {
        var a = r.state.activeKey;
        "1" === a ? r.setState({
          flag: e,
          carInfo: t,
          tabContent: r.showTabPane(e, t)
        }) : "2" === a && r.setState({
          flag: e,
          carInfo: t,
          privateTabContent: r.showTabPane(e, t)
        });
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "showTabPane", (function(e, t) {
      var a = r.state, i = a.communityDatas, n = a.criterias, u = [];
      switch (e) {
       case "1":
        u.push(_react.default.createElement(_publicInterface.default, {
          key: 1,
          updateAddView: r.updateAddView,
          dataList: r.state.dataList,
          requestMethod: r.requestMethod,
          criterias: n,
          visibility: "0"
        }));
        break;

       case "2":
        u.push(_react.default.createElement(_privateInterface.default, {
          key: 2,
          communityDatas: i,
          updateAddView: r.updateAddView,
          dataList: r.state.dataList,
          requestMethod: r.requestMethod,
          criterias: n,
          visibility: "1"
        }));
        break;

       case "3":
        u.push(_react.default.createElement(_PrivateInterfaceDetail.default, {
          key: 3,
          communityDatas: i,
          carInfo: t
        }));
        break;

       case "4":
        u.push(_react.default.createElement(_addInterface.default, {
          key: 4,
          communityDatas: i,
          updateAddView: r.updateAddView
        }));
        break;

       default:
        u.push(_react.default.createElement(_publicInterface.default, {
          key: 1,
          updateAddView: r.updateAddView,
          criterias: n,
          visibility: "0"
        }));
      }
      return u;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(r), "handleCriterias", (function(e) {
      var t = r.state.visibility;
      r.setState({
        criterias: e
      }), r.requestMethod(t, e);
    }));
    var i = "1", n = r.props.location;
    return n.query.activeKey && (i = n.query.activeKey), r.state = {
      visibility: "0",
      criterias: [],
      flag: i,
      dataList: [],
      communityDatas: [],
      communityOptions: [],
      tabContent: [],
      privateTabContent: [],
      activeKey: i
    }, r;
  }
  return (0, _createClass2.default)(a, [ {
    key: "componentWillMount",
    value: function() {
      var e = this;
      _processor.AmosFetch.get(_urlConsts.default.communityProtocol).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) {
            a.push({
              value: e.id,
              label: e.name,
              selected: !1,
              style: "all-filter-btn"
            });
          })), e.setState({
            communityOptions: a,
            communityDatas: t.dataList
          });
        }
      })), this.requestMethod("1" === this.state.activeKey ? "0" : "1", []);
    }
  }, {
    key: "render",
    value: function() {
      var e = this.state, t = e.communityOptions, a = e.activeKey, r = e.privateTabContent, i = e.tabContent;
      return _react.default.createElement("div", {
        className: "tabs-outside"
      }, _react.default.createElement(_amosAntd.Tabs, {
        activeKey: a,
        onTabClick: this.onTabClick,
        tabBarExtraContent: _react.default.createElement(_searchBar.default, {
          handleCriterias: this.handleCriterias,
          communityOptions: t
        })
      }, _react.default.createElement(TabPane, {
        tab: _react.default.createElement("div", null, "公共"),
        key: "1"
      }, i), _react.default.createElement(TabPane, {
        tab: _react.default.createElement("div", null, "我的"),
        key: "2"
      }, r)));
    }
  } ]), a;
}(_react.Component);

DeviceInterface.displayName = "DeviceInterface", DeviceInterface.propTypes = {};

var _default = DeviceInterface;

exports.default = _default;