"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = Record;
var _react = _interopRequireDefault(require("react"));
var _ahooks = require("ahooks");
var _antd = require("antd");
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _api = require("../../api");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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; } /**
 * 考勤记录
 */
function Record(props) {
  var id = props.id,
    startDate = props.startDate,
    endDate = props.endDate;
  var _useSetState = (0, _ahooks.useSetState)({
      shiftClockWay: 'CLOCK_IN_OUT',
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0
      }
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var pagination = state.pagination,
    shiftClockWay = state.shiftClockWay;
  var _AttendanceService$us = _api.AttendanceService.useAttendRecord(id, "".concat(startDate, " 00:00:00"), "".concat(endDate, " 23:59:59"), pagination.current - 1, shiftClockWay),
    attendRecordRes = _AttendanceService$us.attendRecordRes;
  var records = {
    total: (attendRecordRes === null || attendRecordRes === void 0 ? void 0 : attendRecordRes.total) || 0,
    rows: (attendRecordRes === null || attendRecordRes === void 0 ? void 0 : attendRecordRes.rows) || []
  };
  var getColor = function getColor(code) {
    var color = '';
    switch (code) {
      case 'Normal':
        color = 'green';
        break;
      case 'Late':
      case 'Early':
        color = 'red';
        break;
      case 'Leave':
      case 'Absent':
        color = 'orange';
        break;
      default:
        color = 'warning';
        break;
    }
    return color;
  };
  var columnVisible = shiftClockWay === 'CLOCK_IN_OUT';
  var columns = [{
    title: '所属机构',
    dataIndex: 'deptName',
    key: 'deptName',
    width: 120,
    ellipsis: true
  }, {
    title: '姓名',
    dataIndex: 'staffName',
    key: 'staffName'
  }, {
    title: '岗位',
    dataIndex: 'workTypeName',
    key: 'workTypeName'
  }, {
    title: '班次',
    dataIndex: 'shiftName',
    key: 'shiftName',
    width: 100,
    ellipsis: true
  }, {
    title: '开始时间',
    dataIndex: 'shiftStartTime',
    key: 'shiftStartTime',
    width: 160
  }, {
    title: '结束时间',
    dataIndex: 'shiftEndTime',
    key: 'shiftEndTime',
    width: 160
  }, {
    title: '排班区域',
    dataIndex: 'shiftWorkElementNames',
    key: 'shiftWorkElementNames',
    width: 100,
    ellipsis: true,
    render: function render(text) {
      return text ? text : '-';
    }
  }, !columnVisible && {
    title: '打卡时间',
    dataIndex: 'clockInTime',
    key: 'clockInTime',
    width: 180,
    render: function render(text) {
      return text ? text : '-';
    }
  }, !columnVisible && {
    title: '打卡状态',
    dataIndex: 'clockInStatusName',
    key: 'clockInStatusName',
    width: 100,
    render: function render(text, record) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          color: getColor(record.clockInStatusCode)
        }
      }, /*#__PURE__*/_react["default"].createElement(_antd.Tag, {
        color: getColor(record.clockInStatusCode)
      }, text));
    }
  }, columnVisible && {
    title: '上班时间',
    dataIndex: 'clockInTime',
    key: 'clockInTime',
    width: 140,
    render: function render(text) {
      return text ? text : '-';
    }
  }, columnVisible && {
    title: '上班状态',
    dataIndex: 'clockInStatusName',
    key: 'clockInStatusName',
    width: 80,
    render: function render(text, record) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          color: getColor(record.clockInStatusCode)
        }
      }, /*#__PURE__*/_react["default"].createElement(_antd.Tag, {
        color: getColor(record.clockInStatusCode)
      }, text));
    }
  }, columnVisible && {
    title: '下班时间',
    dataIndex: 'clockOutTime',
    key: 'clockOutTime',
    width: 140,
    render: function render(text) {
      return text ? text : '-';
    }
  }, columnVisible && {
    title: '下班状态',
    dataIndex: 'clockOutStatusName',
    key: 'clockOutStatusName',
    width: 80,
    render: function render(text, record) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          color: getColor(record.clockOutStatusCode)
        }
      }, /*#__PURE__*/_react["default"].createElement(_antd.Tag, {
        color: getColor(record.clockOutStatusCode)
      }, text));
    }
  }].filter(function (ele) {
    return !!ele;
  });
  var pageChange = function pageChange(page) {
    setState({
      pagination: Object.assign(Object.assign({}, pagination), {
        current: page
      })
    });
  };
  var tableProps = {
    pagination: Object.assign(Object.assign({}, pagination), {
      total: records.total,
      defaultPageSize: 10,
      onChange: pageChange
    }),
    style: {
      padding: '0 20px'
    },
    height: 250,
    dataSource: records.rows
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    key: id
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u8003\u52E4\u8BB0\u5F55",
    extra: /*#__PURE__*/_react["default"].createElement(_antd.Radio.Group, {
      value: shiftClockWay,
      onChange: function onChange(e) {
        return setState({
          shiftClockWay: e.target.value,
          pagination: {
            current: 1,
            pageSize: 10,
            total: 0
          }
        });
      }
    }, /*#__PURE__*/_react["default"].createElement(_antd.Radio.Button, {
      value: "CLOCK_IN_OUT"
    }, "\u4E0A\u4E0B\u73ED\u6253\u5361"), /*#__PURE__*/_react["default"].createElement(_antd.Radio.Button, {
      value: "SHIFT_CHECK_IN"
    }, "\u73ED\u6B21\u5185\u6253\u5361"))
  }), /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: columns,
    rowKey: "id"
  }, tableProps)));
}
//# sourceMappingURL=Record.js.map
