import { Input, Button, message, Tooltip } from 'antd'
import { connect, useAccess, useModel } from 'umi'
import React, { useEffect, useState, useRef, useMemo } from 'react'
import consts from '@/consts'
import LazyCascader, { formatValues } from '@/components/LazyCascader'
import PersonLabel from '../Company/components/PersonLabel'
import { TagTypeEnum, TagDataTypeEnum, LabelModeType } from '../Company/components/PersonLabel/const'
import { Add, Down, Check } from '@icon-park/react'
import { apiAddClient, queryClient } from '@/services/customer'
import { apiBatchLink } from '@/services/customer'
import styles from './index.less'
import { generateFilterField, generateSortField } from '@/utils/utils'
import { PermDataTypeEunm } from '../Company/components/PermSelect'
import BasicTable from '@/components/Table'
import { getPermAuthCache } from '@/utils/auth'
import { useModal } from '@/components/ModalStore'
import { Plus } from '@icon-park/react'
const Client = props => {
const dispatchModal = useModal()
const {
personTagColorMap,
teamTagColorMap,
personTags,
teamTags,
dispatch,
shouldUpdate,
loading,
sourceList
} = props
const { initialState: { permData } = { permData: {} } } = useModel('@@initialState')
const hasAddPerm = useAccess()?.validatePermByType('client_add') || false
const tRef = useRef()
const [tagState, setTagState] = useState({
tagIds: [],
tagCooperationIds: []
})
const [state, setState] = useState({
params: {},
orderIds: []
})
const tag = useMemo(() => {
const personTagMap = {}
const teamTagMap = {}
const personOptions = []
const teamOptions = []
personTags.forEach(item => {
// personOptions.push({ label: item.name, value: item.id })
personTagMap[item.id] = {
text: (
<>
{item.name}
>
)
}
})
teamTags.forEach(item => {
// teamOptions.push({ label: item.name, value: item.id })
teamTagMap[item.id] = {
text: (
<>
{item.name}
>
)
}
})
return { personTagMap, teamTagMap, personOptions, teamOptions }
}, [loading, shouldUpdate])
// 默认刷新一次列表请求数据
useEffect(() => {
if (!sourceList?.length) {
dispatch({
type: 'client/fetchSourceList'
})
}
if (!personTags.length) {
dispatch({
type: 'client/fetchPersonTags',
payload: { tagType: TagTypeEnum.PERSONTAG, tagColumn: TagDataTypeEnum.CLIENT }
})
}
if (!teamTags.length) {
dispatch({
type: 'client/fetchTeamTags',
payload: { tagType: TagTypeEnum.TEAMTAG, tagColumn: TagDataTypeEnum.CLIENT }
})
}
if (shouldUpdate) {
tRef.current.reload()
}
}, [shouldUpdate])
const toolbarOptionsChange = (type, ids) => {
setTagState({ ...tagState, [type]: ids })
}
const [defaultPermAuthCache] = getPermAuthCache(PermDataTypeEunm.CUSTOMER)
// 重置到默认值,包括表单
const initData = () => {
tRef.current?.reset()
}
// 刷新
const refreshData = () => {
tRef.current?.reload()
}
const handleAddClient = async values => {
const payload = formatValues(values)
const { code = -1, msg = '新增失败' } = await apiAddClient(payload)
if (code === consts.RET_CODE.SUCCESS) {
message.success(msg)
initData()
}
return code === consts.RET_CODE.SUCCESS
}
const columns = [
{
title: '客户',
dataIndex: 'clientName',
key: 'clientName',
width: 80,
fixed: 'left',
render: (clientName, record) => (
dispatchModal('D_CLIENT_DETAIL', { dataId: record.id, orderIds: state.orderIds })}
className="text-primary cursor-pointer hover:text-hex-967bbd">
{clientName}
),
sorter: true,
search: false
},
{
title: '单位名称',
dataIndex: 'companyName',
key: 'companyName',
width: 200,
// ellipsis: true,
render: (companyName, record) =>
record.companyId ? (
{
if (record.companyId !== consts.ENCRYPTION_ZERO) {
dispatchModal('D_COMPANY_DETAIL', {
updateKey: 'client',
dataId: record.companyId,
orderIds: state.orderIds
})
}
}}
className="text-primary cursor-pointer hover:text-hex-967bbd">
{companyName}
) : (
'-'
),
sorter: true,
search: false
},
{
title: '部门',
dataIndex: 'department',
key: 'department',
ellipsis: true,
width: 70,
search: false
},
{
title: '职务',
dataIndex: 'position',
key: 'position',
width: 75,
search: false
},
{
title: '办公室',
dataIndex: 'office',
key: 'office',
width: 90,
ellipsis: true,
search: false
},
{
title: '电话',
dataIndex: 'phone',
key: 'phone',
width: 120,
search: false,
sorter: true
},
{
title: '手机',
dataIndex: 'telephone',
key: 'telephone',
width: 120,
sorter: true,
search: false
},
{
title: 'QQ',
dataIndex: 'qq',
key: 'qq',
width: 120,
sorter: true,
search: false
},
{
title: '邮箱',
dataIndex: 'email',
key: 'email',
width: 165,
sorter: true,
// ellipsis: true,
search: false
},
{
title: '地区',
dataIndex: 'districtName',
key: 'districtName',
width: 120,
search: false,
// ellipsis: true,
// filterDropdown: filterDropdownProps =>