diff --git a/src/components/CommodityCard/CommodityCard.vue b/src/components/CommodityCard/CommodityCard.vue index 4ee7115..a430f2d 100644 --- a/src/components/CommodityCard/CommodityCard.vue +++ b/src/components/CommodityCard/CommodityCard.vue @@ -77,8 +77,9 @@ image { } .name { width: 92%; - height: 54rpx; + height: 76rpx; padding: 5px 4%; + box-sizing: border-box; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; diff --git a/src/pages/cart/cart.vue b/src/pages/cart/cart.vue index 22a89c7..5bccab6 100644 --- a/src/pages/cart/cart.vue +++ b/src/pages/cart/cart.vue @@ -8,6 +8,7 @@ @@ -24,7 +25,8 @@ @longpress="delCart(item.cart_id,index)" > @@ -108,46 +110,89 @@ export default { sk_id:String, mp_id:String, isShowBottom : false, //底部弹窗开关 - totalPrice: 0, - pIsoPen: false, - // childIsOpen:[], + // totalPrice: 0, + pIsoPen: Boolean, + childIsOpenArr:[], cart_id:Number, maxCount: 20, cartIndex:Number } }, computed: { - // skInfo(){ - // return filters() - // } + goodInfo () { - // console.log(this.$store.state.read.goodInfo) return this.$store.state.read.goodInfo }, cartList() { - // console.log('cart-list', this.$store.state.cart.cartList); - // this.totalPrice=0 return this.$store.state.cart.cartList }, - childIsOpen() { - const temp = [] - temp.length = this.$store.state.cart.cartList.length - for (let i = 0; i < temp.length; i++) { - temp[i] = false - } - // console.log('this.childisOPne===>', temp) - return temp - }, + totalPrice() { + const itemPriceArr = [] + this.cartList.map(item =>{ + itemPriceArr.push(item.num*item.nowPrice) + }) + let total = 0 + if(this.pIsoPen){ + itemPriceArr.map(item =>{ + total += item + }) + }else{ + this.childIsOpenArr.map((item,index) =>{ + if(item){ + total += itemPriceArr[index] + } + }) + } + return total + }, + }, onShow() { - this.pIsoPen = false }, onLoad: function() { + //全选置否 + this.pIsoPen = false store.dispatch('cart/getCartList', { uid: this.$store.state.user.userInfo.uid, // 用户id }) + .then((res)=>{ + //单选置否 + const temp = [] + temp.length = this.$store.state.cart.cartList.length + for (let i = 0; i < temp.length; i++) { + temp[i] = false + } + this.childIsOpenArr = temp + }) }, methods: { + //全选按钮 + pClick(){ + if(this.pIsoPen){ + this.pIsoPen = false + this.childIsOpenArr.map((item,index)=> { + this.childIsOpenArr[index] = false + }) + }else{ + this.pIsoPen = true + this.childIsOpenArr.map((item,index)=> { + this.childIsOpenArr[index] = true + }) + } + }, + //单选按钮 + childClick(type,index){ + if(type){ + this.childIsOpenArr[index] = false + this.pIsoPen = false + }else{ + this.childIsOpenArr[index] = true + } + if(this.childIsOpenArr.find(item => item == false)==undefined){ + this.pIsoPen = true + } + console.log(this.childIsOpenArr) + }, //修改购物车 chooseCartModi(mp_id,sk_id,price,pid,num,cart_id,index){ // console.log('modi',mp_id,sk_id,price,pid,num,cart_id) @@ -169,7 +214,7 @@ export default { }) this.$forceUpdate() - console.log('21212121212',this.cartList) + // console.log('21212121212',this.cartList) }, //底部弹窗开关 showBottom(isCart,pid,skId,mp_id,cart_id,index){ @@ -190,8 +235,6 @@ export default { this.isShowBottom = false; }, toGoods(id, sk_id) { - console.log('cart-list', this.$store.state.cart.cartList) - console.log('---', '../frameDetail/frameDetail?pid=' + id + '&sk_id=' + sk_id) uni.navigateTo({ url: '../frameDetail/frameDetail?pid=' + id + '&sk_id=' + sk_id, success: res => {}, @@ -205,20 +248,14 @@ export default { }) }, counter(index, isadd, item) { - // console.log('===>>counter ===>num',num) - // console.log('===>>counter ===>isadd',isadd) - console.log('item=====>', item) - console.log('num=====>', item.num) + // console.log('item=====>', item) + // console.log('num=====>', item.num) const nums = parseInt(item.num) if (isadd) { if (nums >= this.maxCount) { this.addDisabled = true } else { this.addDisabled = true - // 修改num - // if (this.childIsOpen[index]) { - // this.totalPrice = this.totalPrice + this.$store.state.cart.cartList[index].nowPrice - // } store.dispatch('cart/modiCart', { uid: this.$store.state.user.userInfo.uid, openid: this.$store.state.user.userInfo.openid, @@ -240,10 +277,7 @@ export default { this.desDisabled = true } else { this.desDisabled = false - // post 请求修改相关参数 - // if (this.childIsOpen[index]) { - // this.totalPrice = this.totalPrice - this.$store.state.cart.cartList[index].nowPrice - // } + store.dispatch('cart/modiCart', { uid: this.$store.state.user.userInfo.uid, openid: this.$store.state.user.userInfo.openid, @@ -263,57 +297,13 @@ export default { } }, - // Change(isopen, indexC) { - // // console.log('lalla===>',isopen) - // this.childIsOpen[indexC] = !isopen - // if (!isopen) { - // this.totalPrice = this.totalPrice + (this.$store.state.cart.cartList[indexC].num * this.$store.state.cart.cartList[indexC].nowPrice) - // } else { - // this.totalPrice = this.totalPrice - (this.$store.state.cart.cartList[indexC].num * this.$store.state.cart.cartList[indexC].nowPrice) - // } - // let m = true - // for (let i = 0; i < this.childIsOpen.length; i++) { - // m = m & this.childIsOpen[i] - // } - // if (m === 1) { - // this.pIsoPen = true - // } else { - // this.pIsoPen = false - // } - // }, - // pChange(isopen) { - // this.pIsoPen = !isopen - // for (let i = 0; i < this.childIsOpen.length; i++) { - // this.childIsOpen[i] = !isopen - // } - // if (this.pIsoPen) { - // // 计算总价逻辑 - // if (this.childIsOpen.length !== 0) { - // for (let i = 0; i < this.childIsOpen.length; i++) { - // if (this.childIsOpen[i]) { - // this.totalPrice = this.totalPrice + (this.$store.state.cart.cartList[i].num * this.$store.state.cart.cartList[i].nowPrice) - // } - // } - // } - // } else { - // this.totalPrice = 0 - // } - // }, delCart(cart_id, index) { - // console.log('userInfo',this.$store.state.user.userInfo) cart_id = parseInt(cart_id) - // console.log('delcart------>cart_id',cart_id) - // console.log('cartlist====>delcart',this.$store.state.cart.cartList) - // console.log('delcart======>index',index) uni.showModal({ title: '是否删除该商品', - // content: '是否删除该商品', success: function (res) { if (res.confirm) { - // if (this.childIsOpen[index]) { - // this.totalPrice = this.totalPrice - (this.$store.state.cart.cartList[index].nowPrice*this.$store.state.cart.cartList[index].num) - // } - console.log('index===>',index) + store.dispatch('cart/delCart', { uid: this.$store.state.user.userInfo.uid, openid: this.$store.state.user.userInfo.openid,