index.tsx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2023-03-03 11:30:33
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2023-05-11 13:30:28
  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 BMSPagecontainer from '@/components/BMSPageContainer';
  10. import { BMSTable } from '@/components/BMSTable';
  11. import { getComputeDate } from '@/pages/Home/service';
  12. import { getDataByKeyFromDic, getPubDicData } from '@/services/getDic';
  13. import { createFromIconfontCN } from '@ant-design/icons';
  14. import { ActionType, ProFormRadio } from '@ant-design/pro-components';
  15. import { ModalForm, ProFormCascader, ProFormDigit, ProFormSelect, ProFormText, ProFormTextArea } from '@ant-design/pro-form'
  16. import { ProColumns } from '@ant-design/pro-table';
  17. import { Input, message, Popconfirm } from 'antd';
  18. import { useEffect, useRef, useState } from 'react'
  19. import { addData, delData, editData, gainData, getData } from './service';
  20. import './style.less';
  21. const IconFont = createFromIconfontCN({
  22. scriptUrl: '//at.alicdn.com/t/c/font_1927152_4nm5kxbv4m3.js',
  23. });
  24. export default function BilingProjectMana() {
  25. const [tableDataFilterParams, set_tableDataFilterParams] = useState<any | undefined>();
  26. const [tableDataSearchKeywords, set_tableDataSearchKeywords] = useState<string>('');
  27. const tableRef = useRef<ActionType>();
  28. const columns = [
  29. {
  30. title: '项目代码',
  31. dataIndex: 'itemCode',
  32. },
  33. {
  34. title: '项目名称',
  35. dataIndex: 'itemName',
  36. },
  37. {
  38. title: '项目类别',
  39. dataIndex: 'itemType',
  40. },
  41. {
  42. title: '点值',
  43. dataIndex: 'orderPointValue',
  44. },
  45. {
  46. title: '类型',
  47. dataIndex: 'coreFlagName',
  48. },
  49. {
  50. title: '来源',
  51. dataIndex: 'sourceName',
  52. },
  53. {
  54. title: '操作',
  55. key: 'option',
  56. width: 120,
  57. valueType: 'option',
  58. render: (_: any, record: any) => {
  59. return [
  60. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  61. <Popconfirm
  62. title="是否确认删除?"
  63. key="del"
  64. onConfirm={() => delTableData(record)}
  65. >
  66. <a>删除</a>
  67. </Popconfirm>
  68. ]
  69. },
  70. },
  71. ]
  72. const getTableData = async (params: any) => {
  73. const resp = await getData(params);
  74. if (resp) {
  75. return {
  76. data: resp.list,
  77. success: true,
  78. total: resp.totalCount,
  79. pageSize: resp.pageSize,
  80. totalPage: resp.totalPage,
  81. }
  82. }
  83. return []
  84. }
  85. const delTableData = async (record: any) => {
  86. const resp = await delData(record.id);
  87. if (resp) {
  88. message.success('操作成功!');
  89. tableRef.current?.reload();
  90. // message.success('操作成功!');
  91. }
  92. }
  93. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  94. const result = {
  95. itemCode: formVal.itemCode,
  96. itemName: formVal.itemName,
  97. itemTypeCode: formVal.itemType.value,
  98. itemType: formVal.itemType.label,
  99. coreFlag: formVal.coreFlag,
  100. orderPointValue: formVal.orderPointValue
  101. }
  102. if (type == 'ADD') {
  103. const resp = await addData({...result});
  104. if (resp) {
  105. tableRef.current?.reload();
  106. message.success('操作成功!');
  107. }
  108. }
  109. if (type == 'EDIT') {
  110. const resp = await editData({id:formVal.id,...result});
  111. if (resp) {
  112. tableRef.current?.reload();
  113. message.success('操作成功!');
  114. }
  115. }
  116. return true;
  117. }
  118. const [dicData, set_dicData] = useState<any[]>([]);
  119. const getDirecData = async (key?: string) => {
  120. const data = await getPubDicData();
  121. if (data) {
  122. set_dicData(data);
  123. }
  124. }
  125. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  126. return (
  127. <ModalForm
  128. title={`${type == 'EDIT' ? '编辑' : '新增'}收费项目`}
  129. width={352}
  130. initialValues={type == 'EDIT' ? { ...record,itemType:{label:record.itemType,value:record.itemTypeCode} } : {coreFlag:1}}
  131. trigger={
  132. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  133. }
  134. onFinish={(val) => {
  135. return updateTable(type == 'EDIT' ? { ...record, ...val } : { ...val }, type);
  136. }}
  137. modalProps={{ destroyOnClose: true }}
  138. colProps={{ span: 24 }}
  139. grid
  140. >
  141. <ProFormText
  142. name="itemName"
  143. label="项目名称:"
  144. placeholder="请输入"
  145. rules={[{ required: true, message: '名称不能为空!' }]}
  146. />
  147. <ProFormText
  148. name="itemCode"
  149. label="项目代码:"
  150. placeholder="请输入"
  151. rules={[{ required: true, message: '代码不能为空!' }]}
  152. />
  153. <ProFormSelect label="项目类别:"
  154. name='itemType'
  155. options={(getDataByKeyFromDic(dicData, 'ITEM_TYPE')).list}
  156. fieldProps={{ labelInValue: true }}
  157. rules={[{ required: true, message: '类别不能为空!' }]}
  158. />
  159. <ProFormDigit
  160. name="orderPointValue"
  161. label="点值:"
  162. placeholder="请输入"
  163. rules={[{ required: true, message: '点值不能为空!' }]}
  164. />
  165. <ProFormRadio.Group
  166. name="coreFlag"
  167. label="类型:"
  168. fieldProps={{
  169. buttonStyle: 'solid'
  170. }}
  171. options={[
  172. {
  173. label: '核心',
  174. value: 1,
  175. },
  176. {
  177. label: '非核心',
  178. value: 0,
  179. },
  180. {
  181. label: '不计',
  182. value: 2,
  183. },
  184. ]}
  185. />
  186. </ModalForm>
  187. )
  188. }
  189. const tableDataSearchHandle = (paramName: string) => {
  190. set_tableDataFilterParams({
  191. ...tableDataFilterParams,
  192. [`${paramName}`]: tableDataSearchKeywords
  193. })
  194. }
  195. //获取按钮点击后获取数据
  196. const getDataBySQL = async () => {
  197. const resp = await getComputeDate();
  198. if (resp) {
  199. const respStat = await gainData({ compute_date: resp });
  200. if (respStat) {
  201. message.success('获取成功!');
  202. tableRef.current?.reload();
  203. }
  204. }
  205. }
  206. useEffect(() => {
  207. getDirecData();
  208. }, [])
  209. return (
  210. <BMSPagecontainer className='BilingProjectMana' title={false}>
  211. <div className='toolBar'>
  212. <div className='filter'>
  213. <div className='filterItem'>
  214. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  215. <Input placeholder={'请输入项目名称'} allowClear
  216. suffix={
  217. <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('name')} />
  218. }
  219. onChange={(e) => {
  220. set_tableDataSearchKeywords(e.target.value);
  221. if (e.target.value.length == 0) {
  222. set_tableDataFilterParams({
  223. ...tableDataFilterParams,
  224. name: ''
  225. });
  226. }
  227. }}
  228. onPressEnter={(e) => {
  229. set_tableDataFilterParams({
  230. ...tableDataFilterParams,
  231. name: (e.target as HTMLInputElement).value
  232. });
  233. }}
  234. />
  235. </div>
  236. </div>
  237. <div className='btnGroup'>
  238. <span className='getDataBtn' onClick={() => getDataBySQL()}>获取</span>
  239. <UpDataActBtn record type='ADD' />
  240. </div>
  241. </div>
  242. <div style={{ marginTop: 16 }}>
  243. <BMSTable columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  244. </div>
  245. </BMSPagecontainer>
  246. )
  247. }