<script type="text/javascript">
var is_enabled = -1;
var checkSubmitFlg = false;
var sExFlag = false;
var fhFlag = false;
var shdFlag = false;
//check ABC
function checkABC () {
var ABCtype_id = $("#type_id").val();
if (ABCtype_id == "") {
//alert("请选择快递!");
goTotop('J_selectEx');
$("#J_selectExN").show();
$("#J_buyPrice").html("0.00");
is_enabled = 0;
return false;
}
var ABCaddress_id = $("#address_id").val();
if (ABCaddress_id == "") {
//alert("请选择发货地址!");
$("#address_id").focus();
$("#J_selectSentAddrN").show();
$("#J_buyPrice").html("0.00");
is_enabled = 0;
return false;
}
var ABCaddtext = $('#postscript').val();
if (ABCaddtext == "") {
//alert("请您填写收货地址!");
//$("#postscript").focus();
goTotop('J_shAddress');
$("#J_selectShAddrN").show();
$("#J_buyPrice").html("0.00");
$("#J_buyAmount").html("0");
is_enabled = 0;
return false;
}
}
// function chk_submit() {
checkABC ();
addtext = $('#postscript').val(); if (!checkSubmitFlg) {
checkSubmitFlg = true;
} else {
alert("双击无效,不能重复提交");
return false;
}
if (is_enabled == -1) {
alert('请先对数据进行校验!');
checkSubmitFlg = false;
$("#postscript").focus();
return false;
}
//alert(isno);
if (is_enabled != 1) {
alert('有错误数据,请调整后再提交!');
checkSubmitFlg = false;
return false;
}
} $("#J_selectEx li").click(function(){
sExFlag = true;
$this = $(this);
$this.addClass("select-current").siblings().removeClass("select-current");
var $exName = $this.text();
$("#J_exName").html($exName.substring(0,4));
$("#J_selectExN").hide();
//$("#J_currPrice").html('');
//$("#single_price").val('');
//var type_id = obj.val();
var type_id = $this.attr("id");
$("#type_id").val(type_id);
if (type_id == '' || type_id == 0) {
// $("#detail").text('');
$("#current_text").html('');
$("#single_price").val('');
}
//对之前已经校验过的数据进行清理add by liq 20140517
//$('#cheisnos').html('');
//$('#cheisnos').css('display', 'none');
//$('#addinputarrs').html('');
$("#order_nums").val('0');
$("#order_money").val('0');
//$('#postscript').val('');
//is_enabled = -1;
//new
//var obj = $('#type_id option').eq(document.getElementById('type_id').selectedIndex);
//var kdtitle = obj.data('title');
//alert(kdtitle);
//
$.post("{:U('getDetail')}", {
id: type_id
}, function(data, status) {
var return_data = data.data;
//alert(return_data.detail);
var datastr = return_data.detail;
var datastrs = new Array();
datastrs = datastr.split("|");
$("#v1").html(datastrs[0]);
$("#v2").html(datastrs[1]);
$("#v3").html(datastrs[2]);
$("#J_exDesc").html(datastrs[4]);
//alert(datastrs[4]);
//var detail = return_data.detail.replace(/\|/gm, "\r\n")
//$("#detail").text(detail);
var current_text = return_data.current;
var single_price = return_data.price;
$("#J_currPrice").html(current_text);
$("#single_price").val(single_price);
}, 'json');
//
//var sfhAddress = $("#address_id").val();
//var sAddress = $('#postscript').val();
//if(sfhAddress !="" && sAddress !=""){
//alert("dd");
setTimeout(function() {
checkisnos();
}, 300); //}
//checkisnos();
}); function checkisnos() {
checkABC ();
addtext = $('#postscript').val();
var current_price = parseFloat($('#single_price').val());
//alert(current_price);
if (current_price <= 0) {
alert("你选择的快递单价出错!");
return false;
}
//是否错误标识
isno = 1;
var addtextarr = new Array();
var adddan = new Array();
addtextarr = addtext.split("\n");
addstr = "";
addinputarr = "";
addsum = 0;
//最多一次只能提交100个
if (addtextarr.length <= 100) {
for (i = 0; i < addtextarr.length; i++) {
if (addtextarr[i] && trim(addtextarr[i]) != '') {
addtextarr[i] = addtextarr[i].replace(/\'/g, "");
addtextarr[i] = addtextarr[i].replace(/\,/g, ",");
addinputarr += "<input type='hidden' name='addinputarr[" + addsum + "]' value='" + addtextarr[i] + "' >";
adddan = trim(addtextarr[i]).split(",");
addsum += 1;
//保存表单数据方便提交
if (adddan.length != 5 && adddan.length != 4) {
$("#J_selectShAddrN").show().html("第" + addsum + " 个收货地址格式有错误,请仔细检查!");
$("#J_buyAmount").html("0");
$("#J_buyPrice").html("0.00");
is_enabled = 0;
return false;
//alert("第" + addsum + " 个收货地址格式有错误,请仔细检查!"); }
if (adddan.length == 5) {
var shouhuodizhi = adddan[3]; //获取收件地址
} else if (adddan.length == 4) {
var shouhuodizhi = adddan[2]; //获取收件地址
}
var shdz_array = trim(shouhuodizhi).split(" ");
if (shdz_array.length < 4) {
$("#J_selectShAddrN").show().html("第" + addsum + " 个收货地址格式中省、市、县之间应该用空格隔开,请仔细检查!");
$("#J_buyAmount").html("0");
$("#J_buyPrice").html("0.00");
is_enabled = 0;
return false; }
//判断地址之间空格是否是多个
if (exists_multispace(trim(shouhuodizhi))) {
$("#J_selectShAddrN").show().html("第" + addsum + " 个收货地址格式中省、市、县之间只能用一个空格隔开,请仔细检查!");
$("#J_buyAmount").html("0");
$("#J_buyPrice").html("0.00");
is_enabled = 0;
return false; }
$("#J_selectShAddrN").hide();
addstr += "<tr><td width='50' class='addyes'>" + addsum + "</td>";
for (j = 0; j < adddan.length; j++) {
//如果不是四个淘宝的逗号格式提示错误
if (adddan.length != 5 && adddan.length != 4) {
//如果有数据就显示 ,没有显示空
if (adddan[j]) {
addstr += "<td class='adderror'>" + adddan[j] + "</td>";
$("#J_selectShAddrN").show().html("第" + adddan[j] + " a1!");
$("#J_buyAmount").html("0");
$("#J_buyPrice").html("0.00");
is_enabled = 0;
return false; } else {
addstr += "<td class='adderror'>" + "</td>";
$("#J_selectShAddrN").show().html("第" + adddan[j] + " a2!");
$("#J_buyAmount").html("0");
$("#J_buyPrice").html("0.00");
is_enabled = 0;
return false; }
} else {
if (adddan.length == 4 && j == 2) {
addstr += "<td class='td-w-" + j + "'>无</td>";
}
if (isno == 0) {
addstr += "<td class='adderror'>" + adddan[j] + "</td>";
$("#J_selectShAddrN").show().html("第" + adddan[j] + " b1!");
$("#J_buyAmount").html("0");
$("#J_buyPrice").html("0.00");
is_enabled = 0;
return false;
} else {
addstr += "<td class='td-w-" + j + "'>" + adddan[j] + "</td>";
}
}
}
addstr += "</tr>";
}
}
} else {
alert("亲,一次最多只能批量下100单,请减少收货地址!");
isno = 0;
}
//计算价格
kuaidisum = addsum * current_price;
//alert(current_price);
$("#order_nums").val(addsum);
$("#order_money").val(kuaidisum);
var table_html = '<div class="ct-address-list"><table cellpadding="0" width="100%"" cellspacing="0"><thead><tr><th width="50"><p>编号</p></th><th width="80"><p>名字</p></th><th width="110"><p>手机</p></th><th width="110"><p>电话</p></th><th><p>地址</p></th><th width="70">邮编</th></tr></thead><tbody>' + addstr + '</tbody></table></div>' + " <input type='hidden' value=" + kuaidisum.toFixed(2) + " name='kuaidipicle' id='kuaidipicle' /><input type='hidden' value='0' name='youyuer' id='youyuer'/>";
//var danjiads = current_price + "元/单 X " + addsum + "单";
var yingfuk = kuaidisum.toFixed(2);
$('#J_buyAmount').html(addsum);
$('#J_buyPrice').html(yingfuk);
$('#opa-bg-color').css('display', 'block');
$('#machine-list-item').css('display', 'block');
$('#J_checkTab').html(table_html);
//$('#cheisnos').css('display', 'none');
$('#addinputarrs').html(addinputarr);
//alert(isno);
is_enabled = isno;
return (isno);
} function trim(str) {
str = str.replace(/^(\s|\u00A0)+/, '');
for (var i = str.length - 1; i >= 0; i--) {
if (/\S/.test(str.charAt(i))) {
str = str.substring(0, i + 1);
break;
}
}
return str;
} function exists_multispace(str) {
var rtn_result = false;
var str_length_old = str.length;
str = str.replace(/\ /g, " ");
var str_length = str.length;
if (str_length_old != str_length) {
rtn_result = true;
}
return rtn_result;
}
//
function goTotop(obj){
var _targetTop = $('#'+obj).offset().top;//获取位置
jQuery("html,body").animate({scrollTop:_targetTop},300);//跳转
}
//
$("#address_id").change(function(){
//alert("dd");
$("#J_selectSentAddrN").hide();
setTimeout(function() {
checkisnos();
}, 300);
});
$("#postscript").bind("keyup paste",function(){
setTimeout(function() {
checkisnos();
}, 300);
});
</script>
<script>
//add address
$('#J_addAddressBtn').click(function(){
$("#J_opacityBg, #J_addAddressMod").show();
});
//
$('#J_closeAddAdrress').click(function(){
$("#J_opacityBg, #J_addAddressMod").hide();
}); var CndnsValidate = {
//检查用户名格式
checkUserName: function (usrName) {
if (!(/^[a-zA-Z\u4e00-\u9fa5]{2,50}$/.test(usrName))) {
return false;
}
else {
return true;
}
},
//检查手机格式
checkMobile: function (mobile) {
var val = mobile;
return /^(0)?((13|14|15|16|17|18)[0-9]\d{8})$/.test(val);
}
} //发货人姓名
$("#name").focus(function () {
$(this).next("label").attr("class", "note-icon-b").text("请填写发货人姓名。").show();
});
$("#name").blur(function () {
$userName = $("#name").val();
if ($.trim($userName) == "" || !CndnsValidate.checkUserName($userName)) {
$(this).next("label").attr("class", "note-icon-b").text("请填写发货人姓名。").show();
return false;
} else {
//没检验用户名是否已经存在
$(this).next("label").attr("class", "note-icon-a").text("发货人姓名格式正确。").show()
}
});
////手机
$("#shouji").focus(function () {
$("#telmSpan").attr("class", "note-icon-b").text("请填写手机/电话号码!").show();
});
$("#shouji").blur(function () {
var usrMbl = $(this).val();
if ($.trim(usrMbl) == "" || !CndnsValidate.checkMobile(usrMbl)) {
$("#telmSpan").attr("class", "note-icon-b").text("请正确填写手机/电话号码").show();
return false;
} else {
$("#telmSpan").attr("class", "note-icon-a").text("手机号码格式正确").show();
}
});
//选择省市区
$("#s_province, #s_city, #s_county").change(function(){
var $s_province = $("#s_province").val();
var $s_city = $("#s_city").val();
var $s_county = $("#s_county").val(); if($s_province != "省份" && $s_city != "地级市" && $s_county != "市、县级市"){
//alert("ddd");
$("#J_selectadr").attr("class", "note-icon-a").text("已选择完整省市区信息!").show();
}else{
//alert("xx");
$("#J_selectadr").attr("class", "note-icon-b").text("未选择完整省市区信息!").show();
}
});
//添加发货地址
function address_submit() {
var $userName = $("#name").val();
var $obj = $("#name");
if ($.trim($userName) == "" || !CndnsValidate.checkUserName($userName)) {
$obj.next("label").attr("class", "note-icon-b").text("请正确填写发货人姓名。").show();
return false;
} var usrMbl = $("#shouji").val();
var $obj = $("#shouji");
if ($.trim(usrMbl) == "" || !CndnsValidate.checkMobile(usrMbl)) {
$("#telmSpan").attr("class", "note-icon-b").text("请正确填写手机号码").show();
return false;
} var $s_province = $("#s_province").val();
var $s_city = $("#s_city").val();
var $s_county = $("#s_county").val();
if($s_province == "省份" || $s_city == "地级市" || $s_county == "市、县级市"){
$(".note-icon-b").show();
return false;
}
var aObj = $("#address_form").serialize();
//alert(aObj);
$.post("{:U('address_save')}", aObj, function(data, status) {
if (status == 'success') {
alert(data.info);
if (data.status == 1) {
//alert(data.status);
//clearForm($("#address_form"));
//重新获取地址信息
$.post("{:U('address_get')}", {}, function(data1, status1) {
alert("ddd");
if (status1 == 'success') {
if (data1.status == 1) {
$("#address_id").html(data1.data);
}
}
}, 'json');
}
} else {
alert('地址新增失败!');
}
}, 'json');
} function clearForm(form){
$(':input', form).each(function() {
var type = this.type;
var tag = this.tagName.toLowerCase(); // normalize case
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = "";
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
}
</script>
<script>
//left-nav 当前状态颜色
$("#J_service li").eq(0).addClass("current");
//商品名称、重量
var $goods_name = $("#goods_name");
var $zhongliang = $("#zhongliang");
$goods_name.focus(function() {
$goods_name.val("");
});
$goods_name.blur(function() {
if ($goods_name.val() == "") {
$goods_name.val("物品");
}
}); $zhongliang.focus(function() {
$zhongliang.val("");
});
$zhongliang.blur(function() {
if ($zhongliang.val() == "") {
$zhongliang.val("1");
}
}); function checkNum(obj) {
//$("#zhongliang").val("");
//检查是否是非数字值
if (isNaN(obj.value)) {
obj.value = "";
}
if (obj != null) {
//检查小数点后是否对于两位
if (obj.value.toString().split(".").length > 1 && obj.value.toString().split(".")[1].length > 2) {
alert("重量不符,请重新输入!");
obj.value = "";
}
}
}
//购买清单
$(window.top).scroll(function() {
if ($(window.top).scrollTop() >= 220) {
$("#J_buyList").css("top", $(window.top).scrollTop() - 195);
} else {
$("#J_buyList").css("top", 30);
}
});
//
$(function(){
$("#J_ctBtn").toggle(function(){
$("#J_ctBtn span").attr("class", "off").text("收起自动检查收货地址");
$("#J_checkTab").slideDown(300);
},function(){
//$subTab.removeClass("height-auto");
$("#J_ctBtn span").attr("class", "on").text("展开自动检查收货地址");
$("#J_checkTab").slideUp(300);
});
});
//
$(".ct-address-list tbody tr td:nth-child(4)").addClass("tdaddr");
</script>

  

04-17 03:16