duihuanmaDialog.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!-- 小弹窗 一行文字 -->
  2. <template>
  3. <uni-popup ref="tipSmallPopup" :animation="true" :is-mask-click="false"
  4. mask-background-color="rgba(255, 255, 255, 0.6);">
  5. <view class="icon-title-navBar-box">
  6. <view @click="handleBack" class="nav-bar-icon"></view>
  7. <text class="nav-bar-title">兑换码</text>
  8. </view>
  9. <view class="ezy-tip-dialog tip-small-dialog duihuan-dialog" style="height: 100vh">
  10. <view class="tip-content-box">
  11. <view class="icon-title-navBar-box">
  12. <view class="nav-bar-title">{{ title }}</view>
  13. </view>
  14. <icon class="head-img-box" :style="{backgroundImage: 'url(' + icon + ')'}"></icon>
  15. <view>{{ nickName }}</view>
  16. <view>{{ userName }}</view>
  17. <input class="duihuan-input" type="text" focus v-model="duihuamaValue" placeholder="请输入兑换码"/>
  18. <view class="tip-btn-box">
  19. <view class="confirm-btn" @click="confirmBtn"></view>
  20. </view>
  21. </view>
  22. </view>
  23. </uni-popup>
  24. <!-- 失败 -->
  25. <duihuanError ref="dhErrRef"></duihuanError>
  26. <!-- 成功 -->
  27. <duihuanSuccess ref="dhSucRef"></duihuanSuccess>
  28. </template>
  29. <script setup>
  30. import {ref} from 'vue';
  31. import duihuanError from "./duihuanError";
  32. import duihuanSuccess from "./duihuanSuccess";
  33. import {
  34. duihuanmaCode,
  35. } from '@/api/my.js'
  36. import cacheManager from '@/utils/cacheManager';
  37. const props = defineProps({
  38. title: {
  39. type: String,
  40. default: '提示'
  41. },
  42. content: {
  43. type: String,
  44. require: true,
  45. default: ''
  46. },
  47. userName: {
  48. type: String,
  49. default: ''
  50. },
  51. nickName: {
  52. type: String,
  53. default: ''
  54. },
  55. icon: {
  56. type: String,
  57. },
  58. });
  59. const tipSmallPopup = ref(null); // 索引
  60. const duihuamaValue = ref(''); // 索引
  61. const $emit = defineEmits(['confirm-btn'])
  62. const dhErrRef = ref(null);
  63. const dhSucRef = ref(null);
  64. function handleBack() {
  65. handleClose();
  66. }
  67. // 打开弹窗
  68. function handleShow() {
  69. tipSmallPopup.value.open('bottom');
  70. }
  71. // 取消
  72. function handleClose() {
  73. duihuamaValue.value = ''
  74. tipSmallPopup.value.close();
  75. }
  76. // 确认
  77. function confirmBtn() {
  78. let req = {
  79. code: duihuamaValue.value
  80. }
  81. duihuanmaCode(req).then(res => {
  82. if (res.code == 0) {
  83. toast('兑换成功')
  84. // 清空缓存
  85. cacheManager.updateObject('auth', {})
  86. // 关窗清空
  87. tipSmallPopup.value.close();
  88. duihuamaValue.value = ''
  89. } else {
  90. toast('兑换失败请重试或联系管理员')
  91. return false
  92. }
  93. })
  94. }
  95. defineExpose({
  96. handleShow
  97. })
  98. </script>
  99. <style>
  100. </style>