Explorar el Código

Merge remote-tracking branch 'origin/master'

chenxiqiang hace 6 años
padre
commit
d9e238ad0e

+ 66
- 11
miniapp/app/pages/cart/index.js Ver fichero

@@ -181,11 +181,12 @@ new $.Page({
181 181
         goodsList.forEach((g) => {
182 182
             carts.push({
183 183
                 id: g.id,
184
-                amount: g.product_amount
184
+                product_id: g.product_id,
185
+                product_amount: g.product_amount
185 186
             });
186 187
         });
187 188
         $.request('shopcar/pstore', 'POST', {
188
-            products_prices: cart
189
+            data: carts
189 190
         }).then(() => {
190 191
             this.setData({
191 192
                 hasAmountModify: false
@@ -195,11 +196,22 @@ new $.Page({
195 196
 
196 197
     toSettle() {
197 198
         const products = [];
198
-        const goodsList = this.data.goodsList;
199
+        const { name, phone, address, goodsList } = this.data;
199 200
         if (goodsList.length === 0) return;
201
+        if (!name || !phone || !address) {
202
+            return $.wx.showToast({
203
+                title: '请把地址信息填写完整'
204
+            });
205
+        }
206
+        if (!this._isPhone(phone)) {
207
+            return $.wx.showToast({
208
+                title: '请输入正确的手机号码'
209
+            });
210
+        }
200 211
         goodsList.forEach((g) => {
201 212
             if (g.checked) {
202 213
                 g.amount = g.product_amount;
214
+                g.id = g.product_id;
203 215
                 products.push(g);
204 216
             }
205 217
         });
@@ -208,14 +220,57 @@ new $.Page({
208 220
                 title: '请先选择购买商品'
209 221
             });
210 222
         }
211
-        $.router.goto({
212
-            path: '/pages/orderDetail/index',
213
-            params: {
214
-                isCabinet: false,
215
-                products
216
-            },
217
-            query: {
218
-                source: 'cart'
223
+        $.wx.showToast({
224
+            title: '购买中'
225
+        }, 'loading');
226
+        $.request('product_order/store', 'POST', {
227
+            address,
228
+            contact: name,
229
+            phone,
230
+            products
231
+        }).then((res) => {
232
+            if (res.data) {
233
+                this.callWXPay(res.data.id, res.data.order_type || 'product_order');
234
+            }
235
+        });
236
+    },
237
+    callWXPay(order_id, order_type) {
238
+        $.request('payments/pay', 'POST', {
239
+            order_id,
240
+            order_type
241
+        }).then((res) => {
242
+            if (res.msg) {
243
+                const {
244
+                    timestamp,
245
+                    paySign,
246
+                    nonceStr
247
+                } = res.msg;
248
+                const pck = res.msg.package;
249
+                wx.requestPayment({
250
+                    timeStamp: timestamp + '',
251
+                    nonceStr,
252
+                    package: pck,
253
+                    signType: 'MD5',
254
+                    paySign,
255
+                    success(res) {
256
+                        $.wx.showToast({
257
+                            title: '支付成功'
258
+                        });
259
+                    },
260
+                    fail() {
261
+                        $.wx.showToast({
262
+                            title: '支付失败'
263
+                        });
264
+                    },
265
+                    complete() {
266
+                        setTimeout(function () {
267
+                            $.router.goto({
268
+                                path: '/pages/order/index',
269
+                                type: $.ROUTER_TYPE.SWITCH_TAB
270
+                            });
271
+                        }, 2000);
272
+                    }
273
+                });
219 274
             }
220 275
         });
221 276
     }

+ 22
- 0
miniapp/app/pages/cart/index.wxml Ver fichero

@@ -30,6 +30,28 @@
30 30
                     </view>
31 31
                 </view>
32 32
             </view>
33
+            <view class="module-ft">
34
+                <view class="booking">
35
+                    <view class="input-item">
36
+                        <view class="label">姓名</view>
37
+                        <view class="input-content">
38
+                            <input type="text" class="input-text" bindinput="_handleInput" data-name="name" placeholder="您的称呼" />
39
+                        </view>
40
+                    </view>
41
+                    <view class="input-item">
42
+                        <view class="label">电话</view>
43
+                        <view class="input-content">
44
+                            <input type="number" class="input-text" bindinput="_handleInput" data-name="phone" placeholder="您的手机号码" />
45
+                        </view>
46
+                    </view>
47
+                    <view class="input-item ">
48
+                        <view class="label ">地址</view>
49
+                        <view class="input-content">
50
+                            <input type="text" class="input-text" bindinput="_handleInput" data-name="address" placeholder="寄送地址" />
51
+                        </view>
52
+                    </view>
53
+                </view>
54
+            </view>
33 55
         </view>
34 56
         <view class="empty-content" wx:else>
35 57
             <view class="empty-content-text">购物车空空如也</view>

+ 9
- 0
miniapp/app/pages/cart/index.wxss Ver fichero

@@ -196,4 +196,13 @@ text {
196 196
     position: fixed;
197 197
     bottom: 0;
198 198
     width: 100%;
199
+    z-index: 10;
200
+}
201
+
202
+.booking{
203
+    border-top: solid 1rpx #ccc;
204
+}
205
+
206
+.label{
207
+    line-height: 80rpx;
199 208
 }

+ 4
- 2
miniapp/app/pages/goodsDetail/index.js Ver fichero

@@ -57,11 +57,13 @@ new $.Page({
57 57
             title: '购买中'
58 58
         }, 'loading');
59 59
         $.request('product_order/store', 'POST', {
60
-            amount,
61 60
             address,
62 61
             contact: name,
63 62
             phone,
64
-            product_id: this.data.detail.id
63
+            products: [{
64
+                id: this.data.detail.id,
65
+                amount
66
+            }]
65 67
         }).then((res) => {
66 68
             if (res.data) {
67 69
                 this.callWXPay(res.data.id, res.data.order_type || 'product_order');

+ 12
- 10
miniapp/app/pages/order/index.js Ver fichero

@@ -14,17 +14,19 @@ new $.Page({
14 14
     },
15 15
     init() {
16 16
         $.request('my/orders', 'GET', {}).then((res) => {
17
-            const services = []
18
-            const goods = []
19
-            if (res.data && res.data.length > 0) {
20
-                res.data.forEach(e => {
17
+            if (res.data) {
18
+                const services = res.data.others || [];
19
+                const goods = res.data.product_orders || [];
20
+                services.forEach(e => {
21 21
                     e.orderText = orderTexts[e.status];
22
-                    if (e.order_type == 'product_order') {
23
-                        if (e.status == 0)
24
-                            e.orderText = '待付款';
25
-                        goods.push(e);
26
-                    } else {
27
-                        services.push(e);
22
+                });
23
+                goods.forEach(e => {
24
+                    e.orderText = orderTexts[e.status];
25
+                    if (e.status == 0) e.orderText = '待付款';
26
+                    e.text = '';
27
+                    for (let p of e.products) {
28
+                        let t = `${p.name}×${p.amount}`;
29
+                        e.text += e.text ? (';' + t) : t;
28 30
                     }
29 31
                 });
30 32
                 this.setData({

+ 2
- 2
miniapp/app/pages/order/index.wxml Ver fichero

@@ -43,8 +43,8 @@
43 43
                     <view class="left">
44 44
                         <image class="order-img" src="{{item.photo}}"></image>
45 45
                         <view class="info">
46
-                            <view class="name">{{item.classify1}}</view>
47
-                            <view class="text">{{item.classify2}}</view>
46
+                            <view class="name">{{item.text}}</view>
47
+                            <!-- <view class="text">{{item.classify2}}</view> -->
48 48
                             <view class="text">{{item.created_at}}</view>
49 49
                         </view>
50 50
                     </view>

Loading…
Cancelar
Guardar