exchange.uvue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <script setup lang='ts'>
  2. import { ref, computed, onMounted } from 'vue'
  3. import { exchangeCode } from '@/services/user'
  4. import { dict } from '@/.cool/store'
  5. import { user, parse, userInfo } from '@/.cool'
  6. import { type SubjectFeeRecord, fetchSubjectFeeRecord } from '@/services/subject/record'
  7. import { useUi } from "@/uni_modules/cool-ui";
  8. const recordList = ref<SubjectFeeRecord[]>([])
  9. const ui = useUi();
  10. const code = ref<string>('')
  11. const loading = ref<boolean>(false)
  12. onMounted(() => {
  13. if (userInfo.value == null) {
  14. user.logout()
  15. return
  16. }
  17. fetchSubjectFeeRecord({
  18. createdUserId: userInfo.value.userInfo.userId
  19. }).then(res => {
  20. recordList.value = res
  21. })
  22. })
  23. async function handleExchange() {
  24. if (code.value == "" || code.value == null) {
  25. uni.showToast({
  26. title: '请输入兑换码',
  27. icon: 'none'
  28. })
  29. return
  30. }
  31. try {
  32. const subject = dict.getValueByLabelMapByType('index_subject_id')
  33. console.log(subject)
  34. const id = subject['物理'] as string
  35. loading.value = true
  36. await exchangeCode({
  37. exchangeCode: code.value,
  38. subjectId: id,
  39. })
  40. await user.get()
  41. ui.showConfirm({
  42. title: "提示",
  43. message: "兑换成功",
  44. showCancel: false,
  45. callback(action) {
  46. if (userInfo.value == null) {
  47. return
  48. }
  49. fetchSubjectFeeRecord({
  50. createdUserId: userInfo.value.userInfo.userId
  51. }).then(res => {
  52. recordList.value = res
  53. })
  54. },
  55. });
  56. loading.value = false
  57. } catch (err: Error) {
  58. uni.showToast({
  59. title: err.message,
  60. icon: 'error'
  61. })
  62. loading.value = false
  63. }
  64. }
  65. </script>
  66. <template>
  67. <view class="cc">
  68. <view class="cont2" v-if="userInfo != null && userInfo?.userInfo?.memberLevel != 'default'">
  69. <image src="https://oss.xiaoxiongcode.com/static/home/6293.png" mode="scaleToFill" lazy-load alt=""
  70. class="w-full h-full object-cover absolute top-0 left-0 z-[1]" />
  71. <view class="relative z-[2] w-full h-full pt-[70rpx] px-[50rpx] pr-[56rpx]">
  72. <cl-row :gutter="12">
  73. <cl-col :span="8" :pt="{
  74. className: 'bg-[#FDE6BD]',
  75. }">
  76. <text class="text-[16rpx] font-bold py-[5rpx] text-center text-[#A57138]">课程名称</text>
  77. </cl-col>
  78. <cl-col :span="8" :pt="{
  79. className: 'bg-[#FDE6BD]',
  80. }">
  81. <text class="text-[16rpx] font-bold py-[5rpx] text-center text-[#A57138]">兑换时间</text>
  82. </cl-col>
  83. <cl-col :span="8" :pt="{
  84. className: 'bg-[#FDE6BD]',
  85. }">
  86. <text class="text-[16rpx] font-bold py-[5rpx] text-center text-[#A57138]">到期时间</text>
  87. </cl-col>
  88. </cl-row>
  89. <cl-row :gutter="12" v-for="item in recordList" :key="item.id as string" :pt="{
  90. className: 'border-b-[1rpx] border-[#FFE9C0] border-solid align-center',
  91. }">
  92. <cl-col :span="8">
  93. <text class="text-[14rpx] font-bold py-[5rpx] text-center text-[#333]">{{ item.mainTitle }}</text>
  94. </cl-col>
  95. <cl-col :span="8">
  96. <text class="text-[14rpx] font-bold py-[5rpx] text-center text-[#333]">{{ item.createdTime }}</text>
  97. </cl-col>
  98. <cl-col :span="8">
  99. <text class="text-[14rpx] font-bold py-[5rpx] text-center text-[#333]">{{ item.updateTime }}</text>
  100. </cl-col>
  101. </cl-row>
  102. </view>
  103. </view>
  104. <view class="cont" v-else>
  105. <image src="https://oss.xiaoxiongcode.com/static/home/6292.png" mode="widthFix" lazy-load alt=""
  106. class="w-full h-full object-cover absolute top-0 left-0 z-[1]" />
  107. <text class="text-[30px] font-bold relative z-[2] pb-[20rpx]">
  108. —— 兑换码 ——
  109. </text>
  110. <cl-input v-model="code" :pt="{
  111. className: '!h-[40px] relative z-[2] w-[200rpx]',
  112. }" placeholder="请输入兑换码">
  113. <template #append>
  114. <cl-button type="primary" :pt="{
  115. className: 'text-[18px] w-[100px] scale-[1.1] transform translate-x-[3rpx]',
  116. }" @tap="handleExchange()" :loading="loading">兑换</cl-button>
  117. </template>
  118. </cl-input>
  119. </view>
  120. </view>
  121. </template>
  122. <style lang="scss" scoped>
  123. .cc {
  124. @apply w-full flex items-center justify-center;
  125. height: calc(97vh - 85px);
  126. }
  127. .cont {
  128. @apply mx-auto mt-[10rpx] text-black w-[420rpx] rounded-[30px] px-10 h-[270rpx] flex items-center justify-center pb-[20rpx] relative;
  129. }
  130. .cont2 {
  131. @apply w-[600rpx] h-[250rpx] relative;
  132. }
  133. </style>