import { IJobContent, IItemCharacter, IStdBill, IStdJobContent, IStdItemCharacter, } from '@sc/types'; interface IJobsAndCharacterText { jobContentText: string; itemCharacterText: string; } interface IJobContentMap { [id: string]: IStdJobContent; } interface IItemCharacterMap { [id: string]: IStdItemCharacter; } export interface IJobAndCharacter extends IJobsAndCharacterText { jobContents: IJobContent[]; itemCharacters: IItemCharacter[]; } export const getJobsAndCharacterText = ( jobContents: IJobContent[], itemCharacters: IItemCharacter[] ): IJobsAndCharacterText => { const jobContentText = ''; let itemCharacterText = ''; const textArray: string[] = ['[项目特征]']; let i = 1; for (const item of itemCharacters) { if (item.isChecked) textArray.push(`${i}. ${item.character}`); i += 1; } textArray.push('[工作内容]'); i = 1; for (const job of jobContents) { if (job.isChecked) textArray.push(`${i}. ${job.content}`); i += 1; } itemCharacterText = textArray.join('\n'); return { jobContentText, itemCharacterText }; }; export const getJobContents = ( stdBill: IStdBill, stdJobContenMap: IJobContentMap ): IJobContent[] => { const jobs: IJobContent[] = []; let i = 1; for (const j of stdBill.jobs) { const job = stdJobContenMap[j.id]; if (job) { jobs.push({ serialNo: i + 1, content: job.content, isChecked: true }); i += 1; } } return jobs; }; export const getItemCharacters = ( stdBill: IStdBill, itemCharacterMap: IItemCharacterMap ): IItemCharacter[] => { const characters: IItemCharacter[] = []; let i = 1; for (const item of stdBill.items) { const character = itemCharacterMap[item.id]; if (character) { const newItem: IItemCharacter = { serialNo: i + 1, character: character.content, eigenvalue: [], isChecked: false, }; const eigenvalues = character.itemValue; for (let j = 0; j < eigenvalues.length; j += 1) { const newValue = { value: eigenvalues[j].value, isSelected: false }; newItem.eigenvalue.push(newValue); } characters.push(newItem); i += 1; } } return characters; };