exchange.uvue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <script setup lang='ts'>
  2. import { ref } from 'vue'
  3. import { exchangeCode } from '@/services/user'
  4. import { dict } from '@/.cool/store'
  5. import { user } from '@/.cool'
  6. import { useUi } from "@/uni_modules/cool-ui";
  7. const ui = useUi();
  8. const code = ref<string>('')
  9. async function handleExchange() {
  10. if (!code.value) {
  11. uni.showToast({
  12. title: '请输入兑换码',
  13. icon: 'none'
  14. })
  15. return
  16. }
  17. try {
  18. await exchangeCode({
  19. exchangeCode: code.value,
  20. subjectId: dict.getValueByLabelMapByType('index_subject_id')['物理'],
  21. })
  22. await user.get()
  23. ui.showConfirm({
  24. title: "提示",
  25. message: "兑换成功",
  26. showCancel: false,
  27. callback(action) {
  28. console.log("用户已确认:", action);
  29. },
  30. });
  31. } catch (err: any) {
  32. uni.showToast({
  33. title: err.message,
  34. icon: 'error'
  35. })
  36. }
  37. }
  38. </script>
  39. <template>
  40. <view class="content">
  41. <view class="text-[30px] font-bold">
  42. 兑换码
  43. </view>
  44. <cl-input v-model="code" :pt="{
  45. className: '!h-[40px] ',
  46. }" placeholder="请输入兑换码"></cl-input>
  47. <view class="text-[18px] w-[140px] rounded-full text-black text-center check
  48. to-pink-500 py-[5px] " @tap="handleExchange()">
  49. 兑换
  50. </view>
  51. </view>
  52. </template>
  53. <style lang="scss" scoped>
  54. .content {
  55. @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;
  56. }
  57. .check {
  58. background: linear-gradient(0deg, #FBD00E 0%, #FBEC92 100%);
  59. }
  60. </style>