
shr.defineClass("shr.salaryAdjustmentRoToColumnQueryList",shr.framework.List, {

    reportUipk : "com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBill.billList",
    rowNumPerPage : 20,
    gridId: '#reportGrid',
    colModelData: null,
    isFirstTimeLoad: true ,
    initalizeDOM : function() {
        shr.salaryAdjustmentRoToColumnQueryList.superClass.initalizeDOM.call(this);
        var self = this;
        $("#addNew").remove();
        $("#delete").remove();
        $('#operationDialog').hide();
        this.initalSearch();
        //定时监听 adminOrg的值   用于关闭dialog
        var tValue = $('#closeDialogFlag').attr("value");
        setInterval(function(){
            if(tValue !=$('#closeDialogFlag').attr("value")){
                //这里写自己的业务逻辑代码
                $("#iframe1").dialog('close');
                //tValue = "0";
                $('#closeDialogFlag').attr("value","0");
            }
        },200);

        // 快速查询添加事件
        $('#searcher').shrSearchBar('option', {
            afterSearchClick: this.queryGridByEvent
        });

        //快速过滤展开
        if($(".filter-containers").is(":hidden")){
            $("#filter-slideToggle").click();
        }
    },

    //设置高级查询
    initalSearch : function(){
        $('#grid-toolbar').children().eq(1).append('<div id="searcher" class="pull-right"/>');
        var searcherFields = [];
        searcherFields[0] = {columnName:"name",label:"员工姓名"};
        searcherFields[1] = {columnName:"number",label:"员工编码"};
       /* searcherFields[2] = {columnName:"legalPerson",label:"法人"};
        searcherFields[3] = {columnName:"salaryAdjustReason",label:"调薪原因"};*/

        var options = {
            gridId: "grid",
            // uipk: "com.kingdee.eas.hr.ats.app.AttenceResult.list",
            // query: "" ,
            fields :searcherFields
            // propertiesUrl: shr.getContextPath()+'/dynamic.do?uipk=com.kingdee.eas.hr.ats.app.AttenceResult.list&method=getProperField'
        };

        $("#searcher").shrSearchBar(options);
        //设置其默认的过滤方案
        // var filter = $("#searcher").shrSearchBar('option', 'filterView');
        // if ($.isEmptyObject(filter)) {
        // 	// 如果filter为空
        // 	if (!$.isEmptyObject($("#searcher").shrSearchBar('option', 'defaultViewId'))) {
        // 		// 加载默认过滤方案触发表格取数
        // 		$("#searcher").shrSearchBar('chooseDefaultView');
        // 	}
        // }
    } ,


    queryGridByEvent: function(e) {
        var viewPage;
        var self=this;
        if (e.target) {
            viewPage = shr.getCurrentViewPage(e.target);
        } else {
            viewPage = shr.getCurrentViewPage(e);
        }
        viewPage.queryAction();
    }

    /**
     * 获得search查询条件
     */
    ,getSearchFilterItems: function() {
        var filter = $('#searcher').shrSearchBar('option', 'filterView');
        if (filter && filter.filterItems) {
            return filter.filterItems;
        }
    },



    /**
     * 查询表格
     */
    queryGrid: function() {
        var _self = this;
        var $grid = $(this.gridId);
        _self.setFastFilterMap();
        this.setGridTreeParam();
        this.setGridCustomParam();
        this.setBotpFilterItems($grid);

        this.queryFastFilterGrid();

        // selector
        var selector = this.getSelector();
        if (typeof selector !== 'undefined') {
            $grid.setGridParam({ selector: selector	});
        }
        // filter
        var filterItems = this.getFilterItems();
        $grid.jqGrid("option", "filterItems", filterItems);

        // fastFilter
        var fastFilterItems = this.getFastFilterItems();
        if (fastFilterItems) {
            $grid.jqGrid("option", "fastFilterItems", JSON.stringifyOnce(fastFilterItems));
        }

        //seniorFilter
        var advancedFilter = this.getAdvancedFilterItems();
        if(_self.fastFilterMap && _self.fastFilterMap.fastFilterItems && _self.isReturn){
            advancedFilter = _self.fastFilterMap.fastFilterItems.advancedFilter;
        }
        if(advancedFilter){
            $grid.jqGrid("option", "advancedFilter", JSON.stringify(advancedFilter));
        }else{
            $grid.jqGrid("option", "advancedFilter", null);
        }

        // sorter
        var sorterItems = this.getSorterItems();
        if (sorterItems) {
            $grid.jqGrid("option", "sorterItems", sorterItems);
        }
        var keyField = this.getBillIdFieldName();
        if (keyField) {
            $grid.jqGrid("option", "keyField", keyField);
        }
        // 修改为通过URL取数
        if(!_self.isFirstLoadData){
            $grid.jqGrid('setGridParam', {datatype:'local'});
            $grid.bind("jqGridLoadComplete", function(e, datas){
                $grid.jqGrid('showNoRecords');
            });
            _self.isFirstLoadData = true;
        }else{
            $grid.jqGrid('setGridParam', {datatype:'json'});
        }

        // reload
        $grid.jqGrid("reloadGrid");
        var filtertype = 'normal';
        var filterValue = filterItems;
        if(this.getQuickFilterItems()){
            filtertype = 'QuickFilter';
            filterValue = this.getQuickFilterItems();
        }
        if(this.getCustomFilterItems()){
            filtertype = 'CustomFilter';
            filterValue = this.getCustomFilterItems();
        }
        var text = {id:this.uipk,text:this.title,filtertype:filtertype,filter:filterValue};
        var value = {type:2,msg:text};
        shr.operateLogger(value);
    },




    queryGridByEvent: function(e) {
        var viewPage;
        var self=this;
        if (e.target) {
            viewPage = shr.getCurrentViewPage(e.target);
        } else {
            viewPage = shr.getCurrentViewPage(e);
        }
        // 将页码恢复为第1页
        $(viewPage.gridId).jqGrid('option', 'page', 1);
        viewPage.queryAction();
    },


    queryAction : function () {
        var self = this;
        //快速过滤，过滤字段（精确）：内部管理员工、考勤业务组织、行政组织、时间范围
        var fastFilterItems = self.getFastFilterItems();
        //search搜索框过滤，过滤字段（模糊）：员工编码、员工姓名
        var searchFilterItems = self.getSearchFilterItems();
        if( fastFilterItems == undefined)
            fastFilterItems = "";
        if( searchFilterItems == undefined)
            searchFilterItems = "";
        if(fastFilterItems["add"] == "")
            fastFilterItems["add"] = null;

        if(fastFilterItems.SMT_adminOrg.values==''){
            shr.showWarning({
                message: "请选择行政组织"
            });
            return;
        }
        if(fastFilterItems.SMT_hROrgUnit.values==''){
            shr.showWarning({
                message: "请选择发薪业务组织"
            });
            return;
        }
        if(fastFilterItems.applyDate.values==''){
            shr.showWarning({
                message: "请选择薪资期间"
            });
            return;
        }

        if(fastFilterItems.applyDate.values.startDate==''){
            shr.showWarning({
                message: "请选择开始薪资期间"
            });
            return;
        }

        if(fastFilterItems.applyDate.values.endDate==''){
            shr.showWarning({
                message: "请选择结束薪资期间"
            });
            return;
        }
        if(fastFilterItems.CMP_submitscheme.values==''){
            shr.showWarning({
                message: "请选择定调薪查询方案"
            });
            return;
        }



        //需把视图的filterItem其他条件name="add"改成name="advancedFilter"
        var advancedFilterItems = self.getAdvancedFilterItems();
        if(advancedFilterItems != undefined){
            fastFilterItems["add"] = advancedFilterItems;
        }

        $("#reportGrid").jqGrid('setGridParam', {
            datatype : 'json',
            postData : {
                'fastFilterItems' : encodeURIComponent($.toJSON(fastFilterItems)),
                'searchFilterItems' :encodeURIComponent(searchFilterItems),
                'page1' : 1 //??
            },
            page : 0
        });
//		$("#reportGrid").trigger("reloadGrid");
        self.renderDataGrid(fastFilterItems);
    },

    renderDataGrid : function (fastFilterItems) {
        var self = this,
            serviceId =  shr.getUrlRequestParam("serviceId");
        //submitSchemeId = $submitscheme.data('id');
        self.remoteCall({
            method : "getGridColModel",
            param : {
                serviceId: serviceId,
                fastFilterItems:encodeURIComponent($.toJSON(fastFilterItems))
                //	submitSchemeId: submitSchemeId
            },
            success : function (reponse) {
                self.colModelData = reponse;
                self.doRenderDataGrid(reponse);
            }
        });
    },

    doRenderDataGrid : function () {
        var self = this;
        var reponse = self.colModelData;
        $("#gbox_reportGrid").remove();//强制清除grid容器的html,这个标签在渲染表格后由jqgrid创建的表格最外层标签
        $("#reportGrid").remove();
        $("#gridPager1").remove();
        $("#adv-div-container").after('<div id="gridPager1"></div><table id="reportGrid"></table>');
        table = $("#reportGrid");
        var fastFilterItems = self.getFastFilterItems();
        //search搜索框过滤，
        var searchFilterItems = self.getSearchFilterItems();
        if( fastFilterItems == undefined)
            fastFilterItems = "";
        if( searchFilterItems == undefined)
            searchFilterItems = "";
        if(fastFilterItems["add"] == "")
            fastFilterItems["add"] = null;


        var advancedFilterItems = self.getAdvancedFilterItems();
        if(advancedFilterItems != undefined){
            fastFilterItems["add"] = advancedFilterItems;
        }

        var postData = {
            'fastFilterItems' : encodeURIComponent($.toJSON(fastFilterItems)),
            'searchFilterItems' :encodeURIComponent(searchFilterItems),
            'page1' : 1
        };
        var url = self.getGridDataRequestURL();
        var colNames = reponse.colNames;
        var colModel = reponse.colModel;
        var defaultSortname = reponse.defaultSortname,
            options = {
                url : url ,
                datatype : "json",
                mtype: "POST",
                multiselect : true,
                rownumbers : false,
                colNames : colNames,
                colModel : colModel,
                rowNum : self.rowNumPerPage,
                // pager : '#gridPager1',
                postData: postData ,
//			height : 'auto',
                height : self.rowNumPerPage > 21 ? '590px' : 'auto'  ,
                rowList : [20,40,60],
                recordpos : 'left',
                recordtext : '({0}-{1})/{2}',
                gridview : true,
                shrinkToFit :reponse.colModel.length>10?false:true,
                viewrecords : true,
                sortname : defaultSortname,
                //caption: "Frozen Header",
                customPager : '#gridPager1',
                pagerpos:"center",
                pginputpos:"right",
                pginput:true,
                synchTotal:false,
                onSelectRow: function(id){
                    //		   	onSelectRow : function(id){
                    //屏蔽编辑功能
                    // jQuery('#reportGrid').jqGrid('editRow', id, false, function(){ });

                    if(sidValue.length == 0)
                    {
                        sidValue.push(id);
                        lastsel2 = id;
                        $("#reportGrid").attr("sid", sidValue.join(","));
                    }else{
                        var tempId=true;
                        for(var idArr=0;idArr< sidValue.length;idArr++) {
                            // var idArr=sidValue.split(",");
                            if(sidValue[idArr] == id) {
                                tempId=false;
                            }
                        }
                        if(tempId){
                            sidValue.push(id);
                            lastsel2 = id;
                            $("#reportGrid").attr("sid", sidValue.join(","));
                        }
                    }
                },
                editurl: this.dynamicPage_url+ "?method=editRowData"+"&uipk=" + this.reportUipk

            };
        options.loadComplete = function (data) {
            if($("#gridPager1").html() == "" && "true" == "true"){
                $("#reportGrid").setCustomPager("#gridPager1");
            }
            if (!$("#gridPager1")[0]) {
                var pagerDiv = '<div id="gridPager1"></div>';
                if ($('.editGrid-toolbar')[0]) {
                    $('.editGrid-toolbar').after(pagerDiv);
                } else {
                    //$('#entry_cont').prepend(pagerDiv);
                }
                $("#reportGrid").setCustomPager("#gridPager1");
            }

            shr.setIframeHeight();

            $('#gridPager1_left').click(function(){
                $('.ui-pg-selbox').show();
                //$('.ui-pg-selbox').css({"left":"-40px"})
                $(this).children('.ui-paging-info').hide();
            });
            $("#microToolbar").parent().hide()
            //$("#gridPager1").parent().css({"position":"relative"})
            $("#gbox_reportGrid").css("margin-top","40px");
            $("#gridPager1").addClass("shrPage").css({
                "position":"absolute",
                "top":"35px",
                "right":"0px",
                "background":"#FFF"
            })
            // self.handleMicroToolbarInfo();
            filterItems1  = "" ;
            //jQuery('#reportGrid').jqGrid('setFrozenColumns');
            shr.salaryAdjustmentRoToColumnQueryList.superClass.gridLoadComplete.call(this,data);
            $('.frozen-div').css("top","0");
            $('.frozen-bdiv').css("top","41px");
        };
        // clear table
        table.html();
        table.jqGrid(options).jqGrid("reloadGrid");
        //if(self.isFirstTimeLoad){
        //jQuery('#reportGrid').jqGrid('setFrozenColumns');//只有第一次才设置冻结列
        //}
        self.isFirstTimeLoad = false;


    },

    getGridDataRequestURL : function () {
        return this.dynamicPage_url
            + "?method=getGridData"
            + "&uipk=" + this.reportUipk;
    },

    /**
     * 导出选中
     */
    exportSelectAction:function(){
        var self = this;
        var fieldName = this.getExportFieldName();
        var rowIds = $(this.gridId).getDataIDs();
        var sid = $("#reportGrid").jqGrid("getSelectedRows");
        var Exchange_json = [];
        for (var i = 0;i<sid.length; i++) {
            var item = sid[i];
            var data = $("#reportGrid").jqGrid("getRowData", item);
            Exchange_json.push(data);
        }
        var entrysIdStr = '';
        for(var i = 0;i< Exchange_json.length;i++){
            if(i<Exchange_json.length-1){
                entrysIdStr = entrysIdStr + Exchange_json[i].fid+ ",";
            }else {
                entrysIdStr = entrysIdStr+ Exchange_json[i].fid;
            }
        }
        if (rowIds) {
            //获取搜索框内容
            //快速过滤，过滤字段（精确）：内部管理员工、考勤业务组织、行政组织、时间范围
            var fastFilterItems = self.getFastFilterItems();
            //search搜索框过滤，过滤字段（模糊）：员工编码、员工姓名
            var searchFilterItems = self.getSearchFilterItems();
            if( fastFilterItems == undefined)
                fastFilterItems = "";
            if( searchFilterItems == undefined)
                searchFilterItems = "";
            if(fastFilterItems["add"] == "")
                fastFilterItems["add"] = null;

            //需把视图的filterItem其他条件name="add"改成name="advancedFilter"
            var advancedFilterItems = self.getAdvancedFilterItems();
            if(advancedFilterItems != undefined){
                fastFilterItems["add"] = advancedFilterItems;
            }
            var handler = this.getExportHandler();
            var param = {
                serviceId: shr.getServiceId(),
                fastFilterItems : encodeURIComponent($.toJSON(fastFilterItems)),
                searchFilterItems :encodeURIComponent(searchFilterItems),
                method: "exportAll",
                uipk : this.uipk,
                handler: handler,
                entrysIdStr: entrysIdStr
            }
            url = self.dynamicPage_url;
            document.location.href = shr.appendParam(url,param);

        } else {
            shr.showWarning({
                message: jsBizMultLan.atsManager_attendanceRecordList_i18n_0
            });
        }
    },



    //导出全部
    exportAllAction : function(){
        var self = this;

        //获取搜索框内容
        //快速过滤，过滤字段（精确）：内部管理员工、考勤业务组织、行政组织、时间范围
        var fastFilterItems = self.getFastFilterItems();
        //search搜索框过滤，过滤字段（模糊）：员工编码、员工姓名
        var searchFilterItems = self.getSearchFilterItems();
        if( fastFilterItems == undefined)
            fastFilterItems = "";
        if( searchFilterItems == undefined)
            searchFilterItems = "";
        if(fastFilterItems["add"] == "")
            fastFilterItems["add"] = null;

        //需把视图的filterItem其他条件name="add"改成name="advancedFilter"
        var advancedFilterItems = self.getAdvancedFilterItems();
        if(advancedFilterItems != undefined){
            fastFilterItems["add"] = advancedFilterItems;
        }







        var handler = this.getExportHandler();
        var param = {
            serviceId: shr.getServiceId(),
            fastFilterItems : encodeURIComponent($.toJSON(fastFilterItems)),
            searchFilterItems :encodeURIComponent(searchFilterItems),
            method: "exportAll",
            uipk : this.uipk,
            handler: handler
        }
        var self = this,
            url = self.dynamicPage_url;
        document.location.href = shr.appendParam(url,param);

    },

    getExportHandler: function(){
        return "com.kingdee.shr.compensation.web.handler.integrate.SalaryAdjustmentRowToColumnQueryList";
    },

});
