优化购物车列表
This commit is contained in:
parent
965505aef7
commit
a87f0480c4
src/pages/service
|
@ -35,8 +35,13 @@
|
||||||
<text class="text">合计:</text>
|
<text class="text">合计:</text>
|
||||||
<text class="price">¥ {{ utils.formatNumber(item.total, 2) }}</text>
|
<text class="price">¥ {{ utils.formatNumber(item.total, 2) }}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="button" :class="{ active: item.total > 0 }" @click="createOrder(index)">
|
<view class="button-group">
|
||||||
<text>去下单</text>
|
<view v-show="item.canUse" class="button del" @click="deleteCheckedCart(index)">
|
||||||
|
<text>删除</text>
|
||||||
|
</view>
|
||||||
|
<view class="button normal" :class="{ active: item.canUse }" @click="createOrder(index)">
|
||||||
|
<text>去下单</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -107,6 +112,7 @@ export default {
|
||||||
total: 0,
|
total: 0,
|
||||||
list: goods,
|
list: goods,
|
||||||
checked: false,
|
checked: false,
|
||||||
|
canUse: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -132,13 +138,17 @@ export default {
|
||||||
currentItem.checked = currentState;
|
currentItem.checked = currentState;
|
||||||
|
|
||||||
// 判断是否需要选中组
|
// 判断是否需要选中组
|
||||||
let allChecked = true;
|
let allChecked = true,
|
||||||
|
canUse = false;
|
||||||
this.list[parentIndex].list.forEach((item, index) => {
|
this.list[parentIndex].list.forEach((item, index) => {
|
||||||
if (!item.checked) {
|
if (!item.checked) {
|
||||||
allChecked = false;
|
allChecked = false;
|
||||||
|
} else {
|
||||||
|
canUse = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.list[parentIndex].checked = allChecked;
|
this.list[parentIndex].checked = allChecked;
|
||||||
|
this.list[parentIndex].canUse = canUse;
|
||||||
|
|
||||||
this.updateTotal(parentIndex);
|
this.updateTotal(parentIndex);
|
||||||
}
|
}
|
||||||
|
@ -174,20 +184,22 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 删除购物车
|
* 公共删除
|
||||||
*/
|
*/
|
||||||
deleteCart(parentIndex, itemIndex) {
|
commonDeleteCart(parentIndex, itemIndexes) {
|
||||||
const that = this;
|
const that = this;
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: "确定删除该商品?",
|
title: "确定删除该商品?",
|
||||||
content: "数据删除后不可恢复,请谨慎操作!",
|
content: "数据删除后不可恢复,请谨慎操作!",
|
||||||
complete(res) {
|
async complete(res) {
|
||||||
if (res.confirm) {
|
if (!res.confirm) return;
|
||||||
let parentItem = that.list[parentIndex];
|
let parentItem = that.list[parentIndex];
|
||||||
let currentItem = parentItem.list[itemIndex];
|
itemIndexes = itemIndexes.sort((a, b) => b - a);
|
||||||
that.$models.cart.delete(currentItem.id).then(() => {
|
for (let i = 0; i < itemIndexes.length; i++) {
|
||||||
|
let currentItem = parentItem.list[itemIndexes[i]];
|
||||||
|
await that.$models.cart.delete(currentItem.id).then(() => {
|
||||||
that.$store.dispatch("cart/update", true);
|
that.$store.dispatch("cart/update", true);
|
||||||
parentItem.list.splice(itemIndex, 1);
|
parentItem.list.splice(itemIndexes[i], 1);
|
||||||
if (parentItem.list.length > 0) {
|
if (parentItem.list.length > 0) {
|
||||||
that.updateTotal(parentIndex);
|
that.updateTotal(parentIndex);
|
||||||
} else {
|
} else {
|
||||||
|
@ -198,6 +210,25 @@ export default {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 删除购物车
|
||||||
|
*/
|
||||||
|
deleteCart(parentIndex, itemIndex) {
|
||||||
|
this.commonDeleteCart(parentIndex, [itemIndex]);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 删除选中购物车
|
||||||
|
*/
|
||||||
|
deleteCheckedCart(parentIndex) {
|
||||||
|
let currentItem = this.list[parentIndex];
|
||||||
|
let indexes = [];
|
||||||
|
currentItem.list.forEach((item, itemIndex) => {
|
||||||
|
if (item.checked) {
|
||||||
|
indexes.push(itemIndex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.commonDeleteCart(parentIndex, indexes);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 购物车下单
|
* 购物车下单
|
||||||
*/
|
*/
|
||||||
|
@ -290,18 +321,30 @@ export default {
|
||||||
color: #ec7655;
|
color: #ec7655;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.button-group {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
.button {
|
.button {
|
||||||
width: 183rpx;
|
|
||||||
height: 54rpx;
|
height: 54rpx;
|
||||||
line-height: 54rpx;
|
line-height: 54rpx;
|
||||||
background: linear-gradient(-90deg, #8194f2, #8194f2);
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-radius: 23rpx;
|
border-radius: 23rpx;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin-left: 20rpx;
|
||||||
|
}
|
||||||
|
.button.del {
|
||||||
|
width: 90rpx;
|
||||||
|
color: #666666;
|
||||||
|
border: 2rpx solid #e0e0e0;
|
||||||
|
}
|
||||||
|
.button.normal {
|
||||||
|
width: 183rpx;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
|
background: linear-gradient(-90deg, #8194f2, #8194f2);
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
.button.active {
|
.button.normal.active {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue