index.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import BasicTable from '@/components/Table'
  2. import consts from '@/consts'
  3. import { querySoftInvoiceAggregateList } from '@/services/statistic'
  4. import { disabledDate } from '@/utils/utils'
  5. import { Column } from '@ant-design/charts'
  6. import { PageContainer } from '@ant-design/pro-layout'
  7. import { Table, DatePicker } from 'antd'
  8. import dayjs from 'dayjs'
  9. import React, { useRef, useState } from 'react'
  10. import OptionSelect from '../../components/OptionSelect'
  11. const columnGroupMap = {
  12. invoicePrice: '开票金额',
  13. receivablesPrice: '收款金额',
  14. creditPrice: '入账金额'
  15. }
  16. const InvoiceAggregate = () => {
  17. const [state, setState] = useState({
  18. params: {
  19. optionType: 'staff',
  20. dataIds: [],
  21. startMonth: [dayjs(new Date()), dayjs(new Date())]
  22. },
  23. list: []
  24. })
  25. const tRef = useRef(null)
  26. const columns = [
  27. {
  28. dataIndex: 'name',
  29. title: '名称',
  30. align: 'center'
  31. },
  32. {
  33. dataIndex: 'invoicePrice',
  34. title: '开票金额(元)',
  35. align: 'center',
  36. render: text => <div className="text-right">{text}</div>
  37. },
  38. {
  39. dataIndex: 'receivablesPrice',
  40. title: '收款金额(元)',
  41. align: 'center',
  42. render: text => <div className="text-right">{text}</div>
  43. },
  44. {
  45. dataIndex: 'creditPrice',
  46. title: '入账金额(元)',
  47. align: 'center',
  48. render: text => <div className="text-right">{text}</div>
  49. }
  50. ]
  51. const handleOptionChange = (type, ids) =>
  52. setState({ ...state, params: { ...state.params, optionType: type, dataIds: ids } })
  53. const columnConfig = {
  54. data: state.list.reduce((prev, curr) => {
  55. const newList = [...prev]
  56. const keys = Object.keys(curr)
  57. keys.forEach(key => {
  58. if (key !== 'name' && key !== 'id') {
  59. newList.push({
  60. department: curr.name,
  61. type: columnGroupMap[key],
  62. value: parseInt(curr[key])
  63. })
  64. }
  65. })
  66. return newList
  67. }, []),
  68. isGroup: true,
  69. autoFit: true,
  70. // padding: 'auto',
  71. // dodgePadding: 2,
  72. appendPadding: [23, 32, 24, 32],
  73. xField: 'department',
  74. yField: 'value',
  75. seriesField: 'type',
  76. legend: {
  77. position: 'top'
  78. },
  79. color: ['#A7D2F9', '#C4E9C1', '#E9C8C1'],
  80. colorField: 'type'
  81. }
  82. return (
  83. <PageContainer title={false} breadcrumb={false} waterMarkProps={{ offsetTop: 111 }}>
  84. <div className="flex flex-col">
  85. <div className="flex flex-row justify-between mb-4">
  86. <div className="card-transition bg-white w-full">
  87. {/* {pieData.pieLeft ? <Pie {...leftConfig} /> : null} */}
  88. {state.list?.length ? <Column {...columnConfig} /> : null}
  89. </div>
  90. </div>
  91. <BasicTable
  92. // manualRequest
  93. search={false}
  94. columns={columns}
  95. actionRef={tRef}
  96. rowkey="id"
  97. toolbar={{
  98. title: <OptionSelect onChange={handleOptionChange} type="InvoiceAggregate" />,
  99. actions: [
  100. <DatePicker.RangePicker
  101. allowClear={false}
  102. picker="month"
  103. key="DatePicker"
  104. clo
  105. disabledDate={current => disabledDate(current, 'month')}
  106. // disabled={[false, true]}
  107. value={state.params.startMonth}
  108. onChange={val => setState({ ...state, params: { ...state.params, startMonth: val } })}
  109. />
  110. ]
  111. }}
  112. params={state.params}
  113. pagination={false}
  114. bordered
  115. request={async (params, sort, filter) => {
  116. const {
  117. code = -1,
  118. data: { list, sum }
  119. } = await querySoftInvoiceAggregateList({ ...params, ...sort, ...filter })
  120. setState({ ...state, sum, list })
  121. return {
  122. data: list,
  123. success: code === consts.RET_CODE.SUCCESS,
  124. total: list?.length || 0
  125. }
  126. }}
  127. summary={data =>
  128. data?.length ? (
  129. <>
  130. <Table.Summary.Row>
  131. <Table.Summary.Cell className="text-center">{state.sum?.name}</Table.Summary.Cell>
  132. <Table.Summary.Cell className="text-right">{state.sum?.invoicePrice}</Table.Summary.Cell>
  133. <Table.Summary.Cell className="text-right">
  134. {state.sum?.receivablesPrice}
  135. </Table.Summary.Cell>
  136. <Table.Summary.Cell className="text-right">{state.sum?.creditPrice}</Table.Summary.Cell>
  137. </Table.Summary.Row>
  138. </>
  139. ) : null
  140. }
  141. />
  142. </div>
  143. </PageContainer>
  144. )
  145. }
  146. export default InvoiceAggregate