lanjianrong před 4 roky
rodič
revize
4a415275a1

+ 23 - 14
src/pages/Customer/Client/components/AddClient/index.jsx

@@ -1,9 +1,9 @@
-import React, { useState, useRef } from 'react'
+import React, { useRef, useState, useEffect } from 'react'
 import { Form, Row, Col, Button } from 'antd'
 import LazyCascader from '@/components/LazyCascader'
 import { ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
 import { Plus } from '@icon-park/react'
-import { useDispatch } from 'umi'
+import { useDispatch, connect } from 'umi'
 import { ChangeCompMap } from '@/pages/Customer/Company/components/ChangeCompany'
 import ModalDragForm from '@/components/Modal/src/components/ModalDragForm'
 import { isNullOrUnDef } from '@/utils/is'
@@ -17,7 +17,8 @@ const AddClient = props => {
     dataId,
     dataType,
     btnTitle = '客户',
-    defaultValues
+    defaultValues,
+    sourceList
   } = props
   const formRef = useRef(null)
   const layout = {
@@ -27,6 +28,13 @@ const AddClient = props => {
   const [showDataItem, setShowDataItem] = useState(false)
   const [validStatusFtl, setValidStatusFtl] = useState('')
   const dispatch = useDispatch()
+  useEffect(() => {
+    if (!sourceList?.length) {
+      dispatch({
+        type: 'client/fetchSourceList'
+      })
+    }
+  }, [])
   return (
     <ModalDragForm
       {...layout}
@@ -36,11 +44,6 @@ const AddClient = props => {
       onVisibleChange={visible => {
         if (visible) {
           formRef.current?.setFieldsValue({ ...defaultValues })
-          dispatch({
-            type: 'client/fetchSourceList',
-            payload: reload
-          })
-          console.log(dispatch)
         }
       }}
       trigger={
@@ -64,7 +67,8 @@ const AddClient = props => {
                 }
                 formRef.current && formRef.current.setFieldsValue(values)
                 submit()
-              }}>
+              }}
+            >
               添加并关联
             </Button>
           ) : null
@@ -76,7 +80,8 @@ const AddClient = props => {
         setValidStatusFtl('')
         !isNullOrUnDef(reload) && reload()
         return true
-      }}>
+      }}
+    >
       {showDataItem ? <ProFormText name={`${dataType}Id`} hidden /> : null}
       <ProFormText
         name="clientName"
@@ -87,7 +92,8 @@ const AddClient = props => {
       <Form.Item
         label="客户地区"
         name="districtIds"
-        rules={[{ required: true, message: '请选择地区' }]}>
+        rules={[{ required: true, message: '请选择地区' }]}
+      >
         <LazyCascader showFooter={true} />
       </Form.Item>
       <Row>
@@ -109,7 +115,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
@@ -142,11 +149,13 @@ const AddClient = props => {
         label="来源"
         placeholder=""
         rules={[{ message: '来源' }]}
-        fieldProps={{ options: [] }}
+        options={sourceList}
       />
       <ProFormTextArea label="备注" name="mark" placeholder="" />
     </ModalDragForm>
   )
 }
 
-export default AddClient
+export default connect(({ client }) => ({
+  sourceList: client.sourceList
+}))(AddClient)

+ 1 - 1
src/pages/Customer/Company/index.jsx

@@ -6,7 +6,7 @@ import { queryCompany, apiAddCompany } from '@/services/customer'
 import CompanyDetail from '@/pages/Customer/Company/components/CompanyDetail'
 import AddCompany from '@/pages/Customer/Company/components/AddCompany'
 import { useModal } from '@/components/Modal'
-import { formatValues } from '@/components/LazyCascader'
+import LazyCascader, { formatValues } from '@/components/LazyCascader'
 import PersonLabel from './components/PersonLabel'
 import { TagTypeEnum, TagDataTypeEnum, LabelModeType } from './components/PersonLabel/const'
 import { Add, Down, Check } from '@icon-park/react'