index.jsx 3.9 KB

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