"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");
var _classnames = _interopRequireDefault(require("classnames"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
require("./index.less");
var _vmFilter = require("../../../vm-filter");
var _dayjs = _interopRequireDefault(require("dayjs"));
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _utils = require("@vtx/utils");
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
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; }
var getDetail = function getDetail(params) {
  return _utils.request.get('/cloud/zhgc-reborn/api/v101/evaluate/score/getByGcId', {
    data: params
  });
};
var monthScoreChart = function monthScoreChart(params) {
  return _utils.request.post('/cloud/zhgc-reborn/api/v101/evaluate/month/score/monthScoreChart', {
    data: params
  });
};
var getList = function getList(params) {
  return _utils.request.post('/cloud/zhgc-reborn/api/v101/evaluate/month/score/list', {
    data: params
  });
};
var Score = function Score(props) {
  var _a, _b, _c;
  var id = props.id,
    theme = props.theme;
  var _useSetState = (0, _ahooks.useSetState)({
      detail: {
        evaluateLabelCountList: [{}]
      },
      chartsData: {
        names: [],
        values: []
      },
      tableData: [],
      startMonth: '',
      endMonth: '',
      type: 'chart'
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  (0, _react.useEffect)(function () {
    if (id) {
      getDetail({
        id: id
      }).then(function (res) {
        if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
          setState({
            detail: res.data
          });
        }
      });
    }
  }, [id]);
  (0, _react.useEffect)(function () {
    if (id) {
      monthScoreChart({
        gcId: id,
        startMonth: state.startMonth,
        endMonth: state.endMonth
      }).then(function (res) {
        if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
          setState({
            chartsData: res.data || {
              names: [],
              values: []
            }
          });
        }
      });
      getList({
        gcId: id,
        startMonth: state.startMonth,
        endMonth: state.endMonth
      }).then(function (res) {
        if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
          setState({
            tableData: res.data || []
          });
        }
      });
    }
  }, [id, state.startMonth, state.endMonth, state.type]);
  //折线图配置
  var lineOptions = {
    color: ['#07b077'],
    tooltip: {
      trigger: 'axis',
      confine: true,
      textStyle: {
        color: '#333 !important'
      }
    },
    grid: {
      top: 30,
      left: 0,
      bottom: 0,
      right: 40,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: state.chartsData.names,
      axisLabel: {
        color: theme === 'dark' ? '#fff' : '#333'
      }
    },
    yAxis: {
      name: '分数',
      nameGap: 10,
      type: 'value',
      nameTextStyle: {
        padding: [0, 0, 0, 20],
        color: theme === 'dark' ? '#fff' : '#333'
      },
      axisLabel: {
        color: theme === 'dark' ? '#fff' : '#333'
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          opacity: 0.2
        }
      }
    },
    series: [{
      type: 'line',
      data: state.chartsData.values[0]
    }]
  };
  //表格
  var tableProps = {
    columns: [{
      title: '统计月份',
      dataIndex: 'month',
      key: 'month',
      sorter: function sorter(a, b) {
        return (0, _dayjs["default"])(a).valueOf() - (0, _dayjs["default"])(b).valueOf();
      }
    }, {
      title: '分数',
      dataIndex: 'score',
      key: 'score'
      // align: 'right'
    }],
    rowKey: 'id',
    height: 385,
    dataSource: state.tableData
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])('contentMain', "newWr".concat(theme))
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "score"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "title"
  }, "\u5F97\u5206\u60C5\u51B5"), /*#__PURE__*/_react["default"].createElement("div", null, "\u5F97\u5206\uFF1A", /*#__PURE__*/_react["default"].createElement("span", {
    className: "rank"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Rate, {
    disabled: true,
    allowHalf: true,
    value: state.detail.score || 0,
    style: {
      color: '#ff7f08 '
    }
  }), "\u2002", state.detail.score || 0), "\u2003\u2003\u2003\u2003 \u8BC4\u4EF7\u4EBA\u6570\uFF1A", state.detail.evaluateCount), /*#__PURE__*/_react["default"].createElement("div", {
    className: "tagContent"
  }, /*#__PURE__*/_react["default"].createElement("div", null, "\u8BC4\u4EF7\u6807\u7B7E\uFF1A"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "tags"
  }, ((_a = state.detail.evaluateLabelCountList) === null || _a === void 0 ? void 0 : _a.length) ? state.detail.evaluateLabelCountList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: item.id,
      className: (0, _classnames["default"])('tagItem', {
        tagItemY: item.attitude === 'ZM',
        tagItemN: item.attitude === 'FM'
      })
    }, item.name, " ", item.count);
  }) : '暂无评价'))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "record"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "title"
  }, "\u8BC4\u4EF7\u8BB0\u5F55"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "typeChange"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])('changeItem', {
      changeItemA: state.type === 'chart'
    }),
    onClick: function onClick() {
      return setState({
        type: 'chart'
      });
    }
  }, "\u56FE\u8868"), /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])('changeItem', {
      changeItemA: state.type === 'table'
    }),
    onClick: function onClick() {
      return setState({
        type: 'table'
      });
    }
  }, "\u5217\u8868")), /*#__PURE__*/_react["default"].createElement("div", {
    className: "timeContent"
  }, "\u8BC4\u5206\u6708\u4EFD\uFF1A", /*#__PURE__*/_react["default"].createElement(_vmFilter.VMRangePicker, {
    picker: "month",
    value: [state.startMonth && (0, _dayjs["default"])(state.startMonth) || null, state.endMonth && (0, _dayjs["default"])(state.endMonth) || null],
    onChange: function onChange(_date, dateStr) {
      setState({
        startMonth: dateStr[0],
        endMonth: dateStr[1]
      });
    }
  })), state.type === 'chart' && ((_b = state.chartsData.names) === null || _b === void 0 ? void 0 : _b.length) === 0 && (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: '300px',
      width: '590px'
    }
  })), state.type === 'chart' && ((_c = state.chartsData.names) === null || _c === void 0 ? void 0 : _c.length) !== 0 && (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    style: {
      width: '100%',
      height: '385px'
    },
    option: lineOptions,
    notMerge: true
  })), state.type === 'table' && /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({}, tableProps))));
};
var _default = exports["default"] = Score;
//# sourceMappingURL=index.js.map
