"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 _ahooks = require("ahooks");
var _antd = require("antd");
require("../index.less");
var _utils = require("@vtx/utils");
var _components = require("@vtx/components");
var _vmNodata = _interopRequireDefault(require("../../../../vm-nodata"));
var _icons = require("@ant-design/icons");
var _player = require("@vtx/player");
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 Option = _antd.Select.Option;
//基础设施详情
var getJcssDetail = function getJcssDetail(params) {
  return _utils.request.get('/cloud/jcss-reborn/facility/get', {
    data: params
  });
};
var videoList = function videoList(params) {
  return _utils.request.get('/cloud/zhgc-reborn/api/gis/pop/videoList', {
    data: params
  });
};
var previewUrl = function previewUrl(params) {
  return _utils.request.get('/cloud/vis/base/np/artemis/previewUrl.smvc', {
    data: params
  });
};
var JBXX = function JBXX(props) {
  var fields = props.fields,
    detail = props.detail,
    modalShow = props.modalShow,
    _props$theme = props.theme,
    theme = _props$theme === void 0 ? 'light' : _props$theme;
  var _useSetState = (0, _ahooks.useSetState)({
      displayType: 'img',
      order: 1,
      imgList: [],
      channelList: [],
      current: {
        channelNum: ''
      },
      previewUrl: '',
      type: ''
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var displayType = state.displayType,
    order = state.order,
    imgList = state.imgList;
  (0, _react.useEffect)(function () {
    if (detail.id) {
      if (detail.photoIds) {
        setState({
          imgList: detail.photoIds && JSON.parse(detail.photoIds).map(function (item, index) {
            return Object.assign(Object.assign({}, item), {
              index: index + 1,
              name: item.name.split('.')[0],
              url: "/vortex/rest/cloud/np/file/downloadFileThumbnail/".concat(item.id, "?token=").concat((0, _utils.getVtxToken)('token'), "&outputQuality=0.5&scale=0.5")
            });
          }) || []
        });
      } else {
        getJcssDetail({
          id: detail.id,
          coordType: 'bd09'
        }).then(function (res) {
          if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
            setState({
              imgList: res.data.typePhotoIds && JSON.parse(res.data.typePhotoIds).map(function (item, index) {
                return Object.assign(Object.assign({}, item), {
                  index: index + 1,
                  name: item.name.split('.')[0],
                  url: "/vortex/rest/cloud/np/file/downloadFileThumbnail/".concat(item.id, "?token=").concat((0, _utils.getVtxToken)('token'), "&outputQuality=0.5&scale=0.5")
                });
              }) || []
            });
          }
        });
      }
      if (detail.hasVideo) {
        videoList({
          id: detail.id
        }).then(function (res) {
          if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
            setState({
              channelList: res.data,
              current: res.data[0] || {}
            });
          }
        });
      }
    }
  }, [detail.id]);
  var isShow = function isShow(key) {
    return fields.filter(function (item) {
      return item.key === key;
    }).length !== 0;
  };
  var basicList = [{
    name: '行政区划',
    key: 'divisionName',
    isShow: isShow('divisionId'),
    weights: modalShow === false ? 12 : 24
  }, {
    name: '详细地址',
    key: 'address',
    isShow: isShow('address'),
    weights: modalShow === false ? 12 : 24
  }, {
    name: '开放时间',
    key: 'openTime',
    isShow: isShow('openhour'),
    weights: modalShow === false ? 12 : 24
  }, {
    name: '权属单位',
    key: 'belongUnitName',
    isShow: isShow('qsdwId')
  }, {
    name: '权属单位联系人',
    key: 'belongUnitContract',
    isShow: isShow('qsdwlxrId')
  }, {
    name: '权属单位联系电话',
    key: 'belongUnitContractWay',
    isShow: isShow('qsdwlxdhId')
  }, {
    name: '运营单位',
    key: 'runUnitName',
    isShow: isShow('yydwId')
  }, {
    name: '运营单位联系人',
    key: 'runUnitContract',
    isShow: isShow('yydwlxrId')
  }, {
    name: '运营单位联系电话',
    key: 'runUnitContractWay',
    isShow: isShow('yydwlxdhId')
  }, {
    name: '管理类型',
    key: 'manageType',
    isShow: isShow('managementtypeName')
  }, {
    name: '保洁形式',
    key: 'manageMethod',
    isShow: isShow('bjxsName')
  }, {
    name: '保洁员',
    key: 'cleaner',
    isShow: isShow('bjyId')
  }, {
    name: '保洁时间',
    key: 'cleanTime',
    isShow: isShow('bjsjId')
  }];
  var getVideoUrl = function getVideoUrl(params) {
    var channelNum = params.channelNum,
      channelId = params.channelId,
      videoDeviceId = params.videoDeviceId;
    if (channelId || videoDeviceId) {
      previewUrl({
        channelNum: channelNum,
        channelId: channelId,
        deviceId: videoDeviceId
      }).then(function (res) {
        if ((res === null || res === void 0 ? void 0 : res.result) == 0 && res.data.url) {
          setState({
            previewUrl: res.data.url,
            type: res.data.player
          });
        } else {
          _antd.message.warn('暂未查询到视频');
        }
      });
    }
  };
  (0, _react.useEffect)(function () {
    getVideoUrl(state.current);
  }, [state.current]);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "jbxx"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "wrTitle"
  }, "\u57FA\u672C\u4FE1\u606F", /*#__PURE__*/_react["default"].createElement("div", {
    className: "titleExtra"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Radio.Group, {
    value: displayType,
    onChange: function onChange(e) {
      return setState({
        displayType: e.target.value
      });
    }
  }, /*#__PURE__*/_react["default"].createElement(_antd.Radio.Button, {
    value: 'img'
  }, "\u7167\u7247"), detail.hasVideo && /*#__PURE__*/_react["default"].createElement(_antd.Radio.Button, {
    value: 'video'
  }, "\u89C6\u9891\u76D1\u63A7")))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "wrContent"
  }, displayType === 'img' && /*#__PURE__*/_react["default"].createElement("div", {
    className: "imgContent"
  }, imgList.length ? /*#__PURE__*/_react["default"].createElement(_components.VtxImage.PreviewGroup, null, imgList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_components.VtxImage, {
      key: item.id,
      src: item.url,
      alt: item.name,
      style: {
        display: item.index === order ? 'block' : 'none'
      }
    });
  })) : /*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: '280px',
      width: '466px'
    }
  }), imgList.length ? /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "num"
  }, /*#__PURE__*/_react["default"].createElement(_icons.LeftOutlined, {
    style: {
      opacity: order === 1 ? '.251' : '1'
    },
    onClick: function onClick() {
      return order !== 1 && setState({
        order: order - 1
      });
    }
  }), "\u2003", order, "/", imgList.length, "\u2003", /*#__PURE__*/_react["default"].createElement(_icons.RightOutlined, {
    style: {
      opacity: order === imgList.length ? '.251' : '1'
    },
    onClick: function onClick() {
      return order !== imgList.length && setState({
        order: order + 1
      });
    }
  }))) : ''), displayType === 'video' && /*#__PURE__*/_react["default"].createElement("div", {
    className: 'videoContent'
  }, /*#__PURE__*/_react["default"].createElement(_antd.Select, {
    value: state.current.channelNum,
    onChange: function onChange(value) {
      setState({
        current: state.channelList.filter(function (item) {
          return item.channelNum === value;
        })[0]
      });
    },
    style: {
      width: '30%'
    },
    popupClassName: "selectPopupClassName ".concat(theme)
  }, state.channelList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: item.channelNum
    }, item.channelName);
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "videoText"
  }, /*#__PURE__*/_react["default"].createElement(_player.LivePlayer, {
    url: state.previewUrl,
    type: state.type,
    beenHasVideo: false,
    width: 730,
    height: 300
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "basicContent"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: 16
  }, basicList.filter(function (item) {
    return item.isShow;
  }).map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_antd.Col, {
      key: item.key,
      span: item.weights || 12
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "tip"
    }, item.name, "\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
      className: "text",
      title: detail[item.key]
    }, detail[item.key] || '-'));
  })))));
};
var _default = exports["default"] = JBXX;
//# sourceMappingURL=Jbxx.js.map
