...
|
...
|
@@ -8,78 +8,151 @@ var $ = require('jquery'), |
|
|
ellipsis = require('mlellipsis'),
|
|
|
lazyLoad = require('yoho.lazyload');
|
|
|
|
|
|
var chosePanel = require('./chose-panel');
|
|
|
var dialog = require('../me/dialog'),
|
|
|
tip = require('../plugin/tip');
|
|
|
|
|
|
var $curDelPanel;
|
|
|
var $names;
|
|
|
|
|
|
//删除面板显示后任何点击行为都将触发隐藏面板
|
|
|
function docTouchEvt() {
|
|
|
$curDelPanel && $curDelPanel.addClass('hide');
|
|
|
//chosePanel = require('./chose-panel');
|
|
|
|
|
|
//
|
|
|
$(document).off('touchstart', docTouchEvt);
|
|
|
}
|
|
|
var cartType = 'ordinary';
|
|
|
|
|
|
//var $curDelPanel;
|
|
|
|
|
|
////删除面板显示后任何点击行为都将触发隐藏面板
|
|
|
//function docTouchEvt() {
|
|
|
// $curDelPanel && $curDelPanel.addClass('hide');
|
|
|
//
|
|
|
// //
|
|
|
// $(document).off('touchstart', docTouchEvt);
|
|
|
//}
|
|
|
|
|
|
ellipsis.init();
|
|
|
|
|
|
lazyLoad($('.lazy'));
|
|
|
lazyLoad({
|
|
|
try_again_css: 'order-failure'
|
|
|
});
|
|
|
|
|
|
$('.name')[0].mlellipsis(2);
|
|
|
$names = $('.name');
|
|
|
if ($names.length > 0) {
|
|
|
$names[0].mlellipsis(2);
|
|
|
}
|
|
|
|
|
|
//TIP:事件委托在.cart-goods,商品列表的容器统一需要有.cart-goods
|
|
|
$('.cart-goods').on('touchstart', '.checkbox', function() {
|
|
|
var $this = $(this);
|
|
|
var $this = $(this),
|
|
|
id = $(this).closest('.shopping-cart-good').data('id');
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/shoppingCart/select',
|
|
|
data: {
|
|
|
id: id
|
|
|
}
|
|
|
}).then(function(data) {
|
|
|
if (data.code === 200) {
|
|
|
if ($this.hasClass('icon-cb-checked')) {
|
|
|
$this.removeClass('icon-cb-checked').addClass('icon-checkbox');
|
|
|
} else {
|
|
|
$this.removeClass('icon-checkbox').addClass('icon-cb-checked');
|
|
|
}
|
|
|
}).on('touchstart', '.icon-edit', function() {
|
|
|
var id = $(this).closest('.shopping-cart-good').data('id');
|
|
|
|
|
|
}
|
|
|
$.ajax({
|
|
|
type: 'GET',
|
|
|
url: '/shoppingCart/goodinfo',
|
|
|
url: '/shoppingCart/getCartData',
|
|
|
data: {
|
|
|
id: id
|
|
|
},
|
|
|
success: function(data) {
|
|
|
if (data.code === 200) {
|
|
|
chosePanel.show(data.data);
|
|
|
if (data) {
|
|
|
$('#good-totalprice').html('¥' + data.commonCart.price);
|
|
|
$('#good-activityPrice').html('¥' + data.commonCart.activityPrice);
|
|
|
$('#good-total').html(data.commonCart.count + '件总计:¥' + data.commonCart.sumPrice);
|
|
|
}
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络错误');
|
|
|
}
|
|
|
});
|
|
|
}).on('touchstart', '.icon-del', function(e) {
|
|
|
e.stopPropagation();
|
|
|
|
|
|
//手动触发docTouchEvt清除因点击到del按钮上而被阻止冒泡到doc上的事件从而清除已打开的删除面板
|
|
|
docTouchEvt();
|
|
|
|
|
|
$curDelPanel = $(this).closest('.shopping-cart-good').children('.opt-panel').removeClass('hide');
|
|
|
}).fail(function() {
|
|
|
tip.show('网络错误');
|
|
|
});
|
|
|
}).on('touchstart', '.icon-edit', function() {
|
|
|
|
|
|
$(document).on('touchstart', docTouchEvt);
|
|
|
}).on('touchstart', '.opt-panel', function() {
|
|
|
var $this = $(this),
|
|
|
id = $this.closest('.shopping-cart-good').data('id'),
|
|
|
url;
|
|
|
}).on('touchstart', '.icon-del', function(e) {
|
|
|
var $this = $(this);
|
|
|
|
|
|
if ($this.closest('.put-in-favorite').length > 0) {
|
|
|
e.stopPropagation();
|
|
|
|
|
|
//移入收藏夹
|
|
|
url = '/shoppingCart/col';
|
|
|
} else {
|
|
|
//手动触发docTouchEvt清除因点击到del按钮上而被阻止冒泡到doc上的事件从而清除已打开的删除面板
|
|
|
//docTouchEvt();
|
|
|
//
|
|
|
//$curDelPanel = $(this).closest('.shopping-cart-good').children('.opt-panel').removeClass('hide');
|
|
|
//
|
|
|
//$(document).on('touchstart', docTouchEvt);
|
|
|
|
|
|
//删除
|
|
|
url = '/shoppingCart/del';
|
|
|
dialog.showDialog({
|
|
|
dialogText: '您确定要从购物车中删除吗?',
|
|
|
hasFooter: {
|
|
|
leftBtnText: '取消',
|
|
|
rightBtnText: '确定'
|
|
|
}
|
|
|
}, function() {
|
|
|
var id = $this.closest('.shopping-cart-good').data('id');
|
|
|
|
|
|
$.ajax({
|
|
|
type: 'POST',
|
|
|
url: url,
|
|
|
method: 'post',
|
|
|
url: '/shoppingCart/del',
|
|
|
data: {
|
|
|
id: id
|
|
|
}
|
|
|
}).then(function(data) {
|
|
|
if (data.code === 200) {
|
|
|
dialog.showDialog({
|
|
|
dialogText: '删除成功',
|
|
|
autoHide: true,
|
|
|
fast: true
|
|
|
});
|
|
|
history.go(0);
|
|
|
}
|
|
|
}).fail(function() {
|
|
|
dialog.showDialog({
|
|
|
autoHide: true,
|
|
|
dialogText: '网络错误~'
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
// .on('touchstart', '.opt-panel', function() {
|
|
|
// var $this = $(this),
|
|
|
// id = $this.closest('.shopping-cart-good').data('id'),
|
|
|
// url;
|
|
|
//
|
|
|
// if ($this.closest('.put-in-favorite').length > 0) {
|
|
|
//
|
|
|
// //移入收藏夹
|
|
|
// url = '/shoppingCart/col';
|
|
|
// } else {
|
|
|
//
|
|
|
// //删除
|
|
|
// url = '/shoppingCart/del';
|
|
|
// }
|
|
|
//
|
|
|
// $.ajax({
|
|
|
// type: 'POST',
|
|
|
// url: url,
|
|
|
// data: {
|
|
|
// id: id
|
|
|
// }
|
|
|
// });
|
|
|
//})
|
|
|
|
|
|
|
|
|
$('.btn-balance').on('touchend', function() {
|
|
|
window.location.href = '/shoppingCart/orderEnsure?cartType=' + cartType;
|
|
|
});
|
|
|
|
|
|
|
...
|
...
|
|