import { connect } from "umi";
import moment from 'moment/moment'
import { useRef } from "react";
import { ActionType, FormInstance, ProTable } from "@ant-design/pro-components";
import { handleGetPROPERTYASSETSLOGList } from "../service";

type DetailProps = {
    detail: any;
}
const LogList = ({ detail }: DetailProps) => {
    const actionRef = useRef<ActionType>();
    const tableFormRef = useRef<FormInstance>();


    const columns: any = [
        {
            title:'操作类型',
            width: 120,
            ellipsis:true,
            hideInSearch: true,
            dataIndex:'OPERATE_TYPE'
        },
        {
            title:'操作原值',
            width: 250,
            ellipsis:true,
            hideInSearch: true,
            dataIndex:'OPERATE_VALUE'
        },
        {
            title:'操作新值',
            width: 250,
            ellipsis:true,
            hideInSearch: true,
            dataIndex:'OPERATE_NEWVALUE'
        },
        {
            title:'操作描述',
            width: 250,
            ellipsis:true,
            hideInSearch: true,
            dataIndex:'OPERATE_DESC'
        },
        {
            title:'操作人',
            width: 120,
            ellipsis:true,
            hideInSearch: true,
            dataIndex:'OPERATE_NAME'
        },
        {
            title:'操作时间',
            width: 150,
            ellipsis:true,
            hideInSearch: true,
            dataIndex:'OPERATE_DATE',
            render:(_,record)=>{
                return moment(record?.OPERATE_DATE).format('YYYY-MM-DD HH:mm:ss')
            }
        },
    ]


    return (
        <div>
            <ProTable
                actionRef={actionRef}
                formRef={tableFormRef}
                request={async () => {
                    const req: any = {
                        SearchParameter: {
                            TABLE_ID: detail?.PROPERTYASSETS_ID,
                            TABLE_NAME: "T_PROPERTYASSETS"
                        }

                    }
                    const data = await handleGetPROPERTYASSETSLOGList(req)
                    if (data && data.length > 0) {
                        return { data, success: true }
                    }
                    return { data: [], success: true }
                }}
                columns={columns}
            />
        </div>
    )
}

export default connect(({ user, }: ConnectState) => ({
    currentUser: user.currentUser,
}))(LogList);
