/**
 * 维保记录
 */
import React from 'react';
import moment from 'moment';
import VMTable from '../vm-table';
import { BaseService } from './api';
import { useSetState } from 'ahooks';

interface TypeProps {
    id: string;
}

export default function RmRecord(props: TypeProps) {
    const { id } = props;
    window.console.log(props);
    const [state, setState] = useSetState({
        pagination: {
            current: 1,
            pageSize: 10,
            total: 0,
        },
    });
    const { pagination } = state;
    const startDate = moment()
        .startOf('y')
        .format('YYYY-MM-DD HH:mm:ss');
    const endDate = moment().format('YYYY-MM-DD HH:mm:ss');
    const { rmRecord } = BaseService.useRmRecord(id, startDate, endDate, pagination.current - 1);
    const columns = [
        {
            title: '工单编号',
            dataIndex: 'workOrderNo',
            key: 'workOrderNo',
            width: 120,
            ellipsis: true,
        },
        {
            title: '维保类型',
            dataIndex: 'maintainTypeName',
            key: 'maintainTypeName',
            width: 120,
            ellipsis: true,
        },
        {
            title: '申请金额',
            dataIndex: 'fee',
            key: 'fee',
            render: (text: number) => {
                return <span style={{ color: '#FF7272' }}>{text}</span>;
            },
        },
        {
            title: '申请人',
            dataIndex: 'applyUserName',
            key: 'applyUserName',
        },
        {
            title: '申请时间',
            dataIndex: 'applyTime',
            key: 'applyTime',
            width: 150,
        },
        {
            title: '维保状态',
            dataIndex: 'facilityStatusDesc',
            key: 'facilityStatusDesc',
        },
        {
            title: '维保时间',
            dataIndex: 'lastAuditTime',
            key: 'lastAuditTime',
            width: 150,
        },
    ];

    const pageChange = (page: number) => {
        setState({
            pagination: {
                ...pagination,
                current: page,
            },
        });
    };

    const tableProps = {
        pagination: {
            ...pagination,
            total: rmRecord.total,
            defaultPageSize: 10,
            onChange: pageChange,
        },
        height: 240,
        dataSource: rmRecord.rows,
    };

    return <VMTable columns={columns} {...tableProps} />;
}
