ycm 2 years ago
parent
commit
c238ae82d0
2 changed files with 46 additions and 2 deletions
  1. 44 1
      pages/order/placeOrder/placeOrder.js
  2. 2 1
      pages/order/placeOrder/placeOrder.wxml

+ 44 - 1
pages/order/placeOrder/placeOrder.js

@@ -284,8 +284,51 @@ Page({
 
     getOrder() {
         var nid = this.data.worke.id;
-        app.api.useApi(app.globalData.baseAppUrl + "api/makeorder", {
+        if(this.data.carNum>0){
+
+            app.api.useApi(app.globalData.baseAppUrl + "api/makeorder", {
+                network_id: nid,
+            }, "post").then(function (res) {
+                console.log(res);
+                if (res.code != 200) {
+                    wx.showLoading({
+                        title: res.message.msg,
+                    })
+                    wx.setTimeout(() => {
+                        wx.hideLoading();
+                    }, 1000);
+                } else {
+                    var order_no = res.message.data.order_no;
+                    wx.navigateTo({
+                        url: '/pages/order/confirmOreder/confirmOreder?order_no=' + order_no,
+                    })
+                }
+    
+    
+    
+            }).catch(function (err) {
+                console.log(222);
+            })
+        }else{
+            wx.showToast({
+                title: '购物车不能为空',
+                icon: 'none',
+                duration: 2000
+            })
+        }
+
+
+
+
+    },
+    
+    getOrderone(e) {
+        var gid = e.currentTarget.dataset.gid;
+        var nid = this.data.worke.id;
+        app.api.useApi(app.globalData.baseAppUrl + "api/CreateOrder", {
             network_id: nid,
+            good_id: gid,
+            num: 1
         }, "post").then(function (res) {
             console.log(res);
             if (res.code != 200) {

+ 2 - 1
pages/order/placeOrder/placeOrder.wxml

@@ -111,7 +111,8 @@
                                 </view>
                                 <view wx:else>
                                     <view class="main8">
-                                        <text lines="1" class="word16" bindtap="shoppingPlus"  data-item="{{item}}">立即下单</text>
+                                        <!-- bindtap="shoppingPlus"  data-item="{{item}}" -->
+                                        <text lines="1" class="word16" bindtap="getOrderone" data-gid="{{item.id}}">立即下单</text>
                                     </view>
                                 </view>