index.jsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React, { useState, useRef, useEffect } from 'react'
  2. import { Form, Row, Col, Button } from 'antd'
  3. import { validCascaderRule } from '@/components/LazyCascader'
  4. import LazyCascader from '@/components/LazyCascader'
  5. import { ModalForm, ProFormText, ProFormCheckbox } from '@ant-design/pro-form'
  6. import { PlusOutlined } from '@ant-design/icons'
  7. import { connect } from 'dva'
  8. import { ChangeCompMap } from '../ChangeCompany'
  9. const AddCustomerModal = ({ dataId, dataType, onConfirm, dispatch, natures }) => {
  10. const formRef = useRef()
  11. const [modalVisible, setModalVisible] = useState(false)
  12. const layout = {
  13. layout: 'horizontal',
  14. labelCol: { flex: '100px' }
  15. }
  16. useEffect(() => {
  17. const getNatures = () => {
  18. dispatch({
  19. type: 'customer/fetch'
  20. })
  21. }
  22. !natures.length && getNatures()
  23. }, [])
  24. const [showDataItem, setShowDataItem] = useState(false)
  25. return (
  26. <ModalForm
  27. formRef={formRef}
  28. title="添加新客户"
  29. {...layout}
  30. visible={modalVisible}
  31. onVisibleChange={setModalVisible}
  32. submitter={{
  33. render: ({ submit }, defaultDoms) => [
  34. ...defaultDoms,
  35. <Button
  36. type="primary"
  37. key="2"
  38. onClick={() => {
  39. setShowDataItem(true)
  40. const values = {}
  41. if (dataType === ChangeCompMap.CLIENT.key) {
  42. values.clientId = dataId
  43. }
  44. if (dataType === ChangeCompMap.BUSINESS.key) {
  45. values.businessId = dataId
  46. }
  47. formRef.current && formRef.current.setFieldsValue(values)
  48. submit()
  49. }}>
  50. 添加并关联
  51. </Button>
  52. ]
  53. }}
  54. trigger={
  55. <Button prefix={<PlusOutlined />} onClick={() => setModalVisible(true)} type="primary">
  56. 添加新客户
  57. </Button>
  58. }
  59. onFinish={async values => {
  60. await onConfirm(values)
  61. return true
  62. }}>
  63. <ProFormText
  64. name="companyName"
  65. label="客户名称"
  66. placeholder="请输入客户全称"
  67. rules={[{ required: true, message: '请输入客户全称' }]}
  68. />
  69. {showDataItem ? <ProFormText name={`${dataType}Id`} hidden /> : null}
  70. <Form.Item
  71. name="district"
  72. label="客户地区"
  73. required={true}
  74. rules={[{ validator: validCascaderRule }]}>
  75. <LazyCascader />
  76. </Form.Item>
  77. <ProFormCheckbox.Group name="natureIds" label="客户性质" options={natures} />
  78. <ProFormText name="address" label="客户地址" placeholder="" rules={[{ required: true }]} />
  79. <Row>
  80. <Col span={12}>
  81. <ProFormText name="fax" label="客户传真" placeholder="" />
  82. <ProFormText name="ride" label="乘车路线" placeholder="" />
  83. <ProFormText name="stay" label="参考住宿" placeholder="" />
  84. </Col>
  85. <Col span={12}>
  86. <ProFormText name="webservice" label="网址" placeholder="" />
  87. <ProFormText name="landmarks" label="地标建筑" placeholder="" />
  88. <ProFormText name="remarks" label="备注" placeholder="" />
  89. </Col>
  90. </Row>
  91. </ModalForm>
  92. )
  93. }
  94. export default connect(({ customer }) => ({
  95. natures: customer.natures
  96. }))(AddCustomerModal)