import { useAjax } from '@/Hook/useAjax';
import useNewToken from '@/Hook/useNewToken';
import { getMomentsSendLogApi } from '@/pages/weComTask/API/businessPlan/create';
import { Button, Table, Tag } from 'antd';
import React, { useEffect, useState } from 'react';
import { sendLogTableConfig } from './weTableConfig';

interface Props {
    data: any
}

/**
 * 朋友圈发送记录
 * @returns 
 */
const MomentsTaskNotes: React.FC<Props> = ({ data }) => {

    /*************************************/
    const { token } = useNewToken()
    const [queryForm, setQueryForm] = useState<{ pageNum: number, pageSize: number, corpMomentId: number }>({
        pageNum: 1,
        pageSize: 20,
        corpMomentId: data.id,
    });

    const getMomentsSendLog = useAjax((params) => getMomentsSendLogApi(params))
    /*************************************/

    useEffect(() => {
        if (queryForm.corpMomentId) {
            getMomentsSendLog.run(queryForm)
        }
    }, [queryForm])

    return (
        <div>
            <div style={{ marginBottom: 10 }}>
                <Button type='link' style={{ padding: 0, height: 'auto', lineHeight: 'normal' }} loading={getMomentsSendLog.loading} onClick={() => getMomentsSendLog.refresh()}>刷新</Button>
            </div>
            <Table
                dataSource={getMomentsSendLog?.data?.data?.records}
                loading={getMomentsSendLog?.loading}
                columns={sendLogTableConfig()}
                scroll={{ x: 400, y: 280 }}
                rowKey={(s) => {
                    return s.id
                }}
                size='small'
                onRow={(row) => {
                    return !row.status ? {
                        style: { background: token.colorPrimaryBgHover }
                    } : {}
                }}
                pagination={{
                    total: getMomentsSendLog?.data?.data?.total,
                    showTotal: (total) => <Tag color="cyan">总共{total}数据</Tag>,
                    showSizeChanger: true,
                    showLessItems: true,
                    defaultCurrent: 1,
                    defaultPageSize: 200,//默认初始的每页条数
                    current: getMomentsSendLog?.data?.data?.current || 1,
                    pageSize: getMomentsSendLog?.data?.data?.size || 20,
                    onChange: (page, pageSize) => {
                        setQueryForm({ ...queryForm, pageNum: page, pageSize })
                    }
                }}
            />
        </div>
    );
};

export default MomentsTaskNotes;