Authored by weiguang.xie

Merge branch 'fix/issue' into 'develop'

修复问题

1. 修复购物车页面为你优选不显示问题
2. 增加未选择赠品时去结算前的提醒

See merge request !62
@@ -9,6 +9,7 @@ var $ = require('jquery'), @@ -9,6 +9,7 @@ var $ = require('jquery'),
9 Hammer = require('yoho.hammer'); 9 Hammer = require('yoho.hammer');
10 10
11 var chosePanel = require('./chose-panel'), 11 var chosePanel = require('./chose-panel'),
  12 + dialog = require('../me/dialog'),
12 tip = require('../plugin/tip'); 13 tip = require('../plugin/tip');
13 14
14 var $cartContent = $('.cart-content'); 15 var $cartContent = $('.cart-content');
@@ -20,6 +21,48 @@ var navHammer, @@ -20,6 +21,48 @@ var navHammer,
20 21
21 var hasChecked = $('.cart-content:not(.hide) .icon-cb-checked').length > 0 ? true : false; //是否有选中商品 22 var hasChecked = $('.cart-content:not(.hide) .icon-cb-checked').length > 0 ? true : false; //是否有选中商品
22 23
  24 +function shouldSelectGift() {
  25 + var $freebie = $('.freebie');
  26 +
  27 + if ($freebie.length <= 0) {
  28 + return false;
  29 + }
  30 +
  31 + return true;
  32 +}
  33 +
  34 +function shouldLowStocks() {
  35 + var $lowStocks = $('.low-stocks'),
  36 + result = false;
  37 +
  38 + if ($lowStocks.length <= 0) {
  39 + return result;
  40 + }
  41 +
  42 + $lowStocks.each(function(idx, item) {
  43 + if ($(item).parent().parent().parent().siblings('.checkbox').hasClass('icon-cb-checked')) {
  44 + result = true;
  45 + return false;
  46 + }
  47 + });
  48 +
  49 + return result;
  50 +}
  51 +
  52 +function showChooseGifDialog() {
  53 + dialog.showDialog({
  54 + dialogText: '您还未选择赠品,是否去选择赠品',
  55 + hasFooter: {
  56 + leftBtnText: '我不要赠品',
  57 + rightBtnText: '去选择'
  58 + }
  59 + }, function() {
  60 + window.location.href = $('.freebie').find('a').attr('href');
  61 + }, function() {
  62 + window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
  63 + });
  64 +}
  65 +
23 require('./good'); 66 require('./good');
24 67
25 lazyLoad($('img.lazy')); 68 lazyLoad($('img.lazy'));
@@ -83,7 +126,11 @@ if ($('.freebie').length > 0) { @@ -83,7 +126,11 @@ if ($('.freebie').length > 0) {
83 //}); 126 //});
84 127
85 $('.btn-balance').on('touchend', function() { 128 $('.btn-balance').on('touchend', function() {
86 - if ($('.low-stocks').length > 0) { 129 + if (shouldSelectGift()) {
  130 + showChooseGifDialog();
  131 + return false;
  132 + }
  133 + if (shouldLowStocks()) {
87 tip.show('库存不足无法结算'); 134 tip.show('库存不足无法结算');
88 return false; 135 return false;
89 } 136 }
@@ -99,7 +146,7 @@ $('.chose').on('touchend', function() { @@ -99,7 +146,7 @@ $('.chose').on('touchend', function() {
99 chosePanel.show(); 146 chosePanel.show();
100 }); 147 });
101 148
102 -if ($('.cart-zero').length > 0) { 149 +if ($('.shopping-cart-good').length <= 0) {
103 require('../product/recommend-for-you'); 150 require('../product/recommend-for-you');
104 } 151 }
105 152
@@ -33,7 +33,7 @@ dialogTpl = '<div id="dialog-wrapper" class="dialog-wrapper">' + @@ -33,7 +33,7 @@ dialogTpl = '<div id="dialog-wrapper" class="dialog-wrapper">' +
33 33
34 dialogTemplate = Handlebars.compile(dialogTpl); 34 dialogTemplate = Handlebars.compile(dialogTpl);
35 35
36 -exports.showDialog = function(data, callback) { 36 +exports.showDialog = function(data, callback, callbackForLeft) {
37 37
38 var dialogStr = dialogTemplate(data), 38 var dialogStr = dialogTemplate(data),
39 $dialogBox, 39 $dialogBox,
@@ -76,6 +76,9 @@ exports.showDialog = function(data, callback) { @@ -76,6 +76,9 @@ exports.showDialog = function(data, callback) {
76 dialogWrapperHammer.on('tap', function(event) { 76 dialogWrapperHammer.on('tap', function(event) {
77 77
78 if ($(event.target).hasClass('dialog-left-btn')) { 78 if ($(event.target).hasClass('dialog-left-btn')) {
  79 + if (typeof callbackForLeft === 'function') {
  80 + callbackForLeft();
  81 + }
79 $dialogWrapper.fadeOut(); 82 $dialogWrapper.fadeOut();
80 } else if ($(event.target).hasClass('dialog-right-btn')) { 83 } else if ($(event.target).hasClass('dialog-right-btn')) {
81 callback(); 84 callback();