FnaBudgetChgApplySystemBill.jsp 8.29 KB
<%@page import="java.util.UUID"%>
<%@page import="weaver.hrm.HrmUserVarify"%>
<%@page import="weaver.hrm.User"%>
<%@page import="weaver.systeminfo.SystemEnv"%>
<%@page import="weaver.conn.RecordSet"%>
<%@page import="weaver.general.Util"%>
<%@page import="weaver.workflow.field.BrowserComInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%
    String guid1 = UUID.randomUUID().toString();

    User user = HrmUserVarify.getUser (request , response) ;
    if(user==null){
        response.sendRedirect("/notice/noright.jsp") ;
        return ;
    }
%>
<script type="text/javascript" src="/fna/js/e8Common_wev8.js?r=5"></script>
<script type="text/javascript" src="/js/weaver_wev8.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function(){

        //初始化 变更的差额
        initChangeAmount();

        //新预算
        WfForm.bindDetailFieldChangeEvent("field596",function(id,rowIndex,value){
            var tempValue = Number(value);
            if(tempValue < 0){//小于0,置空
                WfForm.changeFieldValue("field596_"+rowIndex,{
                    value:''
                });
            } else {
                changeApplyNumber(rowIndex);
            }
        });

        //审批预算
        WfForm.bindDetailFieldChangeEvent("field597",function(id,rowIndex,value){
            var tempValue = Number(value);
            if(tempValue < 0){//小于0,置空
                WfForm.changeFieldValue("field597_"+rowIndex,{
                    value:''
                });
            } else {
                changeNumber(rowIndex);
            }
        });

        //监听 改变原预算
        WfForm.bindDetailFieldChangeEvent("field681,field589,field590,field591",function(id,rowIndex,value){
            if(checkSameSubject_E9(rowIndex)){
                setRepeatValue(id,rowIndex);
                alert("<%=SystemEnv.getHtmlNoteName(98,user.getLanguage())%>");
            } else {
                getBudget(rowIndex);
            }
        });
    });

    function toFloat(str , def) {
        if(isNaN(parseFloat(str))) return def ;
        else return str ;
    }

    function toInt(str , def) {
        if(isNaN(parseInt(str))) return def ;
        else return str ;
    }

    function _customDelFun0(){  //明细1删除成功后触发事件
        addDelete();
    }

    function _customAddFun0(addIndexStr){      //明细1新增成功后触发事件,addIndexStr即刚新增的行标示,添加多行为(1,2,3)
        //console.log("--------------------",addIndexStr);
    }

    //获取原预算
    function getBudget(index) {
        var budgetperiod = WfForm.getFieldValue("field591"+"_"+index);
        var organizationtype = WfForm.getFieldValue("field681"+"_"+index);
        var organizationid = WfForm.getFieldValue("field589"+"_"+index);
        var subjid = WfForm.getFieldValue("field590"+"_"+index);

        if(subjid!=""&&organizationtype!=""&&organizationid!=""&&budgetperiod!=""){
            var _data = "budgetfeetype="+subjid+"&orgtype="+organizationtype+"&orgid="+organizationid+"&applydate="+budgetperiod;
            jQuery.ajax({
                url : "/workflow/request/BudgetHandlerGetBudgetByDate.jsp",
                type : "post",
                processData : false,
                data : _data,
                dataType : "html",
                success: function do4Success(msg){
                    callback(msg, index);
                }
            });
        }else{
            callback("", index);
        }
    }

    //变更的差额
    function callback(oldBudget, index) {
        WfForm.changeFieldValue("field595_"+index, {
            value: oldBudget
        });

        changeNumber(index);
//        changeApplyNumber(index);
    }

    //审批预算改变
    function changeNumber(index){
        //TD12002 审批预算值大于0时预算差额以审批预算为准计算
        var aproveamount = Number(eval(toFloat(WfForm.getFieldValue("field597_"+index),0)));

        if(aproveamount > 0) {
            changeval = eval(toFloat(WfForm.getFieldValue("field597_"+index),0)) - eval(toFloat(WfForm.getFieldValue("field595_"+index),0));
        } else {
            changeApplyNumber(index);
            return;
        }

        WfForm.changeFieldValue("field598_"+index, {
            value: changeval.toFixed(3)
        });
    }

    //新预算改变
    function changeApplyNumber(index){
        //TD12002 审批预算值大于0时预算差额以审批预算为准计算
        var aproveamount = Number(eval(toFloat(WfForm.getFieldValue("field597_"+index),0)));
        if(aproveamount > 0) {
            changeNumber(index);
            return;
        } else {
            changeval = eval(toFloat(WfForm.getFieldValue("field596_"+index),0)) - eval(toFloat(WfForm.getFieldValue("field595_"+index),0));
        }

        WfForm.changeFieldValue("field598_"+index, {
            value: changeval.toFixed(3)
        });
    }

    //初始化 变更的差额
    function initChangeAmount(){
        //都不为空的时候
            var rowIndexs = WfForm.getDetailAllRowIndexStr("detail_1");
            for(var index = 0;index < rowIndexs.length;index++){
                var budgetperiod = WfForm.getFieldValue("field591"+"_"+index);
                var organizationtype = WfForm.getFieldValue("field681"+"_"+index);
                var organizationid = WfForm.getFieldValue("field589"+"_"+index);
                var subjid = WfForm.getFieldValue("field590"+"_"+index);
                if(subjid != "" && organizationtype != "" && organizationid != "" && budgetperiod != "") {
                    changeNumber(index);
                }
            }
    }

    //检测在相同期间具备相同的值后,将值置空
   function setRepeatValue(fieldId,rowIndex){
//       console.log("fieldId",fieldId);
//       console.log("rowIndex",rowIndex);

        if(fieldId === "field589"){//预算单位
            console.log("预算单位");
            WfForm.changeFieldValue(fieldId + "_" + rowIndex,{
                value: "",
                specialobj:[]
            });

//            WfForm.changeSingleField(fieldId + "_" + rowIndex, {value:""});
        } else if(fieldId === "field590"){//科目
            console.log("科目");
            WfForm.changeFieldValue(fieldId + "_" + rowIndex,{
                value: "",
                specialobj:[
                ]
            });
        } else if(fieldId === "field591"){//预算期间
            console.log("预算期间");
            WfForm.changeFieldValue(fieldId + "_" + rowIndex,{
                value: ""
            });
        }
    }

    //检测是否相同
    function checkSameSubject_E9(index){
        var currentOrgType = WfForm.getFieldValue("field681"+"_"+index);
        var currentOrgId = WfForm.getFieldValue("field589"+"_"+index);
        var currentSubjectValue = WfForm.getFieldValue("field590"+"_"+index);
        var currentBudgetPeriodValue = WfForm.getFieldValue("field591"+"_"+index);

        /*
        console.log("currentOrgType",currentOrgType);
        console.log("currentOrgId",currentOrgId);
        console.log("currentSubjectValue",currentSubjectValue);
        console.log("currentBudgetPeriodValue",currentBudgetPeriodValue);
        */

        var result = false;
        if(currentSubjectValue=='' || currentBudgetPeriodValue=='' || currentOrgType =='' || currentOrgId==''){
            return result;
        }

        var rowIndexs = WfForm.getDetailAllRowIndexStr("detail_1");
        currentBudgetPeriodValue = currentBudgetPeriodValue.substring(0,7);
        for(var i = 0;i < rowIndexs.length ; i++){
            if(i != index ){
                var indexSubjectValue = WfForm.getFieldValue("field590"+"_"+i);
                var indexBudgetPeriodValue = WfForm.getFieldValue("field591"+"_"+i);
                indexBudgetPeriodValue = indexBudgetPeriodValue.substring(0,7);

                var indexOrgType = WfForm.getFieldValue("field681"+"_"+i);
                var indexOrgId = WfForm.getFieldValue("field589"+"_"+i);

                if(currentBudgetPeriodValue == indexBudgetPeriodValue && currentSubjectValue == indexSubjectValue
                        && indexOrgType == currentOrgType && indexOrgId == currentOrgId){
                    result = true;
                    break;
                }
            }
        }
        return result;
    }
</script>