exchange.uvue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <script setup lang='ts'>
  2. import { ref, onMounted } from 'vue'
  3. import { exchangeCode } from '@/services/user'
  4. import { dict } from '@/.cool/store'
  5. import { user, router } from '@/.cool'
  6. import { useUi } from "@/uni_modules/cool-ui";
  7. import { fetchSubjectFeeRecord } from '@/services/subject/record'
  8. const recordList = ref<any[]>([])
  9. const ui = useUi();
  10. const code = ref<string>('')
  11. const loading = ref<boolean>(false)
  12. onMounted(() => {
  13. if (!user.info.value?.userInfo) {
  14. user.logout()
  15. return
  16. }
  17. fetchSubjectFeeRecord({
  18. createdUserId: user.info.value?.userInfo.userId
  19. }).then(res => {
  20. recordList.value = res
  21. })
  22. })
  23. async function handleExchange() {
  24. if (!code.value) {
  25. uni.showToast({
  26. title: '请输入兑换码',
  27. icon: 'none'
  28. })
  29. return
  30. }
  31. loading.value = true
  32. try {
  33. await exchangeCode({
  34. exchangeCode: code.value,
  35. subjectId: dict.getValueByLabelMapByType('index_subject_id')['物理'],
  36. })
  37. await user.get()
  38. ui.showConfirm({
  39. title: "提示",
  40. message: "兑换成功",
  41. showCancel: false,
  42. callback(action) {
  43. console.log("用户已确认:", action);
  44. },
  45. });
  46. loading.value = false
  47. } catch (err: any) {
  48. uni.showToast({
  49. title: err.message,
  50. icon: 'error'
  51. })
  52. loading.value = false
  53. }
  54. }
  55. </script>
  56. <template>
  57. <view class="content" v-if="user.info.value?.userInfo && user.info.value?.userInfo?.memberLevel === 'default'">
  58. <view class="text-[30px] font-bold">
  59. 兑换码
  60. </view>
  61. <cl-input v-model="code" :pt="{
  62. className: '!h-[40px] ',
  63. }" placeholder="请输入兑换码"></cl-input>
  64. <cl-button type="warn" :pt="{
  65. className: 'text-[18px] w-[140px] rounded-full text-black text-center check to-pink-500 py-[5px] ',
  66. }" @tap="handleExchange()" :loading="loading">兑换</cl-button>
  67. </view>
  68. <view class="content2" v-else>
  69. <view v-for="item in recordList" :key="item" class="box flex flex-row items-center gap-2">
  70. <view class="h-full">
  71. <image src="https://oss.xiaoxiongcode.com/static/个人中心/图层 13.png" mode="heightFix" class=" h-full" />
  72. </view>
  73. <view class="flex flex-col justify-around h-full">
  74. <view class="text-[5vh] font-bold text-[#FC500F]">
  75. {{ item.mainTitle }}
  76. </view>
  77. <view class="text-[3vh] text-[#999]">
  78. 兑换时间:{{ item.createdTime }}
  79. </view>
  80. <view class="text-[3vh] text-[#999]">
  81. 到期时间:{{ item.updateTime }}
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <style lang="scss" scoped>
  88. .content {
  89. @apply absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-black w-[120vh] border-[3px] border-[#fff] border-solid rounded-[30px] px-10 py-4 h-[44vh] flex items-center justify-center gap-4 bg-white;
  90. }
  91. .content2 {
  92. @apply absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2;
  93. overflow: hidden;
  94. border-radius: 10px;
  95. }
  96. .box {
  97. width: 120vh;
  98. // 宽高比3/1
  99. aspect-ratio: 4 / 1;
  100. padding: 5px;
  101. border-radius: 10px;
  102. background: linear-gradient(0deg, #FFFBF7 0%, #FFE0CC 100%);
  103. box-shadow: 3px 6px 4px 0px rgba(239, 103, 36, 0.48);
  104. }
  105. .check {
  106. background: linear-gradient(0deg, #FBD00E 0%, #FBEC92 100%);
  107. }
  108. </style>