Bläddra i källkod

新增拼团或参团成功后逻辑

Limengbo 6 år sedan
förälder
incheckning
bae9e236ad

+ 11 - 5
component/group/group.js

@@ -33,12 +33,18 @@ export const groupInit = (that) => {
     })
   }();
   //点击跳转
-  that.more = function () {
+  that.more = function ({currentTarget}) {
+    let type;
+    let title;
+    if(currentTarget.dataset.type == 'group') {
+      type = true
+      title = '限量优惠团购'
+    }else {
+      type = false
+      title = '全部课'
+    }
     wx.navigateTo({
-      url: '/pages/groupPage/discount-group/discount-group'
-    })
-    wx.setNavigationBarTitle({
-      title: '限量优惠团购'
+      url: `/pages/groupPage/discount-group/discount-group?type=${type}&title=${title}`
     })
   }
   //发起团购

+ 2 - 2
component/group/group.wxml

@@ -6,7 +6,7 @@
           <view class="title">
             <image class="ren" src="../../static/groupImg/tuandui@2x.png"></image>
             <text class="left">限量优惠团购<text class="quota">(仅有1000份,售完为止)</text></text>
-            <text class="right" bindtap="more">更多 ></text>
+            <text class="right" bindtap="more" data-type="group">更多 ></text>
           </view>
           <view class="group-box">
             <block wx:for="{{groupData.recommendList}}" wx:key="{{index}}">
@@ -27,7 +27,7 @@
           <view class="title">
             <image class="ren" src="../../static/groupImg/Shape3.png" style="width: 30rpx; height: 38rpx;"></image>
             <text class="left">全部课程<text class="quota" style="margin-left: 20rpx;">拼团大不同</text></text>
-            <text class="right">更多 ></text>
+            <text class="right" bindtap="more" data-type="course">更多 ></text>
           </view>
           <view class="group-box"> 
             <block wx:for="{{groupData.bookList}}" wx:key="{{index}}">

+ 3 - 0
component/popup/popup.js

@@ -41,6 +41,9 @@ Component({
       this.setData({
         closeFlag: !this.data.closeFlag
       })
+    },
+    launchGroup: function () {
+      this.triggerEvent('Group', {})
     }
   }
 })

+ 1 - 1
component/popup/popup.wxml

@@ -19,7 +19,7 @@
                 <text style="color: {{item.color}};">{{item.text}}</text>
             </block>
         </view>
-        <view class="send-btn">
+        <view class="send-btn" bindtap="launchGroup">
             <image src="../../static/groupImg/Invitation.png"></image>
             <text>发起团购</text>
         </view>

+ 30 - 5
pages/groupPage/discount-group/discount-group.js

@@ -1,23 +1,48 @@
 // pages/groupPage//discount-group/discount-group.js
+import httpRequestApi from '../../../utils/APIClient';
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    recommendList: [],
+    bookList: []
   },
 
