🎨refactor: 催信支持多选设置

main
LiaoYijun 8 months ago
parent 2f51a1c40a
commit 354ec5337f

@ -14,7 +14,7 @@ import {
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import { App, Flex, Select, Tooltip, Divider, Typography, Skeleton, Checkbox, Drawer, Button, Empty, Form, Input } from 'antd' import { App, Flex, Select, Tooltip, Divider, Typography, Skeleton, Checkbox, Drawer, Button, Empty, Form, Input } from 'antd'
import { useOrderStore, fetchSetRemindStateAction, OrderLabelDefaultOptions, OrderStatusDefaultOptions, remindStatusOptions } from '@/stores/OrderStore' import { useOrderStore, setRemindStateAction, OrderLabelDefaultOptions, OrderStatusDefaultOptions, remindStatusOptions } from '@/stores/OrderStore'
import { copy, isEmpty } from '@/utils/commons' import { copy, isEmpty } from '@/utils/commons'
import { useShallow } from 'zustand/react/shallow' import { useShallow } from 'zustand/react/shallow'
import useConversationStore from '@/stores/ConversationStore' import useConversationStore from '@/stores/ConversationStore'
@ -35,7 +35,8 @@ const OrderProfile = ({ coliSN, ...props }) => {
orderLabelOptions.unshift({ value: 0, label: '未设置', disabled: true }) orderLabelOptions.unshift({ value: 0, label: '未设置', disabled: true })
const orderStatusOptions = copy(OrderStatusDefaultOptions) const orderStatusOptions = copy(OrderStatusDefaultOptions)
const [orderDetail, customerDetail, fetchOrderDetail, setOrderPropValue, appendOrderComment, updateWhatsapp, updateExtraInfo] = useOrderStore((s) => [ const [orderDetail, customerDetail, fetchOrderDetail, setOrderPropValue,
appendOrderComment, updateWhatsapp, updateExtraInfo, remindCheckList] = useOrderStore((s) => [
s.orderDetail, s.orderDetail,
s.customerDetail, s.customerDetail,
s.fetchOrderDetail, s.fetchOrderDetail,
@ -43,16 +44,13 @@ const OrderProfile = ({ coliSN, ...props }) => {
s.appendOrderComment, s.appendOrderComment,
s.updateWhatsapp, s.updateWhatsapp,
s.updateExtraInfo, s.updateExtraInfo,
s.remindCheckList
]) ])
const loginUser = useAuthStore((state) => state.loginUser) const loginUser = useAuthStore((state) => state.loginUser)
const currentOrder = useConversationStore(useShallow((state) => state.currentConversation?.coli_sn || '')) const currentOrder = useConversationStore(useShallow((state) => state.currentConversation?.coli_sn || ''))
const orderId = coliSN || currentOrder const orderId = coliSN || currentOrder
const [orderRemindState, setOrderRemindState] = useState(orderDetail.remindstate)
useEffect(() => {
setOrderRemindState(orderDetail.remindstate)
}, [orderDetail.remindstate])
useEffect(() => { useEffect(() => {
if (orderId) { if (orderId) {
setLoading(true) setLoading(true)
@ -71,20 +69,12 @@ const OrderProfile = ({ coliSN, ...props }) => {
}, [orderId]) }, [orderId])
const handleSetRemindState = async (checkedValue) => { const handleSetRemindState = async (checkedValue) => {
const state = checkedValue.filter((v) => v !== orderRemindState)
const oldState = orderRemindState
try { try {
if (isEmpty(state)) { await setRemindStateAction(coliSN, checkedValue )
setOrderRemindState(null)
} else {
setOrderRemindState(state[0])
}
await fetchSetRemindStateAction({ coli_sn: coliSN, remindstate: state })
message.success('设置成功') message.success('设置成功')
} catch (error) { } catch (error) {
notification.warning({ message: '设置失败', description: error.message, placement: 'top', duration: 60 }) notification.warning({ message: '设置失败', description: error.message, placement: 'top', duration: 60 })
setOrderRemindState(oldState)
} }
} }
@ -206,7 +196,7 @@ const OrderProfile = ({ coliSN, ...props }) => {
<Divider orientation='left'> <Divider orientation='left'>
<Typography.Text strong>催信</Typography.Text> <Typography.Text strong>催信</Typography.Text>
</Divider> </Divider>
<Checkbox.Group key='substatus' className='px-2' value={[orderRemindState]} options={remindStatusOptions} onChange={handleSetRemindState} /> <Checkbox.Group key='substatus' className='px-2' value={remindCheckList} options={remindStatusOptions} onChange={handleSetRemindState} />
<Divider orientation='left'> <Divider orientation='left'>
<Typography.Text strong>表单信息</Typography.Text> <Typography.Text strong>表单信息</Typography.Text>

@ -2,7 +2,7 @@ import { create } from 'zustand'
import { devtools } from 'zustand/middleware' import { devtools } from 'zustand/middleware'
import { fetchJSON, postForm, postJSON } from '@/utils/request' import { fetchJSON, postForm, postJSON } from '@/utils/request'
import { API_HOST, API_HOST_V3, EMAIL_HOST } from '@/config' import { API_HOST, API_HOST_V3, EMAIL_HOST } from '@/config'
import { isNotEmpty, prepareUrl, uniqWith } from '@/utils/commons' import { isEmpty, isNotEmpty, prepareUrl, uniqWith } from '@/utils/commons'
const initialState = { const initialState = {
orderList: [], orderList: [],
@ -11,6 +11,7 @@ const initialState = {
lastQuotation: {}, lastQuotation: {},
quotationList: [], quotationList: [],
otherEmailList: [], otherEmailList: [],
remindCheckList: [],
} }
export const useOrderStore = create( export const useOrderStore = create(
@ -59,20 +60,19 @@ export const useOrderStore = create(
}, },
fetchOrderDetail: (colisn) => { fetchOrderDetail: (colisn) => {
return fetchJSON(`${API_HOST}/getorderinfo`, { colisn }).then((json) => { // return fetchJSON(`${API_HOST}/getorderinfo`, { colisn }).then((json) => {
return fetchJSON(`http://202.103.68.144:8888/v2/getorderinfo`, { colisn }).then((json) => {
if (json.errcode === 0 && json.result.length > 0) { if (json.errcode === 0 && json.result.length > 0) {
const orderResult = json.result[0] const orderResult = json.result[0]
set(() => ({ set(() => ({
remindCheckList: transferRemind2Checklist(orderResult.remindstate),
orderDetail: { ...orderResult, coli_sn: colisn }, orderDetail: { ...orderResult, coli_sn: colisn },
customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {}, customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {},
// lastQuotation: orderResult.quotes.length > 0 ? orderResult.quotes[0] : {},
// quotationList: orderResult.quotes,
})) }))
return { return {
orderDetail: { ...orderResult, coli_sn: colisn }, orderDetail: { ...orderResult, coli_sn: colisn },
customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {}, customerDetail: orderResult.contact.length > 0 ? orderResult.contact[0] : {},
// lastQuotation: orderResult.quotes.length > 0 ? orderResult.quotes[0] : {},
// quotationList: orderResult.quotes,
} }
} else { } else {
throw new Error(json?.errmsg + ': ' + json.errcode) throw new Error(json?.errmsg + ': ' + json.errcode)
@ -280,20 +280,52 @@ export const RemindStateDefaultOptions = [
* @useage 订单信息: 标记状态 * @useage 订单信息: 标记状态
*/ */
export const remindStatusOptions = [ export const remindStatusOptions = [
{ value: 1, label: '已发一催' }, { value: 'FirstRemind', label: '已发一催' },
{ value: 2, label: '已发二催' }, { value: 'SendFirstRemind', label: '已发二催' },
{ value: 3, label: '已发三催' }, { value: 'ThirdRemind', label: '已发三催' },
{ value: 'important', label: '重点团' }, { value: 'important', label: '重点团' },
{ value: 'sendsurvey', label: '已发 travel advisor survey' }, { value: 'sendsurvey', label: '已发 travel advisor survey' },
] ]
export const remindStatusOptionsMapped = remindStatusOptions.reduce((acc, cur) => { export const remindStatusOptionsMapped = remindStatusOptions.reduce((acc, cur) => {
return { ...acc, [String(cur.value)]: cur } return { ...acc, [String(cur.value)]: cur }
}, {}) }, {})
const transferRemind2Checklist = (remindstate) => {
const remindValueList = []
if (isEmpty(remindstate)) return remindValueList
if (remindstate.FirstRemind) {
remindValueList.push('FirstRemind')
}
if (remindstate.SendFirstRemind) {
remindValueList.push('SendFirstRemind')
}
if (remindstate.ThirdRemind) {
remindValueList.push('ThirdRemind')
}
if (remindstate.important) {
remindValueList.push('important')
}
if (remindstate.sendsurvey) {
remindValueList.push('sendsurvey')
}
return remindValueList
}
/** /**
* @param {Object} params { coli_sn, remindstate } * @param {Object} params { orderId, checkedValue }
*/ */
export const fetchSetRemindStateAction = async (params) => { export const setRemindStateAction = async (orderId, checkedValue) => {
const { errcode, result } = await fetchJSON(`${API_HOST}/SetRemindState`, params) const finalState = {
'FirstRemind': checkedValue.includes('FirstRemind') ? 1 : 0,
'SendFirstRemind': checkedValue.includes('SendFirstRemind') ? 1 : 0,
'ThirdRemind': checkedValue.includes('ThirdRemind') ? 1 : 0,
'important': checkedValue.includes('important') ? 1 : 0,
'sendsurvey': checkedValue.includes('sendsurvey') ? 1 : 0,
}
const { errcode, result } = await postJSON(`${API_HOST}/SetRemindState`, { coli_sn: orderId, remindstate: JSON.stringify(finalState)})
return errcode === 0 ? result : {} return errcode === 0 ? result : {}
} }

Loading…
Cancel
Save