Authored by ccbikai

Merge branch 'develop' of git.yoho.cn:fe/yohoblk-wap into develop

@@ -95,6 +95,15 @@ const component = { @@ -95,6 +95,15 @@ const component = {
95 params.method = 'app.favorite.cancel'; 95 params.method = 'app.favorite.cancel';
96 } 96 }
97 97
  98 + if (!req.user.uid) {
  99 + // 未登陆
  100 + res.json({
  101 + code: 403
  102 + });
  103 +
  104 + return;
  105 + }
  106 +
98 model.favorite(params).then(result => { 107 model.favorite(params).then(result => {
99 res.json(result); 108 res.json(result);
100 }).catch(next); 109 }).catch(next);
1 <template> 1 <template>
2 <ul class="feature-options"> 2 <ul class="feature-options">
3 <li v-for="item in options"> 3 <li v-for="item in options">
4 - <button :class="{ 'button-solid': value && value === item.value}" 4 + <button :class="{ 'button-solid': item.value && value.value === item.value}"
5 :disabled="item.disabled" 5 :disabled="item.disabled"
6 - @click="selectOption(item.value)" 6 + @click="selectOption(item)"
7 class="button feature-button"> 7 class="button feature-button">
8 {{item.text}} 8 {{item.text}}
9 </button> 9 </button>
@@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
38 }, 38 },
39 data() { 39 data() {
40 return { 40 return {
41 - value: '' 41 + value: {}
42 }; 42 };
43 }, 43 },
44 watch: { 44 watch: {
@@ -165,6 +165,7 @@ @@ -165,6 +165,7 @@
165 const selection = {}; 165 const selection = {};
166 const colorSizes = {}; 166 const colorSizes = {};
167 const stocks = {}; 167 const stocks = {};
  168 + const self = this;
168 169
169 // 更新颜色 170 // 更新颜色
170 this.colors = this.entity.goodsList.filter((goods)=> { 171 this.colors = this.entity.goodsList.filter((goods)=> {
@@ -174,7 +175,7 @@ @@ -174,7 +175,7 @@
174 // 缩略图 175 // 缩略图
175 thumbnails[goods.colorId] = goods.colorImage; 176 thumbnails[goods.colorId] = goods.colorImage;
176 177
177 - // 更新颜色对应尺码 178 + // 更新颜色对应尺码 生成colorId 与 size的 映射
178 colorSizes[goods.colorId] = goods.goodsSizeBoList.map((size)=> { 179 colorSizes[goods.colorId] = goods.goodsSizeBoList.map((size)=> {
179 if (!stocks[goods.colorId]) { 180 if (!stocks[goods.colorId]) {
180 stocks[goods.colorId] = 0; 181 stocks[goods.colorId] = 0;
@@ -183,11 +184,21 @@ @@ -183,11 +184,21 @@
183 // 默认选中有库存的第一个颜色尺码 184 // 默认选中有库存的第一个颜色尺码
184 if (size.goodsSizeStorageNum > 0) { 185 if (size.goodsSizeStorageNum > 0) {
185 if (!selection.color) { 186 if (!selection.color) {
186 - selection.color = goods.colorId; 187 + self.selection.color = selection.color = {
  188 + text: goods.colorName,
  189 + value: goods.colorId,
  190 + disabled: false
  191 + };
187 } 192 }
188 193
189 if (!selection.size && size.goodsSizeStorageNum > 0) { 194 if (!selection.size && size.goodsSizeStorageNum > 0) {
190 - selection.size = size.goodsSizeSkuId; 195 + self.selection.size = selection.size = {
  196 + text: size.sizeName,
  197 + value: size.goodsSizeSkuId,
  198 + goodsId: size.goodsId,
  199 + disabled: false
  200 + };
  201 +
191 } 202 }
192 203
193 // 计算所有尺码的库存 204 // 计算所有尺码的库存
@@ -209,7 +220,7 @@ @@ -209,7 +220,7 @@
209 }; 220 };
210 }); 221 });
211 222
212 - this.sizes = colorSizes[selection.color]; 223 + this.sizes = colorSizes[selection.color.value];
213 this.colorSizes = colorSizes; 224 this.colorSizes = colorSizes;
214 this.thumbnails = thumbnails; 225 this.thumbnails = thumbnails;
215 226
@@ -258,24 +269,24 @@ @@ -258,24 +269,24 @@
258 }); 269 });
259 270
260 if (oldSizes && oldSizes.length > 0) { 271 if (oldSizes && oldSizes.length > 0) {
261 - const newSizes = this.colorSizes[opt]; 272 + const newSizes = this.colorSizes[opt.value];
262 273
263 const matchedSize = newSizes.filter((item)=> { 274 const matchedSize = newSizes.filter((item)=> {
264 return !item.disabled && item.text === oldSizes[0].text; 275 return !item.disabled && item.text === oldSizes[0].text;
265 }); 276 });
266 277
267 if (matchedSize && matchedSize.length > 0) { 278 if (matchedSize && matchedSize.length > 0) {
268 - return matchedSize[0].value; 279 + return matchedSize[0];
269 } 280 }
270 } 281 }
271 } 282 }
272 283
273 return null; 284 return null;
274 - })(this.selection.color, this.selection.size), 285 + })(self.selection.color.value, self.selection.size.value),
275 thumbnail: this.thumbnails[opt] 286 thumbnail: this.thumbnails[opt]
276 }; 287 };
277 288
278 - this.sizes = this.colorSizes[opt]; 289 + this.sizes = this.colorSizes[opt.value];
279 Object.assign(this.selection, selection); 290 Object.assign(this.selection, selection);
280 }); 291 });
281 292
@@ -305,32 +316,9 @@ @@ -305,32 +316,9 @@
305 return; 316 return;
306 } 317 }
307 318
308 - this.onAddToCart(this.selection, this.entity.pid);  
309 - },  
310 -  
311 -  
312 - getFullSelection() {  
313 - let size;  
314 -  
315 - this.sizes.forEach((item)=> {  
316 - if (item.value === this.selection.size) {  
317 - size = item;  
318 - }  
319 - }); 319 + const param = Object.assign({goodsId: this.entity.id}, this.selection);
320 320
321 - let color;  
322 -  
323 - this.colors.indexOf((item)=> {  
324 - if (item.value === this.selection.color) {  
325 - color = item;  
326 - }  
327 - });  
328 -  
329 - return {  
330 - size: size,  
331 - color: color,  
332 - productId: this.entity.id  
333 - }; 321 + this.onAddToCart(param);
334 } 322 }
335 } 323 }
336 }; 324 };
@@ -139,7 +139,7 @@ @@ -139,7 +139,7 @@
139 }, 139 },
140 140
141 // 商品 feature改变 141 // 商品 feature改变
142 - whenFeatureChange(selection, pid) { 142 + whenFeatureChange(selection) {
143 const index = this.indexMap[pid]; 143 const index = this.indexMap[pid];
144 144
145 this.showFeatureSelector = false; 145 this.showFeatureSelector = false;
@@ -168,7 +168,7 @@ @@ -168,7 +168,7 @@
168 168
169 <div class="control-box"> 169 <div class="control-box">
170 <button class="button control-button" style="flex: 1"> 170 <button class="button control-button" style="flex: 1">
171 - <a style="position:relative"> 171 + <a href="javascript:void(0);" @click="yoho.goShopingCart()">
172 <i class="icon icon-bag"></i> 172 <i class="icon icon-bag"></i>
173 <span v-if="cartCount > 0" class="badge badge-tr">{{cartCount}}</span> 173 <span v-if="cartCount > 0" class="badge badge-tr">{{cartCount}}</span>
174 </a> 174 </a>
@@ -395,6 +395,7 @@ @@ -395,6 +395,7 @@
395 module.exports = { 395 module.exports = {
396 data() { 396 data() {
397 return { 397 return {
  398 + yoho: yoho,
398 intro: {}, 399 intro: {},
399 entity: { 400 entity: {
400 brand: { 401 brand: {
@@ -407,7 +408,6 @@ @@ -407,7 +408,6 @@
407 }, 408 },
408 showFeatureSelector: false, 409 showFeatureSelector: false,
409 cartCount: 0, 410 cartCount: 0,
410 - yoho: yoho,  
411 411
412 /** 412 /**
413 * 加入购物车回调 413 * 加入购物车回调
@@ -416,7 +416,7 @@ @@ -416,7 +416,7 @@
416 */ 416 */
417 onAddToCart: (selection)=> { 417 onAddToCart: (selection)=> {
418 $.post('/product/cart.json', { 418 $.post('/product/cart.json', {
419 - productSku: selection.size, 419 + productSku: selection.size.value,
420 buyNumber: 1 420 buyNumber: 1
421 }).then((result)=> { 421 }).then((result)=> {
422 if (yoho.goShopingKey && result.data.shopping_key) { 422 if (yoho.goShopingKey && result.data.shopping_key) {
@@ -467,6 +467,9 @@ @@ -467,6 +467,9 @@
467 if (result.code === 200) { 467 if (result.code === 200) {
468 tip('取消收藏成功'); 468 tip('取消收藏成功');
469 this.entity.isCollect = 'N'; 469 this.entity.isCollect = 'N';
  470 + } else if (result.code === 403) {
  471 + // 未登陆
  472 + yoho.goLogin();
470 } 473 }
471 }); 474 });
472 } else { 475 } else {