-//点击跳转到团购详情
-groupDetails:function () {
+  //点击跳转到团购详情
+  groupDetails:function () {
 
-},
+  },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-
+    wx.setNavigationBarTitle({
+      title: options.title
+    })
+    if(options.type == 'true') {
+      //优惠内容
+      httpRequestApi.getGroupList().success( (res) => {
+        console.log('推荐团购',res.data.data)
+        this.setData({
+          recommendList: res.data.data
+        })
+      }).fail((error) => {
+        console.log('错误',error)
+      })
+    }else {
+      //全部课
+      httpRequestApi.getAllBooks(1, 10).success((res) => {
+        console.log('全部课',res.data.data.list)
+        this.setData({
+          bookList: res.data.data.list
+        })
+      }).fail((error) => {
+        console.log('错误',error)
+      })
+    }
   },
 
   /**

+ 18 - 73
pages/groupPage/discount-group/discount-group.wxml

@@ -4,80 +4,25 @@
       <view class="group-container">
         <view class="less-group">
           <view class="group-box">
-            <view class="group-item" bindtap="groupDetails">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>   
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>                  
-          </view>
+            <block wx:for="{{recommendList}}" wx:key="{{index}}">
+              <view class="group-item" bindtap="groupDetail" data-id="{{item.id}}" data-productId="{{item.productId}}" data-groupId="{{item.groupId}}">
+                <image class="item-img" src="{{item.iconImg}}"></image>
+                <view>拼团价 <text>¥{{item.price / 100}}</text></view>
+                <view>原价 <text style="text-decoration: line-through;">¥{{item.originPrice / 100}}</text></view>
+                <view class="group-num">
+                  <image src="../../../static/groupImg/Rectangle_30.png" ></image>
+                  <text>{{item.headcount}}人团</text>
+                </view>
+              </view>
+            </block> 
+            <block wx:for="{{bookList}}" wx:key="{{index}}">
+              <view class="group-item">
+                <image class="item-img" src="{{item.iconImg}}"></image>
+                <view id="grade">一年级</view>
+              </view>    
+            </block>                
+          </view>                        
         </view>
-<view class="less-group">
-          <view class="group-box">
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>   
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>                  
-          </view>
         </view>
-<view class="less-group">
-          <view class="group-box">
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>   
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>                  
-          </view>
-        </view>   
-<view class="less-group">
-          <view class="group-box">
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>   
-            <view class="group-item">
-              <image src="" style="background: red;"></image>
-              <view>拼团价 <text>¥1</text></view>
-              <view>原价 <text style="text-decoration: line-through;">¥99</text></view>
-            </view>                  
-          </view>
-        </view>                           
-      </view>
     </scroll-view>
   </view>

+ 23 - 0
pages/groupPage/discount-group/discount-group.wxss

@@ -35,6 +35,7 @@ scroll-view {
 .group-item {
     display: flex;
     flex-direction: column;
+    position: relative;
 }
 
 .group-item image {
@@ -81,4 +82,26 @@ scroll-view {
 
 .Collage-bottom text {
     vertical-align: middle;
+}
+
+.group-item .group-num {
+    position: absolute;
+    left: 0;
+    top: 14rpx;
+    width: 100rpx;
+    height: 40rpx;
+}
+
+.group-item .group-num image {
+    width: 100%;
+    height: 100%;
+}
+
+.group-item .group-num text {
+    color: #fff;
+    position: absolute;
+    left: 6rpx;
+    top: 4rpx;
+    z-index: 3;
+    font-size: 24rpx;
 }

+ 131 - 46
pages/groupPage/group-details/group-details.js

@@ -17,7 +17,12 @@ Page({
     timeList: [],
     productId: '',
     groupId: '',
-    orderId: ''
+    orderId: '',
+    typeOf:'',
+    title: '',
+    headTextOne: '',
+    headTextTwo: '',
+    content: [],
   },
   //跳转到年级
   gradeDetails: function () {
@@ -39,9 +44,6 @@ Page({
       groupId
     }).success( (res) =>{
       console.log('发起团购',res);
-      // wx.navigateTo({
-      //   url: `/pages/groupPage/collage-details/collage-details`
-      // })
       if(res.data.message) {
         wx.showModal({
           title: '提示',
@@ -56,8 +58,11 @@ Page({
         })
         return false;
       }
-      //掉起支付
-      this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrderDetail.orderId);
+      if(res.data.data.groupPurchaseOrder.groupType === 'BASE') {
+        //掉起支付
+        this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrderDetail.orderId);
+      }
+
     }).fail( (error) => {
       
     })
@@ -81,9 +86,9 @@ Page({
           }
         })
         return false;
-      }
+      }  
       //掉起支付
-      this.prePayMap(res.data.data.prePayMap, res.data.data.groupPurchaseOrderDetail.orderId);
+      //this.prePayMap(res.data.data.prePayMap, res.data.data.orderId);
     }).fail( (error) => {
       
     })
@@ -108,25 +113,14 @@ Page({
             content: '支付成功',
             success (res) {
               if (res.confirm) {
-                that.popup.close();
-                // setTimeout(() => {
-                //   wx.navigateTo({
-                //     url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
-                //   })
-                //   wx.setNavigationBarTitle({
-                //     title: '拼团详情'
-                //   })
-                // }, 1000)
+                //获取拼团信息
+                this.jionSuccess(this.data.orderId);
+                this.groupSuccess(orderId);
+
               } else if (res.cancel) {
-                that.popup.close();
-                setTimeout(() => {
-                  wx.navigateTo({
-                    url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
-                  })
-                  wx.setNavigationBarTitle({
-                    title: '拼团详情'
-                  })
-                }, 1000)                
+                //获取拼团信息
+                this.jionSuccess(this.data.orderId);                
+                this.groupSuccess(orderId);
               }
             }
           })
@@ -141,6 +135,115 @@ Page({
   collage: function () {
 
   },
+  //拼团详情
+  jionSuccess: function (orderId) {
+    httpRequestApi.getMygroupInfo(orderId).success( res => {
+      console.log('拼团详情', res.data.data);
+      const surplusNum = res.data.data.groupPurchaseOrder.headcount - res.data.data.groupPurchaseOrder.joinCount;
+      for(var i = 0; i < surplusNum; i++) {
+        this.data.surplusList.push(1);
+      }
+      console.log(res.data.data.groupPurchaseOrder.closeTimed - res.data.data.groupPurchaseOrder.gmtCreated)
+      //时间转换
+      const timeList = util.formatTime(res.data.data.groupPurchaseOrder.closeTimed - res.data.data.groupPurchaseOrder.gmtCreated);
+      this.setData({
+        surplusNum,
+        joinUserList: res.data.data.joinUserList,
+        surplusList: this.data.surplusList,
+        timeList,
+      })
+    }).fail( error => {
+      console.log('错误', error)
+    })    
+  },
+
+  //拼团是否成功并弹窗
+  groupSuccess: function (orderId) {
+    httpRequestApi.groupSuccess(orderId).success( res => {
+      console.log('团购是否成功',res.data.data)
+      const status = res.data.data.status;
+      const uid = res.data.data.uid;
+      if(status == 'successed') {
+
+        if(wx.getStorageSync(uid) == uid) {
+          this.setData({
+            typeOf: 'success',
+            title: '恭喜 !',
+            headTextOne: '您发起的团购拼团成功',
+            content: [
+              {
+                  text: "领袖体质魅力无穷!",
+                  color: "#000"
+              },
+              {
+                  text: " 您可以继续发起新的团购,",
+                  color: "#000"
+              },
+              {
+                text: " 不再需要支付本课程费用,拼团成功,",
+                color: "#FF9B00"
+              },                          
+              {
+                  text: " 您将得到xxx元奖励。",
+                  color: "#FF0000"
+              }
+            ],
+          })
+        }else {
+          this.setData({
+            typeOf: 'success',
+            title: '拼团成功 ! ',
+            headTextOne: '您参与的团购拼团成功',
+            headTextTwo: '订单号:12344',
+            content: [
+              {
+                  text: "感谢团长的分享",
+                  color: "#000"
+              },
+              {
+                  text: " 您也可以发起新的团购分享给需要的朋友们,",
+                  color: "#000"
+              },
+              {
+                  text: "作为新的发起人,您无需在支付本课程费用;",
+                  color: "#FF0000"
+              },
+              {
+                text: "团购成功,您将得到xxx元奖励。",
+                color: "#FF0000"
+              }                          
+            ],
+          })
+        }
+      }else {
+        setTimeout(() => {
+          wx.navigateTo({
+            url: `/pages/groupPage/collage-details/collage-details?orderId=${orderId}`
+          })
+          wx.setNavigationBarTitle({
+            title: '拼团详情'
+          })
+        }, 1000)
+      }
+    }).fail( error => {
+      console.log('错误', eroor)
+    })    
+  },
+  //再次发起团
+  group: function () {
+    wx.showModal({
+      title: '提示',
+      content: '再次发起团',
+      success (res) {
+        if (res.confirm) {
+          console.log('用户点击确定')
+        } else if (res.cancel) {
+          console.log('用户点击取消')
+        }
+      }
+    })
+  },
+
   /**
    * 生命周期函数--监听页面加载
    */
