import {useState} from "react"
import Request from '../utils/request';
export interface CarProps {
    id:number
    date:string
    plate_no:string
    type:string
    vehicle_type:string
    image:string
}
/**
 * @description 获取车辆列表
 */
export  const useCarList=()=>{
    const [state,setState]=useState<{loading:boolean;dataSource:CarProps[];page:number}>({
        loading:false,
        dataSource:[],
        page:1,
    })
    const request=(params:{page:number;page_size:number;plate_no?:string;start?:number;end?:number})=>{
        Request.sendRequest({
            url:"/v1/vehicle/list",
            params
        }).then((response:any)=>{
            setState(preState=>({...preState,loading:false,dataSource:response.list||[]}))
        }).catch(error=>{
            setState(preState=>({...preState,loading:false,}))
        })
    }
    return {state,request} as const
}