index.tsx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-07-28 13:35:08
  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 { getComputeDate } from '@/pages/Home/service';
  12. import { getDataByKeyFromDic, getPubDicData } from '@/services/getDic';
  13. import { createFromIconfontCN } from '@ant-design/icons';
  14. import { ActionType, ProForm, ProFormRadio } from '@ant-design/pro-components';
  15. import { ModalForm, ProFormCascader, ProFormDependency, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  16. import { ProColumns } from '@ant-design/pro-table';
  17. import { Input, message, Popconfirm,InputNumber,Form } from 'antd';
  18. import { useEffect, useRef, useState } from 'react'
  19. import { addData, addLevelSets, delData, editData, gainData, getDefaultIndicator, getSecondaryProjectDistriData } from './service';
  20. import './style.less';
  21. import '../../../../utils/zhongtaiB';
  22. const IconFont = createFromIconfontCN({
  23. scriptUrl: '',
  24. });
  25. const AddIconFont = createFromIconfontCN({
  26. scriptUrl: '',
  27. });
  28. export default function BilingProjectMana() {
  29. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  30. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  31. const tableRef = useRef<ActionType>();
  32. const columns: ProColumns[] = [
  33. {
  34. title: '项目代码',
  35. dataIndex: 'code',
  36. },
  37. {
  38. title: '项目名称',
  39. dataIndex: 'name',
  40. },
  41. {
  42. title: '评价方式',
  43. dataIndex: 'evaluationName',
  44. },
  45. {
  46. title: '数据格式',
  47. dataIndex: 'dataTypeName',
  48. },
  49. {
  50. title: '数据来源',
  51. dataIndex: 'sourceName',
  52. },
  53. {
  54. title: 'SQL',
  55. dataIndex: 'sql',
  56. width: 400,
  57. ellipsis: true
  58. },
  59. {
  60. title: '操作',
  61. key: 'option',
  62. width: 160,
  63. valueType: 'option',
  64. render: (_: any, record: any) => {
  65. return record.evaluation == 2 ? [
  66. <UpDataActBtn key={'SCORE'} record={record} type='SCORE' />,
  67. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  68. <Popconfirm
  69. title="是否确认删除?"
  70. key="del"
  71. onConfirm={() => delTableData(record)}
  72. >
  73. <a>删除</a>
  74. </Popconfirm>
  75. ]:[
  76. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  77. <Popconfirm
  78. title="是否确认删除?"
  79. key="del"
  80. onConfirm={() => delTableData(record)}
  81. >
  82. <a>删除</a>
  83. </Popconfirm>
  84. ]
  85. },
  86. },
  87. ]
  88. const getTableData = async (params: any) => {
  89. const resp = await getSecondaryProjectDistriData(params);
  90. if (resp) {
  91. return {
  92. data: resp.list,
  93. success: true,
  94. total: resp.totalCount,
  95. pageSize: resp.pageSize,
  96. totalPage: resp.totalPage,
  97. }
  98. }
  99. return []
  100. }
  101. const delTableData = async (record: any) => {
  102. const resp = await delData(record.id);
  103. if (resp) {
  104. message.success('操作成功!');
  105. tableRef.current?.reload();
  106. // message.success('操作成功!');
  107. }
  108. }
  109. const updateTable = async (formVal: any, type: 'EDIT' | "ADD" | 'SCORE') => {
  110. console.log({formVal});
  111. const result = formVal.evaluation == 1? {
  112. name: formVal.name,
  113. evaluation: formVal.evaluation,
  114. dataType: formVal.dataType,
  115. source: formVal.source,
  116. sql: formVal.sql,
  117. ceiling:formVal.ceiling,
  118. floor:formVal.floor
  119. }:{
  120. name: formVal.name,
  121. evaluation: formVal.evaluation,
  122. dataType: formVal.dataType,
  123. source: formVal.source,
  124. sql: formVal.sql
  125. }
  126. if (type == 'ADD') {
  127. const resp = await addData({ ...result });
  128. if (resp) {
  129. tableRef.current?.reload();
  130. message.success('操作成功!');
  131. }
  132. }
  133. if (type == 'EDIT') {
  134. const resp = await editData({ id: formVal.id, ...result });
  135. if (resp) {
  136. tableRef.current?.reload();
  137. message.success('操作成功!');
  138. }
  139. }
  140. if (type == 'SCORE') {
  141. const needData = formVal.secondItem.map((a:any)=>({levelName:a.levelName,levelRate:a.levelRate}))
  142. const resp = await addLevelSets(formVal.secondItemCode,needData);
  143. if (resp) {
  144. tableRef.current?.reload();
  145. message.success('操作成功!');
  146. }
  147. }
  148. return true;
  149. }
  150. const [dicData, set_dicData] = useState<any[]>([]);
  151. const getDirecData = async (key?: string) => {
  152. const data = await getPubDicData();
  153. if (data) {
  154. set_dicData(data);
  155. }
  156. }
  157. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' | 'SCORE' }) => {
  158. const [scoreList, set_scoreList] = useState<any[]>([]);
  159. const [scoreInitList, set_scoreInitList] = useState({});
  160. const addIndicator = () => {
  161. const key = Math.random();
  162. const temp = [...scoreList, { tempId: key, id: key, [`levelName${key}`]: '', [`levelRate${key}`]: '' }];
  163. set_scoreInitList({ ...scoreInitList, [`levelName${key}`]: '', [`levelRate${key}`]: '' });
  164. set_scoreList([...temp]);
  165. }
  166. const delGroupIndic = (data: any, index: number) => {
  167. let temp = [...scoreList];
  168. let defaultFormData: { [key: string]: any } = {};
  169. const result = temp.filter((a: any) => a.id != data.id);
  170. result.forEach((a: any) => {
  171. defaultFormData[`levelName${a.id}`] = a.levelName;
  172. defaultFormData[`levelRate${a.id}`] = a.levelRate;
  173. });
  174. set_scoreInitList({ ...defaultFormData });
  175. set_scoreList([...result]);
  176. }
  177. const getDefaultIndicatorHandle = async () => {
  178. const resp = await getDefaultIndicator(record.code);
  179. if(resp){
  180. if (resp.length > 0) {
  181. let defaultFormData: { [key: string]: any } = {};
  182. const defaultVal = resp.map((a: any) => {
  183. defaultFormData[`levelName${a.id}`] = a.levelName;
  184. defaultFormData[`levelRate${a.id}`] = a.levelRate;
  185. return { ...a, tempId: Math.random() }
  186. });
  187. set_scoreInitList({ ...defaultFormData });
  188. set_scoreList([...defaultVal]);
  189. } else {
  190. set_scoreList([{}]);
  191. }
  192. }
  193. }
  194. useEffect(() => {
  195. if (type == 'SCORE') {
  196. getDefaultIndicatorHandle();
  197. }
  198. },[record]);
  199. return (
  200. <ModalForm
  201. className='SecondaryProjectDistriSet-ModalForm'
  202. title={`${type == 'EDIT' ? '编辑' : '新增'}${type == 'SCORE'?'级别':'二次分配项目'}`}
  203. width={352}
  204. initialValues={type == 'EDIT' ? { ...record } : type == 'SCORE'?{...scoreInitList}:{}}
  205. trigger={
  206. type == 'EDIT' ? <a key="edit" >编辑</a> :type != 'SCORE'?<span className='add'>新增</span>:<a className='score'>评级设定</a>
  207. }
  208. onFinish={(val) => {
  209. return updateTable(type == 'EDIT' ? { ...record, ...val, sql: val.source == 2 ? val.sql : '-' } :type == 'SCORE'?{secondItem:scoreList,secondItemCode:record.code}:{ ...val }, type);
  210. }}
  211. modalProps={{ destroyOnClose: true }}
  212. // colProps={{ span: 24 }}
  213. // grid
  214. >
  215. {
  216. type == 'SCORE' && (
  217. <div>
  218. {
  219. scoreList.map((item: any, index: number) => {
  220. return (
  221. <div className='item' key={index}>
  222. <ProFormText label='等级名称:'
  223. name={`levelName${item.id}`}
  224. fieldProps={{
  225. // labelInValue:true,
  226. onChange:(e)=>{
  227. const temp = [...scoreList];
  228. const newArr = temp.map((a: any) => {
  229. if (a.id == item.id) {
  230. return { ...a, levelName: e.target.value, }
  231. }
  232. return a
  233. });
  234. set_scoreList([...newArr]);
  235. },
  236. }}
  237. width={160} />
  238. <Form.Item name={`levelRate${item.id}`} label='系数:'>
  239. <InputNumber
  240. style={{ width: 120, height: 24, position: 'relative', top: 0 }}
  241. onChange={(value) => {
  242. //console.log({value,index,indicatorData});
  243. const temp = [...scoreList];
  244. const newArr = temp.map((a: any) => {
  245. if (a.id == item.id) {
  246. return { ...a, levelRate: value }
  247. }
  248. return a
  249. });
  250. set_scoreList([...newArr]);
  251. }}
  252. />
  253. </Form.Item>
  254. <span className='delIcon' onClick={() => delGroupIndic(item, index)}><IconFont type="iconshanchu" /></span>
  255. </div>
  256. )
  257. })
  258. }
  259. <div className='addBtn' onClick={() => addIndicator()}>
  260. <AddIconFont type="icon-zengjia" style={{ color: '#3376FE' }} /><span>增加一行</span>
  261. </div>
  262. </div>
  263. )
  264. }
  265. {
  266. type != 'SCORE' && (
  267. <>
  268. <ProFormText
  269. name="name"
  270. label="项目名称:"
  271. placeholder="请输入"
  272. rules={[{ required: true, message: '名称不能为空!' }]}
  273. />
  274. <ProFormRadio.Group
  275. name="evaluation"
  276. label="评价方式:"
  277. fieldProps={{
  278. buttonStyle: 'solid'
  279. }}
  280. options={[
  281. {
  282. label: '评分',
  283. value: 1,
  284. },
  285. {
  286. label: '评级',
  287. value: 2,
  288. },
  289. {
  290. label: '直接给付',
  291. value: 3,
  292. }
  293. ]}
  294. rules={[{ required: true, message: '评价方式不能为空!' }]}
  295. />
  296. <ProFormDependency name={['evaluation']}>
  297. {
  298. ({ evaluation }) => evaluation == 1 && (
  299. <div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
  300. <ProFormDigit name="floor" label="评分下限:" width={155} rules={[{ required: true, message: '评价下限不能为空!' }]} />
  301. <ProFormDigit name="ceiling" label="评分上限:" width={155} rules={[{ required: true, message: '评价上限不能为空!' }]} />
  302. </div>
  303. )
  304. }
  305. </ProFormDependency>
  306. <ProFormRadio.Group
  307. name="dataType"
  308. label="数据格式:"
  309. fieldProps={{
  310. buttonStyle: 'solid'
  311. }}
  312. options={[
  313. {
  314. label: '数值',
  315. value: 1,
  316. },
  317. {
  318. label: '百分比',
  319. value: 2,
  320. }
  321. ]}
  322. rules={[{ required: true, message: '数据格式不能为空!' }]}
  323. />
  324. <ProFormRadio.Group
  325. name="source"
  326. label="数据来源:"
  327. fieldProps={{
  328. buttonStyle: 'solid'
  329. }}
  330. options={[
  331. {
  332. label: '填报',
  333. value: 1,
  334. },
  335. {
  336. label: '自动获取',
  337. value: 2,
  338. }
  339. ]}
  340. rules={[{ required: true, message: '数据来源不能为空!' }]}
  341. />
  342. <ProFormDependency name={['source']}>
  343. {
  344. ({ source }) => source == 2 && (
  345. <ProFormTextArea
  346. name="sql"
  347. label="SQL:"
  348. placeholder="请输入"
  349. rules={[{ required: true, message: 'SQL不能为空!' }]}
  350. />
  351. )
  352. }
  353. </ProFormDependency>
  354. </>
  355. )
  356. }
  357. </ModalForm>
  358. )
  359. }
  360. const tableDataSearchHandle = (paramName: string) => {
  361. set_tableDataFilterParams({
  362. ...tableDataFilterParams,
  363. [`${paramName}`]: tableDataSearchKeywords
  364. })
  365. }
  366. //获取按钮点击后获取数据
  367. const getDataBySQL = async () => {
  368. const resp = await getComputeDate();
  369. if (resp) {
  370. const respStat = await gainData({ compute_date: resp });
  371. if (respStat) {
  372. tableRef.current?.reload();
  373. }
  374. }
  375. }
  376. useEffect(() => {
  377. getDirecData();
  378. }, [])
  379. return (
  380. <BMSPagecontainer className='BilingProjectMana' title={false}>
  381. <div className='toolBar'>
  382. <div className='filter'>
  383. <div className='filterItem'>
  384. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  385. <Input placeholder={'请输入项目名称'} allowClear
  386. suffix={
  387. <IconFont style={{ color: '#99A6BF' }} type="iconsousuo" onClick={() => tableDataSearchHandle('name')} />
  388. }
  389. onChange={(e) => {
  390. set_tableDataSearchKeywords(e.target.value);
  391. if (e.target.value.length == 0) {
  392. set_tableDataFilterParams({
  393. ...tableDataFilterParams,
  394. name: ''
  395. });
  396. }
  397. }}
  398. onPressEnter={(e) => {
  399. set_tableDataFilterParams({
  400. ...tableDataFilterParams,
  401. name: (e.target as HTMLInputElement).value
  402. });
  403. }}
  404. />
  405. </div>
  406. </div>
  407. <div className='btnGroup'>
  408. {/* <span className='getDataBtn' onClick={() => getDataBySQL()}>获取</span> */}
  409. <UpDataActBtn record type='ADD' />
  410. </div>
  411. </div>
  412. <div style={{ marginTop: 16 }}>
  413. <BMSTable columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  414. </div>
  415. </BMSPagecontainer>
  416. )
  417. }