index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2024-08-16 10:28:49
  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 KCIMPagecontainer from '@/components/KCIMPageContainer';
  10. import { KCIMTable } from '@/components/KCIMTable';
  11. import { formatMoneyNumber } from '@/utils/format';
  12. import { createFromIconfontCN } from '@ant-design/icons';
  13. import FormItem from 'antd/es/form/FormItem';
  14. import { ActionType, ProFormDatePicker, ProFormDateTimePicker, ProFormInstance, ProFormText } from '@ant-design/pro-components';
  15. import { ModalForm, ProFormDependency, ProFormDigit, ProFormRadio, ProFormSelect, ProFormSwitch } from '@ant-design/pro-form'
  16. import { ProColumns } from '@ant-design/pro-table';
  17. import { Input, message, Popconfirm, Form } from 'antd';
  18. import { Fragment, useEffect, useRef, useState } from 'react';
  19. import 'moment/locale/zh-cn';
  20. import locale from 'antd/es/date-picker/locale/zh_CN';
  21. import { addData, delData, editData, getDrugTableData, getDrugTypeReq, importDataPost } from './service';
  22. import './style.less';
  23. import KCIMUpload from '@/components/KCIMUpload';
  24. import { downloadTemplateReq } from '@/utils/tooljs';
  25. const IconFont = createFromIconfontCN({
  26. scriptUrl: '',
  27. });
  28. export default function DrugCostManagement() {
  29. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  30. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  31. const tableRef = useRef<ActionType>();
  32. const formRef = useRef<ProFormInstance>();
  33. const [stopStat,set_stopStat] = useState(0);
  34. const columns: ProColumns[] = [
  35. {
  36. title: '项目代码',
  37. dataIndex: 'code',
  38. width:100
  39. },
  40. {
  41. title: '项目名称',
  42. dataIndex: 'name',
  43. width:350,
  44. },
  45. {
  46. title: '项目类型',
  47. dataIndex: 'typeName',
  48. width:90
  49. },
  50. {
  51. title: '单价',
  52. dataIndex: 'price',
  53. width:90,
  54. renderText(num) {
  55. return formatMoneyNumber(num)
  56. },
  57. },
  58. {
  59. title: '成本',
  60. dataIndex: 'cost',
  61. width:90,
  62. renderText(num) {
  63. return formatMoneyNumber(num)
  64. },
  65. },
  66. {
  67. title: '停用',
  68. dataIndex: 'status',
  69. width:90,
  70. renderText(stat) {
  71. return stat ? '是' : '否'
  72. },
  73. },
  74. {
  75. title: '操作',
  76. key: 'option',
  77. width: 60,
  78. valueType: 'option',
  79. render: (_: any, record: any) => {
  80. return [
  81. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  82. <Popconfirm
  83. title="是否确认删除?"
  84. key="del"
  85. onConfirm={() => delTableData(record)}
  86. >
  87. <a>删除</a>
  88. </Popconfirm>
  89. ]
  90. },
  91. },
  92. ]
  93. const getTableData = async (params: any) => {
  94. const resp = await getDrugTableData({...params,stop:stopStat});
  95. if (resp) {
  96. return {
  97. data: resp.list,
  98. success: true,
  99. total: resp.totalCount,
  100. pageSize: resp.pageSize,
  101. totalPage: resp.totalPage,
  102. }
  103. }
  104. return []
  105. }
  106. const delTableData = async (record: any) => {
  107. const resp = await delData(record.id);
  108. if (resp) {
  109. message.success('操作成功!');
  110. tableRef.current?.reload();
  111. // message.success('操作成功!');
  112. }
  113. }
  114. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  115. const result = {
  116. ...formVal
  117. }
  118. if (type == 'ADD') {
  119. const resp = await addData(result);
  120. if (resp) {
  121. tableRef.current?.reload();
  122. message.success('操作成功!');
  123. }
  124. }
  125. if (type == 'EDIT') {
  126. const resp = await editData({...result});
  127. if (resp) {
  128. tableRef.current?.reload();
  129. message.success('操作成功!');
  130. }
  131. }
  132. return true;
  133. }
  134. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  135. return (
  136. <ModalForm
  137. title={`${type == 'EDIT' ? '编辑' : '新增'}药品`}
  138. width={350}
  139. formRef={formRef}
  140. initialValues={type == 'EDIT' ? {
  141. ...record,
  142. } : {status:0}}
  143. trigger={
  144. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  145. }
  146. onFinish={(val) => {
  147. return updateTable(type == 'EDIT' ? { ...record, ...val } : { ...val }, type);
  148. }}
  149. modalProps={{ destroyOnClose: true }}
  150. colProps={{ span: 24 }}
  151. grid
  152. >
  153. <ProFormText
  154. name="code"
  155. label="项目代码:"
  156. placeholder="请输入"
  157. rules={[{ required: true, message: '项目代码不能为空!' }]}
  158. />
  159. <ProFormText
  160. name="name"
  161. label="项目名称:"
  162. placeholder="请输入"
  163. rules={[{ required: true, message: '项目名称不能为空!' }]}
  164. />
  165. <ProFormSelect
  166. name="type"
  167. label="项目类型:"
  168. placeholder="请选择"
  169. request={async () => {
  170. const resp = await getDrugTypeReq();
  171. if(resp){
  172. return resp.map((a:any)=>({label:a.name,value:a.code}))
  173. }
  174. }}
  175. rules={[{ required: true, message: '项目类型不能为空!' }]}
  176. />
  177. <ProFormDigit
  178. name="price"
  179. label="单价:"
  180. placeholder="请输入"
  181. rules={[{ required: true, message: '单价不能为空!' }]}
  182. />
  183. <ProFormDigit
  184. name="cost"
  185. label="成本:"
  186. placeholder="请输入"
  187. rules={[{ required: true, message: '成本不能为空!' }]}
  188. />
  189. <Form.Item style={{ width: 322 }} label={<span style={{}}><i style={{ fontSize: 14, color: '#FF4060', fontWeight: 400, position: 'relative', paddingRight: 4, paddingLeft: 4 }}>*</i>停用:</span>}>
  190. <div style={{ display: 'flex', flex: 1, flexDirection: 'row', justifyContent: 'space-between' }}>
  191. <ProFormRadio.Group
  192. name="status"
  193. noStyle
  194. colProps={{ span: 10 }}
  195. options={[
  196. {
  197. label: '否',
  198. value: 0
  199. },
  200. {
  201. label: '是',
  202. value: 1
  203. }
  204. ]}
  205. />
  206. {/* style={{position:'relative',left:-10}} */}
  207. <ProFormDependency name={['status']}>
  208. {
  209. ({ status }) => {
  210. // console.log({report});
  211. return (
  212. status ? <ProFormDateTimePicker fieldProps={{locale}} name="stopTime" placeholder="请选择停用时间" rules={[{ required: true, message: '时间不能为空!' }]} colProps={{ span: 14 }} noStyle />:null
  213. )
  214. }
  215. }
  216. </ProFormDependency>
  217. </div>
  218. </Form.Item>
  219. </ModalForm>
  220. )
  221. }
  222. const tableDataSearchHandle = (paramName: string) => {
  223. set_tableDataFilterParams({
  224. ...tableDataFilterParams,
  225. [`${paramName}`]: tableDataSearchKeywords
  226. })
  227. }
  228. const downloadTemplate = async () => {
  229. await downloadTemplateReq('/costAccount/setting/exportDrug');
  230. };
  231. const importData = () => {
  232. return (
  233. <ModalForm
  234. width={360}
  235. title={`导入数据`}
  236. trigger={
  237. <a className="import" key="3">
  238. 导入
  239. </a>
  240. }
  241. submitter={{
  242. render: (props, defaultDoms) => {
  243. const needBtn = defaultDoms.filter((b) => {
  244. return b.key != 'rest';
  245. });
  246. return [
  247. // <Button
  248. // key="ok"
  249. // onClick={auditType == '0' ? () => downloadTemplate(index) : () => { }}
  250. // >
  251. // 下载模板
  252. // </Button>,
  253. ...needBtn,
  254. ];
  255. },
  256. }}
  257. onFinish={async (values) => {
  258. const {
  259. importFile: { fileList },
  260. } = values;
  261. let formData = new FormData();
  262. formData.append('file', fileList[0].originFileObj);
  263. const resp = await importDataPost(formData);
  264. if (resp) {
  265. tableRef.current?.reload();
  266. return true;
  267. }
  268. }}
  269. >
  270. <FormItem name={'importFile'}>
  271. <KCIMUpload downloadTemplateFile={() => downloadTemplate()} />
  272. </FormItem>
  273. </ModalForm>
  274. );
  275. };
  276. useEffect(() => {
  277. }, [])
  278. return (
  279. <KCIMPagecontainer className='DrugCostManagement' title={false}>
  280. <div className='toolBar'>
  281. <div className='filter'>
  282. <div className='filterItem'>
  283. <span className='label' style={{ whiteSpace: 'nowrap' }}> 项目名称:</span>
  284. <Input placeholder={'请输入'} allowClear
  285. suffix={
  286. <IconFont type="iconsousuo" style={{color:'#99A6BF'}} onClick={() => tableDataSearchHandle('name')} />
  287. }
  288. onChange={(e) => {
  289. set_tableDataSearchKeywords(e.target.value);
  290. if (e.target.value.length == 0) {
  291. set_tableDataFilterParams({
  292. ...tableDataFilterParams,
  293. name: ''
  294. });
  295. }
  296. }}
  297. onPressEnter={(e) => {
  298. set_tableDataFilterParams({
  299. ...tableDataFilterParams,
  300. name: (e.target as HTMLInputElement).value
  301. });
  302. }}
  303. />
  304. </div>
  305. </div>
  306. <div className='btnGroup'>
  307. <span style={{paddingRight:16}}><ProFormSwitch noStyle fieldProps={{size:'small',onChange:(bool)=>{
  308. set_stopStat(bool ? 1 : 0);
  309. tableRef.current?.reload();
  310. }}} /> 显示停用项目</span>
  311. {importData()}
  312. <UpDataActBtn record type='ADD' />
  313. </div>
  314. </div>
  315. <div style={{ marginTop: 16 }}>
  316. <KCIMTable columns={columns as ProColumns[]} scroll={{y:`calc(100vh - 235px)`}} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  317. </div>
  318. </KCIMPagecontainer>
  319. )
  320. }