...
|
...
|
@@ -20,6 +20,7 @@ Page({ |
|
|
pitchCart: [], //选中商品
|
|
|
pitchList: [], //选中商品id
|
|
|
hasList: false, // 列表是否有数据
|
|
|
cartnoData: false, //购物车是否为空
|
|
|
totalPrice: 0, // 总价,初始为0
|
|
|
selectAllStatus: true, // 全选状态,默认全选
|
|
|
obj: {
|
...
|
...
|
@@ -28,14 +29,15 @@ Page({ |
|
|
},
|
|
|
//地址信息
|
|
|
getAddress() {
|
|
|
if(wx.getStorageSync('addIndex')){
|
|
|
wx.setStorageSync('addIndex', 0)
|
|
|
}
|
|
|
// if (wx.getStorageSync('addIndex')) {
|
|
|
// wx.removeStorageSync('addIndex')
|
|
|
// }
|
|
|
let index = wx.getStorageSync('addIndex')
|
|
|
method.getRequest("/address", data => {
|
|
|
if (data.statusCode == 0) {
|
|
|
let list = data.data.reverse();
|
|
|
this.setData({
|
|
|
userData: data.data[index],
|
|
|
userData: list[index],
|
|
|
addHint: true
|
|
|
})
|
|
|
}
|
...
|
...
|
@@ -45,26 +47,26 @@ Page({ |
|
|
wx.navigateTo({
|
|
|
url: '/pages/select-address/select-address',
|
|
|
})
|
|
|
wx.setStorageSync("shopCartAdd",'true')
|
|
|
wx.setStorageSync("shopCartAdd", 'true')
|
|
|
},
|
|
|
//没有登录
|
|
|
goAddress1() {
|
|
|
if(wx.getStorageSync('Authorization')){
|
|
|
if (wx.getStorageSync('Authorization')) {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/select-address/select-address',
|
|
|
})
|
|
|
wx.setStorageSync("shopCartAdd",'true')
|
|
|
}else{
|
|
|
wx.setStorageSync("shopCartAdd", 'true')
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '请先登录!',
|
|
|
icon:'none'
|
|
|
icon: 'none'
|
|
|
})
|
|
|
setTimeout(()=>{
|
|
|
setTimeout(() => {
|
|
|
util.getUser();
|
|
|
},2000)
|
|
|
|
|
|
}, 2000)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
},
|
|
|
//配送时间
|
|
|
bindDateChange: function (e) {
|
...
|
...
|
@@ -79,7 +81,6 @@ Page({ |
|
|
var month = myDate.getMonth();
|
|
|
var day = myDate.getDate();
|
|
|
var dayNow = year + '-' + (month + 1) + "-" + day;
|
|
|
console.log(dayNow, 'daynow')
|
|
|
this.setData({
|
|
|
startTime: dayNow
|
|
|
})
|
...
|
...
|
@@ -108,32 +109,42 @@ Page({ |
|
|
this.getTotalNum();
|
|
|
},
|
|
|
|
|
|
// 删除当前商品
|
|
|
deleteList(e) {
|
|
|
const index = e.currentTarget.dataset.index;
|
|
|
const cartIds = e.currentTarget.dataset.cartid;
|
|
|
let carts = this.data.carts;
|
|
|
carts.splice(index, 1);
|
|
|
this.setData({
|
|
|
carts: carts
|
|
|
});
|
|
|
method.deleteRequest("/cart/" + cartIds, data => {
|
|
|
if (data.statusCode == 0) {
|
|
|
wx.showToast({
|
|
|
title: '删除成功',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
//删除
|
|
|
delGoods(e) {
|
|
|
let that = this;
|
|
|
wx.showModal({
|
|
|
title: '提示',
|
|
|
content: '确定删除该商品吗',
|
|
|
success(res) {
|
|
|
if (res.confirm) {
|
|
|
const index = e.currentTarget.dataset.index;
|
|
|
const cartIds = e.currentTarget.dataset.cartid;
|
|
|
let carts = that.data.carts;
|
|
|
carts.splice(index, 1);
|
|
|
that.setData({
|
|
|
carts: carts
|
|
|
});
|
|
|
method.deleteRequest("/cart/" + cartIds, data => {
|
|
|
if (data.statusCode == 0) {
|
|
|
wx.showToast({
|
|
|
title: '删除成功',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
if (!carts.length) {
|
|
|
this.setData({
|
|
|
hasList: false
|
|
|
});
|
|
|
} else {
|
|
|
this.getTotalPrice();
|
|
|
}
|
|
|
} else if (res.cancel) {
|
|
|
console.log('用户点击取消')
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
if (!carts.length) {
|
|
|
this.setData({
|
|
|
hasList: false
|
|
|
});
|
|
|
} else {
|
|
|
this.getTotalPrice();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
// 全选
|
|
|
selectAll(e) {
|
|
|
let selectAllStatus = this.data.selectAllStatus;
|
...
|
...
|
@@ -260,14 +271,14 @@ Page({ |
|
|
}
|
|
|
let list = this.data.carts;
|
|
|
list.forEach((item, index) => {
|
|
|
if(item.selected==true){
|
|
|
console.log(item,"item")
|
|
|
list.splice(index,1)
|
|
|
console.log(list,'list')
|
|
|
}
|
|
|
this.setData({
|
|
|
carts:list
|
|
|
})
|
|
|
if (item.selected == true) {
|
|
|
console.log(item, "item")
|
|
|
list.splice(index, 1)
|
|
|
console.log(list, 'list')
|
|
|
}
|
|
|
this.setData({
|
|
|
carts: list
|
|
|
})
|
|
|
})
|
|
|
wx.setStorageSync('date', this.data.date)
|
|
|
console.log(this.data.date, 'datess')
|
...
|
...
|
@@ -307,7 +318,7 @@ Page({ |
|
|
this.setData({
|
|
|
hasList: true,
|
|
|
carts: [],
|
|
|
checkNum : 0
|
|
|
checkNum: 0
|
|
|
});
|
|
|
this.getTotalPrice();
|
|
|
this.getAddress() //获取默认地址
|
...
|
...
|
@@ -316,6 +327,15 @@ Page({ |
|
|
pitchCart: [],
|
|
|
pitchList: []
|
|
|
})
|
|
|
|
|
|
setTimeout(() => { //判断购物车是否有商品
|
|
|
if (this.data.carts.length == 0) {
|
|
|
this.setData({
|
|
|
cartnoData: true
|
|
|
})
|
|
|
}
|
|
|
}, 500)
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
...
|
...
|
|