shish 9 kuukautta sitten
vanhempi
commit
f33e945d0a
1 muutettua tiedostoa jossa 25 lisäystä ja 19 poistoa
  1. 25 19
      mallApp/src/pages/home/category.vue

+ 25 - 19
mallApp/src/pages/home/category.vue

@@ -322,30 +322,31 @@ export default {
     },
     // 分类
     getMyClass () {
-      return getClass().then(res => {
-        if(res.code && res.code == 1){
-          this.form.categoryId = res.data[0].id
-          this.tabbar = res.data
-        }
-      })
-    },
-    // 列表
-    getGoodList () {
       // 获取当前筛选标签的值
       const filterValue = this.filterTabs[this.currentFilterTab].value
-      const params = {
-        ...this.form, 
-        page: this.list.page,
-        pageSize: 10,
-        requestType: 'mall'
-      }
+      const params = {}
       
       // 添加flower筛选参数(-1表示全部,0表示鲜花,1表示绿植,2表示仿真花)
       if (filterValue !== -1) {
         params.flower = filterValue
       }
       
-      return getList(params).then(res => {
+      return getClass(params).then(res => {
+        if(res.code && res.code == 1){
+          if(res.data && res.data.length > 0) {
+            this.form.categoryId = res.data[0].id
+            this.tabbar = res.data
+          } else {
+            // 如果没有分类数据,清空tabbar
+            this.tabbar = []
+            this.form.categoryId = ''
+          }
+        }
+      })
+    },
+    // 列表
+    getGoodList () {
+      return getList({...this.form, page: this.list.page,pageSize:10,requestType:'mall'}) .then(res => {
           // 处理商品列表数据,completes方法来自list混入
           // 该方法会处理分页数据,更新list对象的data、page、finished等属性
           // res包含接口返回的商品列表数据,completes方法会将数据添加到this.list.data中
@@ -421,9 +422,14 @@ export default {
       // 切换筛选标签时清空搜索状态
       this.clearSearchState()
       
-      // 重置列表并重新加载数据
-      this.resetList()
-      this.getGoodList()
+      // 重置当前分类选择
+      this.currentTab = 0
+      
+      // 重新获取分类数据,然后获取商品列表
+      this.getMyClass().then(() => {
+        this.resetList()
+        this.getGoodList()
+      })
     }
   },