|
|
// pages/cart/cart.js
|
|
|
const app = getApp();
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
|
|
|
choose: false,
|
|
|
choose2: true,
|
|
|
chooseAll2: false,
|
|
|
number: 1,
|
|
|
goodsList: [],
|
|
|
goodsId: 0,
|
|
|
totalPrice: 0,
|
|
|
promotion: [],
|
|
|
goods_Price: 0,
|
|
|
shipment: {},
|
|
|
shipPrice: 0,
|
|
|
ship_balance: 0,
|
|
|
is_vip: 0,
|
|
|
cartId: 1,
|
|
|
listlist: [],
|
|
|
all_both_choose: false,
|
|
|
chuandi: 0,
|
|
|
},
|
|
|
//跳转至详情页
|
|
|
goDetail(e) {
|
|
|
wx.navigateTo({
|
|
|
url: '../index/goodsDetial/goodsDetial?id=' + e.currentTarget.dataset.id,
|
|
|
})
|
|
|
},
|
|
|
goDetail2(e) {
|
|
|
wx.navigateTo({
|
|
|
url: '../index/goodsDetial2/goodsDetial2?id=' + e.currentTarget.dataset.id,
|
|
|
})
|
|
|
},
|
|
|
//获取购物车数量
|
|
|
fetchCartNum() {
|
|
|
let url = '/wxapp/cart/index'
|
|
|
app.post(url).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
if (r.data.cartNum > 0) {
|
|
|
wx.showTabBarRedDot({
|
|
|
index: 1,
|
|
|
success: function(red) {
|
|
|
wx.setTabBarBadge({
|
|
|
index: 1,
|
|
|
text: r.data.cartNum.toString(),
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
wx.hideTabBarRedDot({
|
|
|
index: 1
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//最下面的全选
|
|
|
allBothChoose() {
|
|
|
let that = this
|
|
|
let goodsList = that.data.goodsList
|
|
|
let promotion = that.data.promotion
|
|
|
let all_both_choose = that.data.all_both_choose
|
|
|
if (all_both_choose) {
|
|
|
all_both_choose = false
|
|
|
} else {
|
|
|
all_both_choose = true
|
|
|
}
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
if (all_both_choose) {
|
|
|
ele.chooseAll = true
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
ele.list[i].flag = true
|
|
|
}
|
|
|
that.setData({
|
|
|
goodsList: goodsList
|
|
|
})
|
|
|
} else {
|
|
|
ele.chooseAll = false
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
ele.list[i].flag = false
|
|
|
}
|
|
|
that.setData({
|
|
|
goodsList: goodsList
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
promotion.forEach(function (ele, index) {
|
|
|
if (all_both_choose) {
|
|
|
ele.chooseAll = true
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
ele.list[i].flag = true
|
|
|
}
|
|
|
that.setData({
|
|
|
promotion: promotion
|
|
|
})
|
|
|
} else {
|
|
|
ele.chooseAll = false
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
ele.list[i].flag = false
|
|
|
}
|
|
|
that.setData({
|
|
|
promotion: promotion
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
that.setData({
|
|
|
all_both_choose: all_both_choose
|
|
|
})
|
|
|
this.totalPrice();
|
|
|
},
|
|
|
//fetchUser
|
|
|
fetchUser() {
|
|
|
let url = '/wxapp/user/index'
|
|
|
app.post(url).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
console.log(r)
|
|
|
this.setData({
|
|
|
is_vip: r.data.user.is_vip
|
|
|
})
|
|
|
this.fetchCartList();
|
|
|
this.amount();
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//fetchCartList
|
|
|
fetchCartList() {
|
|
|
let that = this;
|
|
|
let url = '/wxapp/cart/index'
|
|
|
var list = {};
|
|
|
var number = 1;
|
|
|
var g_price = 0;
|
|
|
var vip = that.data.is_vip
|
|
|
app.post(url).then(r => {
|
|
|
r.data.list.forEach(function(ele, index) {
|
|
|
ele.chooseAll = false
|
|
|
for (let v in ele.list) {
|
|
|
ele.list[v].flag = false
|
|
|
if (vip == 1) {
|
|
|
var price = ele.list[v].vip_price
|
|
|
price = price.substring(0, price.length - 3) * 1
|
|
|
ele.list[v].goods_price = ele.list[v].number * price
|
|
|
} else {
|
|
|
var price = ele.list[v].price
|
|
|
price = price.substring(0, price.length - 3) * 1
|
|
|
ele.list[v].goods_price = ele.list[v].number * price
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
r.data.promotion.forEach(function(ele, index) {
|
|
|
ele.chooseAll=false
|
|
|
for (let v in ele.list) {
|
|
|
ele.list[v].t = false
|
|
|
if (vip == 1) {
|
|
|
var price = ele.list[v].vip_price
|
|
|
price = price.substring(0, price.length - 3) * 1
|
|
|
ele.list[v].goods_price = ele.list[v].number * price
|
|
|
} else {
|
|
|
var price = ele.list[v].price
|
|
|
price = price.substring(0, price.length - 3) * 1
|
|
|
ele.list[v].goods_price = ele.list[v].number * price
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
that.setData({
|
|
|
listlist: r.data,
|
|
|
goodsList: r.data.list,
|
|
|
promotion: r.data.promotion,
|
|
|
number: number,
|
|
|
shipment: r.data.shipment,
|
|
|
shipPrice: r.data.shipment.price
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
//每个商品总价
|
|
|
amount() {
|
|
|
var that = this
|
|
|
var goodsList = that.data.goodsList
|
|
|
var promotion = that.data.promotion
|
|
|
var vip = that.data.is_vip * 1
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
for (let v in ele.list) {
|
|
|
console.log("进来了goodsList")
|
|
|
if (vip == 1) {
|
|
|
var price = ele.list[v].vip_price
|
|
|
price = price.substring(0, price.length - 3) * 1
|
|
|
ele.list[v].goods_price = ele.list[v].number * price
|
|
|
} else {
|
|
|
var price = ele.list[v].price
|
|
|
price = price.substring(0, price.length - 3) * 1
|
|
|
ele.list[v].goods_price = ele.list[v].number * price
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
promotion.forEach(function(ele, index) {
|
|
|
for (let v in ele.list) {
|
|
|
if (vip == 1) {
|
|
|
var price = ele.list[v].vip_price
|
|
|
price = price.substring(0, price.length - 3) * 1
|
|
|
ele.list[v].goods_price = ele.list[v].number * price
|
|
|
} else {
|
|
|
var price = ele.list[v].price
|
|
|
price = price.substring(0, price.length - 3) * 1
|
|
|
ele.list[v].goods_price = ele.list[v].number * price
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
//totalPrice
|
|
|
totalPrice() {
|
|
|
var that = this;
|
|
|
var goodsList = that.data.goodsList;
|
|
|
var promotion = that.data.promotion;
|
|
|
var price = 0;
|
|
|
var price2 = 0;
|
|
|
var price3 = 0;
|
|
|
var shipPrice = 0;
|
|
|
var str_price = 0;
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
for (var i in ele.list) {
|
|
|
if (ele.list[i].flag) {
|
|
|
if (that.data.is_vip == 1) {
|
|
|
str_price = ele.list[i].vip_price;
|
|
|
} else {
|
|
|
str_price = ele.list[i].price;
|
|
|
}
|
|
|
str_price = str_price.substring(0, str_price.length - 3);
|
|
|
str_price = str_price * 1 * ele.list[i].number
|
|
|
price = price + str_price;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
promotion.forEach(function(ele, index) {
|
|
|
for (var i in ele.list) {
|
|
|
if (ele.list[i].flag) {
|
|
|
if (that.data.is_vip == 1) {
|
|
|
str_price = ele.list[i].vip_price;
|
|
|
} else {
|
|
|
str_price = ele.list[i].price;
|
|
|
}
|
|
|
str_price = str_price.substring(0, str_price.length - 3);
|
|
|
str_price = str_price * 1 * ele.list[i].number
|
|
|
price2 = price2 + str_price;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
price3 = price + price2;
|
|
|
if (price3 > that.data.shipment.free) {
|
|
|
shipPrice = 0
|
|
|
} else {
|
|
|
shipPrice = this.data.shipment.price
|
|
|
}
|
|
|
var ship_balance = that.data.shipment.free * 1 - price3
|
|
|
if (ship_balance <= 0) {
|
|
|
ship_balance = 0
|
|
|
}
|
|
|
let price4 = price3
|
|
|
let price5 = price3 * 1 + shipPrice * 1
|
|
|
that.setData({
|
|
|
totalPrice: price5,
|
|
|
chuandi: price5,
|
|
|
shipPrice: shipPrice,
|
|
|
ship_balance: ship_balance
|
|
|
});
|
|
|
},
|
|
|
//del_btn删除购物车
|
|
|
del_btn() {
|
|
|
let that = this
|
|
|
let url = '/wxapp/cart/delCart '
|
|
|
let goodsList = that.data.goodsList;
|
|
|
let promotion = that.data.promotion;
|
|
|
let ids = [];
|
|
|
let new_ids = []
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
if (ele.list[i].flag) {
|
|
|
let id = ele.list[i].id
|
|
|
new_ids = ids.push(id)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
promotion.forEach(function(ele, index) {
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
if (ele.list[i].flag) {
|
|
|
let id = ele.list[i].id
|
|
|
new_ids = ids.push(id)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
let params = {
|
|
|
ids: ids
|
|
|
}
|
|
|
app.post(url, params).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
wx.showToast({
|
|
|
title: '删除成功',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
this.totalPrice();
|
|
|
let a=this.data.shipment.free
|
|
|
this.setData({
|
|
|
ship_balance:a,
|
|
|
all_both_choose:false,
|
|
|
totalPrice:0
|
|
|
})
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '请先选择要删除的商品',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
});
|
|
|
this.fetchCartList();
|
|
|
this.choose();
|
|
|
this.choose2();
|
|
|
this.totalPrice();
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
|
|
|
onLoad: function(options) {
|
|
|
this.fetchUser();
|
|
|
},
|
|
|
// 再逛逛
|
|
|
get_return(){
|
|
|
get_return() {
|
|
|
wx.switchTab({
|
|
|
url: '../../pages/index/index'
|
|
|
});
|
|
|
},
|
|
|
//购物车结算
|
|
|
settleAccountGoods() {
|
|
|
var id_arr = [];
|
|
|
var id_arr2 = [];
|
|
|
var id_arr1 = [];
|
|
|
var goodsList = this.data.goodsList;
|
|
|
var promotion = this.data.promotion;
|
|
|
var listlist = this.data.listlist
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
for (var i in ele.list) {
|
|
|
if (ele.list[i].flag) {
|
|
|
id_arr1.push(ele.list[i].id);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
promotion.forEach(function(ele, index) {
|
|
|
for (var i in ele.list) {
|
|
|
if (ele.list[i].flag) {
|
|
|
id_arr2.push(ele.list[i].id);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
if (id_arr1.length == 0 && id_arr2.length != 0) {
|
|
|
id_arr = id_arr2
|
|
|
}
|
|
|
if (id_arr2.length == 0 && id_arr1.length != 0) {
|
|
|
id_arr = id_arr1
|
|
|
}
|
|
|
if (id_arr1.length != 0 && id_arr2.length != 0) {
|
|
|
id_arr = id_arr1.concat(id_arr2);
|
|
|
}
|
|
|
if (id_arr1.length == 0 && id_arr2.length == 0) {
|
|
|
wx.showToast({
|
|
|
title: '请选择商品',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return;
|
|
|
}
|
|
|
if (id_arr2.length != 0 && id_arr2.length < 2) {
|
|
|
wx.showToast({
|
|
|
title: '促销商品至少选择两个商品',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return;
|
|
|
}
|
|
|
var id_str = id_arr.join(',');
|
|
|
var jiesuanjia=''
|
|
|
var jianjia=listlist.minimum_price - this.data.chuandi
|
|
|
var yunfeijia = this.data.shipPrice
|
|
|
if (jianjia >= yunfeijia){
|
|
|
wx.navigateTo({
|
|
|
url: '../my/settle_account/settle_account?id=' + id_str + '&price=' + this.data.chuandi,
|
|
|
})
|
|
|
}else{
|
|
|
wx.showToast({
|
|
|
title: '商品实满'+listlist.minimum_price+'元起送',
|
|
|
icon:'none'
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
//选中商品
|
|
|
choose(e) {
|
|
|
var that = this;
|
|
|
var id = e.currentTarget.dataset.id;
|
|
|
var indexs = e.currentTarget.dataset.index;
|
|
|
var cellindex=e.currentTarget.dataset.cell
|
|
|
var goodsList = this.data.goodsList
|
|
|
var promotion = this.data.promotion
|
|
|
var all_both_choose=that.data.all_both_choose
|
|
|
var n = 0
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
if(cellindex==index){
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
if (indexs == i) {
|
|
|
ele.list[indexs].flag = !ele.list[indexs].flag
|
|
|
}
|
|
|
if (ele.list[i].flag) {
|
|
|
n++
|
|
|
}
|
|
|
if (n == ele.list.length) {
|
|
|
ele.chooseAll = true
|
|
|
} else{
|
|
|
ele.chooseAll = false
|
|
|
}
|
|
|
that.last_both_choose()
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
that.setData({
|
|
|
goodsId: id,
|
|
|
goodsList: goodsList,
|
|
|
});
|
|
|
that.totalPrice();
|
|
|
},
|
|
|
choose2(e) {
|
|
|
var that = this;
|
|
|
var id = e.currentTarget.dataset.id;
|
|
|
var indexs = e.currentTarget.dataset.index;
|
|
|
var cellindex=e.currentTarget.dataset.cell
|
|
|
var promotion = this.data.promotion
|
|
|
var goodsList=that.data.goodsList
|
|
|
var all_both_choose=that.data.all_both_choose
|
|
|
var n = 0
|
|
|
promotion.forEach(function (ele, index) {
|
|
|
if(cellindex==index){
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
if (indexs == i) {
|
|
|
ele.list[indexs].flag = !ele.list[indexs].flag
|
|
|
}
|
|
|
if (ele.list[i].flag) {
|
|
|
n++
|
|
|
}
|
|
|
if (n == ele.list.length) {
|
|
|
ele.chooseAll = true
|
|
|
} else {
|
|
|
ele.chooseAll = false
|
|
|
}
|
|
|
that.last_both_choose();
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
that.setData({
|
|
|
goodsId: id,
|
|
|
promotion: promotion,
|
|
|
});
|
|
|
that.totalPrice();
|
|
|
},
|
|
|
//减少对应的数量
|
|
|
dec(e) {
|
|
|
var indexs = e.currentTarget.dataset.index
|
|
|
var cellindex = e.currentTarget.dataset.cellindex
|
|
|
var goodsList = this.data.goodsList
|
|
|
var number = goodsList[cellindex].list[indexs].number
|
|
|
if (number <= 1) {
|
|
|
wx.showToast({
|
|
|
title: '已经是最少了哦',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return;
|
|
|
} else {
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
if(cellindex==index){
|
|
|
for (let v in ele.list) {
|
|
|
if (v == indexs) {
|
|
|
console.log(number)
|
|
|
number = ele.list[indexs].number - 1;
|
|
|
ele.list[indexs].number = ele.list[indexs].number - 1;
|
|
|
console.log(number)
|
|
|
let url = '/wxapp/cart/editCartNumber'
|
|
|
let params = {
|
|
|
id: ele.list[indexs].id,
|
|
|
num: number
|
|
|
}
|
|
|
app.post(url, params).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: '修改失败',
|
|
|
icon: 'none'
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
this.amount();
|
|
|
this.setData({
|
|
|
goodsList: goodsList,
|
|
|
})
|
|
|
this.totalPrice();
|
|
|
}
|
|
|
},
|
|
|
dec2(e) {
|
|
|
var indexs = e.currentTarget.dataset.index
|
|
|
var cellindex = e.currentTarget.dataset.cellindex
|
|
|
var promotion = this.data.promotion
|
|
|
var number2 = promotion[cellindex].list[indexs].number
|
|
|
if (number2 <= 1) {
|
|
|
wx.showToast({
|
|
|
title: '已经是最少了哦',
|
|
|
icon:'none'
|
|
|
})
|
|
|
return;
|
|
|
} else {
|
|
|
promotion.forEach(function(ele, index) {
|
|
|
if(cellindex==index){
|
|
|
for (let v in ele.list) {
|
|
|
if (v == indexs) {
|
|
|
number2 = ele.list[indexs].number - 1;
|
|
|
ele.list[indexs].number = ele.list[indexs].number - 1;
|
|
|
let url = '/wxapp/cart/editCartNumber'
|
|
|
let params = {
|
|
|
id: ele.list[indexs].id,
|
|
|
num: number2
|
|
|
}
|
|
|
app.post(url, params).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
this.amount();
|
|
|
this.setData({
|
|
|
promotion: promotion
|
|
|
})
|
|
|
this.totalPrice();
|
|
|
}
|
|
|
},
|
|
|
//是否全选
|
|
|
last_both_choose(){
|
|
|
let that=this
|
|
|
let goodsList=that.data.goodsList
|
|
|
let promotion = that.data.promotion
|
|
|
let i=goodsList.length+promotion.length
|
|
|
let all_both_choose=that.data.all_both_choose
|
|
|
let j=0
|
|
|
goodsList.forEach(function(ele){
|
|
|
if(ele.chooseAll){
|
|
|
j++
|
|
|
}
|
|
|
})
|
|
|
promotion.forEach(function (ele) {
|
|
|
if (ele.chooseAll) {
|
|
|
j++
|
|
|
}
|
|
|
})
|
|
|
if(i==j){
|
|
|
console.log('全选success')
|
|
|
all_both_choose=true
|
|
|
}else{
|
|
|
all_both_choose=false
|
|
|
}
|
|
|
that.setData({
|
|
|
all_both_choose:all_both_choose
|
|
|
})
|
|
|
},
|
|
|
//选中所有商品
|
|
|
chooseAll() {
|
|
|
var that = this;
|
|
|
var goodsList = that.data.goodsList;
|
|
|
var promotion=that.data.promotion
|
|
|
var all_both_choose = that.data.all_both_choose
|
|
|
var n = that.data.n
|
|
|
var m=0
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
if (ele.chooseAll) {
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
ele.list[i].flag = false
|
|
|
}
|
|
|
ele.chooseAll = false
|
|
|
n--
|
|
|
that.setData({
|
|
|
goodsList: goodsList
|
|
|
})
|
|
|
} else {
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
ele.list[i].flag = true
|
|
|
}
|
|
|
ele.chooseAll = true
|
|
|
n++
|
|
|
that.setData({
|
|
|
goodsList: goodsList
|
|
|
})
|
|
|
}
|
|
|
that.last_both_choose();
|
|
|
});
|
|
|
// m=goodsList.length+promotion.length
|
|
|
// console.log("商品"+n)
|
|
|
// if(n==m){
|
|
|
// all_both_choose=true
|
|
|
// }else{
|
|
|
// all_both_choose=false
|
|
|
// }
|
|
|
that.setData({
|
|
|
// all_both_choose:all_both_choose,
|
|
|
// n:n
|
|
|
})
|
|
|
that.totalPrice();
|
|
|
},
|
|
|
chooseAll2() {
|
|
|
var that = this;
|
|
|
var promotion = that.data.promotion;
|
|
|
var goodsList=that.data.goodsList
|
|
|
var all_both_choose = that.data.all_both_choose
|
|
|
var n = that.data.n
|
|
|
var m=0
|
|
|
promotion.forEach(function (ele, index) {
|
|
|
if (ele.chooseAll) {
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
ele.list[i].flag = false
|
|
|
}
|
|
|
ele.chooseAll = false
|
|
|
n--
|
|
|
that.setData({
|
|
|
promotion: promotion
|
|
|
})
|
|
|
} else {
|
|
|
for (let i = 0; i < ele.list.length; i++) {
|
|
|
ele.list[i].flag = true
|
|
|
}
|
|
|
ele.chooseAll = true
|
|
|
n++
|
|
|
that.setData({
|
|
|
promotion: promotion
|
|
|
})
|
|
|
}
|
|
|
that.last_both_choose();
|
|
|
});
|
|
|
m=goodsList.length+promotion.length
|
|
|
console.log("促销" + n)
|
|
|
console.log("促销" + m)
|
|
|
if(m==n){
|
|
|
all_both_choose=true
|
|
|
}
|
|
|
else{
|
|
|
all_both_choose=false
|
|
|
}
|
|
|
that.setData({
|
|
|
// all_both_choose:all_both_choose,
|
|
|
n:n
|
|
|
})
|
|
|
that.totalPrice();
|
|
|
},
|
|
|
//增加商品数量
|
|
|
add(e) {
|
|
|
var indexs = e.currentTarget.dataset.index
|
|
|
var cellindex = e.currentTarget.dataset.cellindex
|
|
|
var goodsList = this.data.goodsList
|
|
|
var number2 = goodsList[cellindex].list[indexs].number
|
|
|
console.log(number2+"这个十二号")
|
|
|
var limit=e.currentTarget.dataset.limit
|
|
|
if(limit>number2||limit==0){
|
|
|
goodsList.forEach(function (ele, index) {
|
|
|
if (cellindex == index) {
|
|
|
for (let v in ele.list) {
|
|
|
if (v == indexs) {
|
|
|
console.log(number2)
|
|
|
number2 = ele.list[indexs].number + 1
|
|
|
ele.list[indexs].number = ele.list[indexs].number + 1
|
|
|
console.log(number2)
|
|
|
let url = '/wxapp/cart/editCartNumber'
|
|
|
let params = {
|
|
|
id: ele.list[indexs].id,
|
|
|
num: number2
|
|
|
}
|
|
|
app.post(url, params).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
console.log(r)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
this.amount();
|
|
|
this.setData({
|
|
|
goodsList: goodsList,
|
|
|
})
|
|
|
this.totalPrice();
|
|
|
}else{
|
|
|
wx.showToast({
|
|
|
title: '限购'+limit+'件',
|
|
|
icon:'none'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
},
|
|
|
add2(e) {
|
|
|
var indexs = e.currentTarget.dataset.index
|
|
|
var cellindex = e.currentTarget.dataset.cellindex
|
|
|
var promotion = this.data.promotion
|
|
|
var number2 = promotion[cellindex].list[indexs].number
|
|
|
var limit = e.currentTarget.dataset.limit
|
|
|
if(limit>number2||limit==0){
|
|
|
promotion.forEach(function (ele, index) {
|
|
|
if (cellindex == index) {
|
|
|
for (let v in ele.list) {
|
|
|
if (v == indexs) {
|
|
|
number2 = ele.list[indexs].number + 1
|
|
|
ele.list[indexs].number = ele.list[indexs].number + 1
|
|
|
let url = '/wxapp/cart/editCartNumber'
|
|
|
let params = {
|
|
|
id: ele.list[indexs].id,
|
|
|
num: number2
|
|
|
}
|
|
|
app.post(url, params).then(r => {
|
|
|
if (r.code == 1) {
|
|
|
console.log(r)
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
this.amount();
|
|
|
this.setData({
|
|
|
promotion: promotion
|
|
|
})
|
|
|
this.totalPrice();
|
|
|
}else{
|
|
|
wx.showToast({
|
|
|
title: '限购'+limit+'件',
|
|
|
icon:'none'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
},
|
|
|
|
|
|
//去结算
|
|
|
account() {
|
|
|
var that = this
|
|
|
var goodsList = that.data.goodsList
|
|
|
var id_arr = [];
|
|
|
goodsList.forEach(function(ele, index) {
|
|
|
for (var i in ele.list) {
|
|
|
// console.log(ele.list[i].flag);
|
|
|
if (ele.list[i].flag) {
|
|
|
id_arr.push(ele.list[i].id);
|
|
|
}
|
|
|
}
|
|
|
var id_str = id_arr.join(',');
|
|
|
});
|
|
|
wx.navigateTo({
|
|
|
url: '../my/settle_account/settle_account?id=' + id_arr + '&price=' + that.data.totalPrice,
|
|
|
})
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady: function () {
|
|
|
onReady: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
|
|
|
onShow: function() {
|
|
|
let a=this.data.shipment.free
|
|
|
this.fetchCartList();
|
|
|
this.setData({
|
|
|
chooseAll: false,
|
|
|
chooseAll2: false,
|
|
|
totalPrice: 0,
|
|
|
all_both_choose: false,
|
|
|
ship_balance:a
|
|
|
})
|
|
|
this.fetchCartNum()
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
onHide: function () {
|
|
|
onHide: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function () {
|
|
|
onUnload: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh: function () {
|
|
|
onPullDownRefresh: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom: function () {
|
|
|
onReachBottom: function() {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
onShareAppMessage: function () {
|
|
|
onShareAppMessage: function() {
|
|
|
|
|
|
}
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|