"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = SBXLFX;
var _react = _interopRequireWildcard(require("react"));
require("./index.less");
var _antd = require("antd");
var _ahooks = require("ahooks");
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _api = require("../../api");
var _moment = _interopRequireDefault(require("moment"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
var _icons = require("@ant-design/icons");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function SBXLFX(props) {
  var prefix = props.prefix,
    facilityId = props.facilityId,
    deviceId = props.deviceId;
  var _useSetState = (0, _ahooks.useSetState)({
      timeType: 1,
      dataList: []
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var timeType = state.timeType,
    dataList = state.dataList;
  var option = {
    tooltip: {
      trigger: 'axis',
      valueFormatter: function valueFormatter(value) {
        return "".concat(value, "h");
      }
    },
    legend: {},
    grid: {
      left: '3%',
      right: '130px',
      bottom: '3%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      show: false,
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      }
    },
    yAxis: {
      type: 'category',
      data: dataList === null || dataList === void 0 ? void 0 : dataList.map(function (it) {
        return it === null || it === void 0 ? void 0 : it.facilityName;
      }),
      axisLine: {
        show: false
      },
      splitLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#8C8C8C',
        fontSize: '12'
      }
    },
    series: [{
      name: '高效',
      type: 'bar',
      stack: 'total',
      color: '#52C41A',
      label: {
        show: false
      },
      emphasis: {
        focus: 'series'
      },
      itemStyle: {
        borderRadius: [32, 32, 32, 32]
      },
      barWidth: 10,
      data: dataList === null || dataList === void 0 ? void 0 : dataList.map(function (it) {
        return it === null || it === void 0 ? void 0 : it.efficientHours;
      })
    }, {
      name: '低效',
      type: 'bar',
      stack: 'total',
      color: '#FAAD14',
      label: {
        show: true,
        position: 'right',
        formatter: function formatter(params) {
          var obj = dataList[params === null || params === void 0 ? void 0 : params.dataIndex];
          return "{a|".concat(obj.efficientRate || 0, "%}{c|", "}{b|").concat((obj === null || obj === void 0 ? void 0 : obj.inefficientRate) || 0, "%}");
        },
        textStyle: {
          rich: {
            a: {
              color: '#52C41A',
              fontFamily: 'DIN, DIN',
              fontSize: '14px',
              padding: [0, 10]
            },
            c: {
              width: 1,
              height: 10,
              backgroundColor: '#E8E8E8'
            },
            b: {
              color: '#FAAD14',
              fontFamily: 'DIN, DIN',
              fontSize: '14px',
              padding: [0, 10]
            }
          }
        }
      },
      emphasis: {
        focus: 'series'
      },
      barWidth: 10,
      itemStyle: {
        borderRadius: [32, 32, 32, 32]
      },
      data: dataList === null || dataList === void 0 ? void 0 : dataList.map(function (it) {
        return it === null || it === void 0 ? void 0 : it.inefficientHours;
      })
    }]
  };
  (0, _react.useEffect)(function () {
    if (deviceId) {
      _api.SbxlService.findWaterPumpDayEfficiencyRecord({
        facilityId: facilityId,
        deviceId: deviceId,
        begin: (0, _moment["default"])().subtract(timeType, 'month').startOf('day').format('YYYY-MM-DD HH:mm:ss'),
        end: (0, _moment["default"])().endOf('day').format('YYYY-MM-DD HH:mm:ss')
      }).then(function (data) {
        setState({
          dataList: data
        });
      });
    }
  }, [facilityId, deviceId, timeType]);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sbxl-main-top-sbxlfx")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sbxl-main-top-title")
  }, /*#__PURE__*/_react["default"].createElement("span", null, "\u6C34\u6CF5\u6548\u7387\u5206\u6790\xA0", /*#__PURE__*/_react["default"].createElement(_antd.Tooltip, {
    title: "\u901A\u8FC7\u5B9E\u65F6\u6570\u636E\u8FD0\u7B97\uFF0C\u5F53\u6C34\u6CF5\u6548\u7387\u226575\u65F6\uFF0C\u4E3A\u9AD8\u6548\uFF0C\u6C34\u6CF5\u6548\u7387\uFF1C75\u65F6\uFF0C\u4E3A\u4F4E\u6548"
  }, /*#__PURE__*/_react["default"].createElement(_icons.QuestionCircleOutlined, null))), /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement("span", null, "\u65F6\u95F4\uFF1A"), /*#__PURE__*/_react["default"].createElement(_antd.Radio.Group, {
    style: {
      marginLeft: 10
    },
    options: [{
      label: '近一个月',
      value: 1
    }, {
      label: '近半年',
      value: 5
    }, {
      label: '近一年',
      value: 11
    }],
    optionType: "button",
    value: timeType,
    onChange: function onChange(e) {
      setState({
        timeType: e.target.value
      });
    }
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sbxl-main-top-chart")
  }, (dataList === null || dataList === void 0 ? void 0 : dataList.length) ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      width: '100%',
      height: "".concat(30 * (dataList === null || dataList === void 0 ? void 0 : dataList.length), "px"),
      minHeight: '200px'
    }
  })) : (/*#__PURE__*/_react["default"].createElement("div", {
    style: {
      height: 100,
      marginTop: 10
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmNodata["default"], null)))));
}
//# sourceMappingURL=SBXLFXV2.js.map
