$.ajax({
type: "GET",
url: getCar,
data: {
userID: userID1,
},
dataType: "JSONP",
success: function(data) {
if(data == 0) {
console.log("没有搜索结果");
} else {
console.log(data);
for(var i = 0; i < data; i++);
var getCarHtml = '';
var length = data.length;
for(var i = 0; i < data.length; i++) {
var goodsListImg = data.goodsListImg;
var goodsName = data.goodsName;
var className = data.className;
var goodsIDa = data.goodsID;
var price = data.price;
// var numbers = data.number;
// console.log(numbers+"00000000");
getCarHtml += "<li a='" + goodsIDa + "' class='prdListCon-fir'>
" + goodsName + "
" + className + "
单价 ¥" + price + "
数量:
-
1
+
"
}
$('#prdListCon').append(getCarHtml);
myScroll = new IScroll('#wrapper', {});
//加的效果
$(".add").on("touchend", function() {
var bs = $(this).parent().parent().attr('a');
//console.log(bs);
var n = $(this).prev().text();
console.log(n+"nnnnn")
var num = parseInt(n) + 1;
if(num == 0) {
return;
}
$(this).prev().text(num);
add_Or_del(updatecars,userID1,bs,num);
totalNum_Mon();
});
//减的效果
$(".jian").on("touchend", function() {
var bs = $(this).parent().parent().attr('a');
var n = $(this).next().text();
var num = parseInt(n) - 1;
if(num == 0) {
return;
}
$(this).next().text(num);
//购物车添加更新函数
add_Or_del(updatecars,userID1,bs,num);
totalNum_Mon();
});
$('.delete').on("touchend", function() {
var bs = $(this).parent().parent().attr('a');
//console.log(bs);
//购物车删除
add_Or_del(updatecars,userID1,bs,0);
//删除节点
$(this).parent().parent().remove();
totalNum_Mon();
});
//时时更新商品总数和总价
totalNum_Mon();
function totalNum_Mon(){
var numTop=0,MonTop=0;
//取出每类商品的数量
$('.tit7').each(function(){
numTop+=parseInt(this.innerHTML);
//console.log(numTop);
//取出每类商品数量的单价
var singlePrice=parseInt($('.tit4 b').eq($('.tit7').index($(this))).text());
/*console.log(numTop)
console.log(singlePrice)*/
//每类商品的数量乘上单价,让和相加
MonTop+=parseInt(this.innerHTML)*singlePrice;
// console.log(MonTop);
});
// console.log(numTop);
$('.shopMes span').html(numTop);
$('.shopMes i').html(MonTop);
}
}
}
})
}
//购物车增加、删减更新函数
function add_Or_del(updatecarUrl,userID,goodsID,nums) {
$.ajax({
type: "GET",
url: updatecarUrl,
data: {
userID: userID,
goodsID: goodsID,
number: nums
},
success: function(data) {
console.log(data)
if(data == 1) {
console.log("更新成功");
} else {
console.log('更新不成功')
}
}
})
} |