index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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-22 17:40:53
  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 { KCInput } from '@/components/KCInput';
  10. import KCTable from '@/components/kcTable';
  11. import { getAllHosp } from '@/service/hospList';
  12. import { getUserRelaSeletData } from '@/service/user';
  13. import { ModalForm, ProFormCascader, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  14. import { ProColumns } from '@ant-design/pro-table';
  15. import { Popconfirm } from 'antd';
  16. import { useEffect, useState } from 'react'
  17. import { getSysLists } from '../paramsMana/service';
  18. import { addData, delData, editData, getData } from './service';
  19. import './style.less';
  20. export default function PubDicTypeMana() {
  21. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  22. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  23. const [reload, set_reload] = useState(false);
  24. const [currentEdit, set_currentEdit] = useState<any>(undefined);
  25. //字典
  26. const [dirData, set_dirData] = useState<any[]>([]);
  27. const columns = [
  28. {
  29. title: '主题',
  30. dataIndex: 'title',
  31. },
  32. {
  33. title: '消息内容',
  34. dataIndex: 'content',
  35. },
  36. {
  37. title: '院区',
  38. dataIndex: 'hospName',
  39. },
  40. {
  41. title: '系统',
  42. dataIndex: 'systemName',
  43. },
  44. {
  45. title: '接收类型',
  46. dataIndex: 'receiveTypeName',
  47. },
  48. {
  49. title: '接收对象',
  50. dataIndex: 'receiveTargetName',
  51. },
  52. {
  53. title: '消息级别',
  54. dataIndex: 'receiveLevelName',
  55. },
  56. {
  57. title: '处理链接',
  58. dataIndex: 'resolvePath',
  59. },
  60. {
  61. title: '备注',
  62. dataIndex: 'remark',
  63. },
  64. {
  65. title: '操作',
  66. key: 'option',
  67. width: 120,
  68. valueType: 'option',
  69. render: (_: any, record: any) => {
  70. return [
  71. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  72. <Popconfirm
  73. title="是否确认删除?"
  74. key="del"
  75. onConfirm={() => delTableData(record)}
  76. >
  77. <a>删除</a>
  78. </Popconfirm>
  79. ]
  80. },
  81. },
  82. ]
  83. const getTableData = async (params: any) => {
  84. const resp = await getData(params);
  85. set_reload(false);
  86. if (resp) {
  87. return {
  88. data: resp.list,
  89. success: true,
  90. total: resp.totalCount,
  91. pageSize: resp.pageSize,
  92. totalPage: resp.totalPage,
  93. }
  94. }
  95. return []
  96. }
  97. const delTableData = async (record: any) => {
  98. const resp = await delData(record.id);
  99. if (resp) {
  100. set_reload(true);
  101. // message.success('操作成功!');
  102. }
  103. }
  104. const getDirecData = async (key?: string) => {
  105. const data = await getUserRelaSeletData(key);
  106. if (data) {
  107. set_dirData(data);
  108. }
  109. }
  110. const setSelectorData = (key: string) => {
  111. let result = dirData.filter((t: any) => (t.code == key));
  112. if (result.length > 0) {
  113. let dataArr = result[0].dataVoList;
  114. let defaultValue = dataArr.filter((t: any) => t.defaultValue == 1);
  115. dataArr.sort((prev: any, next: any) => {
  116. return prev.sort - next.sort;
  117. });
  118. return {
  119. defaultvalue: defaultValue[0] ? defaultValue[0].value : '',
  120. list: dataArr.map((t: any) => ({ label: t.value, value: t.code }))
  121. }
  122. }
  123. return {
  124. defaultvalue: '',
  125. list: []
  126. };
  127. }
  128. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  129. if (type == 'ADD') {
  130. const resp = await addData({ ...formVal,
  131. systemPath:formVal.systemId?formVal.systemId.join(','):'',
  132. systemId:(formVal.systemId&&formVal.systemId.length>0)?formVal.systemId[formVal.systemId.length -1]:''});
  133. if (resp) {
  134. set_reload(true);
  135. }
  136. }
  137. if (type == 'EDIT') {
  138. const resp = await editData({ ...formVal,
  139. systemPath:formVal.systemId?formVal.systemId.join(','):'',
  140. systemId:(formVal.systemId&&formVal.systemId.length>0)?formVal.systemId[formVal.systemId.length -1]:''});
  141. if (resp) {
  142. set_reload(true);
  143. }
  144. }
  145. }
  146. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  147. return (
  148. <ModalForm
  149. title={`${type == 'EDIT' ? '编辑' : '新增'}消息模板`}
  150. width={688}
  151. initialValues={type == 'EDIT' ? {
  152. ...record,
  153. systemId:record.systemPath?record.systemPath.split(','):[]
  154. } : {}}
  155. trigger={
  156. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  157. }
  158. onFinish={(val) => {
  159. return updateTable(type == 'EDIT'?{...val,id:record.id}:{...val}, type);
  160. }}
  161. colProps={{span:12}}
  162. grid
  163. >
  164. <ProFormText
  165. name="title"
  166. label="消息主题:"
  167. placeholder="请输入"
  168. rules={[{ required: true, message: '主题不能为空!' }]}
  169. />
  170. <ProFormText
  171. name="content"
  172. label="消息内容:"
  173. placeholder="请输入"
  174. rules={[{ required: true, message: '消息内容不能为空!' }]}
  175. />
  176. <ProFormSelect
  177. name="hospId"
  178. label="院区:"
  179. disabled={type == 'EDIT'}
  180. placeholder="请选择院区"
  181. rules={[{ required: true, message: '院区不能为空!' }]}
  182. request={async () => {
  183. const resp = await getAllHosp({ pageSize: 200, current: 1 });
  184. if (resp) {
  185. const data: any = resp.list?.map((a) => ({
  186. label: a.hospName,
  187. value: a.id
  188. }));
  189. return [{
  190. label:'所有院区',
  191. value:0
  192. },...data];
  193. }
  194. return []
  195. }}
  196. />
  197. <ProFormCascader
  198. label='系统:'
  199. name='systemId'
  200. placeholder="请选择"
  201. request={async () => {
  202. const resp = await getSysLists();
  203. if (resp) {
  204. return resp
  205. }
  206. return []
  207. }}
  208. fieldProps={{
  209. fieldNames: {
  210. label: 'name',
  211. value: 'code'
  212. },
  213. }}
  214. rules={[{ required: true, message: '系统不能为空!' }]}
  215. />
  216. <ProFormSelect
  217. name="receiveType"
  218. label="接收类型:"
  219. options={setSelectorData('RECEIVE_TYPE').list}
  220. placeholder="请选择"
  221. rules={[{ required: true, message: '请选择!' }]}
  222. />
  223. <ProFormSelect
  224. name="receiveTarget"
  225. label="接收对象:"
  226. options={setSelectorData('RECEIVE_TARGET').list}
  227. placeholder="请选择"
  228. rules={[{ required: true, message: '请选择!' }]}
  229. />
  230. <ProFormSelect
  231. name="receiveLevel"
  232. label="消息级别:"
  233. options={setSelectorData('MESSAGE_LEVEL').list}
  234. placeholder="请选择"
  235. rules={[{ required: true, message: '请选择!' }]}
  236. />
  237. <ProFormText
  238. name="resolvePath"
  239. label="处理链接:"
  240. placeholder="请输入"
  241. />
  242. <ProFormTextArea
  243. colProps={{span:24}}
  244. name="remark"
  245. label="备注:"
  246. placeholder="请输入"
  247. />
  248. </ModalForm>
  249. )
  250. }
  251. const tableDataSearchHandle = (paramName: string) => {
  252. set_tableDataFilterParams({
  253. ...tableDataFilterParams,
  254. [`${paramName}`]: tableDataSearchKeywords
  255. })
  256. }
  257. useEffect(()=>{
  258. getDirecData();
  259. },[])
  260. return (
  261. <div className='PubDicTypeMana'>
  262. <div className='toolBar'>
  263. <div className='filter'>
  264. <div className='filterItem'>
  265. <span className='label'>院区:</span>
  266. <ProFormSelect
  267. noStyle
  268. allowClear
  269. placeholder="请选择"
  270. style={{ width: 160, marginRight: 16 }}
  271. request={async () => {
  272. const resp = await getAllHosp({ pageSize: 200, current: 1 });
  273. if (resp) {
  274. const data: any = resp.list?.map((a) => ({
  275. label: a.hospName,
  276. value: a.id
  277. }));
  278. return [
  279. {
  280. label: '所有院区', value: '0'
  281. }, ...data
  282. ];
  283. }
  284. return []
  285. }}
  286. fieldProps={{
  287. onChange(value, option) {
  288. set_tableDataFilterParams({ ...tableDataFilterParams, hospId: value })
  289. },
  290. }}
  291. />
  292. </div>
  293. <div className='filterItem' style={{ marginRight: 16 }}>
  294. <span className='label'>系统名称:</span>
  295. <ProFormCascader
  296. noStyle
  297. allowClear
  298. width={160}
  299. placeholder="请选择"
  300. request={async () => {
  301. const resp = await getSysLists();
  302. if (resp) {
  303. return resp
  304. }
  305. return []
  306. }}
  307. fieldProps={{
  308. fieldNames: {
  309. label: 'name',
  310. value: 'code'
  311. },
  312. onChange(value: any, option: any) {
  313. set_tableDataFilterParams({ ...tableDataFilterParams, systemId: value ? value[value.length - 1] : '' })
  314. },
  315. }}
  316. />
  317. </div>
  318. <div className='filterItem'>
  319. <span className='label'>检索:</span>
  320. <KCInput placeholder={'请输入主题名称'} style={{ width: 160 }} search allowClear
  321. onChange={(e) => {
  322. set_tableDataSearchKeywords(e.target.value);
  323. if (e.target.value.length == 0) {
  324. set_tableDataFilterParams({
  325. ...tableDataFilterParams,
  326. title: ''
  327. });
  328. }
  329. }}
  330. onSearch={() => tableDataSearchHandle('title')}
  331. />
  332. </div>
  333. </div>
  334. <div className='btnGroup'>
  335. <UpDataActBtn record type='ADD' />
  336. </div>
  337. </div>
  338. <div style={{ marginTop: 16 }}>
  339. <KCTable columns={columns as ProColumns[]} reload={reload} rowKey='id' newVer params={tableDataFilterParams} request={(params) => getTableData(params)} />
  340. </div>
  341. </div>
  342. )
  343. }