index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <ie-page bg-color="#F6F8FA">
  3. <ie-navbar title="测录取概率" transparent bg-color="#FFFFFF" title-color="black" keep-title-color/>
  4. <!-- #ifdef MP-WEIXIN -->
  5. <view class="h-90 bg-gradient-to-r from-white to-cyan-100"/>
  6. <!-- #endif -->
  7. <ie-image is-oss src="/volunteer/voluntary/index/banner.png" custom-class="w-full h-483"/>
  8. <view class="mx-30 -mt-180 z-1 bg-white rounded-xl p-35">
  9. <view class="flex justify-between items-center">
  10. <view class="text-lg text-fore-title">报考院校专业</view>
  11. <view class="text-base text-fore-placeholder flex items-center" @click="handleSelect">
  12. <text>请选择</text>
  13. <uv-icon name="arrow-right" color="info"/>
  14. </view>
  15. </view>
  16. <ie-empty v-if="!rules.length" :image="emptyImg" text="请选择你的报考院校专业~"/>
  17. <voluntary-form v-else ref="form"/>
  18. </view>
  19. <ie-safe-toolbar :height="84" :shadow="false">
  20. <view class="px-30 py-16">
  21. <ie-button @click="handleSubmit">测录取概率</ie-button>
  22. </view>
  23. </ie-safe-toolbar>
  24. </ie-page>
  25. </template>
  26. <script setup lang="ts">
  27. import config from "@/config";
  28. import VoluntaryForm from "@/pagesOther/pages/voluntary/index/components/voluntary-form.vue";
  29. import {EnrollRule, VoluntaryDto, VoluntaryModel, SelectedUniversityMajor} from "@/types/voluntary";
  30. import {VOLUNTARY_MODEL, VOLUNTARY_RULES, VOLUNTARY_TARGET} from "@/types/injectionSymbols";
  31. import {useTransferPage} from "@/hooks/useTransferPage";
  32. import {routes} from "@/common/routes";
  33. import {UniversityPickerPageOptions} from "@/types/transfer";
  34. import {getRenderRules, postRenderRules} from "@/api/modules/voluntary";
  35. const emptyImg = computed(() => config.ossUrl + '/volunteer/voluntary/index/empty_data.png')
  36. const form = ref<InstanceType<typeof VoluntaryForm>>()
  37. const target = ref<SelectedUniversityMajor>({} as SelectedUniversityMajor)
  38. const rules = ref<EnrollRule[]>([])
  39. const model = ref<VoluntaryModel>({})
  40. const {transferTo} = useTransferPage()
  41. const handleSelect = async () => {
  42. const option: UniversityPickerPageOptions = {
  43. title: '选择你的报考院校专业',
  44. fromVoluntary: true,
  45. selectedUniversityId: target.value?.universityId,
  46. selectedMajorId: target.value?.majorId
  47. }
  48. const picked = await transferTo(routes.targetPicker, {data: option})
  49. if (!picked) return
  50. target.value = picked as SelectedUniversityMajor
  51. uni.$ie.showLoading()
  52. try {
  53. // reset
  54. model.value = {}
  55. rules.value = []
  56. // request render rules
  57. const res = await getRenderRules(target.value)
  58. rules.value = res.data
  59. // init model
  60. rules.value.forEach((r) => {
  61. r.details?.forEach((d) => {
  62. if (d.options?.length) {
  63. model.value[d.fieldName] = d.defaultValue ? d.defaultValue : ''
  64. model.value[d.fieldName + 'Total'] = d.options ? d.options[0] : null
  65. }
  66. })
  67. })
  68. } catch (e) {
  69. console.log('getRenderRules ex', e, target.value)
  70. target.value = {} as SelectedUniversityMajor // clear for re-pick
  71. } finally {
  72. uni.$ie.hideLoading()
  73. }
  74. }
  75. const handleSubmit = async () => {
  76. if (!target.value.universityId||!target.value.majorId) return uni.$ie.showToast('请选择院校专业')
  77. if (!rules.value.length) return uni.$ie.showToast('由于官方未公布历年录取分数或计划变更,暂时无法计算录取概率')
  78. await form.value?.validate()
  79. // make request
  80. const {data: result} = await postRenderRules(target.value, model.value)
  81. const bigData: VoluntaryDto = {target: target.value, rules: rules.value, model: model.value, result}
  82. transferTo(routes.voluntaryResult, {bigData})
  83. }
  84. provide(VOLUNTARY_TARGET, target)
  85. provide(VOLUNTARY_RULES, rules)
  86. provide(VOLUNTARY_MODEL, model)
  87. // 为了让子组件触发页面滚动
  88. onPageScroll(() => {
  89. })
  90. </script>
  91. <style lang="scss">
  92. </style>