<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<script>
    function adddetail() {
        //首先进行必填校验，不通过直接退出
        //if(!WfForm.verifyFormRequired(false, true)){ return; }

        let mainTableData = {
            xjr: WfForm.getFieldValue(WfForm.convertFieldNameToId("xjr")),
            cxqj: WfForm.getFieldValue(WfForm.convertFieldNameToId("cxqj"))
        }

        let param = {
            mainTableData:JSON.stringify(mainTableData),
        }
        console.log(param);
        $.ajax({
            url:'/api/attendance/allowance/getAllowanceRecordList',
            data:param,
            type:'GET',
            dataType:'json',
            async:false,
            success:function(res){
                if(res.api_status){
                    if(res.data.status){
                        WfForm.delDetailRow("detail_1", "all");
                        let resultData = res.data.data;
                        resultData.filter(item => {
                            let addObj = {};
                            addObj[WfForm.convertFieldNameToId("bc", "detail_1")] = {value:item.bc,specialobj:[{id:item.bc,name:item.bcname}]};
                            addObj[WfForm.convertFieldNameToId("jtlx", "detail_1")] = {value:item.jtlx,specialobj:[{id:item.jtlx,name:item.jtlxname}]};
                            addObj[WfForm.convertFieldNameToId("cqjg", "detail_1")] = {value:item.cqjg,specialobj:[{id:item.cqjg,name:item.cqjgSign}]};
                            addObj[WfForm.convertFieldNameToId("rq", "detail_1")]={value:item.rq};
                            addObj[WfForm.convertFieldNameToId("sc", "detail_1")]={value:item.sc};
                            addObj[WfForm.convertFieldNameToId("zt", "detail_1")]={value:item.zt};
                            addObj[WfForm.convertFieldNameToId("sm", "detail_1")]={value:item.sm};
                            addObj[WfForm.convertFieldNameToId("bcbdxx", "detail_1")]={value:item.bcbdxx};
                            addObj[WfForm.convertFieldNameToId("yxdkxx", "detail_1")]={value:item.yxdkxx};
                            addObj[WfForm.convertFieldNameToId("jtid", "detail_1")]={value:item.jtid};

                            WfForm.addDetailRow("detail_1", addObj);
                        })
                    }

                }
            }
        })


    }
    //确认人值变更时，自动生成明细
    WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("xjr"),function(obj,id,value){
        //自动添加出差明细数据
        adddetail();
    });

    //查询区间值变更时，自动生成明细
    WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("cxqj"),function(obj,id,value){
        //自动添加出差明细数据
        adddetail();
    });

</script>






