Оптимизируй код haveNecessaryMaterials(templateContent, i, item, executer) {…
- User
Оптимизируй код haveNecessaryMaterials(templateContent, i, item, executer) { templateContent[i][2].table.body.push( [{ text: item.equipmentTitle, italics: true, color: '#333138'}, { text: item.operationName, italics: true, color: '#333138'}, { text:
${executer.workStartTime} - ${executer.workEndTime}, italics: true, color: '#333138' }, { text:${item.instructions} работу выполнить на: ${item.complPercentage}%, italics: true, color: '#333138' }, { text: '', italics: true, color: '#333138' }] ) let arrMaterial = [] let firstAdd = true item.necessaryMaterial.forEach((mat) => { if (firstAdd) { arrMaterial = [{ colSpan: 5, table: { widths: [150, 60, '', ''], body: [ [{ text: 'Наименование', style: 'header' }, { text: 'ед. изм', style: 'header' }, { text: 'кол-во план', style: 'header' }, { text: 'кол-во факт', style: 'header' }], [{ text:${mat.name}, alignment: 'left' }, { text:${mat.unitRev}, style: 'subheader' }, { text:${mat.quantity}, style: 'subheader' }, ''], ] } }] firstAdd = false } else { arrMaterial[0].table.body.push([ { text:${mat.name}, alignment: 'left' }, { text:${mat.unitRev}, style: 'subheader' }, { text:${mat.quantity}, style: 'subheader' }, '']) } templateContent[i][2].table.body.push(arrMaterial) }) }, async createPDF() { let templateContent = []this.realPlaneOutfitTask.forEach((item) => { console.log('item', item) item.executers.forEach((executer) => { if (templateContent.length > 0 && executer.active) { for (let i = 0; templateContent.length > i; i++) { let result = templateContent[i][1].text.match(executer.shortName) if (result != null) { console.log('result != null', result) if (item.necessaryMaterial != null) { this.haveNecessaryMaterials(templateContent, i, item, executer) } else { templateContent[i][2].table.body.push( [{ text: item.equipmentTitle, italics: true, color: '#333138' }, { text: item.operationName, italics: true, color: '#333138' }, { text: `${executer.workStartTime} - ${executer.workEndTime}`, italics: true, color: '#333138' }, { text: `${item.instructions} работу выполнить на: ${item.complPercentage}%`, italics: true, color: '#333138' }, { text: '', italics: true, color: '#333138' }] ) } break } else if (i + 1 == templateContent.length) { console.log('templateContent2', templateContent) if (item.necessaryMaterial != null) { let itemContent = { content: [ { text: 'План работ на день профилактики: ' + this.date, style: 'header' }, { text: 'Для сотрудников: ' + executer.shortName, style: 'subheader' }, { style: 'tableExample', table: { widths: [80, '*', 60, '*', 60], body: [ ['Наименование оборудования', 'Наименование операции', 'Время проведения', 'Инструкции к выполнению', 'Отметка о выполнении'], [{ text: item.equipmentTitle, italics: true, color: '#333138' }, { text: item.operationName, italics: true, color: '#333138' }, { text: `${executer.workStartTime} - ${executer.workEndTime}`, italics: true, color: '#333138' }, { text: `${item.instructions} работу выполнить на: ${item.complPercentage}%`, italics: true, color: '#333138' }, { text: '', italics: true, color: '#333138' }] ] } }, ] } let arrMaterial = [] let firstAdd = true item.necessaryMaterial.forEach((mat) => { if (firstAdd) { arrMaterial = [{ colSpan: 5, table: { widths: [152, 60, '*', '*'], body: [ [{ text: 'Наименование', style: 'header' }, { text: 'ед. изм', style: 'header' }, { text: 'кол-во план', style: 'header' }, { text: 'кол-во факт', style: 'header' }], [{ text: `${mat.name}`, alignment: 'left' }, { text: `${mat.unitRev}`, style: 'subheader' }, { text: `${mat.quantity}`, style: 'subheader' }, ''], ] } }] firstAdd = false } else { arrMaterial[0].table.body.push([{ text: `${mat.name}`, alignment: 'left' }, { text: `${mat.unitRev}`, style: 'subheader' }, { text: `${mat.quantity}`, style: 'subheader' }, '']) } }) itemContent.content[2].table.body.push(arrMaterial) templateContent.push(itemContent.content) } else { let itemContent = { content: [ { text: 'План работ на день профилактики: ' + this.date, style: 'header' }, { text: 'Для сотрудников: ' + executer.shortName, style: 'subheader' }, { style: 'tableExample', table: { widths: [80, '*', 60, '*', 60], body: [ ['Наименование оборудования', 'Наименование операции', 'Время проведения', 'Инструкции к выполнению', 'Отметка о выполнении'], [{ text: item.equipmentTitle, italics: true, color: '#333138' }, { text: item.operationName, italics: true, color: '#333138' }, { text: `${executer.workStartTime} - ${executer.workEndTime}`, italics: true, color: '#333138' }, { text: `${item.instructions} работу выполнить на: ${item.complPercentage}%`, italics: true, color: '#333138' }, { text: '', italics: true, color: '#333138' }], ] } }, ] } templateContent.push(itemContent.content) } break } } } else if (executer.active) { if (item.necessaryMaterial != null) { let itemContent = { content: [ { text: 'План работ на день профилактики: ' + this.date, style: 'header' }, { text: 'Для сотрудников: ' + executer.shortName, style: 'subheader' }, { style: 'tableExample', table: { widths: [80, '*', 60, '*', 60], body: [ ['Наименование оборудования', 'Наименование операции', 'Время проведения', 'Инструкции к выполнению', 'Отметка о выполнении'], [{ text: item.equipmentTitle, italics: true, color: '#333138' }, { text: item.operationName, italics: true, color: '#333138' }, { text: `${executer.workStartTime} - ${executer.workEndTime}`, italics: true, color: '#333138' }, { text: `${item.instructions} работу выполнить на: ${item.complPercentage}%`, italics: true, color: '#333138' }, { text: '', italics: true, color: '#333138' }] ] } }, ] } let arrMaterial = [] let firstAdd = true item.necessaryMaterial.forEach((mat) => { if (firstAdd) { arrMaterial = [{ colSpan: 5, table: { widths: [152, 60, '*', '*'], body: [ [{ text: 'Наименование', style: 'header' }, { text: 'ед. изм', style: 'header' }, { text: 'кол-во план', style: 'header' }, { text: 'кол-во факт', style: 'header' }], [{ text: `${mat.name}`, alignment: 'left' }, { text: `${mat.unitRev}`, style: 'subheader' }, { text: `${mat.quantity}`, style: 'subheader' }, ''], ] } }] firstAdd = false } else { arrMaterial[0].table.body.push([{ text: `${mat.name}`, alignment: 'left' }, { text: `${mat.unitRev}`, style: 'subheader' }, { text: `${mat.quantity}`, style: 'subheader' }, '']) } }) itemContent.content[2].table.body.push(arrMaterial) templateContent.push(itemContent.content) } else { let itemContent = { content: [ { text: 'План работ на день профилактики: ' + this.date, style: 'header' }, { text: 'Для сотрудников: ' + executer.shortName, style: 'subheader' }, { style: 'tableExample', table: { widths: [80, '*', 60, '*', 60], body: [ ['Наименование оборудования', 'Наименование операции', 'Время проведения', 'Инструкции к выполнению', 'Отметка о выполнении'], [{ text: item.equipmentTitle, italics: true, color: '#333138' }, { text: item.operationName, italics: true, color: '#333138' }, { text: `${executer.workStartTime} - ${executer.workEndTime}`, italics: true, color: '#333138' }, { text: `${item.instructions} работу выполнить на: ${item.complPercentage}%`, italics: true, color: '#333138' }, { text: '', italics: true, color: '#333138' }], ] } }, ] } templateContent.push(itemContent.content) } } }) }) let dd = { styles: { header: { fontSize: 10, bold: true, margin: [0, 0, 0, 0], alignment: 'center' }, subheader: { fontSize: 8, bold: false, alignment: 'center', margin: [5, 10, 5, 5] }, tableExample: { fontSize: 10, margin: [0, 5, 0, 15], alignment: 'left' }, tableHeader: { bold: true, fontSize: 13, color: 'black' } }, defaultStyle: { alignment: 'justify' } } dd.content = templateContent this.$pdfMake.createPdf(dd).print(); }, - Assistant