function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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),
    _useState10 = _slicedToArray(_useState9, 2),
    count = _useState10[0],
    setCount = _useState10[1];
  var _useState11 = useState(false),
    _useState12 = _slicedToArray(_useState11, 2),
    showLog = _useState12[0],
    setShowLog = _useState12[1];
  var _useState13 = useState(),
    _useState14 = _slicedToArray(_useState13, 2),
    currentHistory = _useState14[0],
    setCurrentHistory = _useState14[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;