|
@@ -9,14 +9,15 @@ import Strategy from './components/Strategy';
|
|
|
import { getBindMpListApi } from '@/pages/weComTask/API/corpUserAssign';
|
|
|
import { DefaultOptionType } from 'antd/es/select';
|
|
|
import { getCorpAllListApi } from '@/API/global';
|
|
|
-import { SaveOutlined, RedoOutlined, SearchOutlined, PlusOutlined } from '@ant-design/icons';
|
|
|
+import { SaveOutlined, RedoOutlined, SearchOutlined, PlusOutlined, CheckOutlined } from '@ant-design/icons';
|
|
|
import Content from './components/content';
|
|
|
-import { removeEmptyValues } from '@/utils/utils';
|
|
|
+import { groupBy, removeEmptyValues } from '@/utils/utils';
|
|
|
import { PreviewColumns } from './tableConfig';
|
|
|
import SubmitModal from '../../../businessPlan/create/submitModal';
|
|
|
import { addTaskApi, getCreateDetailsApi, updateTaskApi } from '@/pages/weComTask/API/businessPlan/create';
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
-import { getRobotSendData } from './const';
|
|
|
+import { getRobotSendData, transformData } from './const';
|
|
|
+import SelectMpCorp from '../../official/create/components/SelectMpCorp';
|
|
|
|
|
|
|
|
|
export const DispatchRobotChatCreate = React.createContext<ROBOT_CHAT_CREATE.DispatchRobotChatCreate | null>(null);
|
|
@@ -39,6 +40,8 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
const [corpList, setCorpList] = useState<DefaultOptionType[]>([])
|
|
|
const [previewContent, setPreviewContent] = useState<{ [x: string]: { [x: string]: string } }>({})
|
|
|
const [subVisible, setSubVisible] = useState<boolean>(false) // 选择设置名称弹窗控制
|
|
|
+ const [corpVisible, setCorpVisible] = useState<boolean>(false)
|
|
|
+ const [corpGroupChat, setCorpGroupChat] = useState<{ [x: string]: any }>({})
|
|
|
|
|
|
const welcomeMsgJobType = useAjax(() => welcomeMsgJobTypeApi())//获取业务类型
|
|
|
const getBindMpList = useAjax(() => getBindMpListApi())
|
|
@@ -59,12 +62,20 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
getCreateDetails.run(id).then(res => {
|
|
|
sessionStorage.removeItem('ROBOT_OFFICIALTASKID')
|
|
|
if (res?.data) {
|
|
|
- const { bizType, platform, templateProductId, channel, robotGroupChatSendTaskAddDTO } = res.data
|
|
|
+ const { bizType, platform, templateProductId, channel, robotGroupChatSendTaskAddDTO, mpAccounts } = res.data
|
|
|
let newSettings: ROBOT_CHAT_CREATE.SettingsProps = {
|
|
|
bizType,
|
|
|
platform: Number(platform) as any,
|
|
|
templateProductId,
|
|
|
- channel
|
|
|
+ channel,
|
|
|
+ mpAccount: mpAccounts.map(m => {
|
|
|
+ return {
|
|
|
+ label: m?.mpAccountVO?.name || '',
|
|
|
+ value: m?.mpAccountVO?.id || '',
|
|
|
+ appId: m?.mpAccountVO?.appId || '',
|
|
|
+ corp: m?.corpVOList?.map(c => ({ label: c.corpName, value: c.corpId })) || []
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
if (robotGroupChatSendTaskAddDTO && Object.keys(robotGroupChatSendTaskAddDTO).length > 0) {
|
|
|
const data = getRobotSendData(robotGroupChatSendTaskAddDTO)
|
|
@@ -116,11 +127,19 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
|
|
|
// 预览
|
|
|
const preview = () => {
|
|
|
- const { bizType, platform, templateProductId, channel } = settings
|
|
|
+ const { bizType, platform, templateProductId, channel, mpAccount } = settings
|
|
|
if (!(settings?.strategyDTO && Object.keys(settings?.strategyDTO).length > 0)) {
|
|
|
message.error('请先配置内容')
|
|
|
return
|
|
|
}
|
|
|
+ if (!mpAccount?.length) {
|
|
|
+ message.error('请选择公众号')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (mpAccount.some(item => !item?.corp?.length)) {
|
|
|
+ message.error('请选择关联主体')
|
|
|
+ return
|
|
|
+ }
|
|
|
if (!bizType) {
|
|
|
message.error('请选择业务类型')
|
|
|
return
|
|
@@ -130,11 +149,12 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
return
|
|
|
}
|
|
|
const list: any[] = []
|
|
|
- let id = 1
|
|
|
if (!settings?.strategyDTO?.strategyList?.every((str, s_index) => {
|
|
|
const { sendData, ...sdto } = str
|
|
|
+ const count = sendData.reduce((pre, cur) => pre + (cur?.contentDTO?.length || 0), 0)
|
|
|
+ let saveIndex = 0
|
|
|
return sendData?.every((sd, f_index) => {
|
|
|
- const { contentDTO, mpAccountId, corpIds, robotCorpId, robotCorpUser, chatCorpId, corpGroupChat, ...cdto } = sd
|
|
|
+ const { contentDTO, robotCorpId, robotCorpUser, chatCorpId, corpGroupChat, ...cdto } = sd
|
|
|
if (contentDTO?.length) {
|
|
|
return contentDTO?.every((cd, c_index) => {
|
|
|
if (cd?.attachmentList?.length || cd?.text?.content) {
|
|
@@ -167,20 +187,13 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
return `<span style="color: red">请联系管理员</span>`
|
|
|
}
|
|
|
})
|
|
|
- const weChat = mpList.find(item => item.value === mpAccountId)
|
|
|
list.push({
|
|
|
- id,
|
|
|
bizType,
|
|
|
platform,
|
|
|
templateProductId,
|
|
|
channel,
|
|
|
- taskName: settings?.strategyDTO?.taskName,
|
|
|
+ groupSendName: settings?.strategyDTO?.groupSendName,
|
|
|
strategyData: sdto,
|
|
|
- mpAccountId,
|
|
|
- weChatName: weChat?.label,
|
|
|
- mpAccountAppid: weChat?.appId,
|
|
|
- corpIds,
|
|
|
- corpNames: corpIds.map(corpId => corpList.find(item => item.value === corpId)?.label),
|
|
|
robotCorpId,
|
|
|
robotCorpName: corpList.find(item => item.value === robotCorpId)?.label,
|
|
|
robotCorpUser,
|
|
@@ -194,9 +207,11 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
sendIndex: f_index,
|
|
|
contentIndex: c_index,
|
|
|
linkData,
|
|
|
- miniProgramData
|
|
|
+ miniProgramData,
|
|
|
+ contentRowSpan: c_index === 0 ? contentDTO.length : 0, // 用于表格合并
|
|
|
+ strategyRowSpan: saveIndex === 0 ? count : 0
|
|
|
})
|
|
|
- id++;
|
|
|
+ saveIndex += 1
|
|
|
return true
|
|
|
} else {
|
|
|
message.error(`策略:${str?.strategyName},发送对象:${sd?.sendGroupName}请填写发送内容`)
|
|
@@ -212,10 +227,27 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
})) {
|
|
|
return
|
|
|
}
|
|
|
- console.log('=========================>', list)
|
|
|
- setPreviewData(list)
|
|
|
- setPreviewDataOld(list)
|
|
|
+ let id = 1
|
|
|
+ const newPreviewData = mpAccount.reduce((pre, cur, index) => {
|
|
|
+ return pre.concat(...list.map((item, i) => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ id: id++,
|
|
|
+ mpAccountId: cur.value,
|
|
|
+ mpAccountName: cur.label,
|
|
|
+ mpAccountAppid: (cur as any).appId,
|
|
|
+ corpIds: cur.corp?.map(item => item.value),
|
|
|
+ corpNames: cur.corp?.map(item => item.label),
|
|
|
+ mpIndex: index,
|
|
|
+ mpRowSpan: i === 0 ? list.length : 0, // 用于表格合并
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ }, [])
|
|
|
+ console.log('=========================>', newPreviewData)
|
|
|
+ setPreviewData(newPreviewData)
|
|
|
+ setPreviewDataOld(newPreviewData)
|
|
|
setPreviewContent({})
|
|
|
+ setCorpGroupChat({})
|
|
|
}
|
|
|
|
|
|
const tableSearch = useCallback((values) => {
|
|
@@ -233,6 +265,13 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
}, [previewDataOld, previewData])
|
|
|
|
|
|
const setTaskName = () => {
|
|
|
+ if (!settings.mpAccount?.every((mp) => settings?.strategyDTO?.strategyList?.every((str, s_index) => str.sendData?.every((sd, f_index) => {
|
|
|
+ const chat = corpGroupChat?.[mp.value + '_' + s_index + '_' + f_index]
|
|
|
+ return chat?.chatCorpId && chat?.corpGroupChat
|
|
|
+ })))) {
|
|
|
+ message.error('请补充群聊主体等信息')
|
|
|
+ return
|
|
|
+ }
|
|
|
if (previewDataOld.every((item, index) => {
|
|
|
if ((item?.linkData?.length > 0 ? previewContent?.[index + 1]?.linkUrl : true) && (item?.miniProgramData?.length > 0 ? (previewContent?.[index + 1]?.miniprogramAppid && previewContent?.[index + 1]?.miniprogramPage) : true)) {
|
|
|
return true
|
|
@@ -246,13 +285,32 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
}
|
|
|
|
|
|
const onSubmit = (values: any) => {
|
|
|
- const { bizType, platform, templateProductId, channel, strategyDTO } = settings
|
|
|
+ console.log('---------->', corpGroupChat, transformData(corpGroupChat))
|
|
|
+ const corpGroupChatData = transformData(corpGroupChat)
|
|
|
+ const groupData = groupBy(previewDataOld, (item) => item['mpAccountId'], true);
|
|
|
+ const { bizType, platform, templateProductId, channel, strategyDTO, mpAccount } = settings
|
|
|
const params = {
|
|
|
...values,
|
|
|
bizType,
|
|
|
platform,
|
|
|
templateProductId,
|
|
|
channel,
|
|
|
+ mpAccounts: mpAccount.map(item => {
|
|
|
+ const data = groupData[item.value] || []
|
|
|
+ const groupChatMsgContent: any[] = []
|
|
|
+ data.forEach(d => {
|
|
|
+ const { strategyIndex, sendIndex, contentIndex, id } = d
|
|
|
+ if (!groupChatMsgContent[strategyIndex]) groupChatMsgContent[strategyIndex] = [];
|
|
|
+ if (!groupChatMsgContent[strategyIndex][sendIndex]) groupChatMsgContent[strategyIndex][sendIndex] = [];
|
|
|
+ groupChatMsgContent[strategyIndex][sendIndex][contentIndex] = previewContent?.[id] || {};
|
|
|
+ })
|
|
|
+ return {
|
|
|
+ mpAccountId: item.value,
|
|
|
+ corpIds: item.corp?.map(c => c.value) || [],
|
|
|
+ groupChatMsgContent,
|
|
|
+ corpGroupChat: corpGroupChatData[item.value]
|
|
|
+ }
|
|
|
+ }),
|
|
|
robotChatSendTaskAddDTO: {
|
|
|
...strategyDTO,
|
|
|
strategyList: strategyDTO?.strategyList?.map(item => {
|
|
@@ -260,11 +318,10 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
return {
|
|
|
...its,
|
|
|
taskDetail: sendData.map(sd => {
|
|
|
- const { externalUserType, externalUserFilter, contentDTO, sendGroupName, chatCorpId, corpGroupChat, robotCorpId, robotCorpUser, ...itsd } = sd
|
|
|
+ const { externalUserType, externalUserFilter, contentDTO, sendGroupName, robotCorpId, robotCorpUser, ...itsd } = sd
|
|
|
|
|
|
const detail: { [x: string]: any } = {
|
|
|
...itsd,
|
|
|
- corpGroupChat,
|
|
|
contentDTO,
|
|
|
externalUserFilterName: sendGroupName,
|
|
|
}
|
|
@@ -283,7 +340,7 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- // console.log('--->', params)
|
|
|
+ console.log('--->', params)
|
|
|
if (projectId) {
|
|
|
params.projectId = projectId
|
|
|
updateTask.run(params).then(res => {
|
|
@@ -297,7 +354,6 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
})
|
|
|
} else {
|
|
|
addTask.run(params).then(res => {
|
|
|
- console.log(res)
|
|
|
if (res?.data) {
|
|
|
modal.success({
|
|
|
content: '任务提交成功',
|
|
@@ -321,6 +377,46 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
<Spin spinning={false}>
|
|
|
<Card title={<strong>{projectId ? getCreateDetails?.data?.data?.projectName + '任务编辑' : ''}配置区</strong>} className={`${style.card} ${style.config}`}>
|
|
|
<Space wrap>
|
|
|
+ <Space.Compact>
|
|
|
+ <Button>群聊关联公众号</Button>
|
|
|
+ <Select
|
|
|
+ showSearch
|
|
|
+ allowClear
|
|
|
+ placeholder="选择公众号"
|
|
|
+ filterOption={(input, option) =>
|
|
|
+ (option?.label as any)?.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
|
|
+ }
|
|
|
+ style={{ minWidth: 200 }}
|
|
|
+ maxTagCount={1}
|
|
|
+ mode='multiple'
|
|
|
+ options={mpList}
|
|
|
+ value={settings?.mpAccount?.map(item => item.value)}
|
|
|
+ onChange={(_, options) => {
|
|
|
+ onPreviewReset()
|
|
|
+ if (options.length > 0) {
|
|
|
+ const oldMpAccountIds = settings?.mpAccount?.reduce((acc, item) => {
|
|
|
+ acc[item.value] = item;
|
|
|
+ return acc;
|
|
|
+ }, {}) || []
|
|
|
+ setSettings({
|
|
|
+ ...settings,
|
|
|
+ mpAccount: options.map(item => {
|
|
|
+ if (oldMpAccountIds?.[item.value]) {
|
|
|
+ return oldMpAccountIds[item.value]
|
|
|
+ }
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ setSettings({ ...settings, mpAccount: [] })
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ </Space.Compact>
|
|
|
+ {settings?.mpAccount?.length > 0 && <Button onClick={() => setCorpVisible(true)}>
|
|
|
+ 选择关联主体
|
|
|
+ {settings?.mpAccount?.some(item => item?.corp?.length) && <CheckOutlined style={{ color: settings?.mpAccount?.every(item => item?.corp?.length) ? '#1890ff' : '#52C41A' }} />}
|
|
|
+ </Button>}
|
|
|
<Space.Compact>
|
|
|
<Button>业务类型</Button>
|
|
|
<Select
|
|
@@ -478,7 +574,7 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
</Form>
|
|
|
<Table
|
|
|
dataSource={previewData}
|
|
|
- columns={PreviewColumns(bookPlatForm, bookList, bookPlatForm.find(item => item.id === Number(settings?.platform)).platformKey, setPreviewContent, previewContent)}
|
|
|
+ columns={PreviewColumns(corpList, bookPlatForm, bookList, bookPlatForm.find(item => item.id === Number(settings?.platform)).platformKey, setPreviewContent, previewContent, corpGroupChat, setCorpGroupChat)}
|
|
|
rowKey={'id'}
|
|
|
bordered={true}
|
|
|
scroll={{ y: 550 }}
|
|
@@ -505,6 +601,24 @@ const OfficialCreate: React.FC<{ weComTaskStore: { data: { bookList: TASK_CREATE
|
|
|
setSubVisible(false)
|
|
|
}}
|
|
|
/>}
|
|
|
+
|
|
|
+ {/* 选择关联主体 */}
|
|
|
+ {corpVisible && <SelectMpCorp
|
|
|
+ corpList={corpList}
|
|
|
+ visible={corpVisible}
|
|
|
+ mpAccount={settings?.mpAccount}
|
|
|
+ onChange={(mpAccount) => {
|
|
|
+ setSettings({
|
|
|
+ ...settings,
|
|
|
+ mpAccount
|
|
|
+ })
|
|
|
+ setCorpVisible(false)
|
|
|
+ onPreviewReset()
|
|
|
+ }}
|
|
|
+ onClose={() => {
|
|
|
+ setCorpVisible(false)
|
|
|
+ }}
|
|
|
+ />}
|
|
|
</div>;
|
|
|
};
|
|
|
|