bill.ts 2.2 KB

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