|
|
@@ -1,6 +1,6 @@
|
|
|
-import React, { useState, useEffect } from 'react'
|
|
|
+import React, { useState, useEffect, useRef, useMemo } from 'react'
|
|
|
import ProTable from '@ant-design/pro-table'
|
|
|
-import useAutoTable, { useTableScroll } from '@/hooks/useAutoTable'
|
|
|
+import { useTableScroll } from '@/hooks/useAutoTable'
|
|
|
import { Button, message } from 'antd'
|
|
|
import { connect } from 'dva'
|
|
|
import consts from '@/consts'
|
|
|
@@ -20,45 +20,59 @@ import { apiBatchLink } from '@/services/customer'
|
|
|
const Company = props => {
|
|
|
const { personTagColorMap, teamTagColorMap, personTags, teamTags, dispatch } = props
|
|
|
const { toggleDrawer, setDrawerProps } = useModal()
|
|
|
- // const needSubtractHeight = 48 + 48 + 48 + 64 + 24 + 32 // 需要被裁掉的高度
|
|
|
- // const needSubtractWidth = 48 + 48 + 48 // 需要被裁掉的高度
|
|
|
+ const tRef = useRef(null)
|
|
|
+ const [selectKeys, setSelectKeys] = useState([])
|
|
|
+
|
|
|
+ const [tagState, setTagState] = useState({
|
|
|
+ tagIds: [],
|
|
|
+ tagCooperationIds: []
|
|
|
+ })
|
|
|
+ const tag = useMemo(() => {
|
|
|
+ const personTagMap = {}
|
|
|
+ const teamTagMap = {}
|
|
|
+ personTags.forEach(item => {
|
|
|
+ personTagMap[item.id] = { text: item.name }
|
|
|
+ })
|
|
|
+ teamTags.forEach(item => {
|
|
|
+ teamTagMap[item.id] = { text: item.name }
|
|
|
+ })
|
|
|
|
|
|
- // const [x, y] = useAutoTable(needSubtractHeight, needSubtractWidth)
|
|
|
+ return { personTagMap, teamTagMap }
|
|
|
+ }, [personTags, teamTags])
|
|
|
|
|
|
const [state, setState] = useState({
|
|
|
- data: [],
|
|
|
- total: 0,
|
|
|
id: '',
|
|
|
+ params: {},
|
|
|
visible: false
|
|
|
})
|
|
|
const [addCompany, setAddCompany] = useState({
|
|
|
visible: false,
|
|
|
loading: false
|
|
|
})
|
|
|
- const initData = async payload => {
|
|
|
- const {
|
|
|
- code = -1,
|
|
|
- data: { customer = [], total = 0 } = { customer: [], total: 0 }
|
|
|
- } = await queryCompany(payload)
|
|
|
- if (code === consts.RET_CODE.SUCCESS) {
|
|
|
- setState({ ...state, data: customer, total })
|
|
|
- }
|
|
|
+
|
|
|
+ // 重置到默认值,包括表单
|
|
|
+ const initData = () => {
|
|
|
+ tRef.current.reset()
|
|
|
}
|
|
|
+
|
|
|
+ // 刷新
|
|
|
+ const refreshData = () => {
|
|
|
+ tRef.current.reload()
|
|
|
+ }
|
|
|
+
|
|
|
const handleAddCompany = async values => {
|
|
|
setAddCompany({ ...addCompany, loading: true })
|
|
|
const params = formatValues(values)
|
|
|
const { code = -1 } = await apiAddCompany(params)
|
|
|
if (code === consts.RET_CODE.SUCCESS) {
|
|
|
message.success('新增成功')
|
|
|
- setState({ ...state, data: values })
|
|
|
}
|
|
|
// 请求完了
|
|
|
setAddCompany({ ...addCompany, loading: false, visible: false })
|
|
|
- await initData()
|
|
|
+ initData()
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
|
- initData()
|
|
|
if (!personTags.length) {
|
|
|
dispatch({
|
|
|
type: 'company/fetchTags',
|
|
|
@@ -73,11 +87,11 @@ const Company = props => {
|
|
|
}
|
|
|
}, [])
|
|
|
const handleSearch = value => {
|
|
|
- initData({ search: value })
|
|
|
+ setState({ ...state, params: { ...state.params, search: value, current: 1 } })
|
|
|
}
|
|
|
const onDistrictChange = value => {
|
|
|
const [province = '', city = '', area = ''] = value
|
|
|
- initData({ province, city, area })
|
|
|
+ setState({ ...state, params: { ...state.params, current: 1, province, city, area } })
|
|
|
}
|
|
|
|
|
|
// 展示drawer
|
|
|
@@ -113,6 +127,7 @@ const Company = props => {
|
|
|
dataIndex: 'biaoqian',
|
|
|
key: 'biaoqian',
|
|
|
width: 100,
|
|
|
+ valueEnum: tag.personTagMap,
|
|
|
render: (_, record) => (
|
|
|
<div className="zh-align-center zh-flex-wrap">
|
|
|
{record.tagIds.map(item => (
|
|
|
@@ -127,39 +142,40 @@ const Company = props => {
|
|
|
tagIds={record.tagIds}
|
|
|
tagType={TagTypeEnum.PERSONTAG}
|
|
|
tagColumn={TagDataTypeEnum.COMPANY}
|
|
|
- checkCallBack={initData}
|
|
|
+ checkCallBack={refreshData}
|
|
|
+ modeType={LabelModeType.column}>
|
|
|
+ <IconPark type="add" theme="filled" size="20" fill="#868e96" className="zh-pointer" />
|
|
|
+ </PersonLabel>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '协作标签',
|
|
|
+ dataIndex: 'tagCooperationIds',
|
|
|
+ key: 'tagCooperationIds',
|
|
|
+ width: 80,
|
|
|
+ valueEnum: tag.teamTagMap,
|
|
|
+ render: (_, record) => (
|
|
|
+ <div className="zh-align-center zh-flex-wrap">
|
|
|
+ {record.tagCooperationIds.map(item => (
|
|
|
+ <span
|
|
|
+ key={record.id + item}
|
|
|
+ className="zh-circle-icon zh-mg-right-3"
|
|
|
+ style={{ backgroundColor: personTagColorMap[item] }}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
+ <PersonLabel
|
|
|
+ dataId={record.id}
|
|
|
+ tagIds={record.tagCooperationIds}
|
|
|
+ tagType={TagTypeEnum.TEAM}
|
|
|
+ tagColumn={TagDataTypeEnum.COMPANY}
|
|
|
+ checkCallBack={refreshData}
|
|
|
modeType={LabelModeType.column}>
|
|
|
<IconPark type="add" theme="filled" size="20" fill="#868e96" className="zh-pointer" />
|
|
|
</PersonLabel>
|
|
|
</div>
|
|
|
)
|
|
|
},
|
|
|
- // {
|
|
|
- // title: '协作标签',
|
|
|
- // dataIndex: 'tagCooperationIds',
|
|
|
- // key: 'tagCooperationIds',
|
|
|
- // width: 80,
|
|
|
- // render: (_, record) => (
|
|
|
- // <div className="zh-align-center zh-flex-wrap">
|
|
|
- // {record.tagCooperationIds.map(item => (
|
|
|
- // <span
|
|
|
- // key={record.id + item}
|
|
|
- // className="zh-circle-icon zh-mg-right-3"
|
|
|
- // style={{ backgroundColor: personTagColorMap[item] }}
|
|
|
- // />
|
|
|
- // ))}
|
|
|
- // <PersonLabel
|
|
|
- // dataId={record.id}
|
|
|
- // tagIds={record.tagCooperationIds}
|
|
|
- // tagType={TagTypeEnum.TEAM}
|
|
|
- // tagColumn={TagDataTypeEnum.COMPANY}
|
|
|
- // checkCallBack={initData}
|
|
|
- // modeType={LabelModeType.column}>
|
|
|
- // <IconPark type="add" theme="filled" size="20" fill="#868e96" className="zh-pointer" />
|
|
|
- // </PersonLabel>
|
|
|
- // </div>
|
|
|
- // )
|
|
|
- // },
|
|
|
{
|
|
|
title: '联系人',
|
|
|
dataIndex: 'clientTotal',
|
|
|
@@ -242,16 +258,10 @@ const Company = props => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- const [selectKeys, setSelectKeys] = useState([])
|
|
|
const hanleRowSelectChange = selectedRowKeys => {
|
|
|
setSelectKeys(selectedRowKeys)
|
|
|
}
|
|
|
|
|
|
- const [tagState, setTagState] = useState({
|
|
|
- tagIds: [],
|
|
|
- tagCooperationIds: []
|
|
|
- })
|
|
|
-
|
|
|
const toolbarOptionsChange = (type, ids) => {
|
|
|
setTagState({ ...tagState, [type]: ids })
|
|
|
}
|
|
|
@@ -276,7 +286,68 @@ const Company = props => {
|
|
|
tagType: TagTypeEnum.PERSONTAG
|
|
|
})
|
|
|
}
|
|
|
- initData()
|
|
|
+ refreshData()
|
|
|
+ }
|
|
|
+
|
|
|
+ const renderTableAlert = ({ selectedRowKeys }) => {
|
|
|
+ return (
|
|
|
+ <div className="zh-flex-row">
|
|
|
+ <div className="zh-mg-right-5">
|
|
|
+ <PersonLabel
|
|
|
+ tagType={TagTypeEnum.PERSONTAG}
|
|
|
+ tagColumn={TagDataTypeEnum.COMPANY}
|
|
|
+ checkCallBack={toolbarOptionsChange}
|
|
|
+ modeType={LabelModeType.toolbar}>
|
|
|
+ {tagState.tagIds.length ? (
|
|
|
+ <Button>
|
|
|
+ {tagState.tagIds.map(item => (
|
|
|
+ <span
|
|
|
+ key={item}
|
|
|
+ className="zh-circle-icon zh-mg-right-3"
|
|
|
+ style={{ backgroundColor: personTagColorMap[item] }}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
+ <IconPark type="down" />
|
|
|
+ </Button>
|
|
|
+ ) : (
|
|
|
+ <Button>
|
|
|
+ 个人标签
|
|
|
+ <IconPark type="down" />
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
+ </PersonLabel>
|
|
|
+ </div>
|
|
|
+ <div className="zh-mg-right-5">
|
|
|
+ <PersonLabel
|
|
|
+ tagType={TagTypeEnum.TEAMTAG}
|
|
|
+ tagColumn={TagDataTypeEnum.COMPANY}
|
|
|
+ checkCallBack={toolbarOptionsChange}
|
|
|
+ modeType={LabelModeType.toolbar}>
|
|
|
+ {tagState.tagCooperationIds.length ? (
|
|
|
+ <Button>
|
|
|
+ {tagState.tagCooperationIds.map(item => (
|
|
|
+ <span
|
|
|
+ key={item}
|
|
|
+ className="zh-square-icon zh-mg-right-3"
|
|
|
+ style={{ backgroundColor: teamTagColorMap[item] }}
|
|
|
+ />
|
|
|
+ ))}
|
|
|
+ <IconPark type="down" />
|
|
|
+ </Button>
|
|
|
+ ) : (
|
|
|
+ <Button>
|
|
|
+ 协作标签
|
|
|
+ <IconPark type="down" />
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
+ </PersonLabel>
|
|
|
+ </div>
|
|
|
+ <Button onClick={() => tagsSettingConfirm(selectedRowKeys)}>
|
|
|
+ <IconPark type="check" size={14} />
|
|
|
+ 确认
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
@@ -284,10 +355,24 @@ const Company = props => {
|
|
|
<ProTable
|
|
|
rowKey={record => record.id}
|
|
|
search={false}
|
|
|
+ actionRef={tRef}
|
|
|
+ params={state.params}
|
|
|
+ request={async (params, sort, filter) => {
|
|
|
+ const {
|
|
|
+ code = -1,
|
|
|
+ data: { customer = [], total = 0 } = { customer: [], total: 0 }
|
|
|
+ } = await queryCompany({ ...params, ...sort, ...filter })
|
|
|
+ return {
|
|
|
+ data: customer,
|
|
|
+ success: code === consts.RET_CODE.SUCCESS,
|
|
|
+ total
|
|
|
+ }
|
|
|
+ }}
|
|
|
headerTitle="客户"
|
|
|
bordered
|
|
|
toolbar={{
|
|
|
search: {
|
|
|
+ allowClear: true,
|
|
|
onSearch: handleSearch
|
|
|
},
|
|
|
actions: [
|
|
|
@@ -299,76 +384,11 @@ const Company = props => {
|
|
|
onChange: hanleRowSelectChange,
|
|
|
type: 'checkbox'
|
|
|
}}
|
|
|
- tableAlertRender={({ selectedRowKeys }) => {
|
|
|
- return (
|
|
|
- <div className="zh-flex-row">
|
|
|
- <div className="zh-mg-right-5">
|
|
|
- <PersonLabel
|
|
|
- tagType={TagTypeEnum.PERSONTAG}
|
|
|
- tagColumn={TagDataTypeEnum.COMPANY}
|
|
|
- checkCallBack={toolbarOptionsChange}
|
|
|
- modeType={LabelModeType.toolbar}>
|
|
|
- {tagState.tagIds.length ? (
|
|
|
- <Button>
|
|
|
- {tagState.tagIds.map(item => (
|
|
|
- <span
|
|
|
- key={item}
|
|
|
- className="zh-circle-icon zh-mg-right-3"
|
|
|
- style={{ backgroundColor: personTagColorMap[item] }}
|
|
|
- />
|
|
|
- ))}
|
|
|
- <IconPark type="down" />
|
|
|
- </Button>
|
|
|
- ) : (
|
|
|
- <Button>
|
|
|
- 个人标签
|
|
|
- <IconPark type="down" />
|
|
|
- </Button>
|
|
|
- )}
|
|
|
- </PersonLabel>
|
|
|
- </div>
|
|
|
- {/* <div className="zh-mg-right-5">
|
|
|
- <PersonLabel
|
|
|
- tagType={TagTypeEnum.TEAMTAG}
|
|
|
- tagColumn={TagDataTypeEnum.COMPANY}
|
|
|
- checkCallBack={toolbarOptionsChange}
|
|
|
- modeType={LabelModeType.toolbar}>
|
|
|
- {tagState.tagCooperationIds.length ? (
|
|
|
- <Button>
|
|
|
- {tagState.tagCooperationIds.map(item => (
|
|
|
- <span
|
|
|
- key={item}
|
|
|
- className="zh-square-icon zh-mg-right-3"
|
|
|
- style={{ backgroundColor: teamTagColorMap[item] }}
|
|
|
- />
|
|
|
- ))}
|
|
|
- <IconPark type="down" />
|
|
|
- </Button>
|
|
|
- ) : (
|
|
|
- <Button>
|
|
|
- 协作标签
|
|
|
- <IconPark type="down" />
|
|
|
- </Button>
|
|
|
- )}
|
|
|
- </PersonLabel>
|
|
|
- </div> */}
|
|
|
- <Button onClick={() => tagsSettingConfirm(selectedRowKeys)}>
|
|
|
- <IconPark type="check" size={14} />
|
|
|
- 确认
|
|
|
- </Button>
|
|
|
- </div>
|
|
|
- )
|
|
|
- }}
|
|
|
+ tableAlertRender={renderTableAlert}
|
|
|
scroll={getScrollRef}
|
|
|
columnsStateMap={columnsStateMap}
|
|
|
onColumnsStateChange={map => setColumnsStateMap(map)}
|
|
|
columns={columns}
|
|
|
- dataSource={state.data}
|
|
|
- pagination={{
|
|
|
- pageSize: consts.PAGE_SIZE,
|
|
|
- total: state.total,
|
|
|
- onChange: (page, size) => initData({ page, size })
|
|
|
- }}
|
|
|
/>
|
|
|
</div>
|
|
|
)
|