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


<script>

    $('.generateLeaveInfoList').css("background-color","#2db7f5")
    $('.generateLeaveInfoList').css("height","35px")
    $('.generateLeaveInfoList span').css("line-height","35px")
    $('.generateLeaveInfoList').css("border-radius","2px")
    $('.generateLeaveInfoList').click(function(){
        //允许继续添加行调用callback，不调用代表阻断添加
        let mainTableData = {
            szjg: WfForm.getFieldValue(WfForm.convertFieldNameToId("szjg")),
            qjr: WfForm.getFieldValue(WfForm.convertFieldNameToId("qjr")),
            jqlx: WfForm.getFieldValue(WfForm.convertFieldNameToId("jqlx")),
            mtcfsdjq: WfForm.getFieldValue(WfForm.convertFieldNameToId("mtcfsdjq")),
            ksrq: WfForm.getFieldValue(WfForm.convertFieldNameToId("ksrq")),
            jsrq: WfForm.getFieldValue(WfForm.convertFieldNameToId("jsrq")),
            kssj: WfForm.getFieldValue(WfForm.convertFieldNameToId("kssj")),
            jssj: WfForm.getFieldValue(WfForm.convertFieldNameToId("jssj")),
            cxjqj: WfForm.getFieldValue(WfForm.convertFieldNameToId("cxjqj")),
            qjsc: WfForm.getFieldValue(WfForm.convertFieldNameToId("qjsc"))
        }

        let detailTableData=[];
        var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
        for(var i=0; i<rowArr.length; i++){
            var rowIndex = rowArr[i];
            if(rowIndex !== ""){
                detailTableData.push({
                    ksrq:WfForm.getFieldValue(WfForm.convertFieldNameToId("ksrq", "detail_1")+"_"+rowIndex),
                    kssj:WfForm.getFieldValue(WfForm.convertFieldNameToId("kssj", "detail_1")+"_"+rowIndex),
                    jsrq:WfForm.getFieldValue(WfForm.convertFieldNameToId("jsrq", "detail_1")+"_"+rowIndex),
                    jssj:WfForm.getFieldValue(WfForm.convertFieldNameToId("jssj", "detail_1")+"_"+rowIndex),
                    qjsc:WfForm.getFieldValue(WfForm.convertFieldNameToId("qjsc", "detail_1")+"_"+rowIndex),
                    qtj:WfForm.getFieldValue(WfForm.convertFieldNameToId("qtj", "detail_1")+"_"+rowIndex),
                    btj:WfForm.getFieldValue(WfForm.convertFieldNameToId("btj", "detail_1")+"_"+rowIndex),
                    cxqj:WfForm.getFieldValue(WfForm.convertFieldNameToId("cxqj", "detail_1")+"_"+rowIndex),
                    cxly:WfForm.getFieldValue(WfForm.convertFieldNameToId("cxly", "detail_1")+"_"+rowIndex),
                    cxid:WfForm.getFieldValue(WfForm.convertFieldNameToId("cxid", "detail_1")+"_"+rowIndex),
                    qjr:WfForm.getFieldValue(WfForm.convertFieldNameToId("qjr", "detail_1")+"_"+rowIndex),
                    qjlx:WfForm.getFieldValue(WfForm.convertFieldNameToId("qjlx", "detail_1")+"_"+rowIndex),
                    jqye:WfForm.getFieldValue(WfForm.convertFieldNameToId("jqye", "detail_1")+"_"+rowIndex),
                })
            }
        }
        let param = {
            mainTableData:JSON.stringify(mainTableData),
            detailTableData:JSON.stringify(detailTableData),
        }
        console.log(param);
        $.ajax({
            url:'/api/attendance/askforleave/generateLeaveInfoList',
            data:param,
            type:'GET',
            dataType:'json',
            async:false,
            success:function(res){
                if(res.api_status){
                    if(res.data.status){
                        let resultData = res.data.data;
                        resultData.filter(item => {
                            let addObj = {}
                            addObj[WfForm.convertFieldNameToId("qjr", "detail_1")] = {value:item.qjr,specialobj:[{id:item.qjr,name:item.qjrName}]};
                            addObj[WfForm.convertFieldNameToId("qjlx", "detail_1")] = {value:item.qjlx,specialobj:[{id:item.qjlx,name:item.qjlxName}]};
                            addObj[WfForm.convertFieldNameToId("ksrq", "detail_1")]={value:item.ksrq}
                            addObj[WfForm.convertFieldNameToId("kssj", "detail_1")]={value:item.kssj}
                            addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")]={value:item.jsrq}
                            addObj[WfForm.convertFieldNameToId("jssj", "detail_1")]={value:item.jssj}
                            addObj[WfForm.convertFieldNameToId("qjsc", "detail_1")]={value:item.qjsc}
                            addObj[WfForm.convertFieldNameToId("qtj", "detail_1")]={value:item.qtj}
                            addObj[WfForm.convertFieldNameToId("btj", "detail_1")]={value:item.btj}
                            addObj[WfForm.convertFieldNameToId("jqye", "detail_1")]={value:item.jqye==undefined?'':item.jqye}

                            WfForm.addDetailRow("detail_1", addObj);
                        })
                    }else{
                        WfForm.showMessage(res.data.errorInfo, 2, 5);
                    }
                }
            }
        })

    })

    //请假方式变更时，同样进行页面显示属性的调整
    WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("cxjqj"),function(obj,id,value){

        resetAttr(value);

    });
    WfForm.registerCheckEvent(WfForm.OPER_SAVE+","+WfForm.OPER_SUBMIT,function(callback){
        let detailNum = WfForm.getDetailRowCount("detail_1")
        if(detailNum > 0){
            callback();
        }else{
            WfForm.showMessage("明细表1没有数据，请点击生成请假按钮", 2, 10);
        }
    });


    resetAttr(WfForm.getFieldValue(WfForm.convertFieldNameToId("cxjqj")))
    /**
     *
     * @param pleavetype 请假方式：0：全天请假；1：按时间区间请假；2：半天；3：按时间长度请假
     */
    function resetAttr(pleavetype) {
        //alert('resetAttr');
        switch (pleavetype){
            case '1'://按时间区间请假
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc"), 4);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("scdw"), 4);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 3);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("jssj"), 3);
                break;
            case '3'://按时间区间请假

                WfForm.changeFieldValue(WfForm.convertFieldNameToId("scdw"),{ value: '1' });//请假时长单位为小时
                //请假时间长度可编辑
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc"), 3);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("scdw"), 1);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 5);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("jssj"), 5);
                //每天请假时长默认为1小时
                WfForm.changeFieldValue(WfForm.convertFieldNameToId("qjsc"),{ value: '1' });
                break;
            default:

                //请假时间长度不可编辑
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc"), 4);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("scdw"), 4);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 5);
                WfForm.changeFieldAttr(WfForm.convertFieldNameToId("jssj"), 5);
                break;
        }
    }

</script>


