"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")), _amosAntd = require("amos-antd"), _processor = require("../../utils/processor"), _urlConsts = _interopRequireDefault(require("../../consts/urlConsts")), _publicDevice = _interopRequireDefault(require("./publicDevice")), _privateDevice = _interopRequireDefault(require("./privateDevice")), _addDevice = _interopRequireDefault(require("./privateDevice/addDevice")), _PrivateDeviceDetail = _interopRequireDefault(require("./privateDevice/PrivateDeviceDetail")), _searchBar = _interopRequireDefault(require("./common/searchBar"));

function _getRequireWildcardCache(e) {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap, r = new WeakMap;
  return (_getRequireWildcardCache = function(e) {
    return e ? r : 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 r = _getRequireWildcardCache(t);
  if (r && r.has(e)) return r.get(e);
  var a = {}, 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(a, n, u) : a[n] = e[n];
  }
  return a.default = e, r && r.set(e, a), a;
}

function _createSuper(e) {
  var t = _isNativeReflectConstruct();
  return function() {
    var r, a = (0, _getPrototypeOf2.default)(e);
    if (t) {
      var i = (0, _getPrototypeOf2.default)(this).constructor;
      r = Reflect.construct(a, arguments, i);
    } else r = a.apply(this, arguments);
    return (0, _possibleConstructorReturn2.default)(this, r);
  };
}

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;
  }
}

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

var TabPane = _amosAntd.Tabs.TabPane, DeviceManage = function(e) {
  (0, _inherits2.default)(r, e);
  var t = _createSuper(r);
  function r(e) {
    var a;
    (0, _classCallCheck2.default)(this, r), a = t.call(this, e), (0, _defineProperty2.default)((0, 
    _assertThisInitialized2.default)(a), "onTabClick", (function(e) {
      "1" === e ? a.requestMethod("0", [], e) : a.requestMethod("1", [], e);
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "requestMethod", (function(e, t, r) {
      var i = {
        visibility: e,
        pageSize: -1
      };
      (0, _extends2.default)(i, t), _processor.AmosFetch.post(_urlConsts.default.pageDevice, {
        data: i
      }).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(e) {
        if ("SUCCESS" === e.result && null !== e.content) {
          var t = [], i = [];
          r && (a.activeKey = r, a.setState({
            flag: r
          }));
          var n = a.activeKey;
          "1" === n ? (t.push(_react.default.createElement(_publicDevice.default, {
            key: 1,
            dataList: e.content,
            updateAddView: a.updateAddView,
            visibility: "0"
          })), a.setState({
            tabContent: t
          })) : "2" === n && (i.push(_react.default.createElement(_privateDevice.default, {
            key: 2,
            dataList: e.content,
            updateAddView: a.updateAddView,
            visibility: "1"
          })), a.setState({
            tabPrivateContent: i
          }));
        }
      }));
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "updateAddView", (function(e, t) {
      if ("1" === e) a.requestMethod("0", []); else if ("2" === e) a.requestMethod("1", []); else {
        var r = a.activeKey;
        "1" === r ? a.setState({
          flag: e,
          carInfo: t,
          tabContent: a.showTabPane(e, t)
        }) : "2" === r && a.setState({
          flag: e,
          carInfo: t,
          tabPrivateContent: a.showTabPane(e, t)
        });
      }
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "showTabPane", (function(e, t, r) {
      var i = a.state, n = i.flag, u = i.criterias, l = i.equiptemplateIndustryOptions;
      n = void 0 === e ? n : e;
      var s = void 0 === t ? a.state.carInfo : t;
      u = void 0 === r ? u : r;
      var o = [];
      switch (n) {
       case "1":
        o.push(_react.default.createElement(_publicDevice.default, {
          key: 1,
          updateAddView: a.updateAddView,
          criterias: u,
          visibility: "0"
        }));
        break;

       case "2":
        o.push(_react.default.createElement(_privateDevice.default, {
          key: 2,
          updateAddView: a.updateAddView,
          criterias: u,
          visibility: "1"
        }));
        break;

       case "3":
        o.push(_react.default.createElement(_PrivateDeviceDetail.default, {
          key: 3,
          carInfo: s,
          equiptemplateIndustryOptions: l
        }));
        break;

       case "4":
        o.push(_react.default.createElement(_addDevice.default, {
          key: 4,
          updateAddView: a.updateAddView,
          equiptemplateIndustryOptions: l
        }));
        break;

       default:
        o.push(_react.default.createElement(_publicDevice.default, {
          key: 1,
          updateAddView: a.updateAddView,
          criterias: u,
          visibility: "0"
        }));
      }
      return o;
    })), (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(a), "handleCriterias", (function(e) {
      var t = a.activeKey;
      "1" === t ? a.requestMethod("0", e) : "2" === t && a.requestMethod("1", e);
    }));
    var i = "1", n = a.props.location;
    return n.query.activeKey && (i = n.query.activeKey), a.activeKey = i, a.state = {
      criterias: {},
      flag: i,
      communityOptions: [],
      equiptemplateIndustryOptions: [],
      tabContent: [],
      tabPrivateContent: []
    }, a;
  }
  return (0, _createClass2.default)(r, [ {
    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 r = [];
          !t || t.dataList.map((function(e) {
            r.push({
              value: e.id,
              label: e.name,
              selected: !1,
              style: "all-filter-btn"
            });
          })), e.setState({
            communityOptions: r
          });
        }
      })), _processor.AmosFetch.get(_urlConsts.default.equiptemplateIndustry).then((function(e) {
        if (e.ok) return e.json();
        throw new Error("从服务端获取数据失败！");
      })).then((function(t) {
        if ("SUCCESS" === t.result) {
          var r = [];
          !t || t.dataList.map((function(e) {
            r.push({
              value: e.id,
              label: e.name,
              selected: !1,
              style: "all-filter-btn"
            });
          })), e.setState({
            equiptemplateIndustryOptions: r
          });
        }
      })), this.requestMethod("0", []);
    }
  }, {
    key: "render",
    value: function() {
      var e = this.state, t = e.flag, r = e.communityOptions, a = e.tabContent, i = e.tabPrivateContent, n = e.equiptemplateIndustryOptions, u = this.activeKey;
      return _react.default.createElement("div", {
        className: "tabs-outside"
      }, _react.default.createElement(_amosAntd.Tabs, {
        activeKey: u,
        onTabClick: this.onTabClick,
        tabBarExtraContent: _react.default.createElement(_searchBar.default, {
          flag: t,
          handleCriterias: this.handleCriterias,
          communityOptions: r,
          equiptemplateIndustryOptions: n
        })
      }, _react.default.createElement(TabPane, {
        tab: _react.default.createElement("div", null, "公共"),
        key: "1"
      }, a), _react.default.createElement(TabPane, {
        tab: _react.default.createElement("div", null, "我的"),
        key: "2"
      }, i)));
    }
  } ]), r;
}(_react.Component);

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

var _default = DeviceManage;

exports.default = _default;