|
|
@@ -3,43 +3,43 @@ import React, { useState, useEffect } from 'react'
|
|
|
import styles from './index.less'
|
|
|
import { SearchOutlined, CloseOutlined, PlusOutlined } from '@ant-design/icons'
|
|
|
import { useDebounceFn } from 'ahooks'
|
|
|
-import { connect } from 'dva'
|
|
|
+import { useDispatch } from 'dva'
|
|
|
import AddCustomerModal from '../addCustomerModal'
|
|
|
-import { createCustomer } from '@/services/customer'
|
|
|
+import { createCustomer, queryCustomers } from '@/services/customer'
|
|
|
import consts from '@/basic/consts'
|
|
|
import { formatValues } from '@/components/LazyCascader'
|
|
|
+import { apiChangeCustomer } from '@/services/contact'
|
|
|
|
|
|
-const SearchModal = ({ data, total, dispatch }) => {
|
|
|
- const [form] = Form.useForm()
|
|
|
- const initData = payload => {
|
|
|
- dispatch({
|
|
|
- type: 'customer/fetch',
|
|
|
- payload
|
|
|
- })
|
|
|
- }
|
|
|
- useEffect(() => {
|
|
|
- if (!data.length) {
|
|
|
- initData({ page: 1, size: 10 })
|
|
|
- }
|
|
|
- }, [])
|
|
|
+const SearchModal = ({ clientId, onSelect }) => {
|
|
|
+ const dispatch = useDispatch()
|
|
|
const [state, setState] = useState({
|
|
|
+ customer: [],
|
|
|
searchVal: '',
|
|
|
page: 1,
|
|
|
- size: 10
|
|
|
+ size: 10,
|
|
|
+ total: 0
|
|
|
})
|
|
|
+ const initData = async params => {
|
|
|
+ const { data = { customer: [], total: 0 }, code = -1 } = await queryCustomers(params)
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ setState({ ...state, ...data })
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- const [visible, setVisible] = useState(false)
|
|
|
+ useEffect(() => {
|
|
|
+ initData({ page: 1, size: 10 })
|
|
|
+ }, [])
|
|
|
const onChange = e => {
|
|
|
const { value = '' } = e.target || e.currentTarget
|
|
|
initData({ search: value, page: state.page, size: state.size })
|
|
|
}
|
|
|
|
|
|
+ const { run: handleInputChange } = useDebounceFn(onChange)
|
|
|
const closeModal = () => {
|
|
|
dispatch({
|
|
|
type: 'single/changeModal'
|
|
|
})
|
|
|
}
|
|
|
- const { run } = useDebounceFn(onChange)
|
|
|
|
|
|
const addConfirm = async values => {
|
|
|
const payload = formatValues(values)
|
|
|
@@ -49,30 +49,49 @@ const SearchModal = ({ data, total, dispatch }) => {
|
|
|
initData()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 联系人关联客户
|
|
|
+ const connectCustomer = async (customerId, companyName) => {
|
|
|
+ const { code = -1 } = await apiChangeCustomer({ id: clientId, customerId })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ onSelect(companyName)
|
|
|
+ closeModal()
|
|
|
+ }
|
|
|
+ }
|
|
|
return (
|
|
|
<div className={['ant-modal-content', styles.modalContainer].join(' ')}>
|
|
|
<div className={styles.modalHeader}>
|
|
|
<Input
|
|
|
prefix={<SearchOutlined />}
|
|
|
- onChange={run}
|
|
|
className={styles.inputSearch}
|
|
|
placeholder="输入客户名称搜索"
|
|
|
+ onChange={handleInputChange}
|
|
|
/>
|
|
|
<span className={styles.closeIcon}>
|
|
|
<CloseOutlined onClick={closeModal} />
|
|
|
</span>
|
|
|
</div>
|
|
|
<div className={styles.modalContent}>
|
|
|
- <span>11</span>
|
|
|
+ {state.customer.map(item => (
|
|
|
+ <div key={item.id} className={styles.card}>
|
|
|
+ <div className="zh-flex-sub">{item.companyName}</div>
|
|
|
+ <div className="zh-flex-sub zh-justify-between">
|
|
|
+ <span>{item.local}</span>
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ size="small"
|
|
|
+ onClick={() => connectCustomer(item.id, item.companyName)}>
|
|
|
+ 关联
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
</div>
|
|
|
<div className={styles.modalFooter}>
|
|
|
- <AddCustomerModal />
|
|
|
+ <AddCustomerModal onConfirm={addConfirm} />
|
|
|
</div>
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-export default connect(({ customer }) => ({
|
|
|
- data: customer.customer,
|
|
|
- total: customer.total
|
|
|
-}))(SearchModal)
|
|
|
+export default SearchModal
|