import RenderForm from "@/webPublic/FormInsertDiy/RenderForm";
import { fetchTemplateById } from '@/webPublic/Services';
import { useState, useEffect } from "react";
import { Form } from 'antd';
import { setToken } from '@/utils/authority';
import { getUrlInfo } from '@/webPublic/one_stop_public/DetailForAudit/utils';

function OtherCheckRecord({ form, location: { pathname }, ...props }) {
  const [data, setData]  = useState();
  useEffect(() => {
    let params = getUrlInfo();
    let id = params.id || props.id;
    const { token, isMobile} = params;
    if(token){
      setToken(token);
    }
    if(!id){
      console.error('没有找到id');
    }
    if(isMobile){
      document.body.style.minWidth = 'auto'; // 移动端宽度自适应
    }
    setData(undefined);
    fetchTemplateById(id).then(res => {
      if (res) setData({...res, content: "{}"});
    });
  }, [pathname]);

  return !!data && <RenderForm form={form}
                               postData={data}
                               style={{ padding: 0 }} />;
}

export default  Form.create()(OtherCheckRecord)
