Index.js 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  1. import React, { useEffect, useState, useRef, useMemo } from 'react';
  2. import { UnorderedListOutlined, PlusOutlined } from '@ant-design/icons';
  3. import { Button, Modal, message, Alert, Avatar, Spin, Select, Menu, Dropdown } from 'antd';
  4. import { connect } from 'dva';
  5. import styles from './Index.less';
  6. import LuckySheet from './LuckySheet';
  7. import router from 'umi/router';
  8. import AuditModal from './AuditModal';
  9. // import CommentDrawer from './CommentDrawer';
  10. import RightDrawer from './RightDrawer';
  11. import CommitModal from './CommitModal';
  12. import CompareModal from './CompareModal';
  13. import ExportModal from './ExportModal';
  14. import FlowModal from './FlowModal';
  15. import HistoryModal from './HistoryModal';
  16. import TimeNode from './TimeNode';
  17. import FilesModal from './FilesModal';
  18. import VersionModal from './VersionModal';
  19. import CommitAuditModal from './CommitAuditModal';
  20. import CommentContent from '@/components/CommentContent';
  21. import MergeModal from './MergeModal';
  22. import { GetTokenFromUrl, getToken } from '@/utils/utils';
  23. import { queryDetail } from '@/services/boom';
  24. import HistoryDrawer from './HistoryDrawer';
  25. import AuditFlow from './AuditFlow';
  26. import { getCurrentUser } from '@/utils/authority';
  27. const LocalData = localStorage.luckysheet;
  28. const { Option } = Select;
  29. function Detail(props) {
  30. const {
  31. dispatch,
  32. comment,
  33. history,
  34. loading,
  35. currentUser,
  36. fileList,
  37. roleList,
  38. template,
  39. versionList,
  40. auditList,
  41. flowDetail,
  42. versionTree,
  43. match: { params },
  44. instanceDetail,
  45. } = props;
  46. const [versionTreeVisible, setVersionTreeVisible] = useState(false);
  47. const [commentVisible, setCommentVisible] = useState(false);
  48. const [mergeVisible, setMergeVisible] = useState(false);
  49. const [compareVisible, setCompareVisible] = useState(false);
  50. const [exportVisible, setExportVisible] = useState(false);
  51. const [commitVisible, setCommitVisible] = useState(false);
  52. const [auditVisible, setAuditVisible] = useState(false);
  53. const [flowVisible, setFlowVisible] = useState(false);
  54. const [versionVisible, setVersionVisible] = useState(false);
  55. const [commitAuditVisible, setCommitAuditVisible] = useState(false);
  56. const [sheet, setSheet] = useState({});
  57. const [compareList, setCompareList] = useState([]);
  58. const [edit, setEdit] = useState(false);
  59. const [isMerge, setIsMerge] = useState(false);
  60. const [version, setVersion] = useState({});
  61. const [user, setUser] = useState([]);
  62. const [updateCount, setUpdateCount] = useState({
  63. diff: 0,
  64. add: 0,
  65. });
  66. const [fileVisible, setFileVisible] = useState(false);
  67. const [exportDate, setExportData] = useState([]);
  68. const sheetRef = useRef();
  69. const sheetRef2 = useRef();
  70. const sheetRef3 = useRef();
  71. const fileRef = useRef();
  72. const userRef = useRef();
  73. const statusRef = useRef({
  74. edit: false,
  75. compare: false,
  76. });
  77. const cellPosition = useRef({});
  78. const projectId = parseInt(params.projectId);
  79. const templateId = parseInt(params.templateId);
  80. const auditDetail = useMemo(() => {
  81. let data = {
  82. processCode: '',
  83. deptId: '14169890',
  84. // userId: '16569001414345099',
  85. // deptId: currentUser.DingDepId || getCurrentUser()?.DingDepId,
  86. userId: currentUser.DingUserId || getCurrentUser()?.DingUserId,
  87. formComponentValues: [],
  88. activityId: '',
  89. status: version.audit_status,
  90. };
  91. if (version?.flow_id && instanceDetail?.tasks && instanceDetail.tasks?.length > 0) {
  92. let item = flowDetail.nodes.find(item => item.Id == version.template_node_id);
  93. if (!item) return data;
  94. const { tasks, form_component_values } = instanceDetail;
  95. data.processCode = item.process_code;
  96. data.activityId = tasks[tasks.length - 1]?.activity_id;
  97. data.formComponentValues = form_component_values?.filter(item => item.name);
  98. }
  99. return data;
  100. }, [instanceDetail, version]);
  101. const flow = useMemo(() => {
  102. let data = {
  103. active: 0,
  104. active_id: null,
  105. current: 0,
  106. currentNode: {},
  107. list: {
  108. FlowNodes: [],
  109. },
  110. };
  111. if (version?.flow_id && auditList?.length > 0) {
  112. let item = auditList.find(item => item.list.id == version.flow_id);
  113. if (!item) return data;
  114. // 查询当前节点
  115. let current = item.list.FlowNodes.findIndex(node => node.seq == item.active);
  116. item.current = current == -1 ? 0 : current;
  117. // 保存当前所处节点
  118. item.currentNode = item.list.FlowNodes[item.current];
  119. data = item;
  120. }
  121. return data;
  122. }, [auditList, version]);
  123. const active_audit = flow.active_audit;
  124. const isAuditor = useMemo(() => {
  125. const getUserRole = () => {
  126. let roleID = flow.currentNode?.AuditRoleInfo?.ID;
  127. let item = currentUser.roleList.find(role => role.ID == roleID);
  128. if (item) return true;
  129. return false;
  130. };
  131. return active_audit == 1 && getUserRole();
  132. }, [active_audit, flow, currentUser]);
  133. const onSave = () => {
  134. let sheet1 = compareList[0];
  135. Modal.confirm({
  136. title: '提示',
  137. content: `是否确认保存【${sheet1.version_name || sheet1.name}】`,
  138. okText: '确定',
  139. cancelText: '取消',
  140. onOk() {
  141. let sheetData = sheetRef3.current.getSheetJson().data;
  142. sheetData.forEach(sheet => {
  143. delete sheet.data;
  144. });
  145. let params = {
  146. ...sheet1,
  147. data: JSON.stringify(sheetData),
  148. };
  149. dispatch({
  150. type: 'detail/commitSheet',
  151. payload: params,
  152. callback: () => {
  153. onCompare(false);
  154. },
  155. });
  156. },
  157. });
  158. };
  159. const onCompare = async checkSheets => {
  160. if (checkSheets) {
  161. const [sheet1, sheet2] = checkSheets;
  162. sheet1.data = (
  163. await queryDetail({
  164. excel_id: sheet1.id,
  165. })
  166. ).data;
  167. sheet2.data = (
  168. await queryDetail({
  169. excel_id: sheet2.id,
  170. })
  171. ).data;
  172. setCompareList(checkSheets);
  173. statusRef.current.compare = true;
  174. } else {
  175. let index = compareList.findIndex(item => item.id == sheet.id);
  176. // 退出比对模式
  177. if (index == 0) {
  178. sheetRef3.current.toggleCompare(false);
  179. } else if (index == 1) {
  180. sheetRef2.current.toggleCompare(false);
  181. }
  182. setIsMerge(false);
  183. setCompareList([]);
  184. setSheet({
  185. ...sheet,
  186. });
  187. setUpdateCount({
  188. diff: 0,
  189. add: 0,
  190. });
  191. statusRef.current.compare = false;
  192. }
  193. setCommentVisible(false);
  194. };
  195. const renderSheetDom = (item, index) => {
  196. return (
  197. <div key={item?.id || 'temp'} className={styles.sheetItem}>
  198. <h3>{item.version_name || item?.name}</h3>
  199. <LuckySheet
  200. className={styles.sheet}
  201. ref={!index ? sheetRef3 : sheetRef2}
  202. data={item.data || null}
  203. // onClickCell={onClickCell}
  204. />
  205. </div>
  206. );
  207. };
  208. const onClickCell = (cell, position, s) => {
  209. console.log(cell);
  210. if (cell?.cid && !statusRef.current.edit) {
  211. let payload = {
  212. sheet_id: s.order || '0',
  213. excel_id: version.id,
  214. cid: cell.cid,
  215. };
  216. dispatch({
  217. type: 'detail/queryComment',
  218. payload,
  219. });
  220. cellPosition.current = {
  221. ...payload,
  222. sheet_index: (s.seq || 0) + '',
  223. };
  224. // setCommentVisible(true);
  225. }
  226. // 比对模式下双excl同步选中
  227. // if (statusRef.current.compare) {
  228. // sheetRef3.current.selectCell(position.r, position.c, s.order);
  229. // sheetRef2.current.selectCell(position.r, position.c, s.order);
  230. // }
  231. };
  232. const onCommit = (values, id) => {
  233. let currentNode = flowDetail.nodes.find?.(item => item.Id == version.template_node_id);
  234. let currentData = sheetRef.current.getSheetJson().data;
  235. let sheets = JSON.parse(JSON.stringify(currentData));
  236. if (!currentNode.muti_version) {
  237. // audit_status=4 表示为清单推进后留存的副本.不计入多清单计算
  238. let serviceVersion = versionList.find(
  239. item => item.audit_status != 4 && item.template_node_id == currentNode.Id
  240. );
  241. if (serviceVersion) {
  242. message.error(`新建清单失败!业务节点【${currentNode.label}】只能有一个清单!`);
  243. return;
  244. }
  245. }
  246. sheets.forEach(item => {
  247. delete item.data;
  248. });
  249. console.log(sheets);
  250. let params = {
  251. ...values,
  252. id: id,
  253. project_id: version.project_id,
  254. name: version.name,
  255. guid: version.guid,
  256. template_id: version.template_id,
  257. template_node_id: version.template_node_id,
  258. flow_id: version.flow_id,
  259. node_id: version.node_id,
  260. new_version: '0',
  261. audit_status: 0,
  262. data: JSON.stringify(sheets),
  263. base_id: version.id,
  264. };
  265. dispatch({
  266. type: 'detail/commitSheet',
  267. payload: params,
  268. callback: newVersion => {
  269. onCompare(false);
  270. setCommitVisible(false);
  271. setVersionVisible(false);
  272. changeVersion(newVersion);
  273. // 更新flow流程图
  274. dispatch({
  275. type: 'xflow/queryBoomFlowDetail',
  276. payload: {
  277. id: templateId,
  278. },
  279. });
  280. },
  281. });
  282. };
  283. const onUpdate = () => {
  284. if (flow.active != 0) return;
  285. let currentData = sheetRef.current.getSheetJson().data;
  286. let sheets = JSON.parse(JSON.stringify(currentData));
  287. sheets.forEach(item => {
  288. delete item.data;
  289. });
  290. console.log(sheets);
  291. let params = {
  292. ...version,
  293. data: JSON.stringify(sheets),
  294. };
  295. dispatch({
  296. type: 'detail/saveSheet',
  297. payload: params,
  298. });
  299. };
  300. const onAudit = ({ audit_comment }) => {
  301. const flowNode = flow.currentNode;
  302. dispatch({
  303. type: 'detail/approve',
  304. payload: {
  305. id: flow.active_id,
  306. project_id: projectId,
  307. audit_status: 2,
  308. flow_id: flowNode.flow_id,
  309. node_id: flowNode.seq,
  310. audit_comment,
  311. },
  312. callback: newVersion => {
  313. setAuditVisible(false);
  314. // 更新flow流程图
  315. dispatch({
  316. type: 'xflow/queryBoomFlowDetail',
  317. payload: {
  318. id: templateId,
  319. },
  320. });
  321. localStorage.excelId = newVersion.id;
  322. setVersion({
  323. ...version,
  324. flow_id: newVersion.flow_id,
  325. id: newVersion.id,
  326. });
  327. },
  328. });
  329. };
  330. const onApprove = flag => {
  331. if (!flag) {
  332. setAuditVisible(true);
  333. return;
  334. }
  335. let isSingle = false;
  336. let serviceNode;
  337. const flowNode = flow.currentNode;
  338. const getLastTemplateNodeId = data => {
  339. let result;
  340. const getFun = item => {
  341. if (item.flow_path?.length > 0) {
  342. getFun(item.flow_path[0]);
  343. } else {
  344. result = item.template_node_id;
  345. }
  346. };
  347. if (!data) return version.template_node_id;
  348. getFun(data[0]);
  349. return result;
  350. };
  351. let lastTemplateNodeId = version.template_node_id;
  352. if (version.flow_path) {
  353. //如果多节点审批 获取当前是否审批流程的最后一个审批节点
  354. let flowPathList = JSON.parse(version.flow_path);
  355. lastTemplateNodeId = getLastTemplateNodeId(flowPathList);
  356. }
  357. // 判断是否为最后一个审批节点
  358. if (
  359. lastTemplateNodeId == version.template_node_id &&
  360. flow.current == flow.list.FlowNodes.length - 1
  361. ) {
  362. serviceNode = flowDetail.nodes.find?.(item => item.Id == version.next_template_node_id);
  363. if (!serviceNode.muti_version) {
  364. //audit_status=4 表示为清单推进后留存的副本.不计入多清单计算
  365. isSingle = versionList.find(
  366. item => item.audit_status != 4 && item.template_node_id == serviceNode.Id
  367. );
  368. }
  369. }
  370. Modal.confirm({
  371. title: '提示',
  372. content: isSingle
  373. ? `节点【${serviceNode.label}】只能拥有一个清单,是否覆盖?`
  374. : `是否通过审批。`,
  375. okText: '确定',
  376. cancelText: '取消',
  377. onOk: () => {
  378. dispatch({
  379. type: 'detail/approve',
  380. payload: {
  381. id: flow.active_id,
  382. project_id: projectId,
  383. audit_status: 3,
  384. flow_id: flowNode.flow_id,
  385. node_id: flowNode.seq,
  386. },
  387. callback: newVersion => {
  388. // 更新flow流程图
  389. dispatch({
  390. type: 'xflow/queryBoomFlowDetail',
  391. payload: {
  392. id: templateId,
  393. },
  394. });
  395. // 更新审批流
  396. dispatch({
  397. type: 'detail/queryAuditList',
  398. payload: {
  399. template_id: version.template_id,
  400. template_node_id: version.template_node_id,
  401. flow_id: version.flow_id,
  402. version_id: version.version_id,
  403. },
  404. });
  405. if (flow.current == flow.list.FlowNodes.length - 1) {
  406. // 最后一个审核节点通过后 需要更新version id 不更不更,留在原地
  407. // localStorage.excelId = newVersion.id;
  408. // setVersion({
  409. // ...version,
  410. // flow_id: newVersion.flow_id,
  411. // id: newVersion.id,
  412. // });
  413. }
  414. },
  415. });
  416. },
  417. });
  418. };
  419. const onMerge = () => {
  420. const [sheet1, sheet2] = compareList;
  421. Modal.confirm({
  422. title: '提示',
  423. content: `是否确认将【${sheet2.version_name}】改动的内容同步至【${sheet1.version_name ||
  424. sheet1.name}】`,
  425. okText: '确定',
  426. cancelText: '取消',
  427. onOk() {
  428. // let sheet2Data = sheetRef2.current.getSheetJson()
  429. sheetRef3.current.mergeExcl(sheetRef2.current.updateCell);
  430. // setCompareList([...compareList]);
  431. // let currentData = sheetRef3.current.getSheetJson()
  432. // // 更新后重新比对
  433. // sheetRef2.current.toggleCompare(false);
  434. // sheetRef2.current.toggleCompare(true, currentData);
  435. },
  436. });
  437. };
  438. const onMergeVersion = async sheet2 => {
  439. // const [sheet1, sheet2] = checkSheets;
  440. const sheet1 = version;
  441. if (!sheet1.data) {
  442. sheet1.data = (
  443. await queryDetail({
  444. excel_id: sheet1.id,
  445. })
  446. ).data;
  447. }
  448. if (!sheet2.data) {
  449. sheet2.data = (
  450. await queryDetail({
  451. excel_id: sheet2.id,
  452. })
  453. ).data;
  454. }
  455. setIsMerge(true);
  456. setCompareList([sheet1, sheet2]);
  457. // setTimeout(() => {
  458. // sheetRef3.current.mergeExcl(sheet.data);
  459. // }, 400);
  460. };
  461. const handleClickFile = () => {
  462. fileRef.current.click();
  463. };
  464. const handleMenuClick = e => {
  465. console.log('click', e);
  466. switch (e.key) {
  467. case 'back':
  468. // 返回
  469. router.push(`/home`);
  470. break;
  471. // case 'version':
  472. // // 清单
  473. // queryHistory();
  474. // setCommentVisible(false);
  475. // setHistoryVisible(true);
  476. // break;
  477. case 'bomDetail':
  478. // 清单
  479. setCommentVisible(true);
  480. break;
  481. case 'export':
  482. // 导出
  483. handleExportClick();
  484. break;
  485. case 'commitAudit':
  486. // 提交流转
  487. setCommitAuditVisible(true);
  488. break;
  489. case 'flow':
  490. // 查看流程
  491. setFlowVisible(true);
  492. break;
  493. case 'compare':
  494. // 比对
  495. setCompareVisible(true);
  496. break;
  497. case 'template':
  498. // 模板
  499. handleClickFile();
  500. break;
  501. // case 'auditSuccess':
  502. // // 审核通过
  503. // onApprove(true);
  504. // break;
  505. // case 'auditFailed':
  506. // // 审核拒绝
  507. // onApprove(false);
  508. // break;
  509. // case 'edit':
  510. // // 编辑
  511. // handleEdit(true);
  512. case 'merge':
  513. // 同步清单
  514. setMergeVisible(true);
  515. break;
  516. case 'commit':
  517. // 提交
  518. // handleClickCommit();
  519. setCommitVisible(true);
  520. setCommentVisible(false);
  521. break;
  522. case 'attachment':
  523. // 附件
  524. setFileVisible(true);
  525. queryFiles();
  526. break;
  527. }
  528. };
  529. const renderBtns = () => {
  530. // 判断是否为比对模式
  531. if (compareList.length == 2) {
  532. // 判断是否为同步最新清单的比对
  533. if (isMerge) {
  534. return (
  535. <>
  536. <Button type="primary" onClick={() => onSave()}>
  537. 保存
  538. </Button>
  539. <Button onClick={() => onMerge()}>同步新增内容</Button>
  540. <Button onClick={() => onCompare(false)}>取消同步</Button>
  541. </>
  542. );
  543. } else {
  544. return <Button onClick={() => onCompare(false)}>取消比对</Button>;
  545. }
  546. }
  547. const menuList = [
  548. <Menu.Item key="back">返回</Menu.Item>,
  549. <Menu.Item key="bomDetail">详情</Menu.Item>,
  550. <Menu.Item key="export">导出</Menu.Item>,
  551. <Menu.Item key="compare">比对</Menu.Item>,
  552. <Menu.Item key="attachment">附件</Menu.Item>,
  553. ];
  554. // version.audit_status:4 为副本。不可操作
  555. if (version.audit_status != 4) {
  556. //判断权限配置,如果配置了,就指定权限的人可提交,没配置就全部人都可提交
  557. const getIsSubmit = () => {
  558. const nodeId = version.template_node_id;
  559. if (!flowDetail?.nodes || !nodeId) return;
  560. const node = flowDetail.nodes.find(item => item.Id == nodeId);
  561. if (!node || node.name == 'custom-circle') return;
  562. if (node?.role_list) {
  563. return node.role_list
  564. .split(',')
  565. .some(id => currentUser.roleList?.find(role => role.ID == id));
  566. }
  567. return true;
  568. };
  569. // console.log('是否有权限提交流转 ', getIsSubmit());
  570. if (getIsSubmit() && version.audit_status != 3)
  571. menuList.push(<Menu.Item key="commitAudit">提交流转</Menu.Item>);
  572. if (!isAuditor && canEdit() && !version.flow_id) {
  573. // menuList.push(<Menu.Item key="edit">编辑</Menu.Item>);
  574. menuList.push(<Menu.Item key="merge">同步</Menu.Item>);
  575. // menuList.push(<Menu.Item key="commit">提交</Menu.Item>);
  576. // if (history.list.length > 0) {
  577. // menuList.push(<Menu.Item key="approval">申请审批</Menu.Item>);
  578. // }
  579. }
  580. }
  581. return (
  582. <>
  583. <Dropdown overlay={<Menu onClick={handleMenuClick}>{menuList}</Menu>}>
  584. <UnorderedListOutlined style={{ fontSize: 30, cursor: 'pointer' }} />
  585. </Dropdown>
  586. </>
  587. );
  588. };
  589. const canEdit = () => {
  590. if (flow.list.FlowNodes.length - 1 == flow.current && active_audit == 3) return false;
  591. return active_audit != 1;
  592. };
  593. const renderAlert = () => {
  594. const audit_comment = history.list[0]?.audit_comment;
  595. let item = '';
  596. switch (active_audit) {
  597. case 0:
  598. if (!flow.list || flow.list.FlowNodes?.length == 0) return;
  599. item = <Alert message="审批拒绝" type="error" />;
  600. break;
  601. case 1:
  602. item = <Alert message="等待审核中" type="info" />;
  603. break;
  604. case 2:
  605. item = (
  606. <Alert
  607. message={`审批被拒绝${
  608. audit_comment ? `,拒绝原因:${audit_comment}` : ''
  609. }。请修改后重新提交`}
  610. type="error"
  611. />
  612. );
  613. break;
  614. case 3:
  615. item = <Alert message="审批通过" type="success" />;
  616. break;
  617. }
  618. return <div style={{ marginTop: 20 }}>{item}</div>;
  619. };
  620. const exportExcl = files => {
  621. sheetRef.current.uploadExcel(files, () => {
  622. fileRef.current.value = null;
  623. });
  624. };
  625. const getRowOneList = () => {
  626. const obj = sheetRef.current.getSheetJson();
  627. console.log(obj);
  628. const list = [];
  629. obj.data.forEach(item => {
  630. list.push(item.data[0]);
  631. });
  632. return list;
  633. };
  634. //点击导出弹出选择导出列弹框
  635. const handleExportClick = () => {
  636. setExportData(sheetRef.current.getSheetJson());
  637. setExportVisible(true);
  638. };
  639. const downloadExcel = checkValue => {
  640. sheetRef.current.downloadExcel(checkValue);
  641. setExportVisible(false);
  642. };
  643. const queryHistory = id => {
  644. return new Promise(reslove => {
  645. dispatch({
  646. type: 'detail/queryHistory',
  647. payload: {
  648. // excel_id: id || excelId,
  649. project_id: projectId,
  650. },
  651. callback: reslove,
  652. });
  653. });
  654. };
  655. const queryFiles = () => {
  656. dispatch({
  657. type: 'detail/queryFiles',
  658. payload: {
  659. // excel_id: id || excelId,
  660. excel_id: version.id,
  661. },
  662. });
  663. };
  664. const getUploadProps = () => {
  665. const token = getToken() || GetTokenFromUrl();
  666. const uploadProps = {
  667. name: 'file',
  668. showUploadList: false,
  669. action: `/api/v1/purchase/attachment/${version.id}`,
  670. headers: {
  671. 'JWT-TOKEN': token,
  672. },
  673. onChange(info) {
  674. if (info.file.status !== 'uploading') {
  675. console.log(info.file, info.fileList);
  676. }
  677. if (info.file.status === 'done') {
  678. message.success(`${info.file.name} 文件上传成功`);
  679. queryFiles();
  680. } else if (info.file.status === 'error') {
  681. message.error(`${info.file.name} 文件上传失败`);
  682. }
  683. },
  684. };
  685. return uploadProps;
  686. };
  687. const deleteFile = id => {
  688. dispatch({
  689. type: 'detail/deleteFiles',
  690. id: id,
  691. callback: () => {
  692. queryFiles();
  693. },
  694. });
  695. };
  696. const queryHistoryDetail = async item => {
  697. return new Promise(resolve => {
  698. dispatch({
  699. type: 'detail/queryHistoryDetail',
  700. payload: {
  701. excel_id: item.excel_id,
  702. history_id: item.id,
  703. },
  704. callback: sheet => {
  705. resolve(sheet);
  706. },
  707. });
  708. });
  709. };
  710. const getLoading = () => {
  711. let effects = loading.effects;
  712. return !loading.effects['detail/queryComment'] && loading.models.detail;
  713. };
  714. const getFilesLoading = () => {
  715. let effects = loading.effects;
  716. return loading.effects['detail/queryFiles'];
  717. };
  718. const downloadFile = record => {
  719. window.location.href = `${record.url}`;
  720. };
  721. const changeVersion = id => {
  722. let version;
  723. if (typeof id == 'object') {
  724. version = id;
  725. localStorage.excelId = version.id;
  726. localStorage.excelItem = JSON.stringify(version);
  727. } else {
  728. version = versionList.find(item => item.id == id);
  729. if (!version) return;
  730. localStorage.excelId = id;
  731. }
  732. setVersion(version);
  733. //请求历史版本
  734. dispatch({
  735. type: 'detail/queryVersionsTree',
  736. payload: {
  737. excel_id: version.id || localStorage.excelId,
  738. },
  739. });
  740. // 判断是否审批节点
  741. if (version.flow_id) {
  742. dispatch({
  743. type: 'detail/queryAuditList',
  744. payload: {
  745. template_id: version.template_id,
  746. template_node_id: version.template_node_id,
  747. flow_id: version.flow_id,
  748. version_id: version.version_id,
  749. },
  750. });
  751. dispatch({
  752. type: 'detail/queryDingInstanceDetail',
  753. payload: {
  754. process_instance_id: version.ding_instance_id, //创建表单成功返回的id
  755. },
  756. });
  757. }
  758. };
  759. const onSubmitNextNode = values => {
  760. dispatch({
  761. type: 'detail/submitNextNode',
  762. payload: values,
  763. callback: newVersion => {
  764. setCommitAuditVisible(false);
  765. // 更新version
  766. // localStorage.excelId = newVersion.id;
  767. // changeVersion({
  768. // ...version,
  769. // ...newVersion,
  770. // version_id: version.id
  771. // });
  772. // 更新flow流程图
  773. dispatch({
  774. type: 'xflow/queryBoomFlowDetail',
  775. payload: {
  776. id: templateId,
  777. },
  778. });
  779. },
  780. });
  781. };
  782. const getUser = newUser => {
  783. try {
  784. if (JSON.stringify(newUser) != JSON.stringify(userRef.current)) {
  785. userRef.current = newUser;
  786. setUser(newUser);
  787. }
  788. } catch (error) {}
  789. };
  790. const renderNode = () => {
  791. const nodeId = version.template_node_id;
  792. if (!flowDetail?.nodes || !nodeId) return;
  793. const node = flowDetail.nodes.find(item => item.Id == nodeId);
  794. // return `当前清单:${version.version_name || '-'}; 当前节点:${node?.label || '-'}`;
  795. return (
  796. <span className={styles.curTitle}>
  797. 当前清单: <span>{version.version_name || '-'}</span>当前节点:{' '}
  798. <span>{node?.label || '-'}</span>
  799. </span>
  800. );
  801. };
  802. const handleSubmitCell = (value, callback) => {
  803. if (!value) return;
  804. dispatch({
  805. type: 'detail/addComment',
  806. payload: {
  807. ...cellPosition.current,
  808. comment: value,
  809. },
  810. callback,
  811. });
  812. };
  813. useEffect(() => {
  814. dispatch({
  815. type: 'detail/queryProjectRecord',
  816. payload: {
  817. project_id: projectId,
  818. },
  819. });
  820. dispatch({
  821. type: 'xflow/queryBoomFlowDetail',
  822. payload: {
  823. id: templateId,
  824. },
  825. });
  826. dispatch({
  827. type: 'user/fetch',
  828. });
  829. }, []);
  830. useEffect(() => {
  831. if (compareList.length == 2) {
  832. const callback = ({ diff, add }) => {
  833. setUpdateCount(updateCount => {
  834. return {
  835. diff: diff.length,
  836. add: updateCount.add + add.length,
  837. };
  838. });
  839. };
  840. var update1 = sheetRef3.current.toggleCompare(true, compareList[1].data, callback);
  841. var update2 = sheetRef2.current.toggleCompare(true, compareList[0].data, callback);
  842. }
  843. }, [compareList]);
  844. useEffect(() => {
  845. if (versionList.length == 0) return;
  846. if (!version.id) {
  847. const excelId = localStorage.excelItem
  848. ? JSON.parse(localStorage.excelItem)
  849. : localStorage.excelId;
  850. changeVersion(excelId);
  851. } else {
  852. changeVersion(version.id);
  853. }
  854. }, [versionList]);
  855. return (
  856. <Spin spinning={false}>
  857. <div className={styles.top}>
  858. <div>
  859. <Button type="primary" style={{ marginRight: 20 }} onClick={() => setFlowVisible(true)}>
  860. 查看流程
  861. </Button>
  862. {/* 非审批节点可以创建清单 */}
  863. {flow?.active == 0 && (
  864. <Button type="primary" onClick={() => setVersionVisible(true)}>
  865. 新建清单
  866. </Button>
  867. )}
  868. {renderNode()}
  869. </div>
  870. <div className={styles.btns}>
  871. <Button
  872. type="primary"
  873. style={{ marginRight: 20 }}
  874. onClick={() => setVersionTreeVisible(true)}
  875. >
  876. 历史版本
  877. </Button>
  878. <Avatar.Group style={{ marginRight: 20 }}>
  879. {user.map((item, id) => (
  880. <Avatar
  881. key={`${id}-${item.name}`}
  882. style={{ backgroundColor: '#008dff' }}
  883. size="large"
  884. >
  885. {item.Name}
  886. </Avatar>
  887. ))}
  888. </Avatar.Group>
  889. {renderBtns()}
  890. </div>
  891. <input
  892. type="file"
  893. ref={fileRef}
  894. style={{ display: 'none' }}
  895. onChange={e => exportExcl(e.target.files)}
  896. />
  897. </div>
  898. {/* <TimeNode flow={flow} isAuditor={isAuditor} onApprove={onApprove}></TimeNode> */}
  899. {version.flow_id ? (
  900. <AuditFlow
  901. status={auditDetail.status}
  902. processCode={auditDetail.processCode}
  903. deptId={auditDetail.deptId}
  904. userId={auditDetail.userId}
  905. activityId={auditDetail.activityId}
  906. formComponentValues={auditDetail.formComponentValues}
  907. />
  908. ) : null}
  909. {/* {renderAlert()} */}
  910. {/* 判断是否为比对模式 */}
  911. {compareList.length == 2 ? (
  912. <>
  913. <Alert
  914. message={`比对结果:${updateCount.diff}项差异。${updateCount.add}项新增`}
  915. type="info"
  916. />
  917. <div className={styles.sheetBox}>{compareList.map(renderSheetDom)}</div>
  918. </>
  919. ) : (
  920. <div className={styles.sheetBox}>
  921. {version.id && (
  922. <LuckySheet
  923. className={styles.sheet}
  924. ref={sheetRef}
  925. onClickCell={onClickCell}
  926. version={version}
  927. templateId={templateId}
  928. getUser={getUser}
  929. onUpdate={onUpdate}
  930. />
  931. )}
  932. </div>
  933. )}
  934. <HistoryDrawer
  935. versionTree={versionTree}
  936. version={version}
  937. visible={versionTreeVisible}
  938. onChangeVersion={version => changeVersion(version)}
  939. onClose={() => setVersionTreeVisible(false)}
  940. />
  941. <CommentContent
  942. title="单元格沟通记录"
  943. comment={comment}
  944. onSubmit={handleSubmitCell}
  945. loading={loading.effects['detail/queryComment'] || loading.effects['detail/addComment']}
  946. />
  947. <RightDrawer
  948. version={version}
  949. visible={commentVisible}
  950. onClose={() => setCommentVisible(false)}
  951. />
  952. <CompareModal
  953. visible={compareVisible}
  954. version={version}
  955. onClose={() => setCompareVisible(false)}
  956. onOk={onCompare}
  957. />
  958. <MergeModal
  959. visible={mergeVisible}
  960. version={version}
  961. onClose={() => setMergeVisible(false)}
  962. onOk={onMergeVersion}
  963. />
  964. <ExportModal
  965. visible={exportVisible}
  966. sheet={exportDate.data}
  967. onClose={() => setExportVisible(false)}
  968. onOk={downloadExcel}
  969. />
  970. <FlowModal
  971. flowDetail={flowDetail}
  972. visible={flowVisible}
  973. onClose={() => setFlowVisible(false)}
  974. version={version}
  975. onChangeVersion={version => changeVersion(version)}
  976. />
  977. <AuditModal
  978. loading={getLoading()}
  979. visible={auditVisible}
  980. onClose={() => setAuditVisible(false)}
  981. onOk={onAudit}
  982. />
  983. <FilesModal
  984. loading={getFilesLoading()}
  985. visible={fileVisible}
  986. onClose={() => setFileVisible(false)}
  987. uploadProps={getUploadProps()}
  988. DeleteFile={deleteFile}
  989. downloadFile={downloadFile}
  990. data={fileList}
  991. />
  992. <VersionModal
  993. loading={getLoading()}
  994. visible={versionVisible}
  995. onClose={() => setVersionVisible(false)}
  996. onOk={values => onCommit(values)}
  997. />
  998. <CommitAuditModal
  999. loading={getLoading()}
  1000. visible={commitAuditVisible}
  1001. version={version}
  1002. onClose={() => setCommitAuditVisible(false)}
  1003. onOk={onSubmitNextNode}
  1004. />
  1005. </Spin>
  1006. );
  1007. }
  1008. export default connect(({ detail, user, xflow, loading }) => ({
  1009. flowDetail: xflow.flowDetail,
  1010. auditList: detail.auditList,
  1011. fileList: detail.fileList,
  1012. history: detail.history,
  1013. comment: detail.comment,
  1014. instanceDetail: detail.dingInstanceDetail,
  1015. currentUser: user.currentUser,
  1016. roleList: detail.roleList,
  1017. versionList: detail.versionList,
  1018. versionTree: detail.versionTree,
  1019. loading,
  1020. }))(Detail);