bill.ts 2.2 KB

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