Authored by 梁志锋

购物车逻辑修改

@@ -10,50 +10,37 @@ @@ -10,50 +10,37 @@
10 // 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框 10 // 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
11 11
12 var $ = require('jquery'), 12 var $ = require('jquery'),
13 - Handlebars = require('yoho.handlebars'),  
14 tip = require('../plugin/tip'), 13 tip = require('../plugin/tip'),
15 loading = require('../plugin/loading'); 14 loading = require('../plugin/loading');
16 15
17 -var panelTmpl,  
18 - $chosePanel = $('#chose-panel'), 16 +var $chosePanel = $('#chose-panel'),
19 $num, 17 $num,
20 $chosed, 18 $chosed,
21 19
22 // re = /\d+/, 20 // re = /\d+/,
23 leftNum, 21 leftNum,
24 confirming, 22 confirming,
25 - hasChooseColor,  
26 - hasChooseSize,  
27 curColorIndex, 23 curColorIndex,
28 curSizeIndex, 24 curSizeIndex,
29 $curSizeRow, 25 $curSizeRow,
  26 + hasChooseColor,
  27 + hasChooseSize,
30 $curSizeBlock, 28 $curSizeBlock,
31 $sizeRowList; 29 $sizeRowList;
32 30
33 -// 读取模板  
34 -$.get('/cart/index/giftinfoTpl', function(html) {  
35 - if (!html) {  
36 - tip.show('网络错误');  
37 - return;  
38 - }  
39 - panelTmpl = Handlebars.compile(html);  
40 -}).fail(function() {  
41 - tip.show('网络错误');  
42 -});  
43 -  
44 //初始化购物车面板显示 31 //初始化购物车面板显示
45 function init() { 32 function init() {
46 var $firstRow; 33 var $firstRow;
47 34
  35 + hasChooseColor = false;
  36 + hasChooseSize = false;
  37 + $curSizeBlock = null;
48 $sizeRowList = $('.size-list ul'); 38 $sizeRowList = $('.size-list ul');
49 $firstRow = $sizeRowList.eq(0); 39 $firstRow = $sizeRowList.eq(0);
50 - $curSizeBlock = null,  
51 -  
52 - hasChooseSize = false,  
53 - hasChooseColor = false,  
54 $firstRow.toggleClass('hide'); 40 $firstRow.toggleClass('hide');
55 $curSizeRow = $firstRow; 41 $curSizeRow = $firstRow;
56 } 42 }
  43 +init();
57 44
58 function checkColorSizeNum() { 45 function checkColorSizeNum() {
59 if (!hasChooseColor && !hasChooseSize) { 46 if (!hasChooseColor && !hasChooseSize) {
@@ -69,9 +56,9 @@ function checkColorSizeNum() { @@ -69,9 +56,9 @@ function checkColorSizeNum() {
69 return true; 56 return true;
70 } 57 }
71 58
72 -function show(data) {  
73 - if (data) {  
74 - $chosePanel.html(panelTmpl(data)); 59 +function show(html) {
  60 + if (html) {
  61 + $chosePanel.html(html);
75 init(); 62 init();
76 } 63 }
77 $('.chose-panel').show(); 64 $('.chose-panel').show();
@@ -19,18 +19,12 @@ function getProductInfo(skn, promotionId) { @@ -19,18 +19,12 @@ function getProductInfo(skn, promotionId) {
19 $.get('/cart/index/giftinfo', { 19 $.get('/cart/index/giftinfo', {
20 skn: skn, 20 skn: skn,
21 promotionId: promotionId 21 promotionId: promotionId
22 - }).then(function(res) {  
23 - if (!res) { 22 + }).then(function(html) {
  23 + if (!html) {
24 tip.show('网络错误'); 24 tip.show('网络错误');
25 return; 25 return;
26 } 26 }
27 - if (res.code === 200) {  
28 - chosePanel.show({  
29 - cartInfo: res.data  
30 - });  
31 - } else {  
32 - tip.show(res.message || '网络错误');  
33 - } 27 + chosePanel.show(html);
34 }).fail(function() { 28 }).fail(function() {
35 tip.show('网络错误'); 29 tip.show('网络错误');
36 }).always(function() { 30 }).always(function() {
@@ -215,7 +215,9 @@ class IndexController extends AbstractAction @@ -215,7 +215,9 @@ class IndexController extends AbstractAction
215 $result = CartModel::giftProductData($skn, $promotionId); 215 $result = CartModel::giftProductData($skn, $promotionId);
216 } 216 }
217 217
218 - $this->_view->display('gift-info', $result); 218 + $this->_view->display('gift-info', array(
  219 + 'cartInfo' => $result['data']
  220 + ));
219 } 221 }
220 222
221 /** 223 /**