parent
f2960ba057
commit
fffde2fda1
8 changed files with 170 additions and 31 deletions
@ -1,24 +1,31 @@ |
||||
var app = getApp() |
||||
const product = require('../../utils/product.js') |
||||
|
||||
Page({ |
||||
data: { items: |
||||
[ |
||||
{ url: 'aaaa.jpg', |
||||
name: 'aaa', |
||||
id: 1 |
||||
}, |
||||
{ |
||||
url: 'aaaa.jpg', |
||||
name: 'bbb', |
||||
id: 2 |
||||
} |
||||
] |
||||
}, |
||||
data: {items: []}, |
||||
|
||||
bindViewTap: function() { |
||||
}, |
||||
|
||||
onLoad: function() { |
||||
var that = this |
||||
|
||||
wx.getNetworkType({ |
||||
success: function(res) { |
||||
var networkType = res.networkType // 返回网络类型2g,3g,4g,wifi
|
||||
// if (networkType) {
|
||||
product.getProducts().then(function(result) { |
||||
that.data.items = result.data |
||||
}) |
||||
// } else {
|
||||
// cache = wx.getStorageSync('products')
|
||||
// if (cache) {
|
||||
// this.data.items = cache
|
||||
// } else {
|
||||
// this.data.items = []
|
||||
// }
|
||||
// }
|
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
|
@ -1,11 +1,31 @@ |
||||
<view> |
||||
<text>{{name}}</text> |
||||
<image src="/images/product_show_{{id}}.png" mode="aspectFill"/> |
||||
<text>{{product.attributes.name}}</text> |
||||
<image src="{{product.attributes['image-url']}}" mode="aspectFill"/> |
||||
|
||||
<view wx:if="{{ address.length > 0 }}"> |
||||
<text bindtap="bindTapAddress">address</text> |
||||
<view wx:if="{{ address > 0 }}" bindtap="bindTapAddress"> |
||||
<text>{{address}}</text> |
||||
<text>edit</text> |
||||
</view> |
||||
<view wx:else> |
||||
<text bindtap="bindTapAddress">address</text> |
||||
<view wx:else bindtap="bindTapAddress"> |
||||
<text>add new address</text> |
||||
</view> |
||||
|
||||
<view> |
||||
<form bindsubmit="formSubmit" bindreset="formReset"> |
||||
<view class="section"> |
||||
<text class="">数量</text> |
||||
<input name="quantity" value="1" /> |
||||
</view> |
||||
<view class="section"> |
||||
<text type="hidden">sku:{{product.attributes.sku || '无法获取sku'}}</text> |
||||
</view> |
||||
<view class="section"> |
||||
<text>{{product.attributes.price || '无法获取价格'}}</text> |
||||
</view> |
||||
<view class="btn-area"> |
||||
<button formType="submit">buy it!</button> |
||||
<button formType="reset">Reset</button> |
||||
</view> |
||||
</form> |
||||
</view> |
||||
</view> |
||||
|
@ -1,20 +1,42 @@ |
||||
const API_URL = 'https://api.bayekeji.com/v2' |
||||
const API_URL = 'http://127.0.0.1:3000' |
||||
|
||||
function postAddress (data) { |
||||
return new Promise((resolve, reject) => { |
||||
wx.request({ |
||||
method: POST, |
||||
method: 'POST', |
||||
url: `${API_URL}/addresses/new`, |
||||
data: Object.assign({}, data), |
||||
header: { 'Content-Type': 'application/json' }, |
||||
success: resolve, |
||||
fail: reject |
||||
success (res) { |
||||
console.log('success') |
||||
wx.setStorageSync('addrss', res.data) |
||||
wx.navigateBack() |
||||
}, |
||||
fail (e) { |
||||
console.log('error') |
||||
console.error(e) |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
function getLocation () { |
||||
wx.getLocation({ |
||||
type: 'gcj02', //返回可以用于 wx.openLocation 的经纬度
|
||||
success: function(res) { |
||||
var latitude = res.latitude |
||||
var longitude = res.longitude |
||||
wx.openLocation({ |
||||
latitude: latitude, |
||||
longitude: longitude, |
||||
scale: 28 |
||||
}) |
||||
} |
||||
}) |
||||
} |
||||
|
||||
module.exports = { |
||||
postAddress (data) { |
||||
return postAddress(data).then(res => res.data) |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,34 @@ |
||||
const API_URL = 'http://localhost:3000' |
||||
|
||||
function getProducts (data) { |
||||
data = data ? `/${data}` : '' |
||||
return new Promise((resolve, reject) => { |
||||
wx.request({ |
||||
url: `${API_URL}/products${data}`, |
||||
header: { 'Content-Type': 'application/json' }, |
||||
success: resolve, |
||||
fail: reject |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
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 |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
module.exports = { |
||||
getProducts (data) { |
||||
return getProducts(data).then(res => res.data) |
||||
}, |
||||
getProduct (data) { |
||||
return getProducts(data).then(res => res.data) |
||||
} |
||||
} |
Loading…
Reference in new issue