analysis-result.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="page-content">
  3. <uv-loading-page :loading="loading"/>
  4. <large-header v-bind="headerBinding" :title="title" :scroll-top="scrollTop"/>
  5. <pretty-card/>
  6. <view class="px-20 fx-col gap-20 flex-1">
  7. <college-major-result v-for="m in prevData.universities" :key="m.num" :model="m"
  8. :results="filterResults(m)"/>
  9. </view>
  10. <view class="h-[80px] px-30 fx-row fx-cen-cen">
  11. <uv-button v-if="voluntaryRef" v-bind="gradientBtnBinding" text="生成报告" @click="handleDirectReport"/>
  12. <uv-button v-else :loading="submitting" v-bind="gradientBtnBinding" text="保存志愿表并查看报告"
  13. @click="handleCommit"/>
  14. </view>
  15. <mx-popup-template ref="inputDialog" title="志愿表名称" left="" right="确定" @right="dialogInputConfirm">
  16. <uv-input v-model="commit.name" placeholder="请输入志愿表名称(选填)"/>
  17. </mx-popup-template>
  18. </view>
  19. </template>
  20. <script>
  21. import {getCurrentInstance, computed} from 'vue';
  22. import LargeHeader from "@/pages/ie/components/large-header.vue";
  23. import PrettyCard from "@/pages/ie/components/card/pretty-card.vue";
  24. import CollegeMajorResult from "@/pages/ie/entry-analysis/components/college-major-result.vue";
  25. import {postMultipleResult, submitVoluntary} from "@/api/webApi/ie-voluntary";
  26. import AIFormCommonStyle from "@/pages/ie/components/AIFormCommonStyle";
  27. import MxConst from "@/common/MxConst";
  28. import {sleep, toast} from "@/uni_modules/uv-ui-tools/libs/function";
  29. import {useProvideUserSnapshot} from "@/pages/ie/hooks/useUserSnapshotInjection";
  30. import {useProvidePageScroll} from "@/hooks/usePageScrollInjection";
  31. import {useTransfer} from "@/hooks/useTransfer";
  32. export default {
  33. components: {CollegeMajorResult, PrettyCard, LargeHeader},
  34. mixins: [AIFormCommonStyle],
  35. data() {
  36. return {
  37. // 志愿表模式能直接进入报告。
  38. // 因为VUE的JS与Template不能同时重写,所以这里定义这个属性进行控制。有点依赖倒置的现象
  39. voluntaryRef: null,
  40. loading: false,
  41. submitting: false,
  42. headerBinding: {
  43. mode: 'light',
  44. bgIcon: '',
  45. fullHeight: 80
  46. },
  47. results: [],
  48. commit: {
  49. year: '', // 缺省的话后台会补充
  50. name: '', // 缺省的话后台会补充
  51. voluntaryType: MxConst.enum.ai.voluntaryType.multiple,
  52. }
  53. }
  54. },
  55. setup() {
  56. const scrollTop = useProvidePageScroll()
  57. const {prevData, transferTo} = useTransfer()
  58. const instance = getCurrentInstance()
  59. const snapshot = computed(() => instance.proxy.voluntaryRef?.userSnapshot)
  60. useProvideUserSnapshot(snapshot)
  61. return {
  62. prevData,
  63. scrollTop,
  64. transferTo
  65. }
  66. },
  67. computed: {
  68. title() {
  69. return this.voluntaryRef?.name || '模拟志愿分析结果'
  70. }
  71. },
  72. mounted() {
  73. this.getAnalysisResult()
  74. },
  75. methods: {
  76. async getAnalysisResult() {
  77. this.loading = true
  78. try {
  79. const res = await postMultipleResult(this.prevData)
  80. this.results = res.data
  81. } catch (e) {
  82. console.log('get analysis result error', e)
  83. } finally {
  84. this.loading = false
  85. }
  86. },
  87. filterResults(model) {
  88. return this.results.filter(r => r.universityCode == model.code)
  89. },
  90. handleCommit() {
  91. if (!this.results?.length) {
  92. toast('异常数据')
  93. return
  94. }
  95. // input name first
  96. this.$refs.inputDialog.open()
  97. },
  98. async dialogInputConfirm() {
  99. this.$refs.inputDialog.close()
  100. // save core
  101. const data = {
  102. ...this.commit,
  103. request: this.prevData,
  104. details: this.results
  105. }
  106. this.submitting = true
  107. try {
  108. const res = await submitVoluntary(data)
  109. toast('保存成功')
  110. if (!res.data) return // 异常情况
  111. await sleep(2000)
  112. const url = '/pages/ie/entry-analysis/analysis-report'
  113. this.transferTo({url, params: {id: res.data, type: data.voluntaryType}, type: 'redirect'})
  114. this.submitting = false
  115. } catch (e) {
  116. console.log('submitVoluntary[multiple] error', e)
  117. this.submitting = false
  118. }
  119. },
  120. handleDirectReport() {
  121. const path = '/pages/ie/entry-analysis/analysis-report'
  122. this.transferTo(path, this.voluntaryRef, null, true)
  123. }
  124. }
  125. }
  126. </script>
  127. <style>
  128. </style>