|
|
@@ -1,25 +1,17 @@
|
|
|
import React, { useRef, useState, useEffect } from 'react'
|
|
|
-import { Form, Row, Col, Button } from 'antd'
|
|
|
+import { Form, Row, Col, Button, Modal } from 'antd'
|
|
|
import LazyCascader from '@/components/LazyCascader'
|
|
|
import { ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
|
|
|
-import { Plus } from '@icon-park/react'
|
|
|
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'
|
|
|
import TelephoneFormItem from './TelephoneFormItem'
|
|
|
+import consts from '@/consts'
|
|
|
|
|
|
const AddClient = props => {
|
|
|
- const {
|
|
|
- reload,
|
|
|
- onConfirm,
|
|
|
- buttonProps,
|
|
|
- dataId,
|
|
|
- dataType,
|
|
|
- btnTitle = '客户',
|
|
|
- defaultValues,
|
|
|
- sourceList
|
|
|
- } = props
|
|
|
+ const { visible, onCancel, reload, onConfirm, dataId, dataType, defaultValues, sourceList } =
|
|
|
+ props
|
|
|
+
|
|
|
const formRef = useRef(null)
|
|
|
const layout = {
|
|
|
layout: 'horizontal',
|
|
|
@@ -37,7 +29,6 @@ const AddClient = props => {
|
|
|
}, [])
|
|
|
|
|
|
const handleChange = changedValues => {
|
|
|
- // const clientName = formRef.current?.getFieldValue('clientName')
|
|
|
if (!changedValues) return
|
|
|
if ('clientName' in changedValues) {
|
|
|
if (!changedValues.clientName || changedValues.clientName?.length === 1) {
|
|
|
@@ -55,41 +46,37 @@ const AddClient = props => {
|
|
|
}
|
|
|
formRef.current?.setFieldsValue({ email: `${changedValues.qq}@qq.com` })
|
|
|
}
|
|
|
- // const clientName = formRef.current?.getFieldValue('clientName')
|
|
|
- // if (clientName) {
|
|
|
- // const clientNameNum = clientName.split('')
|
|
|
- // const [firstName, ...lastName] = clientNameNum
|
|
|
- // const nameAfter = `(${lastName.join('')})`
|
|
|
- // const newClientName = `${firstName + nameAfter}工`
|
|
|
- // formRef.current?.setFieldsValue({ niceName: newClientName })
|
|
|
- // } else if (!formRef.current?.getFieldValue('qq')) {
|
|
|
- // const emailNum = qq.value
|
|
|
- // const newEmail = `${emailNum}@qq.com`
|
|
|
- // formRef.current?.setFieldsValue({ email: newEmail })
|
|
|
- // }
|
|
|
}
|
|
|
+
|
|
|
+ const handleOnOk = () => {
|
|
|
+ formRef.current?.validateFields().then(async values => {
|
|
|
+ try {
|
|
|
+ await onConfirm(values)
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ formRef.current?.resetFields()
|
|
|
+ setValidStatusFtl('')
|
|
|
+ !isNullOrUnDef(reload) && reload()
|
|
|
+ onCancel()
|
|
|
+ }
|
|
|
+ } catch (error) {}
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
- <ModalDragForm
|
|
|
- {...layout}
|
|
|
- formRef={formRef}
|
|
|
- modalProps={{ zIndex: 1003, getContainer: false }}
|
|
|
+ <Modal
|
|
|
+ width="42vw"
|
|
|
+ visible={visible}
|
|
|
+ onCancel={onCancel}
|
|
|
title="添加客户"
|
|
|
- onVisibleChange={visible => {
|
|
|
- if (visible) {
|
|
|
- formRef.current?.setFieldsValue({ ...defaultValues })
|
|
|
- }
|
|
|
- }}
|
|
|
- onValuesChange={handleChange}
|
|
|
- trigger={
|
|
|
- <Button type="primary" {...buttonProps} className="mr-1">
|
|
|
- <Plus className="mr-1" />
|
|
|
- {btnTitle}
|
|
|
- </Button>
|
|
|
- }
|
|
|
- submitter={{
|
|
|
- render: ({ submit }, defaultDoms) => [
|
|
|
- ...defaultDoms,
|
|
|
- dataId ? (
|
|
|
+ footer={
|
|
|
+ <div>
|
|
|
+ <Button type="default" className="ml-2" onClick={onCancel}>
|
|
|
+ 取消
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={handleOnOk}>
|
|
|
+ 确认
|
|
|
+ </Button>
|
|
|
+ {dataId ? (
|
|
|
<Button
|
|
|
type="primary"
|
|
|
key="2"
|
|
|
@@ -99,116 +86,101 @@ const AddClient = props => {
|
|
|
if (dataType === ChangeCompMap.BUSINESS.key) {
|
|
|
values.businessId = dataId
|
|
|
}
|
|
|
- formRef.current && formRef.current.setFieldsValue(values)
|
|
|
- submit()
|
|
|
- }}>
|
|
|
+ formRef.current?.setFieldsValue(values)
|
|
|
+ handleOnOk()
|
|
|
+ }}
|
|
|
+ >
|
|
|
添加并关联
|
|
|
</Button>
|
|
|
- ) : null
|
|
|
- ]
|
|
|
- }}
|
|
|
- onFinish={async values => {
|
|
|
- await onConfirm(values)
|
|
|
- formRef.current?.resetFields()
|
|
|
- setValidStatusFtl('')
|
|
|
- !isNullOrUnDef(reload) && reload()
|
|
|
- return true
|
|
|
- }}>
|
|
|
- {showDataItem ? <ProFormText name={`${dataType}Id`} hidden /> : null}
|
|
|
- <ProFormText
|
|
|
- name="clientName"
|
|
|
- label="姓名"
|
|
|
- placeholder="请输入客户名称"
|
|
|
- rules={[{ required: true, message: '请输入姓名' }]}
|
|
|
- />
|
|
|
- <Form.Item
|
|
|
- label="客户地区"
|
|
|
- name="districtIds"
|
|
|
- rules={[{ required: true, message: '请选择地区' }]}>
|
|
|
- <LazyCascader showFooter={true} />
|
|
|
- </Form.Item>
|
|
|
- <Row>
|
|
|
- <Col span={12}>
|
|
|
- <ProFormSelect
|
|
|
- name="gender"
|
|
|
- label="性别"
|
|
|
- placeholder=""
|
|
|
- rules={[{ message: '请选择性别' }]}
|
|
|
- options={[
|
|
|
- { label: '男', value: '男' },
|
|
|
- { label: '女', value: '女' }
|
|
|
- ]}
|
|
|
- />
|
|
|
- <ProFormText label="部门" name="department" placeholder="" />
|
|
|
+ ) : null}
|
|
|
+ </div>
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <Form
|
|
|
+ {...layout}
|
|
|
+ formRef={formRef}
|
|
|
+ onValuesChange={handleChange}
|
|
|
+ initialValues={defaultValues}
|
|
|
+ >
|
|
|
+ {showDataItem ? <ProFormText name={`${dataType}Id`} hidden /> : null}
|
|
|
+ <ProFormText
|
|
|
+ name="clientName"
|
|
|
+ label="姓名"
|
|
|
+ placeholder="请输入客户名称"
|
|
|
+ rules={[{ required: true, message: '请输入姓名' }]}
|
|
|
+ />
|
|
|
+ <Form.Item
|
|
|
+ label="客户地区"
|
|
|
+ name="districtIds"
|
|
|
+ rules={[{ required: true, message: '请选择地区' }]}
|
|
|
+ >
|
|
|
+ <LazyCascader showFooter={true} />
|
|
|
+ </Form.Item>
|
|
|
+ <Row>
|
|
|
+ <Col span={12}>
|
|
|
+ <ProFormSelect
|
|
|
+ name="gender"
|
|
|
+ label="性别"
|
|
|
+ placeholder=""
|
|
|
+ rules={[{ message: '请选择性别' }]}
|
|
|
+ options={[
|
|
|
+ { label: '男', value: '男' },
|
|
|
+ { label: '女', value: '女' }
|
|
|
+ ]}
|
|
|
+ />
|
|
|
+ <ProFormText label="部门" name="department" placeholder="" />
|
|
|
|
|
|
- <Form.Item
|
|
|
- label="手机"
|
|
|
- name="telephone"
|
|
|
- validateStatus={validStatusFtl}
|
|
|
- hasFeedback
|
|
|
- rules={[{ required: true, message: '请输入手机号码' }]}>
|
|
|
- <TelephoneFormItem validateFn={status => setValidStatusFtl(status)} />
|
|
|
- </Form.Item>
|
|
|
- <ProFormText
|
|
|
- label="电话"
|
|
|
- name="phone"
|
|
|
- rules={[{ message: '请输入电话/座机号' }]}
|
|
|
- placeholder=""
|
|
|
- />
|
|
|
- </Col>
|
|
|
- <Col span={12}>
|
|
|
- <ProFormText label="昵称" name="niceName" placeholder="" />
|
|
|
- {/* <ProFormDependency name={['clientName']}>
|
|
|
- {({ clientName, newClientName }) => {
|
|
|
- if (!clientName === false) {
|
|
|
- const clientNameNum = clientName.split('')
|
|
|
- const [firstName, ...lastName] = clientNameNum
|
|
|
- const nameAfter = `(${lastName.join('')})`
|
|
|
- // eslint-disable-next-line no-param-reassign
|
|
|
- newClientName = `${firstName + nameAfter}工`
|
|
|
- }
|
|
|
- return (
|
|
|
- <ProFormText
|
|
|
- label="昵称"
|
|
|
- name="niceName"
|
|
|
- placeholder=""
|
|
|
- value={`${newClientName || ''}`}
|
|
|
- />
|
|
|
- )
|
|
|
- }}
|
|
|
- </ProFormDependency> */}
|
|
|
- <ProFormText label="职位" name="position" placeholder="" />
|
|
|
- <ProFormText label="QQ" name="qq" placeholder="" />
|
|
|
- <ProFormText label="邮箱" name="email" placeholder="" />
|
|
|
- </Col>
|
|
|
- </Row>
|
|
|
- <Row>
|
|
|
- <Col span={12}>
|
|
|
- <ProFormText label="办公室" name="office" placeholder="" />
|
|
|
- </Col>
|
|
|
- <Col span={12}>
|
|
|
- <ProFormSelect
|
|
|
- name="sourceId"
|
|
|
- label="来源"
|
|
|
- placeholder=""
|
|
|
- rules={[{ message: '来源' }]}
|
|
|
- options={sourceList}
|
|
|
- />
|
|
|
- </Col>
|
|
|
- </Row>
|
|
|
- <Row>
|
|
|
- <Col span={12}>
|
|
|
- <ProFormText label="客户地址" name="address" placeholder="" />
|
|
|
- <ProFormText label="客户地标" name="landmarks" placeholder="" />
|
|
|
- </Col>
|
|
|
- <Col span={12}>
|
|
|
- <ProFormText label="客户乘车" name="ride" placeholder="" />
|
|
|
- <ProFormText label="客户住宿" name="stay" placeholder="" />
|
|
|
- </Col>
|
|
|
- </Row>
|
|
|
+ <Form.Item
|
|
|
+ label="手机"
|
|
|
+ name="telephone"
|
|
|
+ validateStatus={validStatusFtl}
|
|
|
+ hasFeedback
|
|
|
+ rules={[{ required: true, message: '请输入手机号码' }]}
|
|
|
+ >
|
|
|
+ <TelephoneFormItem validateFn={status => setValidStatusFtl(status)} />
|
|
|
+ </Form.Item>
|
|
|
+ <ProFormText
|
|
|
+ label="电话"
|
|
|
+ name="phone"
|
|
|
+ rules={[{ message: '请输入电话/座机号' }]}
|
|
|
+ placeholder=""
|
|
|
+ />
|
|
|
+ </Col>
|
|
|
+ <Col span={12}>
|
|
|
+ <ProFormText label="昵称" name="niceName" placeholder="" />
|
|
|
+ <ProFormText label="职位" name="position" placeholder="" />
|
|
|
+ <ProFormText label="QQ" name="qq" placeholder="" />
|
|
|
+ <ProFormText label="邮箱" name="email" placeholder="" />
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ <Row>
|
|
|
+ <Col span={12}>
|
|
|
+ <ProFormText label="办公室" name="office" placeholder="" />
|
|
|
+ </Col>
|
|
|
+ <Col span={12}>
|
|
|
+ <ProFormSelect
|
|
|
+ name="sourceId"
|
|
|
+ label="来源"
|
|
|
+ placeholder=""
|
|
|
+ rules={[{ message: '来源' }]}
|
|
|
+ options={sourceList}
|
|
|
+ />
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
+ <Row>
|
|
|
+ <Col span={12}>
|
|
|
+ <ProFormText label="客户地址" name="address" placeholder="" />
|
|
|
+ <ProFormText label="客户地标" name="landmarks" placeholder="" />
|
|
|
+ </Col>
|
|
|
+ <Col span={12}>
|
|
|
+ <ProFormText label="客户乘车" name="ride" placeholder="" />
|
|
|
+ <ProFormText label="客户住宿" name="stay" placeholder="" />
|
|
|
+ </Col>
|
|
|
+ </Row>
|
|
|
|
|
|
- <ProFormTextArea label="备注" name="mark" placeholder="" />
|
|
|
- </ModalDragForm>
|
|
|
+ <ProFormTextArea label="备注" name="mark" placeholder="" />
|
|
|
+ </Form>
|
|
|
+ </Modal>
|
|
|
)
|
|
|
}
|
|
|
|