zhengjinyi 1 rok pred
rodič
commit
7555ed64ca
1 zmenil súbory, kde vykonal 22 pridanie a 18 odobranie
  1. 22 18
      src/main/resources/static/js/product/list.js

+ 22 - 18
src/main/resources/static/js/product/list.js

@@ -166,35 +166,27 @@ var productList = new Vue({
             const _self = this;
             ProductApi.getCommoditySearchQUeryBrand(_self.brandParam,function (response) {
                 if (response.code === 0 && response.data ) {
-                    var data = response.data;
-                    _self.defaultBrandLists = data.map((el, index) => {
-                        if(_self.hrefBrandId && _self.hrefBrandId === el.id){
+                    let list = response.data;
+                    let brandIdsArray = _self.hrefBrandId.split(',')
+                    console.log('brandIdsArray',brandIdsArray)
+                    _self.defaultBrandLists = list.map((el, index) => {
+                        if(brandIdsArray.some(ele => ele*1 === el.id)){
                             el.isChecked = true;
                         }else{
                             el.isChecked = false;
                         }
                         return el;
                     })
-                    // 设置选中的品牌
-                    if(this.hrefBrandId){
-                        let brandIdsArray = this.hrefBrandId.split(',')
-                        this.params.brandIds = this.hrefBrandId +',';
-                        this.isChoiceBrandText = true
-                        const names = brandIdsArray.map(function (item) {
-                            const find = _self.defaultBrandLists.find(el => el.id === item*1)
-                            return find && find.name
-                        })
-                        this.choiceBrandText = names.join(',').slice(0,15)
-                    }
+                    console.log('defaultBrandLists',_self.defaultBrandLists)
                     _self.brandLists = _self.defaultBrandLists.slice(0,7)
                 }else {
                     console.log('查询品牌列表异常')
                 }
             });
         },
-        choiceBrandHref: function (brand, index) {// PC端跳转链接
+        choiceBrandHref (brand, index) {// PC端跳转链接
+            const _self = this;
             if(this.isShowAllBrandsButton){// 如果多选的情况下
-                var _self = this;
                 brand.isChecked = !brand.isChecked;
                 if (brand.isChecked) {
                     _self.checkedBrandList.push(brand.id);
@@ -215,7 +207,7 @@ var productList = new Vue({
                     '&newg='+ this.params.newFlag;
             }
         },
-        choiceBrandAllHref:function(){// PC全部品牌跳转链接
+        choiceBrandAllHref(){// PC全部品牌跳转链接
             window.location.href =  '/product/list.html?keyword=' + encodeURIComponent(this.params.keyword) +
                 '&bpn=&pro=' + this.params.promotionFlag +
                 '&newg='+ this.params.newFlag;
@@ -354,7 +346,19 @@ var productList = new Vue({
         }
         // 获取对应品牌列表
         this.getCommoditySearchQUeryBrand();
-
+        // 设置选中的品牌
+        setTimeout(()=>{
+            if(this.hrefBrandId){
+                let brandIdsArray = this.hrefBrandId.split(',')
+                this.params.brandIds = this.hrefBrandId +',';
+                this.isChoiceBrandText = true
+                const names = brandIdsArray.map(function (item) {
+                    const find = _self.defaultBrandLists.find(el => el.id === item*1)
+                    return find && find.name
+                })
+                this.choiceBrandText = names.join(',').slice(0,15)
+            }
+        },500)
         // 获取列表数据
         this.getListByKeyword();
     },