index.tsx 13 KB

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