|
|
/**
|
|
|
* @description: 订单保存
|
|
|
* @time: 2015/12/21
|
|
|
*/
|
|
|
|
|
|
var $ = require('yoho.jquery');
|
|
|
|
|
|
var address = require('./address');
|
|
|
|
|
|
var dialog = require('../common/dialog');
|
|
|
|
|
|
var Order = {
|
|
|
/*业务数据(人民币)*/
|
|
|
Data: {
|
|
|
product: 0,//商品价格
|
|
|
activity: 0,//活动
|
|
|
carriage: 0,//邮费
|
|
|
juan: 0,//优惠卷
|
|
|
yohocoin: 0//YOHO币
|
|
|
},
|
|
|
/*view 交互*/
|
|
|
UI: {
|
|
|
e: {
|
|
|
$pan: $('.pan'),
|
|
|
$jc: $('#juancode'),
|
|
|
$bp: $('#biprice'),
|
|
|
$statistics: $('li', '.play-total'),
|
|
|
$tobi: $('p em', '.play-bi-pan .play-pan'),
|
|
|
$cancel: $('.cancel', '.btn-group'),
|
|
|
$total: $('em', '.to-play'),
|
|
|
$tbody: $('table tbody', '.pay-wapper'),
|
|
|
|
|
|
//请填写并核对一下信息
|
|
|
$orderSelectionSave: $('.address-list h2 span'),
|
|
|
$addAddress: $('.add-address'),
|
|
|
$addressManage: $('.address-manage'),
|
|
|
$spanPayTypeLegend: $('span.pay-type-legend'),
|
|
|
$supportType: $('.support-type'),
|
|
|
$existAddressListWrap: $('.exist-address-list'),
|
|
|
$existAddressList: $('.exist-address-list').find('li'),
|
|
|
$existAddress: $('.exist-address-list').find('input[name="exist-address"]'),
|
|
|
$payTimeModify: $('.pay-time-modify'),
|
|
|
$switchPayModify: $('.switch-pay-modify'),
|
|
|
$modityPayInfo: $('.modity-pay-info'),
|
|
|
$payTotal: $('.play-total'),
|
|
|
$toPay: $('.to-play em'),
|
|
|
|
|
|
$redEnvelopes: $('.red-envelopes'),
|
|
|
$useEnvelopes: $('.use-envelopes'),
|
|
|
$hasEnvelopes: $('.has-envelopes span'),
|
|
|
$useEnvelopesInput: $('.use-envelopes').find('input')
|
|
|
},
|
|
|
init: function() {
|
|
|
var e = this.e,
|
|
|
d = Order.Data,
|
|
|
c = Order.Common;
|
|
|
|
|
|
//初始化产品价格(表格中的价格)
|
|
|
e.$tbody.find('tr').each(function(index) {
|
|
|
|
|
|
var td = $(this).find('td');
|
|
|
var len = e.$tbody.find('tr').length;
|
|
|
var subtotal = parseFloat(td.eq(1).html()) * parseInt(td.eq(3).html());
|
|
|
|
|
|
td.eq(1).html('¥' + td.eq(1).html());
|
|
|
|
|
|
if (td.hasClass('xforone')) {
|
|
|
td.eq(4).find('del').html('¥' + c.strFixed(subtotal));
|
|
|
subtotal = 0;
|
|
|
} else {
|
|
|
td.eq(4).html('¥' + c.strFixed(subtotal));
|
|
|
}
|
|
|
d.product += subtotal;
|
|
|
if (!index) {
|
|
|
td.last().attr('rowspan', len);
|
|
|
} else {
|
|
|
td.last().remove();
|
|
|
}
|
|
|
if (index === len - 1) {
|
|
|
e.$tbody.find('tr').eq(0).find('td').last().html('<strong>¥' + c.strFixed(d.product) + '</strong>');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 使用优惠券、使用yoho币点击展开
|
|
|
e.$pan.find('dt').click(function() {
|
|
|
|
|
|
var pan = $(this).parent('dl.pan');
|
|
|
|
|
|
if (pan.find('dd').is(':hidden')) {
|
|
|
c.winShow(pan);
|
|
|
|
|
|
$(this).addClass('active');
|
|
|
} else {
|
|
|
c.winHide(pan);
|
|
|
|
|
|
$(this).removeClass('active');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//请填写并核对一下信息
|
|
|
e.$orderSelectionSave.click(function() {
|
|
|
var i = 0,
|
|
|
$addressLi = $('.exist-address-list li'),
|
|
|
liLen = $addressLi.length,
|
|
|
notSelect = 0;
|
|
|
|
|
|
if (!$(this).attr('expand')) {
|
|
|
|
|
|
$(this).attr('expand', 'expand').text('[不保存并关闭]');
|
|
|
|
|
|
$('.exist-address-list li').removeClass('hide');
|
|
|
|
|
|
$('.save-btn').removeClass('hide');
|
|
|
|
|
|
e.$existAddressListWrap.addClass('address-expand');
|
|
|
|
|
|
if (liLen === 1) {
|
|
|
e.$addressManage.removeClass('hide');
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (i = 0; i < liLen; i++) {
|
|
|
|
|
|
if ($addressLi.eq(i).hasClass('address_select')) {
|
|
|
notSelect++;
|
|
|
}
|
|
|
|
|
|
if (!$addressLi.eq(i).hasClass('address_select')) {
|
|
|
$addressLi.eq(i).addClass('hide');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (notSelect === 0) {
|
|
|
$('.exist-address-list li:not(".use-new-address")').removeClass('hide');
|
|
|
|
|
|
$('.use-new-address input').removeAttr('checked');
|
|
|
}
|
|
|
|
|
|
$('.address-list-inner li.address_select input').attr('checked', 'checked');
|
|
|
$('.address-list-inner li').removeClass('active');
|
|
|
$('.address-list-inner li.address_select').addClass('active');
|
|
|
|
|
|
$(this).removeAttr('expand').text('[修改]');
|
|
|
|
|
|
$('.save-btn').addClass('hide');
|
|
|
|
|
|
e.$existAddressListWrap.removeClass('address-expand');
|
|
|
|
|
|
e.$addressManage.addClass('hide');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
//支付及送货时间
|
|
|
e.$switchPayModify.click(function() {
|
|
|
|
|
|
if (e.$payTimeModify.hasClass('hide')) {
|
|
|
e.$payTimeModify.removeClass('hide');
|
|
|
e.$modityPayInfo.addClass('hide');
|
|
|
$(this).text('[不保存并关闭]');
|
|
|
} else {
|
|
|
e.$payTimeModify.addClass('hide');
|
|
|
e.$modityPayInfo.removeClass('hide');
|
|
|
$(this).text('[修改]');
|
|
|
|
|
|
e.$payTimeModify.find('input[name="pay-type"]').filter('.checked').attr('checked', 'checked');
|
|
|
e.$payTimeModify.find('input[name="pay-time-radio"]').filter('.checked').attr('checked', 'checked');
|
|
|
e.$payTimeModify.find('input[name="call-me"]').filter('.checked').attr('checked', 'checked');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
e.$spanPayTypeLegend.click(function() {
|
|
|
$(this).toggleClass('active');
|
|
|
|
|
|
e.$supportType.toggleClass('hide');
|
|
|
});
|
|
|
|
|
|
$(document).on('click', '.exist-address-list li', function() {
|
|
|
|
|
|
$('.exist-address-list li').removeClass('active');
|
|
|
|
|
|
$(this).addClass('active');
|
|
|
|
|
|
$(this).find('input').attr('checked', 'checked');
|
|
|
|
|
|
if ($(this).hasClass('use-new-address')) {
|
|
|
e.$addressManage.removeClass('hide');
|
|
|
|
|
|
$('.address-manage input').val('');
|
|
|
|
|
|
$('.save-btn').removeAttr('data-id');
|
|
|
|
|
|
// 0表示获取所有省的列表,'000000'表示无匹配的区域码
|
|
|
address.newAddress(0, '000000');
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
//渲染价格明细
|
|
|
render: function(data, tips) {
|
|
|
|
|
|
// 下面这段是在服务端算价格
|
|
|
var e = this.e,
|
|
|
i,
|
|
|
dArr = data.promotion_formula_list,
|
|
|
str = '',
|
|
|
isExpress = '';
|
|
|
|
|
|
var tipsStr;
|
|
|
|
|
|
var envelopesVal;
|
|
|
|
|
|
if (!!tips) {
|
|
|
tipsStr = tips;
|
|
|
} else {
|
|
|
tipsStr = '';
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < dArr.length; i++) {
|
|
|
|
|
|
if (dArr[i].promotion === '优惠券:') {
|
|
|
dArr[i].promotion = (tipsStr ? tipsStr : '优惠券') + '<span class="juan-modify">[修改]</span>:';
|
|
|
}
|
|
|
|
|
|
if (dArr[i].promotion === 'YOHO币:') {
|
|
|
dArr[i].promotion = 'YOHO币<span class="bi-modify">[修改]</span>:';
|
|
|
}
|
|
|
|
|
|
if (dArr[i].isExpress) {
|
|
|
isExpress = 'total-express-w';
|
|
|
} else {
|
|
|
isExpress = '';
|
|
|
}
|
|
|
|
|
|
str += '<li class="' + isExpress + '">' +
|
|
|
'<label>' + dArr[i].promotion + '</label>' +
|
|
|
'<em>' + dArr[i].promotion_amount + '</em>' +
|
|
|
'</li>';
|
|
|
}
|
|
|
|
|
|
e.$payTotal.html(str);
|
|
|
e.$toPay.html((data.last_order_amount).toFixed(2));
|
|
|
|
|
|
//有货币清零状态更新
|
|
|
$('#biprice').val(100 * data.use_yoho_coin);
|
|
|
if (~~data.use_yoho_coin === 0) {
|
|
|
$('.errbitip').text('');
|
|
|
} else {
|
|
|
$('.errbitip').text('抵扣' + data.use_yoho_coin.toFixed(2) + '元');
|
|
|
}
|
|
|
|
|
|
envelopesVal = e.$useEnvelopesInput.data('all') - data.use_red_envelopes;
|
|
|
|
|
|
if (~~data.use_red_envelopes > 0) {
|
|
|
e.$useEnvelopes.find('span').html('-¥' + data.use_red_envelopes.toFixed(2));
|
|
|
e.$useEnvelopes.find('input').attr('data-use', data.use_red_envelopes);
|
|
|
} else {
|
|
|
e.$useEnvelopes.find('span').html('-¥0.00');
|
|
|
e.$hasEnvelopes.html('¥' + (e.$useEnvelopesInput.attr('data-all') * 1).toFixed(2));
|
|
|
e.$redEnvelopes.removeClass('active');
|
|
|
e.$useEnvelopesInput.prop('checked', false);
|
|
|
}
|
|
|
e.$hasEnvelopes.html('¥' + envelopesVal.toFixed(2));
|
|
|
}
|
|
|
},
|
|
|
/*公共方法*/
|
|
|
Common: {
|
|
|
enterNUM: function(str1, str2) {
|
|
|
str1 = str1.replace(/[^\d]/g, '');
|
|
|
if (str1 && str2) {
|
|
|
str1 = parseInt(str1);
|
|
|
str2 = parseInt(str2);
|
|
|
if (str1 > str2) {
|
|
|
str1 = str2;
|
|
|
}
|
|
|
}
|
|
|
return str1;
|
|
|
},
|
|
|
calucate: function() {
|
|
|
var p = Order.Data;
|
|
|
|
|
|
$.each(Order.Data, function(key, index) {
|
|
|
p[key] = parseFloat(Order.Data[key]);
|
|
|
});
|
|
|
return p.product - p.activity + p.carriage - p.juan - p.yohocoin;
|
|
|
},
|
|
|
winShow: function(pan) {
|
|
|
pan.find('dt').show();
|
|
|
pan.find('dd').show();
|
|
|
if (pan.attr('class').match(/(-bi-)|(-juan-)/g)) {
|
|
|
pan.find('dt').hide();
|
|
|
}
|
|
|
},
|
|
|
winHide: function(pan) {
|
|
|
pan.find('dt').show();
|
|
|
pan.find('dd').hide();
|
|
|
|
|
|
/*if (pan.hasClass('play-juan-pan') && $('.juan-modify').length > 0) {
|
|
|
pan.find('dt').hide();
|
|
|
}
|
|
|
|
|
|
if (pan.hasClass('play-bi-pan') && $('.bi-modify').length > 0) {
|
|
|
pan.find('dt').hide();
|
|
|
}*/
|
|
|
},
|
|
|
strFixed: function(str) {
|
|
|
return parseFloat(str).toFixed(2);
|
|
|
}
|
|
|
},
|
|
|
/*业务逻辑*/
|
|
|
Bll: {
|
|
|
e: {
|
|
|
$juanok: $('#juansubmit'),
|
|
|
$juantip: $('.errtip', '.play-juan-pan'),
|
|
|
$biok: $('#bisubmit'),
|
|
|
$carriageGroup: $('input[name="carriagegroup"]'),
|
|
|
$selectExpress: $('.express-list input'),
|
|
|
$bp: $('#biprice'),
|
|
|
$errorTip: $('.errbitip'),
|
|
|
$useEnvelopes: $('.use-envelopes'),
|
|
|
$hasEnvelopes: $('.has-envelopes span'),
|
|
|
$useEnvelopesInput: $('.use-envelopes').find('input'),
|
|
|
$redEnvelopes: $('.red-envelopes'),
|
|
|
$loading: $('.loading')
|
|
|
},
|
|
|
init: function() {
|
|
|
var e = this.e,
|
|
|
u = Order.UI,
|
|
|
options,
|
|
|
c = Order.Common,
|
|
|
envelopesVal;
|
|
|
|
|
|
function getSelectData(callback) {
|
|
|
|
|
|
var $juangroupInput = $('.play-juan.is-select input[name="juangroup"]:checked');
|
|
|
var expressVal = $('.express-list input[name="carriagegroup"]').val();
|
|
|
var biVal = $('#biprice.is-select').val();
|
|
|
var codeVal = $juangroupInput.val();
|
|
|
var cartType = $('.address-manage').attr('cart-type');
|
|
|
var redEnvelopes = $('.use-envelopes input:checked').attr('data-use');
|
|
|
var resultData;
|
|
|
|
|
|
codeVal = !!codeVal ? codeVal : $juangroupInput.closest('li').find('#juancode').val();
|
|
|
|
|
|
resultData = {
|
|
|
cartType: cartType,
|
|
|
deliveryWay: expressVal,
|
|
|
couponCode: codeVal,
|
|
|
yohoCoin: biVal
|
|
|
|
|
|
//redEnvelopes: e.$useEnvelopesInput.length > 0 ? ~~e.$hasEnvelopes.text().substring(1) : '0'
|
|
|
};
|
|
|
|
|
|
if (!!redEnvelopes) {
|
|
|
resultData.redEnvelopes = redEnvelopes;
|
|
|
}
|
|
|
|
|
|
callback(resultData);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 选择快递
|
|
|
e.$selectExpress.click(function() {
|
|
|
|
|
|
var expressId = $(this).val();
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
d.deliveryWay = expressId;
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
u.render(data.data);
|
|
|
|
|
|
if (expressId === '1') {
|
|
|
|
|
|
$('.express-list.sf').addClass('hide');
|
|
|
} else if (expressId === '2') {
|
|
|
$('.express-list.sf').removeClass('hide');
|
|
|
}
|
|
|
} else {
|
|
|
new dialog.Alert(data.message).show();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
//点击 优惠卷支付 确认按钮
|
|
|
e.$juanok.click(function() {
|
|
|
|
|
|
var pan = $(this).parents('dl.pan');
|
|
|
|
|
|
var juanText = '';
|
|
|
|
|
|
$('.play-juan').addClass('is-select');
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
var code = d.couponCode;
|
|
|
|
|
|
if (!code) {
|
|
|
|
|
|
e.$juantip.html('请选择或填写一个优惠券');
|
|
|
$('.play-juan').removeClass('is-select');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
|
|
|
juanText = $('.play-juan input[value="' + code + '"]').next().text();
|
|
|
u.render(data.data, juanText);
|
|
|
|
|
|
//$('#juancode').val(code);
|
|
|
|
|
|
c.winHide(pan);
|
|
|
e.$juantip.html('');
|
|
|
|
|
|
//$('.play-juan-pan dt').hide();
|
|
|
|
|
|
} else {
|
|
|
e.$juantip.html(data.message);
|
|
|
$('.play-juan').removeClass('is-select');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
// 优惠券修改
|
|
|
$(document).on('click', '.juan-modify', function() {
|
|
|
|
|
|
|
|
|
var $pan = $('.play-juan-pan');
|
|
|
|
|
|
c.winShow($pan);
|
|
|
});
|
|
|
|
|
|
e.$biok.click(function() {
|
|
|
|
|
|
var pan = $(this).parents('dl.pan');
|
|
|
var juanText;
|
|
|
|
|
|
$('#biprice').addClass('is-select');
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
if (!!d.couponCode) {
|
|
|
juanText = $('.play-juan input[value="' + d.couponCode + '"]').next().text();
|
|
|
}
|
|
|
|
|
|
//if (d.yohoCoin * 1 === 0) {
|
|
|
if (!/^\d+$/.test(d.yohoCoin + '') || d.yohoCoin * 1 === 0) {
|
|
|
$('.errbitip').html('请输入一个正整数');
|
|
|
$('#biprice').removeClass('is-select');
|
|
|
|
|
|
} else if (d.yohoCoin * 1 > $('.play-pan em').text() * 1) {
|
|
|
|
|
|
$('.errbitip').html('您的YOHO币不足');
|
|
|
$('#biprice').removeClass('is-select');
|
|
|
|
|
|
} else {
|
|
|
e.$loading.show();
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
|
|
|
u.render(data.data, juanText);
|
|
|
c.winHide(pan);
|
|
|
|
|
|
//$('.play-bi-pan dt').hide();
|
|
|
|
|
|
} else {
|
|
|
$('.errbitip').html(data.message);
|
|
|
$('#biprice').removeClass('is-select');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// 修改yoho币
|
|
|
$(document).on('click', '.bi-modify', function() {
|
|
|
|
|
|
|
|
|
var $pan = $('.play-bi-pan');
|
|
|
|
|
|
c.winShow($pan);
|
|
|
});
|
|
|
|
|
|
e.$bp.keyup(function() {
|
|
|
|
|
|
var val = $(this).val();
|
|
|
|
|
|
//if (val * 1 < 0 || val.indexOf('.') > 0) {
|
|
|
if (!/^\d+$/.test(val + '')) {
|
|
|
e.$errorTip.html('请输入一个正整数');
|
|
|
} else if (val * 1 > $(this).data('bi') * 1) {
|
|
|
e.$errorTip.html('您的YOHO币不足');
|
|
|
} else {
|
|
|
e.$errorTip.html('抵扣' + (val / 100).toFixed(2) + '元');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 取消yoho 币
|
|
|
$('.cancel-bi').click(function() {
|
|
|
|
|
|
|
|
|
var $pan = $('.play-bi-pan');
|
|
|
var juanText;
|
|
|
|
|
|
$('.errbitip').html('');
|
|
|
|
|
|
if ($('#biprice').hasClass('is-select')) {
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
d.yohoCoin = 0;
|
|
|
|
|
|
if (!!d.couponCode) {
|
|
|
juanText = $('.play-juan input[value="' + d.couponCode + '"]').next().text();
|
|
|
}
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
u.render(data.data, juanText);
|
|
|
c.winHide($pan);
|
|
|
|
|
|
$('#biprice').val('0');
|
|
|
|
|
|
//$('.play-bi-pan dt').hide();
|
|
|
$('#biprice').removeClass('is-select');
|
|
|
|
|
|
$('.errbitip').html('');
|
|
|
|
|
|
// $('.use-envelopes input').attr('checked', 'checked');
|
|
|
// $('.red-envelopes').addClass('active');
|
|
|
|
|
|
} else {
|
|
|
$('.errbitip').html(data.message);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
c.winHide($pan);
|
|
|
$('#biprice').val('0');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
// 取消优惠券
|
|
|
$('.cancel-code').click(function() {
|
|
|
|
|
|
var $pan = $('.play-juan-pan');
|
|
|
|
|
|
if ($('.play-juan').hasClass('is-select')) {
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
d.couponCode = '';
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
u.render(data.data);
|
|
|
|
|
|
c.winHide($pan);
|
|
|
$('.play-juan').removeClass('is-select');
|
|
|
|
|
|
$('#juancode').val('')
|
|
|
.siblings('input[name="juangroup"]').attr('checked', 'checked');
|
|
|
|
|
|
// $('.use-envelopes input').attr('checked', 'checked');
|
|
|
// $('.red-envelopes').addClass('active');
|
|
|
|
|
|
} else {
|
|
|
e.$juantip.html(data.message);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
});
|
|
|
} else {
|
|
|
c.winHide($pan);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
// 红包
|
|
|
envelopesVal = e.$useEnvelopesInput.data('all') - e.$useEnvelopesInput.data('use'); // 剩余的红包
|
|
|
e.$hasEnvelopes.text('¥' + envelopesVal.toFixed(2));
|
|
|
e.$useEnvelopes.find('input').click(function() {
|
|
|
|
|
|
var $this = $(this),
|
|
|
juanText;
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
$this.attr('disabled', 'disabled');
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
if (!!$this.attr('checked')) {
|
|
|
|
|
|
//d.redEnvelopes = $this.val();
|
|
|
d.redEnvelopes = $this.data('use');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
d.redEnvelopes = 0;
|
|
|
}
|
|
|
|
|
|
juanText = $('.play-juan input[value="' + d.couponCode + '"]').next().text();
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
u.render(data.data, juanText);
|
|
|
|
|
|
$this.removeAttr('disabled');
|
|
|
|
|
|
if (!!$this.attr('checked')) {
|
|
|
e.$redEnvelopes.addClass('active');
|
|
|
} else {
|
|
|
e.$useEnvelopes.find('span').html('-¥0.00');
|
|
|
e.$hasEnvelopes.html('¥' + ($this.attr('data-all') * 1).toFixed(2));
|
|
|
e.$redEnvelopes.removeClass('active');
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
new dialog.Alert(data.message).show();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
//发票抬头和备注字数限制
|
|
|
function limitStrLen($obj, len) {
|
|
|
|
|
|
var $this = $obj;
|
|
|
|
|
|
$this.keyup(function() {
|
|
|
|
|
|
if ($this.val().length > len) {
|
|
|
|
|
|
$this.val($this.val().substr(0, len));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
limitStrLen($('#piaodesc'), 30);
|
|
|
limitStrLen($('#notedesc'), 100);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
Order.Data.activity = 0;
|
|
|
Order.Data.carriage = 0;
|
|
|
|
|
|
Order.UI.init();
|
|
|
Order.Bll.init();
|
|
|
|
|
|
|
|
|
address.getUserAddressList();
|
|
|
|
|
|
// 0表示获取所有省的列表,'000000'表示无匹配的区域码
|
|
|
address.newAddress(0, '000000');
|
|
|
address.modifyAddress();
|
|
|
address.saveAddress(); |
|
|
/**
|
|
|
* @description: 订单保存
|
|
|
* @time: 2015/12/21
|
|
|
*/
|
|
|
|
|
|
var $ = require('yoho.jquery');
|
|
|
|
|
|
var address = require('./address');
|
|
|
|
|
|
var dialog = require('../common/dialog');
|
|
|
|
|
|
var Order = {
|
|
|
/*业务数据(人民币)*/
|
|
|
Data: {
|
|
|
product: 0, //商品价格
|
|
|
activity: 0, //活动
|
|
|
carriage: 0, //邮费
|
|
|
juan: 0, //优惠卷
|
|
|
yohocoin: 0 //YOHO币
|
|
|
},
|
|
|
/*view 交互*/
|
|
|
UI: {
|
|
|
e: {
|
|
|
$pan: $('.pan'),
|
|
|
$jc: $('#juancode'),
|
|
|
$bp: $('#biprice'),
|
|
|
$statistics: $('li', '.play-total'),
|
|
|
$tobi: $('p em', '.play-bi-pan .play-pan'),
|
|
|
$cancel: $('.cancel', '.btn-group'),
|
|
|
$total: $('em', '.to-play'),
|
|
|
$tbody: $('table tbody', '.pay-wapper'),
|
|
|
|
|
|
//请填写并核对一下信息
|
|
|
$orderSelectionSave: $('.address-list h2 span'),
|
|
|
$addAddress: $('.add-address'),
|
|
|
$addressManage: $('.address-manage'),
|
|
|
$spanPayTypeLegend: $('span.pay-type-legend'),
|
|
|
$supportType: $('.support-type'),
|
|
|
$existAddressListWrap: $('.exist-address-list'),
|
|
|
$existAddressList: $('.exist-address-list').find('li'),
|
|
|
$existAddress: $('.exist-address-list').find('input[name="exist-address"]'),
|
|
|
$payTimeModify: $('.pay-time-modify'),
|
|
|
$switchPayModify: $('.switch-pay-modify'),
|
|
|
$modityPayInfo: $('.modity-pay-info'),
|
|
|
$payTotal: $('.play-total'),
|
|
|
$toPay: $('.to-play em'),
|
|
|
|
|
|
$redEnvelopes: $('.red-envelopes'),
|
|
|
$useEnvelopes: $('.use-envelopes'),
|
|
|
$hasEnvelopes: $('.has-envelopes span'),
|
|
|
$useEnvelopesInput: $('.use-envelopes').find('input')
|
|
|
},
|
|
|
init: function() {
|
|
|
var e = this.e,
|
|
|
d = Order.Data,
|
|
|
c = Order.Common;
|
|
|
|
|
|
//初始化产品价格(表格中的价格)
|
|
|
e.$tbody.find('tr').each(function(index) {
|
|
|
|
|
|
var td = $(this).find('td');
|
|
|
var len = e.$tbody.find('tr').length;
|
|
|
var subtotal = parseFloat(td.eq(1).html()) * parseInt(td.eq(3).html());
|
|
|
|
|
|
td.eq(1).html('¥' + td.eq(1).html());
|
|
|
|
|
|
if (td.hasClass('xforone')) {
|
|
|
td.eq(4).find('del').html('¥' + c.strFixed(subtotal));
|
|
|
subtotal = 0;
|
|
|
} else {
|
|
|
td.eq(4).html('¥' + c.strFixed(subtotal));
|
|
|
}
|
|
|
d.product += subtotal;
|
|
|
if (!index) {
|
|
|
td.last().attr('rowspan', len);
|
|
|
} else {
|
|
|
td.last().remove();
|
|
|
}
|
|
|
if (index === len - 1) {
|
|
|
e.$tbody.find('tr').eq(0).find('td').last().html('<strong>¥' + c.strFixed(d.product) + '</strong>');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 使用优惠券、使用yoho币点击展开
|
|
|
e.$pan.find('dt').click(function() {
|
|
|
|
|
|
var pan = $(this).parent('dl.pan');
|
|
|
|
|
|
if (pan.find('dd').is(':hidden')) {
|
|
|
c.winShow(pan);
|
|
|
|
|
|
$(this).addClass('active');
|
|
|
} else {
|
|
|
c.winHide(pan);
|
|
|
|
|
|
$(this).removeClass('active');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
//请填写并核对一下信息
|
|
|
e.$orderSelectionSave.click(function() {
|
|
|
var i = 0,
|
|
|
$addressLi = $('.exist-address-list li'),
|
|
|
liLen = $addressLi.length,
|
|
|
notSelect = 0;
|
|
|
|
|
|
if (!$(this).attr('expand')) {
|
|
|
|
|
|
$(this).attr('expand', 'expand').text('[不保存并关闭]');
|
|
|
|
|
|
$('.exist-address-list li').removeClass('hide');
|
|
|
|
|
|
$('.save-btn').removeClass('hide');
|
|
|
|
|
|
e.$existAddressListWrap.addClass('address-expand');
|
|
|
|
|
|
if (liLen === 1) {
|
|
|
e.$addressManage.removeClass('hide');
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
for (i = 0; i < liLen; i++) {
|
|
|
|
|
|
if ($addressLi.eq(i).hasClass('address_select')) {
|
|
|
notSelect++;
|
|
|
}
|
|
|
|
|
|
if (!$addressLi.eq(i).hasClass('address_select')) {
|
|
|
$addressLi.eq(i).addClass('hide');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (notSelect === 0) {
|
|
|
$('.exist-address-list li:not(".use-new-address")').removeClass('hide');
|
|
|
|
|
|
$('.use-new-address input').removeAttr('checked');
|
|
|
}
|
|
|
|
|
|
$('.address-list-inner li.address_select input').attr('checked', 'checked');
|
|
|
$('.address-list-inner li').removeClass('active');
|
|
|
$('.address-list-inner li.address_select').addClass('active');
|
|
|
|
|
|
$(this).removeAttr('expand').text('[修改]');
|
|
|
|
|
|
$('.save-btn').addClass('hide');
|
|
|
|
|
|
e.$existAddressListWrap.removeClass('address-expand');
|
|
|
|
|
|
e.$addressManage.addClass('hide');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
//支付及送货时间
|
|
|
e.$switchPayModify.click(function() {
|
|
|
|
|
|
if (e.$payTimeModify.hasClass('hide')) {
|
|
|
e.$payTimeModify.removeClass('hide');
|
|
|
e.$modityPayInfo.addClass('hide');
|
|
|
$(this).text('[不保存并关闭]');
|
|
|
} else {
|
|
|
e.$payTimeModify.addClass('hide');
|
|
|
e.$modityPayInfo.removeClass('hide');
|
|
|
$(this).text('[修改]');
|
|
|
|
|
|
e.$payTimeModify.find('input[name="pay-type"]').filter('.checked').attr('checked', 'checked');
|
|
|
e.$payTimeModify.find('input[name="pay-time-radio"]').filter('.checked').attr('checked', 'checked');
|
|
|
e.$payTimeModify.find('input[name="call-me"]').filter('.checked').attr('checked', 'checked');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
e.$spanPayTypeLegend.click(function() {
|
|
|
$(this).toggleClass('active');
|
|
|
|
|
|
e.$supportType.toggleClass('hide');
|
|
|
});
|
|
|
|
|
|
$(document).on('click', '.exist-address-list li', function() {
|
|
|
|
|
|
$('.exist-address-list li').removeClass('active');
|
|
|
|
|
|
$(this).addClass('active');
|
|
|
|
|
|
$(this).find('input').attr('checked', 'checked');
|
|
|
|
|
|
if ($(this).hasClass('use-new-address')) {
|
|
|
e.$addressManage.removeClass('hide');
|
|
|
|
|
|
$('.address-manage input').val('');
|
|
|
|
|
|
$('.save-btn').removeAttr('data-id');
|
|
|
|
|
|
// 0表示获取所有省的列表,'000000'表示无匹配的区域码
|
|
|
address.newAddress(0, '000000');
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
|
|
|
//渲染价格明细
|
|
|
render: function(data, tips) {
|
|
|
|
|
|
// 下面这段是在服务端算价格
|
|
|
var e = this.e,
|
|
|
i,
|
|
|
dArr = data.promotion_formula_list,
|
|
|
str = '',
|
|
|
isExpress = '';
|
|
|
|
|
|
var tipsStr;
|
|
|
|
|
|
var envelopesVal;
|
|
|
|
|
|
if (!!tips) {
|
|
|
tipsStr = tips;
|
|
|
} else {
|
|
|
tipsStr = '';
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < dArr.length; i++) {
|
|
|
|
|
|
if (dArr[i].promotion === '优惠券:') {
|
|
|
dArr[i].promotion = (tipsStr ? tipsStr : '优惠券') + '<span class="juan-modify">[修改]</span>:';
|
|
|
}
|
|
|
|
|
|
if (dArr[i].promotion === 'YOHO币:') {
|
|
|
dArr[i].promotion = 'YOHO币<span class="bi-modify">[修改]</span>:';
|
|
|
}
|
|
|
|
|
|
if (dArr[i].isExpress) {
|
|
|
isExpress = 'total-express-w';
|
|
|
} else {
|
|
|
isExpress = '';
|
|
|
}
|
|
|
|
|
|
str += '<li class="' + isExpress + '">' +
|
|
|
'<label>' + dArr[i].promotion + '</label>' +
|
|
|
'<em>' + dArr[i].promotion_amount + '</em>' +
|
|
|
'</li>';
|
|
|
}
|
|
|
|
|
|
e.$payTotal.html(str);
|
|
|
e.$toPay.html((data.last_order_amount).toFixed(2));
|
|
|
|
|
|
//有货币清零状态更新
|
|
|
$('#biprice').val(100 * data.use_yoho_coin);
|
|
|
if (~~data.use_yoho_coin === 0) {
|
|
|
$('.errbitip').text('');
|
|
|
} else {
|
|
|
$('.errbitip').text('抵扣' + data.use_yoho_coin.toFixed(2) + '元');
|
|
|
}
|
|
|
|
|
|
envelopesVal = e.$useEnvelopesInput.data('all') - data.use_red_envelopes;
|
|
|
|
|
|
if (~~data.use_red_envelopes > 0) {
|
|
|
e.$useEnvelopes.find('span').html('-¥' + data.use_red_envelopes.toFixed(2));
|
|
|
e.$useEnvelopes.find('input').attr('data-use', data.use_red_envelopes);
|
|
|
} else {
|
|
|
e.$useEnvelopes.find('span').html('-¥0.00');
|
|
|
e.$hasEnvelopes.html('¥' + (e.$useEnvelopesInput.attr('data-all') * 1).toFixed(2));
|
|
|
e.$redEnvelopes.removeClass('active');
|
|
|
e.$useEnvelopesInput.prop('checked', false);
|
|
|
}
|
|
|
e.$hasEnvelopes.html('¥' + envelopesVal.toFixed(2));
|
|
|
}
|
|
|
},
|
|
|
/*公共方法*/
|
|
|
Common: {
|
|
|
enterNUM: function(str1, str2) {
|
|
|
str1 = str1.replace(/[^\d]/g, '');
|
|
|
if (str1 && str2) {
|
|
|
str1 = parseInt(str1);
|
|
|
str2 = parseInt(str2);
|
|
|
if (str1 > str2) {
|
|
|
str1 = str2;
|
|
|
}
|
|
|
}
|
|
|
return str1;
|
|
|
},
|
|
|
calucate: function() {
|
|
|
var p = Order.Data;
|
|
|
|
|
|
$.each(Order.Data, function(key, index) {
|
|
|
p[key] = parseFloat(Order.Data[key]);
|
|
|
});
|
|
|
return p.product - p.activity + p.carriage - p.juan - p.yohocoin;
|
|
|
},
|
|
|
winShow: function(pan) {
|
|
|
pan.find('dt').show();
|
|
|
pan.find('dd').show();
|
|
|
if (pan.attr('class').match(/(-bi-)|(-juan-)/g)) {
|
|
|
pan.find('dt').hide();
|
|
|
}
|
|
|
},
|
|
|
winHide: function(pan) {
|
|
|
pan.find('dt').show();
|
|
|
pan.find('dd').hide();
|
|
|
|
|
|
/*if (pan.hasClass('play-juan-pan') && $('.juan-modify').length > 0) {
|
|
|
pan.find('dt').hide();
|
|
|
}
|
|
|
|
|
|
if (pan.hasClass('play-bi-pan') && $('.bi-modify').length > 0) {
|
|
|
pan.find('dt').hide();
|
|
|
}*/
|
|
|
},
|
|
|
strFixed: function(str) {
|
|
|
return parseFloat(str).toFixed(2);
|
|
|
}
|
|
|
},
|
|
|
/*业务逻辑*/
|
|
|
Bll: {
|
|
|
e: {
|
|
|
$juanok: $('#juansubmit'),
|
|
|
$juantip: $('.errtip', '.play-juan-pan'),
|
|
|
$biok: $('#bisubmit'),
|
|
|
$carriageGroup: $('input[name="carriagegroup"]'),
|
|
|
$selectExpress: $('.express-list input'),
|
|
|
$bp: $('#biprice'),
|
|
|
$errorTip: $('.errbitip'),
|
|
|
$useEnvelopes: $('.use-envelopes'),
|
|
|
$hasEnvelopes: $('.has-envelopes span'),
|
|
|
$useEnvelopesInput: $('.use-envelopes').find('input'),
|
|
|
$redEnvelopes: $('.red-envelopes'),
|
|
|
$loading: $('.loading')
|
|
|
},
|
|
|
init: function() {
|
|
|
var e = this.e,
|
|
|
u = Order.UI,
|
|
|
options,
|
|
|
c = Order.Common,
|
|
|
envelopesVal;
|
|
|
|
|
|
function getSelectData(callback) {
|
|
|
|
|
|
var $juangroupInput = $('.play-juan.is-select input[name="juangroup"]:checked');
|
|
|
var expressVal = $('.express-list input[name="carriagegroup"]').val();
|
|
|
var biVal = $('#biprice.is-select').val();
|
|
|
var codeVal = $juangroupInput.val();
|
|
|
var cartType = $('.address-manage').attr('cart-type');
|
|
|
var redEnvelopes = $('.use-envelopes input:checked').attr('data-use');
|
|
|
var resultData;
|
|
|
|
|
|
codeVal = !!codeVal ? codeVal : $juangroupInput.closest('li').find('#juancode').val();
|
|
|
|
|
|
resultData = {
|
|
|
cartType: cartType,
|
|
|
deliveryWay: expressVal,
|
|
|
couponCode: codeVal,
|
|
|
yohoCoin: biVal
|
|
|
|
|
|
//redEnvelopes: e.$useEnvelopesInput.length > 0 ? ~~e.$hasEnvelopes.text().substring(1) : '0'
|
|
|
};
|
|
|
|
|
|
if (!!redEnvelopes) {
|
|
|
resultData.redEnvelopes = redEnvelopes;
|
|
|
}
|
|
|
|
|
|
callback(resultData);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 选择快递
|
|
|
e.$selectExpress.click(function() {
|
|
|
|
|
|
var expressId = $(this).val();
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
d.deliveryWay = expressId;
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
u.render(data.data);
|
|
|
|
|
|
if (expressId === '1') {
|
|
|
|
|
|
$('.express-list.sf').addClass('hide');
|
|
|
} else if (expressId === '2') {
|
|
|
$('.express-list.sf').removeClass('hide');
|
|
|
}
|
|
|
} else {
|
|
|
new dialog.Alert(data.message).show();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
//点击 优惠卷支付 确认按钮
|
|
|
e.$juanok.click(function() {
|
|
|
|
|
|
var pan = $(this).parents('dl.pan');
|
|
|
|
|
|
var juanText = '';
|
|
|
|
|
|
$('.play-juan').addClass('is-select');
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
var code = d.couponCode;
|
|
|
|
|
|
if (!code) {
|
|
|
|
|
|
e.$juantip.html('请选择或填写一个优惠券');
|
|
|
$('.play-juan').removeClass('is-select');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
|
|
|
juanText = $('.play-juan input[value="' + code + '"]').next().text();
|
|
|
u.render(data.data, juanText);
|
|
|
|
|
|
//$('#juancode').val(code);
|
|
|
|
|
|
c.winHide(pan);
|
|
|
e.$juantip.html('');
|
|
|
|
|
|
//$('.play-juan-pan dt').hide();
|
|
|
|
|
|
} else {
|
|
|
e.$juantip.html(data.message);
|
|
|
$('.play-juan').removeClass('is-select');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
// 优惠券修改
|
|
|
$(document).on('click', '.juan-modify', function() {
|
|
|
|
|
|
|
|
|
var $pan = $('.play-juan-pan');
|
|
|
|
|
|
c.winShow($pan);
|
|
|
});
|
|
|
|
|
|
e.$biok.click(function() {
|
|
|
|
|
|
var pan = $(this).parents('dl.pan');
|
|
|
var juanText;
|
|
|
|
|
|
$('#biprice').addClass('is-select');
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
if (!!d.couponCode) {
|
|
|
juanText = $('.play-juan input[value="' + d.couponCode + '"]').next().text();
|
|
|
}
|
|
|
|
|
|
//if (d.yohoCoin * 1 === 0) {
|
|
|
if (!/^\d+$/.test(d.yohoCoin + '') || d.yohoCoin * 1 === 0) {
|
|
|
$('.errbitip').html('请输入一个正整数');
|
|
|
$('#biprice').removeClass('is-select');
|
|
|
|
|
|
} else if (d.yohoCoin * 1 > $('.play-pan em').text() * 1) {
|
|
|
|
|
|
$('.errbitip').html('您的YOHO币不足');
|
|
|
$('#biprice').removeClass('is-select');
|
|
|
|
|
|
} else {
|
|
|
e.$loading.show();
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
|
|
|
u.render(data.data, juanText);
|
|
|
c.winHide(pan);
|
|
|
|
|
|
//$('.play-bi-pan dt').hide();
|
|
|
|
|
|
} else {
|
|
|
$('.errbitip').html(data.message);
|
|
|
$('#biprice').removeClass('is-select');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// 修改yoho币
|
|
|
$(document).on('click', '.bi-modify', function() {
|
|
|
|
|
|
|
|
|
var $pan = $('.play-bi-pan');
|
|
|
|
|
|
c.winShow($pan);
|
|
|
});
|
|
|
|
|
|
e.$bp.keyup(function() {
|
|
|
|
|
|
var val = $(this).val();
|
|
|
|
|
|
//if (val * 1 < 0 || val.indexOf('.') > 0) {
|
|
|
if (!/^\d+$/.test(val + '')) {
|
|
|
e.$errorTip.html('请输入一个正整数');
|
|
|
} else if (val * 1 > $(this).data('bi') * 1) {
|
|
|
e.$errorTip.html('您的YOHO币不足');
|
|
|
} else {
|
|
|
e.$errorTip.html('抵扣' + (val / 100).toFixed(2) + '元');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 取消yoho 币
|
|
|
$('.cancel-bi').click(function() {
|
|
|
|
|
|
|
|
|
var $pan = $('.play-bi-pan');
|
|
|
var juanText;
|
|
|
|
|
|
$('.errbitip').html('');
|
|
|
|
|
|
if ($('#biprice').hasClass('is-select')) {
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
d.yohoCoin = 0;
|
|
|
|
|
|
if (!!d.couponCode) {
|
|
|
juanText = $('.play-juan input[value="' + d.couponCode + '"]').next().text();
|
|
|
}
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
u.render(data.data, juanText);
|
|
|
c.winHide($pan);
|
|
|
|
|
|
$('#biprice').val('0');
|
|
|
|
|
|
//$('.play-bi-pan dt').hide();
|
|
|
$('#biprice').removeClass('is-select');
|
|
|
|
|
|
$('.errbitip').html('');
|
|
|
|
|
|
// $('.use-envelopes input').attr('checked', 'checked');
|
|
|
// $('.red-envelopes').addClass('active');
|
|
|
|
|
|
} else {
|
|
|
$('.errbitip').html(data.message);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
c.winHide($pan);
|
|
|
$('#biprice').val('0');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
// 取消优惠券
|
|
|
$('.cancel-code').click(function() {
|
|
|
|
|
|
var $pan = $('.play-juan-pan');
|
|
|
|
|
|
if ($('.play-juan').hasClass('is-select')) {
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
d.couponCode = '';
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
u.render(data.data);
|
|
|
|
|
|
c.winHide($pan);
|
|
|
$('.play-juan').removeClass('is-select');
|
|
|
|
|
|
$('#juancode').val('')
|
|
|
.siblings('input[name="juangroup"]').attr('checked', 'checked');
|
|
|
|
|
|
// $('.use-envelopes input').attr('checked', 'checked');
|
|
|
// $('.red-envelopes').addClass('active');
|
|
|
|
|
|
} else {
|
|
|
e.$juantip.html(data.message);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
});
|
|
|
} else {
|
|
|
c.winHide($pan);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
// 红包
|
|
|
envelopesVal = e.$useEnvelopesInput.data('all') - e.$useEnvelopesInput.data('use'); // 剩余的红包
|
|
|
e.$hasEnvelopes.text('¥' + envelopesVal.toFixed(2));
|
|
|
e.$useEnvelopes.find('input').click(function() {
|
|
|
|
|
|
var $this = $(this),
|
|
|
juanText;
|
|
|
|
|
|
e.$loading.show();
|
|
|
|
|
|
$this.attr('disabled', 'disabled');
|
|
|
|
|
|
getSelectData(function(d) {
|
|
|
|
|
|
if (!!$this.attr('checked')) {
|
|
|
|
|
|
//d.redEnvelopes = $this.val();
|
|
|
d.redEnvelopes = $this.data('use');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
d.redEnvelopes = 0;
|
|
|
}
|
|
|
|
|
|
juanText = $('.play-juan input[value="' + d.couponCode + '"]').next().text();
|
|
|
|
|
|
options = {
|
|
|
type: 'POST',
|
|
|
url: '/cart/index/orderCompute',
|
|
|
data: d,
|
|
|
success: function(data) {
|
|
|
e.$loading.hide();
|
|
|
|
|
|
if (data.code === 200) {
|
|
|
u.render(data.data, juanText);
|
|
|
|
|
|
$this.removeAttr('disabled');
|
|
|
|
|
|
if (!!$this.attr('checked')) {
|
|
|
e.$redEnvelopes.addClass('active');
|
|
|
} else {
|
|
|
e.$useEnvelopes.find('span').html('-¥0.00');
|
|
|
e.$hasEnvelopes.html('¥' + ($this.attr('data-all') * 1).toFixed(2));
|
|
|
e.$redEnvelopes.removeClass('active');
|
|
|
}
|
|
|
} else {
|
|
|
|
|
|
new dialog.Alert(data.message).show();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
//发票抬头和备注字数限制
|
|
|
function limitStrLen($obj, len) {
|
|
|
|
|
|
var $this = $obj;
|
|
|
|
|
|
$this.keyup(function() {
|
|
|
|
|
|
if ($this.val().length > len) {
|
|
|
|
|
|
$this.val($this.val().substr(0, len));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
limitStrLen($('#piaodesc'), 30);
|
|
|
limitStrLen($('#notedesc'), 100);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
Order.Data.activity = 0;
|
|
|
Order.Data.carriage = 0;
|
|
|
|
|
|
Order.UI.init();
|
|
|
Order.Bll.init();
|
|
|
|
|
|
|
|
|
address.getUserAddressList();
|
|
|
|
|
|
// 0表示获取所有省的列表,'000000'表示无匹配的区域码
|
|
|
address.newAddress(0, '000000');
|
|
|
address.modifyAddress();
|
|
|
address.saveAddress();
|
|
|
|
|
|
//不同订单包裹提示
|
|
|
|
|
|
$('.why').click(function() {
|
|
|
$('#differentBag').show();
|
|
|
return false;
|
|
|
|
|
|
});
|
|
|
$('#differentBag').click(function() {
|
|
|
return false;
|
|
|
});
|
|
|
$(document).click(function() {
|
|
|
$('#differentBag').hide();
|
|
|
});
|
|
|
|
|
|
//订单包裹左右切换
|
|
|
function lunBo($pre, $next, $ul, $iWidth) {
|
|
|
var i = 1,
|
|
|
j = 1;
|
|
|
|
|
|
var iSpeed = 0,
|
|
|
isMoving = false;
|
|
|
|
|
|
$pre.click(function() {
|
|
|
if (isMoving) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($ul.css('left') === '0px') {
|
|
|
iSpeed = 0;
|
|
|
|
|
|
} else {
|
|
|
iSpeed += j * $iWidth;
|
|
|
isMoving = true;
|
|
|
}
|
|
|
$ul.stop().animate({
|
|
|
left: iSpeed
|
|
|
}, 300, function() {
|
|
|
isMoving = false;
|
|
|
});
|
|
|
});
|
|
|
$next.click(function() {
|
|
|
var $largeLeft = $ul.parent().width() - $ul.width() + 'px';
|
|
|
|
|
|
if (isMoving) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if ($ul.css('left') === $largeLeft) {
|
|
|
$ul.css('left', $largeLeft);
|
|
|
} else {
|
|
|
iSpeed += -i * $iWidth;
|
|
|
isMoving = true;
|
|
|
}
|
|
|
|
|
|
$ul.stop().animate({
|
|
|
left: iSpeed
|
|
|
}, 300, function() {
|
|
|
isMoving = false;
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//订单分类
|
|
|
$('.bag').find('ul').each(function() {
|
|
|
var $pre = $(this).parent().parent().find('.pre');
|
|
|
var $next = $(this).parent().parent().find('.next');
|
|
|
|
|
|
var $iWidth = $(this).find('li').eq(0).width();
|
|
|
var $length = $(this).find('li').size();
|
|
|
var $ulWidth = $iWidth * $length;
|
|
|
|
|
|
$(this).css('width', $ulWidth);
|
|
|
if ($length > 5) {
|
|
|
$pre.show();
|
|
|
$next.show();
|
|
|
lunBo($pre, $next, $(this), $iWidth);
|
|
|
} else {
|
|
|
$pre.hide();
|
|
|
$next.hide();
|
|
|
}
|
|
|
}); |
...
|
...
|
|