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; }
import { Table } from 'antd';
import React, { useContext, useEffect, useState } from 'react';
import apis from '../../constants/api';
import TaskContext from '../../modules/createJob/context';
import { dateRender, stateColumn } from '../../modules/jobList';
import request from '../../utils/ajax';
import CheckTaskLog from '../checkLog';
import './index.less';
var JobHistory = function JobHistory(_ref) {
  var className = _ref.className;
  var classPrefix = 'dt-history';
  var _useContext = useContext(TaskContext),
    taskId = _useContext.taskId;
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    store = _useState2[0],
    setStore = _useState2[1];
  var _useState3 = useState(true),
    _useState4 = _slicedToArray(_useState3, 2),
    loading = _useState4[0],
    setLoading = _useState4[1];
  var _useState5 = useState(10),
    _useState6 = _slicedToArray(_useState5, 2),
    pageSize = _useState6[0],
    setPageSize = _useState6[1];
  var _useState7 = useState(1),
    _useState8 = _slicedToArray(_useState7, 2),
    pageNum = _useState8[0],
    setPageNum = _useState8[1];
  var _useState9 = useState(0),
    _useState0 = _slicedToArray(_useState9, 2),
    count = _useState0[0],
    setCount = _useState0[1];
  var _useState1 = useState(false),
    _useState10 = _slicedToArray(_useState1, 2),
    showLog = _useState10[0],
    setShowLog = _useState10[1];
  var _useState11 = useState(),
    _useState12 = _slicedToArray(_useState11, 2),
    currentHistory = _useState12[0],
    setCurrentHistory = _useState12[1];
  useEffect(function () {
    queryData();
  }, [taskId, pageNum, pageSize]);
  function queryData() {
    setLoading(true);
    request(apis.queryUpdateHistory, {
      method: 'post',
      data: {
        jobId: taskId,
        pageNo: pageNum,
        pageSize: pageSize
      }
    }).then(function (res) {
      if (!res) throw new Error();
      setStore(res.data.data);
      setCount(res.data.total);
    }).catch(function (err) {
      console.error('获取更新记录失败', err);
    }).finally(function () {
      setLoading(false);
    });
  }
  var columns = [{
    title: '更新完成时间',
    dataIndex: 'endTime',
    render: dateRender
  },
  // {
  //   title: '更新数据(条)',
  //   dataIndex: 'successRead',
  //   render(v: number) {
  //     if (v === undefined) return '-';
  //     return v;
  //   },
  // },
  stateColumn, {
    title: '操作',
    render: function render(v, data) {
      return /*#__PURE__*/React.createElement("a", {
        onClick: function onClick() {
          setCurrentHistory(data);
          setShowLog(true);
        }
      }, "\u67E5\u770B\u65E5\u5FD7");
    }
  }];
  return /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, " ").concat(className)
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-title")
  }, "\u5355\u8868\u540C\u6B65"), /*#__PURE__*/React.createElement(Table, {
    columns: columns,
    dataSource: store,
    loading: loading,
    rowKey: "id",
    pagination: {
      pageSize: pageSize,
      total: count,
      current: pageNum,
      showTotal: function showTotal(total) {
        return /*#__PURE__*/React.createElement(React.Fragment, null, "\u5171", /*#__PURE__*/React.createElement("span", {
          className: "".concat(classPrefix, "-total")
        }, total), "\u6761");
      },
      onChange: function onChange(page, pageSize) {
        setPageNum(page);
        setPageSize(pageSize);
      }
    }
  }), showLog && (/*#__PURE__*/React.createElement(CheckTaskLog, {
    taskId: taskId,
    historyId: currentHistory.id,
    onClose: function onClose() {
      setShowLog(false);
    }
  })));
};
export default JobHistory;