index.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2024-05-07 13:41:37
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2024-06-21 14:54:24
  6. * @FilePath: /BudgetManaSystem/src/pages/budgetMana/personnelSalaryBudget/components/cardList/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import { createFromIconfontCN } from '@ant-design/icons';
  10. import { useEffect, useState } from 'react';
  11. import { InputNumber,message,Modal } from 'antd'
  12. import './style.less'
  13. import { copyReq, getKpiRetainList, saveKpiRetain } from '../../service';
  14. const IconFont = createFromIconfontCN({
  15. scriptUrl: '',
  16. });
  17. const formatValue = (value:number) => {
  18. if (value !== undefined && value !== null) {
  19. return parseFloat(value.toString().replace(/(\.\d*?[1-9])0+$/g, '$1').replace(/\.0*$/, ''));
  20. }
  21. return value;
  22. };
  23. function removeTrailingZeros(str:string) {
  24. // 将数字转换为字符串,并去掉多余的0
  25. return str.replace(/(\.\d*?[1-9])0+$/g, '$1').replace(/\.0*$/, '');
  26. }
  27. export const CardList = ({ computeDate }: { computeDate: string }) => {
  28. const [listData, set_listData] = useState<any[]>([]);
  29. const [currentEdit, set_currentEdit] = useState<any>(undefined);
  30. const [currentEditGroup, set_currentEditGroup] = useState<any>(undefined);
  31. const [inputVal, set_inputVal] = useState(0);
  32. const editHandle = (group: any, current: any) => {
  33. if (currentEdit) {
  34. const newArr = listData.map((a) => {
  35. if (a.unitTypeCode === currentEditGroup.unitTypeCode) {
  36. const newRetainList = a.retainList.map((b:any) => {
  37. if (b.code === currentEdit.code) {
  38. return { ...b, value: inputVal };
  39. } else {
  40. return b;
  41. }
  42. });
  43. // 返回更新后的整个对象a,包括新的retainList和其他属性
  44. return { ...a, retainList: newRetainList };
  45. } else {
  46. return a;
  47. }
  48. });
  49. set_listData([...newArr]);
  50. savaData(newArr);
  51. set_currentEditGroup(undefined);
  52. set_currentEdit(undefined); return;
  53. } else {
  54. set_currentEdit({...current,flag:`${group.unitTypeCode}${current.code}`});
  55. set_currentEditGroup(group);
  56. }
  57. }
  58. const getData = async () => {
  59. const resp = await getKpiRetainList(computeDate);
  60. if (resp) {
  61. set_listData(resp);
  62. }
  63. }
  64. const onChangeHandle = (value: any) => {
  65. if (value !== undefined && value !== null) {
  66. // 将值转换为字符串并去掉无效的零
  67. const formattedValue = parseFloat(value.toString().replace(/(\.\d*?[1-9])0+$/g, '$1').replace(/\.0*$/, ''));
  68. set_inputVal(formattedValue);
  69. } else {
  70. set_inputVal(value);
  71. }
  72. }
  73. const savaData = async (newData:any)=>{
  74. const resp = await saveKpiRetain({
  75. computeDate,
  76. list:newData
  77. });
  78. if(resp){
  79. message.success('操作成功!');
  80. }
  81. }
  82. const copyReqHandle = async ()=>{
  83. Modal.confirm({
  84. title:'注意',
  85. content:'复制操作会覆盖已有的保留系数设定,确定要继续操作?',
  86. okText:'确定',
  87. cancelText:'取消',
  88. onOk:async (...args) => {
  89. const resp = await copyReq(computeDate);
  90. if(resp){
  91. message.success('复制成功!');
  92. getData();
  93. }
  94. },
  95. })
  96. }
  97. useEffect(() => {
  98. getData();
  99. // set_listData([
  100. // {
  101. // unitTypeName:'临床医生',
  102. // retainList:[
  103. // {
  104. // name:'季度考核',
  105. // value:1,
  106. // code:1
  107. // },
  108. // {
  109. // name:'季度考核',
  110. // value:1,
  111. // code:2
  112. // }
  113. // ]
  114. // },
  115. // {
  116. // unitTypeName:'临床医生',
  117. // retainList:[
  118. // {
  119. // name:'季度考核',
  120. // value:1,
  121. // code:3
  122. // },
  123. // ]
  124. // }
  125. // ])
  126. }, [])
  127. return (
  128. <div className="CardList">
  129. <div className="header">
  130. <span className="title">保留系数设定</span>
  131. <a className='copyBtn' onClick={()=>copyReqHandle()}> <IconFont style={{ color: '#3377FF', paddingRight: 4,fontSize:16 }} type="iconfuzhi1" />复制上月</a>
  132. </div>
  133. <div className='content'>
  134. {
  135. listData.map((a, index) => (
  136. <div className='group' key={index}>
  137. <div className='groupName'>{a.unitTypeName}</div>
  138. <div className='listWrap'>
  139. {
  140. a.retainList.map((b: any, i: number) => (
  141. <div className='list' key={i}>
  142. <div className='name'>
  143. <img src={require(`../../../../../../static/${b.type == 1 ? 'textImg_xi.png' : 'textImg_zhi.png'}`)} alt="" />
  144. {b.name}
  145. </div>
  146. <div className='detail'>
  147. {currentEdit?.flag != `${a.unitTypeCode}${b.code}` && <span className='num'>{b.type == 1?(removeTrailingZeros((b.value * 100).toFixed(4))+'%'):removeTrailingZeros((b.value).toFixed(2))}</span>}
  148. {currentEdit?.flag == `${a.unitTypeCode}${b.code}` && <InputNumber precision={b.type == 1 ? 4 : 2} min={0} max={b.type == 1?1:10000000000} style={{ width: 160 }} autoFocus defaultValue={formatValue(b.value)} onChange={onChangeHandle} />}
  149. <div className='actIcon'><IconFont style={{ color: '#17181A', cursor: 'pointer' }} onClick={() => editHandle(a, b)} type={currentEdit?.flag != `${a.unitTypeCode}${b.code}` ? 'icon-xiugai' : 'icon-queren'} /></div>
  150. </div>
  151. </div>
  152. ))
  153. }
  154. </div>
  155. </div>
  156. ))
  157. }
  158. </div>
  159. </div>
  160. )
  161. }