index.jsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React, { useRef, useState, useEffect } from 'react'
  2. import { Form, Row, Col, Button } from 'antd'
  3. import LazyCascader from '@/components/LazyCascader'
  4. import {
  5. ProFormSelect,
  6. ProFormText,
  7. ProFormTextArea,
  8. ProFormDependency
  9. } from '@ant-design/pro-form'
  10. import { Plus } from '@icon-park/react'
  11. import { useDispatch, connect } from 'umi'
  12. import { ChangeCompMap } from '@/pages/Customer/Company/components/ChangeCompany'
  13. import ModalDragForm from '@/components/Modal/src/components/ModalDragForm'
  14. import { isNullOrUnDef } from '@/utils/is'
  15. import TelephoneFormItem from './TelephoneFormItem'
  16. const AddClient = props => {
  17. const {
  18. reload,
  19. onConfirm,
  20. buttonProps,
  21. dataId,
  22. dataType,
  23. btnTitle = '客户',
  24. defaultValues,
  25. sourceList
  26. } = props
  27. const formRef = useRef(null)
  28. const layout = {
  29. layout: 'horizontal',
  30. labelCol: { flex: '100px' }
  31. }
  32. const [showDataItem, setShowDataItem] = useState(false)
  33. const [validStatusFtl, setValidStatusFtl] = useState('')
  34. const dispatch = useDispatch()
  35. useEffect(() => {
  36. if (!sourceList?.length) {
  37. dispatch({
  38. type: 'client/fetchSourceList'
  39. })
  40. }
  41. }, [])
  42. // const handleChange = () => {
  43. // if (clientName !== '') {
  44. // const clientNameNum = clientName.value.split('')
  45. // const clientText = '工'
  46. // const symbolBefore = '('
  47. // const symbolAfter = ')'
  48. // if (clientNameNum?.length < 3) {
  49. // const clientNameTwo = clientNameNum[1]
  50. // const newClientName =
  51. // clientNameNum[0] + symbolBefore + clientNameTwo + symbolAfter + clientText
  52. // niceName.value = newClientName
  53. // } else if (clientNameNum?.length < 4) {
  54. // const clientNameTwo = clientNameNum[1] + clientNameNum[2]
  55. // const newClientName =
  56. // clientNameNum[0] + symbolBefore + clientNameTwo + symbolAfter + clientText
  57. // niceName.value = newClientName
  58. // } else if (clientNameNum?.length < 5) {
  59. // const clientNameTwo = clientNameNum[1] + clientNameNum[2] + clientNameNum[3]
  60. // const newClientName =
  61. // clientNameNum[0] + symbolBefore + clientNameTwo + symbolAfter + clientText
  62. // niceName.value = newClientName
  63. // } else {
  64. // niceName.value = ''
  65. // }
  66. // }
  67. // if (qq !== '') {
  68. // const emailText = 'qq.com'
  69. // const emailNew = qq.value + emailText
  70. // email.value = emailNew
  71. // }
  72. // }
  73. // const handleChange = () => {
  74. // const newEmail = `${email.value}@qq.com`
  75. // formRef.current?.setFieldsValue({
  76. // email: newEmail
  77. // })
  78. // }
  79. return (
  80. <ModalDragForm
  81. {...layout}
  82. formRef={formRef}
  83. modalProps={{ zIndex: 1003, getContainer: false }}
  84. title="添加客户"
  85. onVisibleChange={visible => {
  86. if (visible) {
  87. formRef.current?.setFieldsValue({ ...defaultValues })
  88. }
  89. }}
  90. trigger={
  91. <Button type="primary" {...buttonProps} className="mr-1">
  92. <Plus className="mr-1" />
  93. {btnTitle}
  94. </Button>
  95. }
  96. submitter={{
  97. render: ({ submit }, defaultDoms) => [
  98. ...defaultDoms,
  99. dataId ? (
  100. <Button
  101. type="primary"
  102. key="2"
  103. onClick={() => {
  104. setShowDataItem(true)
  105. const values = {}
  106. if (dataType === ChangeCompMap.BUSINESS.key) {
  107. values.businessId = dataId
  108. }
  109. formRef.current && formRef.current.setFieldsValue(values)
  110. submit()
  111. }}>
  112. 添加并关联
  113. </Button>
  114. ) : null
  115. ]
  116. }}
  117. onFinish={async values => {
  118. await onConfirm(values)
  119. formRef.current?.resetFields()
  120. setValidStatusFtl('')
  121. !isNullOrUnDef(reload) && reload()
  122. return true
  123. }}>
  124. {showDataItem ? <ProFormText name={`${dataType}Id`} hidden /> : null}
  125. <ProFormText
  126. name="clientName"
  127. label="姓名"
  128. placeholder="请输入客户名称"
  129. rules={[{ required: true, message: '请输入姓名' }]}
  130. />
  131. <Form.Item
  132. label="客户地区"
  133. name="districtIds"
  134. rules={[{ required: true, message: '请选择地区' }]}>
  135. <LazyCascader showFooter={true} />
  136. </Form.Item>
  137. <Row>
  138. <Col span={12}>
  139. <ProFormSelect
  140. name="gender"
  141. label="性别"
  142. placeholder=""
  143. rules={[{ message: '请选择性别' }]}
  144. options={[
  145. { label: '男', value: '男' },
  146. { label: '女', value: '女' }
  147. ]}
  148. />
  149. <ProFormText label="部门" name="department" placeholder="" />
  150. <Form.Item
  151. label="手机"
  152. name="telephone"
  153. validateStatus={validStatusFtl}
  154. hasFeedback
  155. rules={[{ required: true, message: '请输入手机号码' }]}>
  156. <TelephoneFormItem validateFn={status => setValidStatusFtl(status)} />
  157. </Form.Item>
  158. <ProFormText
  159. label="电话"
  160. name="phone"
  161. rules={[{ message: '请输入电话/座机号' }]}
  162. placeholder=""
  163. />
  164. </Col>
  165. <Col span={12}>
  166. <ProFormDependency name={['clientName']}>
  167. {({ clientName, newClientName }) => {
  168. if (!clientName === false) {
  169. const clientNameNum = clientName.split('')
  170. const [firstName, ...lastName] = clientNameNum
  171. const nameAfter = `(${lastName.join('')})`
  172. // eslint-disable-next-line no-param-reassign
  173. newClientName = `${firstName + nameAfter}工`
  174. }
  175. return (
  176. <ProFormText
  177. label="昵称"
  178. name="niceName"
  179. placeholder=""
  180. value={`${newClientName || ''}`}
  181. />
  182. )
  183. }}
  184. </ProFormDependency>
  185. <ProFormText label="职位" name="position" placeholder="" />
  186. <ProFormText label="QQ" name="qq" placeholder="" />
  187. <ProFormText label="邮箱" name="email" placeholder="" />
  188. </Col>
  189. </Row>
  190. <Row>
  191. <Col span={12}>
  192. <ProFormText label="办公室" name="office" placeholder="" />
  193. </Col>
  194. <Col span={12}>
  195. <ProFormSelect
  196. name="sourceId"
  197. label="来源"
  198. placeholder=""
  199. rules={[{ message: '来源' }]}
  200. options={sourceList}
  201. />
  202. </Col>
  203. </Row>
  204. <Row>
  205. <Col span={12}>
  206. <ProFormText label="客户地址" name="address" placeholder="" />
  207. <ProFormText label="客户地标" name="landmarks" placeholder="" />
  208. </Col>
  209. <Col span={12}>
  210. <ProFormText label="客户乘车" name="ride" placeholder="" />
  211. <ProFormText label="客户住宿" name="stay" placeholder="" />
  212. </Col>
  213. </Row>
  214. <ProFormTextArea label="备注" name="mark" placeholder="" />
  215. </ModalDragForm>
  216. )
  217. }
  218. export default connect(({ client }) => ({
  219. sourceList: client.sourceList
  220. }))(AddClient)