@ -1,7 +1,8 @@
import { Link } from 'react-router-dom'
import { Link } from 'react-router-dom'
import { Form , Input , Button , DatePicker , Select , Table } from 'antd'
import { Form , Input , Button , DatePicker , Select , Table } from 'antd'
import dayjs from 'dayjs'
import dayjs from 'dayjs'
import { ReadIcon , DeliverIcon , SentIcon , WaitingIcon , FailedIcon } from '@/components/Icons'
import { ReadIcon , DeliverIcon , SentIcon , WaitingIcon , FailedIcon , ReplyIcon } from '@/components/Icons'
import { MessageTwoTone } from '@ant-design/icons'
import useCustomerRelationStore from '@/stores/CustomerRelationStore'
import useCustomerRelationStore from '@/stores/CustomerRelationStore'
const { RangePicker } = DatePicker
const { RangePicker } = DatePicker
@ -40,22 +41,28 @@ const Index = () => {
/ / 按 c r t _ t e m p l a t e 分 组 并 统 计 每 个 非 空 m s g _ s t a t u s 的 数 量
/ / 按 c r t _ t e m p l a t e 分 组 并 统 计 每 个 非 空 m s g _ s t a t u s 的 数 量
const templateStatusCount = { }
const templateStatusCount = { }
tasksList . forEach ( ( item ) => {
tasksList . forEach ( ( item ) => {
const { crt _template , msg _status } = item
const { crt _template , msg _status , msg _reply } = item
if ( msg _status !== null && msg _status !== undefined ) {
if ( msg _status !== null && msg _status !== undefined ) {
if ( ! templateStatusCount [ crt _template ] ) {
if ( ! templateStatusCount [ crt _template ] ) {
templateStatusCount [ crt _template ] = { }
templateStatusCount [ crt _template ] = { }
templateStatusCount [ crt _template ] [ 'msgreply' ] = 0
}
}
if ( ! templateStatusCount [ crt _template ] [ msg _status ] ) {
if ( ! templateStatusCount [ crt _template ] [ msg _status ] ) {
templateStatusCount [ crt _template ] [ msg _status ] = 0
templateStatusCount [ crt _template ] [ msg _status ] = 0
}
}
templateStatusCount [ crt _template ] [ msg _status ] ++
templateStatusCount [ crt _template ] [ msg _status ] ++
if ( msg _reply ) {
templateStatusCount [ crt _template ] [ 'msgreply' ] ++
}
}
}
} )
} )
/ / 计 算 分 组 后 的 百 分 比 并 添 加 计 数
/ / 计 算 分 组 后 的 百 分 比 并 添 加 计 数
const groupedResult = { }
const groupedResult = { }
for ( const template in templateStatusCount ) {
for ( const template in templateStatusCount ) {
const total = Object . values ( templateStatusCount [ template ] ) . reduce ( ( acc , val ) => acc + val , 0 )
/ / 总 数 需 要 减 去 m s g r e p l y 的 数 量 , m s g r e p l y 是 状 态 之 外 的 数 据
const total = Object . values ( templateStatusCount [ template ] ) . reduce ( ( acc , val ) => acc + val , 0 ) - templateStatusCount [ template ] [ 'msgreply' ]
groupedResult [ template ] = { }
groupedResult [ template ] = { }
for ( const status in templateStatusCount [ template ] ) {
for ( const status in templateStatusCount [ template ] ) {
const count = templateStatusCount [ template ] [ status ]
const count = templateStatusCount [ template ] [ status ]
@ -63,6 +70,7 @@ const Index = () => {
groupedResult [ template ] [ ` ${ status } _count ` ] = count
groupedResult [ template ] [ ` ${ status } _count ` ] = count
groupedResult [ template ] [ ` ${ status } _percentage ` ] = ` ${ percentage } % `
groupedResult [ template ] [ ` ${ status } _percentage ` ] = ` ${ percentage } % `
}
}
console . log ( groupedResult )
}
}
/ / 将 g r o u p e d R e s u l t 转 换 为 表 格 可 用 的 数 据 格 式
/ / 将 g r o u p e d R e s u l t 转 换 为 表 格 可 用 的 数 据 格 式
@ -82,14 +90,17 @@ const Index = () => {
key : 'crt_template' ,
key : 'crt_template' ,
} )
} )
const allStatuses = new Set ( )
const allStatuses = new Set ( ['msgreply' ] )
tasksList . forEach ( ( item ) => {
tasksList . forEach ( ( item ) => {
if ( item . msg _status !== null && item . msg _status !== undefined ) {
if ( item . msg _status !== null && item . msg _status !== undefined ) {
allStatuses . add ( item . msg _status )
allStatuses . add ( item . msg _status )
}
}
} )
} )
allStatuses . forEach ( ( status ) => {
/ / 将 S e t 转 换 为 数 组 并 排 序
const sortedStatuses = Array . from ( allStatuses ) . sort ( )
sortedStatuses . forEach ( ( status ) => {
groupedColumns . push ( {
groupedColumns . push ( {
title : ` ${ status } 计数 ` ,
title : ` ${ status } 计数 ` ,
dataIndex : ` ${ status } _count ` ,
dataIndex : ` ${ status } _count ` ,
@ -160,7 +171,7 @@ const Index = () => {
const icon = statusIconMap [ record . msg _status ] || statusIconMap [ 'default' ]
const icon = statusIconMap [ record . msg _status ] || statusIconMap [ 'default' ]
return (
return (
< Link to = { ` /order/chat/ ${ record . crt _coli _sn } ` } title = { record . errors _code ? record . errors _code + '' + record . errors _title : '' } >
< Link to = { ` /order/chat/ ${ record . crt _coli _sn } ` } title = { record . errors _code ? record . errors _code + '' + record . errors _title : '' } >
查看会话 { icon }
查看会话 { icon } { record . msg _reply ? < MessageTwoTone title = '已回复' / > : '' }
< / Link >
< / Link >
)
)
}
}