绿满眶商城微信小程序-uniapp
peng
9 天以前 00830f0d160943e29999875d13b19edacbf198c6
pages/order/claim-coupon/claim-coupon.vue
@@ -2,8 +2,8 @@
   <view class="container">
      <!-- 顶部标题 -->
      <view class="header">
         <text class="title">优惠券领取</text>
         <text class="subtitle">领取您的专属优惠券</text>
         <text class="title">商品兑换券领取</text>
         <text class="subtitle">领取您的专属商品兑换券</text>
      </view>
      
      <!-- 单个优惠券展示 -->
@@ -104,15 +104,42 @@
         if (options.id) {
            this.cardId = options.id
            this.loadCouponInfo(options.id);
         } else {
         }else if(options.q) {
               // 双重解码:微信对URL进行了两次编码
               const decodedUrl = decodeURIComponent(decodeURIComponent(options.q));
               console.log('原始URL:', decodedUrl);
               // 解析URL中的查询参数
               const params = this.parseUrlParams(decodedUrl);
               this.cardId =  params.id;
               this.loadCouponInfo(this.cardId);
            }
          else {
            // 如果没有传递ID,显示空状态
            uni.showToast({
               title: '缺少优惠券ID参数',
               title: '缺少兑换券ID参数',
               icon: 'none'
            });
         }
      },
      methods: {
         // 解析URL参数
         parseUrlParams(url) {
            const params = {};
            // 处理可能存在的hash(如果有的话)
            const cleanUrl = url.split('#')[0];
            const queryStr = cleanUrl.split('?')[1] || '';
            queryStr.split('&').forEach(pair => {
               const [key, value] = pair.split('=');
               if (key) {
                  // 如果值存在,则解码,否则设为空字符串
                  params[key] = value ? decodeURIComponent(value) : '';
               }
            });
            return params;
         },
         // 加载指定ID的优惠券信息
         async loadCouponInfo(id) {
            if (this.loading) return;
@@ -125,12 +152,12 @@
               if (res.data.code===200) {
                  this.couponInfo = res.data.data;
               } else {
                  throw new Error(res.message || '获取优惠券失败');
                  throw new Error(res.message || '获取兑换券失败');
               }
            } catch (err) {
               console.error('获取优惠券信息失败:', err);
               console.error('获取兑换券信息失败:', err);
               uni.showToast({
                  title: err.message || '获取优惠券失败',
                  title: err.message || '获取兑换券失败',
                  icon: 'none'
               });
            } finally {
@@ -142,7 +169,7 @@
         async claimCoupon() {
            if (!this.couponInfo || this.couponInfo.claimStatus === 'CLAIM') {
               uni.showToast({
                  title: '该优惠券已领取',
                  title: '该兑换券已领取',
                  icon: 'none'
               });
               return;
@@ -174,7 +201,7 @@
               }
            } catch (err) {
               uni.hideLoading();
               console.error('领取优惠券失败:', err);
               console.error('领取兑换券失败:', err);
               uni.showToast({
                  title: err.message || '领取失败',
                  icon: 'none'