猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
3.8 KiB

2 months ago
  1. <template>
  2. <!-- <view>伴宠师认证</view> -->
  3. <view class="page">
  4. <view class="box">
  5. <view class="content bg-fff">
  6. <view class="group" v-for="(group, gIdx) in list" :key="`group-${gIdx}`">
  7. <view class="label size-22 level" :style="{borderRadius:'10rpx'}">
  8. {{ group.title }}
  9. </view>
  10. <view >
  11. <questionCard
  12. v-for="(item, qIdx) in group.children"
  13. :key="`${gIdx}-question-${qIdx}`"
  14. :index="qIdx"
  15. :data="item"
  16. :type="item.type"
  17. mode="display"
  18. ></questionCard>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="footer-btn flex-colc">
  24. <view class="size-22 color-777 tips-rest">
  25. <!-- todo -->
  26. 剩余考试机会<text class="highlight">{{ restTimes }}</text>
  27. </view>
  28. <view class="btn" @click="onClick">
  29. 重新考试
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script setup>
  35. import { ref } from 'vue'
  36. import { onShow } from '@dcloudio/uni-app'
  37. import { getQuestionList, getQuestionOptions, answeBaseByQuestionId, answeTrainByQuestionId } from '@/api/examination'
  38. import { useStore } from 'vuex'
  39. import questionCard from '../components/questionCard.vue';
  40. const store = useStore()
  41. const configList = computed(() => {
  42. return store.getters.configList
  43. })
  44. const list = ref([
  45. {
  46. title: '选择题',
  47. children: [],
  48. },
  49. {
  50. title: '主观题',
  51. children: [],
  52. },
  53. ])
  54. const initList = async () => {
  55. try {
  56. let groups = [
  57. { title: '选择题', children: [], },
  58. { title: '主观题', children: [], },
  59. ]
  60. let questions = await getQuestionList()
  61. for (let i = 0; i < questions.length; i++) {
  62. const { id, title, type } = questions[i]
  63. let data = { id, title, type }
  64. if (type === '基本') {
  65. const options = (await getQuestionOptions({ questionId: id })).map(item => ({ id: item.id, title: item.title}))
  66. data.options = options
  67. // todo: 替换成批量查询接口
  68. const { answer, answerId } = await answeBaseByQuestionId({ questionId: id })
  69. if (answer.isTrue) {
  70. continue
  71. }
  72. data.answer = answer.id
  73. data.value = answerId
  74. data.isTrue = answer.isTrue
  75. groups[0].children.push(data)
  76. } else {
  77. // todo: 替换成批量查询接口
  78. const { answer, remark } = await answeTrainByQuestionId({ questionId: id })
  79. if (!remark) {
  80. continue
  81. }
  82. data.answer = remark
  83. data.value = answer
  84. groups[1].children.push(data)
  85. }
  86. }
  87. list.value = groups.filter(group => group.children.length > 0)
  88. console.log('--list', list.value)
  89. } catch (err) {
  90. console.log('--initList--err', err)
  91. }
  92. }
  93. const restTimes = ref()
  94. onShow(() => {
  95. // todo: fetch
  96. restTimes.value = parseInt(configList.value.pet_work_num.paramValueText || 0)
  97. initList()
  98. })
  99. const onClick = () => {
  100. uni.reLaunch({
  101. url: "/otherPages/authentication/examination/start"
  102. // todo: check
  103. // url: "/otherPages/authentication/list/index"
  104. })
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. $bar-height: 163rpx;
  109. .page {
  110. padding-bottom: $bar-height;
  111. }
  112. .box {
  113. // background-image: linear-gradient(to bottom, #ffbf60, #f2f2f2);
  114. padding: 16rpx;
  115. .step {
  116. width: 720rpx;
  117. height: 32rpx;
  118. border-radius: 32rpx;
  119. background-color: #D9D9D9;
  120. .in {
  121. width: 50%;
  122. height: 32rpx;
  123. background-color: #ffbf60;
  124. border-radius: 32rpx;
  125. }
  126. }
  127. }
  128. .content {
  129. border-radius: 20rpx;
  130. padding: 15rpx 20rpx;
  131. .label {
  132. width: 86rpx;
  133. padding: 5rpx 15rpx;
  134. color: #fff;
  135. background-color: #FFBF60;
  136. justify-content: center;
  137. }
  138. }
  139. .group + .group {
  140. margin-top: 68rpx;
  141. }
  142. .level {
  143. display: flex;
  144. }
  145. .footer-btn {
  146. height: $bar-height;
  147. }
  148. .tips {
  149. &-rest {
  150. color: #707070;
  151. font-size: 22rpx;
  152. margin: 9rpx 0 13rpx 0;
  153. .highlight {
  154. color: #FF8DC6;
  155. }
  156. }
  157. }
  158. </style>