Authored by 毕凯

加价购 加入购物车直接插入 html

... ... @@ -10,39 +10,45 @@
// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
var $ = require('jquery'),
Handlebars = require('yoho.handlebars'),
tip = require('../plugin/tip'),
loading = require('../plugin/loading');
var panelTmpl,
$chosePanel = $('#chose-panel'),
var $chosePanel = $('#chose-panel'),
$num,
$chosed,
// panelTmpl,
// re = /\d+/,
leftNum,
confirming,
hasChooseColor = false,
hasChooseSize = false,
curColorIndex,
curSizeIndex,
$curSizeRow,
$curSizeBlock = null,
$sizeRowList = $('.size-list ul');
hasChooseColor,
hasChooseSize,
$curSizeBlock,
$sizeRowList;
// 读取模板
$.get('/cart/index/giftinfoTpl', function(html) {
if (!html) {
tip.show('网络错误');
return;
}
panelTmpl = Handlebars.compile(html);
}).fail(function() {
tip.show('网络错误');
});
// $.get('/cart/index/giftinfoTpl', function(html) {
// if (!html) {
// tip.show('网络错误');
// return;
// }
// panelTmpl = Handlebars.compile(html);
// }).fail(function() {
// tip.show('网络错误');
// });
//初始化购物车面板显示
function init() {
var $firstRow;
hasChooseColor = false;
hasChooseSize = false;
$curSizeBlock = null;
$sizeRowList = $('.size-list ul');
$firstRow = $sizeRowList.eq(0);
//$colorList = $('.chose-panel .color-list ul>li');
//$sizeList = $('.chose-panel .size-list ul>li');
... ... @@ -55,11 +61,10 @@ function init() {
// }
//});
var $firstRow = $sizeRowList.eq(0);
$firstRow.toggleClass('hide');
$curSizeRow = $firstRow;
}
init();
function checkColorSizeNum() {
if (!hasChooseColor && !hasChooseSize) {
... ... @@ -75,11 +80,9 @@ function checkColorSizeNum() {
return true;
}
init();
function show(data) {
if (data) {
$chosePanel.html(panelTmpl(data));
function show(html) {
if (html) {
$chosePanel.html(html);
init();
}
$('.chose-panel').show();
... ...
... ... @@ -19,18 +19,12 @@ function getProductInfo(skn, promotionId) {
$.get('/cart/index/giftinfo', {
skn: skn,
promotionId: promotionId
}).then(function(res) {
if (!res) {
}).then(function(html) {
if (!html) {
tip.show('网络错误');
return;
}
if (res.code === 200) {
chosePanel.show({
cartInfo: res.data
});
} else {
tip.show(res.message || '网络错误');
}
chosePanel.show(html);
}).fail(function() {
tip.show('网络错误');
}).always(function() {
... ...
... ... @@ -215,7 +215,9 @@ class IndexController extends AbstractAction
$result = CartModel::giftProductData($skn, $promotionId);
}
$this->_view->display('gift-info', $result);
$this->_view->display('gift-info', array(
'cartInfo' => $result['data']
));
}
/**
... ...