index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import GroupWxTabs from '@/components/GroupWxTabs'
  2. import { columns } from './tableConfig'
  3. import React, { useCallback, useEffect, useRef, useState } from 'react'
  4. import { useModel } from 'umi'
  5. import { AdProfit } from '@/services/operating/adCensus'
  6. import { Button, Card, Col, DatePicker, Row, Select, Space, Table, Tag, Tooltip } from 'antd'
  7. import './index.less'
  8. import moment from 'moment'
  9. import { quanpin } from '@/utils/fullScreen'
  10. import { FullscreenExitOutlined, FullscreenOutlined } from '@ant-design/icons'
  11. function DataCensus() {
  12. const { getAdProfit, getxcxAll } = useModel('useOperating.useAdCensus')
  13. const { state: userState } = useModel('useOperating.useUser')
  14. const { getWxGroupAll, state, getAllOfMember } = useModel('useOperating.useWxGroupList', model => ({ getWxGroupAll: model.getDataList, ...model }))
  15. const [xcxData, setxcxData] = useState<{ appId: string, appName: string, type: number }[]>([]) // 保存所有小程序信息
  16. const [queryForm, setQueryForm] = useState<AdProfit>({ page: 1, size: 20 })
  17. const [accData, setAccData] = useState<any[]>([])
  18. const { isFell } = userState
  19. const ref = useRef(null)
  20. // 获取小程序列表
  21. useEffect(() => {
  22. getxcxAll.run().then((res: any) => {
  23. setxcxData(res?.data)
  24. })
  25. }, [])
  26. // 获取表格列表
  27. useEffect(() => {
  28. if (queryForm?.userId) {
  29. let newQueryForm: any = {}
  30. let { appId, startTime, endTime, userId, page, size, mpName, type } = queryForm
  31. appId && (newQueryForm['appId'] = appId)
  32. startTime && (newQueryForm['startTime'] = startTime)
  33. endTime && (newQueryForm['endTime'] = endTime)
  34. userId && (newQueryForm['userId'] = userId)
  35. page && (newQueryForm['page'] = page)
  36. size && (newQueryForm['size'] = size)
  37. mpName && (newQueryForm['mpName'] = mpName)
  38. type && (newQueryForm['type'] = type)
  39. getAdProfit.run({ ...newQueryForm })
  40. }
  41. }, [queryForm])
  42. // 选中人员id变动
  43. useEffect(() => {
  44. setQueryForm(() => ({ ...queryForm, page: 1, userId: userState?.selectdUserId }))
  45. }, [userState?.selectdUserId])
  46. /** 表格分页onChange */
  47. const paginationOnChange = (page: number, pageSize?: number | undefined) => {
  48. setQueryForm({ ...queryForm, page, size: pageSize || 20 })
  49. }
  50. // 开始日期不可选择日期
  51. const disabledStartDate = useCallback((current: any) => {
  52. if (queryForm?.endTime) {
  53. return current && current > moment(queryForm?.endTime)
  54. }
  55. }, [queryForm?.endTime])
  56. // 结束日期不可选择日期
  57. const disabledEndDate = useCallback((current: any) => {
  58. if (queryForm?.startTime) {
  59. return current && current < moment(queryForm?.startTime)
  60. }
  61. }, [queryForm?.startTime])
  62. useEffect(() => {
  63. if (state?.tabsKey === '自己') {
  64. let newAccData: any[] = []
  65. getWxGroupAll?.data?.forEach((item: { mpAccounts: any[] }) => {
  66. if (item?.mpAccounts?.length > 0) {
  67. newAccData = [...newAccData, ...item?.mpAccounts]
  68. }
  69. })
  70. setAccData(() => newAccData)
  71. } else {
  72. let newAccData = getAllOfMember?.data?.find((item: any) => item?.key?.userId === Number(userState?.selectdUserId))
  73. if (newAccData) {
  74. setAccData(() => newAccData?.value)
  75. } else {
  76. setAccData(() => [])
  77. }
  78. }
  79. }, [userState?.selectdUserId, getWxGroupAll?.data, state?.tabsKey, getAllOfMember?.data])
  80. return <div className="dataCensus">
  81. <GroupWxTabs height='calc(100vh - 180px)' allowClear={false}>
  82. <Row gutter={[0, 20]} ref={ref} style={isFell ? { background: '#fff' } : {}}>
  83. <Col span={24}>
  84. <Card
  85. hoverable
  86. title={"小程序广告数据"}
  87. headStyle={{ textAlign: 'center' }}
  88. >
  89. <div style={{ display: 'flex', justifyContent: 'space-between' }}>
  90. <Space wrap style={{ marginBottom: 10 }}>
  91. <Select style={{ width: 180 }} showSearch value={queryForm?.appId} onChange={(e) => { setQueryForm({ ...queryForm, appId: e, page: 1 }) }} placeholder="请选择小程序" allowClear>
  92. {xcxData?.map((item: { appId: string, appName: string, type: number }, index: number) => <Select.Option value={item.appId} key={index}>{item.appName}</Select.Option>)}
  93. </Select>
  94. <Select style={{ width: 180 }} value={queryForm?.type} onChange={(e) => { setQueryForm({ ...queryForm, type: e, page: 1 }) }} placeholder="请选择类型" allowClear>
  95. <Select.Option value={1} >运营</Select.Option>
  96. <Select.Option value={2} >投手</Select.Option>
  97. </Select>
  98. <DatePicker
  99. onChange={(e: moment.Moment | null) => { setQueryForm({ ...queryForm, startTime: e ? moment(e).format('YYYY-MM-DD') : "", page: 1 }) }}
  100. value={queryForm?.startTime ? moment(queryForm?.startTime) : null}
  101. placeholder="请选择开始日期"
  102. disabledDate={disabledStartDate}
  103. />
  104. <DatePicker
  105. onChange={(e: moment.Moment | null) => { setQueryForm({ ...queryForm, endTime: e ? moment(e).format('YYYY-MM-DD') : "", page: 1 }) }}
  106. value={queryForm?.endTime ? moment(queryForm?.endTime) : null}
  107. placeholder="请选择结束日期"
  108. disabledDate={disabledEndDate}
  109. />
  110. <Select
  111. style={{ width: 185 }}
  112. placeholder="请选择公众号"
  113. onChange={(value: any) => { setQueryForm({ ...queryForm, mpName: value, page: 1 }) }}
  114. allowClear
  115. showSearch
  116. >
  117. {
  118. accData?.map((list: any, eq: number) => {
  119. return <Select.Option key={list?.id} value={list?.nickName}>
  120. {list?.nickName}
  121. </Select.Option>
  122. })
  123. })
  124. </Select>
  125. <Button type="primary" onClick={() => { getAdProfit.refresh() }}>查询</Button>
  126. </Space>
  127. <Button
  128. type='text'
  129. size='small'
  130. onClick={() => {
  131. if (ref?.current) {
  132. quanpin(ref?.current)
  133. }
  134. }}>
  135. {
  136. <Tooltip title={!isFell ? '全屏' : '退出全屏'}>{!isFell ? <FullscreenOutlined /> : <FullscreenExitOutlined />}</Tooltip>
  137. }
  138. </Button>
  139. </div>
  140. <Table
  141. size="small"
  142. loading={getAdProfit.loading}
  143. dataSource={getAdProfit?.data?.data?.bannerMpIncomeDtoList}
  144. columns={columns()}
  145. bordered
  146. scroll={{ x: 1100 }}
  147. rowKey={(record) => { return record?.id }}
  148. pagination={{
  149. current: queryForm.page,
  150. pageSize: queryForm.size,
  151. total: getAdProfit?.data?.data?.totalCount,
  152. showSizeChanger: true,
  153. pageSizeOptions: ['10', '20', '50', '70', '100'],
  154. showTotal: (total) => <Tag color="cyan">总共{total}数据</Tag>,
  155. onChange: paginationOnChange
  156. }}
  157. summary={() => {
  158. return (
  159. <Table.Summary.Row style={{ backgroundColor: '#fafafa' }}>
  160. <Table.Summary.Cell index={0}>
  161. <div style={{ textAlign: 'right', fontWeight: 600, marginRight: 30, fontSize: 14 }}>合计总收入</div>
  162. </Table.Summary.Cell>
  163. <Table.Summary.Cell index={0} colSpan={4}>
  164. <div></div>
  165. </Table.Summary.Cell>
  166. <Table.Summary.Cell index={1} >
  167. <div style={{ fontSize: 18, color: 'rgb(0 14 183', textAlign: 'center', fontWeight: 600 }}>{getAdProfit?.data?.data?.totalPv || 0.00}</div>
  168. </Table.Summary.Cell>
  169. <Table.Summary.Cell index={1} >
  170. <div style={{ fontSize: 18, color: 'rgb(0 14 183', textAlign: 'center', fontWeight: 600 }}>{getAdProfit?.data?.data?.totalNewUserCount || 0.00}</div>
  171. </Table.Summary.Cell>
  172. <Table.Summary.Cell index={1} >
  173. <div style={{ fontSize: 18, color: 'rgb(0 14 183', textAlign: 'center', fontWeight: 600 }}>{getAdProfit?.data?.data?.totalOldUserCount || 0.00}</div>
  174. </Table.Summary.Cell>
  175. <Table.Summary.Cell index={1} >
  176. <div style={{ fontSize: 18, color: 'rgb(0 14 183', textAlign: 'center', fontWeight: 600 }}>{getAdProfit?.data?.data?.totalUv || 0.00}</div>
  177. </Table.Summary.Cell>
  178. <Table.Summary.Cell index={1} >
  179. <div style={{ fontSize: 18, color: 'rgb(0 14 183', textAlign: 'center', fontWeight: 600 }}>{getAdProfit?.data?.data?.avgArpu || 0.00}</div>
  180. </Table.Summary.Cell>
  181. <Table.Summary.Cell index={1} >
  182. <div style={{ fontSize: 18, color: 'rgb(0 14 183', textAlign: 'center', fontWeight: 600 }}>{getAdProfit?.data?.data?.totalIncome || 0.00}</div>
  183. </Table.Summary.Cell>
  184. </Table.Summary.Row>
  185. );
  186. }}
  187. />
  188. </Card>
  189. </Col>
  190. </Row >
  191. </GroupWxTabs>
  192. </div>
  193. }
  194. export default React.memo(DataCensus)