"use strict";
Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.default = void 0;
var _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 _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, i = {},
    n = Object.defineProperty && Object.getOwnPropertyDescriptor;
  for (r in e) Object.prototype.hasOwnProperty.call(e, r) && ((a = n ? Object.getOwnPropertyDescriptor(e, r) : null) && (a.get || a.set) ? Object.defineProperty(i, r, a) : i[r] = e[r]);
  return i.default = e, t && t.set(e, i), i
}

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
}
require("./../common/style/commonTabs.scss"), require("./../common/style/commonStyle.scss");
var TabPane = _amosAntd.Tabs.TabPane,
  DeviceManage = function() {
    _inherits(a, _react.Component);
    var r = _createSuper(a);

    function a(e) {
      var o;
      _classCallCheck(this, a), _defineProperty(_assertThisInitialized(o = r.call(this, e)), "onTabClick", function(e) {
        "1" === e ? o.requestMethod("0", [], e) : o.requestMethod("1", [], e)
      }), _defineProperty(_assertThisInitialized(o), "requestMethod", function(e, t, i) {
        e = {
          visibility: e,
          pageSize: -1
        };
        _extends(e, t), _processor.AmosFetch.post(_urlConsts.default.pageDevice, {
          data: e
        }).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t, r, a;
          "SUCCESS" === e.result && null !== e.content && (t = [], r = [], i && (o.activeKey = i, o.setState({
            flag: i
          })), "1" === (a = o.activeKey) ? (t.push(_react.default.createElement(_publicDevice.default, {
            key: 1,
            dataList: e.content,
            updateAddView: o.updateAddView,
            visibility: "0"
          })), o.setState({
            tabContent: t
          })) : "2" === a && (r.push(_react.default.createElement(_privateDevice.default, {
            key: 2,
            dataList: e.content,
            updateAddView: o.updateAddView,
            visibility: "1"
          })), o.setState({
            tabPrivateContent: r
          })))
        })
      }), _defineProperty(_assertThisInitialized(o), "updateAddView", function(e, t) {
        var r;
        "1" === e ? o.requestMethod("0", []) : "2" === e ? o.requestMethod("1", []) : "1" === (r = o.activeKey) ? o.setState({
          flag: e,
          carInfo: t,
          tabContent: o.showTabPane(e, t)
        }) : "2" === r && o.setState({
          flag: e,
          carInfo: t,
          tabPrivateContent: o.showTabPane(e, t)
        })
      }), _defineProperty(_assertThisInitialized(o), "showTabPane", function(e, t, r) {
        var a = o.state,
          i = a.flag,
          n = a.criterias,
          a = a.equiptemplateIndustryOptions,
          i = void 0 === e ? i : e,
          t = void 0 === t ? o.state.carInfo : t,
          n = void 0 === r ? n : r,
          r = [];
        switch (i) {
          case "1":
            r.push(_react.default.createElement(_publicDevice.default, {
              key: 1,
              updateAddView: o.updateAddView,
              criterias: n,
              visibility: "0"
            }));
            break;
          case "2":
            r.push(_react.default.createElement(_privateDevice.default, {
              key: 2,
              updateAddView: o.updateAddView,
              criterias: n,
              visibility: "1"
            }));
            break;
          case "3":
            r.push(_react.default.createElement(_PrivateDeviceDetail.default, {
              key: 3,
              carInfo: t,
              equiptemplateIndustryOptions: a
            }));
            break;
          case "4":
            r.push(_react.default.createElement(_addDevice.default, {
              key: 4,
              updateAddView: o.updateAddView,
              equiptemplateIndustryOptions: a
            }));
            break;
          default:
            r.push(_react.default.createElement(_publicDevice.default, {
              key: 1,
              updateAddView: o.updateAddView,
              criterias: n,
              visibility: "0"
            }))
        }
        return r
      }), _defineProperty(_assertThisInitialized(o), "handleCriterias", function(e) {
        var t = o.activeKey;
        "1" === t ? o.requestMethod("0", e) : "2" === t && o.requestMethod("1", e)
      });
      var t = "1",
        e = o.props.location;
      return e.query.activeKey && (t = e.query.activeKey), o.activeKey = t, o.state = {
        criterias: {},
        flag: t,
        communityOptions: [],
        equiptemplateIndustryOptions: [],
        tabContent: [],
        tabPrivateContent: []
      }, o
    }
    return _createClass(a, [{
      key: "componentWillMount",
      value: function() {
        var r = this;
        _processor.AmosFetch.get(_urlConsts.default.communityProtocol).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t;
          "SUCCESS" === e.result && (t = [], e && e.dataList.map(function(e) {
            t.push({
              value: e.id,
              label: e.name,
              selected: !1,
              style: "all-filter-btn"
            })
          }), r.setState({
            communityOptions: t
          }))
        }), _processor.AmosFetch.get(_urlConsts.default.equiptemplateIndustry).then(function(e) {
          if (e.ok) return e.json();
          throw new Error("从服务端获取数据失败！")
        }).then(function(e) {
          var t;
          "SUCCESS" === e.result && (t = [], e && e.dataList.map(function(e) {
            t.push({
              value: e.id,
              label: e.name,
              selected: !1,
              style: "all-filter-btn"
            })
          }), r.setState({
            equiptemplateIndustryOptions: t
          }))
        }), 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,
          e = this.activeKey;
        return _react.default.createElement("div", {
          className: "tabs-outside"
        }, _react.default.createElement(_amosAntd.Tabs, {
          activeKey: e,
          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)))
      }
    }]), a
  }();
DeviceManage.displayName = "DeviceManage", DeviceManage.propTypes = {};
var _default = DeviceManage;
exports.default = DeviceManage, module.exports = exports.default;
