index.tsx 15 KB

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