diff --git a/src/assets/methodTool.ts b/src/assets/methodTool.ts index b96d4e4..840cc6e 100644 --- a/src/assets/methodTool.ts +++ b/src/assets/methodTool.ts @@ -1,3 +1,38 @@ +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); +} + const Tool = { addRow: (that: any, rowId: number) => { if (that.selectedRow) { @@ -62,5 +97,154 @@ const Tool = { } that.selectedCell = 9000; }, + 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); + } + } + } + }, }; export { Tool }; diff --git a/src/assets/typeScriptDeclaration.ts b/src/assets/typeScriptDeclaration.ts new file mode 100644 index 0000000..36557ff --- /dev/null +++ b/src/assets/typeScriptDeclaration.ts @@ -0,0 +1,5 @@ +export class typeScriptDeclaration { + name: string; + rollNo: string; + standard: number; +} diff --git a/src/components/reportTemplate/ReportTemplate.vue b/src/components/reportTemplate/ReportTemplate.vue index 01e8662..a32d670 100644 --- a/src/components/reportTemplate/ReportTemplate.vue +++ b/src/components/reportTemplate/ReportTemplate.vue @@ -4,7 +4,7 @@
- +
@@ -59,8 +59,7 @@ {{selectedRow}}
- {{this.infos}} - + @@ -72,29 +71,16 @@ import initialTemplateData from '@/assets/templateInitialData'; // report templa import startUpRowColumn from '@/assets/startUpRowColumn'; // report template for testing import data from '@/assets/data'; // userdata for testing use import reportCell from './reportCell.vue'; -import test from './orderTitle.vue'; import { Tool } from '@/assets/methodTool'; +import { typeScriptDeclaration } from '@/assets/typeScriptDeclaration'; let rowId = 30; // this figure is for testing use let cellId = 9050; // this figure is for testing use let copiedRowHolder: any; -const subKeyWords = [ - 'sublength', - 'subwidth', - 'subthickness', - 'subquantity', - 'subarea', -]; -const totalKeyWords = [ - 'totallength', - 'totalwidth', - 'totalthickness', - 'totalquantity', - 'totalarea', -]; +console.log(new typeScriptDeclaration()); export default Vue.extend({ - components: { reportCell, test }, + components: { reportCell }, data(): { infos: Array<{ rowId: number; @@ -247,99 +233,23 @@ export default Vue.extend({ this.selectedRow = row.rowId; }, 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); - } + return Tool.addTotalAmount(query); }, 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); - } + return Tool.addSubAmount(query, board); }, - copyBanCaiTemplate() { - let temStartLineIndex = Number(this.banCaiHeadStartLineIndex); - - const banCaiHeadTemplateHolder = []; - - while (temStartLineIndex <= Number(this.banCaiHeadEndLineIndex)) { - banCaiHeadTemplateHolder.push( - this.copySingleRow(this.infos[temStartLineIndex].rowId), - ); - temStartLineIndex += 1; - } - - return banCaiHeadTemplateHolder; + copyBanCaiTemplate(this) { + return Tool.copyBanCaiTemplate(this); }, - copyRemainingForm() { - let remainingIndex = Number(this.banCaiHeadEndLineIndex) + 1; - const remainingFormHolder = []; - for ( - remainingIndex; - remainingIndex < this.infos.length; - remainingIndex++ - ) { - if (this.infos[remainingIndex].cells.length !== 0) { - remainingFormHolder.push(this.infos[remainingIndex]); - } - } - for (const eachRemainingRow of remainingFormHolder) { - for (const row of this.infos) { - if (eachRemainingRow === row) { - this.infos.splice(this.infos.indexOf(row), 1); - } - } - } - return remainingFormHolder; + copyRemainingForm(this) { + return Tool.copyRemainingForm(this); }, - pasteRemainingForm(remainingFormHolder) { - for (const eachRemainingRow of remainingFormHolder) { - for (const row of this.infos) { - if (row.cells.length === 0) { - this.infos.splice(this.infos.indexOf(row), 1, eachRemainingRow); - break; - } - } - for (const row of this.infos) { - for (const cell of row.cells) { - if (totalKeyWords.indexOf(cell.title) !== -1) { - cell.title = this.addTotalAmount(cell.title); - } - } - } - } + pasteRemainingForm(this, remainingFormHolder) { + Tool.pasteRemainingForm(this, remainingFormHolder); }, - pasteBanCaiHeadTemplate(copyBanCaiTemplate: any) { - 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; - } - } - } + pasteBanCaiHeadTemplate(this, copyBanCaiTemplate: any) { + Tool.pasteBanCaiHeadTemplate(this, copyBanCaiTemplate); }, copyBanCaiBodyTemplate() { for (const row of this.infos) { @@ -354,101 +264,23 @@ export default Vue.extend({ } }, pasteBanCaiBody(boardIndex: number) { - const boardInfosTemplateHolder = []; - const copyBanCaiBodyTemplateIndex: any = this.copyBanCaiBodyTemplate(); - - for (const i of data.boards[boardIndex].boardInfos) { - 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], - ); - } + Tool.pasteBanCaiBody(this, boardIndex); }, importData() { - 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); - } - - const addOrderDetails = () => { - for (const row of this.infos) { - for (const cell of row.cells) { - if (orderDetailsKeys.indexOf(cell.title) !== -1) { - cell.title = data[cell.title]; - } - } - } - }; - - const addBanCaiHeader = (index: number) => { - 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 addsubQuantity = (board: any) => { - for (const row of this.infos) { - for (const cell of row.cells) { - if (subKeyWords.indexOf(cell.title) !== -1) { - cell.title = this.addSubAmount(cell.title, board); - } - } - } - }; - // 复制完整板材的模板 - const copyBanCaiTemplate = []; + const copyBanCaiTemplateArray = []; for (const board of data.boards) { - copyBanCaiTemplate.push(this.copyBanCaiTemplate()); + copyBanCaiTemplateArray.push(this.copyBanCaiTemplate()); } const copiedRemaingForm = this.copyRemainingForm(); // 复制板材之外的剩余表格 - addOrderDetails(); // 添加表单头部信息 + Tool.addOrderDetails(this); // 添加表单头部信息 for (let i = 0; i < data.boards.length; i++) { - addBanCaiHeader(i); // 添加板材的头部信息 + Tool.addBanCaiHeader(this, i); // 添加板材的头部信息 this.pasteBanCaiBody(i); // 添加板材的身部信息 - addsubQuantity(data.boards[i]); // 添加小计信息 + Tool.addsubQuantity(this, data.boards[i]); // 添加小计信息 if (i < data.boards.length - 1) { - this.pasteBanCaiHeadTemplate(copyBanCaiTemplate[i]); // 添加板材样板 + this.pasteBanCaiHeadTemplate(copyBanCaiTemplateArray[i]); // 添加板材样板 } } this.pasteRemainingForm(copiedRemaingForm); // 粘贴剩余的表格 @@ -459,6 +291,22 @@ export default Vue.extend({ // 暂时排查不到colspan是string类型 this.infos = initialTemplateData; }, + exportAsExcel() { + const tabs = document.getElementsByTagName('table'); + let allElementText: any; + for (const tab of tabs) { + let tabText: string = ''; + + for (let i = 1; i < tab.rows.length; i++) { + tabText += tab.rows[i].innerHTML + ''; + } + allElementText += tabText + '
'; + } + console.log(allElementText); + window.open( + 'data:application/vnd.ms-excel,' + encodeURIComponent(allElementText), + ); + }, }, }); @@ -478,7 +326,7 @@ export default Vue.extend({ .side { background-color: lightgray; height: 100hv; - width: 20%; + width: 15%; } } table { diff --git a/src/components/reportTemplate/orderTitle.vue b/src/components/reportTemplate/orderTitle.vue index 2ec10bc..d2c48f7 100644 --- a/src/components/reportTemplate/orderTitle.vue +++ b/src/components/reportTemplate/orderTitle.vue @@ -1,7 +1,296 @@