|
|
$(function(){
|
|
|
//支付
|
|
|
$('.pay-box').click(function(){
|
|
|
var type = $(this).data('id');
|
|
|
var id = $(this).parent().data('id');
|
|
|
$(this).addClass('active').siblings('.pay-box').removeClass('active');
|
|
|
//支付
|
|
|
$('.pay-box').click(function(){
|
|
|
var type = $(this).data('id');
|
|
|
var id = $(this).parent().data('id');
|
|
|
$(this).addClass('active').siblings('.pay-box').removeClass('active');
|
|
|
$.ajax({
|
|
|
url:param.changePay,
|
|
|
type:"POST",
|
...
|
...
|
@@ -23,111 +23,152 @@ $(function(){ |
|
|
alert(e);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
$('.wechat-radio').change(function(){
|
|
|
if($(this).is(":checked")){
|
|
|
$('.pay-in-weixin').show();
|
|
|
}
|
|
|
});
|
|
|
$('.alipay-radio').change(function(){
|
|
|
if($(this).is(":checked")){
|
|
|
$('.pay-in-weixin').hide();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//地址
|
|
|
$('.ads-box').click(function(){
|
|
|
$('.ads-box').removeClass('active')
|
|
|
$(this).addClass('active')
|
|
|
});
|
|
|
|
|
|
//全选
|
|
|
$('#checkAll').click(function(event) {
|
|
|
if($(this).hasClass('active')){
|
|
|
$('.cart-list .cart-check').prop('checked',false);
|
|
|
$(this).removeClass('active')
|
|
|
}else{
|
|
|
$('.cart-list .cart-check').prop('checked',true);
|
|
|
$(this).addClass('active')
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
$('.wechat-radio').change(function(){
|
|
|
if($(this).is(":checked")){
|
|
|
$('.pay-in-weixin').show();
|
|
|
}
|
|
|
});
|
|
|
$('.alipay-radio').change(function(){
|
|
|
if($(this).is(":checked")){
|
|
|
$('.pay-in-weixin').hide();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//单选
|
|
|
//地址
|
|
|
$('.ads-box').click(function(){
|
|
|
$('.ads-box').removeClass('active')
|
|
|
$(this).addClass('active')
|
|
|
});
|
|
|
|
|
|
//全选
|
|
|
$('#checkAll').click(function(event) {
|
|
|
if($(this).hasClass('active')){
|
|
|
$('.cart-list .cart-check').prop('checked',false);
|
|
|
$(this).removeClass('active')
|
|
|
}else{
|
|
|
$('.cart-list .cart-check').prop('checked',true);
|
|
|
$(this).addClass('active')
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//单选
|
|
|
var length = $('.cart-check').length-1;
|
|
|
$('.cart-check').click(function() {
|
|
|
$(this).toggleClass('chrenActive');
|
|
|
$('.cart-check').click(function() {
|
|
|
$(this).toggleClass('chrenActive');
|
|
|
var chrenLength = $('.chrenActive').length;
|
|
|
if(length==chrenLength){
|
|
|
$('#checkAll').prop('checked',true);
|
|
|
$('#checkAll').addClass('active');
|
|
|
}else{
|
|
|
}else{
|
|
|
$('#checkAll').prop('checked',false);
|
|
|
$('#checkAll').removeClass('active');
|
|
|
}
|
|
|
coin();
|
|
|
});
|
|
|
|
|
|
//数字
|
|
|
$('.total-number').each(function(){
|
|
|
var sort = '';
|
|
|
var t = $(this).find(".numberbox");
|
|
|
}
|
|
|
coin();
|
|
|
});
|
|
|
|
|
|
//数字
|
|
|
$('.total-number').each(function(){
|
|
|
var sort = '';
|
|
|
var t = $(this).find(".numberbox");
|
|
|
var id = $(this).parents('.cart-cell').data('id');
|
|
|
$(this).find(".btn-plus").click(function(){
|
|
|
sort = 'plus';
|
|
|
if (parseInt(t.val())!=1){
|
|
|
$('.btn-less').attr('disabled',false);
|
|
|
}
|
|
|
change(id, sort, 1, $(this));
|
|
|
});
|
|
|
$(this).find(".btn-less").click(function(){
|
|
|
if (parseInt(t.val())<=1){
|
|
|
$(this).siblings(".numberbox").val(1);
|
|
|
} else {
|
|
|
sort = 'reduce';
|
|
|
change(id, sort, 1, $(this));
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
if(!id) {
|
|
|
id = $(this).data('id');
|
|
|
$(this).find(".btn-plus").click(function(){
|
|
|
var num = parseInt($(this).parent().find(".numberbox").val());
|
|
|
sort = 'plus';
|
|
|
if (parseInt(t.val())!=1){
|
|
|
$('.btn-less').attr('disabled',false);
|
|
|
}
|
|
|
change(id, sort, num+1, $(this));
|
|
|
});
|
|
|
$(this).find(".btn-less").click(function(){
|
|
|
var num = parseInt($(this).parent().find(".numberbox").val());
|
|
|
if (parseInt(t.val())<=1){
|
|
|
$(this).siblings(".numberbox").val(1);
|
|
|
} else {
|
|
|
sort = 'reduce';
|
|
|
change(id, sort, num-1, $(this));
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
$(this).find(".btn-plus").click(function(){
|
|
|
sort = 'plus';
|
|
|
if (parseInt(t.val())!=1){
|
|
|
$('.btn-less').attr('disabled',false);
|
|
|
}
|
|
|
change(id, sort, 1, $(this));
|
|
|
});
|
|
|
$(this).find(".btn-less").click(function(){
|
|
|
if (parseInt(t.val())<=1){
|
|
|
$(this).siblings(".numberbox").val(1);
|
|
|
} else {
|
|
|
sort = 'reduce';
|
|
|
change(id, sort, 1, $(this));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 数量输入框
|
|
|
// 数量输入框(购物车)
|
|
|
$('.p-table-border').on('focus','.numberbox',function(){
|
|
|
var id = $(this).parents('.cart-cell').data('id');
|
|
|
var num = $(this).val();
|
|
|
$(this).data('old',num);
|
|
|
});
|
|
|
|
|
|
// 数量输入框
|
|
|
$('.p-table-border').on('blur','.numberbox',function(){
|
|
|
var id = $(this).parents('.cart-cell').data('id');
|
|
|
// 数量输入框(购物车)
|
|
|
$('.p-table-border').on('blur','.numberbox',function(){
|
|
|
var id = $(this).parents('.cart-cell').data('id');
|
|
|
var num = $(this).val();
|
|
|
if(typeof num == 'undefined' || num<1) {
|
|
|
$(this).val($(this).data('old'));
|
|
|
} else {
|
|
|
change(id, 'change', num, $(this));
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 数量输入框(商品详情)
|
|
|
$('.itemInfo-wrap').on('focus','.numberbox',function(){
|
|
|
var id = $(this).parent().data('id');
|
|
|
var num = $(this).val();
|
|
|
$(this).data('old',num);
|
|
|
});
|
|
|
|
|
|
// 数量输入框(商品详情)
|
|
|
$('.itemInfo-wrap').on('blur','.numberbox',function(){
|
|
|
var id = $(this).parent().data('id');
|
|
|
var num = $(this).val();
|
|
|
if(typeof num == 'undefined' || num<1) {
|
|
|
if(typeof num == 'undefined' || num<1) {
|
|
|
$(this).val($(this).data('old'));
|
|
|
} else {
|
|
|
change(id, 'change', num, $(this));
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
change(id, 'change', num, $(this));
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 执行修改数量ajax
|
|
|
function change(id, sort, num, obj) {
|
|
|
// 执行修改数量ajax
|
|
|
function change(id, sort, num, obj) {
|
|
|
var data = {
|
|
|
id:id,
|
|
|
sort:sort,
|
|
|
num:num
|
|
|
};
|
|
|
console.log(data);
|
|
|
$.ajax({
|
|
|
url:param.changeNum,
|
|
|
type:"POST",
|
|
|
data:{
|
|
|
id:id,
|
|
|
sort:sort,
|
|
|
num:num
|
|
|
},
|
|
|
data:data,
|
|
|
dateType:"json",
|
|
|
success:function (data) {
|
|
|
if(data.status) {
|
|
|
if(data.data.sort == 'reduce') {
|
|
|
if(data.data.sort == 'reduce') {
|
|
|
obj.parent().find(".numberbox").val(parseInt(obj.parent().find(".numberbox").val())-1);
|
|
|
}
|
|
|
}
|
|
|
if(data.data.sort == 'plus') {
|
|
|
obj.parent().find(".numberbox").val(parseInt(obj.parent().find(".numberbox").val())+1);
|
|
|
}
|
|
|
obj.parents('.cart-cell').find('.amount').text(data.data.amount);
|
|
|
coin();
|
|
|
obj.parents('.cart-cell').find('.amount').text(data.data.amount);
|
|
|
coin();
|
|
|
} else {
|
|
|
alert(data.msg);
|
|
|
}
|
...
|
...
|
@@ -139,11 +180,11 @@ $(function(){ |
|
|
}
|
|
|
|
|
|
// 删除购物车商品
|
|
|
$('#delete').click(function(){
|
|
|
$('#delete').click(function(){
|
|
|
var chrenLength = $('.chrenActive').length;
|
|
|
if(chrenLength == 0) {
|
|
|
if(chrenLength == 0) {
|
|
|
alert('请选择要删除的商品');
|
|
|
} else {
|
|
|
} else {
|
|
|
if(confirm('确认删除所选商品?')) {
|
|
|
var ids = [];
|
|
|
$('.chrenActive').each(function() {
|
...
|
...
|
@@ -151,10 +192,10 @@ $(function(){ |
|
|
});
|
|
|
delCartGoods(ids,'delele');
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 去付款
|
|
|
// 去付款
|
|
|
$('#topay').click(function(){
|
|
|
var btn = $(this);
|
|
|
var chrenLength = $('.chrenActive').length;
|
...
|
...
|
@@ -169,14 +210,14 @@ $(function(){ |
|
|
}
|
|
|
});
|
|
|
|
|
|
// 删除购物车商品
|
|
|
function delCartGoods(ids,sort) {
|
|
|
// 删除购物车商品
|
|
|
function delCartGoods(ids,sort) {
|
|
|
$.ajax({
|
|
|
url:param.del,
|
|
|
type:"POST",
|
|
|
data:{
|
|
|
ids:ids,
|
|
|
sort:sort
|
|
|
sort:sort
|
|
|
},
|
|
|
dateType:"json",
|
|
|
success:function (data) {
|
...
|
...
|
@@ -194,7 +235,7 @@ $(function(){ |
|
|
alert(e);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 去付款
|
|
|
function handleCart(ids,sort,obj) {
|
...
|
...
|
@@ -233,7 +274,7 @@ $(function(){ |
|
|
Coin = 0;
|
|
|
Num = 0;
|
|
|
$(".chrenActive").each(function() {
|
|
|
Num = parseFloat(Num)+parseFloat($(this).parent().find("input[name=num]").val());
|
|
|
Num = parseFloat(Num)+parseFloat($(this).parent().find("input[name=num]").val());
|
|
|
Coin = parseFloat(Coin)+parseFloat($(this).parent().find(".amount").text());
|
|
|
})
|
|
|
$("#choose").html(Num);
|
...
|
...
|
@@ -247,14 +288,20 @@ $(function(){ |
|
|
var address_id = $('input[name=address_id]').val();
|
|
|
var ids = [];
|
|
|
$('input[name="ids[]"]').each(function(){
|
|
|
ids.push($(this).val());
|
|
|
ids.push($(this).val());
|
|
|
});
|
|
|
if(!address_id) {
|
|
|
alert('请选择收货地址');
|
|
|
return false;
|
|
|
}
|
|
|
$.ajax({
|
|
|
url:param.createOrder,
|
|
|
type:"POST",
|
|
|
data:{
|
|
|
ids:ids,
|
|
|
address_id:address_id
|
|
|
address_id:address_id,
|
|
|
sort:param.sort,
|
|
|
num:param.num
|
|
|
},
|
|
|
dateType:"json",
|
|
|
beforeSend:function() {
|
...
|
...
|
@@ -263,7 +310,7 @@ $(function(){ |
|
|
success:function (data) {
|
|
|
console.log(data);
|
|
|
if(data.status) {
|
|
|
// window.location.href = data.data;
|
|
|
window.location.href = data.data;
|
|
|
} else {
|
|
|
alert(data.msg);
|
|
|
}
|
...
|
...
|
@@ -277,23 +324,170 @@ $(function(){ |
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
//收藏
|
|
|
$(document).on('click','.btn-collect', function(){
|
|
|
if ($(this).hasClass('active')) {
|
|
|
$(this).removeClass('active');
|
|
|
} else {
|
|
|
$(this).addClass('active');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//收藏2
|
|
|
$(document).on('click','.btn-care', function(){
|
|
|
if ($(this).hasClass('active')) {
|
|
|
$(this).removeClass('active');
|
|
|
} else {
|
|
|
$(this).addClass('active');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 选择收货地址
|
|
|
$('.panel-address').on('click','.ads-box',function(){
|
|
|
$('input[name=address_id]').val($(this).parent('li').data('id'));
|
|
|
});
|
|
|
|
|
|
// 关闭地址弹窗
|
|
|
$('.cha').click(function(){
|
|
|
$('.mask').hide();
|
|
|
});
|
|
|
|
|
|
// 添加新地址
|
|
|
$('.add-address').click(function(){
|
|
|
$('.mask_title').html('添加新地址');
|
|
|
$('.mask').show();
|
|
|
});
|
|
|
|
|
|
// 编辑地址
|
|
|
$('.edit-address').click(function(){
|
|
|
var id = $(this).parents('li').data('id');
|
|
|
$('input[name=realname]').val($(this).parents('li').find('.ads-name').html());
|
|
|
$('input[name=mobile]').val($(this).parents('li').find('.ads-tel').html());
|
|
|
$('select[name=province]').val($(this).parents('li').find('input[name=province]').val());
|
|
|
$('select[name=city]').val($(this).parents('li').find('input[name=city]').val());
|
|
|
$('select[name=region]').val($(this).parents('li').find('input[name=region]').val());
|
|
|
$('input[name=address]').val($(this).parents('li').find('.ads-desc').html());
|
|
|
$('input[name=id]').val(id);
|
|
|
$('.mask_title').html('编辑地址');
|
|
|
$('.mask').show();
|
|
|
});
|
|
|
|
|
|
// 删除地址
|
|
|
$('.del-address').click(function(){
|
|
|
var btn = $(this);
|
|
|
var id = $(this).parents('li').data('id');
|
|
|
if(confirm('确认删除该收货地址?')) {
|
|
|
$.ajax({
|
|
|
url:param.delAddress,
|
|
|
type:"POST",
|
|
|
data:{
|
|
|
id:id
|
|
|
},
|
|
|
dateType:"json",
|
|
|
success:function (data) {
|
|
|
if(data.status) {
|
|
|
btn.parents('li').remove();
|
|
|
} else {
|
|
|
alert(data.msg);
|
|
|
}
|
|
|
},
|
|
|
error: function (data, status, e) { //提交失败自动执行的处理函数
|
|
|
alert(e);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$('.sub').click(function(){
|
|
|
address($(this));
|
|
|
});
|
|
|
|
|
|
// 添加/编辑收货地址
|
|
|
function address(obj) {
|
|
|
var text = obj.text();
|
|
|
var form = $('#handle_address').serialize();
|
|
|
if($('input[name=id]').val() == '') {
|
|
|
url = param.addAddress;
|
|
|
} else {
|
|
|
url = param.editAddress;
|
|
|
}
|
|
|
console.log(form);
|
|
|
$.ajax({
|
|
|
url:url,
|
|
|
type:"POST",
|
|
|
data:form,
|
|
|
dateType:"json",
|
|
|
beforeSend:function() {
|
|
|
obj.text('提交中...').attr('disabled', true);
|
|
|
},
|
|
|
success:function (data) {
|
|
|
if(data.status) {
|
|
|
location.reload();
|
|
|
} else {
|
|
|
alert(data.msg);
|
|
|
}
|
|
|
},
|
|
|
error: function (data, status, e) { //提交失败自动执行的处理函数
|
|
|
alert(e);
|
|
|
},
|
|
|
complete: function () {
|
|
|
// Handle the complete event
|
|
|
obj.text(text).attr('disabled', false);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 立即购买
|
|
|
$('.btn-buy').click(function(){
|
|
|
var id = param.id;
|
|
|
var num = $('.numberbox').val();
|
|
|
var data = {
|
|
|
id:id,
|
|
|
num:num
|
|
|
}
|
|
|
$.ajax({
|
|
|
url:param.buy,
|
|
|
type:"POST",
|
|
|
data:data,
|
|
|
dateType:"json",
|
|
|
success:function (data) {
|
|
|
if(data.status) {
|
|
|
window.location.href = data.data;
|
|
|
} else {
|
|
|
alert(data.msg);
|
|
|
}
|
|
|
},
|
|
|
error: function (data, status, e) { //提交失败自动执行的处理函数
|
|
|
alert(e);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
//收藏
|
|
|
$(document).on('click','.btn-collect', function(){
|
|
|
var btn = $(this);
|
|
|
var goods_id = param.id;
|
|
|
favorite(goods_id,btn);
|
|
|
});
|
|
|
|
|
|
//收藏2
|
|
|
$(document).on('click','.btn-care', function(){
|
|
|
var btn = $(this);
|
|
|
var goods_id = btn.parents('li').data('id');
|
|
|
favorite(goods_id,btn);
|
|
|
});
|
|
|
|
|
|
// 收藏/取消收藏处理
|
|
|
function favorite(goods_id,obj) {
|
|
|
var data = {
|
|
|
goods_id:goods_id
|
|
|
};
|
|
|
$.ajax({
|
|
|
url:param.do_favorite,
|
|
|
type:"POST",
|
|
|
data:data,
|
|
|
dateType:"json",
|
|
|
success:function (data) {
|
|
|
console.log(data);
|
|
|
if(data.status) {
|
|
|
if (obj.hasClass('active')) {
|
|
|
obj.find('span').text('收藏');
|
|
|
obj.removeClass('active');
|
|
|
} else {
|
|
|
obj.find('span').text('已收藏');
|
|
|
obj.addClass('active');
|
|
|
}
|
|
|
} else {
|
|
|
alert(data.msg);
|
|
|
}
|
|
|
},
|
|
|
error: function (data, status, e) { //提交失败自动执行的处理函数
|
|
|
alert(e);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
}); |
|
|
\ No newline at end of file |
...
|
...
|
|