Browse Source

feat: 111

lanjianrong 4 năm trước cách đây
mục cha
commit
12f7c74575
1 tập tin đã thay đổi với 30 bổ sung21 xóa
  1. 30 21
      src/pages/Customer/Client/components/AddClient/index.jsx

+ 30 - 21
src/pages/Customer/Client/components/AddClient/index.jsx

@@ -1,12 +1,7 @@
 import React, { useRef, useState, useEffect } from 'react'
 import { Form, Row, Col, Button } from 'antd'
 import LazyCascader from '@/components/LazyCascader'
-import {
-  ProFormSelect,
-  ProFormText,
-  ProFormTextArea,
-  ProFormDependency
-} from '@ant-design/pro-form'
+import { ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
 import { Plus } from '@icon-park/react'
 import { useDispatch, connect } from 'umi'
 import { ChangeCompMap } from '@/pages/Customer/Company/components/ChangeCompany'
@@ -41,18 +36,28 @@ const AddClient = props => {
     }
   }, [])
 
-  const handleChange = () => {
-    if (!formRef.current?.getFieldValue('clientName')) {
-      const clientNameNum = clientName.value.split('')
-      const [firstName, ...lastName] = clientNameNum
-      const nameAfter = `(${lastName.join('')})`
-      const newClientName = `${firstName + nameAfter}工`
+  const handleChange = changedValues => {
+    if (!changedValues) return
+    if ('clientName' in changedValues) {
+      const [lastName, ...firstName] = changedValues.clientName.split('')
+      const newClientName = `${lastName}(${firstName.join('')})工`
       formRef.current?.setFieldsValue({ niceName: newClientName })
-    } else if (!formRef.current?.getFieldValue('qq')) {
-      const emailNum = qq.value
-      const newEmail = `${emailNum}@qq.com`
-      formRef.current?.setFieldsValue({ email: newEmail })
     }
+    if ('qq' in changedValues) {
+      formRef.current?.setFieldsValue({ email: `${changedValues.qq}@qq.com` })
+    }
+    // const clientName = formRef.current?.getFieldValue('clientName')
+    // if (clientName) {
+    //   const clientNameNum = clientName.split('')
+    //   const [firstName, ...lastName] = clientNameNum
+    //   const nameAfter = `(${lastName.join('')})`
+    //   const newClientName = `${firstName + nameAfter}工`
+    //   formRef.current?.setFieldsValue({ niceName: newClientName })
+    // } else if (!formRef.current?.getFieldValue('qq')) {
+    //   const emailNum = qq.value
+    //   const newEmail = `${emailNum}@qq.com`
+    //   formRef.current?.setFieldsValue({ email: newEmail })
+    // }
   }
   return (
     <ModalDragForm
@@ -65,7 +70,7 @@ const AddClient = props => {
           formRef.current?.setFieldsValue({ ...defaultValues })
         }
       }}
-      onChange={handleChange}
+      onValuesChange={handleChange}
       trigger={
         <Button type="primary" {...buttonProps} className="mr-1">
           <Plus className="mr-1" />
@@ -87,7 +92,8 @@ const AddClient = props => {
                 }
                 formRef.current && formRef.current.setFieldsValue(values)
                 submit()
-              }}>
+              }}
+            >
               添加并关联
             </Button>
           ) : null
@@ -99,7 +105,8 @@ const AddClient = props => {
         setValidStatusFtl('')
         !isNullOrUnDef(reload) && reload()
         return true
-      }}>
+      }}
+    >
       {showDataItem ? <ProFormText name={`${dataType}Id`} hidden /> : null}
       <ProFormText
         name="clientName"
@@ -110,7 +117,8 @@ const AddClient = props => {
       <Form.Item
         label="客户地区"
         name="districtIds"
-        rules={[{ required: true, message: '请选择地区' }]}>
+        rules={[{ required: true, message: '请选择地区' }]}
+      >
         <LazyCascader showFooter={true} />
       </Form.Item>
       <Row>
@@ -132,7 +140,8 @@ const AddClient = props => {
             name="telephone"
             validateStatus={validStatusFtl}
             hasFeedback
-            rules={[{ required: true, message: '请输入手机号码' }]}>
+            rules={[{ required: true, message: '请输入手机号码' }]}
+          >
             <TelephoneFormItem validateFn={status => setValidStatusFtl(status)} />
           </Form.Item>
           <ProFormText