index.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-03-31 13:23:29
  6. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/pubDicTypeMana/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import BMSPagecontainer from '@/components/BMSPageContainer';
  10. import { BMSTable } from '@/components/BMSTable';
  11. import { ActionType } from '@ant-design/pro-components';
  12. import { ModalForm, ProFormDigit } from '@ant-design/pro-form'
  13. import { ProColumns } from '@ant-design/pro-table';
  14. import { message } from 'antd';
  15. import { useEffect, useRef, useState } from 'react'
  16. import {editData, getData } from './service';
  17. import './style.less';
  18. export default function ClassAssessAndGradeSet() {
  19. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  20. const [tableColumn, set_tableColumn] = useState<ProColumns[] | any[]>([]);
  21. const [respColumns,set_respColumns ] = useState([]);
  22. const tableRef = useRef<ActionType>();
  23. const getTableData = async (params: any) => {
  24. const resp = await getData(params);
  25. if (resp) {
  26. const { title, unitTypeData } = resp;
  27. const columns = title.map((item: any) => {
  28. if (item.children) {
  29. const children = item.children.map((a: any) => ({
  30. title: a.name,
  31. dataIndex: `${a.code}${item.code}`,
  32. }))
  33. return {
  34. title: item.name,
  35. dataIndex: `${item.code}`,
  36. key: `${item.code}`,
  37. // width: 140,
  38. children: children
  39. }
  40. } else {
  41. return {
  42. title: item.name,
  43. dataIndex: `${item.code}`,
  44. key: `${item.code}`,
  45. // width: 140,
  46. }
  47. }
  48. });
  49. set_respColumns(columns);
  50. set_tableColumn([{
  51. title: '职类',
  52. dataIndex: 'unitTypeName',
  53. key: 'unitTypeName',
  54. width: 140,
  55. fixed: 'left',
  56. }, ...columns, {
  57. title: '操作',
  58. key: 'option',
  59. // width: 120,
  60. valueType: 'option',
  61. render: (_: any, record: any) => {
  62. return [
  63. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  64. ]
  65. },
  66. },]);
  67. const data = unitTypeData.map((item: any) => {
  68. let rowData: { [key: string]: any } = {};
  69. for (let index = 0; index < item.value.length; index++) {
  70. for (const key in item.value[index]) {
  71. if (key != 'code') {
  72. rowData[`${key}${item.value[index].code}`] = item.value[index][`${key}`]
  73. }
  74. }
  75. }
  76. return { ...item, ...rowData, id: item.id, columns }
  77. });
  78. return {
  79. data,
  80. success: true
  81. }
  82. }
  83. return []
  84. }
  85. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  86. let result = {
  87. unitTypeCode:formVal.unitTypeCode,
  88. unitTypeName:formVal.unitTypeName,
  89. value:formVal.record.columns.map((a:any)=>{
  90. return ({
  91. code:a.key,
  92. floor:formVal[`floor${a.key}`],
  93. rate:formVal[`rate${a.key}`],
  94. ceiling:formVal[`ceiling${a.key}`],
  95. })
  96. })
  97. }
  98. if (type == 'EDIT') {
  99. const resp = await editData(result);
  100. if (resp) {
  101. tableRef.current?.reload();
  102. message.success('操作成功!');
  103. }
  104. }
  105. return true;
  106. }
  107. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  108. const [formData,set_formData] = useState([]);
  109. useEffect(()=>{
  110. if(record.columns.length != record.value.length){
  111. const valueCodes = record.value.map((a:any)=>a.key);
  112. const newData = record.columns.map((b:any)=>{
  113. if(!valueCodes.includes(b.key)){
  114. return {
  115. code:b.key,
  116. floor:'',
  117. range:'',
  118. rate:''
  119. }
  120. }
  121. const temp = record.value.filter((c:any)=>c.code == b.key);
  122. return temp[0]
  123. });
  124. set_formData(newData);
  125. }else{
  126. set_formData(record.value);
  127. }
  128. },[record])
  129. return (
  130. <ModalForm
  131. title={`考核分级设定(${record.unitTypeName})`}
  132. className='ClassAssessAndGradeSet-ModalForm'
  133. width={400}
  134. initialValues={type == 'EDIT' ? { ...record } : {}}
  135. trigger={
  136. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  137. }
  138. onFinish={(val) => {
  139. // console.log({val});
  140. return updateTable(type == 'EDIT' ? {unitTypeCode:record.unitTypeCode,unitTypeName:record.unitTypeName,value:record.value, ...val,record} : { ...val }, type);
  141. }}
  142. >
  143. <div className='tip'>区间的上限及下限至少填写一个,没填表示无</div>
  144. {
  145. formData.map((item: any, index: number) => {
  146. let label = record.columns.filter((a:any) => a.key == item.code);
  147. return (
  148. <div className='list' key={index}>
  149. <div className='label'>{label.length > 0 ? `${label[0].title}:` : ''}</div>
  150. <div className='wrap'>
  151. <ProFormDigit width={100} name={`floor${item.code}`} placeholder='分数下限' />
  152. <ProFormDigit width={100} name={`ceiling${item.code}`} placeholder='分数上限' />
  153. <ProFormDigit width={144} name={`rate${item.code}`} placeholder='奖惩系数' />
  154. </div>
  155. </div>
  156. )
  157. })
  158. }
  159. </ModalForm>
  160. )
  161. }
  162. useEffect(() => {
  163. }, [])
  164. return (
  165. <BMSPagecontainer className='ClassAssessAndGradeSet' title={'职类考核分级设定'}>
  166. <div style={{ marginTop: 16 }}>
  167. <BMSTable actionRef={tableRef} bordered rowKey='unitTypeCode' pagination={false} columns={tableColumn as ProColumns[]} params={tableDataFilterParams} request={(params) => getTableData(params)} />
  168. </div>
  169. </BMSPagecontainer>
  170. )
  171. }