forked from gzzfw/frontEnd/gzDyh

zhangyongtian
2024-09-08 f7452b9d6295748c9840245d26df6514e8ed2c1d
gz-customerSystem/src/views/register/visit/index.jsx
@@ -2,60 +2,138 @@
 * @Author: dminyi 1301963064@qq.com
 * @Date: 2024-08-09 09:59:43
 * @LastEditors: dminyi 1301963064@qq.com
 * @LastEditTime: 2024-08-23 10:12:47
 * @LastEditTime: 2024-09-07 17:27:08
 * @FilePath: \gzDyh\gz-customerSystem\src\views\basicInformation\organization\index.jsx
 * @Description: 来访登记
 */
import React, { useState, useEffect, useRef, Fragment } from "react";
import React, { useState, useRef, Fragment, useEffect } from "react";
import { useSearchParams, useNavigate } from 'react-router-dom';
import NewPage from '@/components/NewPage';
import RegisterTab from '@/components/registerTab';
import * as $$ from '@/utils/utility';
import "@arco-themes/react-gzzz/css/arco.css";
import '../index.less';
import { Space } from 'antd';
import { Button, Steps } from '@arco-design/web-react';
import { Button, Steps, Message } from '@arco-design/web-react';
import VisitorRegister from './component/visitorRegister';
import Preview from './preview';
import { useParams } from 'react-router-dom';
const Step = Steps.Step;
function getCaseDataApi(submitData) {
   return $$.ax.request({ url: `caseInfo/getCaseInfo?id=${submitData}`, type: 'get', service: 'mediate' });
function saveDispute(data) {
   return $$.ax.request({ url: `casedraftInfo/caseDraftRegister`, type: 'post', service: 'mediate', data });
}
function getId() {
   return $$.ax.request({ url: `caseUtils/getNewTimeCaseId`, type: 'get', service: 'utils' });
}
function submitDispute(data) {
   return $$.ax.request({ url: `caseInfo/caseRegister`, type: 'post', service: 'mediate', data });
}
function getDetailData(id) {
   return $$.ax.request({ url: `casedraftInfo/getCasedraftInfo?id=${id}`, type: 'get', service: 'mediate' });
}
const Organization = () => {
const Organization = (props) => {
   const formRef = useRef();
   const routeData = useParams();
  const navigate = useNavigate();
   const [isReview, setIsReview] = useState(false);//预览页面控制
   const [current, setCurrent] = useState(1);
   const [id, setId] = useState();
   const [partyList, setPartyList] = useState([]);//当事人信息,用于子组件回显
   const tabs = [
      { label: '事件登记', key: '1' },
      { label: '事件流转', key: '2' },
      { label: '办理反馈', key: '3' },
      { label: '申请结案', key: '4' },
      { label: '当事人评价', key: '5' },
      { label: '结案归档', key: '6', img1: true },
   useEffect(() => {
      if (routeData.id) {
         getDeatil(routeData.id)
         setId(routeData.id)
      } else {
         getAppId()
      }
   ];
   }, [])
   //编辑
   const getDeatil = async (id) => {
      const res = await getDetailData(id)
      if (res.type) {
         const { agentList, personList, ...rest } = res.data
         const parList = agentList.concat(personList)
         formRef.current.setFieldsValue({
            ...rest,
            fakeData: parList,
            myCaseType: [rest.caseTypeFirst, rest.caseType],
            myQuesAddress: rest.queRoad ? [rest.queProv, rest.queCity, rest.queArea, rest.queRoad] : undefined
         })
         setPartyList(parList)
      }
   }
   //获取id
   const getAppId = async () => {
      const res = await getId()
      if (res.type) {
         setId(res.data)
      }
   }
   //提交信息,需要校验规则
   const handleSubmit = async () => {
      if (formRef.current) {
         formRef.current.validate(undefined, (errors, values) => {
            console.log(errors, values);
            if (!errors) {
               const { myCaseType, myQuesAddress, ...rest } = formRef.current.getFields()
               const params = handleData(rest)
               reauestSubmit({
                  ...params,
                  isSelfAccept: 0,
                  isDraft: 0,
                  operateType: 0,
               })
            }
         });
      }
   }
   //保存草稿信息,不需要校验规则
   const handleSave = async () => {
   const handleSave = () => {
      if (formRef.current) {
         const data = formRef.current.getFields()
         console.log(data);
         const { myCaseType, myQuesAddress, ...rest } = formRef.current.getFields()
         const params = handleData(rest)
         requestSave(params)
      }
   }
   //数据处理
   const handleData = (data) => {
      const { fakeData, ...newObj } = data
      if (data.id) {
         return {
            ...newObj,
            personList: fakeData?.filter(item => item.perType === "15_020008-1" || item.perType === "15_020008-2"),
            agentList: fakeData?.filter(item => item.perType === "24_00006-1" || item.perType === "24_00006-2").map(item => {
               return {
                  ...item,
                  personId: item.personId.join(',')
               }
            }),
         }
      } else {
         return {
            ...newObj,
            personList: fakeData?.filter(item => item.perType === "15_020008-1" || item.perType === "15_020008-2"),
            agentList: fakeData?.filter(item => item.perType === "24_00006-1" || item.perType === "24_00006-2").map(item => {
               return {
                  ...item,
                  personId: item.personId.join(',')
               }
            }),
            id: id
         }
      }
   }
@@ -67,21 +145,32 @@
   function selfAcceptance() {
      $$.modalInfo({
         title: '自行受理确认',
         content: '确定自行受理本次登记事项吗?自行受理成功后事项将直接进入到本单位办理流程',
         content: '确定自行受理吗?',
         okText: '确定受理',
         cancelText: '我再想想',
         onOk: async () => {
            console.log('1111111')
            setCurrent(3);
            navigate(`mediate/visit/handleFeedback`, { replace: true })
         },
      });
   }
   function submit() {
      $$.info({ type: 'warning', content: '您没有预约记录,暂时无法提交' })
   //保存请求
   const requestSave = async (data) => {
      const response = await saveDispute(data)
      if (response.type) {
         Message.success('保存草稿成功!')
      }
   }
   console.log(current,'current')
   //提交请求
   const reauestSubmit = async (data) => {
      const response = await submitDispute(data)
      if (response.type) {
         Message.success('提交成功!')
         setCurrent(2)
      }
   }
   return (
      <div style={{ position: 'relative' }}>
@@ -90,35 +179,30 @@
               { breadcrumbData: [{ title: '工作台' }, { title: '来访登记' }], title: '来访登记' }
            }
         >
            {/* <RegisterTab tabs={tabs} activeKey={tabsActive} onChange={(activeKey) => setTabsActive(activeKey)} style={{ background: '#fff' }} /> */}
            <div style={{backgroundColor: '#fff',margin:'12px 16px 0px 16px',paddingTop:'16px',paddingLeft:'91px'}}>
               <Steps type='navigation' current={current} onChange={setCurrent} style={{ }}>
                  <Step title='来访登记' style={{ color: '#1A6FB8' }} disabled/>
                  <Step title='事件流转' disabled/>
                  <Step title='办理反馈' disabled/>
                  <Step title='结案审核' disabled/>
                  <Step title='当事人评价' disabled/>
                  <Step title='结案归档' disabled/>
               </Steps>
            </div>
            {current === 1 &&
               <Fragment>
                  {isReview ? <Preview /> : <VisitorRegister formRef={formRef} />}
                  <div className="dataSync-excel">
                     <Space size="large" style={{ margin: '4px 14px' }}>
                        <Button type="primary" style={{ backgroundColor: '#1A6FB8' }} onClick={handleSave} >保存</Button>
                        <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={handleReview}>预览</Button>
                        <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={handleSubmit}>提交</Button>
                        <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={() => selfAcceptance()}>自行受理</Button>
                        <Button type='secondary' onClick={handleReview}>返回上级页面</Button>
                     </Space>
                  </div>
               </Fragment>
            }
            {/* {preview && <Preview />} */}
            <Fragment>
               <div style={{ backgroundColor: '#fff', margin: '12px 16px 0px 16px', paddingTop: '16px', paddingLeft: '91px' }}>
                  <Steps type='navigation' current={current}>
                     <Step title='来访登记' disabled />
                     <Step title='事件流转' disabled />
                     <Step title='办理反馈' disabled />
                     <Step title='结案审核' disabled />
                     <Step title='当事人评价' disabled />
                     <Step title='结案归档' disabled />
                  </Steps>
               </div>
               <Preview style={{ display: isReview ? '' : 'none' }} data={formRef?.current?.getFields()} />
               <VisitorRegister formRef={formRef} style={{ display: isReview ? 'none' : '' }} mainId={id} partyList={partyList} />
               <div className="dataSync-excel">
                  <Space size="large" style={{ margin: '4px 14px' }}>
                     <Button type="primary" style={{ backgroundColor: '#1A6FB8' }} onClick={handleSave} >保存</Button>
                     <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={handleReview}>预览</Button>
                     <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={handleSubmit}>提交</Button>
                     <Button type='outline' style={{ color: '#1A6FB8', border: '1px solid #1A6FB8' }} onClick={() => selfAcceptance()}>自行受理</Button>
                     <Button type='secondary' onClick={handleReview}>返回上级页面</Button>
                  </Space>
               </div>
            </Fragment>
         </NewPage>
      </div>
   )
}