LuckySheet.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. import React from 'react';
  2. import { Button, message } from 'antd';
  3. import exportExcel, { getExcelBolob } from '@/utils/exportExcl';
  4. import LuckyExcel from 'luckyexcel';
  5. import { getToken, GetTokenFromUrl } from '@/utils/utils';
  6. import GoalSeek from '@/utils/GoalSeek';
  7. const hintText = '禁止编辑!请先点击编辑按钮。';
  8. const DIFF_COLOR = '#ff0000';
  9. const ADD_COLOR = '#00ff00';
  10. class LuckySheet extends React.Component {
  11. constructor(props) {
  12. super(props);
  13. this.sheetRef = React.createRef();
  14. this.luckysheet = null;
  15. this.updateTimer = null;
  16. this.currentSheetIndex = null;
  17. this.updateCell = {
  18. add: [],
  19. diff: [],
  20. };
  21. this.renderTimer = null;
  22. this.chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
  23. }
  24. componentWillUnmount() {
  25. this.luckysheet?.destroy();
  26. }
  27. componentDidUpdate(prveProps) {
  28. const prevVersion = prveProps.version || {};
  29. const curVersion = this.props.version || {};
  30. if (prevVersion?.id != curVersion?.id || prevVersion?.flow_id != curVersion.flow_id) {
  31. console.log(prevVersion, curVersion);
  32. this.renderSheet();
  33. }
  34. }
  35. getUUID(len = 8, radix = 16) {
  36. var chars = this.chars;
  37. var uuid = [],
  38. i;
  39. radix = radix || chars.length;
  40. if (len) {
  41. // Compact form
  42. for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
  43. } else {
  44. // rfc4122, version 4 form
  45. var r;
  46. // rfc4122 requires these characters
  47. uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
  48. uuid[14] = '4';
  49. // Fill in random data. At i==19 set the high bits of clock sequence as
  50. // per rfc4122, sec. 4.1.5
  51. for (i = 0; i < 36; i++) {
  52. if (!uuid[i]) {
  53. r = 0 | (Math.random() * 16);
  54. uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
  55. }
  56. }
  57. }
  58. return uuid.join('');
  59. }
  60. renderSheet(currentData) {
  61. const {
  62. onClickCell,
  63. version,
  64. getUser,
  65. onUpdate,
  66. templateId,
  67. onDelSheet,
  68. permissions,
  69. } = this.props;
  70. const data = currentData || this.props.data;
  71. const _this = this;
  72. if (!this.luckysheet) {
  73. clearTimeout(this.renderTimer);
  74. this.renderTimer = setTimeout(() => {
  75. this.renderSheet(currentData);
  76. }, 300);
  77. return;
  78. }
  79. let token = GetTokenFromUrl() || getToken();
  80. let option = {
  81. lang: 'zh',
  82. showinfobar: false,
  83. showstatisticBar: false,
  84. // forceCalculation: true,
  85. hook: {
  86. cellMousedown: (cell, position, sheet) => {
  87. console.log(cell, position, sheet);
  88. onClickCell && onClickCell(cell, position, sheet);
  89. },
  90. cellPasteBefore: cell => {
  91. console.log(cell);
  92. if (!cell) return;
  93. if (cell.cid) delete cell.cid;
  94. if (cell.bg == DIFF_COLOR || cell.bg == ADD_COLOR) {
  95. delete cell.bg;
  96. }
  97. },
  98. updated(operate) {
  99. if (operate.type == 'datachange') {
  100. if (_this.currentSheetIndex != operate.sheetIndex) {
  101. _this.currentSheetIndex = operate.sheetIndex;
  102. return;
  103. }
  104. // 延迟1秒
  105. clearTimeout(_this.updateTimer);
  106. _this.updateTimer = setTimeout(() => {
  107. onUpdate.bind(_this);
  108. onUpdate();
  109. }, 1000);
  110. }
  111. },
  112. // 修改批注后保存sheet
  113. commentUpdateAfter() {
  114. clearTimeout(_this.updateTimer);
  115. _this.updateTimer = setTimeout(() => {
  116. onUpdate.bind(_this);
  117. onUpdate(true);
  118. }, 1000);
  119. },
  120. sheetActivate: sheet => {
  121. console.log(sheet);
  122. setTimeout(() => {
  123. this.luckysheet.setCellFormat(0, 0, 'bg', '#fff');
  124. }, 100);
  125. },
  126. sheetDeleteAfter: sheet => {
  127. onDelSheet && onDelSheet(sheet?.sheet.id);
  128. },
  129. sheetActivate: sheet => {
  130. console.log(sheet);
  131. setTimeout(() => {
  132. this.luckysheet.setCellFormat(0, 0, 'bg', '#fff');
  133. }, 100);
  134. },
  135. workbookCreateAfter: options => {
  136. this.luckysheet.refreshFormula();
  137. },
  138. },
  139. };
  140. if (version) {
  141. const wsUrl =
  142. process.env.NODE_ENV == 'development'
  143. ? 'ws://47.96.12.136:8896/'
  144. : `ws://${location.host}/`;
  145. option = {
  146. ...option,
  147. allowUpdate: true,
  148. gridKey: version.id,
  149. templateId: templateId,
  150. // flowId: version.flow_id,
  151. loadUrl: `/api/v1/purchase/record/sheet?gridKey=${version.id}&JWT-TOKEN=${token}`,
  152. updateUrl: wsUrl + `api/v1/ws?id=${version.id}&sid=${templateId}&JWT-TOKEN=${token}`,
  153. // updateUrl: `ws://47.96.12.136:8896/api/v1/ws?id=${version.id}&sid=${templateId}&JWT-TOKEN=${token}`,
  154. // updateUrl: `ws://120.55.44.4:8896/api/v1/ws?id=${version.id}&sid=${templateId}&JWT-TOKEN=${token}`,
  155. authorityUrl: `/api/v1/purchase/bom/user/excel/col?depId=${localStorage.depId ||
  156. 0}&JWT-TOKEN=${token}`,
  157. getUser,
  158. permissions,
  159. // workbookCreateBefore(luckysheet) {
  160. // console.log('===============================', luckysheet);
  161. // let oldConfig = JSON.parse(JSON.stringify(luckysheet.getConfig()));
  162. // setTimeout(() => {
  163. // luckysheet.setConfig({
  164. // ...oldConfig,
  165. // authority: { sheet: true, hintText },
  166. // });
  167. // }, 300);
  168. // },
  169. };
  170. console.log(version);
  171. const unableEdit = option => {
  172. option.showtoolbar = false;
  173. option.enableAddRow = false;
  174. option.sheetFormulaBar = false;
  175. option.enableAddBackTop = false;
  176. option.showsheetbarConfig = {
  177. add: false,
  178. sheet: false,
  179. };
  180. option.cellRightClickConfig = {
  181. copy: false, // 复制
  182. copyAs: false, // 复制为
  183. paste: false, // 粘贴
  184. insertRow: false, // 插入行
  185. insertColumn: false, // 插入列
  186. deleteRow: false, // 删除选中行
  187. deleteColumn: false, // 删除选中列
  188. deleteCell: false, // 删除单元格
  189. hideRow: false, // 隐藏选中行和显示选中行
  190. hideColumn: false, // 隐藏选中列和显示选中列
  191. rowHeight: false, // 行高
  192. columnWidth: false, // 列宽
  193. clear: false, // 清除内容
  194. matrix: false, // 矩阵操作选区
  195. sort: false, // 排序选区
  196. filter: false, // 筛选选区
  197. chart: false, // 图表生成
  198. image: false, // 插入图片
  199. link: false, // 插入链接
  200. data: false, // 数据验证
  201. cellFormat: false, // 设置单元格格式
  202. };
  203. };
  204. if (version.flow_id) {
  205. option.authority = {
  206. sheet: true,
  207. hintText: '当前处于审批节点,禁止编辑!',
  208. };
  209. unableEdit(option);
  210. } else if (version.last_version) {
  211. option.authority = {
  212. sheet: true,
  213. hintText: '该清单已设置为最终版本,禁止编辑!',
  214. };
  215. unableEdit(option);
  216. } else if ((version.audit_status != 0 && version.audit_status != 5) || version.status == 1) {
  217. option.authority = {
  218. sheet: true,
  219. hintText: '当前清单不可编辑!',
  220. };
  221. unableEdit(option);
  222. }
  223. } else if (data && data.length > 0) {
  224. option.data = JSON.parse(JSON.stringify(data));
  225. option.data.forEach(item => {
  226. if (item.celldata) {
  227. item.celldata.forEach(cell => {
  228. // 生成uuid
  229. if (!cell.v.cid) cell.v.cid = this.getUUID();
  230. });
  231. }
  232. // 默认禁止编辑
  233. // item.config.authority = { sheet: true, hintText };
  234. });
  235. } else {
  236. // 默认sheet页数据
  237. data.data = [
  238. {
  239. name: 'sheet1',
  240. // config: {
  241. // authority: { sheet: true, hintText },
  242. // },
  243. },
  244. ];
  245. }
  246. this.luckysheet.destroy();
  247. this.luckysheet.create(option);
  248. // 比对模式会导致单元格出现[Object object]的情况 任意编辑后才会正常显示
  249. // 所以默认设置第一个单元格的背景色
  250. setTimeout(() => {
  251. this.luckysheet.setCellFormat(0, 0, 'bg', '#fff');
  252. }, 500);
  253. }
  254. // componentDidUpdate(prevProps) {
  255. // const { data } = this.props;
  256. // if (prevProps.data != data) {
  257. // this.renderSheet(data);
  258. // }
  259. // }
  260. handleLoad() {
  261. const { version } = this.props;
  262. let contentWindow = this.sheetRef.current.contentWindow;
  263. this.luckysheet = contentWindow.luckysheet;
  264. // this.luckysheet = this.luckysheet;
  265. // version存在 则需调用render
  266. if (version) {
  267. this.renderSheet();
  268. }
  269. // onLoad && onLoad();
  270. }
  271. selectCell(row, col, order) {
  272. this.luckysheet.setRangeShow({ row: [row, row], column: [col, col] }, { order });
  273. }
  274. toggleSheet(order) {
  275. this.luckysheet.setSheetActive(order);
  276. }
  277. getSheetJson() {
  278. let data = JSON.parse(JSON.stringify(this.luckysheet.toJson()));
  279. data.data.forEach(sheet => {
  280. let allCell = {},
  281. unknowCid = [];
  282. // 将cell以cid为界分别存储
  283. (sheet.celldata || []).forEach(cell => {
  284. if (!cell.v.cid) {
  285. unknowCid.push(cell);
  286. } else if (!allCell[cell.v.cid]) {
  287. allCell[cell.v.cid] = cell;
  288. } else {
  289. // 当存在相同cid时
  290. // 做异常处理
  291. delete cell.v.cid;
  292. unknowCid.push(cell);
  293. }
  294. if (cell.v.tb) cell.v.tb = Number(cell.v.tb);
  295. // 清除比对样式
  296. if (cell.v.bg == DIFF_COLOR || cell.v.bg == ADD_COLOR) {
  297. delete cell.v.bg;
  298. }
  299. });
  300. unknowCid.forEach(cell => {
  301. // 根据坐标生成唯一key,重复则增加后缀直至不重复
  302. let key = `${cell.r}-${cell.c}`;
  303. while (allCell[key]) {
  304. key += '|c';
  305. }
  306. cell.v.cid = key;
  307. allCell[key] = cell;
  308. });
  309. sheet.celldata = Object.values(allCell);
  310. });
  311. return data;
  312. }
  313. // 切换编辑状态
  314. toggleEdit(edit) {
  315. let luckysheet = this.luckysheet;
  316. if (edit) {
  317. let config = luckysheet.getConfig();
  318. luckysheet.setConfig({
  319. ...config,
  320. authority: { sheet: !edit, hintText },
  321. });
  322. } else {
  323. luckysheet.exitEditMode();
  324. }
  325. }
  326. // 切换比对状态
  327. toggleCompare(isCompare, compareData, callback) {
  328. let luckysheet = this.luckysheet;
  329. let diff = [];
  330. let add = [];
  331. const { onCompareSuccess } = this.props;
  332. // 判断dom是否加载完成
  333. if (!luckysheet) {
  334. setTimeout(() => {
  335. this.toggleCompare(isCompare, compareData, callback);
  336. }, 300);
  337. return;
  338. }
  339. if (isCompare) {
  340. // let currentData = this.luckysheet.toJson();
  341. let currentData = JSON.parse(JSON.stringify(this.props.data));
  342. currentData.forEach((sheet, index) => {
  343. let celldata1 = sheet.celldata;
  344. let celldata2 = compareData[index]?.celldata || [];
  345. celldata1.forEach(item => {
  346. // 不判断空字符串
  347. if (this.isEmpty(item)) return;
  348. var d2Item = celldata2.find(item2 => item2.v.cid == item.v.cid);
  349. if (d2Item && !this.isEmpty(d2Item)) {
  350. // v.ct.s相同,不做处理
  351. if (item.v.ct?.s && JSON.stringify(item.v.ct?.s) == JSON.stringify(d2Item.v.ct?.s))
  352. return;
  353. // v.v相同,不做处理
  354. if (d2Item.v.v == item.v.v) return;
  355. // 内容不同,标记diff颜色
  356. diff.push({
  357. ...item,
  358. sheetOrder: index,
  359. });
  360. item.v.bg = DIFF_COLOR;
  361. // luckysheet.setCellFormat(item.r, item.c, 'bg', DIFF_COLOR);
  362. } else {
  363. // 找不到同cid的单元格,标记add颜色
  364. add.push({
  365. ...item,
  366. sheetOrder: index,
  367. });
  368. item.v.bg = ADD_COLOR;
  369. // luckysheet.setCellFormat(item.r, item.c, 'bg', ADD_COLOR);
  370. }
  371. });
  372. });
  373. console.log(currentData);
  374. this.renderSheet(currentData);
  375. // luckysheet.refresh()
  376. } else {
  377. this.renderSheet(this.props.data);
  378. }
  379. this.updateCell = {
  380. diff,
  381. add,
  382. };
  383. callback && callback(this.updateCell);
  384. }
  385. isEmpty(item) {
  386. return (item?.v?.v ?? '') === '' && !item?.v?.ct?.s;
  387. }
  388. mergeExcl(updateCell = {}) {
  389. const { diff = [], add = [] } = updateCell;
  390. let currentData = this.luckysheet.toJson().data;
  391. let luckysheet = this.luckysheet;
  392. console.log(updateCell);
  393. diff.forEach(item => {
  394. let sheet = currentData[item.sheetOrder];
  395. let d1Item = sheet.celldata.find(item2 => item2.v.cid == item.v.cid);
  396. // 将差异项覆盖至当前文档
  397. d1Item.v = {
  398. ...item.v,
  399. bg: undefined,
  400. };
  401. });
  402. add.forEach(item => {
  403. // 将新增项添加至当前文档
  404. let sheet = currentData[item.sheetOrder];
  405. let d1Item = sheet.celldata.find(item2 => item2.r == item.r && item2.c == item.c);
  406. if (d1Item) {
  407. d1Item.v = {
  408. ...item.v,
  409. bg: undefined,
  410. };
  411. } else {
  412. sheet.celldata.push({
  413. ...item,
  414. sheetOrder: undefined,
  415. });
  416. }
  417. });
  418. currentData.forEach(sheet => {
  419. delete sheet.data;
  420. });
  421. this.renderSheet(currentData);
  422. // currentData.data.forEach((sheet, index) => {
  423. // if (!mergeData[index]) return;
  424. // let celldata1 = sheet.celldata;
  425. // let celldata2 = mergeData[index].celldata;
  426. // celldata2.forEach(item => {
  427. // let bg = item.v?.bg;
  428. // let d1Item;
  429. // if (bg == DIFF_COLOR) {
  430. // delete item.v.bg;
  431. // d1Item = celldata1.find(item2 => item2.v.cid == item.v.cid);
  432. // // 将差异项覆盖至当前文档
  433. // d1Item.v = item.v;
  434. // // luckysheet.setCellValue(d1Item.r, d1Item.c, item.v);
  435. // } else if (bg == ADD_COLOR) {
  436. // delete item.v.bg;
  437. // // 将新增项添加至当前文档
  438. // // luckysheet.setCellValue(item.r, item.c, item.v);
  439. // d1Item = celldata1.find(item2 => item2.r == item.r && item2.c == item.c);
  440. // if (d1Item) {
  441. // d1Item.v = item.v;
  442. // } else {
  443. // celldata1.push(item);
  444. // }
  445. // }
  446. // });
  447. // });
  448. // this.renderSheet(currentData);
  449. }
  450. /**
  451. * 导入excl
  452. * @param {*} files input:file的evt.target.files
  453. * @returns
  454. */
  455. uploadExcel(files, callback) {
  456. if (files == null || files.length == 0) {
  457. return;
  458. }
  459. let name = files[0].name;
  460. let suffixArr = name.split('.'),
  461. suffix = suffixArr[suffixArr.length - 1];
  462. if (suffix != 'xlsx') {
  463. alert('Currently only supports the import of xlsx files');
  464. message.error('只支持xlsx格式的文件!');
  465. return;
  466. }
  467. LuckyExcel.transformExcelToLucky(files[0], (exportJson, luckysheetfile) => {
  468. if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  469. message.error('读取xlsx文件失败!');
  470. return;
  471. }
  472. // this.luckysheet.destroy();
  473. // 同步当前文档内容
  474. let data = this.props.data;
  475. exportJson.sheets.forEach((sheet, index) => {
  476. if (!data || !data[index]) return;
  477. sheet.celldata.forEach(cell => {
  478. if (this.isEmpty(cell)) return;
  479. // return (item.v.v ?? '') === '' && !item.v.ct?.s;
  480. let dCell = (data[index].celldata || []).find(dCell => {
  481. return dCell.r == cell.r && dCell.c == cell.c;
  482. });
  483. if (this.isEmpty(dCell)) return;
  484. // 判断v.ct是否相同
  485. // if (cell?.v?.ct?.s && dCell.v.ct?.s && cell.v.ct?.s.join('') != dCell.v.ct?.s.join('')) return;
  486. if (cell?.v?.ct?.s && dCell.v.ct?.s) {
  487. if (cell.v.ct?.s.join('') != dCell.v.ct?.s.join('')) return;
  488. let cellS = cell.v.ct.s;
  489. let dCellS = dCell.v.ct.s;
  490. let isEqul = cellS.every((cur, idx) => {
  491. return JSON.stringify(cur) === JSON.stringify(dCellS[idx]);
  492. });
  493. if (!isEqul) return;
  494. }
  495. // 判断v.v是否相同
  496. if (cell?.v?.v && dCell.v.v != cell.v.v) return;
  497. // 内容相同则复制cid
  498. cell.cid = dCell.cid;
  499. });
  500. });
  501. this.renderSheet(exportJson.sheets);
  502. callback && callback();
  503. });
  504. }
  505. // 根据url导入excl
  506. // selectExcel(item) {
  507. // const {value,name} = item
  508. // if (value == '') {
  509. // return;
  510. // }
  511. // LuckyExcel.transformExcelToLuckyByUrl(value, name, (exportJson, luckysheetfile) => {
  512. // if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  513. // alert(
  514. // 'Failed to read the content of the excel file, currently does not support xls files!'
  515. // );
  516. // return;
  517. // }
  518. // this.luckysheet.destroy();
  519. // this.luckysheet.create({
  520. // container: 'luckysheet', //luckysheet is the container id
  521. // showinfobar: false,
  522. // data: exportJson.sheets,
  523. // title: exportJson.info.name,
  524. // userInfo: exportJson.info.name.creator,
  525. // });
  526. // });
  527. // }
  528. getExcelData(checkValue = null) {
  529. let resultList = [];
  530. console.log(this.luckysheet.getAllSheets());
  531. let currentData = this.luckysheet.getAllSheets();
  532. currentData.forEach(sheet => {
  533. let data = sheet.data;
  534. let celldata = sheet.celldata;
  535. let colList = [];
  536. data[0]?.forEach((rowOneItem, colIdx) => {
  537. if (rowOneItem) {
  538. if (!checkValue || checkValue.indexOf(rowOneItem.cid) !== -1) {
  539. colList.indexOf(colIdx) == -1 ? colList.push(colIdx) : true;
  540. }
  541. }
  542. });
  543. const newData = [];
  544. data.forEach(item => {
  545. if (item !== null) {
  546. let arr = item.filter((cur, idx) => {
  547. return item && colList.includes(idx);
  548. });
  549. newData.push(arr);
  550. }
  551. });
  552. sheet.data = newData;
  553. //消除空列后都列下标
  554. let newColIdxList = colList.map((cur, idx) => {
  555. return idx;
  556. });
  557. //处理celldata
  558. const newCellData = [];
  559. celldata.forEach(item => {
  560. let idx = colList.indexOf(item.c);
  561. if (idx !== -1) {
  562. item.c = newColIdxList[idx];
  563. newCellData.push(item);
  564. }
  565. });
  566. sheet.celldata = newCellData;
  567. });
  568. return currentData;
  569. }
  570. getExcelBolb() {
  571. let currentData = this.getExcelData();
  572. return getExcelBolob(currentData);
  573. }
  574. downloadExcel(checkValue) {
  575. let currentData = this.getExcelData(checkValue);
  576. exportExcel(currentData, '下载');
  577. }
  578. // 获取批注
  579. getComment() {
  580. let sheets = this.luckysheet.toJson().data;
  581. let comment = [];
  582. sheets.forEach(sheet => {
  583. sheet.celldata.forEach(cell => {
  584. // 判断是否含有批注
  585. if (cell?.v?.ps?.value) {
  586. comment.push({
  587. sheet: sheet.name,
  588. r: cell.r,
  589. c: cell.c,
  590. value: cell.v.ps.value || '',
  591. });
  592. }
  593. });
  594. });
  595. return comment;
  596. }
  597. async goalSeek(type, goal, setting) {
  598. const luckysheet = this.luckysheet;
  599. const sheet = this.luckysheet.getSheet({
  600. name: '毛利概算',
  601. });
  602. const order = sheet.order;
  603. try {
  604. let defaultValue = luckysheet.getCellValue(9, 2, {
  605. order,
  606. });
  607. const result = await GoalSeek({
  608. goal,
  609. fn: fn,
  610. fnParams: [defaultValue, sheet.data, type],
  611. maxIterations: 1000,
  612. independentVariableIdx: 0,
  613. ...setting,
  614. });
  615. luckysheet.setCellValue(9, 2, result, {
  616. order,
  617. });
  618. } catch (error) {
  619. console.log(error);
  620. }
  621. }
  622. render() {
  623. return (
  624. <iframe
  625. onLoad={e => {
  626. this.handleLoad(e);
  627. }}
  628. ref={this.sheetRef}
  629. src="/luckysheet.html"
  630. ></iframe>
  631. );
  632. }
  633. }
  634. function fn(C10, data, type) {
  635. let C50 = data[49][2].v || 0;
  636. let C49 = data[48][2].v || 0;
  637. let C20 = data[19][2].v || 0;
  638. let C21 = data[20][2].v || 0;
  639. let C9 = data[8][2].v || 0;
  640. let C15 = data[14][2].v || 0;
  641. let C16 = data[15][2].v || 0;
  642. let C17 = data[16][2].v || 0;
  643. let C18 = data[17][2].v || 0;
  644. let C19 = data[18][2].v || 0;
  645. let C51 = data[50][2].v || 0;
  646. let G42 = data[41][6].v || 0;
  647. let G12 = data[11][6].v || 0;
  648. let G13 = data[12][6].v || 0;
  649. let G7 = data[6][6].v || 0;
  650. let G8 = data[7][6].v || 0;
  651. switch (type) {
  652. case 1:
  653. // 净利率
  654. return C3() / C59();
  655. case 2:
  656. // 贡献毛利率
  657. return C4() / C59();
  658. case 3:
  659. // 合同总价
  660. return C59();
  661. }
  662. function C59() {
  663. return C58() + C57() + C56() + C54();
  664. }
  665. function C4() {
  666. return C3() + C50 + C49 + C48() + G42 + C43();
  667. }
  668. function C48() {
  669. return C59() * G12;
  670. }
  671. function C58() {
  672. return (C56() + C57()) * 0.12;
  673. }
  674. function C57() {
  675. return (((C20 + C21) * C10) / (1 + G7)) * G7 - ((C20 + C21) / (1 + G8)) * G8;
  676. }
  677. function C56() {
  678. return (
  679. (((C15 + C16 + C17 + C18 + C19) * C10) / (1 + G7)) * G7 -
  680. ((C15 + C16 + C17 + C18 + C19) / (1 + G7)) * G7
  681. );
  682. }
  683. function C54() {
  684. return SUM(2, [14, 20]) * C10;
  685. }
  686. function C3() {
  687. return C55() - C53();
  688. }
  689. function C55() {
  690. return C59() / (1 + G7);
  691. }
  692. function C53() {
  693. return C52() - ((SUM(2, [14, 18]) / (1 + G7)) * G7 + (SUM(2, [19, 20]) / (1 + G8)) * G8);
  694. }
  695. function C52() {
  696. return SUM(2, [14, 50]);
  697. }
  698. function C43() {
  699. return C59() * G13;
  700. }
  701. function C44() {
  702. return C59() * C9;
  703. }
  704. function SUM(x, [y1, y2]) {
  705. let total = 0;
  706. for (let i = y1; i < y2; i++) {
  707. const item = data[i][x];
  708. if (!isNaN(item.v)) {
  709. total += item.v;
  710. }
  711. }
  712. return total;
  713. }
  714. }
  715. export default LuckySheet;