From 33440bb15f8d7f07b68e34760129d3300cab5e88 Mon Sep 17 00:00:00 2001
From: zhangyongtian <1181606322@qq.com>
Date: Tue, 27 Aug 2024 10:57:21 +0800
Subject: [PATCH] feat:编辑当事人逻辑

---
 gz-customerSystem/src/views/register/visit/component/applyDialog.jsx     |   31 ++++++++--
 gz-customerSystem/src/views/register/visit/component/agentDialog.jsx     |   56 +++++++++++++-----
 gz-customerSystem/src/views/register/visit/component/visitorRegister.jsx |   49 +++++++++++++---
 gz-customerSystem/src/components/personCard/index.jsx                    |    4 
 4 files changed, 104 insertions(+), 36 deletions(-)

diff --git a/gz-customerSystem/src/components/personCard/index.jsx b/gz-customerSystem/src/components/personCard/index.jsx
index d9e33c6..fb4cf52 100644
--- a/gz-customerSystem/src/components/personCard/index.jsx
+++ b/gz-customerSystem/src/components/personCard/index.jsx
@@ -18,7 +18,7 @@
  * handleCheckParty, // 点击查看详情
  * handleDeleteParty, // 删除当事人
  */
-const PersonCard = ({ isCheck, data, handleCheckParty, handleDeleteParty, handleAdd }) => {
+const PersonCard = ({ isCheck, data, handleCheckParty, handleDeleteParty, handleAdd, handleEdit }) => {
     let isAgent = false
     let isAgentFor = false
     const typeList = data.map(item => {
@@ -53,7 +53,7 @@
                                 <Text style={{ maxWidth: '80%', paddingRight: '8px' }} ellipsis={{ tooltip: x.trueName }}>
                                     {x.trueName}
                                 </Text>
-                                <Text ellipsis={{ tooltip: x.perClassName }} className={`public-personCard-tag public-personCard-tag-${(x.partyType === 0 || x.partyType === 2) ? 'blue' : 'orange'}`}>
+                                <Text onClick={() => { handleEdit(x) }} ellipsis={{ tooltip: x.perClassName }} className={`public-personCard-tag public-personCard-tag-${(x.partyType === 0 || x.partyType === 2) ? 'blue' : 'orange'}`}>
                                     {x.perClassName}
                                 </Text>
                             </div>
diff --git a/gz-customerSystem/src/views/register/visit/component/agentDialog.jsx b/gz-customerSystem/src/views/register/visit/component/agentDialog.jsx
index 5dfe16e..bea0658 100644
--- a/gz-customerSystem/src/views/register/visit/component/agentDialog.jsx
+++ b/gz-customerSystem/src/views/register/visit/component/agentDialog.jsx
@@ -17,27 +17,48 @@
   const [visitList, setVisitList] = useState([])
 
   useEffect(() => {
-    //过滤代理人
-    setVisitList(props.fakeData.filter(item => {
-      console.log(item,props.dialogType);
-      if (props.dialogType === 2) {
-        return item.partyType === 0
-      } else {
-        return item.partyType === 1
-      }
-    }))
-  }, [props.fakeData])
+    if (props.editData) {
+      //编辑
+      formRef.current.setFieldsValue({
+        ...props.editData
+      })
+      //过滤代理人
+      setVisitList(props.fakeData.filter(item => {
+        if (props.editData.dialogType === 2) {
+          return item.partyType === 0
+        } else {
+          return item.partyType === 1
+        }
+      }))
+    } else {
+      //过滤代理人
+      setVisitList(props.fakeData.filter(item => {
+        if (props.dialogType === 2) {
+          return item.partyType === 0
+        } else {
+          return item.partyType === 1
+        }
+      }))
+    }
+  }, [])
 
   //保存信息
   const handleSave = () => {
     if (formRef.current) {
       formRef.current.validate(undefined, (errors, values) => {
         if (!errors) {
-          props.handleAddParty({
-            ...values,
-            partyType: props.dialogType,
-            perClassName: props.dialogType === 2 ? '申请方代理人' : '被申请方代理人',
-          })
+          if (props.editData) {
+            props.handleAddParty({
+              ...props.editData,
+              ...values,
+            })
+          } else {
+            props.handleAddParty({
+              ...values,
+              partyType: props.dialogType,
+              perClassName: props.dialogType === 2 ? '申请方代理人' : '被申请方代理人',
+            })
+          }
           props.onClose()
         }
       });
@@ -55,6 +76,7 @@
               requiredSymbol={false}
               initialValues={{
               }}//默认值
+              scrollToFirstError
             >
               <Row gutter={[32, 0]} style={{ margin: '0 -10px' }}>
                 <Col span={24}>
@@ -227,7 +249,7 @@
                 <Col span={12}>
                   <FormItem
                     label={(<div style={{ display: 'flex' }}>代理对象<div className="must">必填</div></div>)}
-                    rules={[{ required: true }]}
+                    rules={[{ required: true, message: '请选择代理对象' }]}
                     field='dailimap'
                   >
                     <CheckboxGroup
@@ -256,7 +278,7 @@
           className="dialogPrimary"
           onClick={handleSave}
         >
-          保存信息
+          保存
         </Button>
         <Button className="dialogBack">
           重置
diff --git a/gz-customerSystem/src/views/register/visit/component/applyDialog.jsx b/gz-customerSystem/src/views/register/visit/component/applyDialog.jsx
index bca0bab..3d31adb 100644
--- a/gz-customerSystem/src/views/register/visit/component/applyDialog.jsx
+++ b/gz-customerSystem/src/views/register/visit/component/applyDialog.jsx
@@ -29,6 +29,15 @@
   const [perClass, setPerClass] = useState('09_01001-1');
   const [visible, setVisible] = useState(false);
 
+  useEffect(() => {
+    if (props.editData) {
+      //编辑
+      formRef.current.setFieldsValue({
+        ...props.editData
+      })
+    }
+  }, [])
+
 
   const personIconType = (v) => {
     switch (v) {
@@ -271,12 +280,19 @@
     if (formRef.current) {
       formRef.current.validate(undefined, (errors, values) => {
         if (!errors) {
-          props.handleAddParty({
-            ...values,
-            partyType: props.dialogType,
-            perClass: perClass,
-            perClassName: props.dialogType === 0 ? '申请方当事人' : '被申请方当事人'
-          })
+          if (props.editData) {
+            props.handleAddParty({
+              ...props.editData,
+              ...values
+            })
+          } else {
+            props.handleAddParty({
+              ...values,
+              partyType: props.dialogType,
+              perClass: perClass,
+              perClassName: props.dialogType === 0 ? '申请方当事人' : '被申请方当事人'
+            })
+          }
           props.onClose()
         }
       });
@@ -319,6 +335,7 @@
               requiredSymbol={false}
               initialValues={{
               }}//默认值
+              scrollToFirstError
             >
               <Row gutter={[32, 0]} style={{ margin: '0 -10px' }}>{formType(perClass)}</Row>
             </Form>
@@ -336,7 +353,7 @@
           className="dialogPrimary"
           onClick={handleSave}
         >
-          保存信息
+          保存
         </Button>
         <Button className="dialogBack">
           重置
diff --git a/gz-customerSystem/src/views/register/visit/component/visitorRegister.jsx b/gz-customerSystem/src/views/register/visit/component/visitorRegister.jsx
index 7735b89..3dce4c6 100644
--- a/gz-customerSystem/src/views/register/visit/component/visitorRegister.jsx
+++ b/gz-customerSystem/src/views/register/visit/component/visitorRegister.jsx
@@ -46,9 +46,10 @@
   const [fileTip, setFileTip] = useState('0');
   const [detailVisabled, setDetailVisabled] = useState(false);//查看信息弹窗控制
   const [mapView, setMapView] = useState(false);
-  const [flagId, setFlagId] = useState(0);//赋予当事人唯一id,用于删除
+  const [flagId, setFlagId] = useState(1);//赋予当事人唯一id,用于删除
   const [visible, setVisible] = useState(false);
   const [apply, setApply] = useState(false);
+  const [editData, setEditData] = useState(null);
 
   const addressOptions = [
     { label: '地址1', value: 'address1' },
@@ -369,12 +370,24 @@
 
   //添加当事人
   const handleAddParty = (value) => {
-    console.log(value);
-    setFakeData([...fakeData, {
-      ...value,
-      id: flagId
-    }])
-    setFlagId(flagId + 1)
+    if (value.id) {
+      //编辑
+      const newList = fakeData.map(item => {
+        if (item.id === value.id) {
+          return value
+        } else {
+          return item
+        }
+      })
+      setFakeData(newList)
+      setEditData(null)
+    } else {
+      setFakeData([...fakeData, {
+        ...value,
+        id: flagId
+      }])
+      setFlagId(flagId + 1)
+    }
   }
 
   //删除当事人
@@ -382,6 +395,19 @@
     event.stopPropagation();
     const filterData = fakeData.filter(item => item.id !== value.id)
     setFakeData(filterData)
+  }
+
+  //编辑
+  const handleEdit = (value) => {
+    console.log(value);
+    if (value.partyType === 0 || value.partyType === 1) {
+      //当事人
+      setAddVisabled(true)
+    } else {
+      //代理人
+      setAgentVisible(true)
+    }
+    setEditData(value)
   }
 
 
@@ -401,6 +427,7 @@
           handleCheckParty={handleCheckParty}
           handleAdd={handleAdd}
           handleDeleteParty={handleDeleteParty}
+          handleEdit={handleEdit}
         />
       </div>
       <Col span={24} style={{ display: 'flex', alignItems: 'center', marginBottom: '8px' }}>
@@ -726,6 +753,7 @@
           dialogType={dialogType}
           onClose={() => setAddVisabled(false)}
           handleAddParty={handleAddParty}
+          editData={editData}
         />
       </Modal>
       <Modal
@@ -744,6 +772,7 @@
           onClose={() => setAgentVisible(false)}
           fakeData={fakeData}
           dialogType={dialogType}
+          editData={editData}
         />
       </Modal>
       <Modal
@@ -795,7 +824,7 @@
       >
         <div style={{ marginTop: '-8px' }}>
           <div>
-            <div style={{ color: '#1A6FB8', fontSize: '15px',lineHeight:'23px',marginBottom:'8px' }}>一类重点事件</div>
+            <div style={{ color: '#1A6FB8', fontSize: '15px', lineHeight: '23px', marginBottom: '8px' }}>一类重点事件</div>
             1、5人(含5人)以上到非接待场所聚集、滞留、静坐、游行或准备上访;<br />
             2、拉横幅、穿着“状衣”、呼喊口号、呼喊标语、堵塞交通非法占据公其场所、扰乱公共秩序、向他人散发传单等上访材料;<br />
             3、拖欠工资、劳资纠纷涉及人数5人以上;<br />
@@ -805,7 +834,7 @@
             7、群体性民事纠纷(5人及5人以上的邻里矛盾纠纷、经济债务纠纷、家庭纠纷等可能导致“民转刑”的民事纠纷);8、存在重大安全隐患、重大不稳定因索的矛盾;9、涉及政治类,非宗教类的非访宣传(在出租屋内从事涉邪教迷信印刷、存放资料的;在公共场所粘贴类似邪教的符号、图案、标志等)10、县(市、区)职能部门、各镇(街道)分管领导根据应急情况认为有必要启动红色预警机制的其他矛盾纠纷。
           </div>
           <div>
-            <div style={{ color: '#1A6FB8', fontSize: '15px',lineHeight:'23px',marginBottom:'8px',marginTop:'20px' }}>二类重点事件</div>
+            <div style={{ color: '#1A6FB8', fontSize: '15px', lineHeight: '23px', marginBottom: '8px', marginTop: '20px' }}>二类重点事件</div>
             1、5人(含5人)以上到非接待场所聚集、滞留、静坐、游行或准备上访;<br />
             2、拉横幅、穿着“状衣”、呼喊口号、呼喊标语、堵塞交通非法占据公其场所、扰乱公共秩序、向他人散发传单等上访材料;<br />
             3、拖欠工资、劳资纠纷涉及人数5人以上;<br />
@@ -815,7 +844,7 @@
             7、群体性民事纠纷(5人及5人以上的邻里矛盾纠纷、经济债务纠纷、家庭纠纷等可能导致“民转刑”的民事纠纷);8、存在重大安全隐患、重大不稳定因索的矛盾;9、涉及政治类,非宗教类的非访宣传(在出租屋内从事涉邪教迷信印刷、存放资料的;在公共场所粘贴类似邪教的符号、图案、标志等)10、县(市、区)职能部门、各镇(街道)分管领导根据应急情况认为有必要启动红色预警机制的其他矛盾纠纷。
           </div>
           <div>
-            <div style={{ color: '#1A6FB8', fontSize: '15px',lineHeight:'23px',marginBottom:'8px',marginTop:'20px' }}>三类普通事件</div>
+            <div style={{ color: '#1A6FB8', fontSize: '15px', lineHeight: '23px', marginBottom: '8px', marginTop: '20px' }}>三类普通事件</div>
             1、5人(含5人)以上到非接待场所聚集、滞留、静坐、游行或准备上访;<br />
             2、拉横幅、穿着“状衣”、呼喊口号、呼喊标语、堵塞交通非法占据公其场所、扰乱公共秩序、向他人散发传单等上访材料;<br />
             3、拖欠工资、劳资纠纷涉及人数5人以上;<br />

--
Gitblit v1.8.0