2018-10-09 17:35:47 +08:00
|
|
|
import data from '@/assets/data'; // userdata for testing use
|
|
|
|
|
|
|
|
const subKeyWords = [
|
|
|
|
'sublength',
|
|
|
|
'subwidth',
|
|
|
|
'subthickness',
|
|
|
|
'subquantity',
|
|
|
|
'subarea',
|
|
|
|
];
|
|
|
|
const totalKeyWords = [
|
|
|
|
'totallength',
|
|
|
|
'totalwidth',
|
|
|
|
'totalthickness',
|
|
|
|
'totalquantity',
|
|
|
|
'totalarea',
|
|
|
|
];
|
|
|
|
const orderDetailsKeys: string[] = [];
|
|
|
|
const banCaiHeaderKeys: string[] = [];
|
|
|
|
const banCaiDetailsKeys: string[] = [];
|
|
|
|
const temRowHolder: string[] = [];
|
|
|
|
const banCaiTemplateIndexHolder = [];
|
|
|
|
for (const key in data) {
|
|
|
|
if (key !== 'boards') {
|
|
|
|
orderDetailsKeys.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const key in data.boards[0]) {
|
|
|
|
if (key !== 'boardInfos') {
|
|
|
|
banCaiHeaderKeys.push(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const key of Object.keys(data.boards[0].boardInfos[0])) {
|
|
|
|
banCaiDetailsKeys.push(key);
|
|
|
|
}
|
|
|
|
|
2018-10-08 17:36:24 +08:00
|
|
|
const Tool = {
|
2018-10-09 10:24:24 +08:00
|
|
|
addRow: (that: any, rowId: number) => {
|
2018-10-08 17:36:24 +08:00
|
|
|
if (that.selectedRow) {
|
|
|
|
for (const index in that.infos) {
|
|
|
|
if (that.selectedRow === that.infos[index].rowId) {
|
|
|
|
that.infos.splice(Number(index), 0, {
|
2018-10-09 10:24:24 +08:00
|
|
|
rowId,
|
2018-10-08 17:36:24 +08:00
|
|
|
rowTitle: rowId.toString(),
|
|
|
|
cells: [],
|
|
|
|
});
|
|
|
|
that.selectedRow = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
that.infos.push({
|
|
|
|
rowId: (rowId += 1),
|
|
|
|
rowTitle: rowId.toString(),
|
|
|
|
cells: [],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2018-10-09 10:24:24 +08:00
|
|
|
deleteRow: (that: any) => {
|
2018-10-08 17:36:24 +08:00
|
|
|
if (!that.selectedRow) {
|
|
|
|
return alert('请选择要删除行');
|
|
|
|
}
|
2018-10-09 10:24:24 +08:00
|
|
|
that.infos = that.infos.filter(
|
|
|
|
(item: any) => item.rowId !== that.selectedRow,
|
|
|
|
);
|
2018-10-08 17:36:24 +08:00
|
|
|
that.selectedRow = 0;
|
|
|
|
},
|
2018-10-09 10:24:24 +08:00
|
|
|
addCell: (that: any, cellId: number) => {
|
2018-10-08 17:36:24 +08:00
|
|
|
if (!that.selectedRow) {
|
|
|
|
return alert('请选择要添加单元的行');
|
|
|
|
}
|
|
|
|
for (const row of that.infos) {
|
|
|
|
if (that.selectedRow === row.rowId) {
|
|
|
|
row.cells.push({
|
2018-10-09 10:24:24 +08:00
|
|
|
cellId,
|
2018-10-08 17:36:24 +08:00
|
|
|
title: '列' + cellId,
|
|
|
|
colspan: 0,
|
|
|
|
height: 30,
|
|
|
|
textAlign: 'center',
|
|
|
|
fontSize: 16,
|
|
|
|
fontStyle: 'normal',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-10-09 10:24:24 +08:00
|
|
|
deleteCell: (that: any) => {
|
2018-10-08 17:36:24 +08:00
|
|
|
// 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;
|
|
|
|
},
|
2018-10-09 17:35:47 +08:00
|
|
|
addTotalAmount: (query) => {
|
|
|
|
let total = 0;
|
|
|
|
const query1 = query.slice(5);
|
|
|
|
for (const board of data.boards) {
|
|
|
|
for (const eachBoardInfo of board.boardInfos) {
|
|
|
|
if (Object.keys(eachBoardInfo).indexOf(query1) !== -1) {
|
|
|
|
total += eachBoardInfo[query1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Number.isInteger(total)) {
|
|
|
|
return total;
|
|
|
|
} else {
|
|
|
|
return total.toFixed(3);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addSubAmount: (query, board) => {
|
|
|
|
let sub = 0;
|
|
|
|
const query1 = query.slice(3);
|
|
|
|
|
|
|
|
for (const eachBoardInfo of board.boardInfos) {
|
|
|
|
if (Object.keys(eachBoardInfo).indexOf(query1) !== -1) {
|
|
|
|
sub += eachBoardInfo[query1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Number.isInteger(sub)) {
|
|
|
|
return sub;
|
|
|
|
} else {
|
|
|
|
return sub.toFixed(3);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
copyBanCaiTemplate: (that: any) => {
|
|
|
|
let temStartLineIndex = Number(that.banCaiHeadStartLineIndex);
|
|
|
|
|
|
|
|
const banCaiHeadTemplateHolder = [];
|
|
|
|
|
|
|
|
while (temStartLineIndex <= Number(that.banCaiHeadEndLineIndex)) {
|
|
|
|
banCaiHeadTemplateHolder.push(
|
|
|
|
that.copySingleRow(that.infos[temStartLineIndex].rowId),
|
|
|
|
);
|
|
|
|
temStartLineIndex += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return banCaiHeadTemplateHolder;
|
|
|
|
},
|
|
|
|
copyRemainingForm: (that: any) => {
|
|
|
|
let remainingIndex = Number(that.banCaiHeadEndLineIndex) + 1;
|
|
|
|
const remainingFormHolder = [];
|
|
|
|
for (remainingIndex; remainingIndex < that.infos.length; remainingIndex++) {
|
|
|
|
if (that.infos[remainingIndex].cells.length !== 0) {
|
|
|
|
remainingFormHolder.push(that.infos[remainingIndex]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const eachRemainingRow of remainingFormHolder) {
|
|
|
|
for (const row of that.infos) {
|
|
|
|
if (eachRemainingRow === row) {
|
|
|
|
that.infos.splice(that.infos.indexOf(row), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return remainingFormHolder;
|
|
|
|
},
|
|
|
|
pasteRemainingForm: (that, remainingFormHolder) => {
|
|
|
|
for (const eachRemainingRow of remainingFormHolder) {
|
|
|
|
for (const row of that.infos) {
|
|
|
|
if (row.cells.length === 0) {
|
|
|
|
that.infos.splice(that.infos.indexOf(row), 1, eachRemainingRow);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const row of that.infos) {
|
|
|
|
for (const cell of row.cells) {
|
|
|
|
if (totalKeyWords.indexOf(cell.title) !== -1) {
|
|
|
|
cell.title = that.addTotalAmount(cell.title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pasteBanCaiHeadTemplate: (that, copyBanCaiTemplate: any) => {
|
|
|
|
const temCopyBanCaiTemplate = copyBanCaiTemplate;
|
|
|
|
for (const banCaiRow of temCopyBanCaiTemplate) {
|
|
|
|
for (const row of that.infos) {
|
|
|
|
if (row.cells.length === 0) {
|
|
|
|
that.infos.splice(that.infos.indexOf(row), 0, banCaiRow);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
pasteBanCaiBody: (that, boardIndex: number) => {
|
|
|
|
const boardInfosTemplateHolder = [];
|
|
|
|
const copyBanCaiBodyTemplateIndex: any = that.copyBanCaiBodyTemplate();
|
|
|
|
|
|
|
|
for (const i of data.boards[boardIndex].boardInfos) {
|
|
|
|
boardInfosTemplateHolder.push(
|
|
|
|
that.copySingleRow(that.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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
that.infos.splice(copyBanCaiBodyTemplateIndex, 1);
|
|
|
|
for (let i = 0; i < boardInfosTemplateHolder.length; i++) {
|
|
|
|
that.infos.splice(
|
|
|
|
copyBanCaiBodyTemplateIndex + i,
|
|
|
|
0,
|
|
|
|
boardInfosTemplateHolder[i],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addBanCaiHeader: (that, index: number) => {
|
|
|
|
for (const row of that.infos) {
|
|
|
|
for (const cell of row.cells) {
|
|
|
|
if (banCaiHeaderKeys.indexOf(cell.title) !== -1) {
|
|
|
|
if (temRowHolder.indexOf(row) === -1) {
|
|
|
|
temRowHolder.push(that.copySingleRow(row.rowId));
|
|
|
|
}
|
|
|
|
cell.title = data.boards[index][cell.title];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addOrderDetails: (that) => {
|
|
|
|
for (const row of that.infos) {
|
|
|
|
for (const cell of row.cells) {
|
|
|
|
if (orderDetailsKeys.indexOf(cell.title) !== -1) {
|
|
|
|
cell.title = data[cell.title];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addsubQuantity: (that, board: any) => {
|
|
|
|
for (const row of that.infos) {
|
|
|
|
for (const cell of row.cells) {
|
|
|
|
if (subKeyWords.indexOf(cell.title) !== -1) {
|
|
|
|
cell.title = that.addSubAmount(cell.title, board);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-10-08 17:36:24 +08:00
|
|
|
};
|
|
|
|
export { Tool };
|