import React, { useEffect, useRef, useState } from 'react';
import { Button, Drawer } from 'antd';
import { connect, useModel } from "umi";
import AutoTable from '@/components/AutoTable';
import getPrem from '@/utils/getPrem';//权限判断fn
import Details from "@/components/Details";

let SendList = (props) => {
    const { global, dispatch } = props;
    const actionRef = useRef(),
        [details, cdetails] = useState({
            totalTitle: "推送记录详情",
            visible: false,
            dataSource: {},
            totalCard: []
        });



    let columns = [
        {
            "title": "推送时间",
            "dataIndex": "sendTime",
            "key": "sendTimeList",
            "valueType": "dateRange"
        },
        {
            "title": "接收用户",
            "dataIndex": "userName",
            "key": "userName"
        },
        {
            "title": "推送方式",
            "dataIndex": "sendMethodName",
            "key": "sendMethodName",
            search:false
        },
        {
            "title": "推送内容",
            "dataIndex": "msgContent",
            "key": "msgContent"
        },
        {
            "title": "状态",
            "dataIndex": "sendResultName",
            "key": "sendResult",
            "valueType": "select",
            options: [
                {
                    "label": "成功",
                    "value": 1
                },
                {
                    "label": "失败",
                    "value": 2
                }
            ]
        },
        {
            title: '操作',
            valueType: 'option',
            width: 120,
            render: (text, row, _, action) => extraAction(text, row, _, action)
        },
    ]



    function extraAction(text, record, _, action) {
        return (
            <div>
                {
                    getPrem(true, null, "查看详情", () => {
                        cdetails(details => {
                            return {
                                ...details,
                                visible: true,
                                dataSource: record,
                                totalCard: [
                                    { //每一个模块信息
                                        cardTitle: '记录详情',
                                        itemData: [
                                            {
                                                "title": "推送时间",
                                                "key": "sendTime"
                                            },
                                            {
                                                "title": "接收用户",
                                                "key": "userName"
                                            },
                                            {
                                                "title": "推送方式",
                                                "key": "sendMethodName"
                                            },
                                            {
                                                "title": "消息标题",
                                                "key": "msgTitle",
                                                col: { span: 24 }
                                            },
                                            {
                                                "title": "消息内容",
                                                "key": "msgContent",
                                                col: { span: 24 }
                                            }
                                        ]
                                    }
                                ]
                            }
                        })
                    })
                }

            </div>
        );
    }
    // let extrarender = ([<Button  type="primary" onClick={() => {

    // }}>导出</Button>])


    return (
        <div>
            <AutoTable
                pagetitle={props.route.name} //页面标题
                // pageextra={extrarender} //页面操作 新增or批量删除
                columns={columns}
                actionRef={actionRef}
                path="/ngic-base-business/paMsgSendRecord/queryList"
            ></AutoTable>
            <Drawer
                title={details.totalTitle}
                closable={true}
                visible={details.visible}
                onClose={() => { cdetails({ ...details, visible: false }) }}
                destroyOnClose={true}
                afterVisibleChange={(v) => {
                    cdetails({
                        ...details,
                        shown: v
                    })
                }}
                width="100%"
                className="drawerDetails"
            >
                {details.shown && <Details {...details}></Details>}
            </Drawer>
        </div>
    )
}

export default SendList