bill.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { IJobContent, IItemCharacter, IStdBill, IStdJobContent, IStdItemCharacter } from '@sc/types';
  2. interface IJobsAndCharacterText {
  3. jobContentText: string;
  4. itemCharacterText: string;
  5. onlyItemCharacterText: string;
  6. onlyJobContentText: string;
  7. }
  8. interface IJobContentMap {
  9. [id: string]: IStdJobContent;
  10. }
  11. interface IItemCharacterMap {
  12. [id: string]: IStdItemCharacter;
  13. }
  14. export interface IJobAndCharacter extends IJobsAndCharacterText {
  15. jobContents: IJobContent[];
  16. itemCharacters: IItemCharacter[];
  17. }
  18. export const getJobsAndCharacterText = (
  19. jobContents: IJobContent[],
  20. itemCharacters: IItemCharacter[],
  21. divided = false // 分别对应
  22. ): IJobsAndCharacterText => {
  23. let jobContentText = '';
  24. let itemCharacterText = '';
  25. let onlyJobContentText = '';
  26. let onlyItemCharacterText = '';
  27. jobContents.sort((a, b) => a.seq - b.seq);
  28. itemCharacters.sort((a, b) => a.seq - b.seq);
  29. const characterTextArray: string[] = divided ? [] : ['[项目特征]'];
  30. let i = 1;
  31. for (const item of itemCharacters) {
  32. if (item.isChecked) characterTextArray.push(`${i}. ${item.character || ''}: ${item.eigenvalue || ''}`);
  33. i += 1;
  34. }
  35. onlyItemCharacterText = characterTextArray.join('\n');
  36. const jobTextArray = divided ? [] : ['[工作内容]'];
  37. i = 1;
  38. for (const job of jobContents) {
  39. if (job.isChecked) jobTextArray.push(`${i}. ${job.content || ''}`);
  40. i += 1;
  41. }
  42. onlyJobContentText = jobTextArray.join('\n');
  43. jobContentText = divided ? onlyJobContentText : '';
  44. itemCharacterText = divided ? onlyItemCharacterText : `${onlyItemCharacterText}\n${onlyJobContentText}`;
  45. return { jobContentText, itemCharacterText, onlyItemCharacterText, onlyJobContentText };
  46. };
  47. export const getJobContents = (stdBill: IStdBill, stdJobContentMap: IJobContentMap): IJobContent[] => {
  48. const jobs: IJobContent[] = [];
  49. let i = 1;
  50. for (const j of stdBill.jobs) {
  51. const job = stdJobContentMap[j.id];
  52. if (job) {
  53. jobs.push({ seq: i + 1, content: job.content, isChecked: true });
  54. i += 1;
  55. }
  56. }
  57. return jobs;
  58. };
  59. export const getItemCharacters = (stdBill: IStdBill, itemCharacterMap: IItemCharacterMap): IItemCharacter[] => {
  60. const characters: IItemCharacter[] = [];
  61. let i = 1;
  62. for (const item of stdBill.items) {
  63. const character = itemCharacterMap[item.id];
  64. if (character) {
  65. const newItem: IItemCharacter = {
  66. seq: i + 1,
  67. character: character.content,
  68. eigenvalueList: [],
  69. eigenvalue: '',
  70. isChecked: false,
  71. };
  72. const eigenvalues = character.itemValue;
  73. for (let j = 0; j < eigenvalues.length; j += 1) {
  74. newItem.eigenvalueList.push(eigenvalues[j].value);
  75. }
  76. characters.push(newItem);
  77. i += 1;
  78. }
  79. }
  80. return characters;
  81. };