|
|
/**
|
|
|
* @description: 订单保存
|
|
|
* @time: 2015/12/21
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
* @description: 订单保存
|
|
|
* @time: 2015/12/21
|
|
|
*/
|
|
|
var $ = require('yoho.jquery');
|
|
|
|
|
|
|
|
|
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')
|
|
|
},
|
|
|
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(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>');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
/*初始化价格*/
|
|
|
this.render();
|
|
|
|
|
|
/*点击pan dt 打开dd*/
|
|
|
e.$pan.find('dt').click(function() {
|
|
|
var pan = $(this).parent('dl.pan');
|
|
|
|
|
|
if (pan.find('dd').is(':hidden')) {
|
|
|
c.winShow(pan);
|
|
|
} else {
|
|
|
c.winHide(pan);
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
/*使用优惠卷支付 下面的文本框*/
|
|
|
e.$jc.focus(function() {
|
|
|
$(this).prev('label').prev(':radio').attr('checked', true);
|
|
|
}).change(function() {
|
|
|
$(this).prev('label').prev(':radio').val($(this).val());
|
|
|
});
|
|
|
|
|
|
/*使用YOHO币支付*/
|
|
|
e.$bp.data('tobi', e.$tobi.html());
|
|
|
e.$bp.keyup(function() {
|
|
|
var bi = c.enterNUM($(this).val(), $(this).data('tobi'));
|
|
|
|
|
|
$(this).val(bi);
|
|
|
}).change(function() {
|
|
|
var bi = c.enterNUM($(this).val(), $(this).data('tobi'));
|
|
|
|
|
|
$(this).val(bi);
|
|
|
});
|
|
|
|
|
|
/*取消关闭小窗口*/
|
|
|
e.$cancel.click(function() {
|
|
|
var pan = $(this).parents('.pan');
|
|
|
|
|
|
c.winHide(pan);
|
|
|
});
|
|
|
|
|
|
e.$statistics.slice(3, 5).find('a').click(function() {
|
|
|
var pan = $('.' + $(this).attr('to'));
|
|
|
|
|
|
c.winShow(pan);
|
|
|
});
|
|
|
},
|
|
|
|
|
|
//渲染价格明细
|
|
|
render: function() {
|
|
|
var e = this.e,
|
|
|
d = Order.Data,
|
|
|
c = Order.Common;
|
|
|
var i = 0;
|
|
|
|
|
|
e.$total.html('0.00');
|
|
|
e.$statistics.slice(3, 5).hide();
|
|
|
e.$statistics.slice(0, 5).find('em').html('0.00');
|
|
|
|
|
|
$.each(d, function(key) {
|
|
|
if (d.hasOwnProperty(key)) {
|
|
|
if (d[key]) {
|
|
|
e.$statistics.eq(i).show().find('em').html(c.strFixed(d[key]));
|
|
|
}
|
|
|
}
|
|
|
i++;
|
|
|
});
|
|
|
e.$total.html(c.strFixed(c.calucate()));
|
|
|
|
|
|
}
|
|
|
},
|
|
|
/*公共方法*/
|
|
|
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();
|
|
|
},
|
|
|
strFixed: function(str) {
|
|
|
return parseFloat(str).toFixed(2);
|
|
|
}
|
|
|
},
|
|
|
/*业务逻辑*/
|
|
|
Submit: {
|
|
|
e: {
|
|
|
$juanok: $('#juansubmit'),
|
|
|
$juantip: $('.errtip', '.play-juan-pan'),
|
|
|
$biok: $('#bisubmit')
|
|
|
},
|
|
|
init: function() {
|
|
|
var e = this.e,
|
|
|
d = Order.Data,
|
|
|
c = Order.Common,
|
|
|
u = Order.UI;
|
|
|
var options;
|
|
|
|
|
|
/*点击 优惠卷支付 确认按钮*/
|
|
|
e.$juanok.click(function() {
|
|
|
var $jgroup = $('input[name="juangroup"]:checked');
|
|
|
var pan = $(this).parents('.pan');
|
|
|
|
|
|
if ($jgroup.val()) {
|
|
|
options = {
|
|
|
url: '/Order/save/priceByCode',
|
|
|
type: 'post',
|
|
|
data: {
|
|
|
code: $jgroup.val()
|
|
|
},
|
|
|
success: function(data) {
|
|
|
if (data.code === 200) {
|
|
|
if (data.price) {
|
|
|
d.juan = data.price;
|
|
|
Order.UI.render();
|
|
|
c.winHide(pan);
|
|
|
return;
|
|
|
}
|
|
|
u.render();
|
|
|
}
|
|
|
e.$juantip.html(data.msg);
|
|
|
},
|
|
|
error: function() {
|
|
|
e.$juantip.html('网络出现错误~');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$.ajax(options);
|
|
|
}
|
|
|
});
|
|
|
/*点击 YOHO币支付 确认按钮*/
|
|
|
e.$biok.click(function() {
|
|
|
var pan = $(this).parents('.pan');
|
|
|
|
|
|
d.yohocoin = parseFloat(u.e.$bp.val()) / 100;
|
|
|
u.render();
|
|
|
c.winHide(pan);
|
|
|
return;
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
Order.Data.activity = 0;
|
|
|
Order.Data.carriage = 0;
|
|
|
|
|
|
Order.UI.init();
|
|
|
Order.Submit.init(); |
|
|
\ No newline at end of file |
...
|
...
|
|