duihuanma.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="ezy-dhm-page">
  3. <view class="icon-title-navBar-box">
  4. <view @click="handleBack" class="nav-bar-icon"></view>
  5. <text class="nav-bar-title">使用兑换码</text>
  6. </view>
  7. <view class="ezy-page-body dhm-body">
  8. <view class="dhm-head-box">
  9. <icon class="head-img-box" :style="{backgroundImage: 'url(' + myInfoData.icon + ')'}"></icon>
  10. <view class="head-content-box">
  11. <view>{{ myInfoData.nickName }}</view>
  12. <!-- <view>{{ myInfoData.userName }}</view>-->
  13. </view>
  14. </view>
  15. <view class="duihuan-input-box">
  16. <icon class="duihuan-prefix-icon"></icon>
  17. <input class="duihuan-input" type="text" v-model="duihuamaValue" placeholder="请输入兑换码" />
  18. </view>
  19. <ezyActiveVue class="ezy-btn-active duihuan-confirm-btn" @aclick="confirmBtn">确定兑换
  20. </ezyActiveVue>
  21. </view>
  22. </view>
  23. <!-- 失败 -->
  24. <duihuanError ref="dhErrRef"></duihuanError>
  25. <!-- 成功 -->
  26. <duihuanSuccess ref="dhSucRef"></duihuanSuccess>
  27. </template>
  28. <script setup>
  29. import {
  30. ref,reactive
  31. } from 'vue';
  32. import ezyActiveVue from "@/components/ezyActive/ezyActive.vue"
  33. import duihuanError from "./components/duihuanma/duihuanError";
  34. import duihuanSuccess from "./components/duihuanma/duihuanSuccess";
  35. import {
  36. duihuanmaCodeNew,
  37. } from '@/api/my.js'
  38. import cacheManager from '@/utils/cacheManager';
  39. import {toast} from "@/utils/common";
  40. import {myInfo} from "@/api/my";
  41. import {
  42. onLoad,
  43. onShow
  44. } from '@dcloudio/uni-app';
  45. const duihuamaValue = ref(''); // 索引
  46. const dhErrRef = ref(null);
  47. const dhSucRef = ref(null);
  48. const myInfoData = reactive({
  49. userName: '',
  50. nickName: '',
  51. icon: '',
  52. });
  53. onLoad(() => {
  54. getMyInfo();
  55. })
  56. // 获取用户数据
  57. function getMyInfo() {
  58. myInfo({}).then(res => {
  59. myInfoData.userName = res.data.userName;
  60. myInfoData.nickName = res.data.nickName;
  61. if (res.data.nickName) {
  62. myInfoData.nickName = res.data.nickName;
  63. } else {
  64. myInfoData.nickName = '鹅状元';
  65. }
  66. if (res.data.icon) {
  67. myInfoData.icon = res.data.icon;
  68. } else {
  69. getUserImg()
  70. }
  71. })
  72. }
  73. // 获取用户头像
  74. function getUserImg() {
  75. myInfoData.icon = 'static/images/my/head-img1.png'
  76. }
  77. function handleBack() {
  78. uni.navigateBack()
  79. }
  80. // 确认
  81. function confirmBtn() {
  82. if (!duihuamaValue.value) {
  83. toast('请输入兑换码')
  84. return;
  85. }
  86. let req = {
  87. code: duihuamaValue.value
  88. }
  89. duihuanmaCodeNew(req).then(res => {
  90. if (res.code == 0) {
  91. // toast('兑换成功')
  92. // 清空缓存
  93. cacheManager.remove("contentInfo");
  94. duihuamaValue.value = '';
  95. dhSucRef.value.handleShow()
  96. }
  97. }).catch(err=> {
  98. if (err && err.code == 1001) {
  99. dhErrRef.value.handleShow(err.data.msg)
  100. }
  101. })
  102. }
  103. </script>
  104. <style>
  105. </style>