Authored by xiaowei

JIT拆单

... ... @@ -9,6 +9,19 @@ var address = require('./address');
var dialog = require('../common/dialog');
var accMul = function (arg1, arg2){
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
try {
m += s1.split(".")[1].length
} catch (e) {
}
try {
m += s2.split(".")[1].length
} catch (e) {
}
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
}
var Order = {
/*业务数据(人民币)*/
Data: {
... ... @@ -29,7 +42,6 @@ var Order = {
$cancel: $('.cancel', '.btn-group'),
$total: $('em', '.to-play'),
$tbody: $('table tbody', '.pay-wapper'),
//请填写并核对一下信息
$orderSelectionSave: $('.address-list h2 span'),
$addAddress: $('.add-address'),
... ... @@ -44,19 +56,18 @@ var Order = {
$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() {
init: function () {
var e = this.e,
d = Order.Data,
c = Order.Common;
d = Order.Data,
c = Order.Common;
//初始化产品价格(表格中的价格)
e.$tbody.find('tr').each(function(index) {
e.$tbody.find('tr').each(function (index) {
var td = $(this).find('td');
var len = e.$tbody.find('tr').length;
... ... @@ -82,7 +93,7 @@ var Order = {
});
// 使用优惠券、使用yoho币点击展开
e.$pan.find('dt').click(function() {
e.$pan.find('dt').click(function () {
var pan = $(this).parent('dl.pan');
... ... @@ -99,11 +110,11 @@ var Order = {
});
//请填写并核对一下信息
e.$orderSelectionSave.click(function() {
e.$orderSelectionSave.click(function () {
var i = 0,
$addressLi = $('.exist-address-list li'),
liLen = $addressLi.length,
notSelect = 0;
$addressLi = $('.exist-address-list li'),
liLen = $addressLi.length,
notSelect = 0;
if (!$(this).attr('expand')) {
... ... @@ -155,7 +166,7 @@ var Order = {
//支付及送货时间
e.$switchPayModify.click(function() {
e.$switchPayModify.click(function () {
if (e.$payTimeModify.hasClass('hide')) {
e.$payTimeModify.removeClass('hide');
... ... @@ -172,13 +183,13 @@ var Order = {
}
});
e.$spanPayTypeLegend.click(function() {
e.$spanPayTypeLegend.click(function () {
$(this).toggleClass('active');
e.$supportType.toggleClass('hide');
});
$(document).on('click', '.exist-address-list li', function() {
$(document).on('click', '.exist-address-list li', function () {
$('.exist-address-list li').removeClass('active');
... ... @@ -198,16 +209,15 @@ var Order = {
}
});
},
//渲染价格明细
render: function(data, tips) {
render: function (data, tips) {
// 下面这段是在服务端算价格
var e = this.e,
i,
dArr = data.promotion_formula_list,
str = '',
isExpress = '';
i,
dArr = data.promotion_formula_list,
str = '',
isExpress = '';
var tipsStr;
... ... @@ -236,16 +246,16 @@ var Order = {
}
str += '<li class="' + isExpress + '">' +
'<label>' + dArr[i].promotion + '</label>' +
'<em>' + dArr[i].promotion_amount + '</em>' +
'</li>';
'<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);
$('#biprice').val(accMul(100,data.use_yoho_coin));
if (~~data.use_yoho_coin === 0) {
$('.errbitip').text('');
} else {
... ... @@ -268,7 +278,7 @@ var Order = {
},
/*公共方法*/
Common: {
enterNUM: function(str1, str2) {
enterNUM: function (str1, str2) {
str1 = str1.replace(/[^\d]/g, '');
if (str1 && str2) {
str1 = parseInt(str1);
... ... @@ -279,34 +289,34 @@ var Order = {
}
return str1;
},
calucate: function() {
calucate: function () {
var p = Order.Data;
$.each(Order.Data, function(key, index) {
$.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) {
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) {
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();
}*/
pan.find('dt').hide();
}
if (pan.hasClass('play-bi-pan') && $('.bi-modify').length > 0) {
pan.find('dt').hide();
}*/
},
strFixed: function(str) {
strFixed: function (str) {
return parseFloat(str).toFixed(2);
}
},
... ... @@ -326,12 +336,12 @@ var Order = {
$redEnvelopes: $('.red-envelopes'),
$loading: $('.loading')
},
init: function() {
init: function () {
var e = this.e,
u = Order.UI,
options,
c = Order.Common,
envelopesVal;
u = Order.UI,
options,
c = Order.Common,
envelopesVal;
function getSelectData(callback) {
... ... @@ -351,7 +361,7 @@ var Order = {
couponCode: codeVal,
yohoCoin: biVal
//redEnvelopes: e.$useEnvelopesInput.length > 0 ? ~~e.$hasEnvelopes.text().substring(1) : '0'
//redEnvelopes: e.$useEnvelopesInput.length > 0 ? ~~e.$hasEnvelopes.text().substring(1) : '0'
};
if (!!redEnvelopes) {
... ... @@ -363,13 +373,13 @@ var Order = {
}
// 选择快递
e.$selectExpress.click(function() {
e.$selectExpress.click(function () {
var expressId = $(this).val();
e.$loading.show();
getSelectData(function(d) {
getSelectData(function (d) {
d.deliveryWay = expressId;
... ... @@ -377,7 +387,7 @@ var Order = {
type: 'POST',
url: '/cart/index/orderCompute',
data: d,
success: function(data) {
success: function (data) {
e.$loading.hide();
if (data.code === 200) {
... ... @@ -400,7 +410,7 @@ var Order = {
});
//点击 优惠卷支付 确认按钮
e.$juanok.click(function() {
e.$juanok.click(function () {
var pan = $(this).parents('dl.pan');
... ... @@ -408,7 +418,7 @@ var Order = {
$('.play-juan').addClass('is-select');
getSelectData(function(d) {
getSelectData(function (d) {
var code = d.couponCode;
... ... @@ -425,7 +435,7 @@ var Order = {
type: 'POST',
url: '/cart/index/orderCompute',
data: d,
success: function(data) {
success: function (data) {
e.$loading.hide();
... ... @@ -455,7 +465,7 @@ var Order = {
});
// 优惠券修改
$(document).on('click', '.juan-modify', function() {
$(document).on('click', '.juan-modify', function () {
var $pan = $('.play-juan-pan');
... ... @@ -463,14 +473,14 @@ var Order = {
c.winShow($pan);
});
e.$biok.click(function() {
e.$biok.click(function () {
var pan = $(this).parents('dl.pan');
var juanText;
$('#biprice').addClass('is-select');
getSelectData(function(d) {
getSelectData(function (d) {
if (!!d.couponCode) {
juanText = $('.play-juan input[value="' + d.couponCode + '"]').next().text();
... ... @@ -493,7 +503,7 @@ var Order = {
type: 'POST',
url: '/cart/index/orderCompute',
data: d,
success: function(data) {
success: function (data) {
e.$loading.hide();
... ... @@ -518,7 +528,7 @@ var Order = {
});
// 修改yoho币
$(document).on('click', '.bi-modify', function() {
$(document).on('click', '.bi-modify', function () {
var $pan = $('.play-bi-pan');
... ... @@ -526,7 +536,7 @@ var Order = {
c.winShow($pan);
});
e.$bp.keyup(function() {
e.$bp.keyup(function () {
var val = $(this).val();
... ... @@ -541,7 +551,7 @@ var Order = {
});
// 取消yoho 币
$('.cancel-bi').click(function() {
$('.cancel-bi').click(function () {
var $pan = $('.play-bi-pan');
... ... @@ -553,7 +563,7 @@ var Order = {
e.$loading.show();
getSelectData(function(d) {
getSelectData(function (d) {
d.yohoCoin = 0;
... ... @@ -565,7 +575,7 @@ var Order = {
type: 'POST',
url: '/cart/index/orderCompute',
data: d,
success: function(data) {
success: function (data) {
e.$loading.hide();
... ... @@ -600,7 +610,7 @@ var Order = {
});
// 取消优惠券
$('.cancel-code').click(function() {
$('.cancel-code').click(function () {
var $pan = $('.play-juan-pan');
... ... @@ -608,7 +618,7 @@ var Order = {
e.$loading.show();
getSelectData(function(d) {
getSelectData(function (d) {
d.couponCode = '';
... ... @@ -616,7 +626,7 @@ var Order = {
type: 'POST',
url: '/cart/index/orderCompute',
data: d,
success: function(data) {
success: function (data) {
e.$loading.hide();
... ... @@ -627,7 +637,7 @@ var Order = {
$('.play-juan').removeClass('is-select');
$('#juancode').val('')
.siblings('input[name="juangroup"]').attr('checked', 'checked');
.siblings('input[name="juangroup"]').attr('checked', 'checked');
// $('.use-envelopes input').attr('checked', 'checked');
// $('.red-envelopes').addClass('active');
... ... @@ -649,16 +659,16 @@ var Order = {
// 红包
envelopesVal = e.$useEnvelopesInput.data('all') - e.$useEnvelopesInput.data('use'); // 剩余的红包
e.$hasEnvelopes.text('¥' + envelopesVal.toFixed(2));
e.$useEnvelopes.find('input').click(function() {
e.$useEnvelopes.find('input').click(function () {
var $this = $(this),
juanText;
juanText;
e.$loading.show();
$this.attr('disabled', 'disabled');
getSelectData(function(d) {
getSelectData(function (d) {
if (!!$this.attr('checked')) {
... ... @@ -676,7 +686,7 @@ var Order = {
type: 'POST',
url: '/cart/index/orderCompute',
data: d,
success: function(data) {
success: function (data) {
e.$loading.hide();
if (data.code === 200) {
... ... @@ -709,7 +719,7 @@ var Order = {
var $this = $obj;
$this.keyup(function() {
$this.keyup(function () {
if ($this.val().length > len) {
... ... @@ -740,27 +750,27 @@ address.saveAddress();
//不同订单包裹提示
$('.why').click(function() {
$('.why').click(function () {
$('#differentBag').show();
return false;
});
$('#differentBag').click(function() {
$('#differentBag').click(function () {
return false;
});
$(document).click(function() {
$(document).click(function () {
$('#differentBag').hide();
});
//订单包裹左右切换
function lunBo($pre, $next, $ul, $iWidth) {
var i = 1,
j = 1;
j = 1;
var iSpeed = 0,
isMoving = false;
isMoving = false;
$pre.click(function() {
$pre.click(function () {
if (isMoving) {
return;
}
... ... @@ -774,11 +784,11 @@ function lunBo($pre, $next, $ul, $iWidth) {
}
$ul.stop().animate({
left: iSpeed
}, 300, function() {
}, 300, function () {
isMoving = false;
});
});
$next.click(function() {
$next.click(function () {
var $largeLeft = $ul.parent().width() - $ul.width() + 'px';
if (isMoving) {
... ... @@ -794,7 +804,7 @@ function lunBo($pre, $next, $ul, $iWidth) {
$ul.stop().animate({
left: iSpeed
}, 300, function() {
}, 300, function () {
isMoving = false;
});
});
... ... @@ -803,7 +813,7 @@ function lunBo($pre, $next, $ul, $iWidth) {
//订单分类
$('.bag').find('ul').each(function() {
$('.bag').find('ul').each(function () {
var $pre = $(this).parent().parent().find('.pre');
var $next = $(this).parent().parent().find('.next');
... ...
... ... @@ -847,6 +847,8 @@ class CartModel
$promotionFormulaList[0]['promotion_amount'] = '+ ¥' . Helpers::transPrice($miniAmount);
}
$compute['data']['promotion_formula_list'] = $promotionFormulaList;
//JIT拆单
$compute['packages'] = self::getPackageInfo($compute['data']);
}
$result = $compute;
}
... ...