|
|
@@ -91,15 +91,15 @@
|
|
|
<!-- 列表 -->
|
|
|
<view class="cart-list">
|
|
|
<block v-for="(item, index) in vipcartList" :key="item.id">
|
|
|
- <view class="cart-item" :class="{ 'b-b': index !== cartList.length - 1 }">
|
|
|
+ <view class="cart-item" :class="{ 'b-b': index !== vipcartList.length - 1 }">
|
|
|
<view class="image-wrapper">
|
|
|
<image
|
|
|
:src="item.productInfo.image"
|
|
|
:class="[item.loaded]"
|
|
|
mode="aspectFill"
|
|
|
lazy-load
|
|
|
- @load="onImageLoad('cartList', index)"
|
|
|
- @error="onImageError('cartList', index)"
|
|
|
+ @load="onImageLoad('vipcartList', index)"
|
|
|
+ @error="onImageError('vipcartList', index)"
|
|
|
></image>
|
|
|
<view class="iconfont iconroundcheckfill checkbox" :class="{ checked: item.checked }" @click="check('item', index)"></view>
|
|
|
</view>
|
|
|
@@ -173,6 +173,13 @@ export default {
|
|
|
if (this.empty !== empty) {
|
|
|
this.empty = empty;
|
|
|
}
|
|
|
+ },
|
|
|
+ //显示空白页
|
|
|
+ vipcartList(e) {
|
|
|
+ let empty = e.length === 0 ? true : false;
|
|
|
+ if (this.vipempty !== empty) {
|
|
|
+ this.vipempty = empty;
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -208,25 +215,50 @@ export default {
|
|
|
let obj = this;
|
|
|
getCartList({ vip: obj.isvip })
|
|
|
.then(function(e) {
|
|
|
- // 获取当前购物车物品增加数量
|
|
|
- let nub = obj.cartList.length;
|
|
|
- // 获取之前对象数组
|
|
|
- let aArray = obj.cartList.reverse();
|
|
|
- // 获取返回数据对象数组
|
|
|
- let bArray = e.data.valid.reverse();
|
|
|
- obj.cartList = bArray
|
|
|
- .map((item, ind) => {
|
|
|
- // 设置返回数据默认为勾选状态
|
|
|
- item.checked = true;
|
|
|
- // 获取相同数组之前对象的数据
|
|
|
- let carlist = aArray[ind];
|
|
|
- // 判断之前是否已经加载完毕
|
|
|
- if (carlist && carlist.loaded == 'loaded') {
|
|
|
- item.loaded = 'loaded';
|
|
|
- }
|
|
|
- return item;
|
|
|
- })
|
|
|
- .reverse();
|
|
|
+ if(obj.currentIndex == 0){
|
|
|
+ let list = obj.cartList;
|
|
|
+ // 获取当前购物车物品增加数量
|
|
|
+ let nub = obj.cartList.length;
|
|
|
+ // 获取之前对象数组
|
|
|
+ let aArray = obj.cartList.reverse();
|
|
|
+ // 获取返回数据对象数组
|
|
|
+ let bArray = e.data.valid.reverse();
|
|
|
+ obj.cartList = bArray
|
|
|
+ .map((item, ind) => {
|
|
|
+ // 设置返回数据默认为勾选状态
|
|
|
+ item.checked = true;
|
|
|
+ // 获取相同数组之前对象的数据
|
|
|
+ let carlist = aArray[ind];
|
|
|
+ // 判断之前是否已经加载完毕
|
|
|
+ if (carlist && carlist.loaded == 'loaded') {
|
|
|
+ item.loaded = 'loaded';
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ })
|
|
|
+ .reverse();
|
|
|
+ }
|
|
|
+ if(obj.currentIndex == 1){
|
|
|
+ let list = obj.vipcartList;
|
|
|
+ // 获取当前购物车物品增加数量
|
|
|
+ let nub = obj.vipcartList.length;
|
|
|
+ // 获取之前对象数组
|
|
|
+ let aArray = obj.vipcartList.reverse();
|
|
|
+ // 获取返回数据对象数组
|
|
|
+ let bArray = e.data.valid.reverse();
|
|
|
+ obj.vipcartList = bArray
|
|
|
+ .map((item, ind) => {
|
|
|
+ // 设置返回数据默认为勾选状态
|
|
|
+ item.checked = true;
|
|
|
+ // 获取相同数组之前对象的数据
|
|
|
+ let carlist = aArray[ind];
|
|
|
+ // 判断之前是否已经加载完毕
|
|
|
+ if (carlist && carlist.loaded == 'loaded') {
|
|
|
+ item.loaded = 'loaded';
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ })
|
|
|
+ .reverse();
|
|
|
+ }
|
|
|
obj.calcTotal(); //计算总价
|
|
|
})
|
|
|
.catch(function(e) {
|
|
|
@@ -251,20 +283,36 @@ export default {
|
|
|
},
|
|
|
//选中状态处理
|
|
|
check(type, index) {
|
|
|
- if (type === 'item') {
|
|
|
- this.cartList[index].checked = !this.cartList[index].checked;
|
|
|
- } else {
|
|
|
- const checked = !this.allChecked;
|
|
|
- const list = this.cartList;
|
|
|
- list.forEach(item => {
|
|
|
- item.checked = checked;
|
|
|
- });
|
|
|
- this.allChecked = checked;
|
|
|
+ if(this.currentIndex == '0'){
|
|
|
+ if (type === 'item') {
|
|
|
+ this.cartList[index].checked = !this.cartList[index].checked;
|
|
|
+ } else {
|
|
|
+ const checked = !this.allChecked;
|
|
|
+ const list = this.cartList;
|
|
|
+ list.forEach(item => {
|
|
|
+ item.checked = checked;
|
|
|
+ });
|
|
|
+ this.allChecked = checked;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(this.currentIndex == '1'){
|
|
|
+ if (type === 'item') {
|
|
|
+ this.vipcartList[index].checked = !this.vipcartList[index].checked;
|
|
|
+ } else {
|
|
|
+ const checked = !this.vipallChecked;
|
|
|
+ const list = this.vipcartList;
|
|
|
+ list.forEach(item => {
|
|
|
+ item.checked = checked;
|
|
|
+ });
|
|
|
+ this.vipallChecked = checked;
|
|
|
+ }
|
|
|
}
|
|
|
this.calcTotal(type);
|
|
|
},
|
|
|
navClick(index) {
|
|
|
this.currentIndex = index;
|
|
|
+ this.isvip = index;
|
|
|
+ this.loadData()
|
|
|
},
|
|
|
//数量
|
|
|
numberChange(data) {
|
|
|
@@ -324,43 +372,56 @@ export default {
|
|
|
calcTotal() {
|
|
|
if(this.currentIndex == '0'){
|
|
|
let list = this.cartList;
|
|
|
- }
|
|
|
- if(this.currentIndex == '1') {
|
|
|
- let list = this.vipcartList;
|
|
|
- }
|
|
|
- if (list.length === 0) {
|
|
|
- this.empty = true;
|
|
|
- return;
|
|
|
- }
|
|
|
- let total = 0;
|
|
|
- let checked = true;
|
|
|
- list.forEach(item => {
|
|
|
- if (item.checked === true) {
|
|
|
- total += item.productInfo.price * item.cart_num;
|
|
|
- } else if (checked === true) {
|
|
|
- checked = false;
|
|
|
+ if (list.length === 0) {
|
|
|
+ this.empty = true;
|
|
|
+ return;
|
|
|
}
|
|
|
- });
|
|
|
- if(this.currentIndex == '0'){
|
|
|
+ let total = 0;
|
|
|
+ let checked = true;
|
|
|
+ list.forEach(item => {
|
|
|
+ if (item.checked === true) {
|
|
|
+ total += item.productInfo.price * item.cart_num;
|
|
|
+ } else if (checked === true) {
|
|
|
+ checked = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
this.allChecked = checked;
|
|
|
this.total = Number(total.toFixed(2));
|
|
|
}
|
|
|
if(this.currentIndex == '1') {
|
|
|
+ let list = this.vipcartList;
|
|
|
+ if (list.length === 0) {
|
|
|
+ this.vipempty = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let total = 0;
|
|
|
+ let checked = true;
|
|
|
+ list.forEach(item => {
|
|
|
+ if (item.checked === true) {
|
|
|
+ total += item.productInfo.price * item.cart_num;
|
|
|
+ } else if (checked === true) {
|
|
|
+ checked = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
this.vipallChecked = checked;
|
|
|
this.viptotal = Number(total.toFixed(2));
|
|
|
}
|
|
|
-
|
|
|
},
|
|
|
//创建订单
|
|
|
createOrder() {
|
|
|
- let list = this.cartList;
|
|
|
+ let list
|
|
|
+ if(this.currentIndex == '0') {
|
|
|
+ list = this.cartList
|
|
|
+ }
|
|
|
+ if(this.currentIndex == '1') {
|
|
|
+ list = this.vipcartList
|
|
|
+ }
|
|
|
let goodsData = [];
|
|
|
list.forEach(item => {
|
|
|
if (item.checked) {
|
|
|
goodsData.push(item.id);
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
uni.navigateTo({
|
|
|
url: '/pages/order/createOrder?id=' + goodsData.join(',')
|
|
|
});
|