|
@@ -1,5 +1,6 @@
|
|
<template>
|
|
<template>
|
|
- <view class="cart" :style="{ paddingTop: CustomBar + 'px' }">
|
|
|
|
|
|
+ <view class="cart" :style="[cartPaddingTop]">
|
|
|
|
+ <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
|
|
<header-cart
|
|
<header-cart
|
|
:systeminfo="systeminfo"
|
|
:systeminfo="systeminfo"
|
|
:navbar-data="nvabarData"
|
|
:navbar-data="nvabarData"
|
|
@@ -7,9 +8,9 @@
|
|
:page="1"
|
|
:page="1"
|
|
></header-cart>
|
|
></header-cart>
|
|
<template v-if="!isEmpty">
|
|
<template v-if="!isEmpty">
|
|
- <template v-if="listType !== 'delete'">
|
|
|
|
|
|
+ <template v-if="!isshowDelbtn">
|
|
<!-- 商品统计 / 批量删除商品 -->
|
|
<!-- 商品统计 / 批量删除商品 -->
|
|
- <view class="cart-top">
|
|
|
|
|
|
+ <view class="cart-top" :class="{ fixed: cartTopFixed }" :style="[cartTop]">
|
|
<view class="count">共{{ kindCount }}件商品</view>
|
|
<view class="count">共{{ kindCount }}件商品</view>
|
|
<view class="btn" @click="showDelManager">删除</view>
|
|
<view class="btn" @click="showDelManager">删除</view>
|
|
</view>
|
|
</view>
|
|
@@ -20,23 +21,30 @@
|
|
</view>
|
|
</view>
|
|
</template>
|
|
</template>
|
|
<!-- 购物车列表 -->
|
|
<!-- 购物车列表 -->
|
|
|
|
+ <template v-for="(cart, index) in goodsList">
|
|
|
|
+ <cm-cart-product
|
|
|
|
+ class="product-list"
|
|
|
|
+ :listType="listType"
|
|
|
|
+ :key="index"
|
|
|
|
+ :data="cart"
|
|
|
|
+ vkey="productList"
|
|
|
|
+ @chooseAll="chooseAllProduct"
|
|
|
|
+ @chooseOne="chooseOneProduct"
|
|
|
|
+ ></cm-cart-product>
|
|
|
|
+ </template>
|
|
|
|
+ <!-- 失效商品列表 -->
|
|
<cm-cart-product
|
|
<cm-cart-product
|
|
- v-for="(cart, index) in goodsList"
|
|
|
|
class="product-list"
|
|
class="product-list"
|
|
- :listType="listType"
|
|
|
|
:key="index"
|
|
:key="index"
|
|
- :data="cart"
|
|
|
|
- vkey="productList"
|
|
|
|
- @chooseAll="chooseAll"
|
|
|
|
- @chooseOne="chooseOne"
|
|
|
|
|
|
+ :data="failureList"
|
|
|
|
+ :listType="failureListType"
|
|
|
|
+ @chooseOne="chooseFailureProduct"
|
|
|
|
+ v-if="failureList.length > 0"
|
|
></cm-cart-product>
|
|
></cm-cart-product>
|
|
|
|
|
|
- <!-- 失效商品列表 -->
|
|
|
|
- <cm-cart-product class="product-list" :key="index" :data="failureList" listType="expired"></cm-cart-product>
|
|
|
|
-
|
|
|
|
<!-- 底部按钮 -->
|
|
<!-- 底部按钮 -->
|
|
<view class="footer" :style="[footerBottom]">
|
|
<view class="footer" :style="[footerBottom]">
|
|
- <view class="radio" @click="checkAll">
|
|
|
|
|
|
+ <view class="radio" @click="chooseAll">
|
|
<text class="iconfont" :class="[isCheckAll ? 'icon-xuanze' : 'icon-weixuanze']"></text>
|
|
<text class="iconfont" :class="[isCheckAll ? 'icon-xuanze' : 'icon-weixuanze']"></text>
|
|
<text class="tip">全选</text>
|
|
<text class="tip">全选</text>
|
|
</view>
|
|
</view>
|
|
@@ -142,7 +150,6 @@ export default {
|
|
allPrice: 0, //所有价格
|
|
allPrice: 0, //所有价格
|
|
totalOriginalPrice: 0, //所有原价价
|
|
totalOriginalPrice: 0, //所有原价价
|
|
reducedPrice: 0, //满减
|
|
reducedPrice: 0, //满减
|
|
- skeletonShow: true,
|
|
|
|
isshowDelbtn: false,
|
|
isshowDelbtn: false,
|
|
scrollHeight: 'auto',
|
|
scrollHeight: 'auto',
|
|
hasNextPage: false,
|
|
hasNextPage: false,
|
|
@@ -151,7 +158,10 @@ export default {
|
|
deleteType: 0,
|
|
deleteType: 0,
|
|
couponVisible: false,
|
|
couponVisible: false,
|
|
showDitail: false,
|
|
showDitail: false,
|
|
- listType: 'list'
|
|
|
|
|
|
+ listType: 'normal',
|
|
|
|
+ failureListType: 'expired',
|
|
|
|
+ scrollTop: 0,
|
|
|
|
+ isRequest: true
|
|
}
|
|
}
|
|
},
|
|
},
|
|
onLoad() {
|
|
onLoad() {
|
|
@@ -176,6 +186,30 @@ export default {
|
|
return {
|
|
return {
|
|
bottom: this.isIphoneX ? '0' : ''
|
|
bottom: this.isIphoneX ? '0' : ''
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ cartTopFixed() {
|
|
|
|
+ return this.scrollTop > 0 && !this.isshowDelbtn
|
|
|
|
+ },
|
|
|
|
+ // 购物车顶部删除按钮top
|
|
|
|
+ cartTop() {
|
|
|
|
+ return {
|
|
|
|
+ top: this.CustomBar + 'px'
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ // 购物车页面padding
|
|
|
|
+ cartPaddingTop() {
|
|
|
|
+ let paddingTop = this.CustomBar
|
|
|
|
+ let paddingBottom = 100
|
|
|
|
+ if (this.cartTopFixed) {
|
|
|
|
+ paddingTop += 40
|
|
|
|
+ }
|
|
|
|
+ if(this.isIphoneX){
|
|
|
|
+ paddingBottom += 40
|
|
|
|
+ }
|
|
|
|
+ return {
|
|
|
|
+ paddingTop: paddingTop + 'px',
|
|
|
|
+ paddingBottom: paddingBottom + 'rpx'
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
filters: {
|
|
filters: {
|
|
@@ -195,6 +229,15 @@ export default {
|
|
handler(val, oldval) {
|
|
handler(val, oldval) {
|
|
this.totalPeice()
|
|
this.totalPeice()
|
|
}
|
|
}
|
|
|
|
+ },
|
|
|
|
+ isshowDelbtn(val) {
|
|
|
|
+ if (val) {
|
|
|
|
+ this.failureListType = 'expired delete'
|
|
|
|
+ this.listType = 'normal delete'
|
|
|
|
+ } else {
|
|
|
|
+ this.failureListType = 'expired'
|
|
|
|
+ this.listType = 'normal'
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
//下拉刷新
|
|
//下拉刷新
|
|
@@ -212,22 +255,18 @@ export default {
|
|
this.$api.redirectTo('/pages/login/login')
|
|
this.$api.redirectTo('/pages/login/login')
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- onHide() {
|
|
|
|
- this.saveCartIds([])
|
|
|
|
|
|
+ onPageScroll(e) {
|
|
|
|
+ this.scrollTop = e.scrollTop
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- ...mapActions('cart', ['initCart', 'updateShoppogCount', 'removeFromCart', 'removeFailureFromCart']),
|
|
|
|
- ...mapMutations('cart', [
|
|
|
|
- 'selectProduct',
|
|
|
|
- 'selectAllShopProduct',
|
|
|
|
- 'selectAllProduct',
|
|
|
|
- 'saveCartIds',
|
|
|
|
- 'selectFailure',
|
|
|
|
- 'selectAllFailure'
|
|
|
|
- ]),
|
|
|
|
|
|
+ ...mapActions('cart', ['initCart', 'removeFromCart']),
|
|
|
|
+ ...mapMutations('cart', ['selectAllProduct', 'saveCartIds', 'selectAllFailure']),
|
|
initData() {
|
|
initData() {
|
|
|
|
+ this.saveCartIds([]) // 清空已选项
|
|
|
|
+ this.isCheckAll = false
|
|
|
|
+ this.isshowDelbtn = false
|
|
this.initCart().finally(() => {
|
|
this.initCart().finally(() => {
|
|
- this.skeletonShow = false
|
|
|
|
|
|
+ this.isRequest = false
|
|
})
|
|
})
|
|
},
|
|
},
|
|
// 关闭优惠券弹窗
|
|
// 关闭优惠券弹窗
|
|
@@ -241,31 +280,28 @@ export default {
|
|
this.handlerPros = pros
|
|
this.handlerPros = pros
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- // 优惠明细 TODO
|
|
|
|
|
|
+ // 优惠明细
|
|
showDiscountedDetail() {
|
|
showDiscountedDetail() {
|
|
this.showDitail = true
|
|
this.showDitail = true
|
|
},
|
|
},
|
|
// 勾选单个失效商品
|
|
// 勾选单个失效商品
|
|
- ischeckFailure(failure) {
|
|
|
|
- this.selectFailure({
|
|
|
|
- productId: failure.productId,
|
|
|
|
- checked: !failure.productsChecked
|
|
|
|
- })
|
|
|
|
- this.getCheckedProductId()
|
|
|
|
|
|
+ chooseFailureProduct() {
|
|
|
|
+ this.isSelectAll()
|
|
},
|
|
},
|
|
// 勾选供应商下所有商品
|
|
// 勾选供应商下所有商品
|
|
- chooseAll() {
|
|
|
|
|
|
+ chooseAllProduct() {
|
|
this.isSelectAll()
|
|
this.isSelectAll()
|
|
},
|
|
},
|
|
// 勾选单核商品
|
|
// 勾选单核商品
|
|
- chooseOne() {
|
|
|
|
|
|
+ chooseOneProduct() {
|
|
this.isSelectAll()
|
|
this.isSelectAll()
|
|
},
|
|
},
|
|
// 勾选全部商品
|
|
// 勾选全部商品
|
|
- checkAll() {
|
|
|
|
|
|
+ chooseAll() {
|
|
this.isCheckAll = !this.isCheckAll
|
|
this.isCheckAll = !this.isCheckAll
|
|
|
|
+ // 勾选所有有效商品
|
|
this.selectAllProduct(this.isCheckAll)
|
|
this.selectAllProduct(this.isCheckAll)
|
|
- // 删除商品的全选也要选中失效商品
|
|
|
|
|
|
+ // 勾选所有失效商品
|
|
if (this.isshowDelbtn) {
|
|
if (this.isshowDelbtn) {
|
|
this.selectAllFailure(this.isCheckAll)
|
|
this.selectAllFailure(this.isCheckAll)
|
|
}
|
|
}
|
|
@@ -273,12 +309,17 @@ export default {
|
|
},
|
|
},
|
|
// 判断是否全选商品
|
|
// 判断是否全选商品
|
|
isSelectAll() {
|
|
isSelectAll() {
|
|
|
|
+ // 是否勾选全部正常商品
|
|
this.isCheckAll = this.goodsList.every(shop => shop.checked)
|
|
this.isCheckAll = this.goodsList.every(shop => shop.checked)
|
|
- this.getCheckedProductId()
|
|
|
|
|
|
+ if (this.isshowDelbtn) {
|
|
|
|
+ this.isCheckAll = this.isCheckAll && this.failureList.every(product => product.productsChecked)
|
|
|
|
+ }
|
|
|
|
+ this.saveCartIds(this.getCheckedProductId())
|
|
},
|
|
},
|
|
// 获取勾选商品的id
|
|
// 获取勾选商品的id
|
|
getCheckedProductId() {
|
|
getCheckedProductId() {
|
|
const cartIds = []
|
|
const cartIds = []
|
|
|
|
+ // 获取所有有效商品cartId
|
|
this.goodsList.forEach(shop => {
|
|
this.goodsList.forEach(shop => {
|
|
const ids = shop.productList.reduce((cartIds, prod) => {
|
|
const ids = shop.productList.reduce((cartIds, prod) => {
|
|
if (prod.productsChecked) cartIds.push(prod.cartId)
|
|
if (prod.productsChecked) cartIds.push(prod.cartId)
|
|
@@ -286,6 +327,7 @@ export default {
|
|
}, [])
|
|
}, [])
|
|
cartIds.push(...ids)
|
|
cartIds.push(...ids)
|
|
})
|
|
})
|
|
|
|
+ // 获取所有失效商品cartId
|
|
if (this.isshowDelbtn) {
|
|
if (this.isshowDelbtn) {
|
|
const ids = this.failureList.reduce((cartIds, prod) => {
|
|
const ids = this.failureList.reduce((cartIds, prod) => {
|
|
if (prod.productsChecked) cartIds.push(prod.cartId)
|
|
if (prod.productsChecked) cartIds.push(prod.cartId)
|
|
@@ -294,7 +336,7 @@ export default {
|
|
cartIds.push(...ids)
|
|
cartIds.push(...ids)
|
|
}
|
|
}
|
|
console.log(cartIds)
|
|
console.log(cartIds)
|
|
- this.saveCartIds(cartIds)
|
|
|
|
|
|
+ return cartIds
|
|
},
|
|
},
|
|
//计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
|
|
//计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
|
|
totalPeice() {
|
|
totalPeice() {
|
|
@@ -323,57 +365,15 @@ export default {
|
|
)
|
|
)
|
|
this.allPrice = priceObj.allPrice
|
|
this.allPrice = priceObj.allPrice
|
|
},
|
|
},
|
|
- //商品数量加加
|
|
|
|
- changeCountAdd(item, pros) {
|
|
|
|
- const productCount = pros.productCount + 1
|
|
|
|
- this.updateShoppogCount({
|
|
|
|
- cartId: pros.cartId,
|
|
|
|
- productCount
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- //商品数量减减
|
|
|
|
- changeCountSub(item, pros) {
|
|
|
|
- let productCount = pros.productCount
|
|
|
|
- if (productCount <= 1) {
|
|
|
|
- productCount = 1
|
|
|
|
- this.$util.msg('购买数量不能少于1', 2000)
|
|
|
|
- return
|
|
|
|
- } else {
|
|
|
|
- productCount--
|
|
|
|
- }
|
|
|
|
- this.updateShoppogCount({
|
|
|
|
- cartId: pros.cartId,
|
|
|
|
- productCount
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- //输入商品数量更新
|
|
|
|
- changeInput(pros) {},
|
|
|
|
- //输入商品数量更新
|
|
|
|
- changeNumber(e, item, pros) {
|
|
|
|
- let _value = Math.abs(Number(e.detail.value))
|
|
|
|
- let productCount = pros.productCount
|
|
|
|
- if (_value <= 1) {
|
|
|
|
- this.$util.msg('购买数量不能少于1', 2000)
|
|
|
|
- productCount = 1
|
|
|
|
- } else {
|
|
|
|
- productCount = _value
|
|
|
|
- }
|
|
|
|
- this.updateShoppogCount({
|
|
|
|
- cartId: pros.cartId,
|
|
|
|
- productCount
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
//显示删除商品管理
|
|
//显示删除商品管理
|
|
showDelManager() {
|
|
showDelManager() {
|
|
this.isshowDelbtn = true
|
|
this.isshowDelbtn = true
|
|
- this.listType = 'delete'
|
|
|
|
},
|
|
},
|
|
//隐藏删除商品管理
|
|
//隐藏删除商品管理
|
|
hideDelManage() {
|
|
hideDelManage() {
|
|
this.selectAllFailure(false)
|
|
this.selectAllFailure(false)
|
|
- this.getCheckedProductId()
|
|
|
|
|
|
+ this.isSelectAll()
|
|
this.isshowDelbtn = false
|
|
this.isshowDelbtn = false
|
|
- this.listType = 'list'
|
|
|
|
},
|
|
},
|
|
//删除购物车商品
|
|
//删除购物车商品
|
|
deleteList() {
|
|
deleteList() {
|
|
@@ -382,30 +382,15 @@ export default {
|
|
} else {
|
|
} else {
|
|
this.modal = true
|
|
this.modal = true
|
|
this.contentModalText = '确定删除选中的商品吗?'
|
|
this.contentModalText = '确定删除选中的商品吗?'
|
|
- this.deleteType = 1
|
|
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- // 清空失效商品
|
|
|
|
- deletefailureList() {
|
|
|
|
- this.modal = true
|
|
|
|
- this.contentModalText = '确定清除所有失效商品吗?'
|
|
|
|
- this.deleteType = 2
|
|
|
|
- },
|
|
|
|
//从购物车移除商品
|
|
//从购物车移除商品
|
|
handleClick(e) {
|
|
handleClick(e) {
|
|
if (e.index !== 1) return (this.modal = false)
|
|
if (e.index !== 1) return (this.modal = false)
|
|
- if (this.deleteType === 1) {
|
|
|
|
- // 删除所有勾选的商品
|
|
|
|
- this.removeFromCart().finally(() => {
|
|
|
|
- this.isshowDelbtn = false
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
- //一键删除失效商品
|
|
|
|
- this.removeFailureFromCart().finally(() => {
|
|
|
|
- this.isshowDelbtn = false
|
|
|
|
- this.listType = 'list'
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ // 删除所有勾选的商品
|
|
|
|
+ this.removeFromCart().finally(() => {
|
|
|
|
+ this.isshowDelbtn = false
|
|
|
|
+ })
|
|
this.modal = false
|
|
this.modal = false
|
|
},
|
|
},
|
|
//跳转确认订单页面
|
|
//跳转确认订单页面
|
|
@@ -462,11 +447,14 @@ export default {
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
.cart {
|
|
.cart {
|
|
- padding-bottom: 124rpx;
|
|
|
|
background: #f7f7f7;
|
|
background: #f7f7f7;
|
|
min-height: 100%;
|
|
min-height: 100%;
|
|
box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
|
|
+ &.hasPaddingTop {
|
|
|
|
+ padding-top: 80rpx;
|
|
|
|
+ }
|
|
.cart-top {
|
|
.cart-top {
|
|
|
|
+ flex: 0;
|
|
display: flex;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
align-items: center;
|
|
@@ -475,6 +463,10 @@ export default {
|
|
height: 80rpx;
|
|
height: 80rpx;
|
|
background: #f7f7f7;
|
|
background: #f7f7f7;
|
|
box-sizing: border-box;
|
|
box-sizing: border-box;
|
|
|
|
+ &.fixed {
|
|
|
|
+ position: fixed;
|
|
|
|
+ z-index: 9999;
|
|
|
|
+ }
|
|
.count {
|
|
.count {
|
|
font-size: 30rpx;
|
|
font-size: 30rpx;
|
|
color: #333333;
|
|
color: #333333;
|
|
@@ -646,7 +638,7 @@ export default {
|
|
color: #999999;
|
|
color: #999999;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- .empty{
|
|
|
|
|
|
+ .empty {
|
|
height: 80vh;
|
|
height: 80vh;
|
|
}
|
|
}
|
|
}
|
|
}
|