index.jsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import BasicTable from '@/components/Table'
  2. import consts from '@/consts'
  3. import { querySoftInvoiceTrendsList } from '@/services/statistic'
  4. import { DualAxes } from '@ant-design/charts'
  5. import { DatePicker, Select } from 'antd'
  6. import dayjs from 'dayjs'
  7. import React, { useRef, useState } from 'react'
  8. import OptionSelect from '../../components/OptionSelect'
  9. const InvoiceTrends = () => {
  10. const [state, setState] = useState({
  11. params: {
  12. optionType: 'staff',
  13. dataIds: [],
  14. priceType: 'invoice',
  15. startMonth: [dayjs(new Date()), dayjs(new Date())]
  16. },
  17. chart: []
  18. })
  19. const tRef = useRef(null)
  20. const columns = [
  21. {
  22. dataIndex: 'name',
  23. title: '姓名',
  24. align: 'center',
  25. render: (value, _, idx) => {
  26. const obj = {
  27. children: value,
  28. props: {}
  29. }
  30. if (idx == 0) {
  31. obj.props.rowSpan = 2
  32. }
  33. if (idx == 1) {
  34. obj.props.rowSpan = 0
  35. }
  36. return obj
  37. }
  38. },
  39. {
  40. dataIndex: 'options',
  41. title: '项',
  42. align: 'center'
  43. },
  44. {
  45. dataIndex: 'month_1',
  46. title: '1月',
  47. align: 'center',
  48. render: text => <div className="text-right">{text}</div>
  49. },
  50. {
  51. dataIndex: 'month_2',
  52. title: '2月',
  53. align: 'center',
  54. render: text => <div className="text-right">{text}</div>
  55. },
  56. {
  57. dataIndex: 'month_3',
  58. title: '3月',
  59. align: 'center',
  60. render: text => <div className="text-right">{text}</div>
  61. },
  62. {
  63. dataIndex: 'month_4',
  64. title: '4月',
  65. align: 'center',
  66. render: text => <div className="text-right">{text}</div>
  67. },
  68. {
  69. dataIndex: 'month_5',
  70. title: '5月',
  71. align: 'center',
  72. render: text => <div className="text-right">{text}</div>
  73. },
  74. {
  75. dataIndex: 'month_6',
  76. title: '6月',
  77. align: 'center',
  78. render: text => <div className="text-right">{text}</div>
  79. },
  80. {
  81. dataIndex: 'month_7',
  82. title: '7月',
  83. align: 'center',
  84. render: text => <div className="text-right">{text}</div>
  85. },
  86. {
  87. dataIndex: 'month_8',
  88. title: '8月',
  89. align: 'center',
  90. render: text => <div className="text-right">{text}</div>
  91. },
  92. {
  93. dataIndex: 'month_9',
  94. title: '9月',
  95. align: 'center',
  96. render: text => <div className="text-right">{text}</div>
  97. },
  98. {
  99. dataIndex: 'month_10',
  100. title: '10月',
  101. align: 'center',
  102. render: text => <div className="text-right">{text}</div>
  103. },
  104. {
  105. dataIndex: 'month_11',
  106. title: '11月',
  107. align: 'center',
  108. render: text => <div className="text-right">{text}</div>
  109. },
  110. {
  111. dataIndex: 'month_12',
  112. title: '12月',
  113. align: 'center',
  114. render: text => <div className="text-right">{text}</div>
  115. }
  116. ]
  117. const optionChange = (type, ids) =>
  118. setState({ ...state, params: { ...state.params, optionType: type, dataIds: ids } })
  119. const dualAxesOptions = {
  120. data: [state.chart, state.chart],
  121. xField: 'monthName',
  122. yField: ['price', 'ring'],
  123. appendPadding: [0, 24, 12, 24],
  124. meta: {
  125. price: {
  126. alias: '当月开票金额(元)'
  127. },
  128. ring: {
  129. alias: '环比增长(%)',
  130. formatter: v => `${v}%`,
  131. tickInterval: 100
  132. }
  133. // month: {
  134. // formatter: v => `${v}月`
  135. // }
  136. },
  137. yAxis: {
  138. price: {
  139. label: {
  140. formatter: v => {
  141. return `${v}元`
  142. }
  143. }
  144. },
  145. ring: {
  146. min: -100
  147. }
  148. },
  149. legend: {
  150. position: 'top',
  151. itemName: {
  152. formatter: (_, item) => {
  153. return item.value === 'price' ? '当月开票金额(元)' : '环比增长(%)'
  154. }
  155. }
  156. },
  157. geometryOptions: [
  158. {
  159. geometry: 'column',
  160. color: '#A7D2F9'
  161. },
  162. {
  163. geometry: 'line',
  164. smooth: true,
  165. color: '#C4E9C1'
  166. }
  167. ],
  168. interactions: [
  169. {
  170. type: 'element-highlight'
  171. },
  172. {
  173. type: 'active-region'
  174. }
  175. ]
  176. }
  177. return (
  178. <div className="flex flex-col">
  179. <div className="flex flex-row justify-between mb-4">
  180. <div className="card-transition bg-white w-full">
  181. {state.chart?.length ? <DualAxes {...dualAxesOptions} /> : null}
  182. {/* {pieData.pieLeft ? <Pie {...leftConfig} /> : null} */}
  183. {/* {state.list?.length ? <Column {...columnConfig} /> : null} */}
  184. </div>
  185. </div>
  186. <BasicTable
  187. // manualRequest
  188. search={false}
  189. params={state.params}
  190. columns={columns}
  191. actionRef={tRef}
  192. rowkey="id"
  193. toolbar={{
  194. title: [
  195. <OptionSelect onChange={optionChange} type="InvoiceTrends" key="op" multiple={false} />,
  196. <div className="ml-2" key="pp">
  197. <Select
  198. defaultValue="invoice"
  199. options={[
  200. { label: '发票', value: 'invoice' },
  201. { label: '收款', value: 'receivables' },
  202. { label: '入账', value: 'credit' }
  203. ]}
  204. placeholder="请选择发票类型"
  205. onChange={e => setState({ ...state, params: { ...state.params, priceType: e } })}
  206. />
  207. </div>
  208. ],
  209. actions: [
  210. <DatePicker.RangePicker
  211. picker="month"
  212. key="DatePicker"
  213. disabled={[false, true]}
  214. value={state.startMonth}
  215. onChange={val => setState({ ...state, params: { ...state.params, startMonth: val } })}
  216. />
  217. ]
  218. }}
  219. pagination={false}
  220. bordered
  221. request={async (params, sort, filter) => {
  222. const {
  223. code = -1,
  224. data: { list, chart }
  225. } = await querySoftInvoiceTrendsList({
  226. ...params,
  227. ...sort,
  228. ...filter
  229. })
  230. console.log(chart)
  231. setState({ ...state, chart })
  232. return {
  233. data: list,
  234. success: code === consts.RET_CODE.SUCCESS,
  235. total: list?.length || 0
  236. }
  237. }}
  238. />
  239. </div>
  240. )
  241. }
  242. export default InvoiceTrends