index.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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-24 17:16:20
  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, getIndicProjectTableData } 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:ProColumns[] = [
  29. {
  30. title: '项目代码',
  31. dataIndex: 'indicatorCode',
  32. },
  33. {
  34. title: '项目名称',
  35. dataIndex: 'indicatorName',
  36. },
  37. {
  38. title: '类型',
  39. dataIndex: 'indicatorTypeName',
  40. },
  41. {
  42. title: '定义',
  43. dataIndex: 'indicatorDefinition',
  44. },
  45. {
  46. title: '点值',
  47. dataIndex: 'orderPointValue',
  48. },
  49. {
  50. title: 'SQL',
  51. dataIndex: 'sql',
  52. width:400,
  53. ellipsis:true
  54. },
  55. {
  56. title: '操作',
  57. key: 'option',
  58. width: 120,
  59. valueType: 'option',
  60. render: (_: any, record: any) => {
  61. return [
  62. <UpDataActBtn key={'act'} record={record} type='EDIT' />,
  63. <Popconfirm
  64. title="是否确认删除?"
  65. key="del"
  66. onConfirm={() => delTableData(record)}
  67. >
  68. <a>删除</a>
  69. </Popconfirm>
  70. ]
  71. },
  72. },
  73. ]
  74. const getTableData = async (params: any) => {
  75. const resp = await getIndicProjectTableData(params);
  76. if (resp) {
  77. return {
  78. data: resp.list,
  79. success: true,
  80. total: resp.totalCount,
  81. pageSize: resp.pageSize,
  82. totalPage: resp.totalPage,
  83. }
  84. }
  85. return []
  86. }
  87. const delTableData = async (record: any) => {
  88. const resp = await delData(record.id);
  89. if (resp) {
  90. message.success('操作成功!');
  91. tableRef.current?.reload();
  92. // message.success('操作成功!');
  93. }
  94. }
  95. const updateTable = async (formVal: any, type: 'EDIT' | "ADD") => {
  96. const result = {
  97. indicatorName: formVal.indicatorName,
  98. indicatorType: formVal.indicatorType,
  99. indicatorDefinition: formVal.indicatorDefinition,
  100. orderPointValue: formVal.orderPointValue,
  101. //executePointValue: formVal.executePointValue,
  102. sql: formVal.sql
  103. }
  104. if (type == 'ADD') {
  105. const resp = await addData({...result});
  106. if (resp) {
  107. tableRef.current?.reload();
  108. message.success('操作成功!');
  109. }
  110. }
  111. if (type == 'EDIT') {
  112. const resp = await editData({id:formVal.id,...result});
  113. if (resp) {
  114. tableRef.current?.reload();
  115. message.success('操作成功!');
  116. }
  117. }
  118. return true;
  119. }
  120. const [dicData, set_dicData] = useState<any[]>([]);
  121. const getDirecData = async (key?: string) => {
  122. const data = await getPubDicData();
  123. if (data) {
  124. set_dicData(data);
  125. }
  126. }
  127. const UpDataActBtn = ({ record, type }: { record: any, type: 'EDIT' | 'ADD' }) => {
  128. return (
  129. <ModalForm
  130. title={`${type == 'EDIT' ? '编辑' : '新增'}指标项目`}
  131. width={352}
  132. initialValues={type == 'EDIT' ? { ...record,itemType:{label:record.itemType,value:record.itemTypeCode} } : {coreFlag:1}}
  133. trigger={
  134. type == 'EDIT' ? <a key="edit" >编辑</a> : <span className='add'>新增</span>
  135. }
  136. onFinish={(val) => {
  137. return updateTable(type == 'EDIT' ? { ...record, ...val,orderPointValue:val.orderPointValue?val.orderPointValue:undefined } : { ...val }, type);
  138. }}
  139. modalProps={{ destroyOnClose: true }}
  140. colProps={{ span: 24 }}
  141. grid
  142. >
  143. <ProFormText
  144. name="indicatorName"
  145. label="项目名称:"
  146. placeholder="请输入"
  147. rules={[{ required: true, message: '名称不能为空!' }]}
  148. />
  149. <ProFormSelect label="类型:"
  150. name='indicatorType'
  151. options={[{label:'工作量指标',value:1},{label:'运营指标',value:2}]}
  152. // fieldProps={{ labelInValue: true }}
  153. rules={[{ required: true, message: '类型不能为空!' }]}
  154. />
  155. <ProFormTextArea
  156. name="indicatorDefinition"
  157. label="定义:"
  158. placeholder="请输入"
  159. rules={[{ required: true, message: '定义不能为空!' }]}
  160. />
  161. <ProFormDigit
  162. name="orderPointValue"
  163. label="点值:"
  164. placeholder="请输入"
  165. />
  166. <ProFormTextArea
  167. name="sql"
  168. label="SQL:"
  169. placeholder="请输入"
  170. rules={[{ required: true, message: 'SQL不能为空!' }]}
  171. />
  172. </ModalForm>
  173. )
  174. }
  175. const tableDataSearchHandle = (paramName: string) => {
  176. set_tableDataFilterParams({
  177. ...tableDataFilterParams,
  178. [`${paramName}`]: tableDataSearchKeywords
  179. })
  180. }
  181. //获取按钮点击后获取数据
  182. const getDataBySQL = async () => {
  183. const resp = await getComputeDate();
  184. if (resp) {
  185. const respStat = await gainData({ compute_date: resp });
  186. if (respStat) {
  187. tableRef.current?.reload();
  188. }
  189. }
  190. }
  191. useEffect(() => {
  192. getDirecData();
  193. }, [])
  194. return (
  195. <BMSPagecontainer className='BilingProjectMana' title={false}>
  196. <div className='toolBar'>
  197. <div className='filter'>
  198. <div className='filterItem'>
  199. <span className='label' style={{ whiteSpace: 'nowrap' }}> 检索:</span>
  200. <Input placeholder={'请输入项目名称'} allowClear
  201. suffix={
  202. <IconFont type="iconsousuo" onClick={() => tableDataSearchHandle('name')} />
  203. }
  204. onChange={(e) => {
  205. set_tableDataSearchKeywords(e.target.value);
  206. if (e.target.value.length == 0) {
  207. set_tableDataFilterParams({
  208. ...tableDataFilterParams,
  209. name: ''
  210. });
  211. }
  212. }}
  213. onPressEnter={(e) => {
  214. set_tableDataFilterParams({
  215. ...tableDataFilterParams,
  216. name: (e.target as HTMLInputElement).value
  217. });
  218. }}
  219. />
  220. </div>
  221. </div>
  222. <div className='btnGroup'>
  223. {/* <span className='getDataBtn' onClick={() => getDataBySQL()}>获取</span> */}
  224. <UpDataActBtn record type='ADD' />
  225. </div>
  226. </div>
  227. <div style={{ marginTop: 16 }}>
  228. <BMSTable columns={columns as ProColumns[]} actionRef={tableRef} rowKey='id' params={tableDataFilterParams} request={(params) => getTableData(params)} />
  229. </div>
  230. </BMSPagecontainer>
  231. )
  232. }