shr.defineClass("shr.customer.gtiit.FixAdjustSalaryEx", shr.cmpdesign.FixAdjustSalary, {

    initalizeDOM:function(){
        shr.customer.gtiit.FixAdjustSalaryEx.superClass.initalizeDOM.call(this);
    },
    initEditDiv: function(){
        $("#fileEdit").hide();
        var _self = this;
        $("#fileEdit").children(":first").append('<input type="hidden" id="id"/><span style="float: right;margin-right:20px;" class="shr-toolbar"><button id="fields_save" type="button" name="fields_save" class="shrbtn-primary shrbtn" onclick="">'
                +jsBizMultLan.cod_fixAdjustSalary_i18n_15
                +'</button><button id="fields_cancel" type="button" name="fields_cancel" class="shrbtn-primary shrbtn" onclick="">'
                +jsBizMultLan.cod_fixAdjustSalary_i18n_12
                +'</button></span>');
        $("#fields_save").click(function(){
            window.Messenger().hideAll();
            if (_self.validate()==false) {
                shr.setIframeHeight();
                return;
            }
            if(!isEditButton){
                return;
            }
            if(_self.moneyError) {
                _self.moneyError = false;
                return;
            }
            //isEditButton = false;
            var config = _self.getEditColumnConfig();
            var param = {
                    adjEmpORelationId: $("#adjEmpORelation").val(),
                    adjHrOrgUnit : shr.getUrlRequestParam("adjustHrOrgId"),
                    personId : shr.getUrlRequestParam("personId"),
                    id: $("#id").val(),
                    serviceId : encodeURIComponent(shr.getServiceId()),
            };
            //校验
            if($('#standard').shrPromptBox("getValue") && $('#standard').shrPromptBox("getValue").id){
                if($.isEmptyObject($('#stdLevel').shrPromptBox("getValue")) || !$('#stdLevel').shrPromptBox("getValue").id){
                    shr.showError({
                        message : jsBizMultLan.cod_fixAdjustSalary_i18n_19,
                    });
                    isEditButton = true;
                    return;
                }
            }
            
            //拼装后台需要参数
            for (var i = 0; i < config.length; i++) {
                var columnConfig = config[i];
                var fieldName = columnConfig.name;
                var fieldId = fieldName.replace(".", "_");
                var $field = $("#" + fieldId);
                var dataType = columnConfig.dataType;
                // 后续如果有枚举类型可以在此添加
                if (dataType == "date") {
                    param[fieldName] = $field.shrDateTimePicker("getValue");
                } else if (dataType == "F7") {
                    var arr = $field.shrPromptBox("getValue");
                    //多选的需要特殊处理
                    if(arr && arr.length > 0){
                        var ids = "";
                        for(var k = 0;k < arr.length;k++){
                            ids += arr[k].id + ",";
                        }
                        ids = ids.substring(0, ids.length - 1);
                        param[fieldName] = ids;
                    }else if(arr && "id" in arr){
                        param[fieldName] = arr.id;
                    }
                } else if(fieldName == "money") {
                    param[fieldName] = $field.shrNumberField('getValue');
                } else if(fieldName == "adjEmpORelation"){
                    param[fieldName] = $field.val();    
                }else if(fieldName == "retroactiveDate"){
                    //追溯发放月份
                    param[fieldName] = $field.shrDateTimePicker("getValue"); 
                }else if(fieldName == "traceability"){
                    //是否追溯  
                    param[fieldName] = $field.val();   
                }else{
                    param[fieldName] = $field.shrTextField("getValue");
                }
            }
            
            if($('#defaultCmpStd').shrPromptBox("getValue")!=null && 'id' in $('#defaultCmpStd').shrPromptBox("getValue")){
                param.defaultCmpStd = $('#defaultCmpStd').shrPromptBox("getValue").id;
            }else{
                param.defaultCmpStd = "";
            }
            
            _self.remoteCall({
                method: "saveEditData",
                param: param, 
                async: false,
                success: function(data) {
                    shr.showInfo({message:jsBizMultLan.cod_fixAdjustSalary_i18n_1});
                    var rowdatas = data.afterSaveData;
                    //清空列表数据
                    waf("#cmpSchemeF7table").clearGridData()
                    for(var i = 0;i < rowdatas.length;i++){
                        waf("#cmpSchemeF7table").wafGrid("addRow",{data:rowdatas[i]});
                    }
                    $("#fileEdit").hide();
                    //删除历史
                    if($("#queryTimeCountDataDiv").length > 0 || $("#queryAllTimeCountDataDiv").length > 0){
                        $("#queryTimeCountDataDiv").remove();
                        $("#queryAllTimeCountDataDiv").remove();
                    }
                    isEditButton = true;
                    shr.setIframeHeight();
                },
                error : function(){
                    isEditButton = true;
                }
            });

            if($("#traceability").val() == "Yes"){
                var effectDay = $("#effectDay").shrDateTimePicker("getValue");
                var retroactiveDate = $("#retroactiveDate").shrDateTimePicker("getValue");
                // 人员id
                var personId = shr.getUrlRequestParam("personId");
                var money = $("#money").val();
                _self.remoteCall({
                    method: "addReviewData",
                    param: {personId:personId,effectDay:effectDay,retroactiveDate:retroactiveDate,money:money}, 
                    success: function(data) {
                        
                    },
                    error : function(){
                        
                    }
                });
            }

        });
        //隐藏编辑
        $("#fields_cancel").click(function(){
            $("#fileEdit").hide();
            shr.setIframeHeight();
        });

        
        $("#traceability").on("change", function () {
            var traceabilityValue = $("#traceability_el").val();
            if(traceabilityValue == "1"){
                _self.getField("retroactiveDate").shrDateTimePicker('option', 'required', true);
            }else{
                _self.getField("retroactiveDate").shrDateTimePicker('option', 'required', false);
            }
        });
    },
    addRowAction:function(){
        //增加权限控制
        $("#money").shrTextField("enable");
        _self = this;
        if($("#queryTimeCountDataDiv").length > 0 || $("#queryAllTimeCountDataDiv").length > 0){
            $("#queryTimeCountDataDiv").remove();
            $("#queryAllTimeCountDataDiv").remove();
        }
        _self.remoteCall({
            method : "checkAddRowPerm",
            param : {
                serviceId : encodeURIComponent(shr.getServiceId()),
            },
            success : function(datas){
                $("#fileEdit").show();
                $("label:contains(jsBizMultLan.cod_fixAdjustSalary_i18n_2)").remove();
                for (var i = 0; i < datas.length; i++) {
                    var data = datas[i];    
                    var fieldName = data.name;
                    var dataType = data.dataType;
                    var fieldId = fieldName.replace(".", "_");
                    
                    if(dataType == "F7"){
                        $('#' + fieldId).shrPromptBox("setValue","");
                    }else if(dataType == "date"){
                        $('#' + fieldId).shrDateTimePicker("setValue","");
                    }else if(dataType == "enum"){
                        $('#' + fieldId).shrSelect("setValue","");
                    }else if('adjEmpORelation' == fieldId){
                        $('#' + fieldId).val("");
                    }else if(fieldName == "retroactiveDate"){
                        //追溯发放月份
                        $("#retroactiveDate").shrDateTimePicker("setValue", ""); 
                    }else if(fieldName == "traceability"){
                        //是否追溯默认为否 
                        $("#traceability").val("No");   
                    }else{
                        $('#' + fieldId).shrTextField("setValue","");
                    }

                    
                }
                //增加默认的发薪业务组织
                $("#payHrOrgUnit").shrPromptBox("setValue",adjustHrOrgUnitF7Val);
                
                //需要追加id
                $("#standard").shrPromptBox("setValue",$("#defaultCmpStd").shrPromptBox("getValue"));
                $('#id').val("");
                $('#adjEmpORelation').val("");
                //默认回填人民币
                $("#currency").shrPromptBox("setValue",{id : _self.initData.currency.id, name : _self.initData.currency.name});
                $("label:contains(jsBizMultLan.cod_fixAdjustSalary_i18n_2)",$("#fileEdit")).remove();
                $("div.required.error",$("#fileEdit")).removeClass("error");
                shr.setIframeHeight();
                //增加默认职位，行政组织
                var adjustEmpORelations = $(window.parent.frames["resume-001"].document).find("div[id^='entry']");
                if(adjustEmpORelations.length>0){
                    var lastLeffectDate =null;
                    var $lastAdjustEmpORelation;
                    for(var i = 0;i <adjustEmpORelations.length;i++){
                        var $adjustEmpORelation = $(adjustEmpORelations[0]);
                        var leffectDateStr = $adjustEmpORelation.find("span[id^='leffectDateentry']")[0].value;
                        var assignType = $adjustEmpORelation.find("span[id^='empOrgRelation_assignType']")[0].value;
                        var leffectDate = new Date(leffectDateStr);
                        if(assignType==1&&(lastLeffectDate == null||leffectDate>lastLeffectDate)){
                            lastLeffectDate = leffectDate;
                            $lastAdjustEmpORelation = $adjustEmpORelation;
                        }
                    }
                    var positionVal =   $adjustEmpORelation.find("span[id^='empOrgRelation_positionentry']")[0];
                    var adminOrgUnit =  $adjustEmpORelation.find("span[id^='empOrgRelation_adminOrg_department']")[0];
                    var adjEmpORelationId=$adjustEmpORelation.find("form[id='form']").find("input[id =id]").val();
                    var lastAdminOrgUnit;
                    if(adminOrgUnit.value){
                        lastAdminOrgUnit = {'adminOrg.id':adminOrgUnit.value,'adminOrg.name':adminOrgUnit.title,'position.id':positionVal.value,'position.name':positionVal.title};
                    }else{
                        var company = $adjustEmpORelation.find("span[id^='empOrgRelation_adminOrg_company']")[0];
                        lastAdminOrgUnit = {'adminOrg.id':company.value,'adminOrg.name':company.title,'position.id':positionVal.value,'position.name':positionVal.title}
                    }
                    $("#adminOrgUnit").shrPromptBox("setValue",lastAdminOrgUnit);
                    $('#adjEmpORelation').val(adjEmpORelationId);
                }
            }
        });
        
    },

    // 编辑时设置初始值
    setInitData: function(rowId) {
        var _self = this;
        _self.remoteCall({
            method: "getFieldEditConfig",
            param: {},
            success: function(datas) {
                if (datas) {
                    var rowDatas = waf("#cmpSchemeF7table").getRowRealData(rowId);
                    $("#fileEdit").show();
                    for (var i = 0; i < datas.length; i++) {
                        var data = datas[i];    
                        var fieldName = data.name;
                        var dataType = data.dataType;
                        var fieldId = fieldName.replace(".", "_");
                        if("adminOrgUnit" == fieldId){
                            $("#adminOrgUnit").shrPromptBox("setValue", {"adminOrg.id" : rowDatas[fieldName].id, "adminOrg.name":rowDatas[fieldName].name});
                        }else if (dataType == "F7") {
                            $("#" + fieldId).shrPromptBox("setValue", rowDatas[fieldName]);
                        } else if(fieldName == 'money') {
                            $("#" + fieldId).shrNumberField("setValue", rowDatas[fieldName]);
                        }else if(fieldName == 'effectDay' || fieldName == 'leffectDay'){
                            $("#" + fieldId).shrDateTimePicker('setValue', rowDatas[fieldName]);
                        } else {
                            $("#" + fieldId).val(rowDatas[fieldName]);  
                        }
                    }
                    if(rowDatas.stdLevel && rowDatas.stdLevel.id && rowDatas.stdPoint && rowDatas.stdPoint.id && isControl){
                        $("#money").shrTextField("disable");
                    }else{
                        $("#money").shrTextField("enable");
                    }
                    if(rowDatas.standard && rowDatas.standard.id && rowDatas.currency){
                        $("#currency").shrPromptBox("disable")
                    }else{
                        $("#currency").shrPromptBox("enable");
                    }
                    //需要追加id
                    $('#id').val(rowDatas.id_add);
                    $('#adjEmpORelation').val(rowDatas.adjEmpORelation);
                    _self.fillRemark(rowDatas.id_add);
                }
                
                shr.setIframeHeight();

                var thisTraceabilityValue = $("#traceability").val();
                if(thisTraceabilityValue == "Yes"){
                    _self.getField("retroactiveDate").shrDateTimePicker('option', 'required', true);
                }
            }
        
        });
    }
});