Index.js 35 KB

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