Authored by 陈峰

Merge branch 'hotfix/brand-error-channel' into 'gray'

Hotfix/brand error channel

1、商品详情页优化

See merge request !30
1 <template> 1 <template>
2 - <div class="image-swipe" v-if="allLoaded"> 2 + <div class="image-swipe" v-if="showSwiper">
3 <div class="swipe-wrap" @click.prevent="showcase()"> 3 <div class="swipe-wrap" @click.prevent="showcase()">
4 <swiper :options="swiperOption" ref="swiper"> 4 <swiper :options="swiperOption" ref="swiper">
5 <swiper-slide v-for="item in goodsList" :key="item.title"> 5 <swiper-slide v-for="item in goodsList" :key="item.title">
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 vm.setActiveSlide(swiper.realIndex) 41 vm.setActiveSlide(swiper.realIndex)
42 } 42 }
43 }, 43 },
44 - allLoaded: false 44 + showSwiper: false
45 }; 45 };
46 }, 46 },
47 components: { 47 components: {
@@ -59,49 +59,12 @@ @@ -59,49 +59,12 @@
59 let temp = val.slice(); 59 let temp = val.slice();
60 const len = temp.length; 60 const len = temp.length;
61 61
62 - if (len > 1 && len < 4) { 62 + if (len > 1) {
63 temp.unshift(temp.splice(len - 1)[0]); 63 temp.unshift(temp.splice(len - 1)[0]);
64 } 64 }
65 65
66 - if (len >= 4) {  
67 - const sp = temp.splice(0, 2);  
68 -  
69 - temp.push(sp[0]);  
70 - temp.push(sp[1]);  
71 - }  
72 this.goodsList = temp; 66 this.goodsList = temp;
73 this.slideCount = this.goodsList.length; 67 this.slideCount = this.goodsList.length;
74 - },  
75 - goodsList(goods) {  
76 - const preloadImg = (list, loaded) => {  
77 - loaded = loaded || [];  
78 -  
79 - // 加载完成  
80 - if(list.length === 0) {  
81 - let $ssr = document.getElementById('ssr');  
82 - $ssr && $ssr.remove();  
83 - this.allLoaded = true;  
84 - return;  
85 - }  
86 -  
87 - let img = new Image();  
88 - img.src = util.getImgUrl(list[0].image_url, '580', '770');  
89 -  
90 - if(img.complete) {  
91 - loaded.push(img);  
92 - list.shift();  
93 - preloadImg(list, loaded);  
94 - }  
95 - else {  
96 - img.onload = function() {  
97 - loaded.push(img);  
98 - list.shift();  
99 - preloadImg(list, loaded);  
100 - };  
101 - }  
102 - };  
103 -  
104 - preloadImg(goods[0].images_list);  
105 } 68 }
106 }, 69 },
107 methods: { 70 methods: {
@@ -122,25 +85,10 @@ @@ -122,25 +85,10 @@
122 this.activeIndex = this.calcIndex(idx); 85 this.activeIndex = this.calcIndex(idx);
123 }, 86 },
124 calcIndex(realIdx){ 87 calcIndex(realIdx){
125 - const len = this.goods.length;  
126 -  
127 - if (len >= 4) {  
128 - if (realIdx === len -1) {  
129 - realIdx = 0;  
130 - } else {  
131 - realIdx += 1;  
132 - }  
133 -  
134 - if (realIdx < len -2) {  
135 - realIdx += 2;  
136 - } else if (realIdx === len -2) {  
137 - realIdx = 0;  
138 - } else {  
139 - realIdx = 1;  
140 - }  
141 - }  
142 -  
143 return realIdx; 88 return realIdx;
  89 + },
  90 + show() {
  91 + this.showSwiper = true;
144 } 92 }
145 } 93 }
146 }; 94 };
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <div> 2 <div>
3 <top-nav v-if="isApp"></top-nav> 3 <top-nav v-if="isApp"></top-nav>
4 <show-box :is-first="true" class="carousel"> 4 <show-box :is-first="true" class="carousel">
5 - <image-swiper :goods="entity.goods_list"></image-swiper> 5 + <image-swiper :goods="entity.goods_list" ref="imageSwiper"></image-swiper>
6 </show-box> 6 </show-box>
7 <show-box :zero-top-margin="true" class="action"> 7 <show-box :zero-top-margin="true" class="action">
8 <operation-bar :entity="entity" :brand="brand" :share-title="entity.product_name" 8 <operation-bar :entity="entity" :brand="brand" :share-title="entity.product_name"
@@ -374,6 +374,11 @@ @@ -374,6 +374,11 @@
374 $.get('/product/mightLike', {skn, shopId}).then(res => { 374 $.get('/product/mightLike', {skn, shopId}).then(res => {
375 this.preferList = res.data || []; 375 this.preferList = res.data || [];
376 }); 376 });
  377 + },
  378 +
  379 + dataLoaded() {
  380 + this.$refs.imageSwiper.show();
  381 + document.querySelector('#ssr').remove();
377 } 382 }
378 }, 383 },
379 created() { 384 created() {
@@ -391,6 +396,7 @@ @@ -391,6 +396,7 @@
391 return; 396 return;
392 } 397 }
393 this.entity = result.data; 398 this.entity = result.data;
  399 + this.dataLoaded();
394 this.brand = result.data.brand_info; 400 this.brand = result.data.brand_info;
395 if (this.entity.storage === 0 || this.entity.status === 0) { 401 if (this.entity.storage === 0 || this.entity.status === 0) {
396 this.isSoldOut = true; 402 this.isSoldOut = true;