Index.js 35 KB

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