Skip to content

Instantly share code, notes, and snippets.

@marcmoore
Last active January 23, 2017 15:42
Show Gist options
  • Save marcmoore/6a72225d609b202ad426bbbac9854eac to your computer and use it in GitHub Desktop.
Save marcmoore/6a72225d609b202ad426bbbac9854eac to your computer and use it in GitHub Desktop.
function submit_Order() {
	//港澳售项目
	var canSubmitFlag=false;
  	var consignee_area = $("#hideAreaIds").val();
  	if(consignee_area!=null){
	  	var consignee_provinceId = consignee_area.split("-")[0];
	  	if(consignee_provinceId==52993){
			//先判断是否有港澳无货标签,如果有港澳无货的,弹框:不支持配送返回购物车提示;再判断是否勾选了同意按钮,没勾选弹框:继续提交提示
			var j=$("body");
			if($(".hknostock").length>0){
				var a=$("#hkmt-box01").html();
				j.dialog({title:"\u63d0\u793a",width:420,height:125,type:"html",source:a});
			}else{
				if($("#hkmtbuy").is(":checked")){
					canSubmitFlag=true;
				}else{
					//弹框 继续提交提示
					var a=$("#hkmt-box02").html();
					var b=j.dialog({
						title:"\u63d0\u793a",
						width:570,
						height:270,
						type:"html",
						source:a,
						onReady:function(){
							$(".agreement-showall").bind("click",function(){
								$(this).parent().addClass("hide"),
								$(this).parent().prev().removeClass("agreement-off").addClass("agreement-on"),
								$(this).closest(".ui-dialog-content").height(390),b.updateMain()})
								}
					});
				}
			}
		}else{
			canSubmitFlag=true;
		}
  	}else{
  		canSubmitFlag=true;
  	}
	if(canSubmitFlag){
		var actionUrl = OrderAppConfig.Domain + "/order/submitOrder.action";
		  var checkcodeTxt = null;
		  var checkCodeRid = null;
		  var payPassword = null;
		  var remark = null;
		  var trackID = null;
		  var mobileForPresale = null;
		  var presalePayType = null;
		  var param = "";
		  // 检查如果存在没保存,则直接弹到锚点
		  if (!$("#submit_check_info_message").is(":hidden")) {
		    var anchor = $("#anchor_info").val();
		    window.location.hash = anchor;
		    return;
		  }
		  // 验证是否输入验证码
		  if (!isEmpty($("#checkCodeDiv").html())) {
		    checkcodeTxt = $("#checkcodeTxt").val();
		    if (isEmpty(checkcodeTxt)) {
		      alert("请先填写验证码!");
		      return;
		    }
		  }
		  // 验证码的随机码
		  if (!isEmpty($("#checkCodeDiv").html())) {
		    checkCodeRid = $("#checkcodeRid").val();
		  }
		  // 验证是否输入支付密码
		  if (!$("#paypasswordPanel").is(":hidden")) {
		    payPassword = $("#txt_paypassword").val();
		    if (isEmpty(payPassword)) {
		      $("#no-pwd-error").show();
		      return;
		    }
		  }

		  // 预售验证手机号
		  if ($("#isPresale").val() == "true") {
		    if ($("#presaleStepPay").val() == "1") {// 全款支付
		      presalePayType = 1;
		    }else if ($("#presaleStepPay").val() == "3") { // 定金支付
		      presalePayType = 2;
		    }else if ($("#presaleStepPay").val() == "5") { // 定金支付
		      presalePayType = 2;
		    }else if ($("#presaleStepPay").val() == "2"||$("#presaleStepPay").val() == "4") {
		      if ($("#AllPayRadio").attr("class") == "presale-payment-item item-selected"){
		        presalePayType = 1;
		      } else {
		        presalePayType = 2;
		      }
		    }
		    if (presalePayType == 2) {// 定金支付必须要手机号码
		      if (check_presaleMobile()) {
		        if ($("#presaleMobile input").size() > 0) {
		          mobileForPresale = $("#presaleMobile input").val();
		          if(mobileForPresale.indexOf("*") > -1){
		            return false;
		          }
		        } else {
		          mobileForPresale = $("#userMobileByPresale").html();
		        }
		      } else {
		        alert("请您先输入有效的预售手机号");
		        return;
		      }
		    }
		    if ($("#presaleEarnest").prop("checked") != true) {
		      alert("请您同意交付定金");
		      return;
		    }
		  }

		  // 获取订单备注
		  if (!isEmpty($("#orderRemarkItem").html())) {
		    remark = $("#remarkText").val();
		    if (remark == "限45个字"){
		      remark = "";
		    }
		    else{
		      if(!is_order_remark_forbid(remark)){alert('订单备注中含有非法字符'); return ;}
		    }
		  }

        /**
         * 电视搭售会员时,提示用户关注不能退货的条款,避免争议
         * 主流程:使用配送方式来识别
         * loc流程:使用商家id和标记位来区分
         */
        if(($(".is-video-loc-ship").length > 0 && $("#agreeNoRefundInMain").val() == "false")
            || ($("#cartVenderIdStr").val() == "613991" && $("#agreeNoRefundInLoc").val() == "false")){
            var a = $("#virtual-box01").html();
            $("body").dialog({
                title: "\u63d0\u793a",
                width: 400,
                type: "html",
                source: a
            })
            return;
        }

  if (!isEmpty(checkcodeTxt)) {
    param = param + "submitOrderParam.checkcodeTxt=" + checkcodeTxt;
  }
    param = param +"&overseaPurchaseCookies="+$("#overseaPurchaseCookies").val();
  if (!isEmpty(checkCodeRid)) {
    param = param + "&submitOrderParam.checkCodeRid=" + checkCodeRid;
  }
  if (!isEmpty(payPassword)) {
    param = param + "&submitOrderParam.payPassword=" + encodeURIComponent(stringToHex(payPassword));
  }
  if (!isEmpty(remark)) {
    param = param + "&submitOrderParam.remark=" + remark;
  }
  if (!isEmpty($("#sopNotPutInvoice").val())) {
    param = param + "&submitOrderParam.sopNotPutInvoice=" + $("#sopNotPutInvoice").val();
  } else {
    param = param + "&submitOrderParam.sopNotPutInvoice=" + false;
  }
  if (!isEmpty(mobileForPresale)) {
    param = param + "&submitOrderParam.presaleMobile=" + mobileForPresale;
  }
  if (null != presalePayType) {
    param = param + "&submitOrderParam.presalePayType=" + presalePayType;
  }
  if (isGiftBuy()) {
    var hidePrice = false;
    if (!$("#giftBuyHidePriceDiv").is(":hidden")) {
      hidePrice = $("#giftBuyHidePrice").is(":checked");
    }
    param = param + "&submitOrderParam.giftBuyHidePrice=" + hidePrice;
  }
  trackID = $("#TrackID").val();
  if (!isEmpty(trackID)) {
    param = param + "&submitOrderParam.trackID=" + trackID;
  }
  var indexFlag = param.substring(0, 1);
  if (indexFlag == "&") {
    param = param.substring(1, param.length);
  }
  param = addFlowTypeParam(param);
  var regionId = $("#regionId").val();
  var shopId = $("#shopId").val();
  if(regionId){
    param += "&regionId=" + regionId;
  }
  if(shopId){
    param += "&shopId=" + shopId;
  }
  var easyBuyFlag = $("#easyBuyFlag").val();
  if(easyBuyFlag == "1"||easyBuyFlag=="2"){
    param += "&ebf=" + easyBuyFlag;
  }
  var ignorePriceChange = $('#ignorePriceChange').val();
  if(ignorePriceChange){
    param += "&submitOrderParam.ignorePriceChange=" + ignorePriceChange;
  }
  var onlinepaytype = $(".payment-item.item-selected").attr('onlinepaytype');
  var paymentId = $(".payment-item.item-selected").attr('payid');
  try{
	  log('ord', 'trade', '20',paymentId+onlinepaytype);
	}catch(e){
	}
  if(onlinepaytype=="1"){
      var lastneedPay=$("#lastneedPay").val();
      var limit = $("#cod_bt").attr("limit");
      if(parseFloat(lastneedPay)>parseFloat(limit)){
    	  showSubmitErrorMessage("亲爱的用户您的白条剩余额度¥"+limit+",请选择其他支付方式!");
    	  return;
      }
	  var baitiaoInfo = $("#baitiaoPayRequest").val();
	  if(!isEmpty(baitiaoInfo)){
		  param += "&" + baitiaoInfo;
	  }
      //如果白条首次还款日期未自动设置(#baitiaoPayRequest中),则使用结算页初始化时的默认值。
	  var baitiaoPayRepayDateInfo = $("#baitiaoPayRepayDateRequest").val();
	  if(!isEmpty(baitiaoPayRepayDateInfo) && param.indexOf("repayDate") < 0){
		  param += "&" + baitiaoPayRepayDateInfo;
	  }
  }
  if($(".payment-item[onlinepaytype=1]").length==0||$(".payment-item[onlinepaytype=1]").hasClass("payment-item-disabled")){
	  param += "&submitOrderParam.btSupport=0";
  }else{
	  param += "&submitOrderParam.btSupport=1";
  }
  if(onlinepaytype=="3"){
	  var card=$("#"+$("#jdpy_cardInfo").val());
	  var cardInfo = card.attr("cardInfo");
	  var cardkey = card.attr("key");
	  if(!isEmpty(cardInfo)){
		  param += "&submitOrderParam.cardInfo=" + cardInfo;
	  }
	  if(!isEmpty(cardkey)){
		  param += "&submitOrderParam.cardkey=" + cardkey;
	  }
	  param += "&submitOrderParam.cardsign=" + card.attr("sign");
	  param += "&submitOrderParam.cardvalid=" + card.attr("valid");
	  param += "&submitOrderParam.cardid=" + card.attr("id");
  }
  var eid = $('#eid').val();
  if(eid){
	param += "&submitOrderParam.eid=" + eid;
  }
  var fp = $('#fp').val();
  if(fp){
	 param += "&submitOrderParam.fp=" + fp;
  }
  var isBestCoupon =$('#isBestCoupon').val();
  if(isBestCoupon){
    param +="&submitOrderParam.isBestCoupon="+isBestCoupon;
  }

		  var submitButtonABTest = $('#submitButtonABTest').val();
		  if(submitButtonABTest && submitButtonABTest == 1){
		    log('ord_abtest','trade_abtest', $('#order-submit').data('data-clkwl'));
		  }
		  // 提交loading
		  $('body').append("<div id='submit_loading' class='purchase-loading'><div class='loading-cont'></div></div>");
		  jQuery.ajax({
		    type : "POST",
		    dataType : "json",
		    url : actionUrl,
		    data : param,
		    cache : false,
		    success : function(result) {
		      // 没有登录跳登录
		      if (isUserNotLogin(result)) {
		        goToLogin();
		        return;
		      }
		      $('#ignorePriceChange').val(0);
		      if (result.success) {
		        // 跳订单中心列表
		    	if(result.payInfo){
		    		$('#direct_pay input[name=orderId]').val(result.payInfo.orderId);
		    		$('#direct_pay input[name=orderType]').val(result.payInfo.orderType);
		    		$('#direct_pay input[name=toType]').val(result.payInfo.toType);
		    		$('#direct_pay input[name=directPayInfoJson]').val(result.payInfo.directPayInfoJson);
		    		$('#direct_pay input[name=payMethod]').val(result.payInfo.payMethod);
		    		$('#direct_pay input[name=key]').val(result.payInfo.key);
		    		 window.setTimeout("$('#direct_pay').submit();",450);
		    		
		    		return;
		    	}
		        if (result.goJumpOrderCenter) {
		          successUrl = OrderAppConfig.Protocol +"order.jd.com/center/list.action";
		          // 等待拆单,定时450毫秒
		          window.setTimeout('window.location.href=successUrl+"?rd="+Math.random();', 450);
		          return;

		        } else {
		          successUrl = "//success.jd.com/success/success.action";
		          window.location.href = successUrl + "?orderId=" + result.orderId + "&rid=" + Math.random();
		          return;
		        }

      } else {
        if (result.message != null) {
          //价格提高
          if(result.resultCode == 600160){
            $("#submit_loading").remove();
            showPriceIncreaseDialog(result.message);
          } else if(result.message.indexOf("支付密码不正确") != -1){
        	  $("#submit_loading").remove();
        	  $("#pwd-error .error-msg").text(result.message);
        	  $("#pwd-error").show();
        	  if($(".sixDigitPassword").val()!=undefined && $(".sixDigitPassword").val().length>0){
        		  resetPaypassword();
        	  }
        	  $("#txt_paypassword").val("");
        	  return;
          }else if (result.message.indexOf("商品无货") != -1 && !isLocBuy()) {
            $("#submit_loading").remove();
            var outSkus = result.noStockSkuIds;
            var resultCode = result.resultCode;
            // 对无货商品的处理
            showSubmitErrorMessage(result.message);
            if (!isEmpty(outSkus)) {
              if (isLipinkaPhysical() || isCarO2OFlow()) {
                return;
              }
              var flowType = $("#flowType").val();
              if((flowType == "" || flowType == 10) && resultCode != 600159){
                doOutSku(outSkus, resultCode,result.addressVO);
              }else{
                window.location.href = cartUrl + '?outSkus=' + outSkus + '&rid=' + Math.random();
                return;
              }
            }
          } else if (result.message.indexOf("收货人信息中的省市县选择有误") != -1) {
            var consigneeId = $("#consignee_id").val();
            //consigneeList(consigneeId);
            $("#submit_loading").remove();
            showSubmitErrorMessage("亲爱的用户,由于地址已经升级,请重新选择!");
          } else if (result.message.indexOf("由于订单金额较大") != -1) {
            $("#submit_loading").remove();
            showSubmitErrorMessage(result.message);
            return;
          } else if (result.message.indexOf("验证码不正确") != -1) {
            $("#submit_loading").remove();
            showSubmitErrorMessage(result.message);
            getNextCheckCode();// 刷新验证码
            return;
          } else if (result.message.indexOf("正在参与预售活动") != -1) {
            var a = result.message.indexOf("您购买的商品");
            var b = result.message.indexOf("正在参与预售活动");
            var outSkus = result.message.substring(a + 6, b);
            if (!isEmpty(outSkus)) {
              var tmpHtml = "";
              var skuList = outSkus.split(",");
              for (var i = 0; i < skuList.length; i++) {
                tmpHtml = tmpHtml + "<a target=\"_parent\" href=\"http://item.jd.com/" + skuList[i] + ".html\">" + skuList[i] + "</a>,";
              }
              tmpHtml = tmpHtml.substring(0, tmpHtml.length - 1);
              result.message = "您购买的商品" + tmpHtml + "正在参与预售活动,请进入商品详情页单独购买";
            }
            $("#submit_loading").remove();
            showSubmitErrorMessage(result.message);
          } else {
            $("#submit_loading").remove();
            showSubmitErrorMessage(result.message);
            return;
          }
        } else {
          $("#submit_loading").remove();
          showSubmitErrorMessage("亲爱的用户请不要频繁点击, 请稍后重试...");
          return;
        }
      }
    },
    error : function(error) {
      $("#submit_loading").remove();
      $('#ignorePriceChange').val(0);
      showSubmitErrorMessage("亲爱的用户请不要频繁点击, 请稍后重试...");
    }
  });
	}
}window.submit_Order = submit_Order;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment