shoppingMall.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="">
  3. <view class="margin-top" style="padding: 0 30rpx;">
  4. <view class="title">选择兑换平台</view>
  5. <view class="flex" style="justify-content: space-between; margin: 20rpx 0;">
  6. <view class="module" :class="{ selected: selectedModule === 1 }" @click="selectModule(1)">
  7. <image v-if="globalImages" :src="globalImages + 'images/my/douyin.png'" style="width: 100rpx;height: 100rpx;" mode="">
  8. </image>
  9. <view style="font-size: 33rpx;margin-top: 20rpx;">抖音兑换码</view>
  10. <view style="font-size: 23rpx; color: #999;margin-top: 10rpx;">输入抖音兑换码领取奖励</view>
  11. </view>
  12. <view class="module" :class="{ selected2: selectedModule === 2 }"
  13. @click="selectModule(2)">
  14. <image v-if="globalImages" :src="globalImages + 'images/my/kuaishou.png'" style="width: 100rpx;height: 100rpx;" mode="">
  15. </image>
  16. <view style="font-size: 33rpx;margin-top: 20rpx;">快手兑换码</view>
  17. <view style="font-size: 23rpx; color: #999;margin-top: 10rpx;">输入快手兑换码领取奖励</view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="margin-top" style="padding: 0 30rpx;">
  22. <view class="flex align-center" style="position: relative;">
  23. <view class="title">输入兑换码</view>
  24. </view>
  25. <view class="margin-top padding" style="background: #FFFFFF;border-radius: 20upx;">
  26. <view class="flex"
  27. style="margin: 20rpx 0; padding: 20rpx;border-radius: 11rpx; border: 1px #ccc solid;">
  28. <input class="uni-input" style="width: 90%;" placeholder="请输入兑换码" v-model="exchangeCode" />
  29. <image v-if="globalImages" :src="globalImages + 'images/saoma.png'" style="width: 44rpx;height: 44rpx;margin-left: 15rpx;"
  30. mode="" @click="scanQRCode"></image>
  31. </view>
  32. </view>
  33. <view class="margin-top padding" style="background: #FFFFFF;border-radius: 20upx;">
  34. <view class="title">使用说明</view>
  35. <view class="instruction-list">
  36. <view class="instruction-item">
  37. <text class="step-number">1.</text>
  38. <text class="step-content">在抖音/快手 APP 内获取兑换码</text>
  39. </view>
  40. <view class="instruction-item">
  41. <text class="step-number">2.</text>
  42. <text class="step-content">选择对应平台并输入兑换码</text>
  43. </view>
  44. <view class="instruction-item">
  45. <text class="step-number">3.</text>
  46. <text class="step-content">点击“立即兑换”按钮完成兑换</text>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="margin-top padding" style="background: #FFFFFF;border-radius: 20upx;">
  51. <view class="title">注意事项</view>
  52. <ul class="notice-list">
  53. <li class="notice-item">兑换码有效期通常为 30 天,请及时兑换</li>
  54. <li class="notice-item">每个兑换码仅使用一次</li>
  55. <li class="notice-item">兑换成功奖励直接发放至账户</li>
  56. <li class="notice-item">如有问题请联系客服 400 - 123 - 4567</li>
  57. </ul>
  58. </view>
  59. <view class="login_btn" @click="handleRedeem">立即兑换</view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import { waitForGlobalImages } from '@/utils/globalImageLoader'
  65. export default {
  66. data() {
  67. return {
  68. selectedModule: 1,
  69. globalImages: '',
  70. exchangeCode: '', // 用于显示明文
  71. encryptedCode: '',
  72. isScanned: false // 是否是扫码
  73. }
  74. },
  75. methods: {
  76. selectModule(module) {
  77. this.selectedModule = module;
  78. },
  79. // 扫码逻辑(获取密文 -> 调用解密接口 -> 设置明文)
  80. scanQRCode() {
  81. uni.scanCode({
  82. onlyFromCamera: false,
  83. success: (res) => {
  84. this.encryptedCode = res.result;
  85. console.log('扫码密文:', this.encryptedCode);
  86. if (!this.encryptedCode) {
  87. return uni.showToast({ title: '扫码结果无效', icon: 'none' });
  88. }
  89. // this.isScanned = true; // 标记为扫码获取
  90. uni.showLoading({ title: '解密中...' });
  91. this.$Request.getT("/app/redeemCode/decryptAES?encryptedData=" + this.encryptedCode)
  92. .then(res => {
  93. uni.hideLoading();
  94. if (res.code === 0 && res.data) {
  95. this.exchangeCode = res.data; // 解密成功,赋值明文
  96. this.isScanned = true;
  97. } else {
  98. this.exchangeCode = '';
  99. this.isScanned = false;
  100. uni.showToast({ title: res.msg || '解密失败', icon: 'none' });
  101. }
  102. })
  103. .catch(err => {
  104. uni.hideLoading();
  105. this.exchangeCode = '';
  106. this.isScanned = false;
  107. uni.showToast({ title: '解密接口异常', icon: 'none' });
  108. console.error('解密错误:', err);
  109. });
  110. },
  111. fail: (err) => {
  112. uni.showToast({ title: '扫码失败', icon: 'none' });
  113. console.error('扫码失败:', err);
  114. }
  115. });
  116. },
  117. // 点击“立即兑换”
  118. handleRedeem() {
  119. if (!this.exchangeCode) {
  120. return uni.showToast({ title: '请输入兑换码', icon: 'none' });
  121. }
  122. uni.showLoading({ title: '兑换中...' });
  123. // 如果是扫码(走解密流程后),调用正式兑换接口
  124. if (this.isScanned) {
  125. this.$Request.getT("/app/redeemCode/useRedeemCode?platform=" + this.selectedModule + '&encryptedData=' + this.encryptedCode)
  126. .then(res => {
  127. uni.hideLoading();
  128. if (res.code === 0) {
  129. uni.showToast({ title: '兑换成功', icon: 'success' });
  130. this.resetFields();
  131. } else {
  132. uni.showToast({ title: res.msg || '兑换失败', icon: 'none' });
  133. }
  134. })
  135. .catch(err => {
  136. uni.hideLoading();
  137. uni.showToast({ title: '请求出错', icon: 'none' });
  138. console.error('兑换失败:', err);
  139. });
  140. } else {
  141. // 手动输入走正常兑换
  142. this.$Request.getT("/app/redeemCode/useRedeemCode?platform=" + this.selectedModule + '&cdk=' + this.exchangeCode)
  143. .then(res => {
  144. uni.hideLoading();
  145. if (res.code === 0) {
  146. uni.showToast({ title: '兑换成功', icon: 'success' });
  147. this.resetFields();
  148. } else {
  149. uni.showToast({ title: res.msg || '兑换失败', icon: 'none' });
  150. }
  151. })
  152. .catch(err => {
  153. uni.hideLoading();
  154. uni.showToast({ title: '请求出错', icon: 'none' });
  155. console.error('兑换失败:', err);
  156. });
  157. }
  158. },
  159. // 重置表单
  160. resetFields() {
  161. this.exchangeCode = '';
  162. this.encryptedCode = '';
  163. this.isScanned = false;
  164. }
  165. },
  166. onLoad() {
  167. waitForGlobalImages().then((path) => {
  168. console.log('✅ 全局图片路径:', path)
  169. this.globalImages = path
  170. })
  171. },
  172. mounted() {
  173. }
  174. }
  175. </script>
  176. <style scoped>
  177. .title {
  178. font-size: 33rpx;
  179. font-family: PingFang SC;
  180. color: #333333;
  181. }
  182. .instruction-list {
  183. display: flex;
  184. flex-direction: column;
  185. gap: 15rpx;
  186. margin-top: 20rpx;
  187. }
  188. .instruction-item {
  189. display: flex;
  190. align-items: flex-start;
  191. }
  192. .step-number {
  193. font-size: 28rpx;
  194. color: #666;
  195. margin-right: 15rpx;
  196. }
  197. .step-content {
  198. font-size: 28rpx;
  199. color: #666;
  200. line-height: 1.5;
  201. }
  202. .notice-list {
  203. margin-top: 20rpx;
  204. list-style-type: none;
  205. padding: 0;
  206. }
  207. /* 注意事项列表项 */
  208. .notice-item {
  209. font-size: 28rpx;
  210. color: #666;
  211. line-height: 1.6;
  212. position: relative;
  213. padding-left: 30rpx;
  214. margin-bottom: 10rpx;
  215. }
  216. /* 自定义列表项前面的圆点 */
  217. .notice-item::before {
  218. content: "";
  219. position: absolute;
  220. left: 0;
  221. top: 50%;
  222. transform: translateY(-50%);
  223. width: 10rpx;
  224. height: 10rpx;
  225. background-color: #666;
  226. border-radius: 50%;
  227. }
  228. .login_btn {
  229. width: 100%;
  230. margin: 60rpx auto;
  231. text-align: center;
  232. background: #fe6b01;
  233. height: 80rpx;
  234. border-radius: 16rpx;
  235. color: #ffffff;
  236. line-height: 80rpx;
  237. }
  238. .module {
  239. width: 45%;
  240. height: 300rpx;
  241. border-radius: 16rpx;
  242. padding: 40rpx;
  243. text-align: center;
  244. border: #e5e7eb 1rpx solid;
  245. }
  246. .module:nth-child(1) {
  247. background: #fee8d9;
  248. }
  249. .module:nth-child(2) {
  250. background: #ecf5ff;
  251. }
  252. .selected {
  253. border-color: #fe6b01;
  254. }
  255. .selected2 {
  256. border-color: #409eff;
  257. }
  258. </style>