springmvc和easyui使用ajax前台后台互传数据,假删除提示警告问题。

前台

//删除 多/单条数据
function del(cid){
    var id='';
    if(cid=='-1'){
        if(getSelections().length > 0){
            id=getSelections();
        }else{
            $.messager.alert("提示", "请选择要删除的行", "error");
            return;
        }
    }else{
        id=cid;
    }
     var arr =id.split(":");//分割选中的特卫ID
     for(var i = 0; i < arr.length; i++){
         var delOrder = isConfirmOrder(arr[i]);
     }
}

function isConfirmOrder(id){
    parent.window.$("#loadingImg").css("display","");
     $.ajax({
            url : '/LiveManager/sg/delSpecialguardInfo',//②后台url
            data : {'ids':id,"queryOrder":2},//①向后台传入id参数和queryOrder参数(查询是否有预约)
            type : 'POST',
            dataType : 'json',
            async:true,
            success : function(data) {
                var confirmDelOrder = "0";
                //console.info("data",data);
                if(data.isOrder == 0){//十三:没有预约直接删除,刷新
                    parent.window.$("#loadingImg").css("display","none");
                    $('#tt').datagrid('reload');
                     clearSelections();
                    return;
                } 
                if(data.isOrder == 1){//⑦证明有预约的特位要被删除
                    //⑧提示是否确认删除
                    $.messager.confirm("提示",data.name + "有预约未完成,确认删除?", function (r) {
                        if (r) {
                            parent.window.$("#loadingImg").css("display","");
                            $.ajax({
                                url : '/LiveManager/sg/delSpecialguardInfo',
                                data : {'ids':id,"queryOrder":1},//⑨再次调删除的url,传参数id和queryOrder
                                type : 'POST',
                                dataType : 'json',
                                success : function() {
                                    parent.window.$("#loadingImg").css("display","none");
                                    $('#tt').datagrid('reload');
                                    clearSelections();
                                    $.messager.alert("提示", "操作成功", "success");
                                }
                            });
                          }
                      });
                } 
                parent.window.$("#loadingImg").css("display","none");
                $('#tt').datagrid('reload');
                clearSelections();
            }
      });
}

后台

    @RequestMapping(value="delSpecialguardInfo",method=RequestMethod.POST)
    public void delSpecialguardInfo(HttpServletRequest request,HttpServletResponse response,@RequestParam("ids")String ids,@RequestParam("queryOrder")Integer queryOrder) throws IOException{
        //③接收传过来的参数ids,queryOrder
        Map<String,Object> status=new HashMap<String,Object>();
        if(ids!=null&&!"".equals(ids)){
            boolean boo=false;
            List<String> list=specialguardService.findSgIdFormOrder();
                SpecialguardInfo order=specialguardService.findSpecialguardInfoById(ids);
                boo=list.contains(ids);//判断string变量代表的id号是否在list中,list代表有预约的特位
                if(boo){//④存在预约
                    if(queryOrder == 1){//⑤前边传过来的是2,不执行此if//⑩前段确认删除传过来queryorder=1执行删除
                        order.set_state(0);
                    }
                    specialguardService.save(order);
                    status.put("isOrder", 1);//⑥传参数到前台
                    status.put("name", order.getName());
                    status.put("status", 200);
                    } else {//十一:不存在预约,直接删除
                        order.set_state(0);
                        specialguardService.save(order);
                        status.put("isOrder", 0);//十二:删除后给前台传参数isOrder=0
                        status.put("status", 200);
                    }
            
        }else{
            status.put("status", 201);
        }
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Access-Control-Allow-Methods","GET,POST");
        returnJson(response, status);//记得返回提交数据
    }

 

posted @ 2017-08-03 15:54  云晴  阅读(205)  评论(0编辑  收藏  举报