exchange.uvue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. console.log("用户已确认:", action);
  47. },
  48. });
  49. loading.value = false
  50. } catch (err: Error) {
  51. uni.showToast({
  52. title: err.message,
  53. icon: 'error'
  54. })
  55. loading.value = false
  56. }
  57. }
  58. </script>
  59. <template>
  60. <view class="cc">
  61. <view class="cont2" v-if="userInfo != null && userInfo?.userInfo?.memberLevel != 'default'">
  62. <image src="https://oss.xiaoxiongcode.com/static/home/6293.png" mode="scaleToFill" lazy-load alt=""
  63. class="w-full h-full object-cover absolute top-0 left-0 z-[1]" />
  64. <view class="relative z-[2] w-full h-full pt-[70rpx] px-[50rpx] pr-[56rpx]">
  65. <cl-row :gutter="12">
  66. <cl-col :span="8" :pt="{
  67. className: 'bg-[#FDE6BD]',
  68. }">
  69. <text class="text-[16rpx] font-bold py-[5rpx] text-center text-[#A57138]">课程名称</text>
  70. </cl-col>
  71. <cl-col :span="8" :pt="{
  72. className: 'bg-[#FDE6BD]',
  73. }">
  74. <text class="text-[16rpx] font-bold py-[5rpx] text-center text-[#A57138]">兑换时间</text>
  75. </cl-col>
  76. <cl-col :span="8" :pt="{
  77. className: 'bg-[#FDE6BD]',
  78. }">
  79. <text class="text-[16rpx] font-bold py-[5rpx] text-center text-[#A57138]">到期时间</text>
  80. </cl-col>
  81. </cl-row>
  82. <cl-row :gutter="12" v-for="item in recordList" :key="item.id as string" :pt="{
  83. className: 'border-b-[1rpx] border-[#FFE9C0] border-solid align-center',
  84. }">
  85. <cl-col :span="8">
  86. <text class="text-[14rpx] font-bold py-[5rpx] text-center text-[#333]">{{ item.mainTitle }}</text>
  87. </cl-col>
  88. <cl-col :span="8">
  89. <text class="text-[14rpx] font-bold py-[5rpx] text-center text-[#333]">{{ item.createdTime }}</text>
  90. </cl-col>
  91. <cl-col :span="8">
  92. <text class="text-[14rpx] font-bold py-[5rpx] text-center text-[#333]">{{ item.updateTime }}</text>
  93. </cl-col>
  94. </cl-row>
  95. </view>
  96. </view>
  97. <view class="cont" v-else>
  98. <image src="https://oss.xiaoxiongcode.com/static/home/6292.png" mode="widthFix" lazy-load alt=""
  99. class="w-full h-full object-cover absolute top-0 left-0 z-[1]" />
  100. <text class="text-[30px] font-bold relative z-[2] pb-[20rpx]">
  101. —— 兑换码 ——
  102. </text>
  103. <cl-input v-model="code" :pt="{
  104. className: '!h-[40px] relative z-[2] w-[200rpx]',
  105. }" placeholder="请输入兑换码">
  106. <template #append>
  107. <cl-button type="primary" :pt="{
  108. className: 'text-[18px] w-[100px] scale-[1.1] transform translate-x-[3rpx]',
  109. }" @tap="handleExchange()" :loading="loading">兑换</cl-button>
  110. </template>
  111. </cl-input>
  112. </view>
  113. </view>
  114. </template>
  115. <style lang="scss" scoped>
  116. .cc {
  117. @apply w-full flex items-center justify-center;
  118. height: calc(97vh - 85px);
  119. }
  120. .cont {
  121. @apply mx-auto mt-[10rpx] text-black w-[420rpx] rounded-[30px] px-10 h-[270rpx] flex items-center justify-center pb-[20rpx] relative;
  122. }
  123. .cont2 {
  124. @apply w-[600rpx] h-[250rpx] relative;
  125. }
  126. </style>