|
@@ -6,14 +6,14 @@ var app = getApp();
|
|
|
|
|
|
Page({
|
|
|
data: {
|
|
|
- cartGoods00: [],//保税仓数据
|
|
|
- cartGoods02: [],//保税展示数据
|
|
|
- cartGoods10: [],//现场速递数据
|
|
|
- cartGoods11: [],//普通商品
|
|
|
+ cartGoods00: [], //保税仓数据
|
|
|
+ cartGoods02: [], //保税展示数据
|
|
|
+ cartGoods10: [], //现场速递数据
|
|
|
+ cartGoods11: [], //普通商品
|
|
|
cartGoods: [],
|
|
|
validCartList: [],
|
|
|
- goodsBizTypeList: ['保税仓','保税展示','现场速递','普通商品'],
|
|
|
- goodsBizType: '',//货品业务类型
|
|
|
+ goodsBizTypeList: ['保税仓', '保税展示', '现场速递', '普通商品'],
|
|
|
+ goodsBizType: '', //货品业务类型
|
|
|
footprintList: [],
|
|
|
cartTotal: {
|
|
|
"goodsCount": 0,
|
|
@@ -36,15 +36,18 @@ Page({
|
|
|
retailPrice: '',
|
|
|
stockNum: 0,
|
|
|
cartNumber: 0,
|
|
|
+ checkCart: '00',
|
|
|
+ total00: 0,
|
|
|
+ total11: 0
|
|
|
},
|
|
|
- onLoad: function (options) {
|
|
|
+ onLoad: function(options) {
|
|
|
// 页面初始化 options为页面跳转所带来的参数
|
|
|
},
|
|
|
- onReady: function () {
|
|
|
+ onReady: function() {
|
|
|
// 页面渲染完成
|
|
|
|
|
|
},
|
|
|
- onShow: function () {
|
|
|
+ onShow: function() {
|
|
|
// 页面显示
|
|
|
if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
|
|
|
this.getCartList();
|
|
@@ -55,11 +58,38 @@ Page({
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
- onHide: function () {
|
|
|
+ openSortFilter: function(event) {
|
|
|
+ let that = this;
|
|
|
+ let currentId = event.currentTarget.id;
|
|
|
+ switch (currentId) {
|
|
|
+ case 'defaultActivity':
|
|
|
+ that.setData({
|
|
|
+ 'checkCart': '00'
|
|
|
+ });
|
|
|
+ this.getCartList();
|
|
|
+ this.getFootprintList();
|
|
|
+ break;
|
|
|
+ case 'ordActivity':
|
|
|
+ that.setData({
|
|
|
+ 'checkCart': '11'
|
|
|
+ });
|
|
|
+ this.getCartList();
|
|
|
+ this.getFootprintList();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ //综合排序
|
|
|
+ that.setData({
|
|
|
+ 'checkCart': '00'
|
|
|
+ });
|
|
|
+ this.getCartList();
|
|
|
+ this.getFootprintList();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onHide: function() {
|
|
|
// 页面隐藏
|
|
|
|
|
|
},
|
|
|
- onUnload: function () {
|
|
|
+ onUnload: function() {
|
|
|
// 页面关闭
|
|
|
|
|
|
},
|
|
@@ -73,7 +103,9 @@ Page({
|
|
|
cartGoods11: res.data.cart11List,
|
|
|
validCartList: res.data.validCartList,
|
|
|
cartTotal: res.data.cartTotal,
|
|
|
- couponInfoList: res.data.couponInfoList
|
|
|
+ couponInfoList: res.data.couponInfoList,
|
|
|
+ total00: res.data.total00,
|
|
|
+ total11: res.data.total11
|
|
|
});
|
|
|
},
|
|
|
setCheckedData() {
|
|
@@ -96,12 +128,14 @@ Page({
|
|
|
checkedTypeStatus11: that.isCheckedAll()
|
|
|
});
|
|
|
},
|
|
|
- getCartList: function () {//获取购物车数据
|
|
|
+ getCartList: function() { //获取购物车数据
|
|
|
let that = this;
|
|
|
wx.showLoading({
|
|
|
title: '加载中...',
|
|
|
});
|
|
|
- util.request(api.CartList).then(function (res) {
|
|
|
+ util.request(api.CartList, {
|
|
|
+ checkCart: that.data.checkCart
|
|
|
+ }).then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
that.setCommonData(res);
|
|
|
}
|
|
@@ -110,9 +144,9 @@ Page({
|
|
|
that.setCheckedData();
|
|
|
});
|
|
|
},
|
|
|
- isCheckedAll: function () {
|
|
|
+ isCheckedAll: function() {
|
|
|
//判断购物车所有商品是否已全选
|
|
|
- return this.data.cartGoods.every(function (element, index, array) {
|
|
|
+ return this.data.cartGoods.every(function(element, index, array) {
|
|
|
if (element.checked == true) {
|
|
|
return true;
|
|
|
} else {
|
|
@@ -120,19 +154,19 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- isCheckedTypeStatus00: function () {
|
|
|
- //判断该业务类型的购物车商品是否已全选
|
|
|
- return this.data.cartGoods00.every(function (element, index, array) {
|
|
|
- if (element.checked == true) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- });
|
|
|
+ isCheckedTypeStatus00: function() {
|
|
|
+ //判断该业务类型的购物车商品是否已全选
|
|
|
+ return this.data.cartGoods00.every(function(element, index, array) {
|
|
|
+ if (element.checked == true) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
- isCheckedTypeStatus02: function () {
|
|
|
+ isCheckedTypeStatus02: function() {
|
|
|
//判断该业务类型的购物车商品是否已全选
|
|
|
- return this.data.cartGoods02.every(function (element, index, array) {
|
|
|
+ return this.data.cartGoods02.every(function(element, index, array) {
|
|
|
if (element.checked == true) {
|
|
|
return true;
|
|
|
} else {
|
|
@@ -140,9 +174,9 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- isCheckedTypeStatus10: function () {
|
|
|
+ isCheckedTypeStatus10: function() {
|
|
|
//判断该业务类型的购物车商品是否已全选
|
|
|
- return this.data.cartGoods10.every(function (element, index, array) {
|
|
|
+ return this.data.cartGoods10.every(function(element, index, array) {
|
|
|
if (element.checked == true) {
|
|
|
return true;
|
|
|
} else {
|
|
@@ -150,9 +184,9 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- isCheckedTypeStatus11: function () {
|
|
|
+ isCheckedTypeStatus11: function() {
|
|
|
//判断该业务类型的购物车商品是否已全选
|
|
|
- return this.data.cartGoods11.every(function (element, index, array) {
|
|
|
+ return this.data.cartGoods11.every(function(element, index, array) {
|
|
|
if (element.checked == true) {
|
|
|
return true;
|
|
|
} else {
|
|
@@ -160,19 +194,20 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- toIndexPage: function () {
|
|
|
+ toIndexPage: function() {
|
|
|
wx.switchTab({
|
|
|
url: "/pages/index/index"
|
|
|
});
|
|
|
},
|
|
|
- checkedItem: function (event) {
|
|
|
+ checkedItem: function(event) {
|
|
|
let itemIndex = event.target.dataset.itemIndex;
|
|
|
let that = this;
|
|
|
|
|
|
util.request(api.CartChecked, {
|
|
|
productIds: that.data.cartGoods[itemIndex].product_id,
|
|
|
- isChecked: that.data.cartGoods[itemIndex].checked ? 0 : 1
|
|
|
- }, 'POST').then(function (res) {
|
|
|
+ isChecked: that.data.cartGoods[itemIndex].checked ? 0 : 1,
|
|
|
+ checkCart: that.data.checkCart
|
|
|
+ }, 'POST').then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
that.setCommonData(res);
|
|
|
}
|
|
@@ -180,9 +215,9 @@ Page({
|
|
|
});
|
|
|
|
|
|
},
|
|
|
- getCheckedGoodsCount: function () {
|
|
|
+ getCheckedGoodsCount: function() {
|
|
|
let checkedGoodsCount = 0;
|
|
|
- this.data.cartGoods.forEach(function (v) {
|
|
|
+ this.data.cartGoods.forEach(function(v) {
|
|
|
if (v.checked === true) {
|
|
|
checkedGoodsCount += v.number;
|
|
|
}
|
|
@@ -190,22 +225,22 @@ Page({
|
|
|
console.log(checkedGoodsCount);
|
|
|
return checkedGoodsCount;
|
|
|
},
|
|
|
- checkedAll: function () {
|
|
|
+ checkedAll: function() {
|
|
|
let that = this;
|
|
|
- var productIds = this.data.cartGoods.map(function (v) {
|
|
|
+ var productIds = this.data.cartGoods.map(function(v) {
|
|
|
return v.product_id;
|
|
|
});
|
|
|
util.request(api.CartChecked, {
|
|
|
productIds: productIds.join(','),
|
|
|
isChecked: that.isCheckedAll() ? 0 : 1
|
|
|
- }, 'POST').then(function (res) {
|
|
|
+ }, 'POST').then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
that.setCommonData(res);
|
|
|
}
|
|
|
that.setCheckedAllData();
|
|
|
});
|
|
|
},
|
|
|
- checkedAllGoodType: function (e) {
|
|
|
+ checkedAllGoodType: function(e) {
|
|
|
let that = this;
|
|
|
let goodsBizType = e.target.dataset.goodsBizType;
|
|
|
let isCheckedTypeStatu;
|
|
@@ -224,14 +259,14 @@ Page({
|
|
|
util.request(api.CartChecked, {
|
|
|
isChecked: isCheckedTypeStatu ? 0 : 1,
|
|
|
goodsBizType: goodsBizType
|
|
|
- }, 'POST').then(function (res) {
|
|
|
+ }, 'POST').then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
that.setCommonData(res);
|
|
|
}
|
|
|
|
|
|
if (goodsBizType == '00') {
|
|
|
- that.setData({
|
|
|
- checkedTypeStatus00: that.isCheckedTypeStatus00()
|
|
|
+ that.setData({
|
|
|
+ checkedTypeStatus00: that.isCheckedTypeStatus00()
|
|
|
});
|
|
|
}
|
|
|
if (goodsBizType == '02') {
|
|
@@ -254,15 +289,16 @@ Page({
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
- updateCart: function (productId, goodsId, number, beforeNumber, id, itemIndex) {
|
|
|
+ updateCart: function(productId, goodsId, number, beforeNumber, id, itemIndex) {
|
|
|
let that = this;
|
|
|
|
|
|
util.request(api.CartUpdate, {
|
|
|
productId: productId,
|
|
|
goodsId: goodsId,
|
|
|
number: number,
|
|
|
- id: id
|
|
|
- }, 'POST').then(function (res) {
|
|
|
+ id: id,
|
|
|
+ checkCart: that.data.checkCart
|
|
|
+ }, 'POST').then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
// console.log(res.data);
|
|
|
that.setCommonData(res);
|
|
@@ -283,7 +319,7 @@ Page({
|
|
|
that.setCheckedData();
|
|
|
});
|
|
|
},
|
|
|
- cutNumber: function (event) {
|
|
|
+ cutNumber: function(event) {
|
|
|
let itemIndex = event.target.dataset.itemIndex;
|
|
|
let cartItem = this.data.cartGoods[itemIndex];
|
|
|
let beforeNumber = cartItem.number;
|
|
@@ -294,7 +330,7 @@ Page({
|
|
|
});
|
|
|
this.updateCart(cartItem.product_id, cartItem.goods_id, number, beforeNumber, cartItem.id, itemIndex);
|
|
|
},
|
|
|
- addNumber: function (event) {
|
|
|
+ addNumber: function(event) {
|
|
|
let itemIndex = event.target.dataset.itemIndex;
|
|
|
let cartItem = this.data.cartGoods[itemIndex];
|
|
|
let beforeNumber = cartItem.number;
|
|
@@ -305,12 +341,12 @@ Page({
|
|
|
});
|
|
|
this.updateCart(cartItem.product_id, cartItem.goods_id, number, beforeNumber, cartItem.id, itemIndex);
|
|
|
},
|
|
|
- checkoutOrder: function () {
|
|
|
+ checkoutOrder: function() {
|
|
|
//获取已选择的商品
|
|
|
let that = this;
|
|
|
util.request(api.getCurUser, {
|
|
|
userInfo: app.globalData.userInfo
|
|
|
- }, 'POST').then(function (res) {
|
|
|
+ }, 'POST').then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
// console.log('that.data.mobile:' + res.data.mobile);
|
|
|
if (res.data.mobile == '' || res.data.mobile == null) {
|
|
@@ -319,7 +355,7 @@ Page({
|
|
|
confirmColor: '#b4282d',
|
|
|
showCancel: false,
|
|
|
content: '您的手机号码未绑定,请先绑定手机号再进行购买',
|
|
|
- success: function (res) {
|
|
|
+ success: function(res) {
|
|
|
if (res.confirm) {
|
|
|
wx.navigateTo({
|
|
|
url: '../../pages/auth/newuser/newuser'
|
|
@@ -328,7 +364,7 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
- var checkedGoods = that.data.cartGoods.filter(function (element, index, array) {
|
|
|
+ var checkedGoods = that.data.cartGoods.filter(function(element, index, array) {
|
|
|
if (element.checked == true) {
|
|
|
return true;
|
|
|
} else {
|
|
@@ -340,13 +376,13 @@ Page({
|
|
|
return false;
|
|
|
}
|
|
|
wx.navigateTo({
|
|
|
- url: '../shopping/checkout/checkout'
|
|
|
+ url: '../shopping/checkout/checkout?checkCart=' + that.data.checkCart
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- deleteCart: function (event) {
|
|
|
+ deleteCart: function(event) {
|
|
|
//获取已选择的商品
|
|
|
let that = this;
|
|
|
|
|
@@ -356,11 +392,12 @@ Page({
|
|
|
wx.showModal({
|
|
|
title: '',
|
|
|
content: '确定要删除' + goodsName + '?',
|
|
|
- success: function (res) {
|
|
|
+ success: function(res) {
|
|
|
if (res.confirm) {
|
|
|
util.request(api.CartDelete, {
|
|
|
- cartId: cartId
|
|
|
- }, 'POST').then(function (res) {
|
|
|
+ cartId: cartId,
|
|
|
+ checkCart: that.data.checkCart
|
|
|
+ }, 'POST').then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
that.setCommonData(res);
|
|
|
}
|
|
@@ -373,7 +410,10 @@ Page({
|
|
|
},
|
|
|
getFootprintList() {
|
|
|
let that = this;
|
|
|
- util.request(api.GuessFootprintList, { storeId: wx.getStorageSync('storeId') },).then(function (res) {
|
|
|
+ util.request(api.GuessFootprintList, {
|
|
|
+ storeId: wx.getStorageSync('storeId'),
|
|
|
+ checkCart: that.data.checkCart
|
|
|
+ }, ).then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
that.setData({
|
|
|
footprintList: res.data.list
|
|
@@ -381,12 +421,12 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- switchAttrPop: function () {
|
|
|
+ switchAttrPop: function() {
|
|
|
this.setData({
|
|
|
openAttr: !this.data.openAttr
|
|
|
})
|
|
|
},
|
|
|
- clickSkuValue: function (event) {
|
|
|
+ clickSkuValue: function(event) {
|
|
|
let that = this;
|
|
|
let specValueId = event.currentTarget.dataset.valueId;
|
|
|
let index = event.currentTarget.dataset.index;
|
|
@@ -409,25 +449,27 @@ Page({
|
|
|
//重新计算spec改变后的信息
|
|
|
goodsUtil.changeSpecInfo(that);
|
|
|
},
|
|
|
- cutNumber2: function () {
|
|
|
+ cutNumber2: function() {
|
|
|
this.setData({
|
|
|
number: (this.data.number - 1 > 1) ? this.data.number - 1 : 1
|
|
|
});
|
|
|
},
|
|
|
- addNumber2: function () {
|
|
|
+ addNumber2: function() {
|
|
|
this.setData({
|
|
|
number: this.data.number + 1
|
|
|
});
|
|
|
},
|
|
|
|
|
|
//购物车增加
|
|
|
- addCart: function (e) {
|
|
|
+ addCart: function(e) {
|
|
|
let that = this;
|
|
|
that.setData({
|
|
|
- number:1
|
|
|
+ number: 1
|
|
|
});
|
|
|
var goodsId = e.currentTarget.dataset.goodsId;
|
|
|
- util.request(api.GoodsSku, { goodsId: goodsId }).then(function (res) {
|
|
|
+ util.request(api.GoodsSku, {
|
|
|
+ goodsId: goodsId
|
|
|
+ }).then(function(res) {
|
|
|
if (res.errno === 0 && null != res.data) {
|
|
|
that.setData({
|
|
|
goodsVo: res.data.goodsVo,
|
|
@@ -453,7 +495,7 @@ Page({
|
|
|
});
|
|
|
},
|
|
|
//购物车增加
|
|
|
- addToCart: function () {
|
|
|
+ addToCart: function() {
|
|
|
let that = this;
|
|
|
var goodsId = that.data.goodsVo.id;
|
|
|
//提示选择完整规格
|
|
@@ -479,8 +521,9 @@ Page({
|
|
|
util.request(api.CartAdd, {
|
|
|
goodsId: goodsId,
|
|
|
productId: checkedProduct[0].id,
|
|
|
- number: this.data.number
|
|
|
- }, 'POST').then(function (res) {
|
|
|
+ number: this.data.number,
|
|
|
+ checkCart: that.data.checkCart
|
|
|
+ }, 'POST').then(function(res) {
|
|
|
if (res.errno === 0 && null != res.data) {
|
|
|
wx.showToast({
|
|
|
title: '添加成功',
|
|
@@ -501,14 +544,16 @@ Page({
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- deleteValidCart: function () {//获取购物车数据
|
|
|
+ deleteValidCart: function() { //获取购物车数据
|
|
|
let that = this;
|
|
|
wx.showModal({
|
|
|
title: '',
|
|
|
content: '确定要清空所有失效商品?',
|
|
|
- success: function (res) {
|
|
|
+ success: function(res) {
|
|
|
if (res.confirm) {
|
|
|
- util.request(api.deleteValidCart).then(function (res) {
|
|
|
+ util.request(api.deleteValidCart, {
|
|
|
+ checkCart: that.data.checkCart
|
|
|
+ }).then(function(res) {
|
|
|
if (res.errno === 0) {
|
|
|
that.setCommonData(res);
|
|
|
} else {
|