buy
<script type="text/javascript"> var is_enabled = -1; var checkSubmitFlg = false; var sExFlag = 0; var fhFlag = 0; var shFlag = 0; //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 (); if (!checkSubmitFlg) { checkSubmitFlg = true; } else { alert("双击无效,不能重复提交"); return false; } if (is_enabled == -1) { alert('请先对数据进行校验!'); checkSubmitFlg = false; $("#postscript").focus(); return false; } if (is_enabled != 1) { alert('有错误数据,请调整后再提交!'); checkSubmitFlg = false; return false; } } $("#J_selectEx li").click(function(){ $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 = $this.attr("id"); $("#type_id").val(type_id); if (type_id == '' || type_id == 0) { $("#current_text").html(''); $("#single_price").val(''); } $("#order_nums").val('0'); $("#order_money").val('0'); $.post("/Order-getDetail.html", { 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]); var current_text = return_data.current; var single_price = return_data.price; $("#J_currPrice").html(current_text); $("#single_price").val(single_price); //alert(single_price + "c"); if (status == 'success') { //checkAdressList(); submitCalcAcoumt(); } }, 'json'); //} //checkisnos(); }); function checkAdressList() { addtext = $('#postscript').val(); //是否错误标识 //alert(addtext); 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("<div class='err-notice' >" + "第" + addsum + " 个收货地址格式有错误,请仔细检查!</div>"); goTotop('J_shAddress'); $("#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("<div class='err-notice' >" + "第" + addsum + " 个收货地址格式中省、市、县之间应该用空格隔开,请仔细检查!</div>"); goTotop('J_shAddress'); $("#J_buyAmount").html("0"); $("#J_buyPrice").html("0.00"); is_enabled = 0; return false; }*/ //判断地址之间空格是否是多个 if (exists_multispace(trim(shouhuodizhi))) { $("#J_selectShAddrN").show().html("<div class='err-notice' >" + "第" + addsum + " 个收货地址格式中省、市、县之间只能用一个空格隔开,请仔细检查!</div>"); goTotop('J_shAddress'); $("#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("<div class='err-notice' >" + "第" + adddan[j] + " a1!</div>" ); $("#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; } current_price = parseFloat($('#single_price').val()); if (current_price <= 0) { alert("你选择的快递单价出错!"); return false; } //alert("addsum"); //alert(current_price + "dd"); //计算价格 kuaidisum = addsum * current_price; 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'/>"; $('#J_checkTab').html(table_html); $('#addinputarrs').html(addinputarr); //alert(isno); //alert(addsum +"r"); is_enabled = isno; return (isno); } function calcuAmount() { $("#order_nums").val(addsum); $("#order_money").val(kuaidisum); var yingfuk = kuaidisum.toFixed(2); $('#J_buyAmount').html(addsum); $('#J_buyPrice').html(yingfuk); } function submitCalcAcoumt() { //alert("subm"); var ABCtype_id = $("#type_id").val(); if (ABCtype_id != "") { sExFlag = 1; } var ABCaddress_id = $("#address_id").val(); if (ABCaddress_id != "") { fhFlag = 1; } checkAdressList(); if(sExFlag == 1 && fhFlag == 1 && isno == 1){ calcuAmount(); }else{ $("#J_buyPrice").html("0.00"); } } 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(){ var ABCaddress_id = $("#address_id").val(); if (ABCaddress_id != "") { $("#J_selectSentAddrN").hide(); fhFlag = 1; submitCalcAcoumt(); }else{ $("#J_selectSentAddrN").show(); } }); $("#postscript").bind("keyup paste",function(){ submitCalcAcoumt(); }); </script>