documentInfo.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { defineStore } from 'pinia';
  2. import { ref } from 'vue';
  3. import { useDocumentApi } from '@/api/document';
  4. import to from 'await-to-js';
  5. export const useDocumentInfoStore = defineStore('documentInfo', () => {
  6. const documentApi = useDocumentApi();
  7. const documentDetail = ref<any>(null);
  8. const loading = ref(false);
  9. /**
  10. * 根据业务编码和流程编码获取单据详情
  11. * @param defCode 流程定义编码
  12. * @param businessCode 业务代码 (可能是业务流水号,也可能是ID)
  13. */
  14. async function fetchDocumentDetail(defCode: string, businessCode: string) {
  15. if (!businessCode) return null;
  16. loading.value = true;
  17. documentDetail.value = null;
  18. let apiFn: any = null;
  19. let paramValue: any = businessCode;
  20. // 纵向项目/预申报
  21. if (['sci_project_vertical', 'pre_sci_project_vertical', 'sci_project_spontaneity_declaration_project'].includes(defCode)) {
  22. apiFn = documentApi.getVerticalByCode;
  23. }
  24. // 横向项目
  25. else if (defCode === 'sci_project_horizontal') {
  26. apiFn = documentApi.getHorizontalByCode;
  27. }
  28. // 校内项目
  29. else if (defCode === 'sci_project_spontaneity') {
  30. apiFn = documentApi.getSpontaneityByCode;
  31. }
  32. // 学术会议 (ID-based)
  33. else if (defCode === 'sci_academic_conferences') {
  34. apiFn = documentApi.getConferenceById;
  35. }
  36. // 学术讲座 (ID-based)
  37. else if (defCode === 'sci_academic_lectures') {
  38. apiFn = documentApi.getLectureById;
  39. }
  40. // 社会任职 (ID-based)
  41. else if (defCode === 'sci_academic_committee_positions') {
  42. apiFn = documentApi.getDutiesById;
  43. }
  44. // 人员派驻 (ID-based)
  45. else if (defCode === 'sci_scientific_researchers_dispatch') {
  46. apiFn = documentApi.getDispatchById;
  47. }
  48. // 学术成果
  49. else if (defCode === 'sci_academic_achievement') {
  50. const code = businessCode.includes('-') ? businessCode.split('-')[1] : businessCode;
  51. paramValue = code;
  52. if (businessCode.includes('学术论文')) {
  53. apiFn = documentApi.getPaperByCode;
  54. } else if (businessCode.includes('奖项荣誉')) {
  55. apiFn = documentApi.getAwardsByCode;
  56. } else if (businessCode.includes('学术专利') || businessCode.includes('专利转化')) {
  57. apiFn = documentApi.getPatentByCode;
  58. } else if (businessCode.includes('学术著作')) {
  59. apiFn = documentApi.getWorkByCode;
  60. }
  61. }
  62. // 学术委员会成果 (Code-based with split)
  63. else if (defCode === 'sci_academic_committee') {
  64. paramValue = businessCode.includes('-') ? businessCode.split('-')[1] : businessCode;
  65. apiFn = documentApi.getCommitteeByCode;
  66. }
  67. // 经费相关 (ID-based)
  68. else if (defCode === 'sci_fund_allot_apply') {
  69. apiFn = documentApi.getFundClaimById;
  70. }
  71. else if (defCode === 'sci_fund_expense') {
  72. apiFn = documentApi.getFundExpenseById;
  73. }
  74. else if (defCode === 'sci_fund_reward') {
  75. apiFn = documentApi.getFundRewardById;
  76. }
  77. else if (defCode === 'sci_fund_carryover') {
  78. apiFn = documentApi.getFundCarryoverById;
  79. }
  80. // 考核批次 (ID-based)
  81. else if (defCode === 'sci_assessment_batch') {
  82. apiFn = documentApi.getAssessmentBatchById;
  83. }
  84. // 项目中期/结项 (ID-based)
  85. else if (['sci_project_inspection', 'sci_project_conclusion'].includes(defCode)) {
  86. apiFn = documentApi.getProjectAuditById;
  87. }
  88. // 学科分类 (Code-based)
  89. else if (defCode === 'sci_project_discipline') {
  90. apiFn = documentApi.getDisciplineByCode;
  91. }
  92. if (!apiFn) {
  93. loading.value = false;
  94. console.warn('Unhandled defCode for API mapping:', defCode);
  95. return null;
  96. }
  97. const [err, res] = await to(apiFn(paramValue)) as [any, any];
  98. loading.value = false;
  99. if (err) {
  100. console.error('Fetch document detail error:', err);
  101. return null;
  102. }
  103. const data = res?.Data || res?.data;
  104. if (data) {
  105. documentDetail.value = data;
  106. return data;
  107. }
  108. return null;
  109. }
  110. return {
  111. documentDetail,
  112. loading,
  113. fetchDocumentDetail
  114. };
  115. });