|
@@ -0,0 +1,91 @@
|
|
|
|
|
+import { Input, Form, Button } from 'antd'
|
|
|
|
|
+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 AddCustomerModal from '../addCustomerModal'
|
|
|
|
|
+import { createCustomer } from '@/services/customer'
|
|
|
|
|
+import consts from '@/basic/consts'
|
|
|
|
|
+import { formatValues } from '@/components/LazyCascader'
|
|
|
|
|
+
|
|
|
|
|
+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 [state, setState] = useState({
|
|
|
|
|
+ searchVal: '',
|
|
|
|
|
+ page: 1,
|
|
|
|
|
+ size: 10
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const [visible, setVisible] = useState(false)
|
|
|
|
|
+ const onChange = e => {
|
|
|
|
|
+ const { value = '' } = e.target || e.currentTarget
|
|
|
|
|
+ initData({ search: value, page: state.page, size: state.size })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const closeModal = () => {
|
|
|
|
|
+ dispatch({
|
|
|
|
|
+ type: 'single/changeModal'
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ const { run } = useDebounceFn(onChange)
|
|
|
|
|
+
|
|
|
|
|
+ const addConfirm = async values => {
|
|
|
|
|
+ const payload = formatValues(values)
|
|
|
|
|
+
|
|
|
|
|
+ const { code = -1 } = await createCustomer(payload)
|
|
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
|
|
+ initData()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return (
|
|
|
|
|
+ <div className={['ant-modal-content', styles.modalContainer].join(' ')}>
|
|
|
|
|
+ <div className={styles.modalHeader}>
|
|
|
|
|
+ <Input
|
|
|
|
|
+ prefix={<SearchOutlined />}
|
|
|
|
|
+ onChange={run}
|
|
|
|
|
+ className={styles.inputSearch}
|
|
|
|
|
+ placeholder="输入客户名称搜索"
|
|
|
|
|
+ />
|
|
|
|
|
+ <span className={styles.closeIcon}>
|
|
|
|
|
+ <CloseOutlined onClick={closeModal} />
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className={styles.modalContent}>
|
|
|
|
|
+ <span>11</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className={styles.modalFooter}>
|
|
|
|
|
+ <Button prefix={<PlusOutlined />} type="primary" onClick={() => setVisible(true)}>
|
|
|
|
|
+ 添加新客户
|
|
|
|
|
+ </Button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <AddCustomerModal
|
|
|
|
|
+ visible={visible}
|
|
|
|
|
+ title="添加新客户"
|
|
|
|
|
+ onCancel={() => setVisible(false)}
|
|
|
|
|
+ onOk={() => {
|
|
|
|
|
+ form.validateFields().then(values => {
|
|
|
|
|
+ form.resetFields()
|
|
|
|
|
+ addConfirm(values)
|
|
|
|
|
+ })
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ )
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+export default connect(({ customer }) => ({
|
|
|
|
|
+ data: customer.customer,
|
|
|
|
|
+ total: customer.total
|
|
|
|
|
+}))(SearchModal)
|