|
|
@@ -1,7 +1,8 @@
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
import ProTable from '@ant-design/pro-table'
|
|
|
-import useAutoTable from '@/hooks/useAutoTable'
|
|
|
-import { message } from 'antd'
|
|
|
+import useAutoTable, { useTableScroll } from '@/hooks/useAutoTable'
|
|
|
+import { Button, message } from 'antd'
|
|
|
+import { connect } from 'dva'
|
|
|
import consts from '@/consts'
|
|
|
import { queryCompany, apiAddCompany } from '@/services/company'
|
|
|
import LazyCascader from '@/components/LazyCascader'
|
|
|
@@ -9,13 +10,20 @@ import CompanyDetail from '@/pages/Customer/Company/components/CompanyDetail'
|
|
|
import AddCompany from '@/pages/Customer/Company/components/AddCompany'
|
|
|
import { useModal } from '@/components/Modal'
|
|
|
import { formatValues } from '@/components/LazyCascader'
|
|
|
+import PersonLabel from './components/PersonLabel'
|
|
|
+import { TagTypeEnum } from './components/PersonLabel'
|
|
|
+import { TagDataTypeEnum } from './components/PersonLabel'
|
|
|
+import { LabelModeType } from './components/PersonLabel'
|
|
|
+import { IconPark } from '@/components/SvgIcon'
|
|
|
+import { apiBatchLink } from '@/services/customer'
|
|
|
|
|
|
-const Company = () => {
|
|
|
+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 needSubtractHeight = 48 + 48 + 48 + 64 + 24 + 32 // 需要被裁掉的高度
|
|
|
+ // const needSubtractWidth = 48 + 48 + 48 // 需要被裁掉的高度
|
|
|
|
|
|
- const [x, y] = useAutoTable(needSubtractHeight, needSubtractWidth)
|
|
|
+ // const [x, y] = useAutoTable(needSubtractHeight, needSubtractWidth)
|
|
|
|
|
|
const [state, setState] = useState({
|
|
|
data: [],
|
|
|
@@ -51,6 +59,18 @@ const Company = () => {
|
|
|
|
|
|
useEffect(() => {
|
|
|
initData()
|
|
|
+ if (!personTags.length) {
|
|
|
+ dispatch({
|
|
|
+ type: 'company/fetchTags',
|
|
|
+ payload: { tagType: TagTypeEnum.PERSONTAG, tagColumn: TagDataTypeEnum.COMPANY }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (!teamTags.length) {
|
|
|
+ dispatch({
|
|
|
+ type: 'company/fetchTags',
|
|
|
+ payload: { tagType: TagTypeEnum.TEAMTAG, tagColumn: TagDataTypeEnum.COMPANY }
|
|
|
+ })
|
|
|
+ }
|
|
|
}, [])
|
|
|
const handleSearch = value => {
|
|
|
initData({ search: value })
|
|
|
@@ -79,20 +99,40 @@ const Company = () => {
|
|
|
title: '客户名称',
|
|
|
dataIndex: 'companyName',
|
|
|
key: 'companyName',
|
|
|
- width: 320,
|
|
|
+ width: 150,
|
|
|
render: (companyName, record) => <a onClick={() => showDrawer(record.id)}>{companyName}</a>
|
|
|
},
|
|
|
{
|
|
|
title: '地区',
|
|
|
dataIndex: 'local',
|
|
|
key: 'local',
|
|
|
- width: 150
|
|
|
+ width: 100
|
|
|
},
|
|
|
{
|
|
|
title: '个人标签',
|
|
|
dataIndex: 'biaoqian',
|
|
|
key: 'biaoqian',
|
|
|
- width: 80
|
|
|
+ width: 100,
|
|
|
+ render: (_, record) => (
|
|
|
+ <div className="zh-align-center zh-flex-wrap">
|
|
|
+ {record.tagIds.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.tagIds}
|
|
|
+ tagType={TagTypeEnum.PERSONTAG}
|
|
|
+ tagColumn={TagDataTypeEnum.COMPANY}
|
|
|
+ checkCallBack={initData}
|
|
|
+ modeType={LabelModeType.column}>
|
|
|
+ <IconPark type="add" theme="filled" size="20" fill="#868e96" className="zh-pointer" />
|
|
|
+ </PersonLabel>
|
|
|
+ </div>
|
|
|
+ )
|
|
|
},
|
|
|
{
|
|
|
title: '协作标签',
|
|
|
@@ -182,8 +222,45 @@ const Company = () => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+ const [selectKeys, setSelectKeys] = useState([])
|
|
|
+ const hanleRowSelectChange = selectedRowKeys => {
|
|
|
+ setSelectKeys(selectedRowKeys)
|
|
|
+ }
|
|
|
+
|
|
|
+ const [tagState, setTagState] = useState({
|
|
|
+ tagIds: [],
|
|
|
+ tagCooperationIds: []
|
|
|
+ })
|
|
|
+
|
|
|
+ const toolbarOptionsChange = (type, ids) => {
|
|
|
+ setTagState({ ...tagState, [type]: ids })
|
|
|
+ }
|
|
|
+
|
|
|
+ const { getScrollRef } = useTableScroll(columns, selectKeys)
|
|
|
+
|
|
|
+ // 批量设置-确认触发
|
|
|
+ const tagsSettingConfirm = async clientIds => {
|
|
|
+ if (tagState.tagIds.length) {
|
|
|
+ await apiBatchLink({
|
|
|
+ tagIds: tagState.tagIds,
|
|
|
+ dataIds: clientIds,
|
|
|
+ dataType: TagDataTypeEnum.COMPANY,
|
|
|
+ tagType: TagTypeEnum.PERSONTAG
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (tagState.tagCooperationIds.length) {
|
|
|
+ await apiBatchLink({
|
|
|
+ tagIds: tagState.tagIds,
|
|
|
+ dataIds: clientIds,
|
|
|
+ dataType: TagDataTypeEnum.COMPANY,
|
|
|
+ tagType: TagTypeEnum.PERSONTAG
|
|
|
+ })
|
|
|
+ }
|
|
|
+ initData()
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
- <div>
|
|
|
+ <div className="zh-container">
|
|
|
<ProTable
|
|
|
rowKey={record => record.id}
|
|
|
search={false}
|
|
|
@@ -198,7 +275,71 @@ const Company = () => {
|
|
|
<AddCompany onConfirm={handleAddCompany} key="addCompanyBtn" />
|
|
|
]
|
|
|
}}
|
|
|
- scroll={{ x, y }}
|
|
|
+ rowSelection={{
|
|
|
+ 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>
|
|
|
+ )
|
|
|
+ }}
|
|
|
+ scroll={getScrollRef}
|
|
|
columnsStateMap={columnsStateMap}
|
|
|
onColumnsStateChange={map => setColumnsStateMap(map)}
|
|
|
columns={columns}
|
|
|
@@ -213,4 +354,9 @@ const Company = () => {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-export default Company
|
|
|
+export default connect(({ company }) => ({
|
|
|
+ personTagColorMap: company.personTagColorMap,
|
|
|
+ personTags: company.personTags,
|
|
|
+ teamTagColorMap: company.teamTagColorMap,
|
|
|
+ teamTags: company.teamTags
|
|
|
+}))(Company)
|