index.vue 4.6 KB

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