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

type DetailProps = {
    detailData: any;
    onShow: boolean
}
const StoreInfor = ({ detailData,onShow }: DetailProps) => {
    const actionRef = useRef<ActionType>();
    const tableFormRef = useRef<FormInstance>();

    const businessStateObj: any = session.get('businessStateObj')
    const BUSINESSTYPEObj: any = session.get('BUSINESSTYPEObj')
    const SHOPTRADEObj: any = session.get('SHOPTRADEObj')
    const BUSINESSBRANDObj: any = session.get('BUSINESSBRANDObj')
    const SHOPREGIONObj: any = session.get('shopregionObj')

    const columns: any = [
        {
            title: '经营单位',
            dataIndex: 'BUSINESS_UNIT',
        },
        {
            title: '服务区名称',
            dataIndex: 'SERVERPART_NAME'
        },
        {
            title: '商品业态',
            dataIndex: 'SHOPTRADE',
            valueType: 'select',
            valueEnum: SHOPTRADEObj
        },
        {
            title: '经营业态',
            dataIndex: 'BUSINESS_TRADENAME',
        },
        {
            title: '经营品牌',
            dataIndex: 'BUSINESS_BRAND',
            valueType: 'select',
            valueEnum: BUSINESSBRANDObj
        },
        {
            title: '门店简称',
            dataIndex: 'SHOPSHORTNAME',
        },
        {
            title: '销售数量上限',
            valueType: 'digit',
            dataIndex: 'SALECOUNT_LIMIT',
        },
        {
            title: '金额上限',
            valueType: 'digit',
            dataIndex: 'SALEAMOUNT_LIMIT',
        },
        {
            title: '优惠折扣',
            dataIndex: 'SALEAMOUNT_LIMIT',
            valueType: 'select',
            valueEnum: {
                0: '不记异常稽核',
                1: '记录异常稽核'
            }
        },
        {
            title: '门店方位',
            dataIndex: 'SHOPREGION',
            valueType: 'select',
            valueEnum: SHOPREGIONObj
        },
        {
            title: '门店名称',
            dataIndex: 'SHOPNAME'
        },
        {
            title: '经营模式',
            dataIndex: 'BUSINESS_TYPE',
            valueType: 'select',
            valueEnum: BUSINESSTYPEObj
        },
        {
            title: '经营状态',
            dataIndex: 'BUSINESS_STATE',
            valueType: 'select',
            valueEnum: businessStateObj
        },
        {
            title: '开业时间',
            dataIndex: 'BUSINESS_DATE',
            render:(_,record)=>{
                return record?.BUSINESS_DATE ? moment(record?.BUSINESS_DATE).format('YYYY-MM-DD HH:mm:ss'):''
            }
        },
        {
            title: '停业时间',
            dataIndex: 'BUSINESS_ENDDATE',
            render:(_,record)=>{
                return record?.BUSINESS_DATE ? moment(record?.BUSINESS_DATE).format('YYYY-MM-DD HH:mm:ss'):''
            }
        },
    ]

    const tableColumns: any = [
        {
            title: '序号',
            dataIndex: "index",
            valueType: 'index',
            hideInSearch: true
        },
        {
            title: '门店名称',
            dataIndex: 'ShopName',
            hideInSearch: true
        },
        {
            title: '开业时间',
            dataIndex: 'BusinessDate',
            hideInSearch: true,
            render: (_, record) => {
                return record?.BusinessDate || ''
            }
        },
        {
            title: '停业时间',
            dataIndex: 'BusinessEndDate',
            hideInSearch: true,
            render: (_, record) => {
                return record?.BusinessEndDate || ''
            }
        },
        {
            title: '操作人员',
            dataIndex: 'StaffName',
            hideInSearch: true
        },
        {
            title: '操作时间',
            dataIndex: 'OperateDate',
            hideInSearch: true,
            render: (_, record) => {
                return record?.OperateDate ? moment(record?.OperateDate).format('YYYY-MM-DD') : ''
            }
        },
    ]

    return (
        <div>
            <ProDescriptions
                columns={columns}
                dataSource={detailData}
            ></ProDescriptions>

            <ProTable
                actionRef={actionRef}
                formRef={tableFormRef}
                className={"shopMessageTable"}
                headerTitle={"门店经营信息"}
                columns={tableColumns}
                request={async () => {
                    if (detailData?.SERVERPARTSHOP_ID) {
                        console.log('detailData2', detailData);
                        const req: any = {
                            serverPartShopId: detailData?.SERVERPARTSHOP_ID
                        }
                        const data = await handleGetServerPartShopNewDetail(req)
                        console.log('data2', data);
                        let res = data.RtServerPartShopList
                        if (res && res.length > 0) {
                            return { data: res, success: true }
                        }
                    }
                    return { data: [], success: true }
                }}
                search={false}
            />
        </div>
    )
}

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