index.jsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import React, { useState, useRef } from 'react'
  2. import { Form, Row, Col, Button } from 'antd'
  3. import LazyCascader from '@/components/LazyCascader'
  4. import { ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  5. import { Plus } from '@icon-park/react'
  6. import { ChangeCompMap } from '@/pages/Customer/Company/components/ChangeCompany'
  7. import ModalDragForm from '@/components/Modal/src/components/ModalDragForm'
  8. import { isNullOrUnDef } from '@/utils/is'
  9. import TelephoneFormItem from './TelephoneFormItem'
  10. const AddClient = props => {
  11. const {
  12. reload,
  13. onConfirm,
  14. buttonProps,
  15. dataId,
  16. dataType,
  17. btnTitle = '客户',
  18. defaultValues
  19. } = props
  20. const formRef = useRef(null)
  21. const layout = {
  22. layout: 'horizontal',
  23. labelCol: { flex: '100px' }
  24. }
  25. const [showDataItem, setShowDataItem] = useState(false)
  26. const [validStatusFtl, setValidStatusFtl] = useState('')
  27. return (
  28. <ModalDragForm
  29. {...layout}
  30. formRef={formRef}
  31. modalProps={{ zIndex: 1003, getContainer: false }}
  32. title="添加客户"
  33. onVisibleChange={visible => {
  34. if (visible) {
  35. formRef.current?.setFieldsValue({ ...defaultValues })
  36. }
  37. }}
  38. trigger={
  39. <Button type="primary" {...buttonProps} className="mr-1">
  40. <Plus className="mr-1" />
  41. {btnTitle}
  42. </Button>
  43. }
  44. submitter={{
  45. render: ({ submit }, defaultDoms) => [
  46. ...defaultDoms,
  47. dataId ? (
  48. <Button
  49. type="primary"
  50. key="2"
  51. onClick={() => {
  52. setShowDataItem(true)
  53. const values = {}
  54. if (dataType === ChangeCompMap.BUSINESS.key) {
  55. values.businessId = dataId
  56. }
  57. formRef.current && formRef.current.setFieldsValue(values)
  58. submit()
  59. }}
  60. >
  61. 添加并关联
  62. </Button>
  63. ) : null
  64. ]
  65. }}
  66. onFinish={async values => {
  67. await onConfirm(values)
  68. formRef.current?.resetFields()
  69. setValidStatusFtl('')
  70. !isNullOrUnDef(reload) && reload()
  71. return true
  72. }}
  73. >
  74. {showDataItem ? <ProFormText name={`${dataType}Id`} hidden /> : null}
  75. <ProFormText
  76. name="clientName"
  77. label="姓名"
  78. placeholder="请输入客户名称"
  79. rules={[{ required: true, message: '请输入姓名' }]}
  80. />
  81. <Form.Item
  82. label="客户地区"
  83. name="districtIds"
  84. rules={[{ required: true, message: '请选择地区' }]}
  85. >
  86. <LazyCascader showFooter={true} />
  87. </Form.Item>
  88. <Row>
  89. <Col span={12}>
  90. <ProFormSelect
  91. name="gender"
  92. label="性别"
  93. placeholder=""
  94. rules={[{ message: '请选择性别' }]}
  95. options={[
  96. { label: '男', value: '男' },
  97. { label: '女', value: '女' }
  98. ]}
  99. />
  100. <ProFormText label="部门" name="department" placeholder="" />
  101. <Form.Item
  102. label="手机"
  103. name="telephone"
  104. validateStatus={validStatusFtl}
  105. hasFeedback
  106. rules={[{ required: true, message: '请输入手机号码' }]}
  107. >
  108. <TelephoneFormItem validateFn={status => setValidStatusFtl(status)} />
  109. </Form.Item>
  110. <ProFormText
  111. label="电话"
  112. name="phone"
  113. rules={[{ message: '请输入电话/座机号' }]}
  114. placeholder=""
  115. />
  116. </Col>
  117. <Col span={12}>
  118. <ProFormText label="昵称" name="niceName" placeholder="" />
  119. <ProFormText label="职位" name="position" placeholder="" />
  120. <ProFormText label="QQ" name="qq" placeholder="" />
  121. <ProFormText label="邮箱" name="email" placeholder="" />
  122. </Col>
  123. </Row>
  124. <ProFormText label="办公室" name="office" placeholder="" />
  125. <Row>
  126. <Col span={12}>
  127. <ProFormText label="客户地址" name="address" placeholder="" />
  128. <ProFormText label="客户地标" name="landmarks" placeholder="" />
  129. </Col>
  130. <Col span={12}>
  131. <ProFormText label="客户乘车" name="ride" placeholder="" />
  132. <ProFormText label="客户住宿" name="stay" placeholder="" />
  133. </Col>
  134. </Row>
  135. <ProFormTextArea label="备注" name="mark" placeholder="" />
  136. </ModalDragForm>
  137. )
  138. }
  139. export default AddClient