index.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-09-27 16:38:25
  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. if(item.value){
  70. for (let index = 0; index < item.value.length; index++) {
  71. for (const key in item.value[index]) {
  72. if (key != 'code') {
  73. rowData[`${key}${item.value[index].code}`] = item.value[index][`${key}`]
  74. }
  75. }
  76. }
  77. }
  78. return { ...item, ...rowData, id: item.id, columns }
  79. });
  80. return {
  81. data,
  82. success: true
  83. }
  84. }
  85. return []
  86. }
  87. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  88. let result = {
  89. unitTypeCode:formVal.unitTypeCode,
  90. unitTypeName:formVal.unitTypeName,
  91. value:formVal.record.columns.map((a:any)=>{
  92. return ({
  93. code:a.key,
  94. floor:formVal[`floor${a.key}`],
  95. rate:formVal[`rate${a.key}`],
  96. ceiling:formVal[`ceiling${a.key}`],
  97. })
  98. })
  99. }
  100. if (type == 'EDIT') {
  101. const resp = await editData(result);
  102. if (resp) {
  103. tableRef.current?.reload();
  104. message.success('操作成功!');
  105. }
  106. }
  107. return true;
  108. }
  109. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  110. const [formData,set_formData] = useState([]);
  111. useEffect(()=>{
  112. if(record.columns.length != (record.value?record.value.length:0)){
  113. const valueCodes = record.value?record.value.map((a:any)=>a.key):[];
  114. const newData = record.columns.map((b:any)=>{
  115. if(!valueCodes.includes(b.key)){
  116. return {
  117. code:b.key,
  118. floor:'',
  119. range:'',
  120. rate:''
  121. }
  122. }
  123. const temp = record.value?record.value.filter((c:any)=>c.code == b.key):[];
  124. return temp[0]
  125. });
  126. set_formData(newData);
  127. }else{
  128. set_formData(record.value);
  129. }
  130. },[record])
  131. return (
  132. <ModalForm
  133. title={record.unitTypeName?`考核分级设定(${record.unitTypeName})`:'新增考核分级设定'}
  134. className='ClassAssessAndGradeSet-ModalForm'
  135. width={400}
  136. initialValues={type == 'EDIT' ? { ...record } : {}}
  137. trigger={
  138. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  139. }
  140. onFinish={(val) => {
  141. // console.log({val});
  142. return updateTable(type == 'EDIT' ? {unitTypeCode:record.unitTypeCode,unitTypeName:record.unitTypeName,value:record.value, ...val,record} : { ...val }, type);
  143. }}
  144. >
  145. <div className='tip'>区间的上限及下限至少填写一个,没填表示无</div>
  146. {
  147. formData.map((item: any, index: number) => {
  148. let label = record.columns.filter((a:any) => a.key == item.code);
  149. return (
  150. <div className='list' key={index}>
  151. <div className='label'>{label.length > 0 ? `${label[0].title}:` : ''}</div>
  152. <div className='wrap'>
  153. <ProFormDigit width={100} name={`floor${item.code}`} placeholder='分数下限' />
  154. <ProFormDigit width={100} name={`ceiling${item.code}`} placeholder='分数上限' />
  155. <ProFormDigit width={144} name={`rate${item.code}`} placeholder='奖惩系数' />
  156. </div>
  157. </div>
  158. )
  159. })
  160. }
  161. </ModalForm>
  162. )
  163. }
  164. useEffect(() => {
  165. }, [])
  166. return (
  167. <BMSPagecontainer className='ClassAssessAndGradeSet' title={'职类考核分级设定'}>
  168. <div style={{ marginTop: 16 }}>
  169. <BMSTable actionRef={tableRef} bordered rowKey='unitTypeCode' pagination={false} columns={tableColumn as ProColumns[]} params={tableDataFilterParams} request={(params) => getTableData(params)} />
  170. </div>
  171. </BMSPagecontainer>
  172. )
  173. }