@@ -181,26 +284,8 @@ Page({
     }).fail( (error) => {
 
     })
-    //拼团详情
-    httpRequestApi.getMygroupInfo(orderId).success( res => {
-      console.log('支付详情', res.data.data);
-      const surplusNum = res.data.data.groupPurchaseOrder.headcount - res.data.data.groupPurchaseOrder.joinCount;
-      for(var i = 0; i < surplusNum; i++) {
-        this.data.surplusList.push(1);
-      }
-      console.log(res.data.data.groupPurchaseOrder.closeTimed - res.data.data.groupPurchaseOrder.gmtCreated)
-      //时间转换
-      const timeList = util.formatTime(res.data.data.groupPurchaseOrder.closeTimed - res.data.data.groupPurchaseOrder.gmtCreated);
-      this.setData({
-        surplusNum,
-        joinUserList: res.data.data.joinUserList,
-        surplusList: this.data.surplusList,
-        timeList,
-      })
-    }).fail( error => {
-      console.log('错误', error)
-    })
-    
+    //获取拼团信息
+    this.jionSuccess(orderId);
   },
 
   /**

+ 6 - 1
pages/groupPage/group-details/group-details.json

@@ -1 +1,6 @@
-{}
+{
+    "component": true,
+    "usingComponents": {
+        "popup": "/component/popup/popup"
+    }  
+}

+ 12 - 2
pages/groupPage/group-details/group-details.wxml

@@ -14,7 +14,8 @@
             </block>                      
         </view>
         <view class="shengyu">
-            <view class="shengyu-num">仅剩<text>{{surplusNum}}</text>个名额就拼团成功了</view>
+            <view class="shengyu-num" hidden="{{surplusNum !== '0'}}">仅剩<text>{{surplusNum}}</text>个名额就拼团成功了</view>
+            <view class="shengyu-num" hidden="{{surplusNum === '0'}}">拼团成功</view>
             <view class="shengyu-time">
                 剩余时间:
                 <view class="time">
@@ -65,4 +66,13 @@
             <text>参团</text>
         </view>
     </view>
-</view>
+</view>
+
+<popup
+    typeOf="{{typeOf}}"
+    title="{{title}}"
+    headTextOne="{{headTextOne}}"
+    headTextTwo="{{headTextTwo}}"
+    content="{{content}}"
+    bindGroup="group"
+></popup>

+ 9 - 0
utils/APIClient.js

@@ -182,4 +182,13 @@ module.exports = {
 			uid: wx.getStorageSync('uid')
 		}).url(url).send();
 	},
+	//团购是否成功
+	groupSuccess (orderId) {
+		let url = getBaseUrl(`wx/groupPurchase/joinStatus`);
+		return request.getInstance().header({
+			uid: wx.getStorageSync('uid')
+		}).url(url).data({
+			orderId
+		}).send();
+	}
 }