Bläddra i källkod

feat(卡券):领取

zhoumuhao 3 år sedan
förälder
incheckning
9daa5c2fa6

+ 15 - 0
api/activity.js

@@ -28,6 +28,21 @@ class activity extends request {
 
     return res.data
   }
+
+  /**
+   * 分享活动的分享码
+   * @param {*} activityId 
+   * @param {*} mobile 
+   */
+  static async createShareActivityCode(activityId,mobile) {
+    let params = {
+      activityId:activityId,
+      mobile:mobile
+      // mobile:13205528979
+    };
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/create-share-activity-code`, params)
+    return res.data
+  }
   
   static async getSessionKeyFromApi(code) {
     let params = {

+ 1 - 0
app.json

@@ -3,6 +3,7 @@
     
     "pages/activityList/activityList",
     "pages/activityInfo/activityInfo",
+    "pages/couponReceive/couponReceive",
     "pages/myCoupons/myCoupons",
     "pages/index/index",
     "pages/receiveCoupon/receiveCoupon",

+ 48 - 2
pages/activityInfo/activityInfo.js

@@ -1,19 +1,34 @@
 const { default: activity } = require("../../api/activity");
+import drawQrcode from '../../utils/weapp.qrcode.js'
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    activityId:0, //活动id
+    userMobile:'', //电话
+    codeId:'',//code唯一码
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    console.log('接受参数');
+    console.log(options);
+    let _self = this;
     if(options.id){
       this.activityInfo(options.id)
+      _self.activityId = options.id;
+    }
+    //用户手机
+    if(options.mobile) {
+      _self.userMobile = options.mobile;
+    }
+    if(_self.activityId!=0 && _self.userMobile!='') {
+      //获取code
+      _self.getCode()
     }
 
   },
@@ -66,8 +81,14 @@ Page({
   onShareAppMessage: function () {
 
   },
+
+  /**
+   * 获取活动详细信息
+   * @param {*} activityId 
+   */
    async activityInfo(activityId){
     let result = await activity.getActivityDetail(activityId);
+    console.log('获取活动详细信息');
     console.log(result)
     var objSwitch = getApp().globalData.typeSwitchObj
 
@@ -94,6 +115,31 @@ Page({
     this.setData({
       activityInfo:result
     })
-   
+  },
+
+  /**
+   * 获取分享码
+   */
+  async getCode() {
+    let _self = this;
+    let res = await activity.createShareActivityCode(_self.activityId,_self.userMobile);
+    _self.codeId = res.codeId;
+    //根据codeId 生成二维码
+
+    drawQrcode({
+      width: 200,
+      height: 200,
+      canvasId: 'myQrcode',
+      // ctx: wx.createCanvasContext('myQrcode'),
+      text: 'https://github.com/yingye',
+      // v1.0.0+版本支持在二维码上绘制图片
+      image: {
+        imageResource: '../../images/logo.png',
+        dx: 70,
+        dy: 70,
+        dWidth: 60,
+        dHeight: 60
+      }
+    })
   }
 })

+ 3 - 1
pages/activityInfo/activityInfo.wxml

@@ -8,7 +8,9 @@
   <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>
+  <!-- 生成二维码 -->
+  <!-- <image class="qrcode-img" src="/images/logo.png"> </image> -->
+  <canvas class="qrcode-img" canvas-id="myQrcode"></canvas>
   <view class="qrcode-title over-ellipsi">扫二维码 获得卡券礼包</view>
   <view class="bottom-line"></view>
   <view class="flex-row bottom-date">

+ 3 - 1
pages/activityList/activityList.js

@@ -86,10 +86,12 @@ Page({
   },
   goToShare(e){
     console.log(e)
+    let _self = this;
     wx.navigateTo({
-      url: '/pages/activityInfo/activityInfo?id='+e.currentTarget.dataset.id,
+      url: '/pages/activityInfo/activityInfo?id='+e.currentTarget.dataset.id+'&mobile='+_self.data.userMobile,
     })
   },
+  //获取手机号
   getPhoneNumber(e) {
     let _self = this;
     var encryptedData = e.detail.encryptedData;

+ 1 - 1
project.config.json

@@ -24,7 +24,7 @@
     "lazyloadPlaceholderEnable": false,
     "useMultiFrameRuntime": true,
     "useApiHook": true,
-    "useApiHostProcess": false,
+    "useApiHostProcess": true,
     "babelSetting": {
       "ignore": [],
       "disablePlugins": [],

+ 7 - 0
project.private.config.json

@@ -1,4 +1,5 @@
 {
+  "setting": {},
   "condition": {
     "plugin": {
       "list": []
@@ -16,6 +17,12 @@
           "pathName": "pages/activityInfo/activityInfo",
           "query": "id=Bg5740r78w",
           "scene": null
+        },
+        {
+          "name": "pages/couponReceive/couponReceive",
+          "pathName": "pages/couponReceive/couponReceive",
+          "query": "id=Bg5740r78w&codeId= MYR72N738b",
+          "scene": null
         }
       ]
     }

+ 1 - 1
utils/request.js

@@ -2,7 +2,7 @@ import util from './util.js'
 class request {
 
     //本地的
-     static BASE_URL = 'http://www.lx.com:81/'
+     static BASE_URL = 'http://www.zmh.com:81/'
 //   pre环境的
 //   static BASE_URL = 'https://oapi.shpr.top/'
 //   正式的