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 district = require('../../utils/address_data.js')
const product = require('../../utils/product.js')
Page({ Page({
data: { data: {
@ -16,8 +17,8 @@ Page({
var cartItems = wx.getStorageSync("cartItems") var cartItems = wx.getStorageSync("cartItems")
this.setData({cartItems: cartItems}) this.setData({cartItems: cartItems})
var detailAddress = wx.getStorageSync('detailAddress') var detailAddress = wx.getStorageSync('detailAddress')
var receiverName = wx.getStorageSync('receiverName') var receiverName = wx.getStorageSync('receiverName')
var receiverMobile = wx.getStorageSync('receiverMobile') var receiverMobile = wx.getStorageSync('receiverMobile')
var address = {detail: detailAddress, name: receiverName, mobile: receiverMobile} var address = {detail: detailAddress, name: receiverName, mobile: receiverMobile}
@ -69,9 +70,19 @@ Page({
}) })
}, },
// bindBilling: function () { bindBilling: function () {
// var cartItems = wx.getStorageSync('cartItems') 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 () { bindTapAddress () {
wx.navigateTo({ wx.navigateTo({

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

@ -6,13 +6,11 @@ Page({
toastAddProduct: true, toastAddProduct: true,
title: '', title: '',
id: 0, id: 0,
address: '',
quantity: 1, quantity: 1,
product: {} product: {}
}, },
onShow () { onShow () {
this.setData({'address': Date.now()})
}, },
onLoad (params) { 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 () { function getSlides () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.request({ wx.request({
@ -39,7 +27,7 @@ function postBilling (data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.request({ wx.request({
method: 'POST', method: 'POST',
url: `${API_URL}/cart/billing`, url: `${API_URL}/carts/billings`,
data: data, data: data,
header: { 'Content-Type': 'application/json'}, header: { 'Content-Type': 'application/json'},
success: resolve, success: resolve,

Loading…
Cancel
Save