Преглед изворни кода

feat(飞码) 对接活动详情接口

xing.li пре 3 година
родитељ
комит
ca6df4c917

+ 12 - 0
api/activity.js

@@ -16,6 +16,18 @@ class activity extends request {
 
     return res.data
   }
+  /**
+   * 获取活动详情
+   * @param {*} activityId 活动id
+   */
+  static async getActivityDetail(activityId) {
+    let params = {
+      activityId:activityId
+    };
+    const res = await this.getRequest(`${this.BASE_URL}open/activity/get`, params)
+
+    return res.data
+  }
   
   static async getSessionKeyFromApi(code) {
     let params = {

+ 1 - 0
app.js

@@ -89,5 +89,6 @@ App({
   globalData: {
     userInfo: null,
     appCode:'HSAY_SHARE_COUPON',
+    typeSwitchObj : {"C":'现金券',"D":"折扣券"}
   }
 })

+ 1 - 0
app.json

@@ -5,6 +5,7 @@
     "pages/activityInfo/activityInfo",
     "pages/myCoupons/myCoupons",
     "pages/index/index",
+    "pages/receiveCoupon/receiveCoupon",
     "pages/logs/logs"
     
   ],

+ 34 - 1
pages/activityInfo/activityInfo.js

@@ -1,4 +1,4 @@
-// pages/activityInfo/activityInfo.js
+const { default: activity } = require("../../api/activity");
 Page({
 
   /**
@@ -12,6 +12,9 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    if(options.id){
+      this.activityInfo(options.id)
+    }
 
   },
 
@@ -62,5 +65,35 @@ Page({
    */
   onShareAppMessage: function () {
 
+  },
+   async activityInfo(activityId){
+    let result = await activity.getActivityDetail(activityId);
+    console.log(result)
+    var objSwitch = getApp().globalData.typeSwitchObj
+
+      var couponTypeAndNumObj = {};
+      var couponList = result.activityCouponList;
+      for (let j = 0; j < couponList.length; j++) {
+        var couponNum = couponList[j]['num'] ? couponList[j]['num'] : 1;
+
+        var value = couponList[j]['coupon']['type'];
+        var showText = objSwitch[couponList[j]['coupon']['type']];
+        
+        var nowNume = 0;
+        if (couponTypeAndNumObj[value]) {
+          nowNume = couponTypeAndNumObj[value]['num'];
+          console.log(nowNume)
+        }
+        couponTypeAndNumObj[value] = {
+          "typeText": showText,
+          "num": couponNum + nowNume
+        }
+    
+      }
+      result.couponTypeAndNumObj = couponTypeAndNumObj
+    this.setData({
+      activityInfo:result
+    })
+   
   }
 })

+ 6 - 4
pages/activityInfo/activityInfo.wxml

@@ -4,14 +4,16 @@
     <image src="/images/logo.png" class="top-image"></image>
   </view>
   <view class="bottom flex-column">
-  <view class="title over-ellipsi">长阳路外卖店</view>
-  <view class="coupon-info over-ellipsi">含 折扣券(3)| 现金券(1)</view>
+  <view class="title over-ellipsi">{{activityInfo.name}}</view>
+  <view class="coupon-info over-ellipsi">含 
+  <span wx:for="{{activityInfo.couponTypeAndNumObj}}">{{item.typeText}} ({{item.num}}) </span>  
+  </view>
   <image class="qrcode-img" src="/images/logo.png"> </image>
   <view class="qrcode-title over-ellipsi">扫二维码 获得卡券礼包</view>
   <view class="bottom-line"></view>
   <view class="flex-row bottom-date">
-  <view>有效期</view>
-  <view>2021.09.07-2021.12.15</view>
+  <view>有效期:</view>
+  <view style="font-size: 10px;">{{activityInfo.beginTimestamp}} 至 {{activityInfo.endTimestamp}}</view>
   </view>
   </view>
 </view>

+ 44 - 5
pages/activityList/activityList.js

@@ -12,7 +12,8 @@ Page({
      list: [], //卡券列表
      page:1,
      pageNum:10,
-     count:0
+     count:0,
+   
 
   },
 
@@ -83,9 +84,10 @@ Page({
   onShareAppMessage: function () {
 
   },
-  goToShare(){
+  goToShare(e){
+    console.log(e)
     wx.navigateTo({
-      url: '/pages/activityInfo/activityInfo',
+      url: '/pages/activityInfo/activityInfo?id='+e.currentTarget.dataset.id,
     })
   },
   getPhoneNumber(e) {
@@ -98,6 +100,7 @@ Page({
     //获取手机号
     getApp().doDecodePhone(encryptedData, iv, function () {
       let userMobile = activity.getMobileCache();
+      console.log(userMobile)
       if (userMobile.length !== 0) {
         _self.setData({
           userMobile: userMobile,
@@ -109,10 +112,12 @@ Page({
 
   getList: async function() {
     var result = await activity.getActivityList(this.data.page,this.data.pageNum,2);
+
+    var list = this.handleCouponList(result.list);
     if(this.data.page != 1){
-      var nowResult = this.data.list.concat(result.list)
+      var nowResult = this.data.list.concat(list)
     }else{
-      var nowResult = result.list
+      var nowResult = list
     }
     
     this.setData({
@@ -121,4 +126,38 @@ Page({
       page:result.page
     })
   },
+
+  handleCouponList(list) {
+    if (list.length === 0) {
+      return list;
+    }
+
+    var objSwitch = getApp().globalData.typeSwitchObj
+    for (let i = 0; i < list.length; i++) {
+
+      var couponList = list[i].activityCouponList;
+
+      var couponTypeAndNumObj = {};
+      for (let j = 0; j < couponList.length; j++) {
+        var couponNum = couponList[j]['num'] ? couponList[j]['num'] : 1;
+
+        var value = couponList[j]['coupon']['type'];
+        var showText = objSwitch[couponList[j]['coupon']['type']];
+        
+        var nowNume = 0;
+        if (couponTypeAndNumObj[value]) {
+          nowNume = couponTypeAndNumObj[value]['num'];
+          console.log(nowNume)
+        }
+        couponTypeAndNumObj[value] = {
+          "typeText": showText,
+          "num": couponNum + nowNume
+        }
+    
+      }
+      list[i].couponTypeAndNum = couponTypeAndNumObj
+    }
+    console.log(list);
+    return list;
+  },
 })

+ 8 - 10
pages/activityList/activityList.wxml

@@ -4,15 +4,13 @@
       <image class="top-left" src="{{item.fullCoverImg}}"></image>
       <view class="top-right flex-column">
         <view class="top-right-top">{{item.name}}</view>
-        <view class="top-right-bottom flex-row">
-          <view class="top-right-bottom-view  flex-row">
-            <image class="trbv-img" src="/images/xjq.png"></image>
-            <view class="trbv-name">折扣券(3)</view>
-          </view>
-          <view class="top-right-bottom-view  flex-row">
-            <image class="trbv-img" src="/images/zkq.png"></image>
-            <view class="trbv-name">折扣券(3)</view>
+        <view class="top-right-bottom flex-row" >
+          <view class="top-right-bottom-view  flex-row" wx:for="{{item.couponTypeAndNum}}" wx:for-item="itemCoupon" wx:for-index="indexCoupon" wx:key="unique">
+            <image class="trbv-img" src="/images/xjq.png" wx:if="{{indexCoupon=='C'}}"></image>
+            <image class="trbv-img" src="/images/zkq.png" wx:if="{{indexCoupon=='D'}}"></image>
+            <view class="trbv-name">{{itemCoupon.typeText}} ({{itemCoupon.num}}) </view>
           </view>
+         
         </view>
         <view></view>
       </view>
@@ -21,8 +19,8 @@
       <view class="middle-line"></view>
     </view>
     <view class="bottom flex-row">
-      <view class="bottom-left">{{item.beginTimestamp}}至{{item.endTimestamp}}</view>
-      <view class="bottom-right" bindtap="goToShare" wx:if="{{userMobile.length>0}}">立即分享</view>
+      <view class="bottom-left">{{item.beginTimestamp}}  {{item.endTimestamp}}</view>
+      <view class="bottom-right" bindtap="goToShare" wx:if="{{userMobile.length>0}}" data-id="{{item.activityId}}">立即分享</view>
       <button class="bottom-right" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" wx:else>立即分享</button>
     </view>
   </view>

+ 18 - 16
pages/activityList/activityList.wxss

@@ -84,37 +84,39 @@ Page {
   height: 1px;
   border-bottom: 1px dashed #BF2637;
 }
-.middle{
+
+.middle {
   margin: 0 auto;
   margin-top: 9px;
 }
-.bottom{
+
+.bottom {
   width: 100%;
   height: 20px;
   margin-top: 9px;
-  justify-content: space-between!important;
+  justify-content: space-between !important;
 }
-.bottom-left{
-  width: 200px;
-height: 20px;
-line-height: 20px;
-font-size: 9.5px;
-font-weight: 400;
-color: #BF2637;
-margin-left: 22px;
+
+.bottom-left {
+  width: 205px;
+  height: 20px;
+  line-height: 20px;
+  font-size: 9.5px;
+  font-weight: 400;
+  color: #BF2637;
+  margin-left: 22px;
 }
 
-.bottom-right{
-  width: 80px!important;
+.bottom-right {
+  width: 80px !important;
   height: 20px;
   background-color: #BF2637;
   color: #fff;
-  font-size:10px ;
+  font-size: 10px;
   text-align: center;
   line-height: 20px;
   border-radius: 10px;
-  margin-right: 25px!important;
+  margin-right: 25px !important;
   padding: 0 0;
 
 }
-

+ 66 - 0
pages/receiveCoupon/receiveCoupon.js

@@ -0,0 +1,66 @@
+// pages/receiveCoupon/receiveCoupon.js
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 3 - 0
pages/receiveCoupon/receiveCoupon.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 2 - 0
pages/receiveCoupon/receiveCoupon.wxml

@@ -0,0 +1,2 @@
+<!--pages/receiveCoupon/receiveCoupon.wxml-->
+<text>pages/receiveCoupon/receiveCoupon.wxml</text>

+ 1 - 0
pages/receiveCoupon/receiveCoupon.wxss

@@ -0,0 +1 @@
+/* pages/receiveCoupon/receiveCoupon.wxss */

+ 23 - 0
project.private.config.json

@@ -0,0 +1,23 @@
+{
+  "condition": {
+    "plugin": {
+      "list": []
+    },
+    "game": {
+      "list": []
+    },
+    "gamePlugin": {
+      "list": []
+    },
+    "miniprogram": {
+      "list": [
+        {
+          "name": "pages/activityInfo/activityInfo",
+          "pathName": "pages/activityInfo/activityInfo",
+          "query": "id=Bg5740r78w",
+          "scene": null
+        }
+      ]
+    }
+  }
+}