more with json api

wechat_user_type
Ge Hao 8 years ago
parent 7e7f7e42c5
commit 1f539b6787
  1. 23
      pages/address/address.js
  2. 19
      pages/index/index.js
  3. 21
      pages/show_product/show_product.js
  4. 2
      pages/show_product/show_product.wxml
  5. 28
      utils/address.js

@ -23,5 +23,28 @@ Page({
onLoad (params) {
//this.data.sku = params.sku
},
getAddressMenu: function() {
var that = this
wx.request({
method: 'POST',
url: `cities?province=${that.data.arraySheng[indexSheng]}`,
data: Object.assign({}, data),
header: { 'Content-Type': 'application/json' },
success (res) {
debugger
console.log('success')
wx.setStorageSync('addrss', res.data)
wx.navigateBack()
},
fail (e) {
console.log('error')
console.error(e)
}
})
}
})

@ -10,18 +10,19 @@ Page({
wx.getNetworkType({
success: function(res) {
var networkType = res.networkType // 返回网络类型2g,3g,4g,wifi
// if (networkType) {
if (networkType) {
product.getProducts().then(function(result) {
that.data.items = result.data
wx.setStorageSync('products', result.data)
})
// } else {
// cache = wx.getStorageSync('products')
// if (cache) {
// this.data.items = cache
// } else {
// this.data.items = []
// }
// }
} else {
cache = wx.getStorageSync('products')
if (cache) {
this.data.items = cache
} else {
this.data.items = []
}
}
}
})
}

@ -17,26 +17,9 @@ Page({
var that = this
this.data.id = params.id
wx.getNetworkType({
success: function(res) {
var networkType = res.networkType // 返回网络类型2g,3g,4g,wifi
if (networkType) {
product.getProduct(params.id).then(function(result) {
console.log(result)
that.data.product = result.data
wx.setStorage({key: `product-${params.id}`, value: that.data.product})
})
} else {
cache = wx.getStorageSync(`product-${params.id}`)
if (cache) {
this.data.product = cache
} else {
this.data.product = {}
}
}
}
that.data.product = wx.getStorageSync('products').find(function(i){
return i.id === that.data.id;
})
},
onReady () {

@ -4,7 +4,7 @@
<view wx:if="{{ address > 0 }}" bindtap="bindTapAddress">
<text>{{address}}</text>
<text>edit</text>
<text>修改地址</text>
</view>
<view wx:else bindtap="bindTapAddress">
<text>add new address</text>

@ -3,19 +3,19 @@ const API_URL = 'http://127.0.0.1:3000'
function postAddress (data) {
return new Promise((resolve, reject) => {
wx.request({
method: 'POST',
url: `${API_URL}/addresses/new`,
data: Object.assign({}, data),
header: { 'Content-Type': 'application/json' },
success (res) {
console.log('success')
wx.setStorageSync('addrss', res.data)
wx.navigateBack()
},
fail (e) {
console.log('error')
console.error(e)
}
method: 'POST',
url: `${API_URL}/addresses/new`,
data: Object.assign({}, data),
header: { 'Content-Type': 'application/json' },
success (res) {
console.log('success')
wx.setStorageSync('addrss', res.data)
wx.navigateBack()
},
fail (e) {
console.log('error')
console.error(e)
}
})
})
}
@ -35,6 +35,8 @@ function getLocation () {
})
}
module.exports = {
postAddress (data) {
return postAddress(data).then(res => res.data)

Loading…
Cancel
Save