我的代码片段

var assetListTable = function () {

    var dataTable;
    var zTreeObj;
    var $table = $("#dataTable");
    var zNodes;
   
    var handleRecords = function () {
        dataTable = new Datatable();
        dataTable.init({
            src: $table,
            onQuery:function(data){
                data.assetId=$("#assetIdQuery").val();
                data.assetName=$("#assetNameQuery").val();
                data.assetRole=$("#assetRoleQuery").val();
                data.assetTag=$("#assetTagQuery").val();
            },
            onSortColumn:function (sortColumn, sortDirection) {
                switch (sortColumn) {
                    case "assetId":
                        sortColumn = "asset_id";
                        break;
                    case "assetName":
                        sortColumn = "asset_name";
                        break;
                    case "assetRole":
                        sortColumn="asset_role";
                        break;
                    case"assetTag":
                        sortColumn="asset_tag";
                        break;
                }
                return customGlobal.onSortColumnDefault(sortColumn, sortDirection);
            },
            dataTable: {
                "ajax": {
                    "url": basePath + "asset/getAssetListPage" // ajax source
                },
                "columns": [
                    {data: 'assetId', orderable: false,
                        render: function (data, type, full) {
                            return ' ';
                        }},
                    {data: 'assetId', orderable: true,searchable:true},
                    {data: 'assetName', orderable: true,searchable:true},
                    {data:'className',orderable:true,searchable:true},
                    {data:'abbreviation',orderable:true,searchable:true},
                    {data:'version',orderable:true,searchable:true},
                    {data:'homeUnit',orderable:true,searchable:true},
                    {data:'grade',orderable:true,searchable:true},
                    {data:'person',orderable:true,searchable:true},
                    {data:'user',orderable:true,searchable:true},
                    {data: 'operate', orderable: false,
                        render: function (data, type, full) {////渲染方式设置为table
                            return '查看 编辑';
                         
                        }
                    }
                ]
            }
        });
    };


    function fun(str){
        obj = document.getElementsByName(str);
        check_val = [];
        for(k in obj){
            if(obj[k].checked)
                check_val.push(obj[k].value);
        }
        return check_val;
    }
    
    

    var handleEvent = function(){
        //添加资产
        $("#addAsset").on("click",function(){
            $("#modalTitle").html("添加资产");
            customGlobal.clearFormAndShowDialog("modalDialog");
            zTreeInit();
                rules: {
                    assetId: {
                        required: true
                    }
                    assetName:{
                        required: true
                    }
                }
            $('#roleNameList').select2();
            $('#tagList').select2();
            $("#dialogForm").validate({
            }).resetForm();
            $("#addBtn").show();
        });
        //添加资产后保存
        $("#addBtn").on("click",function(){
            if ($("#dialogForm").validate().form()) {
                customGlobal.blockUI("#modalContent");
                $.ajax({
                    url: "asset/addAsset",
                    data: {
                        assetId: $("#assetId").val(),
                        assetName: $("#assetName").val(),
                        assetRole:$("#className option:selected").val(),
                        assetTag:$("#abbreviation").val(),
                        version:$("#version").val(),
                        homeUnit:$("#homeUnit  option:selected ").val(),
                        grade:$("#grade  option:selected ").val(),
                        
                        //高级信息
                        factoryName: $("#factoryName").val(),
                        buyPrice: $("#buyPrice").val(),
                        buyDate:$("#buyDate  option:selected ").val(),
                        agency: $("#agency").val(),
                        agencyPhone: $("#agencyPhone").val(),
                        person: $("#person").val(),
                        user: $("#user").val(),
                        userPhone: $("#userPhone").val(),
                        remark: $("#remark").val()
                       
                        
                    },
                   // contentType: "application/json; charset=utf-8",
                    type: "post",
                    success: function (data) {
                        if (customGlobal.ajaxCallback(data)) {
                            $("#modalDialog").modal("hide");
                            dataTable.reloadTable();
                        }
                    }
                });
            }
        });

       
        
   
        
        //设置标签
        $("#setTag").on("click",function(){
            $("#modalTitleTag").html("设置标签");
            customGlobal.clearFormAndShowDialog("modalDialogTag");
            zTreeInit();
            rules: {
                userId:{
                    required: true
                }
                userName: {
                    required: true
                }
            }
            $('#tagList1').select2();
            $("#dialogFormTag").validate({

            }).resetForm();
             $("#addTagBtn").hide();
            $("#updateTagBtn").show();
        });
        //保存设置的标签
        $("#updateTagBtn").on("click",function(){
            if ($("#dialogFormTag").validate().form()) {
                customGlobal.blockUI("#modalContentTag");
                $.ajax({
                    url: "asset/setTag",
                    data:{
                        assetId :fun(),
                        assetTag: $("#tagList1 option:selected").val()
                    },
                    type:"post",
                    success: function (data) {
                        if (customGlobal.ajaxCallback(data)) {
                            $("#modalDialogTag").modal("hide");
                            dataTable.reloadTable();
                        }
                    }
                });
            }
        });


       


       
        //查看资产信息
        $table.on("click","a.check",function(){
            //
            $("#modalTitleRole").html("查看资产信息");
            customGlobal.clearFormAndShowDialog("modalDialogRole");
            zTreeInit();
           
            $.ajax({
                url: "xxxxxx" ,
                type: "get",
                success: function (data) {
               
                    $("#assetId").val();
                    $("#assetName").val();
                    $("#className").val();
                    $("#abbreviation").val();
                    $("#version").val();
                    $("#homeUnit").val();
                    $("#grade").val();
                    $("#initGeom").val();
                    
                    
                    $("#Department").val();
                    $("#buyPrice").val();
                    $("#buyDate").val();
                    $("#agency").val();
                    $("#agencyPhone").val();
                    $("#person").val();
                    $("#user").val();
                    $("#userPhone").val();
                    $("#remark").val();
                }
            });
           
            $("#updateBtn").hide();
            //$("#addRoleBtn").show();
           // $("#updateRoleBtn").show();
        });
//编辑资产
      $table.on("click","a.edit",function(){
            
          $("#modalTitleRole").html("编辑资产");
          customGlobal.clearFormAndShowDialog("modalDialogRole");
          zTreeInit();
         
          $.ajax({
              url: "xxxxxx" ,
              type: "get",
              success: function (data) {
             
                  $("#assetId").val();
                  $("#assetName").val();
                  $("#className").val();
                  $("#abbreviation").val();
                  $("#version").val();
                  $("#homeUnit").val();
                  $("#grade").val();
                  $("#initGeom").val();
                  
                  
                  $("#Department").val();
                  $("#buyPrice").val();
                  $("#buyDate").val();
                  $("#agency").val();
                  $("#agencyPhone").val();
                  $("#person").val();
                  $("#user").val();
                  $("#userPhone").val();
                  $("#remark").val();
              }
          });
          $("#updateBtn").show();
       

        });

        //
     
       
       
       
       // 编辑后保存
       
       $("#updateBtn").on("click", function () {
          
      
                 $.ajax({
                   url: "xxxxxxx",
                   dataType: "json",
                   data: JSON.stringify({
                       id:$("#assetId").val(),
                       name:$("#assetName").val(),
                       position:$("#className").val(),
                       tel:$("#abbreviation").val(),
                       email:$("#version").val(),
                       email:$("#homeUnit").val(),
                       email:$("#grade").val(),
                       email:$("#initGeom").val(),
                       
                       email:$("#Department").val(),
                       email:$("#buyPrice").val(),
                       email:$("#buyDate").val(),
                       organId:$("#agency").val(),
                       organId:$("#agencyPhone").val(),
                       organId:$("#person").val(),
                       organId:$("#user").val(),
                       organId:$("#userPhone").val(),
                       organId:$("#remark").val()
                      
                   }),
                   contentType: "application/json; charset=utf-8",
                   type: "put",
                   success: function (data) {
                      
                   }
               })
               
       
       });  
       
       
       
       
       

        
        
      

     

       
    
        
    };
    
    
    //基本信息和高级信息tab切换事件
          
   $(".tab_content").hide();
           $("ul.tabs li:first").addClass("active").show();
           $(".tab_content:first").show();
             
           //点击事件
           $("ul.tabs li").click(function() {
              //
            $("ul.tabs li").removeClass("active");
            $(this).addClass("active");
            $(".tab_content").hide();
            var activeTab = $(this).find("a").attr("href");
            $(activeTab).fadeIn();
            return false;
           });
    
          
           //实验tab页
    function tab(){
    var hdw = $('.tab_title li');
    
    hdw.click(function(){
        
        $(this).addClass('one').siblings().removeClass();
        
        var hdw_index = hdw.index(this);
        
        $('.ct').eq(hdw.index(this)).show().siblings().hide();
        //
    });
    }
    tab();
    
   
          
          
          
    
           
           
           
           
           //日历插件
    //删除
    $("#assetremove").click(function() {
        
    $("input[name='test']:checked").each(function() { // 遍历选中的checkbox
            
           n = $(this).parents("tr").index()+1;  // 获取checkbox所在行的顺序
            $("table#dataTable").find("tr:eq("+n+")").remove();
           
        });
    });
           
           
           


    

    var zTreeInit = function (node){
        node = node == undefined ? zNodes : node;
        zTreeObj = $.fn.zTree.init($("#permissionTree"), {
            check: {
                enable: true
            },
            view: {
                showLine:false
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        }, node);
    };

    return {
        init: function (zTreeNodes) {
            handleRecords();
            handleEvent();
            zNodes = zTreeNodes;
        }
    };
}();
posted @ 2017-07-14 10:14  前端视听  阅读(167)  评论(0编辑  收藏  举报