index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. /*
  2. * @Author: code4eat awesomedema@gmail.com
  3. * @Date: 2022-07-12 11:14:21
  4. * @LastEditors: code4eat awesomedema@gmail.com
  5. * @LastEditTime: 2022-07-20 10:44:16
  6. * @FilePath: /KC-MiddlePlatform/src/pages/platform/setting/indicatorMana/index.tsx
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. import KCTable from '@/components/kcTable';
  10. import { ActionType, ProColumns } from '@ant-design/pro-table';
  11. import React, { useEffect, useRef, useState } from 'react'
  12. import { Button, Drawer, Popconfirm } from 'antd'
  13. import Divider from '@ant-design/pro-card/lib/components/Divider';
  14. import DrawerForm from './DrawerForm/drawer';
  15. import ProForm from '@ant-design/pro-form/lib/layouts/ProForm';
  16. import { addIndicatorManaList, delIndicatorManaList, editIndicatorManaList, getIndicatorCateList, getIndicatorManaList, IndicatorManaItemType } from '@/service/indicator';
  17. import TreeDirectory from './TreeDirectory';
  18. import './style.less';
  19. import { getIndicatorDictionary, IndicatorDictionaryDataType } from '@/service/dictionary';
  20. import { useLocation } from 'umi';
  21. const IndicatorMana = () => {
  22. const [reloadTable, set_reloadTable] = useState(false);
  23. const [drawerVisible, set_drawerVisible] = useState(false);
  24. const [indicateType, set_indicateType] = useState<IndicatorDictionaryDataType[]>([]);
  25. const [currentEditRowData, set_currentEditRowData] = useState<any | undefined>(undefined);
  26. const [indicatorCateTreeData, set_indicatorCateTreeData] = useState<any[]>([]);
  27. const [defaultExpandedRowKeys, set_defaultExpandedRowKeys] = useState<string[]>([]);
  28. const [tableData, set_tableData] = useState<any[]>([]);
  29. const [cateId, set_cateId] = useState<string>();
  30. const [drawerActype, set_drawerActype] = useState<'ADD' | 'EDIT'>('ADD');
  31. const indicatorTableRef = useRef<ActionType>();
  32. const columns: ProColumns<any>[] = [
  33. {
  34. title: '指标名称',
  35. dataIndex: 'name',
  36. hideInSearch: false,
  37. width: '30%',
  38. ellipsis: true,
  39. },
  40. // {
  41. // title: '指标编码',
  42. // dataIndex: 'code',
  43. // ellipsis: true,
  44. // render: (text, record) => {
  45. // if (record) {
  46. // const { indicatorBoolean, code } = record;
  47. // return indicatorBoolean ? code : ''
  48. // } else {
  49. // return ''
  50. // }
  51. // }
  52. // },
  53. {
  54. title: '指标类别',
  55. dataIndex: 'indicatorType',
  56. hideInSearch:true,
  57. ellipsis: true,
  58. hideInTable: true,
  59. valueType: 'select',
  60. request: async () => {
  61. const resp = await getIndicatorDictionary();
  62. if (resp) {
  63. const data = resp.filter(t => t.code == 'IndicatorType');
  64. if (data.length > 0) {
  65. return data[0].children.map(t => ({ label: t.name, value: t.code }))
  66. }
  67. }
  68. return []
  69. },
  70. render: (text, record) => {
  71. if (record) {
  72. const { indicatorBoolean, indicatorTypeList } = record;
  73. return indicatorBoolean && indicatorTypeList ? (indicatorTypeList.map((t: any) => t.name)).join('/') : ''
  74. } else {
  75. return ''
  76. }
  77. }
  78. },
  79. {
  80. title: '外部指标',
  81. dataIndex: 'outsideIndexes',
  82. hideInSearch: true,
  83. ellipsis: true,
  84. hideInTable: true,
  85. valueType: 'cascader',
  86. fieldProps: {
  87. fieldNames: { label: 'name', value: 'code' },
  88. placeholder: '请选择'
  89. },
  90. request: async () => {
  91. const resp = await getIndicatorDictionary();
  92. if (resp) {
  93. const data = resp.filter(t => t.code == 'IndicatorExternal');
  94. if (data.length > 0) {
  95. return data[0].children
  96. }
  97. }
  98. return []
  99. },
  100. render: (text, record) => {
  101. if (record) {
  102. const { indicatorBoolean, indicatorExternalList } = record;
  103. return indicatorBoolean ? indicatorExternalList ? (indicatorExternalList.map((t: any) => t.name)).join('/') : '-' : ''
  104. } else {
  105. return ''
  106. }
  107. }
  108. },
  109. {
  110. title: '指标编码',
  111. dataIndex: 'code',
  112. hideInSearch:true,
  113. width: '10%',
  114. ellipsis: true,
  115. },
  116. {
  117. title: '指标定义',
  118. dataIndex: 'targetDefinition',
  119. hideInSearch:true,
  120. width: '30%',
  121. ellipsis: true,
  122. },
  123. {
  124. title: '操作',
  125. width: 200,
  126. key: 'option',
  127. valueType: 'option',
  128. render: (text, record) => {
  129. if (record && record.indicatorBoolean) {
  130. return (
  131. [
  132. <a key="linka" href={record.indicatorPath} target='_blank'>
  133. 数据展示
  134. </a>,
  135. <a key="link3" onClick={() => actionHandle('EDIT', record)}>
  136. 管理信息
  137. </a>,
  138. <Popconfirm
  139. title="是否确定删除?"
  140. onConfirm={() => delHandle(record)}
  141. okText="确定"
  142. cancelText="取消"
  143. key="link2"
  144. >
  145. <a>删除</a>
  146. </Popconfirm>,
  147. ]
  148. )
  149. }
  150. return []
  151. }
  152. ,
  153. },
  154. ];
  155. const getIndicatorDir = async () => {
  156. const resp = await getIndicatorDictionary();
  157. if (resp) {
  158. set_indicateType(resp);
  159. }
  160. }
  161. const getData = async (params: any) => {
  162. const { current = 1, name, indicatorType, outsideIndexes } = params;
  163. console.log({params});
  164. if(cateId){
  165. const resp = await getIndicatorManaList({
  166. current:1,
  167. pageSize:0,
  168. menuCode: cateId as string,
  169. indicatorName: name,
  170. indicatorType: indicatorType,
  171. outsideIndexes: outsideIndexes && outsideIndexes.length > 0 ? outsideIndexes[outsideIndexes.length - 1] : ''
  172. });
  173. if (resp&&resp[0]) {
  174. const getName:any = (obj:any)=>{
  175. let isArr = Array.isArray(obj);
  176. let reslut = [];
  177. if(isArr){
  178. obj.forEach((item: any) => {
  179. reslut.push(...getName(item));
  180. });
  181. }else{
  182. reslut.push(obj.menuId)
  183. if(obj.children){
  184. reslut.push(...getName(obj.children));
  185. }
  186. }
  187. return reslut;
  188. }
  189. set_tableData(resp[0].children as unknown as []);
  190. set_defaultExpandedRowKeys(getName(resp[0].children));
  191. return {
  192. data: resp[0].children as unknown as [],
  193. success: true,
  194. total: 1,
  195. };
  196. } else {
  197. return {
  198. data: [],
  199. success: true,
  200. total: 0,
  201. };
  202. }
  203. }
  204. return {
  205. data: [],
  206. success: false,
  207. total: 0,
  208. }
  209. }
  210. const getIndicatorCateTree = async () => {
  211. // console.log(location.search);
  212. let menuId = '';
  213. if (location.search.length > 0) {
  214. const searchArr = location.search.split('=');
  215. // console.log({ searchArr });
  216. if(searchArr[1]){
  217. const resp = await getIndicatorCateList({ menuCode: searchArr[1] });
  218. if (resp) {
  219. set_indicatorCateTreeData(resp);
  220. }
  221. }
  222. }
  223. }
  224. const actionHandle = async (key: 'EDIT' | 'DEL', record: IndicatorDictionaryDataType) => {
  225. set_currentEditRowData(record);
  226. if (key == 'EDIT') {
  227. set_drawerActype('EDIT');
  228. set_drawerVisible(true);
  229. }
  230. }
  231. const addHandle = () => {
  232. set_drawerActype('ADD');
  233. set_currentEditRowData(undefined);
  234. set_drawerVisible(true);
  235. }
  236. const delHandle = async (record: IndicatorDictionaryDataType) => {
  237. const resp = await delIndicatorManaList({ id: record.id });
  238. if (resp) {
  239. indicatorTableRef.current?.reload();
  240. }
  241. }
  242. const onVisibleChangeHandle = (bool: boolean) => {
  243. if (!bool) {
  244. set_drawerVisible(false);
  245. }
  246. if (bool) {
  247. set_drawerVisible(true);
  248. }
  249. }
  250. const drawerFormCommitHanndle = async (data: any) => {
  251. // const formData = Object.assign({}, data[0].baseInfoformRef, data[1].manaInfoformRef, data[2].showSetInfoformRef, data[3].adminInfoformRef);
  252. //const _formData = {...data[0].baseInfoformRef,...data[1].manaInfoformRef,...data[2].showSetInfoformRef,...data[3].adminInfoformRef}
  253. let formData:any;
  254. data.forEach((element:any) => {
  255. if(element.baseInfoformRef){
  256. formData = {...formData,...element.baseInfoformRef}
  257. }
  258. if(element.manaInfoformRef){
  259. formData = {...formData,...element.manaInfoformRef}
  260. }
  261. if(element.showSetInfoformRef){
  262. formData = {...formData,...element.showSetInfoformRef}
  263. }
  264. if(element.adminInfoformRef){
  265. formData = {...formData,...element.adminInfoformRef}
  266. }
  267. });
  268. if (drawerActype == 'ADD') {
  269. const resp = await addIndicatorManaList({
  270. ...formData,
  271. caseBreakdown: formData.caseBreakdown ? formData.caseBreakdown.join('/') : '',
  272. dataDownload: formData.dataDownload ? formData.dataDownload.join('/') : '',
  273. drillLevel: formData.drillLevel ? formData.drillLevel.join('/') : '',
  274. dataSum: formData.dataSum ? formData.dataSum.join('/') : '',
  275. chartType: formData.chartType ? formData.chartType.join('/') : '',
  276. indicatorMenuList: formData.indicatorMenuList ? formData.indicatorMenuList : [],
  277. indicatorTypeList: formData.indicatorTypeList ? formData.indicatorTypeList : [],
  278. indicatorExternalList: formData.indicatorExternalList ? formData.indicatorExternalList : [],
  279. divisionId: `${formData.divisionId}`,
  280. });
  281. if (resp) {
  282. set_drawerVisible(false);
  283. indicatorTableRef.current?.reload();
  284. }
  285. }
  286. if (drawerActype == 'EDIT') {
  287. const resp = await editIndicatorManaList({
  288. ...currentEditRowData,
  289. ...formData,
  290. caseBreakdown: formData.caseBreakdown ? formData.caseBreakdown.join('/') : '',
  291. dataDownload: formData.dataDownload ? formData.dataDownload.join('/') : '',
  292. drillLevel: formData.drillLevel ? formData.drillLevel.join('/') : '',
  293. dataSum: formData.dataSum ? formData.dataSum.join('/') : '',
  294. chartType: formData.chartType ? formData.chartType.join('/') : '',
  295. });
  296. if (resp) {
  297. set_drawerVisible(false);
  298. indicatorTableRef.current?.reload();
  299. }
  300. }
  301. }
  302. const onSelectChangehandle = (currentSelected: any) => {
  303. // console.log({ currentSelected });
  304. set_cateId(currentSelected.code);
  305. }
  306. useEffect(() => {
  307. if (tableData) {
  308. const keys = tableData.map((t: any) => t ? t.code : '');
  309. }
  310. }, [tableData]);
  311. useEffect(() => {
  312. // console.log({ cateId });
  313. // set_reloadTable(true);
  314. indicatorTableRef.current?.reload();
  315. }, [cateId]);
  316. useEffect(() => {
  317. getIndicatorCateTree();
  318. }, [location.search]);
  319. useEffect(() => {
  320. getIndicatorDir();
  321. getIndicatorCateTree();
  322. }, [])
  323. return (
  324. <div className='IndicatorMana'>
  325. <DrawerForm actType={drawerActype} visible={drawerVisible} onVisibleChange={onVisibleChangeHandle} onFinish={data => drawerFormCommitHanndle(data)} record={currentEditRowData} />
  326. <div className='content'>
  327. <div className='left'>
  328. <TreeDirectory data={indicatorCateTreeData} onSelectChange={(info) => onSelectChangehandle(info)} />
  329. </div>
  330. <div className='right'>
  331. {
  332. cateId && (
  333. <KCTable
  334. className='indicatorTable'
  335. rowKey="menuId"
  336. headerTitle="指标管理"
  337. columns={columns}
  338. actionRef={indicatorTableRef}
  339. expandable={{
  340. expandedRowKeys:defaultExpandedRowKeys,
  341. onExpand:(expanded, record)=>{
  342. // console.log({expanded, record});
  343. let _expandedKeys = [...defaultExpandedRowKeys];
  344. if(expanded){
  345. _expandedKeys.push(record.menuId)
  346. }else{
  347. const index = _expandedKeys.findIndex(t=>t==`${record.menuId}`);
  348. if(index != -1){
  349. _expandedKeys.splice(index,1);
  350. }
  351. }
  352. set_defaultExpandedRowKeys([..._expandedKeys]);
  353. }
  354. }}
  355. reload={reloadTable}
  356. search={{
  357. span: 8
  358. }}
  359. tableStyle={{ height: 600, overflow: 'scroll' }}
  360. pagination={{pageSize:100}}
  361. toolBarRender={() => [
  362. // <Button key="1" onClick={addHandle}>
  363. // 上传
  364. // </Button>,
  365. // <Button key="2" onClick={addHandle}>
  366. // 下载
  367. // </Button>,
  368. <Button key="3" type="primary" onClick={addHandle}>
  369. 新增
  370. </Button>,
  371. ]}
  372. request={(params) => getData(params)}
  373. />
  374. )
  375. }
  376. </div>
  377. </div>
  378. </div>
  379. )
  380. }
  381. export default IndicatorMana