// 会员优惠券
import { connect } from "umi";
import type { ConnectState } from "@/models/connect";
import PageTitleBox from "@/components/PageTitleBox";
import ProTable, { ActionType } from "@ant-design/pro-table";
import { useRef } from "react";
import { FormInstance } from "antd";
import { handeGetCOUPON_SENDList, handeGetMemberShipLicenseList } from "../../service";
import moment from 'moment'

type DetailProps = {
    parentDetail?: any
}
const MemberDiscounts = ({ parentDetail }: DetailProps) => {
    const actionRef = useRef<ActionType>();
    const formRef = useRef<FormInstance>();

    const columns: any = [
        {
            title: "优惠券名称",
            width: 150,
            dataIndex: "COUPON_NAME",
            hideInSearch: true,
            align: 'center',
            ellipsis: true,
        },
        {
            title: "优惠券状态",
            width: 150,
            dataIndex: "COUPON_STATE",
            hideInSearch: true,
            align: 'center',
            ellipsis: true,
            valueType: 'select',
            valueEnum: {
                "0": { text: '未使用', status: 'processing' },
                "1": { text: '已使用', status: 'success' },
                "2": { text: '失效', status: 'error' }
            }
        },
        {
            title: "使用说明",
            width: 250,
            dataIndex: "COUPON_DESC",
            hideInSearch: true,
            align: 'center',
            ellipsis: true,
        },
        {
            title: "优惠形式",
            width: 150,
            dataIndex: "COUPON_TYPE",
            hideInSearch: true,
            align: 'center',
            ellipsis: true,
            valueType: 'select',
            valueEnum: {
                "1000": "满减券",
                "2000": "折扣券",
                "3000": "抵扣券",
                "4000": "兑换券",
            }
        },
        {
            title: "有效期至",
            width: 180,
            dataIndex: "VALID_END_TIME",
            hideInSearch: true,
            align: 'center',
            ellipsis: true,
            render: (_, record) => {
                return record?.VALID_END_TIME ? moment(record?.VALID_END_TIME).format('YYYY-MM-DD HH:mm:ss') : "-"
            }
        },
        {
            title: "适用门店",
            width: 250,
            dataIndex: "COOPSHOP_DESC",
            hideInSearch: true,
            align: 'center',
            ellipsis: true,
        }
    ]

    return (
        <div>
            <ProTable
                actionRef={actionRef}
                formRef={formRef}
                columns={columns}
                bordered
                expandable={{
                    expandRowByClick: true
                }}
                search={false}
                options={false}
                scroll={{ x: "100%", y: '300px' }}
                // headerTitle={<PageTitleBox props={props} />} // 列表表头
                request={async (params) => {
                    const req: any = {
                        searchParameter: {
                            MEMBERSHIP_IDS: parentDetail?.MEMBERSHIP_ID,
                            // OWNERUNIT_ID: 911,
                        },
                        PageIndex: 1,
                        PageSize: 999999,
                    }
                    const data = await handeGetCOUPON_SENDList(req)
                    console.log('datadatadata', data);
                    if (data && data.length > 0) {
                        return { data, success: true }
                    }
                    return { data: [], success: true }
                }}
            // toolbar={{
            //     actions: [

            //     ]
            // }}
            />


        </div>
    )
}

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