shr.defineClass("shr.customer.gtiit.AtsOverTimeBillEditEx", shr.ats.AtsOverTimeBillEdit, {

    initalizeDOM:function(){
        shr.customer.gtiit.AtsOverTimeBillEditEx.superClass.initalizeDOM.call(this);
        var that = this ;
        if(that.getOperateState() != 'VIEW'){
            $('#entries_otDate').bind('change',function(){
                var otDate=atsMlUtile.getFieldOriginalValue('entries_otDate');
                $('#entries_startTime').shrDateTimePicker('setValue', otDate);
                $('#entries_endTime').shrDateTimePicker('setValue', otDate);
                that.setOverTimeRemark();
                that.changeWorkType(otDate);
            });
        }
    },
    changeWorkType: function (otDate) {
        var that = this;
        if (!otDate) {
            return;
        }

        _self.remoteCall({
            type:"post",
            async: false,
            method:"workMultiple",
            param:{otDate:otDate},
            success:function(res){
                if(res.otTypeValue){
                    var responseObejct = {id: res.otTypeValue,name: res.otTypeText};
                    $("#entries_otType").shrPromptBox("setValue", responseObejct);
                }
            }
        });
    },
    checkOtDate:function(){
        var otDate = $("#entries_otDate").val();
        otDate  = new Date(otDate);
        const currentDate = new Date();
        const lastMonthDate = new Date(currentDate.getFullYear(), currentDate.getMonth() - 1, currentDate.getDate());
        var lastYear = lastMonthDate.getFullYear();
        var lastMonth = lastMonthDate.getMonth();

        if(otDate.getMonth() != lastMonth || otDate.getFullYear() != lastYear){
            shr.showWarning({message: "当月只能提交加班日期为上个月加班记录"});
            return false;
        }
        return true;
    },

    verify:function(){
        var _self = this ;
        var workArea = _self.getWorkarea();
        $form = $('form', workArea);
        if (!$form.valid()) {
            return false;
        }
        if ( !_self.verifyRestTime(true)) {
            return
        }

        var startTime = atsMlUtile.getFieldOriginalValue("entries_startTime");
        var endTime = atsMlUtile.getFieldOriginalValue("entries_endTime");
        var regEx = new RegExp("\\-","gi"); //i不区分大小写 g匹配所有
        startTime = startTime.replace(regEx,"/");
        endTime = endTime.replace(regEx,"/");
        var startTimeOfDate = new Date(startTime);
        var endTimeOfDate = new Date(endTime);
        var longTime = endTimeOfDate.getTime() - startTimeOfDate.getTime();

        var realstartTime = atsMlUtile.getFieldOriginalValue("entries_realStartTime");
        var realendTime = atsMlUtile.getFieldOriginalValue("entries_realEndTime");
        var realstartTimeOfDate = new Date( realstartTime.replace(regEx,"/") );
        var realendTimeOfDate = new Date( realendTime.replace(regEx,"/") );
        var longTime_real = realendTimeOfDate.getTime() - realstartTimeOfDate.getTime();

        //处理加班日期 与 加班开始时间 和结束时间的日期保持一致
        var overDate = atsMlUtile.getFieldOriginalValue("entries_otDate");
        var overTimeBegin = atsMlUtile.getFieldOriginalValue("entries_startTime");
        overTimeBegin = overTimeBegin.substring(0,10); //2014-01-02 00:00
        var overTimeEnd = atsMlUtile.getFieldOriginalValue("entries_endTime");
        overTimeEnd = overTimeEnd.substring(0,10);

        var overTimeDate = new Date(overDate.replace(regEx,"/"));
        var overTimeStartDate = new Date(overTimeBegin.replace(regEx,"/"));
        var overTimeEndDate = new Date(overTimeEnd.replace(regEx,"/"));

        var otTypeId = "";
        if (_self.getOperateState().toUpperCase() == 'VIEW') {
            otTypeId = $("#entries_otType").val();
        }else {
            otTypeId = $("#entries_otType_el").val();
        }
        if(otTypeId == null || otTypeId == undefined || otTypeId.length == 0){
            shr.showInfo({message: overDate + jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_12});
            return false;
        }

        //检查人员是否有考勤档案
        var isExistsFile = true;
        var personNum = "";
        if("ADDNEW" == this.getOperateState() || "EDIT" == this.getOperateState()){
            personNum = $("#entries_person_number").val()//@
        }else if("VIEW" == this.getOperateState()){
            personNum = $("#entries_person_number").text()//@
        }
        
        if ( overTimeStartDate.getTime() <overTimeDate.getTime()-24*60*60*1000  ) {//longTime_start != 0 &&  longTime_end != 0
            shr.showInfo({message: jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_2});
            return false;
        }
        if ( overTimeEndDate.getTime()-24*60*60*1000  > overTimeDate.getTime() ) {
            shr.showInfo({message: jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_2});
            return false;
        }
        if ( overTimeEndDate.getTime()- overTimeStartDate.getTime() >=2*24*60*60*1000) {
            shr.showInfo({message: jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_2});
            return false;
        }

        if (longTime <= 0) {
            shr.showInfo({message: jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_10});
            return false;
        }else if (longTime_real <= 0) {
            shr.showInfo({message: jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_19});
            return false;
        }else if ($("#entries_otCompens").attr("title")
            ==jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_4 && !_self.isOverMaxQuota()){
            return false;
        }
        var otTime = atsMlUtile.getFieldOriginalValue("entries_applyOTTime");
        if(parseFloat(otTime) < 0){
            shr.showWarning({message:jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_11});
            return false;
        }

        if(parseFloat(otTime) == 0){
            shr.showWarning({message:jsBizMultLan.atsManager_atsOverTimeBillEdit_YM_0001});
            return false;
        }

        var personId = $('#entries_person_el').val();
        if (_self.getOperateState().toUpperCase() == 'VIEW') {
            personId = $('#entries_person').val();
        }
        var flag = true ;
        _self.remoteCall({
            type:"post",
            method:"isCrossShift",
            async: false,
            param:{personId: personId,overDate:overDate,overTimeBegin:atsMlUtile.getFieldOriginalValue("entries_startTime")+":00",overTimeEnd:atsMlUtile.getFieldOriginalValue("entries_endTime")+":00"},
            success:function(res){
                var info =  res;
                if (info.isCrossShift){
                    shr.showWarning({message:jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_42});
                    flag = false ;
                }
            }
        });

        var model = _self.getCurrentModel();

        _self.remoteCall({
            method:"validateIsFillOt",
            param:{model:model},
            async: false,
            success:function(res){
                info =  res;
                if(res.errorString){
                    shr.showError({message:res.errorString});
                    flag = false;
                    // return false;
                }
            }
        });

        _self.remoteCall({
            type:"post",
            method:"isWorkTime",
            async: false,
            param:{personId: personId,overDate:overDate,overTimeBegin:atsMlUtile.getFieldOriginalValue("entries_startTime")+":00",overTimeEnd:atsMlUtile.getFieldOriginalValue("entries_endTime")+":00"},
            success:function(res){
                var info =  res;
                if (info.isWorkTime){
                    shr.showWarning({message:jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_9});
                    flag = false ;
                }
            }
        });
        _self.remoteCall({
            type:"post",
            method:"isAtFixedOverTimeOrExcep",
            async: false,
            param:{personId: personId,overDate:overDate,overTimeBegin:atsMlUtile.getFieldOriginalValue("entries_startTime")+":00",overTimeEnd:atsMlUtile.getFieldOriginalValue("entries_endTime")+":00"},
            success:function(res){
                var info =  res;
                if (info.isAtFixedOverTimeOrExcep){
                    shr.showWarning({message:jsBizMultLan.atsManager_atsOverTimeBillEdit_i18n_1});
                    flag = false ;
                }
            }
        });
        if(_self.isFromWF())
        {
            var model = _self.getCurrentModel();
            _self.remoteCall({
                method:"validateIsFillOt",
                param:{model:model},
                async: false,
                success:function(res){
                    info =  res;
                    if(res.errorString){
                        shr.showError({message:res.errorString});
                        flag = false;
                        // return false;
                    }
                }
            });

            _self.remoteCall({
                method:"validOtStart",
                param:{personId:personId,applyOTTime:otTime},
                async: false,
                success:function(res){
                    info =  res;
                    if(res.info){
                        shr.showError({message:res.info});
                        flag = false ;
                    }
                }
            });
        }
        if(!_self.checkOtDate()){
            return false;
        }
        return flag;
    }

});