You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.5 KiB

8 years ago
const app = getApp()
8 years ago
const product = require('../../utils/product.js')
8 years ago
Page({
data: {
8 years ago
toastAddProduct: true,
8 years ago
title: '',
8 years ago
id: 0,
address: '',
quantity: 1,
8 years ago
product: {}
},
onShow () {
this.setData({'address': Date.now()})
8 years ago
},
onLoad (params) {
8 years ago
var that = this
8 years ago
this.data.id = params.id
that.data.product = wx.getStorageSync('products').find(function(i){
return i.id === that.data.id
8 years ago
})
8 years ago
},
onReady () {
wx.setNavigationBarTitle({ title: this.data.title })
},
bindAddToCart (e) {
var cartItems = wx.getStorageSync('cartItems') || {data:[]}
var exist = cartItems.data.find(function(ele){
return ele.id === app.getCurrentPage().data.id
})
if (exist) {
exist.quantity = this.data.quantity
} else {
var model = getApp().jsonModel
var product = new model('products', this.data.id)
product.setAttribute('quantity', this.data.quantity)
cartItems.data.push(product)
}
8 years ago
this.setData({ toastAddProduct:false });
wx.setStorage({
key: 'cartItems',
data: cartItems
})
},
bindQuantityInput (e) {
this.setData({'quantity': e.detail.value})
},
8 years ago
toastChange: function(){
this.setData({ toastAddProduct:true });
},
// 立即购买
8 years ago
formSubmit: function(e) {
8 years ago
e.detail.value['sku'] = e.target.dataset['sku']
8 years ago
// address.postBuyProduct(e.detail.value)
console.log('form发生了submit事件,携带数据为:', e.detail.value)
},
8 years ago
})