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.

54 lines
1.3 KiB

4 months ago
const { getCart,delGoodsCart } = require("../../api/index.js")
3 months ago
Page({
4 months ago
/**
* 页面的初始数据
*/
data: {
cartData:[]
},
/**
* 每次打开页面都会执行
*/
onShow(){
this.http()
},
3 months ago
goDetail(e) {
const id = e.currentTarget.dataset.id;
wx.navigateTo({
url: `/pages/goodsDetails/goodsDetails?id=${id}`
});
},
4 months ago
// 根源
delCartHandle(e){
3 months ago
console.log("删除按钮被点击");
4 months ago
console.log(e.currentTarget.dataset.id);
/**
* 这里有两个ID
* 1. currentID:商品ID同一个商品加入购物车多次的时候会一次性全删除
* 2. id:每条数据的唯一索引(推荐)课程中选择的方式
*/
delGoodsCart({currentID:e.currentTarget.dataset.id}).then(res =>{
if(res.data.status === 200){
wx.showToast({
title: '删除成功',
3 months ago
});
4 months ago
this.http()
}else{
wx.showToast({
title: '删除失败',
3 months ago
});
4 months ago
}
3 months ago
});
4 months ago
},
http(){
getCart().then(res =>{
console.log(res.data.data);
this.setData({
cartData:res.data.data
3 months ago
});
});
4 months ago
}
})