index.tsx 12 KB

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