瀏覽代碼

feat(卡券):跳转沪上阿姨小程序

zhoumuhao 3 年之前
父節點
當前提交
7e3b334c3d

+ 45 - 1
api/activity.js

@@ -2,7 +2,12 @@ import request from '../utils/request.js'
 
 class activity extends request {
 
-
+/**
+ * 获取活动列表
+ * @param {*} nextPage 
+ * @param {*} pageSize 
+ * @param {*} status 
+ */
   static async getActivityList(nextPage,pageSize,status) {
     let params = {
       nextPage:nextPage,
@@ -16,6 +21,16 @@ class activity extends request {
 
     return res.data
   }
+
+  static async isShareByMobile(mobile) {
+    let params = {
+      mobile:mobile
+    };
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/is-share-by-mobile`, params)
+
+    return res.data
+  }
+
   /**
    * 获取活动详情
    * @param {*} activityId 活动id
@@ -58,6 +73,7 @@ class activity extends request {
     let params = {
       activityId:activityId,
       mobile:mobile
+      // activityId:'Bg5740r78w',
       // mobile:13205528979
     };
     const res = await this.postRequest(`${this.BASE_URL}open/activity/create-share-activity-code`, params)
@@ -72,6 +88,34 @@ class activity extends request {
     const res = await this.postRequest(`${this.BASE_URL}open/activity/get-share-activity-code`, params)
     return res.data
   }
+
+  /**
+   * 获取我的券列表
+   * @param {*} nextPage 
+   * @param {*} pageSize 
+   * @param {*} mobile 
+   */
+  static async getSnListMember(nextPage,pageSize,mobile) {
+    let params = {
+      nextPage:nextPage,
+      pageSize:pageSize,
+      condition:{
+        mobile:mobile
+      }
+    };
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/sn-list-member`, params)
+    return res.data
+  }
+
+  //绑定券与codeId之间的关系
+  static async bindShareCode(orderSn,codeId) {
+    let params = {
+      orderSn:orderSn,
+      codeId:codeId
+    };
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/bind-share-code`, params)
+    return res.data
+  }
   
   static async getSessionKeyFromApi(code) {
     let params = {

+ 13 - 0
app.js

@@ -86,6 +86,19 @@ App({
       }
     });
   },
+
+  showToast(title,icon='success',time=2000,call='') {
+    wx.showToast({
+      title: title,
+      icon: icon,
+      duration: time,
+      success:function(){
+        if(typeof(call)=='function') {
+          call();
+        }
+      }
+    })
+  },
   globalData: {
     userInfo: null,
     appCode:'HSAY_SHARE_COUPON',

+ 13 - 9
pages/activityInfo/activityInfo.js

@@ -20,13 +20,17 @@ Page({
     let _self = this;
     if(options.id){
       this.activityInfo(options.id)
-      _self.activityId = options.id;
+      _self.setData({
+        activityId:options.id,
+      })
     }
     //用户手机
     if(options.mobile) {
-      _self.userMobile = options.mobile;
+      _self.setData({
+        userMobile:options.mobile
+      })
     }
-    if(_self.activityId!=0 && _self.userMobile!='') {
+    if(_self.data.activityId!=0 && _self.data.userMobile!='') {
       //获取code
       _self.getCode()
     }
@@ -122,17 +126,17 @@ Page({
    */
   async getCode() {
     let _self = this;
-    let res = await activity.createShareActivityCode(_self.activityId,_self.userMobile);
-    _self.codeId = res.codeId;
-    //根据codeId 生成二维码
+    let res = await activity.createShareActivityCode(_self.data.activityId,_self.data.userMobile);
+    _self.setData({
+      codeId:res.codeId,
+    })
 
+    //根据codeId 生成二维码
     drawQrcode({
       width: 200,
       height: 200,
       canvasId: 'myQrcode',
-      // ctx: wx.createCanvasContext('myQrcode'),
-      text: 'https://github.com/yingye',
-      // v1.0.0+版本支持在二维码上绘制图片
+      text: 'https://oapi.shpr.top?id='+_self.data.codeId,
       image: {
         imageResource: '../../images/logo.png',
         dx: 70,

+ 22 - 3
pages/activityList/activityList.js

@@ -21,9 +21,10 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function () {
-    this.getList()
+    let _self = this;
+    //获取列表
+    _self.getList();
   },
-
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
@@ -108,12 +109,16 @@ Page({
         _self.setData({
           userMobile: userMobile,
         })
+        //判断该手机号在不在分享名单里
+        _self.isShareByMobile();
       }
     
     });
   },
 
+  //获取活动列表
   getList: async function() {
+    let _self = this;
     var result = await activity.getActivityList(this.data.page,this.data.pageNum,2);
 
     var list = this.handleCouponList(result.list);
@@ -122,7 +127,11 @@ Page({
     }else{
       var nowResult = list
     }
-    
+    //判断该电话是否存在 如果不存在 取第一条
+    if(_self.data.userMobile=='') {
+      nowResult = nowResult.length>0?[nowResult[0]]:nowResult;
+    }
+   
     this.setData({
       list:nowResult,
       count:result.count,
@@ -130,6 +139,16 @@ Page({
     })
   },
 
+  async isShareByMobile(){
+    let _self = this;
+    var result = await activity.isShareByMobile(_self.data.userMobile);
+    if(result.isShare==1){
+      _self.setData({
+        page:1
+      })
+      _self.getList();
+    }
+  },
   handleCouponList(list) {
     if (list.length === 0) {
       return list;

+ 79 - 1
pages/myCoupons/myCoupons.js

@@ -1,18 +1,69 @@
 // pages/myCoupons/myCoupons.js
+const { default: activity } = require("../../api/activity");
+const util = require('../../utils/util.js');
+const app = getApp();
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    couponList:[], //我的卡券列表
+    nextPage:1,
+    pageSize:12,
+    mobile:'', //我的手机号
+    totalPage:1, //总页码
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    //获取我的卡券列表   api/supers/coupon/sn-list-member
+    let _self = this;
+    if(options.mobile) {
+      _self.setData({
+        mobile:options.mobile
+      })
+    }
+    _self.getSnListMember();  
+  },
+
+  //获取我的券列表
+  async getSnListMember(step='init') {
+    let _self = this;
+    let nextPage = _self.data.nextPage;
+    let pageSize = _self.data.pageSize;
+    let mobile = _self.data.mobile;
+    let res =await activity.getSnListMember(nextPage,pageSize,mobile);
+    let totalPage =Math.ceil(res.count/pageSize);
+    _self.setData({
+      totalPage:totalPage
+    })
+    let list =_self.handleList(res.list);
+    if(step=='init') {
+      _self.setData({
+        couponList:list
+      })
+    } else if(step=='pull') {
+      _self.setData({
+        couponList:_self.data.couponList.concat(list),
+      })
+    }
+
+  },
 
+  /**
+   * 处理数据
+   */
+  handleList(list) {
+    list.map((item,key)=>{
+      item.beignTime = util.format(item.beginTimestamp*1000);
+      item.endTime = util.format(item.endTimestamp*1000);
+      item.coupon.discount = item.coupon.type.value=='D'?item.coupon.discount/10:item.coupon.discount;
+      item.isFree = item.coupon.type.value=='D'&& item.coupon.discount==0?true:false;
+    })
+    return list;
   },
 
   /**
@@ -54,7 +105,34 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
+    let _self = this;
+    let nextPage = _self.data.nextPage;
+    let totalPage = _self.data.totalPage;
+    if(nextPage>=totalPage) {
+      app.showToast ('亲,到底了!');
+      return;
+    }
+    _self.setData({
+      nextPage:nextPage+1
+    })
+    _self.getSnListMember('pull')
+  },
 
+  /**
+   * 使用券跳转小程序
+   */
+  goUseCoupon() {
+    wx.navigateToMiniProgram({
+      appId: 'wxd92a2d29f8022f40',
+      path: 'pages/index/index',
+      extraData: {
+        foo: 'bar'
+      },
+      envVersion: 'develop',
+      success(res) {
+        // 打开成功
+      }
+    })
   },
 
   /**

+ 15 - 34
pages/myCoupons/myCoupons.wxml

@@ -1,44 +1,25 @@
 <!--我的卡券-->
 <view class="coupon_outer">
-  <view class="coupon_li">
-    <view class="coupon_type">折</view>
+  <view class="coupon_li" wx:for="{{couponList}}" wx:for-index="index" wx:for-item="item">
+  <block wx:if="{{item.isFree==false}}">
+    <view class="coupon_type" wx:if="{{item.coupon.type.value=='D'}}">折</view>
+    <view class="coupon_type" wx:if="{{item.coupon.type.value=='C'}}">元</view>
     <view class="coupon-title">
-      <view class="coupon-price">5</view>
-      <view class="coupon-title-type">大福系列</view>
+      <view class="coupon-price">{{item.coupon.discount?item.coupon.discount:'0'}}</view>
+      <!-- <view class="coupon-title-type">大福系列</view> -->
     </view>
-    <view class="coupon-li-line"></view>
-    <view class="coupon-detail">
-      <view class="coupon-detail-title">椰子新品5元尝鲜券</view>
-      <view class="coupon-detail-date">2021.09.07-2021.12.31</view>
-    </view>
-    <view class="use-button">去使用</view>
-  </view>
-
-  <view class="coupon_li">
-    <view class="coupon_type">折</view>
-    <view class="coupon-title">
-      <view class="coupon-price">5</view>
-      <view class="coupon-title-type">大福系列</view>
-    </view>
-    <view class="coupon-li-line"></view>
-    <view class="coupon-detail">
-      <view class="coupon-detail-title">椰子新品5元尝鲜券</view>
-      <view class="coupon-detail-date">2021.09.07-2021.12.31</view>
-    </view>
-    <view class="use-button">去使用</view>
-  </view>
-
-  <view class="coupon_li">
-    <view class="coupon_type">折</view>
-    <view class="coupon-title">
-      <view class="coupon-price">5</view>
-      <view class="coupon-title-type">大福系列</view>
+  </block>
+  <block wx:else>
+    <view class="coupon-title-free">
+      <view>免</view>
+      <view>费</view>
     </view>
+  </block>
     <view class="coupon-li-line"></view>
     <view class="coupon-detail">
-      <view class="coupon-detail-title">椰子新品5元尝鲜券</view>
-      <view class="coupon-detail-date">2021.09.07-2021.12.31</view>
+      <view class="coupon-detail-title">{{item.title}}</view>
+      <view class="coupon-detail-date">{{item.beignTime}}-{{item.endTime}}</view>
     </view>
-    <view class="use-button">去使用</view>
+    <view class="use-button" bindtap="goUseCoupon">去使用</view>
   </view>
 </view>

+ 18 - 4
pages/myCoupons/myCoupons.wxss

@@ -27,14 +27,14 @@
   flex-direction: column;
   margin-left: 30rpx;
   width: 144rpx;
-  padding-top: 18rpx;
+  padding-top: 42rpx;
 }
 .coupon-title>view {
   text-align: center;
 }
 .coupon-price {
-  font-size: 66rpx;
-  font-weight: 700;
+  font-size: 55rpx;
+  font-weight: 600;
 }
 .coupon-title-type {
   font-size: 22rpx;
@@ -69,9 +69,23 @@
   border-radius: 40rpx;
   font-size: 24rpx;
   margin: auto 0;
-  margin-left: 30rpx;
+  margin-left: 53rpx;
   cursor: pointer;
 }
+
 .coupon_outer > .coupon_li {
   margin-bottom: 20rpx;
+}
+
+.coupon-title-free {
+  display: flex;
+  margin-left: 30rpx;
+  width: 144rpx;
+  padding-top: 18rpx;
+}
+.coupon-title-free>view {
+  line-height: 123rpx;
+} 
+.coupon-title-free>view:first-child {
+  margin-left: 30rpx;
 }

+ 20 - 1
utils/util.js

@@ -72,8 +72,27 @@ function getUnixTime(dateStr){
   return time_str.substr(0, 10);
 }
 
+function format(shijianchuo,type=1)
+{
+//shijianchuo是整数,否则要parseInt转换
+var time = new Date(shijianchuo);
+var y = time.getFullYear();
+var m = time.getMonth()+1;
+var d = time.getDate();
+var h = time.getHours();
+var mm = time.getMinutes();
+var s = time.getSeconds();
+if(type==1) {
+  return y+'.'+add0(m)+'.'+add0(d)
+}
+// return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
+}
+function add0(m){return m<10?'0'+m:m }
+
 module.exports = {
   formatTime,
   sha1,
-  getUnixTime
+  getUnixTime,
+  format,
+  add0
 }