detail.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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. console.log(jsonData);
  348. // if (Array.isArray(data)) {
  349. jsonData.map((item) => {
  350. if (item.celldata && typeof item.celldata == 'string')
  351. item.celldata = JSON.parse(item.celldata);
  352. if (item.config && typeof item.celldata == 'string')
  353. item.config = JSON.parse(item.config);
  354. });
  355. // } else {
  356. // if (data.celldata) data.celldata = JSON.parse(data.celldata);
  357. // if (data.config) data.config = JSON.parse(data.config);
  358. // }
  359. renderSheet(jsonData, data.is_edit);
  360. // if (jsonData[0].celldata && typeof jsonData[0].celldata == 'string')
  361. // jsonData[0].celldata = JSON.parse(jsonData[0].celldata);
  362. // if (jsonData[0].config && typeof jsonData[0].config == 'string')
  363. // jsonData[0].config = JSON.parse(jsonData[0].config);
  364. // renderSheet(jsonData, data.is_edit);
  365. } else {
  366. setExcelData({ name: '' });
  367. setNoData(true);
  368. }
  369. },
  370. });
  371. //请求签字版PSR历史版本列表
  372. const { run: run, loading: loading } = useRequest(
  373. (id) =>
  374. queryPsrExcelList({
  375. project_id: projectId,
  376. template_node_id: id,
  377. }),
  378. {
  379. manual: true,
  380. formatResult: (res) => {
  381. if (res.code == 200) {
  382. const list = res?.data?.list?.map((item) => {
  383. return { ...item, name: item.version_name };
  384. });
  385. setHistoryList(list);
  386. }
  387. },
  388. },
  389. );
  390. // useEffect(() => {
  391. // let url = '/psrData.json';
  392. // axios.get(url).then((res) => {
  393. // if (res.status == 200) {
  394. // renderSheet(res.data);
  395. // }
  396. // });
  397. // }, [key]);
  398. const data_type = useMemo(() => {
  399. if (key == '3') return 1;
  400. if (key == '4') return 2;
  401. return null;
  402. }, [key]);
  403. useEffect(() => {
  404. let str = '';
  405. switch (key) {
  406. case '2':
  407. str = '签字版PSR_';
  408. break;
  409. case '3':
  410. str = '过程/终版PSR_';
  411. break;
  412. case '4':
  413. str = '现金流_';
  414. break;
  415. }
  416. titleRef.current = str;
  417. setCompareValues([]);
  418. if (key) {
  419. onChange(key);
  420. } else {
  421. queryPsrExcel({ gridKey: node_id });
  422. }
  423. }, [key]);
  424. //请求投标版、签字版psr excel
  425. const queryPsrExcel = (data) => {
  426. axios({
  427. url: `/api/v1/purchase/record/sheet?${stringify(data)}`,
  428. method: 'POST',
  429. data,
  430. headers: {
  431. 'JWT-TOKEN': token,
  432. },
  433. }).then((req) => {
  434. if (req.status == 200) {
  435. const jsonData = JSON.parse(req.data);
  436. renderSheet(jsonData);
  437. }
  438. });
  439. };
  440. const onChange = (key) => {
  441. if (key == '1') {
  442. queryPsrExcel({ gridKey: node_id });
  443. } else if (key == '2') {
  444. queryPsrExcel({ gridKey: flow_id });
  445. } else {
  446. initPsrActrual(key);
  447. }
  448. };
  449. //请求前两个tab的数据
  450. const initPsrActrual = async (key) => {
  451. const data_type = key == '3' ? 1 : 2;
  452. const res = await queryPsrMonthLast({ project_id: projectId, data_type });
  453. if (res.data?.length > 0 && res.data[0].json_data) {
  454. let name = `${titleRef.current}${dayjs(res.data[0].day).format(
  455. 'YYYY-MM',
  456. )}`;
  457. if (res.data[0].ver_type == 1) name = '原始版本';
  458. if (res.data[0].ver_type == 2) name = '基础版本';
  459. const isOrigin = res.data[0].ver_type == 1 ? 1 : 0;
  460. setIsOriginVer(isOrigin);
  461. setExcelData({ ...res.data[0], name });
  462. const data = JSON.parse(res.data[0].json_data);
  463. const canEdit = isOrigin ? 0 : res.data[0].is_edit;
  464. if (Array.isArray(data)) {
  465. data.map((item) => {
  466. if (item.celldata && typeof item.celldata == 'string')
  467. item.celldata = JSON.parse(item.celldata);
  468. if (item.config && typeof item.celldata == 'string')
  469. item.config = JSON.parse(item.config);
  470. });
  471. renderSheet(data, canEdit);
  472. } else {
  473. if (data.celldata) data.celldata = JSON.parse(data.celldata);
  474. if (data.config) data.config = JSON.parse(data.config);
  475. renderSheet([data], canEdit);
  476. }
  477. } else {
  478. setIsOriginVer(false);
  479. setExcelData({ name: '' });
  480. setNoData(true);
  481. }
  482. };
  483. //另存为月版本
  484. const handlerSaveOther = (data) => {
  485. const luckyData = luckysheetRef.current?.toJson();
  486. luckyData?.data.forEach((item) => delete item.data);
  487. //设置表单日期
  488. const date =
  489. data.ver_type == 2 //基础版本是创建当天的日期 月版本是创建月份的最后一天
  490. ? dayjs().format('YYYY-MM-DD')
  491. : dayjs(data.day).endOf('month').format('YYYY-MM-DD');
  492. const days = changeDate(date);
  493. const celldata = luckyData?.data[0]?.celldata;
  494. const rc = key == '3' ? { r: 1, c: 1 } : { r: 1, c: 3 }; //psr日期位置是1 1 现金流日期位置是 1 3
  495. const dateItem = celldata?.find((item) => item.r == rc.r && item.c == rc.c);
  496. if (dateItem) {
  497. dateItem.v.v = days + '';
  498. // dateItem.v.m = days;
  499. }
  500. if (luckyData?.data) {
  501. const params = {
  502. ...data,
  503. project_id: Number(projectId),
  504. json_data: JSON.stringify(luckyData.data),
  505. data_type: data_type,
  506. };
  507. runSaveOther(params);
  508. }
  509. };
  510. //保存
  511. const handlerSave = () => {
  512. const luckyData = luckysheetRef.current?.toJson();
  513. let allData;
  514. //如果是现金流的保存。需要计算一些数值填充到psr中;
  515. if (key == '4') {
  516. //当月发生额数据 计算当月发生额的月份 originC
  517. let newMonthConfig = [...curMonthConfig];
  518. const celldata = luckyData.data[0].celldata;
  519. const originC = getMonthCol(celldata);
  520. if (originC || originC == 0) {
  521. newMonthConfig = curMonthConfig.map((item) => {
  522. return { ...item, originC };
  523. });
  524. }
  525. allData = getPsrDataByAct([...preActConfig, ...newMonthConfig]);
  526. console.log(allData);
  527. }
  528. const params = {
  529. id: excelData?.id,
  530. data_type: excelData?.data_type,
  531. project_id: excelData?.project_id,
  532. day: dayjs(excelData?.day).format('YYYY-MM-DD'),
  533. json_data: JSON.stringify(luckyData.data),
  534. psr_json_data: JSON.stringify(allData),
  535. };
  536. console.log(params);
  537. runSave(params);
  538. };
  539. //获取当月发生额的月份
  540. const getMonthCol = (celldata) => {
  541. //计算出当月发生额的月份 originC
  542. const date = changeDate(excelData?.day); //转换成55078这种格式
  543. const originC = celldata.find(
  544. (item) => item.r == 5 && Math.abs(item.v?.v - date) < 5,
  545. )?.c;
  546. return originC;
  547. };
  548. const getPsrDataByAct = (configList) => {
  549. const luckyData = luckysheetRef.current?.toJson();
  550. let otherValueTotal = 0; //获取除设备费之外的所有费用的和
  551. const preValues = configList.map((item) => {
  552. const celldata = luckyData.data[0].celldata;
  553. const {
  554. type,
  555. originC,
  556. num,
  557. originR: { begin, end },
  558. } = item;
  559. let value = 0;
  560. for (let i = begin; i <= end; i++) {
  561. const item = celldata.find((item) => item.c == originC && item.r == i);
  562. if (item?.v?.v) value += item.v.v;
  563. }
  564. if (type !== ZeroNineType.Equipment) otherValueTotal += value;
  565. return { num, value };
  566. });
  567. const EquPreItem = preValues.find(
  568. (item) => item.type == ZeroNineType.Equipment,
  569. );
  570. if (EquPreItem?.value)
  571. EquPreItem.value = EquPreItem?.value - otherValueTotal; //全部的费用 减去 除设备费之外的所有费用的和 得到设备费
  572. console.log('------预算列的值---------', preValues);
  573. return preValues;
  574. };
  575. const exportExcl = (className) => {
  576. const luckyData = luckysheetRef.current?.toJson();
  577. exportExcel(luckyData.data, name);
  578. };
  579. const handlerLoad = () => {
  580. const contentWindow = iframeRef.current.contentWindow;
  581. luckysheetRef.current = contentWindow.luckysheet;
  582. };
  583. const renderSheet = (currentData, is_edit = false) => {
  584. if (!currentData || !currentData[0]?.celldata) {
  585. setNoData(true);
  586. return;
  587. }
  588. setNoData(false);
  589. if (!luckysheetRef.current) {
  590. setTimeout(() => {
  591. renderSheet(currentData, is_edit);
  592. }, 500);
  593. return;
  594. }
  595. console.log('----------------------', currentData);
  596. const data = currentData;
  597. //设置单元格不可编辑
  598. data?.forEach((item) => {
  599. item.config.authority = is_edit
  600. ? null
  601. : {
  602. sheet: true,
  603. hintText: '当前excel不可编辑!',
  604. };
  605. // 公式计算
  606. let calcChain = [];
  607. let index = item.index;
  608. item.celldata?.forEach((cell) => {
  609. if (typeof cell.v.f !== 'undefined') {
  610. calcChain.push({
  611. r: cell.r,
  612. c: cell.c,
  613. index,
  614. });
  615. }
  616. });
  617. item.calcChain = calcChain;
  618. });
  619. let option = {
  620. lang: 'zh',
  621. showinfobar: false,
  622. showstatisticBar: false,
  623. permissions: user?.Permission,
  624. data: JSON.parse(JSON.stringify(data)),
  625. hook: {
  626. cellMousedown: (cell, position, sheet) => {
  627. console.log(cell, sheet);
  628. },
  629. cellUpdated: () => {
  630. luckysheetRef.current.refreshFormula();
  631. },
  632. workbookCreateAfter: async () => {
  633. setTimeout(() => {
  634. luckysheetRef.current.refreshFormula();
  635. }, 800);
  636. //当前为为终版psr标签并且可编辑状态时填充人日数据
  637. if (key == '3' && is_edit) {
  638. fillWorkLoadData();
  639. // const res = await queryPsrWorkLoad({ project_id: projectId });
  640. // if (res?.data) {
  641. // console.log('--------------------', res.data);
  642. // luckysheetRef.current.setCellValue(8, 4, res.data.Total);
  643. // luckysheetRef.current.setCellValue(8, 8, res.data.Month);
  644. // }
  645. }
  646. },
  647. },
  648. };
  649. option.data.forEach((item) => {
  650. delete item.data;
  651. if (item.celldata) {
  652. item.celldata.forEach((cell) => {
  653. // 生成uuid
  654. if (!cell.v.cid) cell.v.cid = getUUID();
  655. });
  656. }
  657. // 默认禁止编辑
  658. // item.config.authority = { sheet: true, hintText };
  659. });
  660. console.log(JSON.stringify(option));
  661. //设置不可编辑
  662. if (!is_edit) unableEdit(option);
  663. luckysheetRef.current.destroy();
  664. luckysheetRef.current.create(option);
  665. };
  666. const fillWorkLoadData = async () => {
  667. const param = { project_id: projectId };
  668. param.code = workConfig.map((item) => item.code).join(',');
  669. param.s_time = dayjs('2023-01').startOf('month').format('YYYY-MM-DD');
  670. param.e_time = dayjs('2023-07').endOf('month').format('YYYY-MM-DD');
  671. const res = await queryPsrWorkLoad(param);
  672. if (res?.data) {
  673. const data = { '02-010': [800, 100] };
  674. Object.keys(data).forEach((code) => {
  675. const list = data[code]; //第一个是当月的,第二个是累计的
  676. const fill = workConfig.find((item) => item.code == code)?.fill;
  677. if (list?.length > 0 && fill)
  678. luckysheetRef.current.setCellValue(fill.r, fill.curC, list[0]);
  679. luckysheetRef.current.setCellValue(fill.r, fill.actC, list[1]);
  680. });
  681. console.log('--------------------', res.data);
  682. // luckysheetRef.current.setCellValue(8, 4, res.data.Total);
  683. // luckysheetRef.current.setCellValue(8, 8, res.data.Month);
  684. }
  685. };
  686. const renderTitle = (data_type, name) => {
  687. if (compareValues?.length == 2) {
  688. return (
  689. <div className={styles.exportDiv}>
  690. <Button
  691. type="primary"
  692. onClick={() => {
  693. setCompareValues([]);
  694. setTimeout(() => {
  695. initPsrActrual(key);
  696. }, 500);
  697. }}
  698. >
  699. 退出比对
  700. </Button>
  701. </div>
  702. );
  703. }
  704. if (data_type == 0)
  705. //投标版psr
  706. return (
  707. <div className={styles.exportDiv}>
  708. <Button
  709. type="primary"
  710. onClick={() => exportExcl(name)}
  711. disabled={noData}
  712. >
  713. 导出
  714. </Button>
  715. </div>
  716. );
  717. if (data_type == 3)
  718. //签字版psr
  719. return (
  720. <div className={styles.excelTitle}>
  721. <div style={{ minWidth: '10px' }}>
  722. {/* 当前PSR表单:
  723. <span style={{ color: 'blue' }}>{excelData?.name}</span> */}
  724. </div>
  725. <Space>
  726. <Button
  727. type="primary"
  728. onClick={() => {
  729. run(init_flow_id);
  730. setHistoryOpen(true);
  731. }}
  732. disabled={noData}
  733. >
  734. 历史版本
  735. </Button>
  736. <Button
  737. type="primary"
  738. onClick={() => exportExcl(name)}
  739. disabled={noData}
  740. >
  741. 导出
  742. </Button>
  743. </Space>
  744. </div>
  745. );
  746. //过程/终版psr 现金流
  747. return (
  748. <div className={styles.excelTitle}>
  749. <div>
  750. 当前{key == '4' ? '现金流' : 'PSR'}表单:
  751. <span style={{ color: 'blue' }}>{excelData?.name}</span>
  752. </div>
  753. <Space>
  754. <Button
  755. type="primary"
  756. onClick={() => {
  757. runList();
  758. setHistoryOpen(true);
  759. }}
  760. disabled={noData}
  761. >
  762. 历史版本
  763. </Button>
  764. <Button
  765. type="primary"
  766. onClick={() => setOpen(true)}
  767. disabled={!excelData?.is_edit}
  768. >
  769. 另存为
  770. </Button>
  771. <Button
  772. type="primary"
  773. onClick={handlerSave}
  774. loading={saveLoading}
  775. disabled={!excelData?.is_edit || isOriginVer}
  776. >
  777. 保存
  778. </Button>
  779. <Button
  780. type="primary"
  781. onClick={() => setCompareOpen(true)}
  782. disabled={noData}
  783. >
  784. 比对
  785. </Button>
  786. <Button
  787. type="primary"
  788. onClick={() => exportExcl(excelData?.name)}
  789. disabled={noData}
  790. >
  791. 导出
  792. </Button>
  793. </Space>
  794. </div>
  795. );
  796. };
  797. const changeDate = (date) => {
  798. date = dayjs(date);
  799. const startDate = dayjs('1900-01-01');
  800. const daysDifference = date.diff(startDate, 'day');
  801. return daysDifference;
  802. };
  803. const items = [
  804. {
  805. key: '1',
  806. label: '投标版PSR',
  807. children: renderTitle(0, '投标版PSR'),
  808. },
  809. {
  810. key: '2',
  811. label: '签字版PSR',
  812. children: renderTitle(3, '签字版PSR'),
  813. },
  814. {
  815. key: '3',
  816. label: '过程/终版PSR',
  817. children: renderTitle(1, '过程/终版PSR'),
  818. },
  819. {
  820. key: '4',
  821. label: '现金流',
  822. children: renderTitle(2, '现金流'),
  823. },
  824. ];
  825. // const handlerOnChange = (event) => {
  826. // console.log(event);
  827. // console.log('----------------', luckysheetRef.current);
  828. // var file = event.target.files[0];
  829. // var fileName = file.name;
  830. // fileName = fileName + '';
  831. // //將文件加載到頁面上
  832. // LuckyExcel.transformExcelToLucky(
  833. // file,
  834. // function (exportJson, luckysheetfile) {
  835. // if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  836. // alert(
  837. // 'Failed to read the content of the excel file, currently does not support xls files!',
  838. // );
  839. // return;
  840. // }
  841. // console.log(exportJson, luckysheetfile);
  842. // renderSheet(exportJson?.sheets);
  843. // // window.luckysheet.destroy();
  844. // // window.luckysheet.create({
  845. // // container: 'luckysheet', //luckysheet is the container id
  846. // // showinfobar:false,
  847. // // lang: 'zh', // 设定表格语言
  848. // // allowEdit: true,//作用:是否允许前台编辑
  849. // // // allowUpdate: true,
  850. // // allowCopy: true, //是否允许拷贝
  851. // // showtoolbar: true, //是否第二列显示工具栏
  852. // // showinfobar: true, //是否显示顶部名称栏
  853. // // showsheetbar: true, //是否显示底部表格名称区域
  854. // // showstatisticBar: true, //是否显示底部计数栏
  855. // // pointEdit: false, //是否是编辑器插入表格模式
  856. // // pointEditUpdate: null, //编辑器表格更新函数
  857. // // data:exportJson.sheets,
  858. // // title:exportJson.info.name,
  859. // // userInfo:exportJson.info.name.creator,
  860. // // functionButton: '<button id="" class="btn btn-primary" style=" padding:3px 6px; font-size: 16px;width: 100px;height: 27px; margin-right: 85px;" οnclick="downExcelData()">導出</button>',
  861. // // });
  862. // },
  863. // );
  864. // };
  865. const handlerDetailClick = (id) => {
  866. if (key == '2') {
  867. queryPsrExcel({ gridKey: id });
  868. setHistoryOpen(false);
  869. return;
  870. }
  871. runDetail({ id });
  872. };
  873. return (
  874. <PageContent>
  875. <div className={styles.titleDev}>
  876. <Button type="primary" onClick={() => navigate(-1)}>
  877. 返回
  878. </Button>
  879. {/* <input type="file" onChange={handlerOnChange} /> */}
  880. <span className={styles.title}>{project_name}</span>
  881. </div>
  882. <Tabs
  883. defaultActiveKey="1"
  884. type="card"
  885. items={items}
  886. onChange={(key) => {
  887. setKey(key);
  888. titleRef.current = '';
  889. }}
  890. />
  891. {noData && <div className={styles.noData}>暂无数据</div>}
  892. {compareValues?.length == 2 ? (
  893. <CompareCom values={compareValues} />
  894. ) : (
  895. <iframe
  896. style={{
  897. width: '100%',
  898. height: '80vh',
  899. overflowX: 'hidden',
  900. display: noData ? 'none' : 'block',
  901. }}
  902. ref={iframeRef}
  903. onLoad={handlerLoad}
  904. src="/luckysheet.html"
  905. />
  906. )}
  907. <Drawer
  908. title="历史版本"
  909. placement="right"
  910. loading={listLoading}
  911. onClose={() => setHistoryOpen(false)}
  912. open={historyOpen}
  913. >
  914. <Timeline
  915. items={historyList?.map((item) => {
  916. return {
  917. children: (
  918. <a onClick={() => handlerDetailClick(item.id)}>
  919. {titleRef.current}
  920. {item.name}
  921. </a>
  922. ),
  923. };
  924. })}
  925. />
  926. </Drawer>
  927. <SaveModal
  928. showType={key == '4'}
  929. loading={saveOtherLoading}
  930. open={open}
  931. onCancel={() => setOpen(false)}
  932. onOk={handlerSaveOther}
  933. />
  934. <CompareModal
  935. list={historyList}
  936. open={compareOpen}
  937. onOk={(values) => {
  938. setCompareValues(values);
  939. setCompareOpen(false);
  940. }}
  941. onCancel={() => setCompareOpen(false)}
  942. />
  943. </PageContent>
  944. );
  945. };
  946. export default PSRDetail;