detail.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  1. import PageContent from '@/components/PageContent';
  2. import { Button, Tabs, Space, Drawer, Timeline, message } from 'antd';
  3. import styles from './index.less';
  4. import { useEffect, useMemo, useRef, useState } from 'react';
  5. import axios from 'axios';
  6. import {
  7. useLocation,
  8. useParams,
  9. useRequest,
  10. useSearchParams,
  11. useNavigate,
  12. useModel,
  13. } from '@umijs/max';
  14. import {
  15. queryPsrExcel,
  16. queryPsrExcelList,
  17. queryPsrMonthDetail,
  18. queryPsrMonthLast,
  19. queryPsrMonthList,
  20. queryPsrWorkLoad,
  21. querySavePsrMonth,
  22. } from '../../services/psr';
  23. import SaveModal from './components/saveOtherModal';
  24. import CompareModal from './components/compareModal';
  25. import CompareCom from './components/compareCom';
  26. import dayjs from 'dayjs';
  27. import { getToken } from '@/utils/utils';
  28. import { exportExcel, getUUID } from '../../utils/exportExcl';
  29. import { stringify } from 'qs';
  30. import LuckyExcel from 'luckyexcel';
  31. const ZeroNineType = {
  32. Equipment: '09-010', //设备费
  33. Production: '09-020', //金科制造中心设备制造费
  34. UF: '09-030', //金科制造中心-UF膜(
  35. AI: '09-040', //数字双胞胎
  36. Install: '09-050', //安装分包费用(包括增值税)
  37. Construction: '09-060', //土建分包费用(包括增值税)
  38. };
  39. const preActConfig = [
  40. {
  41. type: ZeroNineType.Equipment,
  42. originC: 6,
  43. originR: { begin: 6, end: 297 }, //总的减上面所有的
  44. fill: { c: 5, r: 36 },
  45. num: 293,
  46. },
  47. {
  48. type: ZeroNineType.Production,
  49. originC: 6,
  50. originR: { begin: 17, end: 27 },
  51. //填充到psr表中的位置
  52. fill: { c: 5, r: 37 },
  53. num: 301,
  54. },
  55. {
  56. type: ZeroNineType.UF,
  57. originC: 6,
  58. originR: { begin: 6, end: 16 },
  59. fill: { c: 5, r: 38 },
  60. num: 309,
  61. },
  62. {
  63. type: ZeroNineType.AI,
  64. originC: 6,
  65. originR: { begin: 172, end: 192 },
  66. fill: { c: 5, r: 39 },
  67. num: 317,
  68. },
  69. {
  70. type: ZeroNineType.Install,
  71. originC: 6,
  72. originR: { begin: 214, end: 224 },
  73. fill: { c: 5, r: 40 },
  74. num: 325,
  75. },
  76. {
  77. type: ZeroNineType.Construction,
  78. originC: 6,
  79. originR: { begin: 214, end: 224 },
  80. fill: { c: 5, r: 41 },
  81. num: 333,
  82. },
  83. {
  84. type: ZeroNineType.Equipment,
  85. originC: 8,
  86. originR: { begin: 6, end: 297 }, //总的减上面所有的
  87. fill: { c: 3, r: 36 },
  88. num: 291,
  89. },
  90. {
  91. type: ZeroNineType.Production,
  92. originC: 8,
  93. originR: { begin: 17, end: 27 },
  94. //填充到psr表中的位置
  95. fill: { c: 3, r: 37 },
  96. num: 299,
  97. },
  98. {
  99. type: ZeroNineType.UF,
  100. originC: 8,
  101. originR: { begin: 6, end: 16 },
  102. fill: { c: 3, r: 38 },
  103. num: 307,
  104. },
  105. {
  106. type: ZeroNineType.AI,
  107. originC: 8,
  108. originR: { begin: 172, end: 192 },
  109. fill: { c: 3, r: 39 },
  110. num: 315,
  111. },
  112. {
  113. type: ZeroNineType.Install,
  114. originC: 8,
  115. originR: { begin: 214, end: 224 },
  116. fill: { c: 3, r: 40 },
  117. num: 323,
  118. },
  119. {
  120. type: ZeroNineType.Construction,
  121. originC: 8,
  122. originR: { begin: 214, end: 224 },
  123. fill: { c: 3, r: 41 },
  124. num: 331,
  125. },
  126. ];
  127. const curMonthConfig = [
  128. {
  129. type: ZeroNineType.Equipment,
  130. originC: null,
  131. originR: { begin: 6, end: 297 }, //总的减上面所有的
  132. fill: { c: 7, r: 36 },
  133. num: 295,
  134. },
  135. {
  136. type: ZeroNineType.Production,
  137. originC: null, //需要计算的出,当前表单是第几月,取当月的那列
  138. originR: { begin: 17, end: 27 },
  139. fill: { c: 7, r: 37 },
  140. num: 303,
  141. },
  142. {
  143. type: ZeroNineType.UF,
  144. originC: null,
  145. originR: { begin: 6, end: 16 },
  146. fill: { c: 7, r: 38 },
  147. num: 311,
  148. },
  149. {
  150. type: ZeroNineType.AI,
  151. originC: null,
  152. originR: { begin: 172, end: 192 },
  153. fill: { c: 7, r: 39 },
  154. num: 319,
  155. },
  156. {
  157. type: ZeroNineType.Install,
  158. originC: null,
  159. originR: { begin: 214, end: 224 },
  160. fill: { c: 7, r: 40 },
  161. num: 327,
  162. },
  163. {
  164. type: ZeroNineType.Construction,
  165. originC: null,
  166. originR: { begin: 214, end: 224 },
  167. fill: { c: 7, r: 41 },
  168. num: 335,
  169. },
  170. ];
  171. const workConfig = [
  172. {
  173. code: '02-010',
  174. fill: { r: 7, actC: 3, curC: 7 }, // actC实际支出 curC当月发生额
  175. },
  176. {
  177. code: '04-010',
  178. fill: { r: 11, actC: 3, curC: 7 },
  179. },
  180. {
  181. code: '05-010',
  182. fill: { r: 16, actC: 3, curC: 7 },
  183. },
  184. {
  185. code: '06-010',
  186. fill: { r: 24, actC: 3, curC: 7 },
  187. },
  188. {
  189. code: '07-010',
  190. fill: { r: 28, actC: 3, curC: 7 },
  191. },
  192. {
  193. code: '08-010',
  194. fill: { r: 32, actC: 3, curC: 7 },
  195. },
  196. {
  197. code: '10-010',
  198. fill: { r: 44, actC: 3, curC: 7 },
  199. },
  200. {
  201. code: '11-010',
  202. fill: { r: 59, actC: 3, curC: 7 },
  203. },
  204. {
  205. code: '11-030',
  206. fill: { r: 61, actC: 3, curC: 7 },
  207. },
  208. {
  209. code: '11-050',
  210. fill: { r: 63, actC: 3, curC: 7 },
  211. },
  212. ];
  213. const PSRDetail = () => {
  214. const { initialState } = useModel('@@initialState');
  215. const user = initialState?.user || {};
  216. const navigate = useNavigate();
  217. const params = useParams();
  218. const location = useLocation();
  219. const token = getToken();
  220. const { id: projectId } = params;
  221. const {
  222. state: { project_name, flow_id, node_id, init_flow_id },
  223. } = location;
  224. const [historyList, setHistoryList] = useState([]);
  225. const [excelData, setExcelData] = useState();
  226. const [historyOpen, setHistoryOpen] = useState();
  227. const [open, setOpen] = useState(false);
  228. const [key, setKey] = useState();
  229. const [compareOpen, setCompareOpen] = useState(false);
  230. const [compareValues, setCompareValues] = useState([]);
  231. const [isOriginVer, setIsOriginVer] = useState(false); //是否原始版本 是的话只能另存不能编辑
  232. const [noData, setNoData] = useState(false); //是否展示导出按钮
  233. const titleRef = useRef('');
  234. const luckysheetRef = useRef();
  235. const iframeRef = useRef();
  236. const unableEdit = (option) => {
  237. option.showtoolbar = false;
  238. option.enableAddRow = false;
  239. option.sheetFormulaBar = false;
  240. option.enableAddBackTop = false;
  241. option.showsheetbarConfig = {
  242. add: false,
  243. sheet: false,
  244. };
  245. option.cellRightClickConfig = {
  246. copy: false, // 复制
  247. copyAs: false, // 复制为
  248. paste: false, // 粘贴
  249. insertRow: false, // 插入行
  250. insertColumn: false, // 插入列
  251. deleteRow: false, // 删除选中行
  252. deleteColumn: false, // 删除选中列
  253. deleteCell: false, // 删除单元格
  254. hideRow: false, // 隐藏选中行和显示选中行
  255. hideColumn: false, // 隐藏选中列和显示选中列
  256. rowHeight: false, // 行高
  257. columnWidth: false, // 列宽
  258. clear: false, // 清除内容
  259. matrix: false, // 矩阵操作选区
  260. sort: false, // 排序选区
  261. filter: false, // 筛选选区
  262. chart: false, // 图表生成
  263. image: false, // 插入图片
  264. link: false, // 插入链接
  265. data: false, // 数据验证
  266. cellFormat: false, // 设置单元格格式
  267. };
  268. };
  269. //请求投标版、签字版psr excel
  270. // const { run: runExcel } = useRequest(queryPsrExcel, {
  271. // manual: true,
  272. // formatResult: (res) => {
  273. // if (res) {
  274. // const jsonData = JSON.parse(res);
  275. // renderSheet(jsonData);
  276. // }
  277. // },
  278. // });
  279. //请求月度psr和现金流列表 data_type 1 psr 2 现金流
  280. const {
  281. // data: historyList,
  282. run: runList,
  283. loading: listLoading,
  284. } = useRequest(
  285. (data) =>
  286. queryPsrMonthList({
  287. project_id: projectId,
  288. data_type: data_type,
  289. ...data,
  290. }),
  291. {
  292. manual: true,
  293. formatResult: (res) => {
  294. if (res.code == 200) {
  295. const list = res?.data?.list?.map((item) => {
  296. let name = dayjs(item.day).format('YYYY-MM');
  297. if (item.ver_type == 1) name = '原始版本';
  298. if (item.ver_type == 2) name = '基础版本';
  299. return { ...item, name };
  300. });
  301. setHistoryList(list);
  302. }
  303. },
  304. },
  305. );
  306. //保存月度psr和现金流接口
  307. const { run: runSave, loading: saveLoading } = useRequest(
  308. (data) => querySavePsrMonth(data),
  309. {
  310. manual: true,
  311. onSuccess: () => {
  312. message.success('保存成功');
  313. },
  314. onError: () => {
  315. message.success('添加失败');
  316. },
  317. },
  318. );
  319. //另存为月度psr和现金流接口
  320. const { run: runSaveOther, loading: saveOtherLoading } = useRequest(
  321. (data) => querySavePsrMonth(data),
  322. {
  323. manual: true,
  324. onSuccess: () => {
  325. message.success('另存成功');
  326. if (open) setOpen(false);
  327. //另存成功之后切换到最新的记录
  328. initPsrActrual(key);
  329. },
  330. onError: () => {
  331. message.success('另存失败');
  332. },
  333. },
  334. );
  335. //请求月度psr和现金流详情接口
  336. const { run: runDetail } = useRequest((data) => queryPsrMonthDetail(data), {
  337. manual: true,
  338. formatResult: (res) => {
  339. if (res?.data) {
  340. let data = res.data;
  341. let name = dayjs(data.day).format('YYYY-MM');
  342. if (data.ver_type == 1) name = '原始版本';
  343. if (data.ver_type == 2) name = '基础版本';
  344. setExcelData({ ...data, name });
  345. setHistoryOpen(false);
  346. const jsonData = JSON.parse(data.json_data);
  347. if (jsonData[0].celldata && typeof jsonData[0].celldata == 'string')
  348. jsonData[0].celldata = JSON.parse(jsonData[0].celldata);
  349. if (jsonData[0].config && typeof jsonData[0].config == 'string')
  350. jsonData[0].config = JSON.parse(jsonData[0].config);
  351. renderSheet(jsonData, data.is_edit);
  352. } else {
  353. setExcelData({ name: '' });
  354. setNoData(true);
  355. }
  356. },
  357. });
  358. //请求签字版PSR历史版本列表
  359. const { run: run, loading: loading } = useRequest(
  360. (id) =>
  361. queryPsrExcelList({
  362. project_id: projectId,
  363. template_node_id: id,
  364. }),
  365. {
  366. manual: true,
  367. formatResult: (res) => {
  368. if (res.code == 200) {
  369. const list = res?.data?.list?.map((item) => {
  370. return { ...item, name: item.version_name };
  371. });
  372. setHistoryList(list);
  373. }
  374. },
  375. },
  376. );
  377. // useEffect(() => {
  378. // let url = '/psrData.json';
  379. // axios.get(url).then((res) => {
  380. // if (res.status == 200) {
  381. // renderSheet(res.data);
  382. // }
  383. // });
  384. // }, [key]);
  385. const data_type = useMemo(() => {
  386. if (key == '3') return 1;
  387. if (key == '4') return 2;
  388. return null;
  389. }, [key]);
  390. useEffect(() => {
  391. let str = '';
  392. switch (key) {
  393. case '2':
  394. str = '签字版PSR_';
  395. break;
  396. case '3':
  397. str = '过程/终版PSR_';
  398. break;
  399. case '4':
  400. str = '现金流_';
  401. break;
  402. }
  403. titleRef.current = str;
  404. setCompareValues([]);
  405. if (key) {
  406. onChange(key);
  407. } else {
  408. queryPsrExcel({ gridKey: node_id });
  409. }
  410. }, [key]);
  411. //请求投标版、签字版psr excel
  412. const queryPsrExcel = (data) => {
  413. axios({
  414. url: `/api/v1/purchase/record/sheet?${stringify(data)}`,
  415. method: 'POST',
  416. data,
  417. headers: {
  418. 'JWT-TOKEN': token,
  419. },
  420. }).then((req) => {
  421. if (req.status == 200) {
  422. const jsonData = JSON.parse(req.data);
  423. renderSheet(jsonData);
  424. }
  425. });
  426. };
  427. const onChange = (key) => {
  428. if (key == '1') {
  429. queryPsrExcel({ gridKey: node_id });
  430. } else if (key == '2') {
  431. queryPsrExcel({ gridKey: flow_id });
  432. } else {
  433. initPsrActrual(key);
  434. }
  435. };
  436. //请求前两个tab的数据
  437. const initPsrActrual = async (key) => {
  438. const data_type = key == '3' ? 1 : 2;
  439. const res = await queryPsrMonthLast({ project_id: projectId, data_type });
  440. if (res.data?.length > 0 && res.data[0].json_data) {
  441. let name = `${titleRef.current}${dayjs(res.data[0].day).format(
  442. 'YYYY-MM',
  443. )}`;
  444. if (res.data[0].ver_type == 1) name = '原始版本';
  445. if (res.data[0].ver_type == 2) name = '基础版本';
  446. const isOrigin = res.data[0].ver_type == 1 ? 1 : 0;
  447. setIsOriginVer(isOrigin);
  448. setExcelData({ ...res.data[0], name });
  449. const data = JSON.parse(res.data[0].json_data);
  450. const canEdit = isOrigin ? 0 : res.data[0].is_edit;
  451. if (Array.isArray(data)) {
  452. data.map((item) => {
  453. if (item.celldata) item.celldata = JSON.parse(item.celldata);
  454. if (item.config) item.config = JSON.parse(item.config);
  455. });
  456. renderSheet(data, canEdit);
  457. } else {
  458. if (data.celldata) data.celldata = JSON.parse(data.celldata);
  459. if (data.config) data.config = JSON.parse(data.config);
  460. renderSheet([data], canEdit);
  461. }
  462. } else {
  463. setIsOriginVer(false);
  464. setExcelData({ name: '' });
  465. setNoData(true);
  466. }
  467. };
  468. //另存为月版本
  469. const handlerSaveOther = (data) => {
  470. const luckyData = luckysheetRef.current?.toJson();
  471. luckyData?.data.forEach((item) => delete item.data);
  472. //设置表单日期
  473. const date =
  474. data.ver_type == 2 //基础版本是创建当天的日期 月版本是创建月份的最后一天
  475. ? dayjs().format('YYYY-MM-DD')
  476. : dayjs(data.day).endOf('month').format('YYYY-MM-DD');
  477. const days = changeDate(date);
  478. const celldata = luckyData?.data[0]?.celldata;
  479. const rc = key == '3' ? { r: 1, c: 1 } : { r: 1, c: 3 }; //psr日期位置是1 1 现金流日期位置是 1 3
  480. const dateItem = celldata?.find((item) => item.r == rc.r && item.c == rc.c);
  481. if (dateItem) {
  482. dateItem.v.v = days + '';
  483. // dateItem.v.m = days;
  484. }
  485. if (luckyData?.data) {
  486. const params = {
  487. ...data,
  488. project_id: Number(projectId),
  489. json_data: JSON.stringify(luckyData.data),
  490. data_type: data_type,
  491. };
  492. runSaveOther(params);
  493. }
  494. };
  495. //保存
  496. const handlerSave = () => {
  497. const luckyData = luckysheetRef.current?.toJson();
  498. let allData;
  499. //如果是现金流的保存。需要计算一些数值填充到psr中;
  500. if (key == '4') {
  501. //当月发生额数据 计算当月发生额的月份 originC
  502. let newMonthConfig = [...curMonthConfig];
  503. const celldata = luckyData.data[0].celldata;
  504. const originC = getMonthCol(celldata);
  505. if (originC || originC == 0) {
  506. newMonthConfig = curMonthConfig.map((item) => {
  507. return { ...item, originC };
  508. });
  509. }
  510. allData = getPsrDataByAct([...preActConfig, ...newMonthConfig]);
  511. console.log(allData);
  512. }
  513. const params = {
  514. id: excelData?.id,
  515. data_type: excelData?.data_type,
  516. project_id: excelData?.project_id,
  517. day: dayjs(excelData?.day).format('YYYY-MM-DD'),
  518. json_data: JSON.stringify(luckyData.data),
  519. psr_json_data: JSON.stringify(allData),
  520. };
  521. console.log(params);
  522. runSave(params);
  523. };
  524. //获取当月发生额的月份
  525. const getMonthCol = (celldata) => {
  526. //计算出当月发生额的月份 originC
  527. const date = changeDate(excelData?.day); //转换成55078这种格式
  528. const originC = celldata.find(
  529. (item) => item.r == 5 && Math.abs(item.v?.v - date) < 5,
  530. )?.c;
  531. return originC;
  532. };
  533. const getPsrDataByAct = (configList) => {
  534. const luckyData = luckysheetRef.current?.toJson();
  535. let otherValueTotal = 0; //获取除设备费之外的所有费用的和
  536. const preValues = configList.map((item) => {
  537. const celldata = luckyData.data[0].celldata;
  538. const {
  539. type,
  540. originC,
  541. num,
  542. originR: { begin, end },
  543. } = item;
  544. let value = 0;
  545. for (let i = begin; i <= end; i++) {
  546. const item = celldata.find((item) => item.c == originC && item.r == i);
  547. if (item?.v?.v) value += item.v.v;
  548. }
  549. if (type !== ZeroNineType.Equipment) otherValueTotal += value;
  550. return { num, value };
  551. });
  552. const EquPreItem = preValues.find(
  553. (item) => item.type == ZeroNineType.Equipment,
  554. );
  555. if (EquPreItem?.value)
  556. EquPreItem.value = EquPreItem?.value - otherValueTotal; //全部的费用 减去 除设备费之外的所有费用的和 得到设备费
  557. console.log('------预算列的值---------', preValues);
  558. return preValues;
  559. };
  560. const exportExcl = (className) => {
  561. const luckyData = luckysheetRef.current?.toJson();
  562. exportExcel(luckyData.data, name);
  563. };
  564. const handlerLoad = () => {
  565. const contentWindow = iframeRef.current.contentWindow;
  566. luckysheetRef.current = contentWindow.luckysheet;
  567. };
  568. const renderSheet = (currentData, is_edit = false) => {
  569. if (!currentData || !currentData[0]?.celldata) {
  570. setNoData(true);
  571. return;
  572. }
  573. setNoData(false);
  574. if (!luckysheetRef.current) {
  575. setTimeout(() => {
  576. renderSheet(currentData, is_edit);
  577. }, 500);
  578. return;
  579. }
  580. console.log('----------------------', currentData);
  581. const data = currentData;
  582. //设置单元格不可编辑
  583. data?.forEach((item) => {
  584. item.config.authority = is_edit
  585. ? null
  586. : {
  587. sheet: true,
  588. hintText: '当前excel不可编辑!',
  589. };
  590. // 公式计算
  591. let calcChain = [];
  592. let index = item.index;
  593. item.celldata?.forEach((cell) => {
  594. if (typeof cell.v.f !== 'undefined') {
  595. calcChain.push({
  596. r: cell.r,
  597. c: cell.c,
  598. index,
  599. });
  600. }
  601. });
  602. item.calcChain = calcChain;
  603. });
  604. let option = {
  605. lang: 'zh',
  606. showinfobar: false,
  607. showstatisticBar: false,
  608. permissions: user?.Permission,
  609. data: JSON.parse(JSON.stringify(data)),
  610. hook: {
  611. cellMousedown: (cell, position, sheet) => {
  612. console.log(cell, sheet);
  613. },
  614. cellUpdated: () => {
  615. luckysheetRef.current.refreshFormula();
  616. },
  617. workbookCreateAfter: async () => {
  618. setTimeout(() => {
  619. luckysheetRef.current.refreshFormula();
  620. }, 800);
  621. //当前为为终版psr标签并且可编辑状态时填充人日数据
  622. if (key == '3' && is_edit) {
  623. fillWorkLoadData();
  624. // const res = await queryPsrWorkLoad({ project_id: projectId });
  625. // if (res?.data) {
  626. // console.log('--------------------', res.data);
  627. // luckysheetRef.current.setCellValue(8, 4, res.data.Total);
  628. // luckysheetRef.current.setCellValue(8, 8, res.data.Month);
  629. // }
  630. }
  631. },
  632. },
  633. };
  634. option.data.forEach((item) => {
  635. delete item.data;
  636. if (item.celldata) {
  637. item.celldata.forEach((cell) => {
  638. // 生成uuid
  639. if (!cell.v.cid) cell.v.cid = getUUID();
  640. });
  641. }
  642. // 默认禁止编辑
  643. // item.config.authority = { sheet: true, hintText };
  644. });
  645. console.log(JSON.stringify(option));
  646. //设置不可编辑
  647. if (!is_edit) unableEdit(option);
  648. luckysheetRef.current.destroy();
  649. luckysheetRef.current.create(option);
  650. };
  651. const fillWorkLoadData = async () => {
  652. const param = { project_id: projectId };
  653. param.code = workConfig.map((item) => item.code).join(',');
  654. param.s_time = dayjs('2023-01').startOf('month').format('YYYY-MM-DD');
  655. param.e_time = dayjs('2023-07').endOf('month').format('YYYY-MM-DD');
  656. const res = await queryPsrWorkLoad(param);
  657. if (res?.data) {
  658. const data = { '02-010': [800, 100] };
  659. Object.keys(data).forEach((code) => {
  660. const list = data[code]; //第一个是当月的,第二个是累计的
  661. const fill = workConfig.find((item) => item.code == code)?.fill;
  662. if (list?.length > 0 && fill)
  663. luckysheetRef.current.setCellValue(fill.r, fill.curC, list[0]);
  664. luckysheetRef.current.setCellValue(fill.r, fill.actC, list[1]);
  665. });
  666. console.log('--------------------', res.data);
  667. // luckysheetRef.current.setCellValue(8, 4, res.data.Total);
  668. // luckysheetRef.current.setCellValue(8, 8, res.data.Month);
  669. }
  670. };
  671. const renderTitle = (data_type, name) => {
  672. if (compareValues?.length == 2) {
  673. return (
  674. <div className={styles.exportDiv}>
  675. <Button
  676. type="primary"
  677. onClick={() => {
  678. setCompareValues([]);
  679. setTimeout(() => {
  680. initPsrActrual(key);
  681. }, 500);
  682. }}
  683. >
  684. 退出比对
  685. </Button>
  686. </div>
  687. );
  688. }
  689. if (data_type == 0)
  690. //投标版psr
  691. return (
  692. <div className={styles.exportDiv}>
  693. <Button
  694. type="primary"
  695. onClick={() => exportExcl(name)}
  696. disabled={noData}
  697. >
  698. 导出
  699. </Button>
  700. </div>
  701. );
  702. if (data_type == 3)
  703. //签字版psr
  704. return (
  705. <div className={styles.excelTitle}>
  706. <div style={{ minWidth: '10px' }}>
  707. {/* 当前PSR表单:
  708. <span style={{ color: 'blue' }}>{excelData?.name}</span> */}
  709. </div>
  710. <Space>
  711. <Button
  712. type="primary"
  713. onClick={() => {
  714. run(init_flow_id);
  715. setHistoryOpen(true);
  716. }}
  717. disabled={noData}
  718. >
  719. 历史版本
  720. </Button>
  721. <Button
  722. type="primary"
  723. onClick={() => exportExcl(name)}
  724. disabled={noData}
  725. >
  726. 导出
  727. </Button>
  728. </Space>
  729. </div>
  730. );
  731. //过程/终版psr 现金流
  732. return (
  733. <div className={styles.excelTitle}>
  734. <div>
  735. 当前{key == '4' ? '现金流' : 'PSR'}表单:
  736. <span style={{ color: 'blue' }}>{excelData?.name}</span>
  737. </div>
  738. <Space>
  739. <Button
  740. type="primary"
  741. onClick={() => {
  742. runList();
  743. setHistoryOpen(true);
  744. }}
  745. disabled={noData}
  746. >
  747. 历史版本
  748. </Button>
  749. <Button
  750. type="primary"
  751. onClick={() => setOpen(true)}
  752. disabled={!excelData?.is_edit}
  753. >
  754. 另存为
  755. </Button>
  756. <Button
  757. type="primary"
  758. onClick={handlerSave}
  759. loading={saveLoading}
  760. disabled={!excelData?.is_edit || isOriginVer}
  761. >
  762. 保存
  763. </Button>
  764. <Button
  765. type="primary"
  766. onClick={() => setCompareOpen(true)}
  767. disabled={noData}
  768. >
  769. 比对
  770. </Button>
  771. <Button
  772. type="primary"
  773. onClick={() => exportExcl(excelData?.name)}
  774. disabled={noData}
  775. >
  776. 导出
  777. </Button>
  778. </Space>
  779. </div>
  780. );
  781. };
  782. const changeDate = (date) => {
  783. date = dayjs(date);
  784. const startDate = dayjs('1900-01-01');
  785. const daysDifference = date.diff(startDate, 'day');
  786. return daysDifference;
  787. };
  788. const items = [
  789. {
  790. key: '1',
  791. label: '投标版PSR',
  792. children: renderTitle(0, '投标版PSR'),
  793. },
  794. {
  795. key: '2',
  796. label: '签字版PSR',
  797. children: renderTitle(3, '签字版PSR'),
  798. },
  799. {
  800. key: '3',
  801. label: '过程/终版PSR',
  802. children: renderTitle(1, '过程/终版PSR'),
  803. },
  804. {
  805. key: '4',
  806. label: '现金流',
  807. children: renderTitle(2, '现金流'),
  808. },
  809. ];
  810. // const handlerOnChange = (event) => {
  811. // console.log(event);
  812. // console.log('----------------', luckysheetRef.current);
  813. // var file = event.target.files[0];
  814. // var fileName = file.name;
  815. // fileName = fileName + '';
  816. // //將文件加載到頁面上
  817. // LuckyExcel.transformExcelToLucky(
  818. // file,
  819. // function (exportJson, luckysheetfile) {
  820. // if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  821. // alert(
  822. // 'Failed to read the content of the excel file, currently does not support xls files!',
  823. // );
  824. // return;
  825. // }
  826. // console.log(exportJson, luckysheetfile);
  827. // renderSheet(exportJson?.sheets);
  828. // // window.luckysheet.destroy();
  829. // // window.luckysheet.create({
  830. // // container: 'luckysheet', //luckysheet is the container id
  831. // // showinfobar:false,
  832. // // lang: 'zh', // 设定表格语言
  833. // // allowEdit: true,//作用:是否允许前台编辑
  834. // // // allowUpdate: true,
  835. // // allowCopy: true, //是否允许拷贝
  836. // // showtoolbar: true, //是否第二列显示工具栏
  837. // // showinfobar: true, //是否显示顶部名称栏
  838. // // showsheetbar: true, //是否显示底部表格名称区域
  839. // // showstatisticBar: true, //是否显示底部计数栏
  840. // // pointEdit: false, //是否是编辑器插入表格模式
  841. // // pointEditUpdate: null, //编辑器表格更新函数
  842. // // data:exportJson.sheets,
  843. // // title:exportJson.info.name,
  844. // // userInfo:exportJson.info.name.creator,
  845. // // functionButton: '<button id="" class="btn btn-primary" style=" padding:3px 6px; font-size: 16px;width: 100px;height: 27px; margin-right: 85px;" οnclick="downExcelData()">導出</button>',
  846. // // });
  847. // },
  848. // );
  849. // };
  850. const handlerDetailClick = (id) => {
  851. if (key == '2') {
  852. queryPsrExcel({ gridKey: id });
  853. setHistoryOpen(false);
  854. return;
  855. }
  856. runDetail({ id });
  857. };
  858. return (
  859. <PageContent>
  860. <div className={styles.titleDev}>
  861. <Button type="primary" onClick={() => navigate(-1)}>
  862. 返回
  863. </Button>
  864. {/* <input type="file" onChange={handlerOnChange} /> */}
  865. <span className={styles.title}>{project_name}</span>
  866. </div>
  867. <Tabs
  868. defaultActiveKey="1"
  869. type="card"
  870. items={items}
  871. onChange={(key) => {
  872. setKey(key);
  873. titleRef.current = '';
  874. }}
  875. />
  876. {compareValues?.length == 2 ? (
  877. <CompareCom values={compareValues} />
  878. ) : noData ? (
  879. <div className={styles.noData}>暂无数据</div>
  880. ) : (
  881. <iframe
  882. style={{
  883. width: '100%',
  884. height: '80vh',
  885. overflowX: 'hidden',
  886. }}
  887. ref={iframeRef}
  888. onLoad={handlerLoad}
  889. src="/luckysheet.html"
  890. />
  891. )}
  892. <Drawer
  893. title="历史版本"
  894. placement="right"
  895. loading={listLoading}
  896. onClose={() => setHistoryOpen(false)}
  897. open={historyOpen}
  898. >
  899. <Timeline
  900. items={historyList?.map((item) => {
  901. return {
  902. children: (
  903. <a onClick={() => handlerDetailClick(item.id)}>
  904. {titleRef.current}
  905. {item.name}
  906. </a>
  907. ),
  908. };
  909. })}
  910. />
  911. </Drawer>
  912. <SaveModal
  913. showType={key == '4'}
  914. loading={saveOtherLoading}
  915. open={open}
  916. onCancel={() => setOpen(false)}
  917. onOk={handlerSaveOther}
  918. />
  919. <CompareModal
  920. list={historyList}
  921. open={compareOpen}
  922. onOk={(values) => {
  923. setCompareValues(values);
  924. setCompareOpen(false);
  925. }}
  926. onCancel={() => setCompareOpen(false)}
  927. />
  928. </PageContent>
  929. );
  930. };
  931. export default PSRDetail;