post billing to server

wechat_user_type
Ge Hao 8 years ago
parent 3c81ad9df8
commit a8a26a3d80
  1. 21
      pages/cart/cart.js
  2. 2
      pages/cart/cart.wxml
  3. 2
      pages/show_product/show_product.js
  4. 14
      utils/product.js

@ -1,4 +1,5 @@
const district = require('../../utils/address_data.js')
const product = require('../../utils/product.js')
Page({
data: {
@ -16,8 +17,8 @@ Page({
var cartItems = wx.getStorageSync("cartItems")
this.setData({cartItems: cartItems})
var detailAddress = wx.getStorageSync('detailAddress')
var receiverName = wx.getStorageSync('receiverName')
var detailAddress = wx.getStorageSync('detailAddress')
var receiverName = wx.getStorageSync('receiverName')
var receiverMobile = wx.getStorageSync('receiverMobile')
var address = {detail: detailAddress, name: receiverName, mobile: receiverMobile}
@ -69,9 +70,19 @@ Page({
})
},
// bindBilling: function () {
// var cartItems = wx.getStorageSync('cartItems')
// },
bindBilling: function () {
var cartItems = wx.getStorageSync('cartItems')
if (cartItems) {
var cartArray = cartItems.map(function(obj){
var rObj = {};
rObj['id'] = obj.id;
rObj['quantity'] = obj.quantity;
return rObj;
});
product.postBilling({items: cartArray,
address: this.data.address})
}
},
bindTapAddress () {
wx.navigateTo({

@ -43,7 +43,7 @@
<view class="billing-btn">
<button class="button" type='warn'> 去支付 </button>
<button class="button" type='warn' bindtap="bindBilling"> 去支付 </button>
</view>

@ -6,13 +6,11 @@ Page({
toastAddProduct: true,
title: '',
id: 0,
address: '',
quantity: 1,
product: {}
},
onShow () {
this.setData({'address': Date.now()})
},
onLoad (params) {

@ -12,18 +12,6 @@ function getProducts (data) {
})
}
function postBuyProduct (data) {
return new Promise((resolve, reject) => {
wx.request({
url: `${API_URL}/products/buy`,
data: Object.assign({}, data),
header: { 'Content-Type': 'application/json' },
success: resolve,
fail: reject
})
})
}
function getSlides () {
return new Promise((resolve, reject) => {
wx.request({
@ -39,7 +27,7 @@ function postBilling (data) {
return new Promise((resolve, reject) => {
wx.request({
method: 'POST',
url: `${API_URL}/cart/billing`,
url: `${API_URL}/carts/billings`,
data: data,
header: { 'Content-Type': 'application/json'},
success: resolve,

Loading…
Cancel
Save