"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"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _index = require("../../index");
var _api = require("../../api");
require("./index.less");
var _antd = require("antd");
var _ahooks = require("ahooks");
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _moment = _interopRequireDefault(require("moment"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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; }
var Sxyx = function Sxyx() {
  var _useContext = (0, _react.useContext)(_index.PumpContext),
    prefix = _useContext.prefix,
    id = _useContext.id;
  var _useSetState = (0, _ahooks.useSetState)({
      sxId: '',
      dataList: [],
      currentSx: {
        liquidLevelHeight: 0,
        sxHigh: 0,
        sxdx: 0,
        name: '',
        azwz: '',
        cz: '',
        sxgg: '',
        waterTankAge: ''
      }
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var sxId = state.sxId,
    dataList = state.dataList,
    currentSx = state.currentSx;
  (0, _react.useEffect)(function () {
    _api.SxyxService.sxyxData(id).then(function (data) {
      if (data) {
        var newDataList = data.map(function (item) {
          return Object.assign(Object.assign({}, item), item.dataJson);
        });
        setState({
          dataList: newDataList,
          sxId: newDataList.length ? newDataList[0].id : '',
          currentSx: newDataList.length ? newDataList[0] : ''
        });
      }
    });
  }, []);
  var fields = [{
    label: '水箱位置',
    key: 'azwz'
  }, {
    label: '材质',
    key: 'cz'
  }, {
    label: '规格',
    key: 'sxgg'
  }, {
    label: '水箱水龄',
    key: 'waterTankAge'
  }];
  var ywTrendDataList = _api.SxyxService.ywTrendData({
    ids: dataList.map(function (item) {
      return item.id;
    }).join(',')
  });
  var xData = ywTrendDataList.length ? ywTrendDataList[0].values.map(function (value) {
    return (0, _moment["default"])(value.x).format('HH:mm');
  }) : [];
  var options = {
    color: ['#0E85FF', '#49FF81', '#26D4FF', '#F5D629', '#C97CFF'],
    tooltip: {
      trigger: 'axis',
      formatter: function formatter(params) {
        var _params$ = params[0],
          value = _params$.value,
          marker = _params$.marker,
          name = _params$.name;
        return "<div>".concat(marker).concat(name, "\uFF1A").concat(value, "m</div>");
      }
    },
    legend: {
      type: 'scroll',
      top: 0,
      left: 'center',
      textStyle: {
        color: '#000000'
      }
    },
    grid: {
      top: 50,
      left: 20,
      right: 20,
      bottom: 20,
      containLabel: true
    },
    xAxis: {
      data: xData,
      axisLabel: {
        color: '#000000',
        interval: 'auto'
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      z: 10
    },
    yAxis: {
      name: 'm',
      nameTextStyle: {
        color: '#000000'
      },
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: '#000000'
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(255,255,255,0.2)'
        }
      }
    },
    series: ywTrendDataList.map(function (item) {
      var _a;
      return {
        name: ((_a = dataList.find(function (each) {
          return each.pumpId === item.facilityId;
        })) === null || _a === void 0 ? void 0 : _a['name']) || '',
        type: 'line',
        smooth: true,
        data: item.values.map(function (value) {
          return value.y;
        })
      };
    })
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      height: 250,
      width: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-card")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-card-title")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-title-text")
  }, "\u6C34\u7BB1\u8FD0\u884C\u60C5\u51B5"), /*#__PURE__*/_react["default"].createElement(_antd.Radio.Group, {
    optionType: "button",
    value: sxId,
    onChange: function onChange(e) {
      setState({
        sxId: e.target.value,
        currentSx: dataList.find(function (one) {
          return one.id === e.target.value;
        })
      });
    }
  }, dataList.map(function (item) {
    return {
      label: item.name,
      value: item.id
    };
  }).map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_antd.Radio, {
      value: item.value,
      key: item.value
    }, item.label);
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-card-content")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      width: '30%',
      display: 'flex',
      flexDirection: 'column',
      justifyContent: 'center'
    }
  }, fields.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: item.key,
      style: {
        marginBottom: 10
      }
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefix, "-sxyx-card-content-label")
    }, item.label, "\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefix, "-sxyx-card-content-value")
    }, (currentSx === null || currentSx === void 0 ? void 0 : currentSx[item.key]) || '--'));
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info-sxHeight")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-content-label")
  }, "\u6C34\u7BB1\u9AD8(m)\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-content-value")
  }, (currentSx === null || currentSx === void 0 ? void 0 : currentSx.height) || 0), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info-line")
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info-sxMaxHeight")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-content-label")
  }, "\u6C34\u7BB1\u9AD8\u9650(m)\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-content-value")
  }, (currentSx === null || currentSx === void 0 ? void 0 : currentSx.sxHigh) || 0), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info-line")
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info-sxMinHeight")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-content-label")
  }, "\u6C34\u7BB1\u4F4E\u9650(m)\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-content-value")
  }, (currentSx === null || currentSx === void 0 ? void 0 : currentSx.sxdx) || 0), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info-line")
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "lui-column-bg"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "lui-inner",
    style: {
      height: (currentSx === null || currentSx === void 0 ? void 0 : currentSx.liquidLevelHeight) && (currentSx === null || currentSx === void 0 ? void 0 : currentSx.sxHigh) ? (Number(currentSx === null || currentSx === void 0 ? void 0 : currentSx.liquidLevelHeight) / Number(currentSx === null || currentSx === void 0 ? void 0 : currentSx.sxHigh) * 100).toFixed(0) + '%' : 0
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info-sxNowHeight"),
    style: {
      // bottom: currentSx?.liquidLevelHeight && currentSx?.sxHigh ?
      //     ( Number(currentSx?.liquidLevelHeight) - 13 ) + 'px'
      //     : -13
      bottom: (currentSx === null || currentSx === void 0 ? void 0 : currentSx.liquidLevelHeight) && (currentSx === null || currentSx === void 0 ? void 0 : currentSx.height) ? (Number(currentSx === null || currentSx === void 0 ? void 0 : currentSx.liquidLevelHeight) / Number(currentSx === null || currentSx === void 0 ? void 0 : currentSx.height) * 100).toFixed(0) + '%' : 0
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-sx-info-line")
  }), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-content-label")
  }, "\u5F53\u524D\u6DB2\u4F4D(m)\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-content-value")
  }, (currentSx === null || currentSx === void 0 ? void 0 : currentSx.liquidLevelHeight) || 0)))))), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      height: 350,
      marginTop: 10,
      width: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-card")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-card-title")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-sxyx-card-title-text")
  }, "\u6DB2\u4F4D\u8D8B\u52BF\u5206\u6790")), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-sxyx-card-content")
  }, ywTrendDataList && ywTrendDataList.length ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: options,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: 280,
      width: '100%'
    }
  })) : (/*#__PURE__*/_react["default"].createElement("div", {
    style: {
      height: 100,
      width: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmNodata["default"], null)))))));
};
var _default = exports["default"] = Sxyx;
//# sourceMappingURL=index.js.map
