restructured
This commit is contained in:
parent
681c6a43cc
commit
a1cc5c7677
262
methodsBackUp.txt
Normal file
262
methodsBackUp.txt
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
// 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 字段');
|
||||||
|
}
|
||||||
|
},
|
67
src/assets/methodTool.ts
Normal file
67
src/assets/methodTool.ts
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
const Tool = {
|
||||||
|
addRow: (that, rowId) => {
|
||||||
|
if (that.selectedRow) {
|
||||||
|
for (const index in that.infos) {
|
||||||
|
if (that.selectedRow === that.infos[index].rowId) {
|
||||||
|
that.infos.splice(Number(index), 0, {
|
||||||
|
rowId: rowId,
|
||||||
|
rowTitle: rowId.toString(),
|
||||||
|
cells: [],
|
||||||
|
});
|
||||||
|
that.selectedRow = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
that.infos.push({
|
||||||
|
rowId: (rowId += 1),
|
||||||
|
rowTitle: rowId.toString(),
|
||||||
|
cells: [],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deleteRow: (that) => {
|
||||||
|
if (!that.selectedRow) {
|
||||||
|
return alert('请选择要删除行');
|
||||||
|
}
|
||||||
|
that.infos = that.infos.filter((item) => item.rowId !== that.selectedRow);
|
||||||
|
that.selectedRow = 0;
|
||||||
|
},
|
||||||
|
addCell: (that, cellId) => {
|
||||||
|
if (!that.selectedRow) {
|
||||||
|
return alert('请选择要添加单元的行');
|
||||||
|
}
|
||||||
|
for (const row of that.infos) {
|
||||||
|
if (that.selectedRow === row.rowId) {
|
||||||
|
row.cells.push({
|
||||||
|
cellId: cellId,
|
||||||
|
title: '列' + cellId,
|
||||||
|
colspan: 0,
|
||||||
|
height: 30,
|
||||||
|
textAlign: 'center',
|
||||||
|
fontSize: 16,
|
||||||
|
fontStyle: 'normal',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
deleteCell: (that) => {
|
||||||
|
// 9000 is initial cell Id.
|
||||||
|
if (that.selectedCell === 9000) {
|
||||||
|
return alert('请选择要删除的单元');
|
||||||
|
}
|
||||||
|
for (const row of that.infos) {
|
||||||
|
for (const cell in row.cells) {
|
||||||
|
if (row.cells[cell].cellId === that.selectedCell) {
|
||||||
|
row.cells.splice(Number(cell), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
that.selectedCell = 9000;
|
||||||
|
},
|
||||||
|
copySingleRow: (Id: number) => {
|
||||||
|
Id += 1;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export { Tool };
|
@ -728,7 +728,30 @@ const initialTemplateData = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{ rowId: 9, rowTitle: '9', cells: [] },
|
{
|
||||||
|
rowId: 9,
|
||||||
|
rowTitle: '9',
|
||||||
|
cells: [
|
||||||
|
{
|
||||||
|
cellId: 9050,
|
||||||
|
title: '总计:',
|
||||||
|
colspan: '10',
|
||||||
|
height: 30,
|
||||||
|
textAlign: 'right',
|
||||||
|
fontSize: 16,
|
||||||
|
fontStyle: 'bold',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cellId: 9051,
|
||||||
|
title: 'totalquantity',
|
||||||
|
colspan: '14',
|
||||||
|
height: 30,
|
||||||
|
textAlign: 'center',
|
||||||
|
fontSize: 16,
|
||||||
|
fontStyle: 'normal',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
{ rowId: 10, rowTitle: '10', cells: [] },
|
{ rowId: 10, rowTitle: '10', cells: [] },
|
||||||
{ rowId: 11, rowTitle: '11', cells: [] },
|
{ rowId: 11, rowTitle: '11', cells: [] },
|
||||||
{ rowId: 12, rowTitle: '12', cells: [] },
|
{ rowId: 12, rowTitle: '12', cells: [] },
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
<button @click="deleteRow">删除行</button>
|
<button @click="deleteRow">删除行</button>
|
||||||
</div>
|
</div>
|
||||||
<div class='td-tool'>
|
<div class='td-tool'>
|
||||||
<button @click="addCell()">添加列</button>
|
<button @click="addCell()">添加单元</button>
|
||||||
<button @click="deleteCell()">删除列</button>
|
<button @click="deleteCell()">删除单元</button>
|
||||||
</div>
|
</div>
|
||||||
<div class='td-tool'>
|
<div class='td-tool'>
|
||||||
<button @click="copySingleRow(selectedRow)">复制行</button>
|
<button @click="copySingleRow(selectedRow)">复制行</button>
|
||||||
@ -41,10 +41,16 @@
|
|||||||
<input type="radio" id="three" value="right" v-model="textAlign">
|
<input type="radio" id="three" value="right" v-model="textAlign">
|
||||||
<label for="three">居右</label>
|
<label for="three">居右</label>
|
||||||
<br>
|
<br>
|
||||||
<button @click="undoHandler">undo</button>
|
|
||||||
<button @click="redoHandler">redo</button><br>
|
|
||||||
<div>
|
<div>
|
||||||
<p>{{this.inputTitle}}</p>
|
<span>选择板材头模板:</span><br>
|
||||||
|
<span>开始:</span><input type="number" v-model="banCaiHeadStartLine"><br>
|
||||||
|
<span>结束:</span><input type="number" v-model="banCaiHeadEndLine">
|
||||||
|
<button @click="copyBanCaiHeadTemplate">确定板材头</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
|
||||||
<p style="color: blue">以下功能用于测试使用</p>
|
<p style="color: blue">以下功能用于测试使用</p>
|
||||||
<button @click="importTemplate">导入设计样式</button>
|
<button @click="importTemplate">导入设计样式</button>
|
||||||
<button @click="importData">导入数据</button><br>
|
<button @click="importData">导入数据</button><br>
|
||||||
@ -67,8 +73,10 @@ import startUpRowColumn from '@/assets/startUpRowColumn'; // report template for
|
|||||||
import data from '@/assets/data'; // userdata for testing use
|
import data from '@/assets/data'; // userdata for testing use
|
||||||
import reportCell from './reportCell.vue';
|
import reportCell from './reportCell.vue';
|
||||||
import test from './orderTitle.vue';
|
import test from './orderTitle.vue';
|
||||||
|
import { Tool } from '@/assets/methodTool';
|
||||||
|
import { debug } from 'util';
|
||||||
|
|
||||||
let rowId = 29; // this figure is for testing use
|
let rowId = 30; // this figure is for testing use
|
||||||
let cellId = 9050; // this figure is for testing use
|
let cellId = 9050; // this figure is for testing use
|
||||||
let undoRodoPointer = -1;
|
let undoRodoPointer = -1;
|
||||||
let isundoOrRedoClick = false;
|
let isundoOrRedoClick = false;
|
||||||
@ -135,15 +143,13 @@ export default Vue.extend({
|
|||||||
fontSize: 0,
|
fontSize: 0,
|
||||||
fontStyle: '',
|
fontStyle: '',
|
||||||
},
|
},
|
||||||
|
banCaiHeadStartLine: 5,
|
||||||
|
banCaiHeadEndLine: 8,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
// 感知所有的用户输入 并且更新data和dom
|
||||||
rows(): any {
|
rows(): any {
|
||||||
if (!isUpdateInfos) {
|
|
||||||
isUpdateInfos = true;
|
|
||||||
return this.infos;
|
|
||||||
}
|
|
||||||
// undo的时候 给this.infos 从新赋值之后 所有user input 都感知不到。
|
|
||||||
for (const row of this.infos) {
|
for (const row of this.infos) {
|
||||||
for (const cellKey in row.cells) {
|
for (const cellKey in row.cells) {
|
||||||
if (row.cells[cellKey].cellId === this.selectedCell) {
|
if (row.cells[cellKey].cellId === this.selectedCell) {
|
||||||
@ -159,16 +165,7 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 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;
|
return this.infos;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -193,78 +190,31 @@ export default Vue.extend({
|
|||||||
this.fontStyle = this.currentCell.fontStyle;
|
this.fontStyle = this.currentCell.fontStyle;
|
||||||
},
|
},
|
||||||
addRow() {
|
addRow() {
|
||||||
if (this.selectedRow) {
|
Tool.addRow(this, rowId);
|
||||||
for (const index in this.infos) {
|
rowId += 1;
|
||||||
if (this.selectedRow === this.infos[index].rowId) {
|
|
||||||
this.infos.splice(Number(index), 0, {
|
|
||||||
rowId: (rowId += 1),
|
|
||||||
rowTitle: rowId.toString(),
|
|
||||||
cells: [],
|
|
||||||
});
|
|
||||||
this.selectedRow = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.infos.push({
|
|
||||||
rowId: (rowId += 1),
|
|
||||||
rowTitle: rowId.toString(),
|
|
||||||
cells: [],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
deleteRow() {
|
deleteRow() {
|
||||||
if (!this.selectedRow) {
|
Tool.deleteRow(this);
|
||||||
return alert('请选择要删除行');
|
|
||||||
}
|
|
||||||
this.infos = this.infos.filter((item) => item.rowId !== this.selectedRow);
|
|
||||||
this.selectedRow = 0;
|
|
||||||
},
|
},
|
||||||
addCell() {
|
addCell() {
|
||||||
if (!this.selectedRow) {
|
Tool.addCell(this, cellId);
|
||||||
return alert('请选择要添加单元的行');
|
cellId += 1;
|
||||||
}
|
|
||||||
for (const row of this.infos) {
|
|
||||||
if (this.selectedRow === row.rowId) {
|
|
||||||
row.cells.push({
|
|
||||||
cellId: (cellId += 1),
|
|
||||||
title: '列' + cellId,
|
|
||||||
colspan: 0,
|
|
||||||
height: 30,
|
|
||||||
textAlign: 'center',
|
|
||||||
fontSize: 16,
|
|
||||||
fontStyle: 'normal',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
deleteCell() {
|
deleteCell() {
|
||||||
// 9000 is initial cell Id.
|
Tool.deleteCell(this);
|
||||||
if (this.selectedCell === 9000) {
|
|
||||||
return alert('请选择要删除的单元');
|
|
||||||
}
|
|
||||||
for (const row of this.infos) {
|
|
||||||
for (const cell in row.cells) {
|
|
||||||
if (row.cells[cell].cellId === this.selectedCell) {
|
|
||||||
row.cells.splice(Number(cell), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.selectedCell = 9000;
|
|
||||||
},
|
},
|
||||||
copySingleRow(Id: number) {
|
copySingleRow(Id: number) {
|
||||||
if (Id) {
|
if (Id) {
|
||||||
copiedRowHolder = JSON.parse(
|
copiedRowHolder = JSON.parse(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
this.infos.filter((eachRow) => eachRow.rowId === Id),
|
this.infos.filter((eachRow) => eachRow.rowId === Id)[0],
|
||||||
)[0],
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
copiedRowHolder.rowId = ++rowId;
|
copiedRowHolder.rowId = ++rowId;
|
||||||
|
|
||||||
for (const cell of copiedRowHolder.cells) {
|
for (const cell of copiedRowHolder.cells) {
|
||||||
cell.cellId = ++cellId;
|
cell.cellId = ++cellId;
|
||||||
}
|
}
|
||||||
|
return copiedRowHolder;
|
||||||
} else {
|
} else {
|
||||||
alert('请选择要复制的行');
|
alert('请选择要复制的行');
|
||||||
}
|
}
|
||||||
@ -283,226 +233,150 @@ export default Vue.extend({
|
|||||||
rowClickHandler(row: any): void {
|
rowClickHandler(row: any): void {
|
||||||
this.selectedRow = row.rowId;
|
this.selectedRow = row.rowId;
|
||||||
},
|
},
|
||||||
undoHandler(): void {
|
copyBanCaiHeadTemplate() {
|
||||||
if (undoRodoPointer === -1) {
|
let temStartLine = Number(this.banCaiHeadStartLine);
|
||||||
undoRodoPointer = this.recordHistory.length - 1;
|
let banCaiHeadTemplateHolder = [];
|
||||||
}
|
|
||||||
// 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) {
|
while (temStartLine <= Number(this.banCaiHeadEndLine)) {
|
||||||
return;
|
banCaiHeadTemplateHolder.push(
|
||||||
|
this.copySingleRow(this.infos[temStartLine].rowId),
|
||||||
|
);
|
||||||
|
temStartLine += 1;
|
||||||
|
}
|
||||||
|
return banCaiHeadTemplateHolder;
|
||||||
|
},
|
||||||
|
pasteBanCaiHeadTemplate(copyBanCaiTemplate) {
|
||||||
|
const temCopyBanCaiTemplate = copyBanCaiTemplate;
|
||||||
|
for (const banCaiRow of temCopyBanCaiTemplate) {
|
||||||
|
for (const row of this.infos) {
|
||||||
|
if (row.cells.length === 0) {
|
||||||
|
this.infos.splice(this.infos.indexOf(row), 0, banCaiRow);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
copyBanCaiBodyTemplate() {
|
||||||
|
for (const row of this.infos) {
|
||||||
|
for (const cell of row.cells) {
|
||||||
|
if (
|
||||||
|
Object.keys(data.boards[0].boardInfos[0]).indexOf(cell.title) !== -1
|
||||||
|
) {
|
||||||
|
return this.infos.indexOf(row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
pasteBanCaiBodyTemplate(boardIndex) {
|
||||||
|
const boardInfosTemplateHolder = [];
|
||||||
|
const copyBanCaiBodyTemplateIndex = this.copyBanCaiBodyTemplate();
|
||||||
|
|
||||||
|
for (let i = 0; i < data.boards[boardIndex].boardInfos.length; i++) {
|
||||||
|
boardInfosTemplateHolder.push(
|
||||||
|
this.copySingleRow(this.infos[copyBanCaiBodyTemplateIndex].rowId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < boardInfosTemplateHolder.length; i++) {
|
||||||
|
for (const cell of boardInfosTemplateHolder[i].cells) {
|
||||||
|
for (const key in data.boards[boardIndex].boardInfos[i]) {
|
||||||
|
if (key === cell.title) {
|
||||||
|
cell.title = data.boards[boardIndex].boardInfos[i][key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.infos.splice(copyBanCaiBodyTemplateIndex, 1);
|
||||||
|
for (let i = 0; i < boardInfosTemplateHolder.length; i++) {
|
||||||
|
this.infos.splice(
|
||||||
|
copyBanCaiBodyTemplateIndex + i,
|
||||||
|
0,
|
||||||
|
boardInfosTemplateHolder[i],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.infos = JSON.parse(this.recordHistory[(undoRodoPointer += 1)]);
|
|
||||||
isundoOrRedoClick = true;
|
|
||||||
isUpdateInfos = false;
|
|
||||||
},
|
},
|
||||||
importData() {
|
importData() {
|
||||||
const addOrderTitle = () => {
|
const orderDetailsKeys = [];
|
||||||
let foundMatchedString = false;
|
const banCaiHeaderKeys = [];
|
||||||
for (const row of this.infos) {
|
const banCaiDetailsKeys = [];
|
||||||
for (const cell of row.cells) {
|
const temRowHolder = [];
|
||||||
for (const dataKey in data) {
|
const banCaiTemplateIndexHolder = [];
|
||||||
if (dataKey === cell.title) {
|
for (const key in data) {
|
||||||
foundMatchedString = true;
|
if (key !== 'boards') {
|
||||||
cell.title = this.data[dataKey];
|
orderDetailsKeys.push(key);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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 字段');
|
|
||||||
}
|
}
|
||||||
|
for (const key in data.boards[0]) {
|
||||||
|
if (key !== 'boardInfos') {
|
||||||
|
banCaiHeaderKeys.push(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const key in data.boards[0].boardInfos[0]) {
|
||||||
|
banCaiDetailsKeys.push(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
const orderDetails = () => {
|
||||||
|
for (const row of this.infos) {
|
||||||
|
for (const cell of row.cells) {
|
||||||
|
if (orderDetailsKeys.indexOf(cell.title) !== -1) {
|
||||||
|
cell.title = data[cell.title];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const banCaiHeader = (index) => {
|
||||||
|
for (const row of this.infos) {
|
||||||
|
for (const cell of row.cells) {
|
||||||
|
if (banCaiHeaderKeys.indexOf(cell.title) !== -1) {
|
||||||
|
if (temRowHolder.indexOf(row) === -1) {
|
||||||
|
temRowHolder.push(this.copySingleRow(row.rowId));
|
||||||
|
}
|
||||||
|
|
||||||
|
cell.title = data.boards[index][cell.title];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const subQuantityMatch = (query) => {
|
||||||
|
for (const row of this.infos) {
|
||||||
|
for (const cell of row.cells) {
|
||||||
|
if (cell.title === query) {
|
||||||
|
cell.title = '单个板材数量';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const totalQuantityMatch = (query) => {
|
||||||
|
for (const row of this.infos) {
|
||||||
|
for (const cell of row.cells) {
|
||||||
|
if (cell.title === query) {
|
||||||
|
cell.title = '总共板材数量';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 复制板材的模板
|
||||||
|
const copyBanCaiTemplate = [];
|
||||||
|
for (let i = 0; i < data.boards.length - 1; i++) {
|
||||||
|
copyBanCaiTemplate.push(this.copyBanCaiHeadTemplate());
|
||||||
|
}
|
||||||
|
|
||||||
|
// orderDetails();
|
||||||
|
for (let i = 0; i < data.boards.length - 1; i++) {
|
||||||
|
banCaiHeader(i);
|
||||||
|
this.pasteBanCaiBodyTemplate(i);
|
||||||
|
subQuantityMatch('subquantity');
|
||||||
|
this.pasteBanCaiHeadTemplate(copyBanCaiTemplate[i]);
|
||||||
|
banCaiHeader(i + 1);
|
||||||
|
this.pasteBanCaiBodyTemplate(i + 1);
|
||||||
|
subQuantityMatch('subquantity');
|
||||||
|
}
|
||||||
|
totalQuantityMatch('totalquantity');
|
||||||
},
|
},
|
||||||
|
|
||||||
// for testing use -----import data from other file
|
// for testing use -----import data from other file
|
||||||
@ -565,3 +439,5 @@ table {
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
256
temdata.txt
256
temdata.txt
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user