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.

61 lines
1.1 KiB

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,
quantity: 1,
8 years ago
product: {}
},
8 years ago
onLoad (params) {
8 years ago
var id = params.id
var product = wx.getStorageSync('products').find(function(i){
return i.id === id
})
this.setData({
id: id,
product: product,
title: product.name
8 years ago
})
8 years ago
},
onReady() {
8 years ago
wx.setNavigationBarTitle({ title: this.data.title })
},
bindAddToCart (e) {
8 years ago
var that = this
var cartItems = wx.getStorageSync('cartItems') || []
var exist = cartItems.find(function(ele){
8 years ago
return ele.id === that.data.id
})
if (exist) {
exist.quantity = parseInt(exist.quantity) + 1
} else {
8 years ago
cartItems.push({
id: this.data.id,
quantity: this.data.quantity,
product: this.data.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
})