tanyanfei 4 years ago
parent
commit
77b46d9b0f
8 changed files with 91 additions and 4 deletions
  1. 1 0
      app.json
  2. 5 0
      pages/apply/apply.js
  3. 1 1
      pages/apply/apply.wxml
  4. 42 2
      pages/pay/pay.js
  5. 1 1
      pages/pay/pay.wxml
  6. 8 0
      pages/post/post.js
  7. 16 0
      pages/upload/upload.js
  8. 17 0
      pages/user/user.js

+ 1 - 0
app.json

@@ -1,5 +1,6 @@
 {
   "pages":[ 
+    
     "pages/index/index",
     "pages/user/user",
     "pages/online/online",

+ 5 - 0
pages/apply/apply.js

@@ -41,6 +41,11 @@ Page({
       }
     })
   },
+  pay:function(e){
+    wx.navigateTo({
+      url: '../pay/pay?id='+e.target.dataset.id,
+    })
+  },
 
   /**
    * 生命周期函数--监听页面初次渲染完成

+ 1 - 1
pages/apply/apply.wxml

@@ -15,7 +15,7 @@
             <text wx:if="{{item.order_status == 2||item.order_status == 3}}" style="color:#358BFF;" decode="{{true}}">学时情况  &nbsp;&nbsp;已学习{{item.class_hour_finished}}/{{item.class_hour}}学时</text>
             <text style="color:#999;margin-top:12px;">{{item.ctime}}</text>
         </view>
-        <navigator url="../pay/pay" wx:if="{{item.order_status == 1}}" class="study">立即支付</navigator>
+        <view  data-id='{{item.id}}' catchtap="pay" wx:if="{{item.order_status == 1}}" class="study">立即支付</view>
         <navigator url="../online/online" wx:if="{{item.order_status == 2}}" class="study">立即学习</navigator>
     </navigator>
 

+ 42 - 2
pages/pay/pay.js

@@ -18,7 +18,6 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
-      options.id=9
       wx.request({
         url: host + '/api/wx/signup',
         method: 'GET',
@@ -42,7 +41,48 @@ Page({
       })
     };
   },
-
+  pay:function(){
+    var data=this.data.data;
+    wx.showLoading({
+      title: '正在提交...',
+    })
+    wx.request({
+      url: host+'/api/wx/signup/pay',
+      method:'POST',
+      header: {
+        openid: app.globalData.openid
+      },
+      data:{
+        total_fee: data.price,
+        signup_id:data.id,
+        bill_type:1,
+        bill_no:'',
+        bill_mat:1
+      },
+      success:res=>{
+        console.log(res.data.data)
+          wx.hideLoading()
+          var timestamp = Date.parse(new Date());
+          var _data={
+            timeStamp: String(timestamp),
+            nonceStr: res.data.data.nonce_str,
+            package: 'prepay_id=' + res.data.data.prepay_id,
+            signType: 'MD5',
+            paySign: res.data.data.sign,
+          }
+        console.log(_data)
+          wx.requestPayment({
+            timeStamp: String(timestamp),
+            nonceStr: res.data.data.nonce_str,
+            package: 'prepay_id=' + res.data.data.prepay_id,
+            signType: 'MD5',
+            paySign: res.data.data.sign,
+            success(res) { console.log(res)},
+            fail(res) { console.log(res)}
+          })
+      }
+    })
+  },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */

+ 1 - 1
pages/pay/pay.wxml

@@ -60,6 +60,6 @@
 
   <view class="bottom">
     实付款  <text>¥{{data.price}}</text>
-    <view>立即支付</view>
+    <view bindtap="pay">立即支付</view>
   </view>
 </form>

+ 8 - 0
pages/post/post.js

@@ -335,6 +335,14 @@ Page({
             duration: 2000
           })
         }
+      },
+      fail: res => {
+        wx.hideLoading()
+        wx.showToast({
+          title: res.data.message,
+          icon: 'none',
+          duration: 2000
+        })
       }
     })
     

+ 16 - 0
pages/upload/upload.js

@@ -123,6 +123,14 @@ Page({
               })
           },2000)
         }
+      },
+      fail:res=>{
+        wx.hideLoading()
+        wx.showToast({
+          title: res.data.message,
+          icon: 'none',
+          duration: 2000
+        })
       }
     })
   },
@@ -183,6 +191,14 @@ Page({
                 oldcard_img: data.data.url
               })
             }
+          },
+          fail: res => {
+            wx.hideLoading()
+            wx.showToast({
+              title: res.data.message,
+              icon: 'none',
+              duration: 2000
+            })
           }
         })
       },

+ 17 - 0
pages/user/user.js

@@ -122,6 +122,14 @@ Page({
               data:_data,
               
             })
+          },
+          fail: res => {
+            wx.hideLoading()
+            wx.showToast({
+              title: res.data.message,
+              icon: 'none',
+              duration: 2000
+            })
           }
         })
       },
@@ -141,11 +149,20 @@ Page({
         },
         method:'PUT',
         success: res => {
+          wx.hideLoading()
           wx.showToast({
             title: '提交成功',
             icon: 'success',
             duration: 2000
           })
+        },
+        fail: res => {
+          wx.hideLoading()
+          wx.showToast({
+            title: res.data.message,
+            icon: 'none',
+            duration: 2000
+          })
         }
       })
   },