zs 2 년 전
부모
커밋
0470a8e552
1개의 변경된 파일31개의 추가작업 그리고 11개의 파일을 삭제
  1. 31 11
      pages/market/index.vue

+ 31 - 11
pages/market/index.vue

@@ -306,17 +306,37 @@
 					content: '请选择要删除的商品',
 					success: async (res) => {
 						if (!res.confirm) return
-						const result = await this.$api(`/cart/${e.cart_id}`, 'Delete');
-						if (result.errcode === 0) {
-							list = list.map(i => ({
-								...i,
-								goods: i.goods.filter(f => f.cart_id !== e.cart_id)
-							}))
-							this.$set(this, `list`, list);
-							// 检查店铺内是否还有商品
-							this.checkShopGoodsExist();
-							// 计算总额
-							this.countMoney();
+						if (e?.cart_id) {
+							const result = await this.$api(`/cart/${e.cart_id}`, 'Delete');
+							if (result.errcode === 0) {
+								list = list.map(i => ({
+									...i,
+									goods: i.goods.filter(f => f.cart_id !== e.cart_id)
+								}))
+								this.$set(this, `list`, list);
+								// 检查店铺内是否还有商品
+								this.checkShopGoodsExist();
+								// 计算总额
+								this.countMoney();
+							}
+						} else {
+							console.log(1);
+							const goodsList = this.list.map(i => i.goods).flat();
+							const cartIds = goodsList.filter(i => i.check).map(i => i.cart_id)
+							for (let val of cartIds) {
+								const result = await this.$api(`/cart/${val}`, 'Delete');
+								if (result.errcode === 0) {
+									list = list.map(i => ({
+										...i,
+										goods: i.goods.filter(f => f.cart_id !== val)
+									}))
+									this.$set(this, `list`, list);
+									// 检查店铺内是否还有商品
+									this.checkShopGoodsExist();
+									// 计算总额
+									this.countMoney();
+								}
+							}
 						}
 					}
 				});