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

221 lines
4.7 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
2 weeks ago
4 months ago
4 months ago
4 months ago
4 months ago
4 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. <!-- 客服组件 -->
  45. <CustomerService />
  46. </view>
  47. </template>
  48. <script setup>
  49. import { ref, computed } from 'vue'
  50. import { useStore } from 'vuex'
  51. import { onLoad } from '@dcloudio/uni-app'
  52. import { insertUser, udpateUser, getUserOne } from '@/api/userTeacher'
  53. import dayjs from 'dayjs'
  54. const store = useStore()
  55. const petType = ref([])
  56. const restTimes = ref()
  57. const lastExamTime = ref('')
  58. //已考试次数
  59. const examNumber = ref(0)
  60. const configList = computed(() => {
  61. return store.getters.configList
  62. })
  63. const userId = computed(() => {
  64. return store.state.user.userInfo.userId
  65. })
  66. // 计算下次考试时间
  67. const nextExamTime = computed(() => {
  68. if (!lastExamTime.value) return ''
  69. const nextTime = dayjs(lastExamTime.value).add(1, 'year')
  70. return nextTime.format('YYYY年MM月DD日')
  71. })
  72. // 判断是否可以参加考试
  73. const canTakeExam = computed(() => {
  74. if((restTimes.value - examNumber.value) > 0){
  75. return true
  76. }
  77. if (!lastExamTime.value) return true
  78. const nextTime = dayjs(lastExamTime.value).add(1, 'year')
  79. return dayjs().isAfter(nextTime)
  80. })
  81. const getInfo = async () => {
  82. try {
  83. if(!userId.value) {
  84. return
  85. }
  86. const data = await getUserOne(userId.value)
  87. examNumber.value = data.examNumber || 0
  88. lastExamTime.value = data.examTime
  89. petType.value = data.petType.split(',').map(n => parseInt(n))
  90. } catch (err) {
  91. console.log('--err', err)
  92. }
  93. }
  94. const petTypeImg = computed(() => {
  95. return store.getters.petTypeOptions.
  96. filter(item => petType.value.includes(item.id))
  97. })
  98. onLoad((option) => {
  99. store.dispatch('fetchPetTypeOptions')
  100. getInfo()
  101. restTimes.value = parseInt(configList.value.pet_work_num.paramValueText || 0)
  102. })
  103. const toNext = () => {
  104. if (!canTakeExam.value) {
  105. uni.showToast({
  106. title: `请于${nextExamTime.value}后再来考试`,
  107. icon: 'none'
  108. })
  109. return
  110. }
  111. uni.navigateTo({
  112. url: "/otherPages/authentication/examination/base"
  113. })
  114. }
  115. </script>
  116. <style lang="scss" scoped>
  117. .mb150 {
  118. margin-bottom: 150rpx;
  119. }
  120. .text {
  121. padding: 50rpx 37rpx;
  122. border-radius: 20rpx;
  123. margin-top: 43px;
  124. }
  125. .tips {
  126. width: 302rpx;
  127. height: 67rpx;
  128. background-color: #FFEBCE;
  129. top: -28rpx;
  130. left: 20rpx;
  131. border-radius: 0 90rpx 0 0;
  132. image {
  133. width: 40rpx;
  134. }
  135. }
  136. .content {
  137. padding: 16rpx;
  138. width: 718rpx;
  139. left: 0;
  140. top: 0;
  141. }
  142. .bg {
  143. width: 750rpx;
  144. height: 432px;
  145. background-image: linear-gradient(to bottom, #FFBF60, #f5f5f5);
  146. }
  147. .top {
  148. padding: 46rpx 17rpx 17rpx;
  149. margin: 16rpx;
  150. border-radius: 20rpx;
  151. image {
  152. width: 198rpx;
  153. height: 228rpx;
  154. }
  155. }
  156. .tips {
  157. &-rest {
  158. color: #707070;
  159. font-size: 22rpx;
  160. margin: 9rpx 0 13rpx 0;
  161. .highlight {
  162. color: #FF8DC6;
  163. }
  164. }
  165. }
  166. .next-exam-time {
  167. color: #FF2A2A;
  168. }
  169. .footer-btn {
  170. height: 163rpx;
  171. box-sizing: border-box;
  172. padding-bottom: 18rpx;
  173. }
  174. .btn {
  175. width: 600rpx;
  176. height: 80rpx;
  177. line-height: 80rpx;
  178. text-align: center;
  179. background: #FFBF60;
  180. color: #fff;
  181. border-radius: 40rpx;
  182. font-size: 32rpx;
  183. &-disabled {
  184. background: #CCCCCC;
  185. color: #FFFFFF;
  186. }
  187. }
  188. </style>