index.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * @Author: your name
  3. * @Date: 2021-07-26 10:13:13
  4. * @LastEditTime: 2021-08-28 19:31:21
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
  8. */
  9. // import { PlusOutlined } from '@ant-design/icons';
  10. import {Form,Button} from 'antd';
  11. import React, { useRef, useState, useEffect } from 'react';
  12. import { PageContainer } from '@ant-design/pro-layout';
  13. import ProTable from '@ant-design/pro-table';
  14. import {
  15. ProFormDatePicker,
  16. } from '@ant-design/pro-form';
  17. import { getCostShareList,startAllocation,cancelAllocation } from './service';
  18. import moment from 'moment';
  19. import 'moment/locale/zh-cn';
  20. import locale from 'antd/es/date-picker/locale/zh_CN';
  21. const CostShare = () => {
  22. const [currentTime, setCurrentTime] = useState(moment(new Date()).subtract(1,'months').format('YYYY-MM'));
  23. const columns = [
  24. {
  25. title: '选择年月',
  26. key: 'date',
  27. hideInTable: true,
  28. dataIndex: 'date',
  29. renderFormItem: (item, {type, defaultRender,formItemProps, fieldProps, ...rest }, form) => {
  30. if (type === 'form') {
  31. return null;
  32. }
  33. return (
  34. <Form.Item >
  35. <ProFormDatePicker initialValue={currentTime}
  36. fieldProps={{
  37. picker:'month',format:(value)=>{return value.format('YYYY-MM')},locale:locale,
  38. onChange:(val)=>{console.log({val});setCurrentTime(val)}
  39. }}
  40. name="date" />
  41. </Form.Item>
  42. )
  43. },
  44. },
  45. {
  46. title: '年份',
  47. dataIndex: 'year',
  48. key: 'year',
  49. hideInSearch: true,
  50. },
  51. {
  52. title: '月份',
  53. dataIndex: 'month',
  54. key: 'month',
  55. hideInSearch: true,
  56. },
  57. {
  58. title: '金额',
  59. dataIndex: 'amount',
  60. key: 'amount',
  61. hideInSearch: true,
  62. },
  63. {
  64. title: '是否分摊',
  65. dataIndex: 'isAllocation',
  66. key: 'isAllocation',
  67. hideInSearch: true,
  68. render:bool=>bool?'已分摊':'未分摊'
  69. },
  70. {
  71. title:'操作',
  72. dataIndex: 'option',
  73. valueType: 'option',
  74. key: 'option',
  75. width: '15%',
  76. render: (_, record) =>{
  77. const {isAllocation} = record;
  78. return [
  79. <Button
  80. key="config"
  81. size='small'
  82. // disabled={isAllocation}
  83. type={isAllocation?'default':'primary'}
  84. onClick={() => {
  85. setCurrentRow(record);
  86. optionBtnGroupshandle(isAllocation,record);
  87. }}
  88. >
  89. <span style={{fontSize:12}}>{isAllocation?'撤销分摊':'开始分摊'}</span>
  90. </Button>
  91. ]
  92. },
  93. },
  94. ];
  95. const actionRef = useRef();
  96. const [currentRow,setCurrentRow] = useState(undefined);
  97. //获取列表
  98. const getList = async (params = {}, sort, filter) => {
  99. const {date,pageSize,current} = params;
  100. const res = await getCostShareList({pageSize,current,date:moment(date).format('YYYY-MM-DD')});
  101. if(res&&res.status){
  102. return {
  103. data: res.data.list,
  104. total: res.data.totalCount,
  105. success: res.success,
  106. };
  107. }
  108. };
  109. const optionBtnGroupshandle = async (isAllocation,record)=>{
  110. if(!isAllocation){
  111. //开始分摊
  112. await startAllocation({year:currentTime.format('YYYY'),month:currentTime.format('MM')});
  113. }
  114. if(isAllocation){
  115. //撤销分摊
  116. await cancelAllocation({year:currentTime.format('YYYY'),month:currentTime.format('MM')});
  117. }
  118. actionRef?.current?.reload();
  119. }
  120. return (
  121. <PageContainer>
  122. <ProTable
  123. columns={columns}
  124. request={getList}
  125. actionRef={actionRef}
  126. rowKey="id"
  127. toolBarRender={() => [
  128. ]}
  129. pagination={{
  130. pageSize: 10,
  131. }}
  132. search={{
  133. defaultCollapsed: false,
  134. labelWidth: 'auto',
  135. }}
  136. />
  137. </PageContainer>
  138. );
  139. };
  140. export default CostShare;