sub and total has done

This commit is contained in:
郑茂强 2018-10-09 15:21:55 +08:00
parent e2d7f832ad
commit 6f9fdf39f4
4 changed files with 137 additions and 27 deletions

View File

@ -20,7 +20,7 @@ const data = {
length: 944,
width: 59,
thickness: 18,
quantity: 1,
quantity: 10,
area: 0.568,
mutation: '',
shape: '',

View File

@ -62,8 +62,5 @@ const Tool = {
}
that.selectedCell = 9000;
},
copySingleRow: (Id: number) => {
Id += 1;
},
};
export { Tool };

View File

@ -728,6 +728,30 @@ const initialTemplateData = [
},
],
},
{
rowId: 9,
rowTitle: '9',
cells: [
{
cellId: 9049,
title: '总计:',
colspan: 10,
height: 30,
textAlign: 'right',
fontSize: 16,
fontStyle: 'bold',
},
{
cellId: 9050,
title: 'totalquantity',
colspan: 14,
height: 30,
textAlign: 'left',
fontSize: 16,
fontStyle: 'normal',
},
],
},
{ rowId: 10, rowTitle: '10', cells: [] },
{ rowId: 11, rowTitle: '11', cells: [] },

View File

@ -47,10 +47,10 @@
<p style="color: blue">以下功能用于测试使用</p>
<div>
<span>选择板材模板</span><br>
<span>开始</span><input type="number" v-model="banCaiHeadStartLine"><br>
<span>结束</span><input type="number" v-model="banCaiHeadEndLine">
<button @click="copyBanCaiHeadTemplate">确定板材头</button>
<span>选择重用板材模板</span><br>
<span>开始</span><input type="number" v-model="banCaiHeadStartLineIndex"><br>
<span>结束</span><input type="number" v-model="banCaiHeadEndLineIndex">
<button @click="copyBanCaiTemplate">确定板材头</button>
</div>
<button @click="importTemplate">导入设计样式</button>
<button @click="importData">导入数据</button><br>
@ -78,6 +78,20 @@ import { Tool } from '@/assets/methodTool';
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',
];
export default Vue.extend({
components: { reportCell, test },
@ -116,8 +130,8 @@ export default Vue.extend({
fontSize: number;
fontStyle: string;
};
banCaiHeadStartLine: string;
banCaiHeadEndLine: string;
banCaiHeadStartLineIndex: string;
banCaiHeadEndLineIndex: string;
} {
return {
infos: startUpRowColumn,
@ -141,8 +155,9 @@ export default Vue.extend({
fontSize: 0,
fontStyle: '',
},
banCaiHeadStartLine: '5',
banCaiHeadEndLine: '8',
banCaiHeadStartLineIndex: '5',
banCaiHeadEndLineIndex: '8',
afterBanCaiIdHolder: [],
};
},
computed: {
@ -231,18 +246,90 @@ export default Vue.extend({
rowClickHandler(row: any): void {
this.selectedRow = row.rowId;
},
copyBanCaiHeadTemplate() {
let temStartLine = Number(this.banCaiHeadStartLine);
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() {
let temStartLineIndex = Number(this.banCaiHeadStartLineIndex);
const banCaiHeadTemplateHolder = [];
while (temStartLine <= Number(this.banCaiHeadEndLine)) {
while (temStartLineIndex <= Number(this.banCaiHeadEndLineIndex)) {
banCaiHeadTemplateHolder.push(
this.copySingleRow(this.infos[temStartLine].rowId),
this.copySingleRow(this.infos[temStartLineIndex].rowId),
);
temStartLine += 1;
temStartLineIndex += 1;
}
return banCaiHeadTemplateHolder;
},
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;
},
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);
}
}
}
}
},
pasteBanCaiHeadTemplate(copyBanCaiTemplate: any) {
const temCopyBanCaiTemplate = copyBanCaiTemplate;
for (const banCaiRow of temCopyBanCaiTemplate) {
@ -266,7 +353,7 @@ export default Vue.extend({
}
}
},
pasteBanCaiBodyTemplate(boardIndex: number) {
pasteBanCaiBody(boardIndex: number) {
const boardInfosTemplateHolder = [];
const copyBanCaiBodyTemplateIndex: any = this.copyBanCaiBodyTemplate();
@ -338,11 +425,11 @@ export default Vue.extend({
}
};
const subQuantityMatch = (query: string) => {
const addsubQuantity = (board: any) => {
for (const row of this.infos) {
for (const cell of row.cells) {
if (cell.title === query) {
cell.title = '单个板材数量';
if (subKeyWords.indexOf(cell.title) !== -1) {
cell.title = this.addSubAmount(cell.title, board);
}
}
}
@ -351,18 +438,20 @@ export default Vue.extend({
//
const copyBanCaiTemplate = [];
for (const board of data.boards) {
copyBanCaiTemplate.push(this.copyBanCaiHeadTemplate());
copyBanCaiTemplate.push(this.copyBanCaiTemplate());
}
const copiedRemaingForm = this.copyRemainingForm(); //
addOrderDetails();
addOrderDetails(); //
for (let i = 0; i < data.boards.length; i++) {
addBanCaiHeader(i);
this.pasteBanCaiBodyTemplate(i);
subQuantityMatch('subquantity');
addBanCaiHeader(i); //
this.pasteBanCaiBody(i); //
addsubQuantity(data.boards[i]); //
if (i < data.boards.length - 1) {
this.pasteBanCaiHeadTemplate(copyBanCaiTemplate[i]);
this.pasteBanCaiHeadTemplate(copyBanCaiTemplate[i]); //
}
}
this.pasteRemainingForm(copiedRemaingForm); //
},
// for testing use -----import data from other file