Skip to content

Commit

Permalink
Merge pull request #53 from School-of-Website-Engineering/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mason369 authored Jan 21, 2023
2 parents 8e54880 + c6e87f7 commit 7d4b1e6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 16 deletions.
57 changes: 41 additions & 16 deletions src/components/user/Cart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<td>{{ item.coin }}鸡腿</td>
<td>
<div class="step">
<span @click="add(item.id)">-</span>
<span>-</span>
<input
type="text"
disabled
Expand All @@ -71,7 +71,7 @@
</div>
</template>
<script>
import { reqGetCartList } from "@/request/api";
import { reqGetCartList, reqDeleteCart } from "@/request/api";
export default {
data() {
Expand All @@ -85,24 +85,49 @@ export default {
cartList : []
};
},
async created() {
const { data: cartList } = await reqGetCartList();
this.cartList = cartList;
console.log(this.cartList);
//将cartList中的total数量存入stepNum
this.cartList.forEach((item) => {
this.stepNum.push(item.total);
});
console.log(this.stepNum);
created() {
this.getCartList();
},
methods: {
// 获取购物车列表
async getCartList() {
const { data: cartList } = await reqGetCartList();
this.cartList = cartList;
console.log(this.cartList);
//将cartList中的total数量存入stepNum
this.cartList.forEach((item) => {
this.stepNum.push(item.total);
});
console.log(this.stepNum);
},
// 删除购物车
deleteShopCart(id) {
console.log(id);
},
add(id) {
console.log(id);
}
this.$confirm("确定删除该商品吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText : "取消",
type : "warning"
})
.then(async() => {
const data = await reqDeleteCart(id);
console.log(data);
if (data.code === 0) {
this.$message({
type : "success",
message: "删除成功!"
});
this.cartList = this.cartList.filter(
(item) => item.id !== id
);
}
})
.catch(() => {
this.$message({
type : "info",
message: "已取消删除"
});
});
this.getCartList();
}
},
computed: {
// 计算总价
Expand Down
3 changes: 3 additions & 0 deletions src/request/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ export const reqGetGoodsSearch = (params) => request.get("/products", { params }

//获取购物车列表
export const reqGetCartList = () => request.get("/shop/carts");

//删除购物车商品
export const reqDeleteCart = (id) => request.delete(`/shop/carts?productIds=${id}`);

0 comments on commit 7d4b1e6

Please sign in to comment.