695593266@qq.com 4 gün önce
ebeveyn
işleme
a47f9ae3f3

+ 53 - 32
src/views/material/product/components/index-data.vue

@@ -917,53 +917,72 @@
         });
       },
       /* 表格数据源 */
+      hasCurrentCategory() {
+        return (
+          this.currentId !== undefined &&
+          this.currentId !== null &&
+          this.currentId !== ''
+        );
+      },
+      getCategoryParams(params = {}) {
+        return {
+          ...params,
+          categoryLevelId: this.currentId
+        };
+      },
       async datasource({ page, limit, where, order }) {
         this.currentPage = page;
-        let labs = getMaterialList({
+        if (!this.hasCurrentCategory()) {
+          return {
+            pageNum: page,
+            current: page,
+            size: limit,
+            count: 0,
+            list: []
+          };
+        }
+        const params = this.getCategoryParams({
           pageNum: page,
           size: limit,
           ...this.sort,
-          ...where,
-          categoryLevelId: this.currentId
+          ...where
         });
-        this.whereData = {
-          pageNum: page,
-          size: limit,
-          ...this.sort,
-          ...where,
-          categoryLevelId: this.currentId
-        };
-        let a = await labs;
-
-        return labs;
+        this.whereData = params;
+        return getMaterialList(params);
       },
       /* 刷新表格 */
       reload(where) {
-        let labs = {
-          page: 1,
-          where: where,
-          categoryLevelId: this.currentId
-        };
-        this.whereData = labs;
-        this.$refs.table.reload({
+        if (!this.hasCurrentCategory()) {
+          return;
+        }
+        let labs = this.getCategoryParams({
           page: 1,
-          where: where,
-          categoryLevelId: this.currentId
+          where: where
         });
+        this.whereData = labs;
+        this.$refs.table.reload(
+          this.getCategoryParams({
+            page: 1,
+            where: where
+          })
+        );
       },
       /* 刷新表格 */
       reloadNew(where) {
-        let labs = {
+        if (!this.hasCurrentCategory()) {
+          return;
+        }
+        let labs = this.getCategoryParams({
           page: 1,
-          where: where,
-          categoryLevelId: this.currentId
-        };
-        this.whereData = labs;
-        this.$refs.table.reload({
-          page: this.currentPage,
-          where: where,
-          categoryLevelId: this.currentId
+          where: where
         });
+        this.whereData = labs;
+        this.$refs.table.reload(
+          this.getCategoryParams({
+            page: this.currentPage,
+            where: where
+          })
+        );
       },
       getFieldModel() {
         fieldModel({ relevance: 't_main_category' }).then((res) => {
@@ -1186,7 +1205,9 @@
     watch: {
       // 监听物料组id变化
       currentId() {
-        this.reload();
+        if (this.hasCurrentCategory()) {
+          this.reload();
+        }
       },
 
       $route: {

+ 3 - 1
src/views/material/product/index.vue

@@ -166,7 +166,9 @@
     activated() {
       // this.getTreeData();
       this.$nextTick(() => {
-        this.$refs.listData.reloadNew(this.where);
+        if (this.current && this.current.id && this.$refs.listData) {
+          this.$refs.listData.reloadNew(this.where);
+        }
       });
     },
     computed: {

+ 3 - 1
src/views/material/product/oneProduct.vue

@@ -170,7 +170,9 @@
       this.$nextTick(() => {
         if (this.$refs.listData) {
           this.$refs.listData.getCategoryNeedApprove();
-          this.$refs.listData.reloadNew(this.where);
+          if (this.current && this.current.id) {
+            this.$refs.listData.reloadNew(this.where);
+          }
         }
       });
     },