diff --git a/src/assets/data.ts b/src/assets/data.ts index 2729994..6705e4d 100644 --- a/src/assets/data.ts +++ b/src/assets/data.ts @@ -106,46 +106,3 @@ const data = { }; export default data; -/* - { - id: 1235, - matierial: '生态板 ', - color: '暖白', - boardInfos: [ - { - houseName: 'F01', - closetName: 'G01', - boardNo: 'B1816478862', - boardName: '背板', - length: 944, - width: 598, - thickness: 18, - quantity: 1, - area: 0.568, - mutation: '', - shape: '', - direction: '1/1/1/1 ', - stripe: '正纹', - boardAddOn: '', - }, - { - houseName: 'F01', - closetName: 'G01', - boardNo: 'B1816478861', - - boardName: '背板', - length: 944, - width: 598, - thickness: 18, - quantity: 1, - area: 0.568, - mutation: '', - shape: '', - direction: '1/1/1/1 ', - stripe: '正纹', - boardAddOn: '', - }, - ], - }, - -*/ diff --git a/src/assets/templateInitialData.ts b/src/assets/templateInitialData.ts index 8287694..3f79edc 100644 --- a/src/assets/templateInitialData.ts +++ b/src/assets/templateInitialData.ts @@ -704,7 +704,30 @@ const initialTemplateData = [ }, ], }, - { rowId: 8, rowTitle: '8', cells: [] }, + { + rowId: 8, + rowTitle: '8', + cells: [ + { + cellId: 9047, + title: '小计:', + colspan: 10, + height: 30, + textAlign: 'right', + fontSize: 16, + fontStyle: 'bold', + }, + { + cellId: 9048, + title: 'subquantity', + colspan: 14, + height: 30, + textAlign: 'left', + fontSize: 16, + fontStyle: 'normal', + }, + ], + }, { rowId: 9, rowTitle: '9', cells: [] }, { rowId: 10, rowTitle: '10', cells: [] }, { rowId: 11, rowTitle: '11', cells: [] }, diff --git a/src/components/reportTemplate/ReportTemplate.vue b/src/components/reportTemplate/ReportTemplate.vue index 5958180..0d0b979 100644 --- a/src/components/reportTemplate/ReportTemplate.vue +++ b/src/components/reportTemplate/ReportTemplate.vue @@ -69,7 +69,7 @@ import reportCell from './reportCell.vue'; import test from './orderTitle.vue'; let rowId = 29; // this figure is for testing use -let cellId = 9046; // this figure is for testing use +let cellId = 9050; // this figure is for testing use let undoRodoPointer = -1; let isundoOrRedoClick = false; let isUpdateInfos = true; @@ -317,6 +317,7 @@ export default Vue.extend({ if (dataKey === cell.title) { foundMatchedString = true; cell.title = this.data[dataKey]; + console.log('找到', this.data[dataKey]); } } } @@ -364,39 +365,60 @@ export default Vue.extend({ } for (const banCaiRow of banCaiRowsHolder) { - this.infos.splice( - index + 1 + banCaiRowsHolder.indexOf(banCaiRow), - 0, - banCaiRow, - ); + if (banCaiRow.cells.length !== 0) { + this.infos.splice( + index + 1 + banCaiRowsHolder.indexOf(banCaiRow), + 0, + banCaiRow, + ); + } + } + if (index) { + this.infos.splice(index, 1); // 删除matched 的字段 } - this.infos.splice(index, 1); // 删除matched 的字段 }; const copyBanCaiHeader = () => { - const matchedRowIdHolder = []; - + 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 (data.boards[0].hasOwnProperty(cell.title)) { - if (matchedRowIdHolder.indexOf(this.infos.indexOf(row)) === -1) { - matchedRowIdHolder.push(this.infos.indexOf(row)); - } - } else if ( - data.boards[0].boardInfos[0].hasOwnProperty(cell.title) + if ( + boardInfosKeysHolder.indexOf(cell.title) !== -1 || + boardInfosKeysHolder.indexOf(cell.title.toString().slice(3)) !== + -1 ) { - if (matchedRowIdHolder.indexOf(this.infos.indexOf(row)) === -1) { - matchedRowIdHolder.push(this.infos.indexOf(row)); + if ( + matchedRowIndexHolder.indexOf(this.infos.indexOf(row)) === -1 + ) { + matchedRowIndexHolder.push(this.infos.indexOf(row)); } + break; } } } const matchedRowHolder = []; - for (let index = 0; index <= matchedRowIdHolder[1]; index += 1) { + for ( + let index = 0; + index <= matchedRowIndexHolder[matchedRowIndexHolder.length - 1]; + index += 1 + ) { if ( - index >= matchedRowIdHolder[0] && - index <= matchedRowIdHolder[1] + index >= matchedRowIndexHolder[0] && + index <= matchedRowIndexHolder[matchedRowIndexHolder.length - 1] ) { const matchedRow = JSON.parse(JSON.stringify(this.infos[index])); matchedRow.rowId = ++rowId; @@ -432,12 +454,32 @@ export default Vue.extend({ } } }; + const addSubTotal = (boardInfos) => { + 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); + const x = copyBanCaiHeader(); // 复制板材表头备用 + addBanCaiHeader(board); // 添加板材表头 + addBanCaiBody(board); // 添加板材表身 + addSubTotal(board.boardInfos); // 添加 小计 + // 添加 板材内的每一条信息 if (data.boards.indexOf(board) !== data.boards.length - 1) { pasteBanCaiHeader(x); } @@ -507,60 +549,3 @@ table { } -/* -importData() { - x += 1; - for (const row of this.infos) { - for (const cell of row.cells) { - // userdata for loop - for (const userData in this.importedData) { - if (userData + ':' === cell.title) { - cell.title += this.importedData[userData]; - } - } - for (const boards of this.importedData.boards) { - for (const board in boards) { - if (board + ':' === cell.title) { - cell.title += boards[board]; - } - } - } - } - } - for (const row of this.infos) { - // get each cell - console.log(x); - const borderInfo: any = this.importedData.boards[x].boardInfos; - for (const details of borderInfo) { - const tem: any[] = []; - for (const each of Object.keys(details)) { - for (const cell of row.cells) { - if (each === cell.title) { - tem.push({ - cellId: (cellId += 1), - title: details[each], - colspan: cell.colspan, - height: 30, - textAlign: 'center', - fontSize: 16, - fontStyle: 'normal', - }); - } - } - } - if (tem.length) { - for (const eachRow in this.infos) { - if (!this.infos[eachRow].cells.length) { - this.infos[eachRow].cells = this.infos[eachRow].cells.concat( - tem, - ); - break; - } - } - } - } - } - }, -*/ - -