262 lines
8.2 KiB
Plaintext
262 lines
8.2 KiB
Plaintext
// back up of redo and undo methods
|
|
|
|
在computed 属性下的 redo 和undo
|
|
computed: {
|
|
rows(): any {
|
|
if (!isUpdateInfos) {
|
|
isUpdateInfos = true;
|
|
return this.infos;
|
|
}
|
|
// undo的时候 给this.infos 从新赋值之后 所有user input 都感知不到。
|
|
for (const row of this.infos) {
|
|
for (const cellKey in row.cells) {
|
|
if (row.cells[cellKey].cellId === this.selectedCell) {
|
|
row.cells.splice(Number(cellKey), 1, {
|
|
cellId: this.selectedCell,
|
|
title: this.inputTitle,
|
|
colspan: this.inputColspan,
|
|
height: this.inputHeight,
|
|
textAlign: this.textAlign,
|
|
fontSize: this.fontSize,
|
|
fontStyle: this.fontStyle,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
// will not add to recordHistory if this.info is update by redo/undo button
|
|
if (
|
|
isundoOrRedoClick === false &&
|
|
this.recordHistory[this.recordHistory.length - 1] !==
|
|
JSON.stringify(this.infos)
|
|
) {
|
|
this.recordHistory.push(JSON.stringify(this.infos));
|
|
} else {
|
|
isundoOrRedoClick = false;
|
|
}
|
|
return this.infos;
|
|
},
|
|
},
|
|
|
|
|
|
undoHandler(): void {
|
|
if (undoRodoPointer === -1) {
|
|
undoRodoPointer = this.recordHistory.length - 1;
|
|
}
|
|
// this is to avoid JSON error on console log
|
|
if (undoRodoPointer === 0) {
|
|
return;
|
|
}
|
|
this.infos = JSON.parse(this.recordHistory[(undoRodoPointer -= 1)]);
|
|
isundoOrRedoClick = true;
|
|
isUpdateInfos = false;
|
|
},
|
|
redoHandler() {
|
|
if (undoRodoPointer === -1) {
|
|
undoRodoPointer = this.recordHistory.length - 1;
|
|
}
|
|
// this is to avoid JSON error on console log
|
|
|
|
if (undoRodoPointer === this.recordHistory.length - 1) {
|
|
return;
|
|
}
|
|
this.infos = JSON.parse(this.recordHistory[(undoRodoPointer += 1)]);
|
|
isundoOrRedoClick = true;
|
|
isUpdateInfos = false;
|
|
},
|
|
//----------------------------------------------------------------------------- importdata函数备份-----------------------------------------
|
|
importData() {
|
|
const addOrderTitle = () => {
|
|
let foundMatchedString = false;
|
|
for (const row of this.infos) {
|
|
for (const cell of row.cells) {
|
|
for (const dataKey in data) {
|
|
if (dataKey === cell.title) {
|
|
foundMatchedString = true;
|
|
cell.title = this.data[dataKey];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return foundMatchedString;
|
|
};
|
|
const addBanCaiHeader = (board: any) => {
|
|
for (const row of this.infos) {
|
|
for (const cell of row.cells) {
|
|
if (board.hasOwnProperty(cell.title)) {
|
|
cell.title = board[cell.title];
|
|
}
|
|
}
|
|
}
|
|
};
|
|
const addBanCaiBody = (board: any) => {
|
|
const banCaiRowsHolder = [];
|
|
let index = 0;
|
|
for (const orderInfoDetails of board.boardInfos) {
|
|
const banCaiCellsHolder = [];
|
|
for (const eachDetail of Object.keys(orderInfoDetails)) {
|
|
// eachDetail === 每一条板材的信息
|
|
for (const row of this.infos) {
|
|
for (const cell of row.cells) {
|
|
if (eachDetail === cell.title) {
|
|
index = this.infos.indexOf(row);
|
|
banCaiCellsHolder.push({
|
|
cellId: (cellId += 1),
|
|
title: orderInfoDetails[eachDetail],
|
|
colspan: cell.colspan,
|
|
height: 30,
|
|
textAlign: 'center',
|
|
fontSize: 16,
|
|
fontStyle: 'normal',
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
banCaiRowsHolder.push({
|
|
rowId: (rowId += 1),
|
|
rowTitle: rowId.toString(),
|
|
cells: banCaiCellsHolder,
|
|
});
|
|
}
|
|
|
|
for (const banCaiRow of banCaiRowsHolder) {
|
|
if (banCaiRow.cells.length !== 0) {
|
|
this.infos.splice(
|
|
index + 1 + banCaiRowsHolder.indexOf(banCaiRow),
|
|
0,
|
|
banCaiRow,
|
|
);
|
|
}
|
|
}
|
|
if (index) {
|
|
this.infos.splice(index, 1); // 删除matched 的字段
|
|
}
|
|
};
|
|
const copyBanCaiHeader = () => {
|
|
const matchedRowIndexHolder = [];
|
|
const boardInfosKeysHolder = [];
|
|
for (const boardHeaderKey of Object.keys(data.boards[0])) {
|
|
if (boardInfosKeysHolder.indexOf(boardHeaderKey) === -1) {
|
|
boardInfosKeysHolder.push(boardHeaderKey);
|
|
}
|
|
}
|
|
for (const boardHeaderKey of Object.keys(
|
|
data.boards[0].boardInfos[0],
|
|
)) {
|
|
if (boardInfosKeysHolder.indexOf(boardHeaderKey) === -1) {
|
|
boardInfosKeysHolder.push(boardHeaderKey);
|
|
}
|
|
}
|
|
for (const row of this.infos) {
|
|
for (const cell of row.cells) {
|
|
if (
|
|
boardInfosKeysHolder.indexOf(cell.title) !== -1 ||
|
|
boardInfosKeysHolder.indexOf(cell.title.toString().slice(3)) !==
|
|
-1
|
|
) {
|
|
if (
|
|
matchedRowIndexHolder.indexOf(this.infos.indexOf(row)) === -1
|
|
) {
|
|
matchedRowIndexHolder.push(this.infos.indexOf(row));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
const matchedRowHolder = [];
|
|
|
|
for (
|
|
let index = 0;
|
|
index <= matchedRowIndexHolder[matchedRowIndexHolder.length - 1];
|
|
index += 1
|
|
) {
|
|
if (
|
|
index >= matchedRowIndexHolder[0] &&
|
|
index <= matchedRowIndexHolder[matchedRowIndexHolder.length - 1]
|
|
) {
|
|
const matchedRow = JSON.parse(JSON.stringify(this.infos[index]));
|
|
matchedRow.rowId = ++rowId;
|
|
for (const cell of matchedRow.cells) {
|
|
cell.cellId = ++cellId;
|
|
}
|
|
matchedRowHolder.push(matchedRow);
|
|
}
|
|
}
|
|
return matchedRowHolder;
|
|
};
|
|
const pasteBanCaiHeader = (
|
|
items: Array<{
|
|
rowId: number;
|
|
rowTitle: string;
|
|
cells: Array<{
|
|
cellId: number;
|
|
title: string;
|
|
colspan: number;
|
|
height: number;
|
|
textAlign: string;
|
|
fontSize: number;
|
|
fontStyle: string;
|
|
}>;
|
|
}>,
|
|
) => {
|
|
for (const item of items) {
|
|
for (const row of this.infos) {
|
|
if (row.cells.length === 0) {
|
|
this.infos.splice(this.infos.indexOf(row), 1, item);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
const addSubTotal = (
|
|
boardInfos: Array<{
|
|
houseName: string;
|
|
closetName: string;
|
|
boardNo: string;
|
|
boardName: string;
|
|
length: number;
|
|
width: number;
|
|
thickness: number;
|
|
quantity: number;
|
|
area: number;
|
|
mutation: string;
|
|
shape: string;
|
|
direction: string;
|
|
stripe: string;
|
|
boardAddOn: string;
|
|
}>,
|
|
) => {
|
|
let amountHolder = 0;
|
|
|
|
for (const row of this.infos) {
|
|
for (const cell of row.cells) {
|
|
if (cell.title === 'subquantity') {
|
|
for (const eachBoardInfo of boardInfos) {
|
|
for (const detail in eachBoardInfo) {
|
|
if (detail === cell.title.slice(3)) {
|
|
amountHolder += eachBoardInfo[detail];
|
|
}
|
|
}
|
|
}
|
|
cell.title = amountHolder.toString();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
if (addOrderTitle()) {
|
|
addOrderTitle();
|
|
for (const board of data.boards) {
|
|
const x = copyBanCaiHeader(); // 复制板材表头备用
|
|
addBanCaiHeader(board); // 添加板材表头
|
|
addBanCaiBody(board); // 添加板材表身
|
|
addSubTotal(board.boardInfos); // 添加 小计
|
|
// 添加 板材内的每一条信息
|
|
if (data.boards.indexOf(board) !== data.boards.length - 1) {
|
|
pasteBanCaiHeader(x);
|
|
}
|
|
}
|
|
} else {
|
|
alert('没有找到匹配的orderTitle 字段');
|
|
}
|
|
}, |