删除购物车

feature/v-xuexi
wangdong 9 months ago
parent f83998b75a
commit 67001a2918
  1. 4
      api/store.js
  2. 2
      pages/index/index.vue
  3. 42
      pages/store/shoppingCart.vue

@ -72,3 +72,7 @@ export function getCartList(params) {
export function joinCart(params) {
return http.get("/Auth_Api/set_cart", params);
}
export function deleteCart(params) {
return http.get("/auth_api/remove_cart", params);
}

@ -121,7 +121,7 @@
<view class="price">
<span class="num">{{ item.price }}</span>
</view>
<view class="sale-num">已售588</view>
<view class="sale-num">已售{{ item.sales || 0 }}</view>
</view>
</view>
</navigator>

@ -4,7 +4,7 @@
<view class="cart-container">
<view class="cart-info flex flex-center-x">
<view> {{ goodsList.length }} 件商品</view>
<view class="edit">编辑</view>
<view class="edit" @click="isEdit = !isEdit;checkedGoods = [];">{{ isEdit ? '完成' : '编辑' }}</view>
</view>
<view class="list">
<view v-for="item in goodsList" :key="item.id" class="item">
@ -39,8 +39,9 @@
<label class="radio" @click="changeAllSelect">
<radio value="全部" :checked="allSelect" /><text>全选</text>
</label>
<view class="total">合计<text>{{ total }}</text></view>
<view class="pay-btn" @click="toPay">去结算<text v-if="checkedGoods.length > 0">({{ checkedGoods.length }})</text></view>
<view v-if="!isEdit" class="total">合计<text>{{ total }}</text></view>
<view v-if="!isEdit" class="pay-btn" @click="toPay">去结算<text v-if="checkedGoods.length > 0">({{ checkedGoods.length }})</text></view>
<view v-else class="delete-btn" @click="deleteGoods">删除</view>
</view>
<PayDialog v-if="initDataLoading" :open.sync="payDialogOpen" :money="Number(total)" :now_money="now_money"
:pay_type_num="pay_type_num" :special_id="Number(special_id)" :is-wechat="isWechat" :is-alipay="is_alipay" :is-balance="is_yue"
@ -49,7 +50,7 @@
</template>
<script>
import { getCartList } from "@/api/store";
import { getCartList, deleteCart } from "@/api/store";
import {
getInitData
} from "@/api/special";
@ -74,6 +75,7 @@
templateId: "",
wxpayH5: false,
initDataLoading: false,
isEdit: false,
};
},
watch: {
@ -157,6 +159,32 @@
addCartNum(item) {
item.cart_num = Number(item.cart_num) + 1;
},
deleteGoods() {
if (this.checkedGoods.length == 0) {
this.$util.showMsg("请选择商品");
} else {
uni.showModal({
title: "提示",
content: `确定删除${this.checkedGoods.length}件商品?`,
success: async ({ confirm }) => {
if (!confirm) return;
// uni.showModal({ mask: true });
try {
const { data } = await deleteCart({
ids: this.checkedGoods.join(',')
});
uni.hideLoading();
this.$util.showMsg("删除成功");
this.goodsList = this.goodsList.filter(item => !this.checkedGoods.includes(item.productInfo.id));
this.checkedGoods = [];
} catch (err) {
uni.hideLoading();
console.log(err);
}
},
});
}
},
toPay() {
console.log(111);
if (this.total === 0) {
@ -415,7 +443,7 @@
color: #FF2825;
}
}
.pay-btn {
.pay-btn, .delete-btn {
width: 240rpx;
height: 100rpx;
background: #0F74BB;
@ -424,6 +452,10 @@
font-size: 28rpx;
color: #fff;
}
.delete-btn {
background: #F8473E;
margin-left: auto;
}
}
}
</style>
Loading…
Cancel
Save