// component/single-item/index.js import utils from '../../utils/util'; const app = getApp(); Component({ /** * 组件的属性列表 */ options: { multipleSlots: true // 在组件定义时的选项中启用多slot支持 }, properties: { goods: { type: Object, value: {}, }, isGoEvents:{ type:Boolean, value:false } }, /** * 组件的初始数据 */ data: { }, lifetimes: { // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached() { }, moved() { }, detached() { }, }, pageLifetimes: { // 组件所在页面的生命周期函数 show() { }, hide() { }, }, /** * 组件的方法列表 */ methods: { addCart(e){ let quantity = e.currentTarget.dataset.mininum||1; var matcode = e.currentTarget.dataset.matcode; wx.request({ url: utils.getUrl('/shopping/cart.do?m=add'), header: { "Cookie": "JSESSIONID=" + wx.getStorageSync('sessionID') }, data: { matcode, quantity, }, success: function(res) { wx.hideLoading(); if(!utils.requestError(res)){ return false; } wx.setTabBarBadge({ index: app.globalData.cartIndex, text: res.data['cart-num'].toString() }) utils.showTip("添加成功!"); }, fail: function(errmsg) { utils.requestFail(errmsg,'/shopping/cart.do'); } }) }, } })