猫妈狗爸伴宠师小程序前端代码
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.

218 lines
4.7 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <template>
  2. <view class="po-r">
  3. <image class="bg" src="" mode=""></image>
  4. <view class="po-a content w-100">
  5. <view class="top bg-fff">
  6. <view class="com-title size-32 fw700 flex-rowl">
  7. 您选择的宠物类型
  8. </view>
  9. <view>
  10. <image class="mt32"
  11. style="margin-right: 10rpx;"
  12. v-for="(img, inde) in petTypeImg"
  13. :src="img.image" mode="widthFix"></image>
  14. </view>
  15. </view>
  16. <view class="text po-r bg-fff">
  17. <up-parse class="size-28" :content="configList.pet_raising_details.paramValueArea"></up-parse>
  18. <view class="po-a flex-rowl tips">
  19. <image class="ml16" src="@/static/images/ydd/icon1.png" mode="widthFix"></image>
  20. <text class="size-28 ml16">养宠考试说明</text>
  21. </view>
  22. </view>
  23. <view class="text po-r bg-fff mb150">
  24. <up-parse class="size-28" :content="configList.pet_attention_details.paramValueArea"></up-parse>
  25. <view class="po-a flex-rowl tips">
  26. <image class="ml16" src="@/static/images/ydd/icon2.png" mode="widthFix"></image>
  27. <text class="size-28 ml16">考试注意事项</text>
  28. </view>
  29. </view>
  30. </view>
  31. <view class="footer-btn flex-colc">
  32. <view class="size-22 color-777 tips-rest">
  33. <template v-if="canTakeExam">
  34. 剩余考试机会<text class="highlight">{{ restTimes - examNumber }}</text>
  35. </template>
  36. <template v-else>
  37. <text class="next-exam-time">下次考试时间{{ nextExamTime }}</text>
  38. </template>
  39. </view>
  40. <view class="btn" :class="{ 'btn-disabled': !canTakeExam }" @click="toNext">
  41. {{ canTakeExam ? '开始考试' : '暂无考试机会' }}
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script setup>
  47. import { ref, computed } from 'vue'
  48. import { useStore } from 'vuex'
  49. import { onLoad } from '@dcloudio/uni-app'
  50. import { insertUser, udpateUser, getUserOne } from '@/api/userTeacher'
  51. import dayjs from 'dayjs'
  52. const store = useStore()
  53. const petType = ref([])
  54. const restTimes = ref()
  55. const lastExamTime = ref('')
  56. //已考试次数
  57. const examNumber = ref(0)
  58. const configList = computed(() => {
  59. return store.getters.configList
  60. })
  61. const userId = computed(() => {
  62. return store.state.user.userInfo.userId
  63. })
  64. // 计算下次考试时间
  65. const nextExamTime = computed(() => {
  66. if (!lastExamTime.value) return ''
  67. const nextTime = dayjs(lastExamTime.value).add(1, 'year')
  68. return nextTime.format('YYYY年MM月DD日')
  69. })
  70. // 判断是否可以参加考试
  71. const canTakeExam = computed(() => {
  72. if((restTimes.value - examNumber.value) > 0){
  73. return true
  74. }
  75. if (!lastExamTime.value) return true
  76. const nextTime = dayjs(lastExamTime.value).add(1, 'year')
  77. return dayjs().isAfter(nextTime)
  78. })
  79. const getInfo = async () => {
  80. try {
  81. if(!userId.value) {
  82. return
  83. }
  84. const data = await getUserOne(userId.value)
  85. examNumber.value = data.examNumber || 0
  86. lastExamTime.value = data.examTime
  87. petType.value = data.petType.split(',').map(n => parseInt(n))
  88. } catch (err) {
  89. console.log('--err', err)
  90. }
  91. }
  92. const petTypeImg = computed(() => {
  93. return store.getters.petTypeOptions.
  94. filter(item => petType.value.includes(item.id))
  95. })
  96. onLoad((option) => {
  97. store.dispatch('fetchPetTypeOptions')
  98. getInfo()
  99. restTimes.value = parseInt(configList.value.pet_work_num.paramValueText || 0)
  100. })
  101. const toNext = () => {
  102. if (!canTakeExam.value) {
  103. uni.showToast({
  104. title: `请于${nextExamTime.value}后再来考试`,
  105. icon: 'none'
  106. })
  107. return
  108. }
  109. uni.navigateTo({
  110. url: "/otherPages/authentication/examination/base"
  111. })
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .mb150 {
  116. margin-bottom: 150rpx;
  117. }
  118. .text {
  119. padding: 50rpx 37rpx;
  120. border-radius: 20rpx;
  121. margin-top: 43px;
  122. }
  123. .tips {
  124. width: 302rpx;
  125. height: 67rpx;
  126. background-color: #FFEBCE;
  127. top: -28rpx;
  128. left: 20rpx;
  129. border-radius: 0 90rpx 0 0;
  130. image {
  131. width: 40rpx;
  132. }
  133. }
  134. .content {
  135. padding: 16rpx;
  136. width: 718rpx;
  137. left: 0;
  138. top: 0;
  139. }
  140. .bg {
  141. width: 750rpx;
  142. height: 432px;
  143. background-image: linear-gradient(to bottom, #FFBF60, #f5f5f5);
  144. }
  145. .top {
  146. padding: 46rpx 17rpx 17rpx;
  147. margin: 16rpx;
  148. border-radius: 20rpx;
  149. image {
  150. width: 198rpx;
  151. height: 228rpx;
  152. }
  153. }
  154. .tips {
  155. &-rest {
  156. color: #707070;
  157. font-size: 22rpx;
  158. margin: 9rpx 0 13rpx 0;
  159. .highlight {
  160. color: #FF8DC6;
  161. }
  162. }
  163. }
  164. .next-exam-time {
  165. color: #FF2A2A;
  166. }
  167. .footer-btn {
  168. height: 163rpx;
  169. box-sizing: border-box;
  170. padding-bottom: 18rpx;
  171. }
  172. .btn {
  173. width: 600rpx;
  174. height: 80rpx;
  175. line-height: 80rpx;
  176. text-align: center;
  177. background: #FFBF60;
  178. color: #fff;
  179. border-radius: 40rpx;
  180. font-size: 32rpx;
  181. &-disabled {
  182. background: #CCCCCC;
  183. color: #FFFFFF;
  184. }
  185. }
  186. </style>