index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2025-07-09 17:35: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 { createFromIconfontCN } from '@ant-design/icons';
  10. import {
  11. ActionType,
  12. ProFormInstance,
  13. ProFormSelect,
  14. } from '@ant-design/pro-components';
  15. import {
  16. ModalForm,
  17. ProFormDigit,
  18. ProFormText,
  19. ProFormTextArea,
  20. } from '@ant-design/pro-form';
  21. import { ProColumns } from '@ant-design/pro-table';
  22. import { Input, message, Popconfirm } from 'antd';
  23. import { useEffect, useRef, useState } from 'react';
  24. import {
  25. addData,
  26. delData,
  27. editData,
  28. getColorFromDic,
  29. getData,
  30. } from './service';
  31. import './style.less';
  32. import KCIMPagecontainer from '@/components/KCIMPageContainer';
  33. import { KCIMTable } from '@/components/KCIMTable';
  34. const IconFont = createFromIconfontCN({
  35. scriptUrl: '',
  36. });
  37. type TableDataResponse = {
  38. data: any[];
  39. success: boolean;
  40. total: number;
  41. pageSize: number;
  42. totalPage: number;
  43. };
  44. const resultTypeList = [
  45. {
  46. label: '无需操作',
  47. value: 1,
  48. },
  49. {
  50. label: '需改善回复',
  51. value: 2,
  52. },
  53. {
  54. label: '需使用改善工具',
  55. value: 3,
  56. },
  57. ];
  58. export default function DicClassfication() {
  59. const [tableDataFilterParams, set_tableDataFilterParams] = useState<
  60. any | undefined
  61. >();
  62. const [tableDataSearchKeywords, set_tableDataSearchKeywords] =
  63. useState<string>('');
  64. const tableRef = useRef<ActionType>();
  65. const modalFormRef = useRef<ProFormInstance>();
  66. const [pagination, set_pagination] = useState({
  67. total: 0,
  68. pageSize: 10,
  69. current: 1,
  70. });
  71. const columns: ProColumns[] = [
  72. {
  73. title: 'ID',
  74. dataIndex: 'id',
  75. },
  76. {
  77. title: '定性选项',
  78. dataIndex: 'name',
  79. },
  80. {
  81. title: '选项编码',
  82. dataIndex: 'code',
  83. },
  84. {
  85. title: '类型',
  86. dataIndex: 'resultTypeName',
  87. },
  88. {
  89. title: '是否默认',
  90. dataIndex: 'defaultFlag',
  91. renderText(num, record, index, action) {
  92. return num == 1 ? '是' : '否';
  93. },
  94. },
  95. {
  96. title: '排序序号',
  97. dataIndex: 'sort',
  98. },
  99. {
  100. title: '默认颜色',
  101. dataIndex: 'color',
  102. renderText(text, record, index, action) {
  103. return (
  104. <span
  105. style={{
  106. display: 'inline-block',
  107. backgroundColor: `#${text}`,
  108. padding: 2,
  109. borderRadius: 4,
  110. color: '#fff',
  111. }}
  112. >
  113. {text}
  114. </span>
  115. );
  116. },
  117. },
  118. {
  119. title: '操作',
  120. key: 'option',
  121. width: 120,
  122. valueType: 'option',
  123. render: (_: any, record: any) => {
  124. return [
  125. <UpDataActBtn key={'act'} record={record} type="EDIT" />,
  126. <Popconfirm
  127. title="是否确认作废?"
  128. key="del"
  129. onConfirm={() => delTableData(record)}
  130. >
  131. <a>作废</a>
  132. </Popconfirm>,
  133. ];
  134. },
  135. },
  136. ];
  137. const getTableData = async (
  138. params: any,
  139. ): Promise<TableDataResponse | any[]> => {
  140. const resp = await getData({ ...params });
  141. if (resp) {
  142. if (resp.totalCount == 0 && resp.currPage != 1) {
  143. return getTableData({ ...params, current: resp.currPage - 1 });
  144. } else {
  145. return {
  146. data: resp.list,
  147. success: true,
  148. total: resp.totalCount,
  149. pageSize: resp.pageSize,
  150. totalPage: resp.totalPage,
  151. };
  152. }
  153. }
  154. return [];
  155. };
  156. const delTableData = async (record: any) => {
  157. const resp = await delData(record.id);
  158. if (resp) {
  159. message.success('操作成功!');
  160. tableRef.current?.reload();
  161. // message.success('操作成功!');
  162. }
  163. };
  164. const updateTable = async (formVal: any, type: 'EDIT' | 'ADD') => {
  165. if (type == 'ADD') {
  166. const currentHosp = localStorage.getItem('currentSelectedSubHop');
  167. const currentUser = localStorage.getItem('userData');
  168. if (currentHosp && currentUser) {
  169. const { id } = JSON.parse(currentHosp);
  170. const { userId } = JSON.parse(currentUser);
  171. const result = {
  172. hiId: id,
  173. code: formVal.code,
  174. name: formVal.name,
  175. resultType: formVal.resultType,
  176. defaultFlag: formVal.defaultFlag,
  177. sort: formVal.sort,
  178. delFlag: '',
  179. createUser: userId,
  180. createTime: new Date().getTime(),
  181. color: formVal.color,
  182. };
  183. const resp = await addData({ ...formVal });
  184. if (resp) {
  185. tableRef.current?.reload();
  186. message.success('操作成功!');
  187. }
  188. }
  189. }
  190. if (type == 'EDIT') {
  191. const resp = await editData({ ...formVal });
  192. if (resp) {
  193. tableRef.current?.reload();
  194. message.success('操作成功!');
  195. }
  196. }
  197. return true;
  198. };
  199. const UpDataActBtn = ({
  200. record,
  201. type,
  202. }: {
  203. record: any;
  204. type: 'EDIT' | 'ADD';
  205. }) => {
  206. return (
  207. <ModalForm
  208. title={`${type == 'EDIT' ? '编辑' : '新增'}定性选项`}
  209. width={352}
  210. initialValues={type == 'EDIT' ? { ...record } : {}}
  211. trigger={
  212. type == 'EDIT' ? (
  213. <a key="edit">编辑</a>
  214. ) : (
  215. <span className="add">新增</span>
  216. )
  217. }
  218. formRef={modalFormRef}
  219. onFinish={(val) => {
  220. return updateTable(
  221. type == 'EDIT' ? { ...record, ...val } : { ...val },
  222. type,
  223. );
  224. }}
  225. modalProps={{ destroyOnClose: true }}
  226. colProps={{ span: 24 }}
  227. grid
  228. >
  229. <ProFormText
  230. name="name"
  231. label="定性选项:"
  232. placeholder="请输入"
  233. rules={[{ required: true, message: '定性不能为空!' }]}
  234. />
  235. <ProFormText
  236. name="code"
  237. label="选项编码:"
  238. placeholder="请输入"
  239. rules={[{ required: true, message: '编码不能为空!' }]}
  240. />
  241. <ProFormSelect
  242. label="类型:"
  243. name="resultType"
  244. request={async () => {
  245. return resultTypeList;
  246. }}
  247. rules={[{ required: true, message: '类型不能为空!' }]}
  248. />
  249. <ProFormSelect
  250. label="是否默认:"
  251. name="defaultFlag"
  252. request={async () => {
  253. return [
  254. { label: '是', value: 1 },
  255. { label: '否', value: 0 },
  256. ];
  257. }}
  258. />
  259. <ProFormDigit name="sort" label="排序序号:" placeholder="请输入" />
  260. <ProFormSelect
  261. label="默认颜色:"
  262. name="color"
  263. request={async () => {
  264. const currentSys = localStorage.getItem('currentSelectedTab');
  265. if (currentSys) {
  266. const { systemId } = JSON.parse(currentSys);
  267. const resp = await getColorFromDic({
  268. dictType: 'COLOR_TYPE',
  269. systemId: systemId,
  270. });
  271. if (resp) {
  272. const list = resp.dataVoList.map((a: any) => {
  273. if (type == 'ADD' && a.defaultValue) {
  274. modalFormRef.current?.setFieldValue('color', a.value);
  275. }
  276. return {
  277. label: (
  278. <span
  279. style={{
  280. background: `#${a.value}`,
  281. color: '#fff',
  282. width: 20,
  283. height: 15,
  284. display: 'inline-block',
  285. position: 'relative',
  286. top: 1,
  287. }}
  288. >
  289. {}
  290. </span>
  291. ),
  292. value: a.value,
  293. };
  294. });
  295. return list;
  296. }
  297. }
  298. return [];
  299. }}
  300. />
  301. </ModalForm>
  302. );
  303. };
  304. const tableDataSearchHandle = (paramName: string) => {
  305. set_tableDataFilterParams({
  306. ...tableDataFilterParams,
  307. [`${paramName}`]: tableDataSearchKeywords,
  308. });
  309. };
  310. useEffect(() => {}, []);
  311. return (
  312. <KCIMPagecontainer className="QualitativeOptMana" title={false}>
  313. <div className="toolBar">
  314. <div className="filter">
  315. <div className="filterItem" style={{ marginRight: 16, width: 205 }}>
  316. <span className="label" style={{ whiteSpace: 'nowrap' }}>
  317. 检索:
  318. </span>
  319. <Input
  320. placeholder={'请输入定性名称'}
  321. allowClear
  322. suffix={
  323. <IconFont
  324. type="iconsousuo"
  325. style={{ color: '#99A6BF' }}
  326. onClick={() => tableDataSearchHandle('filter')}
  327. />
  328. }
  329. onChange={(e) => {
  330. set_tableDataSearchKeywords(e.target.value);
  331. if (e.target.value.length == 0) {
  332. set_tableDataFilterParams({
  333. ...tableDataFilterParams,
  334. filter: '',
  335. });
  336. }
  337. }}
  338. onPressEnter={(e) => {
  339. set_tableDataFilterParams({
  340. ...tableDataFilterParams,
  341. filter: (e.target as HTMLInputElement).value,
  342. });
  343. }}
  344. />
  345. </div>
  346. <div className="filterItem">
  347. <span className="label" style={{ whiteSpace: 'nowrap' }}>
  348. {' '}
  349. 类型:
  350. </span>
  351. <ProFormSelect
  352. noStyle
  353. allowClear
  354. placeholder="请选择"
  355. style={{ width: 160, marginRight: 16 }}
  356. request={async () => {
  357. return resultTypeList;
  358. }}
  359. fieldProps={{
  360. onChange(value, option) {
  361. set_tableDataFilterParams({
  362. ...tableDataFilterParams,
  363. resultType: value,
  364. });
  365. },
  366. }}
  367. />
  368. </div>
  369. </div>
  370. <div className="btnGroup">
  371. <UpDataActBtn record type="ADD" />
  372. </div>
  373. </div>
  374. <div style={{ marginTop: 16 }}>
  375. <KCIMTable
  376. columns={columns as ProColumns[]}
  377. actionRef={tableRef}
  378. rowKey="id"
  379. params={tableDataFilterParams}
  380. request={(params) => getTableData(params)}
  381. />
  382. </div>
  383. </KCIMPagecontainer>
  384. );
  385. }