123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import { queryRecordSheet } from '@/services/boom';
- import LuckySheet from '../Detail/LuckySheet';
- import react, { useRef } from 'react';
- import LuckyExcel from 'luckyexcel';
- import { Button, message } from 'antd';
- import { getToken } from '@/utils/utils';
- import moment from 'moment';
- const TEMPLATE_URL =
- 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/bom/635/%E5%90%88%E5%90%8C%E6%96%87%E4%BB%B6/%E6%8A%95%E6%A0%87%E6%A8%A1%E6%9D%BF.xlsx';
- const TEMPLATE_URL2 = 'https://water-service-test.oss-cn-hangzhou.aliyuncs.com/public/bom/psr.xlsx';
- function Index(props) {
- const { versionId = 2376 } = props;
- const sheetRef = useRef();
- const luckysheetRef = useRef();
- const uploadExcelByUrl = type => {
- LuckyExcel.transformExcelToLuckyByUrl(
- type == 1 ? TEMPLATE_URL : TEMPLATE_URL2,
- '模板.xlsx',
- async (exportJson, luckysheetfile) => {
- // if (type == 2) initData(exportJson.sheets);
- let [record] = await getExcel(versionId);
- let len = exportJson.sheets.length;
- record.order = len - 1;
- record.index = len;
- record.status = '0';
- const data = [...exportJson.sheets, record];
- console.log(data);
- luckysheetRef.current.destroy();
- luckysheetRef.current.create({
- data,
- lang: 'zh',
- showinfobar: false,
- showstatisticBar: false,
- hook: {
- cellMousedown: (cell, position, sheet) => {
- console.log(cell, position, sheet);
- },
- cellUpdated: () => {
- luckysheetRef.current.refreshFormula();
- },
- },
- });
- }
- );
- };
- const handleLoad = () => {
- let contentWindow = sheetRef.current.contentWindow;
- luckysheetRef.current = contentWindow.luckysheet;
- };
- const initData = sheets => {
- let r = 5,
- c = 12;
- // let dateCell = sheets[3].celldata.find(item => item.r == 1 && item.c == 3);
- let timer = sheets[3].celldata.filter(item => item.r == r && item.c >= c);
- timer.forEach((item, index) => {
- const cell = item.v;
-
- cell.f = `=EDATE(D2,${index})`;
- });
- console.log(timer);
- };
- return (
- <div>
- <Button type="primary" style={{ marginRight: 20 }} onClick={() => uploadExcelByUrl(1)}>
- 导入投标投标
- </Button>
- <Button type="primary" onClick={() => uploadExcelByUrl(2)}>
- 导入合同模板
- </Button>
- <iframe
- style={{
- width: '100%',
- height: '80vh',
- }}
- ref={sheetRef}
- onLoad={handleLoad}
- src="/luckysheet.html"
- ></iframe>
- </div>
- );
- }
- async function getExcel(gridKey) {
- var formData = new FormData();
- formData.append('gridKey', gridKey);
- let res = await fetch(
- `/api/v1/purchase/record/sheet?gridKey=${gridKey}&JWT-TOKEN=${getToken()}`,
- {
- method: 'POST',
- body: formData,
- }
- ).then(response => response.text());
- return JSON.parse(JSON.parse(res));
- }
- export default Index;
|