reghao 1 год назад
Родитель
Сommit
8a13418c7e
3 измененных файлов с 24 добавлено и 7 удалено
  1. 4 0
      src/api/mall.js
  2. 11 4
      src/views/mall/Cart.vue
  3. 9 3
      src/views/mall/Mall.vue

+ 4 - 0
src/api/mall.js

@@ -26,6 +26,10 @@ export function addCart(data) {
   return post(mallApi.cartApi, data)
 }
 
+export function deleteFromCart(itemId) {
+  return delete0(mallApi.cartApi + '/' + itemId)
+}
+
 export function getCartItems() {
   return get(mallApi.cartApi)
 }

+ 11 - 4
src/views/mall/Cart.vue

@@ -54,11 +54,11 @@
             <template slot-scope="scope">
               <el-button
                 size="mini"
-                @click="cache(scope.row)"
+                @click="collect(scope.row)"
               >移入关注</el-button>
               <el-button
                 size="mini"
-                @click="cache(scope.row)"
+                @click="deleteOne(scope.row)"
               >删除</el-button>
             </template>
           </el-table-column>
@@ -110,7 +110,7 @@ import {
   getFolderTree,
   moveDiskFile
 } from "@/api/disk";
-import {getCartItems} from "@/api/mall";
+import {deleteFromCart, getCartItems} from "@/api/mall";
 
 export default {
   name: 'Cart',
@@ -158,7 +158,14 @@ export default {
         })
       })
     },
-    cache(row) {
+    collect(row) {
+    },
+    deleteOne(row) {
+      deleteFromCart(row.itemId).then(resp => {
+        if (resp.code === 0) {
+          this.dataList.pop()
+        }
+      })
     },
     handleSelectionChange(val) {
       this.multipleSelection = val

+ 9 - 3
src/views/mall/Mall.vue

@@ -29,9 +29,8 @@
             </el-submenu>
             <el-menu-item index="/mall/cart">
               <template slot="title">
-<!--                <span class="el-icon-shopping-cart-full">购物车</span>-->
                 <span>购物车</span>
-                <el-badge class="item" :value="statusCount" :max="99"></el-badge>
+                <el-badge class="item" :value="cartCount" :max="99"></el-badge>
               </template>
             </el-menu-item>
             <el-menu-item index="/mall/fav">
@@ -74,6 +73,7 @@
 <script>
 import { userMixin } from 'assets/js/mixin'
 import { getAuthedUser } from '@/utils/auth'
+import {getCartItems} from "@/api/mall";
 
 export default {
   name: 'Mall',
@@ -83,7 +83,7 @@ export default {
       user: {
         avatarUrl: '//picx.zhimg.com/v2-df2ee990a53f8fa8d86226026630c354_xl.jpg'
       },
-      statusCount: 12
+      cartCount: 0
     }
   },
   created() {
@@ -92,6 +92,12 @@ export default {
     if (userInfo !== null) {
       this.user = userInfo
     }
+
+    getCartItems().then(resp => {
+      if (resp.code === 0) {
+        this.cartCount = resp.data.length
+      }
+    })
   }
 }
 </script>