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.
59 lines
1.1 KiB
59 lines
1.1 KiB
const product = require('../../utils/product.js') |
|
|
|
Page({ |
|
data: { |
|
toastAddProduct: true, |
|
title: '', |
|
id: 0, |
|
quantity: 1, |
|
product: {} |
|
}, |
|
|
|
onLoad (params) { |
|
var id = params.id |
|
var product = wx.getStorageSync('products').find(function(i){ |
|
return i.id === id |
|
}) |
|
|
|
this.setData({ |
|
id:id, |
|
product:product |
|
}) |
|
}, |
|
|
|
onReady () { |
|
wx.setNavigationBarTitle({ title: this.data.title }) |
|
}, |
|
|
|
bindAddToCart (e) { |
|
var that = this |
|
var cartItems = wx.getStorageSync('cartItems') || [] |
|
|
|
var exist = cartItems.find(function(ele){ |
|
return ele.id === that.data.id |
|
}) |
|
|
|
if (exist) { |
|
exist.quantity = this.data.quantity |
|
} else { |
|
cartItems.push({ |
|
id: this.data.id, |
|
quantity: this.data.quantity, |
|
product: this.data.product |
|
}) |
|
} |
|
this.setData({ toastAddProduct:false }); |
|
wx.setStorage({ |
|
key: 'cartItems', |
|
data: cartItems |
|
}) |
|
}, |
|
|
|
bindQuantityInput (e) { |
|
this.setData({'quantity': e.detail.value}) |
|
}, |
|
|
|
toastChange: function(){ |
|
this.setData({ toastAddProduct:true }); |
|
} |
|
})
|
|
|