|
@@ -43,7 +43,7 @@
|
|
|
<view class="goods-pros" v-for="(pros, idx) in item.productList" :key="idx">
|
|
|
<view class="goods-pros-t">
|
|
|
<!--选择商品-->
|
|
|
- <view class="checkbox-box" @click.stop="ischeck(item, pros)">
|
|
|
+ <view class="checkbox-box" @click.stop="checkProduct(item, pros)">
|
|
|
<view
|
|
|
class="checkbox iconfont"
|
|
|
:class="[pros.productsChecked ? 'icon-xuanze' : 'icon-weixuanze']"
|
|
@@ -78,7 +78,7 @@
|
|
|
type="number"
|
|
|
maxlength="4"
|
|
|
v-model="pros.productCount"
|
|
|
- @blur="changeNnmber($event, item, pros)"
|
|
|
+ @blur="changeNumber($event, item, pros)"
|
|
|
@focus="changeInput(pros)"
|
|
|
/>
|
|
|
<view
|
|
@@ -188,7 +188,7 @@
|
|
|
<tui-modal
|
|
|
:show="modal"
|
|
|
@click="handleClick"
|
|
|
- @cancel="hideMobel"
|
|
|
+ @cancel="hideModal"
|
|
|
:content="contentModalText"
|
|
|
color="#333"
|
|
|
:size="32"
|
|
@@ -206,7 +206,7 @@ import authorize from '@/common/authorize.js'
|
|
|
import HeaderCart from '@/components/cm-module/headerNavbar/header-cart.vue' //顶部自定义胶囊'
|
|
|
import activiPopup from '@/components/cm-module/productDetails/cm-activipopu'
|
|
|
import modalLayer from '@/components/cm-module/modal-layer/modal-layer'
|
|
|
-import { mapGetters } from 'vuex'
|
|
|
+import { mapGetters, mapActions, mapMutations } from 'vuex'
|
|
|
import { cartList } from '@/common/json/data.json.js' //本地数据
|
|
|
|
|
|
export default {
|
|
@@ -227,33 +227,15 @@ export default {
|
|
|
headerBtnPosi: this.setHeaderBtnPosi(), //获取设备顶部胶囊高度
|
|
|
systeminfo: this.setSysteminfo(), //获取设备信息
|
|
|
CustomBar: this.CustomBar, // 顶部导航栏高度
|
|
|
- userId: '',
|
|
|
popupShow: false,
|
|
|
handlerPros: {}, //监听单挑促销商品
|
|
|
- failureList: [], //失效商品列表
|
|
|
- goodsList: [], //购物车的商品
|
|
|
- delGoodsList: '', //要删除的商品
|
|
|
- setGoodData: '', //确认订单的商品
|
|
|
isCheckAll: false, //是否全选
|
|
|
- kindCount: 0, //购物车宝贝数量
|
|
|
allPrice: 0, //所有价格
|
|
|
totalOriginalPrice: 0, //所有原价价
|
|
|
reducedPrice: 0, //满减
|
|
|
- allCount: 0, //被选中的产品数量
|
|
|
- isModallayer: false,
|
|
|
skeletonShow: true,
|
|
|
isshowDelbtn: false,
|
|
|
- isDisabled: false, // 供应商/店铺全选是否禁用状态
|
|
|
- isEmpty: false, //显示空购物车
|
|
|
scrollHeight: 'auto',
|
|
|
- nomoreText: '上拉显示更多',
|
|
|
- hasNextPage: false,
|
|
|
- loadding: false,
|
|
|
- pullUpOn: true,
|
|
|
- pullFlag: true,
|
|
|
- pageSize: 10,
|
|
|
- pageNum: 1,
|
|
|
- submitIds: [],
|
|
|
modal: false,
|
|
|
contentModalText: '',
|
|
|
deleteType: 0
|
|
@@ -263,7 +245,20 @@ export default {
|
|
|
this.setScrollHeight()
|
|
|
},
|
|
|
computed: {
|
|
|
- ...mapGetters(['hasLogin', 'isIphoneX'])
|
|
|
+ ...mapGetters([
|
|
|
+ 'hasLogin',
|
|
|
+ 'isIphoneX',
|
|
|
+ 'isEmpty',
|
|
|
+ 'goodsList',
|
|
|
+ 'failureList',
|
|
|
+ 'kindCount',
|
|
|
+ 'userId',
|
|
|
+ 'cartIds'
|
|
|
+ ]),
|
|
|
+ //被选中的产品数量
|
|
|
+ allCount() {
|
|
|
+ return this.cartIds.length
|
|
|
+ }
|
|
|
},
|
|
|
filters: {
|
|
|
NumFormat(value) {
|
|
@@ -275,463 +270,257 @@ export default {
|
|
|
return (val * count).toFixed(2)
|
|
|
}
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ //深度监听所有数据,每次改变重新计算总价和总数
|
|
|
+ goodsList: {
|
|
|
+ deep: true,
|
|
|
+ handler(val, oldval) {
|
|
|
+ this.totalPeice()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //下拉刷新
|
|
|
+ onPullDownRefresh() {
|
|
|
+ this.initCart().finally(() => {
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.stopPullDownRefresh()
|
|
|
+ }, 2000)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onShow() {
|
|
|
+ if (this.hasLogin) {
|
|
|
+ this.initData()
|
|
|
+ } else {
|
|
|
+ this.$api.redirectTo('/pages/login/login')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onHide() {
|
|
|
+ this.saveCartIds([])
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ ...mapActions('cart', ['initCart', 'updateShoppogCount', 'removeFromCart', 'removeFailureFromCart']),
|
|
|
+ ...mapMutations('cart', [
|
|
|
+ 'selectProduct',
|
|
|
+ 'selectAllShopProduct',
|
|
|
+ 'selectAllProduct',
|
|
|
+ 'saveCartIds',
|
|
|
+ 'selectFailure',
|
|
|
+ 'selectAllFailure'
|
|
|
+ ]),
|
|
|
initData() {
|
|
|
- this.isModallayer = false //遮罩层 防止多次点击
|
|
|
- this.isCheckAll = false //是否全选
|
|
|
- this.submitIds = []
|
|
|
- this.$api.getStorage().then(resolve => {
|
|
|
- this.userId = resolve.userId ? resolve.userId : 0
|
|
|
- this.InitGetCartGoodsList()
|
|
|
+ this.initCart().finally(() => {
|
|
|
+ this.skeletonShow = false
|
|
|
})
|
|
|
},
|
|
|
+ // 活动价弹窗
|
|
|
clickPopupShow(pros, type) {
|
|
|
if (pros.ladderList.length > 0) {
|
|
|
this.popupShow = true
|
|
|
this.handlerPros = pros
|
|
|
}
|
|
|
},
|
|
|
- setScrollHeight() {
|
|
|
- // 窗口高度-footer高度
|
|
|
- const { windowHeight, pixelRatio } = uni.getSystemInfoSync()
|
|
|
- setTimeout(() => {
|
|
|
- const query = uni.createSelectorQuery().in(this)
|
|
|
- query.selectAll('.footer').boundingClientRect()
|
|
|
- query.exec(res => {
|
|
|
- this.windowHeight = windowHeight
|
|
|
- if (res[0][0]) {
|
|
|
- this.scrollHeight = windowHeight - res[0][0].height
|
|
|
- }
|
|
|
- })
|
|
|
- }, 500)
|
|
|
- },
|
|
|
- InitGetCartGoodsList() {
|
|
|
- //初始化购物车 index:1
|
|
|
- this.ProductService.QueryShoppingCartList({ userId: this.userId })
|
|
|
- .then(response => {
|
|
|
- this.skeletonShow = false
|
|
|
- let data = response.data
|
|
|
- this.kindCount = data.cartQuantity
|
|
|
- if (data.shopList.length > 0 || data.products.length > 0) {
|
|
|
- this.isEmpty = false
|
|
|
- } else {
|
|
|
- this.isEmpty = true
|
|
|
- }
|
|
|
- if (data.shopList && data.shopList.length > 0) {
|
|
|
- this.goodsList = data.shopList
|
|
|
- console.log(this.goodsList)
|
|
|
- this.totalShopPeice()
|
|
|
- } else {
|
|
|
- this.goodsList = []
|
|
|
- }
|
|
|
- if (data.products && data.products.length > 0) {
|
|
|
- this.failureList = data.products
|
|
|
- } else {
|
|
|
- this.failureList = []
|
|
|
- }
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- this.$util.msg(error.msg, 2000)
|
|
|
- })
|
|
|
- },
|
|
|
+ // 勾选单个失效商品
|
|
|
ischeckFailure(failure) {
|
|
|
- failure.productsChecked = !failure.productsChecked
|
|
|
- this.updateCheckAllBtn()
|
|
|
- },
|
|
|
- ischeck(item, pro) {
|
|
|
- //为未选中的时候改变为true,反之为true
|
|
|
- pro.productsChecked = !pro.productsChecked
|
|
|
- if (pro.productsChecked) {
|
|
|
- if (!this.submitIds.includes(pro.productID * 1)) {
|
|
|
- this.submitIds.push(pro.productID)
|
|
|
- }
|
|
|
- } else {
|
|
|
- var lent = this.submitIds.indexOf(pro.productID * 1)
|
|
|
- if (lent >= 0) {
|
|
|
- this.submitIds.splice(lent, 1)
|
|
|
- }
|
|
|
- }
|
|
|
- this.updateProductCheckedAllBtn(item)
|
|
|
- this.updateCheckAllBtn()
|
|
|
- },
|
|
|
- updateProductCheckedAllBtn(item) {
|
|
|
- // 单独每个供应商的勾选判断
|
|
|
- let productList = item.productList,
|
|
|
- productsCheckedLength = 0,
|
|
|
- disabledLength = 0
|
|
|
- if (this.isshowDelbtn) {
|
|
|
- productList.forEach(pros => {
|
|
|
- if (pros.productsChecked) {
|
|
|
- productsCheckedLength++
|
|
|
- }
|
|
|
- })
|
|
|
- } else {
|
|
|
- productList.forEach(pros => {
|
|
|
- if (pros.productsChecked) {
|
|
|
- productsCheckedLength++
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- item.checked = productsCheckedLength === productList.length
|
|
|
- },
|
|
|
- updateCheckAllBtn() {
|
|
|
- // 全选勾选判断
|
|
|
- let goodsCheckedLength = 0,
|
|
|
- goodsList = this.goodsList,
|
|
|
- failureList = this.failureList
|
|
|
- goodsList.forEach(item => {
|
|
|
- if (item.checked) {
|
|
|
- goodsCheckedLength++
|
|
|
- }
|
|
|
- })
|
|
|
- failureList.forEach(failureItem => {
|
|
|
- if (failureItem.productsChecked) {
|
|
|
- goodsCheckedLength++
|
|
|
- }
|
|
|
+ this.selectFailure({
|
|
|
+ productId: failure.productId,
|
|
|
+ checked: !failure.productsChecked
|
|
|
})
|
|
|
- if (this.isshowDelbtn) {
|
|
|
- this.isCheckAll = goodsCheckedLength === goodsList.length + failureList.length
|
|
|
- } else {
|
|
|
- this.isCheckAll = goodsCheckedLength === goodsList.length
|
|
|
- }
|
|
|
+ this.getCheckedProductId()
|
|
|
},
|
|
|
- checkShop(item) {
|
|
|
- //与单选商品类似
|
|
|
- item.checked = !item.checked
|
|
|
- this.setProductChecked(item)
|
|
|
- this.updateCheckAllBtn()
|
|
|
+ // 勾选单个商品
|
|
|
+ checkProduct(shop, product) {
|
|
|
+ this.selectProduct({
|
|
|
+ shopId: shop.shopId,
|
|
|
+ productId: product.productId,
|
|
|
+ checked: !product.productsChecked
|
|
|
+ })
|
|
|
+ this.isSelectAll()
|
|
|
},
|
|
|
- setProductChecked(item) {
|
|
|
- item.productList.forEach(pros => {
|
|
|
- if (item.checked) {
|
|
|
- pros.productsChecked = true
|
|
|
- if (!this.submitIds.includes(pros.productId * 1)) {
|
|
|
- this.submitIds.push(pros.productId)
|
|
|
- }
|
|
|
- } else {
|
|
|
- pros.productsChecked = false
|
|
|
- var lent = this.submitIds.indexOf(pros.productId * 1)
|
|
|
- if (lent >= 0) {
|
|
|
- this.submitIds.splice(lent, 1)
|
|
|
- }
|
|
|
- }
|
|
|
+ // 勾选商店所有商品
|
|
|
+ checkShop(shop) {
|
|
|
+ this.selectAllShopProduct({
|
|
|
+ shopId: shop.shopId,
|
|
|
+ checked: !shop.checked
|
|
|
})
|
|
|
+ this.isSelectAll()
|
|
|
},
|
|
|
- updateBothCheckBtn() {
|
|
|
+ // 勾选全部商品
|
|
|
+ checkAll() {
|
|
|
+ this.isCheckAll = !this.isCheckAll
|
|
|
+ this.selectAllProduct(this.isCheckAll)
|
|
|
+ // 删除商品的全选也要选中失效商品
|
|
|
if (this.isshowDelbtn) {
|
|
|
- // 当管理删除按钮出现时,失效的商品可被选择
|
|
|
- this.goodsList.forEach(item => {
|
|
|
- item.checked = this.isCheckAll
|
|
|
- this.setProductChecked(item)
|
|
|
- })
|
|
|
- //删除按钮 全选包括失效商品勾选
|
|
|
- this.failureList.forEach(failureItem => {
|
|
|
- failureItem.productsChecked = this.isCheckAll
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.goodsList.forEach(item => {
|
|
|
- item.checked = this.isCheckAll && !item.isDisabled
|
|
|
- this.setProductChecked(item)
|
|
|
- })
|
|
|
+ this.selectAllFailure(this.isCheckAll)
|
|
|
}
|
|
|
+ this.isSelectAll()
|
|
|
},
|
|
|
- checkAll() {
|
|
|
- //全选方法内调用方法
|
|
|
- this.isCheckAll = !this.isCheckAll
|
|
|
- this.updateBothCheckBtn()
|
|
|
+ // 判断是否全选商品
|
|
|
+ isSelectAll() {
|
|
|
+ this.isCheckAll = this.goodsList.every(shop => shop.checked)
|
|
|
+ this.getCheckedProductId()
|
|
|
},
|
|
|
- totalShopPeice() {
|
|
|
- //每次所属会所下的商品增减重新计算合计价格&减去含有下架的商品
|
|
|
- let touchPrice = 0
|
|
|
- let reducedPrice = 0 //商铺合计满减价
|
|
|
- this.goodsList.map((item, index) => {
|
|
|
- let _totalPrice = 0
|
|
|
- let _reducedPrice = 0
|
|
|
- let _totalOriginalPrice = 0
|
|
|
- item.productList.forEach(pros => {
|
|
|
- let _price = pros.price * pros.productCount
|
|
|
- _totalOriginalPrice += pros.price * pros.productCount
|
|
|
- if (pros.promotion && pros.promotion.type != 2 && pros.promotion.mode == 2) {
|
|
|
- if (_price >= pros.promotion.touchPrice) {
|
|
|
- _price = _price - pros.promotion.reducedPrice
|
|
|
- _reducedPrice += pros.promotion.reducedPrice
|
|
|
- }
|
|
|
- _totalPrice += _price
|
|
|
- } else {
|
|
|
- _reducedPrice = 0
|
|
|
- _totalPrice += pros.price * pros.productCount
|
|
|
- }
|
|
|
- })
|
|
|
- item.reducedPrice = _reducedPrice
|
|
|
- item.totalOriginalPrice = _totalOriginalPrice
|
|
|
- item.totalPrice = _totalPrice
|
|
|
+ // 获取勾选商品的id
|
|
|
+ getCheckedProductId() {
|
|
|
+ const cartIds = []
|
|
|
+ this.goodsList.forEach(shop => {
|
|
|
+ const ids = shop.productList.reduce((cartIds, prod) => {
|
|
|
+ if (prod.productsChecked) cartIds.push(prod.cartId)
|
|
|
+ return cartIds
|
|
|
+ }, [])
|
|
|
+ cartIds.push(...ids)
|
|
|
})
|
|
|
+ if (this.isshowDelbtn) {
|
|
|
+ const ids = this.failureList.reduce((cartIds, prod) => {
|
|
|
+ if (prod.productsChecked) cartIds.push(prod.cartId)
|
|
|
+ return cartIds
|
|
|
+ }, [])
|
|
|
+ cartIds.push(...ids)
|
|
|
+ }
|
|
|
+ console.log(cartIds)
|
|
|
+ this.saveCartIds(cartIds)
|
|
|
},
|
|
|
+ //计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
|
|
|
totalPeice() {
|
|
|
- //计算总价格,每次调用此方法,将初始值为0,遍历价格并累加
|
|
|
- let totalPrice = 0
|
|
|
- let reducedPrice = 0
|
|
|
- let originalPrice = 0
|
|
|
- this.goodsList.forEach((item, index) => {
|
|
|
- let supplierPrice = 0
|
|
|
- let supplierReducedPrice = 0
|
|
|
- item.totalprice = 0
|
|
|
- item.reducedprice = 0
|
|
|
- item.originalprice = 0
|
|
|
- item.productList.forEach(pros => {
|
|
|
- if (pros.productsChecked) {
|
|
|
- supplierPrice += pros.price * pros.productCount
|
|
|
- // 单品满减
|
|
|
- if (pros.promotion && pros.promotion.type * 1 === 1 && pros.promotion.mode * 1 === 2) {
|
|
|
- // 单品满减-重新计算供应商总价/满减金额
|
|
|
- if (pros.price * pros.productCount >= pros.promotion.touchPrice) {
|
|
|
- supplierPrice -= pros.promotion.reducedPrice
|
|
|
- supplierReducedPrice += pros.promotion.reducedPrice
|
|
|
+ const priceObj = this.goodsList.reduce(
|
|
|
+ (priceObj, shop) => {
|
|
|
+ shop.productList.forEach(prod => {
|
|
|
+ if (prod.productsChecked) {
|
|
|
+ priceObj.totalOriginalPrice += prod.price * prod.productCount
|
|
|
+ // 单品满减
|
|
|
+ if (prod.promotion && prod.promotion.type * 1 === 1 && prod.promotion.mode * 1 === 2) {
|
|
|
+ // 单品满减-重新计算供应商总价/满减金额
|
|
|
+ if (prod.price * prod.productCount >= prod.promotion.touchPrice) {
|
|
|
+ priceObj.reducedPrice += prod.promotion.reducedPrice
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- })
|
|
|
- item.totalprice = supplierPrice
|
|
|
- item.reducedprice = supplierReducedPrice
|
|
|
- item.originalprice = supplierPrice + supplierReducedPrice
|
|
|
- totalPrice += item.totalprice
|
|
|
- reducedPrice += item.reducedprice
|
|
|
- originalPrice += item.originalprice
|
|
|
- })
|
|
|
- //最后统计商品原价
|
|
|
- this.totalOriginalPrice = originalPrice
|
|
|
- //最后满减金额 = 店铺减去金额 + 单品减去金额 + 凑单减去金额
|
|
|
- this.reducedPrice = reducedPrice
|
|
|
- //最终合计价格 = 店铺满减合计 + 单品满减 + 正常合计 + 凑单满减
|
|
|
- this.allPrice = totalPrice
|
|
|
- },
|
|
|
- totalCount() {
|
|
|
- //计算总数量
|
|
|
- this.allCount = 0
|
|
|
- let prosAllCount = 0
|
|
|
- let validCount = 0
|
|
|
- let validList = []
|
|
|
- let productList = []
|
|
|
- this.goodsList.forEach(item => {
|
|
|
- productList = item.productList
|
|
|
- productList.forEach(pros => {
|
|
|
- if (pros.productsChecked) {
|
|
|
- prosAllCount += parseInt(pros.productCount)
|
|
|
- this.allCount = prosAllCount
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
+ })
|
|
|
+ priceObj.allPrice = priceObj.totalOriginalPrice - priceObj.reducedPrice
|
|
|
+ return priceObj
|
|
|
+ },
|
|
|
+ {
|
|
|
+ totalOriginalPrice: 0,
|
|
|
+ reducedPrice: 0,
|
|
|
+ allPrice: 0
|
|
|
+ }
|
|
|
+ )
|
|
|
+ this.allPrice = priceObj.allPrice
|
|
|
},
|
|
|
+ //商品数量加加
|
|
|
changeCountAdd(item, pros) {
|
|
|
- //商品数量加加
|
|
|
- pros.productCount++
|
|
|
- this.processActivityPrice(pros)
|
|
|
- this.updateShoppogNum(pros)
|
|
|
- this.totalShopPeice()
|
|
|
+ const productCount = pros.productCount + 1
|
|
|
+ this.updateShoppogCount({
|
|
|
+ cartId: pros.cartId,
|
|
|
+ productCount
|
|
|
+ })
|
|
|
},
|
|
|
+ //商品数量减减
|
|
|
changeCountSub(item, pros) {
|
|
|
- //商品数量减减
|
|
|
- if (pros.productCount <= 1) {
|
|
|
- pros.productCount = 1
|
|
|
+ let productCount = pros.productCount
|
|
|
+ if (productCount <= 1) {
|
|
|
+ productCount = 1
|
|
|
this.$util.msg('购买数量不能少于1', 2000)
|
|
|
return
|
|
|
} else {
|
|
|
- pros.productCount--
|
|
|
+ productCount--
|
|
|
}
|
|
|
- this.processActivityPrice(pros)
|
|
|
- this.updateShoppogNum(pros)
|
|
|
- this.totalShopPeice()
|
|
|
- },
|
|
|
- changeInput(pros) {
|
|
|
- //输入商品数量更新
|
|
|
+ this.updateShoppogCount({
|
|
|
+ cartId: pros.cartId,
|
|
|
+ productCount
|
|
|
+ })
|
|
|
},
|
|
|
- changeNnmber(e, item, pros) {
|
|
|
- //输入商品数量更新
|
|
|
- let _value = Number(e.detail.value)
|
|
|
- if (!this.$api.isNumber(_value)) {
|
|
|
- pros.productCount = 1
|
|
|
- } else if (_value <= 1) {
|
|
|
+ //输入商品数量更新
|
|
|
+ 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)
|
|
|
- pros.productCount = 1
|
|
|
- } else {
|
|
|
- pros.productCount = e.detail.value
|
|
|
- }
|
|
|
- this.processActivityPrice(pros)
|
|
|
- this.updateShoppogNum(pros)
|
|
|
- this.totalShopPeice()
|
|
|
- },
|
|
|
- processActivityPrice(pros) {
|
|
|
- //单独处理活动价格和阶梯价格
|
|
|
- if (pros.activeStatus == 1) {
|
|
|
- pros.ladderList.forEach((item, index) => {
|
|
|
- if (pros.productCount >= item.buyNum) {
|
|
|
- pros.price = item.buyPrice
|
|
|
- }
|
|
|
- })
|
|
|
+ productCount = 1
|
|
|
} else {
|
|
|
- pros.price = pros.price
|
|
|
+ productCount = _value
|
|
|
}
|
|
|
- },
|
|
|
- updateShoppogNum(pros) {
|
|
|
- //加减购物车商品更新到后台
|
|
|
- this.ProductService.ShoppingCartUpdate({
|
|
|
+ this.updateShoppogCount({
|
|
|
cartId: pros.cartId,
|
|
|
- productCount: pros.productCount
|
|
|
- })
|
|
|
- .then(response => {
|
|
|
- this.isshowDelbtn = false
|
|
|
- this.InitGetCartGoodsList()
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- this.$util.msg(error.msg, 2000)
|
|
|
- })
|
|
|
- },
|
|
|
- toConfirmation() {
|
|
|
- //跳转确认订单页面
|
|
|
- let setGoodsList = []
|
|
|
- this.goodsList.forEach(res => {
|
|
|
- let products = res.productList
|
|
|
- products.forEach(pros => {
|
|
|
- if (pros.productsChecked) {
|
|
|
- setGoodsList.push(pros.productId)
|
|
|
- }
|
|
|
- })
|
|
|
+ productCount
|
|
|
})
|
|
|
- if (setGoodsList == '') {
|
|
|
- this.$util.msg('请先选择结算商品~', 2000)
|
|
|
- return
|
|
|
- }
|
|
|
- let cartIds = ''
|
|
|
- this.goodsList.forEach(el => {
|
|
|
- //获取勾选的商品ID拼接字符串逗号隔开,最后一个逗号去掉
|
|
|
- el.productList.forEach(pros => {
|
|
|
- if (pros.productsChecked) {
|
|
|
- cartIds += pros.cartId + ','
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- let cartPramsData = {
|
|
|
- allPrice: this.allPrice,
|
|
|
- allCount: this.allCount,
|
|
|
- cartIds: cartIds.substring(0, cartIds.lastIndexOf(',')),
|
|
|
- productCount: ''
|
|
|
- }
|
|
|
- this.$api.navigateTo(`/pages/user/order/create-order?data=${JSON.stringify({ data: cartPramsData })}`)
|
|
|
},
|
|
|
+ //显示删除商品管理
|
|
|
showDelManager() {
|
|
|
- //显示删除商品管理
|
|
|
this.isshowDelbtn = true
|
|
|
- if (this.isCheckAll) {
|
|
|
- this.updateBothCheckBtn()
|
|
|
- } else {
|
|
|
- this.goodsList.forEach(item => {
|
|
|
- if (item.checked) {
|
|
|
- item.productList.forEach(pros => {
|
|
|
- pros.productsChecked = true
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
- this.updateCheckAllBtn()
|
|
|
- }
|
|
|
- // 失效也被勾选
|
|
|
- this.failureList.forEach(failureItem => {
|
|
|
- if (failureItem.isFailureLayer) {
|
|
|
- failureItem.isFailureLayer = false
|
|
|
- }
|
|
|
- })
|
|
|
},
|
|
|
+ //隐藏删除商品管理
|
|
|
hideDelManage() {
|
|
|
- //隐藏删除商品管理
|
|
|
+ this.selectAllFailure(false)
|
|
|
+ this.getCheckedProductId()
|
|
|
this.isshowDelbtn = false
|
|
|
- let isFailureLayer,
|
|
|
- newFailureList = []
|
|
|
- if (this.isCheckAll) {
|
|
|
- this.updateBothCheckBtn()
|
|
|
- } else {
|
|
|
- // 失效商品取消勾选
|
|
|
- this.goodsList.forEach(item => {
|
|
|
- if (item.isDisabled) {
|
|
|
- item.checked = false
|
|
|
- }
|
|
|
- item.productList.forEach(pros => {
|
|
|
- if (pros.validFlag == 3) {
|
|
|
- pros.productsChecked = false
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- this.updateCheckAllBtn()
|
|
|
- }
|
|
|
- this.failureList.forEach((failure, index) => {
|
|
|
- if (failure.failureState == 1 || failure.failureState == 2) {
|
|
|
- isFailureLayer = true
|
|
|
- } else {
|
|
|
- isFailureLayer = false
|
|
|
- }
|
|
|
- newFailureList.push(Object.assign({}, failure, { isFailureLayer: isFailureLayer }))
|
|
|
- })
|
|
|
- this.failureList = newFailureList
|
|
|
},
|
|
|
+ //删除购物车商品
|
|
|
deleteList() {
|
|
|
- //删除购物车商品
|
|
|
- this.delGoodsList = []
|
|
|
- this.goodsList.forEach(delitem => {
|
|
|
- let products = delitem.productList
|
|
|
- products.forEach(pros => {
|
|
|
- if (pros.productsChecked) {
|
|
|
- this.delGoodsList += pros.cartId + ','
|
|
|
- }
|
|
|
- })
|
|
|
- })
|
|
|
- this.failureList.forEach(failure => {
|
|
|
- if (failure.productsChecked) {
|
|
|
- this.delGoodsList += failure.cartId + ','
|
|
|
- }
|
|
|
- })
|
|
|
- if (this.delGoodsList.length == 0) {
|
|
|
- this.$util.msg('请选择要删除的商品~', 2000)
|
|
|
- return
|
|
|
+ if (this.cartIds.length <= 0) {
|
|
|
+ return this.$util.msg('请选择要删除的商品~', 2000)
|
|
|
} else {
|
|
|
this.modal = true
|
|
|
this.contentModalText = '确定删除选中的商品吗?'
|
|
|
this.deleteType = 1
|
|
|
}
|
|
|
},
|
|
|
+ // 清空失效商品
|
|
|
deletefailureList() {
|
|
|
- this.delGoodsList = ''
|
|
|
- this.failureList.forEach(failure => {
|
|
|
- this.delGoodsList += failure.cartId + ','
|
|
|
- })
|
|
|
this.modal = true
|
|
|
this.contentModalText = '确定清除所有失效商品吗?'
|
|
|
this.deleteType = 2
|
|
|
},
|
|
|
+ //从购物车移除商品
|
|
|
handleClick(e) {
|
|
|
- //用户操作订单
|
|
|
- let index = e.index
|
|
|
- if (index == 1) {
|
|
|
- this.ProductService.ShoppingCartDelete({
|
|
|
- cartIds: this.delGoodsList
|
|
|
+ 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
|
|
|
})
|
|
|
- .then(response => {
|
|
|
- this.$util.msg('删除成功', 2000)
|
|
|
- setTimeout(() => {
|
|
|
- this.isshowDelbtn = false
|
|
|
- this.InitGetCartGoodsList()
|
|
|
- }, 1000)
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- this.$util.msg(error.msg, 2000)
|
|
|
- })
|
|
|
}
|
|
|
this.modal = false
|
|
|
},
|
|
|
- hideMobel() {
|
|
|
+ //跳转确认订单页面
|
|
|
+ toConfirmation() {
|
|
|
+ if (this.cartIds.length <= 0) {
|
|
|
+ return this.$util.msg('请先选择结算商品~', 2000)
|
|
|
+ }
|
|
|
+ let cartPramsData = {
|
|
|
+ allPrice: this.allPrice,
|
|
|
+ allCount: this.allCount,
|
|
|
+ cartIds: this.cartIds.join(','),
|
|
|
+ productCount: ''
|
|
|
+ }
|
|
|
+ this.$api.navigateTo(`/pages/user/order/create-order?data=${JSON.stringify({ data: cartPramsData })}`)
|
|
|
+ },
|
|
|
+ hideModal() {
|
|
|
this.modal = false
|
|
|
},
|
|
|
navToListPage(item) {
|
|
|
- this.isModallayer = true
|
|
|
this.$api.navigateTo(`/pages/goods/product?productId=${item.productId}`)
|
|
|
},
|
|
|
+ // 窗口高度-footer高度
|
|
|
+ setScrollHeight() {
|
|
|
+ const { windowHeight, pixelRatio } = uni.getSystemInfoSync()
|
|
|
+ setTimeout(() => {
|
|
|
+ const query = uni.createSelectorQuery().in(this)
|
|
|
+ query.selectAll('.footer').boundingClientRect()
|
|
|
+ query.exec(res => {
|
|
|
+ this.windowHeight = windowHeight
|
|
|
+ if (res[0][0]) {
|
|
|
+ this.scrollHeight = windowHeight - res[0][0].height
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, 500)
|
|
|
+ },
|
|
|
setHeaderBtnPosi() {
|
|
|
// 获得胶囊按钮位置信息
|
|
|
let headerBtnPosi = uni.getMenuButtonBoundingClientRect()
|
|
@@ -746,39 +535,6 @@ export default {
|
|
|
}
|
|
|
})
|
|
|
return systeminfo
|
|
|
- },
|
|
|
- PromotionsFormat(promo) {
|
|
|
- //促销活动类型数据处理
|
|
|
- if (promo != null) {
|
|
|
- if (promo.type == 1 && promo.mode == 1) {
|
|
|
- return true
|
|
|
- } else {
|
|
|
- return false
|
|
|
- }
|
|
|
- }
|
|
|
- return false
|
|
|
- }
|
|
|
- },
|
|
|
- watch: {
|
|
|
- //深度监听所有数据,每次改变重新计算总价和总数
|
|
|
- goodsList: {
|
|
|
- deep: true,
|
|
|
- handler(val, oldval) {
|
|
|
- this.totalPeice()
|
|
|
- this.totalCount()
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- onPullDownRefresh() {
|
|
|
- //下拉刷新
|
|
|
- this.InitGetCartGoodsList()
|
|
|
- uni.stopPullDownRefresh()
|
|
|
- },
|
|
|
- onShow() {
|
|
|
- if (this.hasLogin) {
|
|
|
- this.initData()
|
|
|
- } else {
|
|
|
- this.$api.redirectTo('/pages/login/login')
|
|
|
}
|
|
|
}
|
|
|
}
|