// 整改情况追踪表
import { connect } from "umi";

import LeftSelectTree from "@/components/leftSelectTree/leftSelectTree";
import { ActionType, FormInstance, ProTable } from "@ant-design/pro-components";
import { useEffect, useRef, useState } from "react";
import { handleGetPATROLList, handleGetRECTIFICATIONList } from "./service";
import moment from 'moment'
import { encryptAES } from "@/utils/handleAes";
import { Drawer } from "antd";
import OperationReport from './index'


const rectificationStatus = () => {
    const actionRef = useRef<ActionType>();
    const formRef = useRef<FormInstance>();
    const [collapsible, setCollapsible] = useState<boolean>(false)
    // 树相关的属性和方法
    const [selectedId, setSelectedId] = useState<string>()
    // 行数据信息
    const [currentRow, setCurrentRow] = useState<any>()
    // 显示详情抽屉
    const [showDetailDrawer, setShowDetailDrawer] = useState<boolean>(false)

    const columns: any = [
        {
            title: '巡检时间',
            dataIndex: 'search_date',
            valueType: 'dateRange',
            hideInTable: true,
            hideInDescriptions: true,
            search: {
                transform: (value: any) => {
                    return {
                        INSPECTION_STARTTIME_Start: value[0],
                        INSPECTION_STARTTIME_End: value[1],
                    };
                },
            },
            fieldProps: {
                ranges: {
                    "本月": [moment().startOf('M'), moment()],
                    "上月": [moment().subtract(1, 'M').startOf('M'), moment().subtract(1, 'M').endOf('M')],
                    "近三月": [moment().subtract(3, 'M').startOf('M'), moment().endOf('M')],
                    "近半年": [moment().subtract(6, 'M').startOf('M'), moment().endOf('M')],
                }
            },
            initialValue: [moment().startOf('M'), moment()],
        },
        {
            title: "内容类型",
            dataIndex: "PATROLCONTENT_TYPE",
            valueType: 'select',
            fieldProps: {
                options: [
                    { label: '服务质量监督', value: 1000 },
                    { label: '运营维护', value: 2000 },
                    { label: '安全管理', value: 3000 },
                    { label: '通用', value: 4000 },
                ]
            }
        },
        {
            title: "序号",
            dataIndex: 'index',
            valueType: 'index',
            hideInSearch: true,
            align: 'center',
            width: 80,
            ellipsis: true
        },
        {
            title: "片区名称",
            dataIndex: 'BELONGAREA',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "服务区名称",
            dataIndex: 'SANAME',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "责任单位",
            dataIndex: 'DUTYUNIT',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "责任人",
            dataIndex: 'DUTYPSNNAME',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "联系电话",
            dataIndex: 'PHONE',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "巡检人",
            dataIndex: 'INSPECTIONPSN',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "巡检日期",
            dataIndex: 'INSPECTIONDATE',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true,
        },
        {
            title: "巡检问题",
            dataIndex: 'INSPECTIONQUESTION',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "整改要求",
            dataIndex: 'RECTIFICATIONREQUEST',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "整改期限",
            dataIndex: 'DEADLINE',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "整改截止时间",
            dataIndex: 'TILLTIME',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "整改完成时间",
            dataIndex: 'FINISHTIME',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "整改结果",
            dataIndex: 'RECTIFICATION_RESULT',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "现场照片",
            dataIndex: 'LOCALEPHOTO',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "整改后照片",
            dataIndex: 'RESULTPHOTO',
            hideInSearch: true,
            align: 'center',
            width: 150,
            ellipsis: true
        },
        {
            title: "状态",
            dataIndex: 'COMPLETE_STATE',
            valueType: 'select',
            hideInSearch: true,
            align: 'center',
            width: 120,
            ellipsis: true,
            fieldProps: {
                options: [
                    { label: "编辑中", value: 1 },
                    { label: "巡查中", value: 2 },
                    { label: "待跟进", value: 3 },
                    { label: "整改中", value: 4 },
                    { label: "已完成", value: 5 },
                ]
            }
        }
    ]

    return (
        <div style={{ height: 'calc(100vh - 100px)', backgroundColor: '#fff', display: 'flex' }}>
            <LeftSelectTree setSelectedId={setSelectedId} setCollapsible={setCollapsible} collapsible={collapsible} />
            <div style={{
                width: !collapsible ? 'calc(100% - 300px)' : 'calc(100% - 60px)',
                paddingTop: 0,
                paddingBottom: 0,
                paddingRight: 0
            }}>
                <ProTable
                    actionRef={actionRef}
                    formRef={formRef}
                    columns={columns}
                    bordered
                    scroll={{ x: '100%', y: 'calc(100vh - 450px)' }}
                    headerTitle={'整改情况追踪表'}
                    search={{ span: 6, }}
                    request={async (params) => {
                        const req: any = {
                            SearchParameter: {
                                PATROL_STATE: 1000,
                                INSPECTIONDATE_Start: params?.INSPECTION_STARTTIME_Start || "",
                                INSPECTIONDATE_End: params?.INSPECTION_STARTTIME_End || "",
                                PATROLCONTENT_TYPE: params?.PATROLCONTENT_TYPE || ""
                            },
                            PageIndex: 1,
                            PageSize: 999999,
                        }

                        let newReq: any = {
                            name: "",
                            value: encryptAES(JSON.stringify(req))
                        }

                        const data = await handleGetRECTIFICATIONList(newReq)
                        if (data && data.length > 0) {
                            return { data, success: true }
                        }
                        return { data: [], success: true }
                    }}
                    toolbar={{
                        actions: [

                        ]
                    }}
                />
            </div>


        </div>
    )
}



export default connect(({ user }: ConnectState) => ({
    currentUser: user.data
}))(rectificationStatus);