feat: 增加批量导入邮件消息

dev/emitter
LiaoYijun 10 months ago
parent f039bbeff2
commit 89e365d89a

@ -139,6 +139,27 @@ export const useOrderStore = create(devtools((set, get) => ({
}) })
}, },
batchImportEmailMessage: () => {
const { orderList } = get()
const orderPromiseList = orderList.map(order => {
return new Promise((resolve, reject) => {
fetchJSON(`${API_HOST}/generate_email_msg`, { coli_sn: order.COLI_SN, coli_id: order.COLI_ID })
.then(json => {
if (json.errcode === 0) {
resolve(json)
} else {
reject(json?.errmsg + ': ' + json.errcode)
}
})
})
})
Promise.all(orderPromiseList).then((values) => {
console.log(values);
})
},
fetchOtherEmail: (coli_sn) => { fetchOtherEmail: (coli_sn) => {
return fetchJSON(`${EMAIL_HOST}/email_supplier`, { coli_sn }) return fetchJSON(`${EMAIL_HOST}/email_supplier`, { coli_sn })
.then(json => { .then(json => {

@ -5,23 +5,15 @@ import useFormStore from '@/stores/FormStore'
import { useOrderStore } from '@/stores/OrderStore' import { useOrderStore } from '@/stores/OrderStore'
import { copy, isNotEmpty, isEmpty } from '@/utils/commons' import { copy, isNotEmpty, isEmpty } from '@/utils/commons'
import { WhatsAppOutlined, ImportOutlined } from '@ant-design/icons' import { WhatsAppOutlined, ImportOutlined } from '@ant-design/icons'
import { import { App, Badge, Empty, Flex, Button, Radio, Space, Switch, Table, Tabs, Divider, Tag, Tooltip } from 'antd'
App, Badge,
Empty,
Flex,Button,
Radio, Space, Switch, Table,
Tabs, Divider,
Tag, Tooltip
} from 'antd'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { useCallback, useEffect, useState } from 'react' import { useCallback, useEffect, useState } from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { useShallow } from 'zustand/react/shallow' import { useShallow } from 'zustand/react/shallow'
import { UNREAD_MARK } from '@/actions/ConversationActions'; import { UNREAD_MARK } from '@/actions/ConversationActions'
import AdvanceSearchForm from './AdvanceSearchForm'; import AdvanceSearchForm from './AdvanceSearchForm'
function OrderGroupTable({ formValues }) { function OrderGroupTable({ formValues }) {
const handleImportEmail = useCallback((order) => { const handleImportEmail = useCallback((order) => {
importEmailMessage({ orderId: order.COLI_SN, orderNumber: order.COLI_ID }) importEmailMessage({ orderId: order.COLI_SN, orderNumber: order.COLI_ID })
.then((r) => { .then((r) => {
@ -38,7 +30,8 @@ function OrderGroupTable({ formValues }) {
description: ex.message, description: ex.message,
placement: 'top', placement: 'top',
duration: 4, duration: 4,
})) }),
)
}, []) }, [])
const orderColumns = [ const orderColumns = [
@ -57,7 +50,7 @@ function OrderGroupTable({ formValues }) {
<Space> <Space>
<Conditional <Conditional
condition={isPermitted(PERM_IMPORT_EMAIL)} condition={isPermitted(PERM_IMPORT_EMAIL)}
whenTrue={<Button type="default" shape="round" icon={<ImportOutlined />} size='small' onClick={() => handleImportEmail(record)} />} whenTrue={<Button type='default' shape='round' icon={<ImportOutlined />} size='small' onClick={() => handleImportEmail(record)} />}
/> />
<Link to={`/order/chat/${record.COLI_SN}`} state={record}> <Link to={`/order/chat/${record.COLI_SN}`} state={record}>
{text} {text}
@ -65,7 +58,7 @@ function OrderGroupTable({ formValues }) {
{tagIcon} {tagIcon}
</Space> </Space>
) )
} },
}, },
{ {
title: '客人姓名', title: '客人姓名',
@ -77,7 +70,11 @@ function OrderGroupTable({ formValues }) {
<Space> <Space>
<Conditional <Conditional
condition={isPermitted(record.coli_guest_WhatsApp)} condition={isPermitted(record.coli_guest_WhatsApp)}
whenTrue={<Tooltip title={record.coli_guest_WhatsApp}><WhatsAppOutlined className={['pl-1', record.last_received_time ? 'text-whatsapp' : 'text-neutral-500']} /></Tooltip>} whenTrue={
<Tooltip title={record.coli_guest_WhatsApp}>
<WhatsAppOutlined className={['pl-1', record.last_received_time ? 'text-whatsapp' : 'text-neutral-500']} />
</Tooltip>
}
/> />
{text + regularText} {text + regularText}
<Badge <Badge
@ -88,7 +85,7 @@ function OrderGroupTable({ formValues }) {
/> />
</Space> </Space>
) )
} },
}, },
{ {
title: '订单状态', title: '订单状态',
@ -106,18 +103,13 @@ function OrderGroupTable({ formValues }) {
{text} {text}
</Space> </Space>
) )
} },
}, },
{ {
title: '报价 Title', title: '报价 Title',
dataIndex: 'lettertitle', dataIndex: 'lettertitle',
ellipsis: true, ellipsis: true,
hidden: false, hidden: false,
// render: (text, record) => {
// return (
// <Tooltip title={text}>{text}</Tooltip>
// )
// }
}, },
{ {
title: '出发日期', title: '出发日期',
@ -129,7 +121,7 @@ function OrderGroupTable({ formValues }) {
const datejsA = isEmpty(a.COLI_OrderStartDate) ? 0 : new dayjs(a.COLI_OrderStartDate).valueOf() const datejsA = isEmpty(a.COLI_OrderStartDate) ? 0 : new dayjs(a.COLI_OrderStartDate).valueOf()
const datejsB = isEmpty(b.COLI_OrderStartDate) ? 0 : new dayjs(b.COLI_OrderStartDate).valueOf() const datejsB = isEmpty(b.COLI_OrderStartDate) ? 0 : new dayjs(b.COLI_OrderStartDate).valueOf()
return datejsA - datejsB return datejsA - datejsB
} },
}, },
{ {
title: '客人最后一次回复时间', title: '客人最后一次回复时间',
@ -139,7 +131,7 @@ function OrderGroupTable({ formValues }) {
if (record.last_received_time) { if (record.last_received_time) {
return new dayjs(record.last_received_time).format('YYYY-MM-DD HH:mm:ss') return new dayjs(record.last_received_time).format('YYYY-MM-DD HH:mm:ss')
} }
} },
}, },
{ {
title: '附加信息', title: '附加信息',
@ -153,9 +145,7 @@ function OrderGroupTable({ formValues }) {
const orderList = useOrderStore((state) => state.orderList) const orderList = useOrderStore((state) => state.orderList)
const fetchOrderList = useOrderStore((state) => state.fetchOrderList) const fetchOrderList = useOrderStore((state) => state.fetchOrderList)
const importEmailMessage = useOrderStore((state) => state.importEmailMessage) const importEmailMessage = useOrderStore((state) => state.importEmailMessage)
const [loginUser, isPermitted] = useAuthStore((state) => [ const [loginUser, isPermitted] = useAuthStore((state) => [state.loginUser, state.isPermitted])
state.loginUser, state.isPermitted
])
useEffect(() => { useEffect(() => {
let canSearch = true let canSearch = true
@ -163,7 +153,7 @@ function OrderGroupTable({ formValues }) {
if (formValues.type === 'advance') { if (formValues.type === 'advance') {
const copyObject = copy(formValues) const copyObject = copy(formValues)
delete copyObject.type delete copyObject.type
const allEmpty = Object.values(copyObject).every(val => { const allEmpty = Object.values(copyObject).every((val) => {
return val === null || val === '' || val === undefined return val === null || val === '' || val === undefined
}) })
if (allEmpty) { if (allEmpty) {
@ -181,7 +171,7 @@ function OrderGroupTable({ formValues }) {
setLoading(true) setLoading(true)
fetchOrderList(formValues, loginUser) fetchOrderList(formValues, loginUser)
.finally(() => setLoading(false)) .finally(() => setLoading(false))
.catch(reason => { .catch((reason) => {
notification.error({ notification.error({
message: '查询出错', message: '查询出错',
description: reason.message, description: reason.message,
@ -196,12 +186,14 @@ function OrderGroupTable({ formValues }) {
showQuickJumper: true, showQuickJumper: true,
showLessItems: true, showLessItems: true,
showSizeChanger: true, showSizeChanger: true,
showTotal: (total) => { return `总数:${total}` } showTotal: (total) => {
return `总数:${total}`
},
} }
function groupByParam(array, param) { function groupByParam(array, param) {
return array.reduce((result, item) => { return array.reduce((result, item) => {
(result[item[param]] = result[item[param]] || []).push(item) ;(result[item[param]] = result[item[param]] || []).push(item)
return result return result
}, {}) }, {})
} }
@ -262,88 +254,75 @@ function OrderGroupTable({ formValues }) {
return o.coli_ordertype === 8 return o.coli_ordertype === 8
}) })
if (formValues.type === 'today') { if (formValues.type === 'today') {
deptItems.push( deptItems.push({
{ key: index,
key: index, label: deptMap.get(deptNo),
label: deptMap.get(deptNo), children: (
children: <> <>
<Divider orientation='left'>新订单</Divider> <Divider orientation='left'>新订单</Divider>
<Conditional <Conditional
condition={newOrderList.length > 0} condition={newOrderList.length > 0}
whenTrue={<Table key={'newOrderTable' + deptNo} loading={loading} dataSource={newOrderList} whenTrue={<Table key={'newOrderTable' + deptNo} loading={loading} dataSource={newOrderList} columns={orderColumns} pagination={newOrderList.length <= 10 ? false : paginationProps} />}
columns={orderColumns}
pagination={newOrderList.length <= 10 ? false : paginationProps} />}
whenFalse={<Empty />} whenFalse={<Empty />}
/> />
<Divider orientation='left'>新消息/老邮件</Divider> <Divider orientation='left'>新消息/老邮件</Divider>
<Conditional <Conditional
condition={newMsgList.length > 0} condition={newMsgList.length > 0}
whenTrue={<Table key={'newMsgTable' + deptNo} loading={loading} dataSource={newMsgList} whenTrue={<Table key={'newMsgTable' + deptNo} loading={loading} dataSource={newMsgList} columns={orderColumns} pagination={newMsgList.length <= 10 ? false : paginationProps} />}
columns={orderColumns}
pagination={newMsgList.length <= 10 ? false : paginationProps} />}
whenFalse={<Empty />} whenFalse={<Empty />}
/> />
<Divider orientation='left'>催信</Divider> <Divider orientation='left'>催信</Divider>
<Conditional <Conditional
condition={followUpList.length > 0} condition={followUpList.length > 0}
whenTrue={<Table key={'followUpTable' + deptNo} loading={loading} dataSource={followUpList} whenTrue={<Table key={'followUpTable' + deptNo} loading={loading} dataSource={followUpList} columns={orderColumns} pagination={followUpList.length <= 10 ? false : paginationProps} />}
columns={orderColumns}
pagination={followUpList.length <= 10 ? false : paginationProps} />}
whenFalse={<Empty />} whenFalse={<Empty />}
/> />
<Divider orientation='left'>余款收付</Divider> <Divider orientation='left'>余款收付</Divider>
<Conditional <Conditional
condition={paymentList.length > 0} condition={paymentList.length > 0}
whenTrue={<Table key={'paymentTable' + deptNo} loading={loading} dataSource={paymentList} whenTrue={<Table key={'paymentTable' + deptNo} loading={loading} dataSource={paymentList} columns={orderColumns} pagination={paymentList.length <= 10 ? false : paginationProps} />}
columns={orderColumns}
pagination={paymentList.length <= 10 ? false : paginationProps} />}
whenFalse={<Empty />} whenFalse={<Empty />}
/> />
<Divider orientation='left'>入境提醒</Divider> <Divider orientation='left'>入境提醒</Divider>
<Conditional <Conditional
condition={entryList.length > 0} condition={entryList.length > 0}
whenTrue={<Table key={'entryTable' + deptNo} loading={loading} dataSource={entryList} whenTrue={<Table key={'entryTable' + deptNo} loading={loading} dataSource={entryList} columns={orderColumns} pagination={entryList.length <= 10 ? false : paginationProps} />}
columns={orderColumns}
pagination={entryList.length <= 10 ? false : paginationProps} /> }
whenFalse={<Empty />} whenFalse={<Empty />}
/> />
</> </>
} ),
) })
} else { } else {
deptItems.push( deptItems.push({
{ key: index,
key: index, label: deptMap.get(deptNo),
label: deptMap.get(deptNo), children: (
children: <> <>
<Table key={'advanceOrderTable' + deptNo} loading={loading} dataSource={deptOrderList} <Table key={'advanceOrderTable' + deptNo} loading={loading} dataSource={deptOrderList} columns={orderColumns} pagination={deptOrderList.length <= 10 ? false : paginationProps} />
columns={orderColumns}
pagination={deptOrderList.length <= 10 ? false : paginationProps} />
</> </>
} ),
) })
} }
}) })
return ( return <Conditional condition={orderList.length > 0} whenTrue={<Tabs defaultActiveKey={0} items={deptItems} />} whenFalse={<Empty />} />
<Conditional
condition={orderList.length > 0}
whenTrue={<Tabs defaultActiveKey={0} items={deptItems} />}
whenFalse={<Empty />}
/>
)
} }
function Follow() { function Follow() {
const [formValues, setFormValues] = useFormStore(useShallow((state) => [state.orderFollowForm, state.setOrderFollowForm])) const [formValues, setFormValues] = useFormStore(useShallow((state) => [state.orderFollowForm, state.setOrderFollowForm]))
const [advanceChecked, toggleAdvance] = useFormStore(useShallow((state) => [state.orderFollowAdvanceChecked, state.setOrderFollowAdvanceChecked])) const [advanceChecked, toggleAdvance] = useFormStore(useShallow((state) => [state.orderFollowAdvanceChecked, state.setOrderFollowAdvanceChecked]))
const batchImportEmailMessage = useOrderStore((state) => state.batchImportEmailMessage)
const [isPermitted] = useAuthStore((state) => [state.isPermitted])
const handleImportEmail = useCallback(() => {
batchImportEmailMessage()
}, [])
const handleSubmit = useCallback((values) => { const handleSubmit = useCallback((values) => {
setFormValues({ ...values, type: 'advance' }) setFormValues({ ...values, type: 'advance' })
}, []) }, [])
@ -359,25 +338,34 @@ function Follow() {
{ label: '次重点客户', value: 'qianli' }, { label: '次重点客户', value: 'qianli' },
{ label: '成行', value: 'chengxing' }, { label: '成行', value: 'chengxing' },
{ label: '走团中', value: 'zoutuan' }, { label: '走团中', value: 'zoutuan' },
{ label: '走团后一月', value: 'zoutuanhou' } { label: '走团后一月', value: 'zoutuanhou' },
]} ]}
value={formValues.type} value={formValues.type}
onChange={({ target: { value } }) => { onChange={({ target: { value } }) => {
setFormValues({ setFormValues({
...formValues, ...formValues,
type: value type: value,
}) })
}} }}
optionType='button' optionType='button'
buttonStyle='solid' buttonStyle='solid'
disabled={advanceChecked} disabled={advanceChecked}
/> />
<Switch checkedChildren='高级查询' unCheckedChildren='高级查询' <Switch
checkedChildren='高级查询'
unCheckedChildren='高级查询'
checked={advanceChecked} checked={advanceChecked}
onChange={() => { toggleAdvance(!advanceChecked) }} /> onChange={() => {
toggleAdvance(!advanceChecked)
}}
/>
<Conditional
condition={isPermitted(PERM_IMPORT_EMAIL)}
whenTrue={<Button type='default' shape='round' icon={<ImportOutlined />} size='small' onClick={handleImportEmail}/>}
/>
</Flex> </Flex>
<Conditional condition={advanceChecked} whenTrue={<AdvanceSearchForm onSubmit={handleSubmit} initialValues={formValues} />} <Conditional condition={advanceChecked} whenTrue={<AdvanceSearchForm onSubmit={handleSubmit} initialValues={formValues} />} />
/>
<OrderGroupTable formValues={formValues} /> <OrderGroupTable formValues={formValues} />
</Space> </Space>
</> </>

Loading…
Cancel
Save