index.jsx 3.8 KB

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