2018-10-11 17:14:55 +08:00
|
|
|
import data from '@/components/reportTemplate/rescource/orderDetails'; // use data for testing use
|
2018-10-09 17:35:47 +08:00
|
|
|
|
2018-10-11 17:14:55 +08:00
|
|
|
const orderDetails: {
|
|
|
|
[index: string]: string | object;
|
|
|
|
orderNo: string;
|
|
|
|
clientName: string;
|
|
|
|
soldDate: string;
|
|
|
|
contactName: string;
|
|
|
|
contactNo: string;
|
|
|
|
deliveryAddress: string;
|
|
|
|
addOn: string;
|
|
|
|
boards: Array<{
|
|
|
|
[index: string]: number | string | object;
|
|
|
|
id: number;
|
|
|
|
material: string;
|
|
|
|
color: string;
|
|
|
|
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;
|
|
|
|
|
|
|
|
[index: string]: number | string;
|
|
|
|
}>;
|
|
|
|
}>;
|
|
|
|
} = data;
|
|
|
|
|
|
|
|
interface BoardFormat {
|
|
|
|
id: number;
|
|
|
|
material: string;
|
|
|
|
color: string;
|
|
|
|
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;
|
|
|
|
[index: string]: number | string;
|
|
|
|
}>;
|
|
|
|
}
|
2018-10-09 17:35:47 +08:00
|
|
|
const subKeyWords = [
|
|
|
|
'sublength',
|
|
|
|
'subwidth',
|
|
|
|
'subthickness',
|
|
|
|
'subquantity',
|
|
|
|
'subarea',
|
|
|
|
];
|
|
|
|
const totalKeyWords = [
|
|
|
|
'totallength',
|
|
|
|
'totalwidth',
|
|
|
|
'totalthickness',
|
|
|
|
'totalquantity',
|
|
|
|
'totalarea',
|
|
|
|
];
|
2018-10-11 17:14:55 +08:00
|
|
|
const tagsObject: any = {
|
|
|
|
'${订单号}': 'orderNo',
|
|
|
|
'${客户名}': 'clientName',
|
|
|
|
'${出售日期}': 'soldDate',
|
|
|
|
'${联系人}': 'contactName',
|
|
|
|
'${联系电话}': 'contactNo',
|
|
|
|
'${送货地址}': 'deliveryAddress',
|
|
|
|
'${订单备注}': 'addOn',
|
|
|
|
'${板材材料}': 'material',
|
|
|
|
'${板材颜色}': 'color',
|
|
|
|
'${板材房名}': 'houseName',
|
|
|
|
'${板材柜名}': 'closetName',
|
|
|
|
'${板材号}': 'boardNo',
|
|
|
|
'${板材名}': 'boardName',
|
|
|
|
'${长度}': 'length',
|
|
|
|
'${宽度}': 'width',
|
|
|
|
'${厚度}': 'thickness',
|
|
|
|
'${数量}': 'quantity',
|
|
|
|
'${面积}': 'area',
|
|
|
|
'${变异}': 'mutation',
|
|
|
|
'${形状}': 'shape',
|
|
|
|
'${方向}': 'direction',
|
|
|
|
'${条纹}': 'stripe',
|
|
|
|
'${板材备注}': 'boardAddOn',
|
|
|
|
};
|
2018-10-09 17:35:47 +08:00
|
|
|
const orderDetailsKeys: string[] = [];
|
|
|
|
const banCaiHeaderKeys: string[] = [];
|
|
|
|
const banCaiDetailsKeys: string[] = [];
|
|
|
|
const temRowHolder: string[] = [];
|
2018-10-11 17:14:55 +08:00
|
|
|
for (const key in orderDetails) {
|
2018-10-09 17:35:47 +08:00
|
|
|
if (key !== 'boards') {
|
|
|
|
orderDetailsKeys.push(key);
|
|
|
|
}
|
|
|
|
}
|
2018-10-11 17:14:55 +08:00
|
|
|
for (const key in orderDetails.boards[0]) {
|
2018-10-09 17:35:47 +08:00
|
|
|
if (key !== 'boardInfos') {
|
|
|
|
banCaiHeaderKeys.push(key);
|
|
|
|
}
|
|
|
|
}
|
2018-10-11 17:14:55 +08:00
|
|
|
for (const key of Object.keys(orderDetails.boards[0].boardInfos[0])) {
|
2018-10-09 17:35:47 +08:00
|
|
|
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);
|
2018-10-11 17:14:55 +08:00
|
|
|
|
|
|
|
// Vue.nextTick(() => {
|
|
|
|
// row.cells.splice(Number(cell), 1);
|
|
|
|
// });
|
2018-10-08 17:36:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
that.selectedCell = 9000;
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
isTagName(cellTitle: string) {
|
|
|
|
if (cellTitle.slice(0, 2) === '${') {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2018-10-10 17:19:24 +08:00
|
|
|
addTotalAmount: (query: string) => {
|
2018-10-11 17:14:55 +08:00
|
|
|
let total: any = 0;
|
2018-10-09 17:35:47 +08:00
|
|
|
const query1 = query.slice(5);
|
2018-10-11 17:14:55 +08:00
|
|
|
for (const board of orderDetails.boards) {
|
2018-10-09 17:35:47 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
addSubAmount: (query: string, board: BoardFormat) => {
|
|
|
|
let sub: any = 0;
|
2018-10-09 17:35:47 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
addBoardInfoAmount: (that: any, board: BoardFormat) => {
|
2018-10-10 11:55:36 +08:00
|
|
|
for (const row of that.infos) {
|
|
|
|
for (const cell of row.cells) {
|
|
|
|
if (cell.title === 'bancaiinfoamount') {
|
|
|
|
cell.title = board.boardInfos.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-10-09 17:35:47 +08:00
|
|
|
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;
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
pasteRemainingForm: (that: any, remainingFormHolder: any[]) => {
|
2018-10-09 17:35:47 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
pasteBanCaiHeadTemplate: (that: any, copyBanCaiTemplate: any) => {
|
2018-10-09 17:35:47 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
copyBanCaiBodyTemplate: (that) => {
|
|
|
|
for (const row of that.infos) {
|
|
|
|
for (const cell of row.cells) {
|
|
|
|
if (
|
|
|
|
Object.keys(data.boards[0].boardInfos[0]).indexOf(
|
|
|
|
tagsObject[cell.title],
|
|
|
|
) !== -1
|
|
|
|
) {
|
|
|
|
return that.infos.indexOf(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
pasteBanCaiBody: (that: any, boardIndex: number) => {
|
2018-10-09 17:35:47 +08:00
|
|
|
const boardInfosTemplateHolder = [];
|
2018-10-11 17:14:55 +08:00
|
|
|
const copyBanCaiBodyTemplateIndex: any = Tool.copyBanCaiBodyTemplate(that);
|
2018-10-09 17:35:47 +08:00
|
|
|
|
2018-10-11 17:14:55 +08:00
|
|
|
for (const i of orderDetails.boards[boardIndex].boardInfos) {
|
2018-10-09 17:35:47 +08:00
|
|
|
boardInfosTemplateHolder.push(
|
|
|
|
that.copySingleRow(that.infos[copyBanCaiBodyTemplateIndex].rowId),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < boardInfosTemplateHolder.length; i++) {
|
|
|
|
for (const cell of boardInfosTemplateHolder[i].cells) {
|
2018-10-11 17:14:55 +08:00
|
|
|
for (const key in orderDetails.boards[boardIndex].boardInfos[i]) {
|
|
|
|
if (key === tagsObject[cell.title]) {
|
|
|
|
cell.title = orderDetails.boards[boardIndex].boardInfos[i][key];
|
2018-10-09 17:35:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
that.infos.splice(copyBanCaiBodyTemplateIndex, 1);
|
|
|
|
for (let i = 0; i < boardInfosTemplateHolder.length; i++) {
|
|
|
|
that.infos.splice(
|
|
|
|
copyBanCaiBodyTemplateIndex + i,
|
|
|
|
0,
|
|
|
|
boardInfosTemplateHolder[i],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
addBanCaiHeader: (that: any, index: number) => {
|
2018-10-09 17:35:47 +08:00
|
|
|
for (const row of that.infos) {
|
|
|
|
for (const cell of row.cells) {
|
2018-10-11 17:14:55 +08:00
|
|
|
if (banCaiHeaderKeys.indexOf(tagsObject[cell.title]) !== -1) {
|
2018-10-09 17:35:47 +08:00
|
|
|
if (temRowHolder.indexOf(row) === -1) {
|
|
|
|
temRowHolder.push(that.copySingleRow(row.rowId));
|
|
|
|
}
|
2018-10-11 17:14:55 +08:00
|
|
|
|
|
|
|
cell.title = orderDetails.boards[index][tagsObject[cell.title]];
|
2018-10-09 17:35:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
addOrderDetails: (that: any) => {
|
2018-10-09 17:35:47 +08:00
|
|
|
for (const row of that.infos) {
|
|
|
|
for (const cell of row.cells) {
|
2018-10-11 17:14:55 +08:00
|
|
|
if (orderDetailsKeys.indexOf(tagsObject[cell.title]) !== -1) {
|
|
|
|
cell.title = orderDetails[tagsObject[cell.title]];
|
2018-10-09 17:35:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-10-11 17:14:55 +08:00
|
|
|
addsubQuantity: (that: any, board: any) => {
|
2018-10-09 17:35:47 +08:00
|
|
|
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-11 17:14:55 +08:00
|
|
|
exportAsExcel: () => {
|
|
|
|
const tabs = document.getElementsByTagName('table');
|
|
|
|
let allElementText: any = '';
|
|
|
|
for (const tab of tabs) {
|
|
|
|
let tabText: string = '<table border="2px"><tr>';
|
|
|
|
for (let i = 1; i < tab.rows.length; i++) {
|
|
|
|
const tds = tab.rows[i].getElementsByTagName('td');
|
|
|
|
let tdText = '';
|
|
|
|
for (const td of tds) {
|
|
|
|
tdText += td.outerHTML;
|
|
|
|
}
|
|
|
|
tabText += tdText + '</tr>';
|
|
|
|
}
|
|
|
|
allElementText += tabText + '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
window.open(
|
|
|
|
'data:application/vnd.ms-excel,' + encodeURIComponent(allElementText),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
printAsPdf: () => {
|
|
|
|
const tabs = document.getElementsByTagName('table');
|
|
|
|
let allElementText: any = '';
|
|
|
|
for (const tab of tabs) {
|
|
|
|
let tabText: string =
|
|
|
|
'<table style="border-collapse: collapse;" border="2px"><tr>';
|
|
|
|
for (let i = 1; i < tab.rows.length; i++) {
|
|
|
|
const tds = tab.rows[i].getElementsByTagName('td');
|
|
|
|
let tdText = '';
|
|
|
|
for (const td of tds) {
|
|
|
|
tdText += td.outerHTML;
|
|
|
|
}
|
|
|
|
tabText += tdText + '</tr>';
|
|
|
|
}
|
|
|
|
allElementText += tabText + '</table>';
|
|
|
|
}
|
|
|
|
|
|
|
|
const WinPrint: any = window.open(
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'left=0,top=0,width=800,height=900,toolbar=0,scrollbars=0,status=0',
|
|
|
|
);
|
|
|
|
WinPrint.document.write(allElementText);
|
|
|
|
WinPrint.document.close();
|
|
|
|
WinPrint.focus();
|
|
|
|
WinPrint.print();
|
|
|
|
WinPrint.close();
|
|
|
|
},
|
2018-10-08 17:36:24 +08:00
|
|
|
};
|
|
|
|
export { Tool };
|