jquery操作以及ajax异步处理

jquery操作以及ajax异步处理

<script type="text/javascript" >
    $(function(){
        var addFormValilater = $("#addForm").valilater({});
        window.formSubmit = function(thiz){
            addotNull();
            if(addFormValilater.checkPassNull()){
                var $password = $("#password").val();
                if ($password == null || $password === "" || $password.length < 6 ||  $password.length >= 20)
                {
    				$("#password").showErrorMsg("密码在6-20位之间");
    				return;
    			}
               	$("#main-container").mask("提交中··········");
				$.ajax({
                    type: "POST",
                    url: "/rest/basePlatform/savePlatformInfo",
                    data : $("#addForm").serialize(),
                    dataType:"json",
					async: false,
                    success:function(data){
                        if(data.success){
							layer.msg('操作成功', {
                                    icon: 1,
                                    time: 3000
                                },
                                function () {
                                    var channelId = $("#channelId").val();
									var channelType = $("#channelType").val();
                            		location.href="/rest/basePlatform/add?selectBusinessPattern="+channelType +"&channelNameId="+channelId;
                                }
                        	);
							
                        }else{
							alert(data.msg || '操作失败');
							$("#main-container").unmask();
                        }
                    },
                    error:function (XMLHttpRequest, textStatus, errorThrown) {
						alert('服务器正忙,请稍后再试');
						$("#main-container").unmask();
                    }
				});
            }
        };
        jQuery("#submitBtn").bind("click", function(){
            formSubmit(jQuery(this));
        });
        jQuery("#payCourseCode").bind("change", function(){
            $("#payCourse").val("");
            if(""!=$("#payCourseCode").val()) {
                $("#payCourse").val($("#payCourseCode").find("option:selected").text());
            }
        });

        fybm();
        gbhy();
    });
       //动态增加非空校验
        function addotNull(){
            delNotNull();
            //国标品目校验逻辑
            var hidIindustryItemIds=$("input[name='industryItemIds']");
            if(hidIindustryItemIds.length==0){
                $("#selIndustryItemGoods").attr("refType","notNull");
            }else {
                $("#selIndustryItemGoods").removeAttr("refType");
            }
            //根据客户类别 增加非空校验
            if($("#customerCategory").val()==2){
                //客户类别为外部时 支付账号信息必填
                $("#payCompanyName").attr("refType","notNull");
                $("#payCompanyBankName").attr("refType","notNull");
                $("#secondBusinessNum").attr("refType","notNull");
            }else if($("#customerCategory").val()==3){
                //客户类别为金融时 erp、费用科目、字段必填
                $("#erp").attr("refType","notNull");
                $("#payCourseCode").attr("refType","notNull");
                var endPathNames=$("input[name='endPathName']");
                if(endPathNames.length==0){
                    $("#inputDept").attr("refType","notNull");
                }else {
                    $("#inputDept").removeAttr("refType");
                }
            }else {
                //客户类别为集团时 费用部门必填
                var endPathNames=$("input[name='endPathName']");
                if(endPathNames.length==0){
                    $("#inputDept").attr("refType","notNull");
                }else {
                    $("#inputDept").removeAttr("refType");
                }
            }
            //根据平台模式 增加非空校验
            if($("#invoiceModel").val()==1){
               //购买方模式
                $("#buyerName").attr("refType","notNull");
                $("#buyerIdentificationNumber").attr("refType","notNull");
                $("#buyerAddress").attr("refType","notNull");
                $("#buyerPhone").attr("refType","notNull");
                $("#buyerBank").attr("refType","notNull");
                $("#buyerCard").attr("refType","notNull");
            }
        }
        function delNotNull(){
            $("#payCompanyName").removeAttr("refType");
            $("#payCompanyBankName").removeAttr("refType");
            $("#secondBusinessNum").removeAttr("refType");
            $("#erp").removeAttr("refType");
            $("#payCourseCode").removeAttr("refType");
            $("#inputDept").removeAttr("refType");
            $("#buyerName").removeAttr("refType");
            $("#buyerIdentificationNumber").removeAttr("refType");
            $("#buyerAddress").removeAttr("refType");
            $("#buyerPhone").removeAttr("refType");
            $("#buyerBank").removeAttr("refType");
            $("#buyerCard").removeAttr("refType");
            $("#inputDept").val("");
        }
		jQuery("#reBack").bind("click", function(){
			location.href = "/rest/basePlatform/list";
 		});

        $(function(){
            if ("$!{MSG}" != "") {
                alert("$!{MSG}");
            }
        });

        function getCustomerCategory(){
            var bN=$("#buyerName").val();
            var bIN=$("#buyerIdentificationNumber").val();
            jQuery.ajax({
                type: "post",
                url: "/rest/basePlatform/getCustomerCategory?buyerName="+bN+"&buyerIdentificationNumber="+bIN,
                dataType: "json",
                async: false,
                success: function(data) {
                    if(data.success){
                        $("#customerCategorySel").val(data.customerCategory);
                        $("#customerCategory").val(data.customerCategory);
                        $("#jrCompanyCode").val(data.jrCompanyCode);
                        $("#buyerOuId").val(data.buyerOuId);
                    }
                    alert(data.msg);
                }
            });
        }
    //========================= 国标行业开始=========================
    function gbhy() {
        //绑定国标行业下拉框
        $("#selIndustryItemGoods").append("<option value=''>选择要增加的项</option>");
        #foreach($item in $!industryItemGoodsDataList)
            var selValue='$!{item.id}';
            var selText='$!{item.goodsName}_$!{item.industryType}_$!{item.industryDesc}_$!{item.itemsType}_$!{item.itemsDesc}';
            $("#selIndustryItemGoods").append("<option value='"+selValue+"'>"+selText+"</option>");
        #end
        //国标行业初始化
        #foreach($item in $!{basePlatformWebDto.industryItemGoodsList})
            var checkValue='$!{item.id}';
            var checkText='$!{item.goodsName}_$!{item.industryType}_$!{item.industryDesc}_$!{item.itemsType}_$!{item.itemsDesc}';
            addGbhy(checkText,checkValue);
        #end
        //添加国标行业事件
        jQuery("#selIndustryItemGoods").bind("change", function(){
            var checkText=$("#selIndustryItemGoods").find("option:selected").text();
            var checkValue=$("#selIndustryItemGoods").val();
            
            //检查是否存在
            var eles = $("#gbhyTbody").find("input[name=industryItemIds]");
            for (var i=0; i<eles.length; i++) {
            	if(checkValue==$(eles[i]).val()) {
            		alert('重复添加');
            		return;
            	}
            }
            
            addGbhy(checkText,checkValue);
            $("#selIndustryItemGoods").val("");
        });
    }
    //删除国标行业事件
    function delGbhy(obj) {
        jQuery(obj).parents('tr').remove();
    }
    //页面增加国标行业
    function addGbhy(checkTest,checkValue) {
        $("#gbhyTbody").append("<tr>" +
                "<td style='width:90%'><input type='hidden' name='industryItemIds' value='"+checkValue+"'/>"+checkTest+"</td>"+
                "<td style='width:10%'><div class='visible-md visible-lg hidden-sm hidden-xs btn-group'><button οnclick='delGbhy(this)' type='button' class='btn btn-xs btn-danger'><i class='icon-trash bigger-120'></i></button></div></td>"+
                "</tr>");
    }
    //========================= 国标行业结束=========================
    //========================= 费用部门开始=========================
    //费用部门操作
    function fybm() {
        //费用部门初始化
        #foreach($item in $!{basePlatformWebDto.feeDepartmentList})
            var checkText='$!{item.allPathName}';
            var checkValue='$!{item.humanCapitalCode}(#)$!{item.endPathName}(#)$!{item.allPathName}(#)$!{item.allPathNameCode}';
            addFybm(checkValue,checkText);
        #end
    }
    //页面增加费用部门
    function addFybm(checkValue,checkTest) {
        $("#fybmTbody").append("<tr>" +
                "<td><input type='hidden' name='endPathName' value='"+checkValue+"' />"+checkTest+"</td>"+
                "<td><div class='visible-md visible-lg hidden-sm hidden-xs btn-group'><button οnclick='delFybm(this)' type='button' class='btn btn-xs btn-danger'><i class='icon-trash bigger-120'></i></button></div></td>"+
                "</tr>");
    }
    //删除费用部门
    function delFybm(obj) {
        jQuery(obj).parents('tr').remove();
    }

    function deptSearch(obj){
        var deptName = jQuery(obj).val();
        if(deptName.length>0){
            var a = getDeptDate(deptName);
            jQuery(obj).autocomplete({
                source:a,
                minLength: 0,
                select: function( event, ui ) { // 选中某项时执行的操作
                	//检查是否存在
                    var eles = $("#fybmTbody").find("input[name=endPathName]");
                    for (var i=0; i<eles.length; i++) {
                    	if(ui.item.beanStr==$(eles[i]).val()) {
                    		alert('重复添加');
                    		return;
                    	}
                    }
                    addFybm(ui.item.beanStr,ui.item.label);
                    jQuery(obj).val("");
                }
            });
        }
    }
    //搜索费用部门
    function getDeptDate(obj){
        var a = [];
        jQuery.ajax({
            type: "post",
            url: "/rest/basePlatform/listDeptJson?endPathName="+obj,
            dataType: "json",
            async: false,
            success: function(data) {
                if(data !=null){
                    var infoBean = data.infoBean;
                    if(infoBean.resStatus==200){
                        var banddata = data.infoBean.responsebody.organizationVoList;
                        banddata.forEach(function(item){
                            a.push({
                                // 设置item信息
                                label: item.organizationFullname, // 下拉项显示内容
                                value: item.organizationFullname,   // 下拉项对应数值
                                beanStr:item.organizationCode+"(#)"+item.organizationName+"(#)"+item.organizationFullname+"(#)"+item.organizationFullPath,
                            })
                        })
                    }else{
                        alert(infoBean.resMsg);
                    }
                }
            }
        });
        return a;
    }
    //========================= 费用部门结束=========================
</script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章