|
@@ -127,7 +127,7 @@
|
|
|
<!-- 购物车栏 begin -->
|
|
|
<view class="cart-box">
|
|
|
<view class="mark">
|
|
|
- <image src="/static/img/ic-shopping-cart.png" class="cart-img" @tap="cart.length !== 0 ? lockcatble = !lockcatble : ''"></image>
|
|
|
+ <image src="/static/img/ic-shopping-cart.png" class="cart-img" @tap="openCart"></image>
|
|
|
<view class="tag" v-if="cart.length > 0">{{ getCartGoodsNumber }}</view>
|
|
|
</view>
|
|
|
<view style="font-weight: 500;font-size: 27rpx;color: #999999;" class="price" v-if="cart.length === 0">配送费2元</view>
|
|
@@ -144,7 +144,7 @@
|
|
|
<!-- 判断数量大于0显示 -->
|
|
|
<view class="mode-clear" v-if="getCartGoodsNumber>0">
|
|
|
<text class="mode-txt">数量:<text style="color: #FD6716 ;">({{getCartGoodsNumber}})</text></text>
|
|
|
- <text @tap="cart = [], lockcatble = false" class="mode-txt1">清空</text>
|
|
|
+ <text @tap="clearCart" class="mode-txt1">清空</text>
|
|
|
</view>
|
|
|
<view class="mode-box">
|
|
|
<view class="items">
|
|
@@ -161,12 +161,12 @@
|
|
|
<view class="price_and_action">
|
|
|
<text class="price">¥{{ good.price * good.number }}</text>
|
|
|
<view class="btn-group">
|
|
|
- <button type="default" v-show="goodCartNum(good.props_text)" plain class="btn reduce_btn" size="mini"
|
|
|
- hover-class="none" @tap="handleReduceFromCart(item, good)">
|
|
|
+ <button type="default" plain class="btn reduce_btn" size="mini"
|
|
|
+ hover-class="none" @tap="handleReduceFromCart(good.category, good)">
|
|
|
<view class="iconfont iconsami-select">-</view>
|
|
|
</button>
|
|
|
- <view class="number" v-show="goodCartNum(good.props_text)">{{ goodCartNum(good.props_text) }}</view>
|
|
|
- <button type="primary" class="btn add_btn bg-color" size="min" hover-class="none" @tap="handleAddToCart(item, good, 1)">
|
|
|
+ <view class="number" >{{ good.number }}</view>
|
|
|
+ <button type="primary" class="btn add_btn bg-color" size="min" hover-class="none" @tap="handleAddToCart(good.category, good, 1)">
|
|
|
<view class="iconfont iconadd-select">+</view>
|
|
|
</button>
|
|
|
</view>
|
|
@@ -446,6 +446,14 @@
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ clearCart(){
|
|
|
+ this.cart = []
|
|
|
+ this.lockcatble = false
|
|
|
+ },
|
|
|
+ openCart(){
|
|
|
+ console.log(this.cart,'this.cart')
|
|
|
+ this.cart.length !== 0 ? this.lockcatble = !this.lockcatble : ''
|
|
|
+ },
|
|
|
getFormattedSales(value) {
|
|
|
// 转换成字符串,然后截取前三位,并添加“+”
|
|
|
return value.length>3?`${String(value).slice(0, 3)}+`:value;
|
|
@@ -594,7 +602,7 @@
|
|
|
// return ''
|
|
|
},
|
|
|
handleReduceFromCart(item, good) {
|
|
|
- const goodText = this.getGoodSelectedProps(this.good) // 购物车当前选中的规格
|
|
|
+ const goodText = this.getGoodSelectedProps(this.good?.id ? this.good : good) // 购物车当前选中的规格
|
|
|
const index = this.cart.findIndex(item => item.id === good.id && item.props_text === goodText)
|
|
|
this.cart[index].number -= 1
|
|
|
if (this.cart[index].number <= 0) {
|
|
@@ -602,7 +610,7 @@
|
|
|
}
|
|
|
},
|
|
|
handleAddToCart(cate, good, num) { //添加到购物车
|
|
|
- const goodText = this.getGoodSelectedProps(this.good) // 购物车当前选中的规格
|
|
|
+ const goodText = this.getGoodSelectedProps(this.good?.id ? this.good : good) // 购物车当前选中的规格
|
|
|
const index = this.cart.findIndex(item => {
|
|
|
// if (good.use_property) {
|
|
|
// !good.props_text ? good.props_text = this.getGoodSelectedProps(good) : ''
|
|
@@ -622,29 +630,29 @@
|
|
|
number: num,
|
|
|
icon: good.icon,
|
|
|
use_property: good.use_property || goodText,
|
|
|
- props_text: this.getGoodSelectedProps(this.good),
|
|
|
- props: this.getGoodSelectedProps(this.good, 'id'),
|
|
|
+ props_text: this.getGoodSelectedProps(this.good?.id ? this.good : good),
|
|
|
+ props: this.getGoodSelectedProps(this.good?.id ? this.good : good, 'id'),
|
|
|
productid: this.productObj[goodText].id,
|
|
|
iconText: this.productObj[goodText].image,
|
|
|
...good
|
|
|
})
|
|
|
}
|
|
|
- let q = {
|
|
|
- productId: parseFloat(good.id),
|
|
|
- cartNum: parseFloat(index > -1 ? num+this.cart[index].number : num),
|
|
|
- isNew: false,
|
|
|
- productAttrUnique: this.productObj[goodText].id,
|
|
|
- };
|
|
|
- let that = this
|
|
|
- postCartAdd(q)
|
|
|
- .then(function(res) {
|
|
|
- that.$util.Tips({
|
|
|
- title: "添加购物车成功",
|
|
|
- success: () => {
|
|
|
- },
|
|
|
- });
|
|
|
- })
|
|
|
- console.log(this.cart, '购物车')
|
|
|
+ // let q = {
|
|
|
+ // productId: parseFloat(good.id),
|
|
|
+ // cartNum: parseFloat(index > -1 ? num+this.cart[index].number : num),
|
|
|
+ // isNew: false,
|
|
|
+ // productAttrUnique: this.productObj[goodText].id,
|
|
|
+ // };
|
|
|
+ // let that = this
|
|
|
+ // postCartAdd(q)
|
|
|
+ // .then(function(res) {
|
|
|
+ // that.$util.Tips({
|
|
|
+ // title: "添加购物车成功",
|
|
|
+ // success: () => {
|
|
|
+ // },
|
|
|
+ // });
|
|
|
+ // })
|
|
|
+ // console.log(this.cart, '购物车')
|
|
|
},
|
|
|
toPay() {
|
|
|
// if(!this.isLogin) {
|