浏览代码

仓库、品牌、分类数据缓存

lilei 1 年之前
父节点
当前提交
1611db6896

+ 4 - 0
src/store/modules/app.js

@@ -42,6 +42,10 @@ const app = {
     curActionPermission: '', // 当前激活状态的权限码
     showPdfPrintView: false, // pdf 打印预览
     pdfUrl: '',
+    productBrandAllList: null, // 产品品牌列表
+    productTypeAllList: null, // 产品分类列表
+    warehouseAuthList: null, // 有权限的仓库列表
+    warehouseAllList: null, // 无权限所有仓库列表
     defWarehouse: null, // 默认仓库
     isWarehouse: false// 仓库管理权限
   },

+ 48 - 16
src/views/common/chooseWarehouse.js

@@ -57,11 +57,28 @@ const warehouse = {
     }
   },
   mounted () {
+    // 如果已经存在仓库数据
+    const a = this.$store.state.app.warehouseAuthList 
+    const b = this.$store.state.app.warehouseAllList
+
     if (this.isPermission) {
       this.$store.state.app.defWarehouse = null
       this.$store.state.app.isWarehouse = true
+      if(a){
+        this.setWarehouseData(a)
+      }else{
+        // 不存在,远程获取
+        this.getWarehouse()
+      }
+    }else{
+      if(b){
+        this.setWarehouseData(b)
+      }else{
+        // 不存在,远程获取
+        this.getWarehouse()
+      }
     }
-    this.getWarehouse()
+    
   },
   watch: {
     value (newValue, oldValue) {
@@ -79,26 +96,36 @@ const warehouse = {
       this.$emit('input', value)
       this.$emit('change', value)
     },
+    // 设置仓库数据
+    setWarehouseData(data){
+      // 有权限控制的
+      if (this.isPermission) {
+        this.$store.state.app.isWarehouse = true
+        this.$store.state.app.defWarehouse = data && data[0]
+      }
+      this.warehouseData = data || []
+      let defaultWarehouseVal = {}
+      if (this.isDefault) {
+        defaultWarehouseVal = data.find(con => {
+          return con.defaultFlag == 1 ? con.warehouseSn : ''
+        })
+        this.defaultVal = defaultWarehouseVal.warehouseSn
+        this.$emit('load', defaultWarehouseVal.warehouseSn, this.warehouseData)
+      } else {
+        this.$emit('load', null, this.warehouseData)
+      }
+    },
     //  获取仓库列表
     getWarehouse () {
       const ajaxName = this.isPermission ? queryAuthWarehouse : warehouseAllList
       ajaxName({}).then(res => {
         if (res.status == 200) {
-          // 有权限控制的
-          if (this.isPermission) {
-            this.$store.state.app.isWarehouse = true
-            this.$store.state.app.defWarehouse = res.data && res.data[0]
-          }
-          this.warehouseData = res.data || []
-          let defaultWarehouseVal = {}
-          if (this.isDefault) {
-            defaultWarehouseVal = res.data.find(con => {
-              return con.defaultFlag == 1 ? con.warehouseSn : ''
-            })
-            this.defaultVal = defaultWarehouseVal.warehouseSn
-            this.$emit('load', defaultWarehouseVal.warehouseSn, this.warehouseData)
-          } else {
-            this.$emit('load', null, this.warehouseData)
+          this.setWarehouseData(res.data)
+          // 存储仓库数据本地
+          if(this.isPermission){
+            this.$store.state.app.warehouseAuthList = this.warehouseData
+          }else{
+            this.$store.state.app.warehouseAllList = this.warehouseData
           }
         } else {
           if (this.isPermission) {
@@ -114,6 +141,11 @@ const warehouse = {
     },
     clearData () {
       this.handleChange([])
+    },
+    // 清空缓存的数据
+    clearCacheData(){
+      this.$store.state.app.warehouseAuthList = null
+      this.$store.state.app.warehouseAllList = null
     }
   }
 }

+ 30 - 10
src/views/common/productBrand.js

@@ -27,10 +27,6 @@ const ProductBrand = {
       type: String,
       default: '请选择产品品牌'
     },
-    sysFlag: {
-      type: String,
-      default: ''
-    },
     brandType: {
       type: String,
       default: ''
@@ -47,7 +43,13 @@ const ProductBrand = {
     };
   },
   mounted() {
-    this.getProductBrand()
+    const a = this.$store.state.app.productBrandAllList
+    // 有缓存
+    if(a){
+      this.setBrandData(a||[])
+    }else{
+      this.getProductBrand()
+    }
   },
   watch: {
     value(newValue, oldValue) {
@@ -55,7 +57,13 @@ const ProductBrand = {
     },
     brandType(newValue,oldValue){
       this.handleChange(undefined)
-      this.getProductBrand()
+      const a = this.$store.state.app.productBrandAllList
+      // 有缓存
+      if(a){
+        this.setBrandData(a||[])
+      }else{
+        this.getProductBrand()
+      }
     }
   },
   methods: {
@@ -70,14 +78,26 @@ const ProductBrand = {
       this.$emit('input', value);
       this.$emit('change', value, this.id, row);
     },
-    //  产品品牌列表, sysFlag: 1 箭冠 0 自建
+    setBrandData(data){
+      // brandType: 1 自主品牌 2 代理品牌
+      if(this.brandType!=''){
+        this.productBrandList = data.filter(item => item.brandType == this.brandType)
+      }else{
+        this.productBrandList = data
+      }
+    },
+    //  产品品牌列表,
     getProductBrand () {
-      productBrandQuery({ 'sysFlag': this.sysFlag, 'brandType': this.brandType }).then(res => {
+      productBrandQuery({}).then(res => {
+        let ret = []
         if (res.status == 200) {
-          this.productBrandList = res.data
+          ret = res.data
         } else {
-          this.productBrandList = []
+          ret = []
         }
+        // 缓存数据
+        this.$store.state.app.productBrandAllList = ret
+        this.setBrandData(ret)
       })
     },
   },

+ 9 - 1
src/views/common/productTypeAll.js

@@ -50,7 +50,13 @@ const ProductType = {
     }
   },
   mounted () {
-    this.getProductType()
+    const a = this.$store.state.app.productTypeAllList
+    // 如果有缓存
+    if(this.isAll && a){
+      this.productTypeList = a || []
+    }else{
+      this.getProductType()
+    }
   },
   methods: {
     filter(inputValue, path) {
@@ -80,6 +86,8 @@ const ProductType = {
           } else {
             this.productTypeList = []
           }
+          // 缓存数据
+          this.$store.state.app.productTypeAllList = this.productTypeList
         })
       }else{
         productTypeQuery({}).then(res => {

+ 1 - 0
src/views/salesManagement/salesQueryNew/edit.vue

@@ -254,6 +254,7 @@ export default {
       })
     },
     showNewActiveOk(){
+      this.showNewActiveModal = false
       this.pageInit()
     },
     // 添加产品,包括正常和活动的产品

+ 5 - 0
src/views/user/Login.vue

@@ -191,6 +191,11 @@ export default {
         customActiveKey,
         Login
       } = this
+      // 清空仓库缓存数据
+      this.$store.state.app.warehouseAuthList = null
+      this.$store.state.app.warehouseAllList = null
+      this.$store.state.app.productTypeAllList = null
+      this.$store.state.app.productBrandAllList = null
 
       state.loginBtn = true
       const validateFieldsKey = customActiveKey === 'tab1' ? ['username', 'password', 'rememberMe'] : ['mobile', 'captcha']