index.tsx 14 KB

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