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

<jsp:useBean id="strUtil" class="weaver.common.StringUtil" scope="page" />
<jsp:useBean id="dateUtil" class="weaver.common.DateUtil" scope="page" />
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="attProcSetManager" class="com.engine.kq.wfset.attendance.manager.HrmAttProcSetManager" scope="page" />
<%

%>

<script >

  jQuery(document).ready(function(){

    try{

        //依据当前请假方式，对页面上的控件显示属性进行调整
        resetAttr(WfForm.getFieldValue(WfForm.convertFieldNameToId("cxjqj")));
        //是否自动产生明细记录标记
        //考虑到影响明细记录的栏位如开始结束日期时间等发生变更时，需要重新生成明细，而请假方式变更时又需要对相应栏位的值做修改，所以添加这个开关，防止重复生成明细记录
        var autodetail = true;

        //假期类别值变更时，自动生成明细
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("jqlx"),function(obj,id,value){
            //alert("jqlx change");
            //关掉自动生成明细记录功能
            autodetail = false;
            detailtTable();
            //自动添加请假明细数据
            adddetail();
            //打开自动生成明细记录功能
            autodetail = true;

        });

        //请假人员值变更时，自动生成明细
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("qjry"),function(obj,id,value){
            //alert("qjry change");
            //关掉自动生成明细记录功能
            autodetail = false;
            //自动添加请假明细数据
            adddetail();
            //打开自动生成明细记录功能
            autodetail = true;
            detailtTable();
        });

        //请假方式变更时，同样进行页面显示属性的调整
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("cxjqj"),function(obj,id,value){
            //alert("cxjqj change");
            //关掉自动生成明细记录功能
            autodetail = false;
            //请假方式变更后，修改页面上的控件显示属性
            resetAttr(value);
            //自动添加请假明细数据
            adddetail();
            //打开自动生成明细记录功能
            autodetail = true;
        });

        //是否每日重复时间段值变更时，自动生成明细
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("mtcfsdjq"),function(obj,id,value){
            //alert("mtcfsdjq change");
            //关掉自动生成明细记录功能
            autodetail = false;
            //自动添加请假明细数据
            adddetail();
            //打开自动生成明细记录功能
            autodetail = true;
        });

        //开始日期变更后，自动重新生成明细
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("ksrq"),function(obj,id,value){
            //alert("ksrq change");
            if (autodetail){
                autodetail = false;
                adddetail();
                autodetail = true;
            }
            detailtTable();
        });

        //结束日期变更后，自动重新生成明细
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("jsrq"),function(obj,id,value){
            //alert("jsrq change");
            if (autodetail){
                autodetail = false;
                adddetail();
                autodetail = true;
            }
            detailtTable();
        });

        //开始时间变更后，自动重新生成明细
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("kssj"),function(obj,id,value){
            //alert("kssj change");
            if (autodetail){
                autodetail = false;
                adddetail();
                autodetail = true;
            }
        });

        //结束时间变更后，自动重新生成明细
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("jssj"),function(obj,id,value){
            //alert("jssj change");
            if (autodetail){
                autodetail = false;
                adddetail();
                autodetail = true;
            }
        });

        //请假时长发生变更后，自动重新生成明细
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("qjsc"),function(obj,id,value){
            //alert("qjsc change");
            if (autodetail){
                autodetail = false;
                adddetail();
                autodetail = true;
            }
        });

        //绑定全天假栏位值变更事件
        WfForm.bindDetailFieldChangeEvent(WfForm.convertFieldNameToId("qtj", "detail_1"),function(id,rowIndex,value){
            //alert('qtj change');
            if (autodetail){
                autodetail = false;
                if (value === '0')
                    WfForm.changeFieldValue(WfForm.convertFieldNameToId("btj", "detail_1")+"_"+rowIndex, {value:"1"});
                else
                    WfForm.changeFieldValue(WfForm.convertFieldNameToId("btj", "detail_1")+"_"+rowIndex, {value:"0"});
                var totalsc = getTotalsc();
                WfForm.changeFieldValue(WfForm.convertFieldNameToId("qjsc"), {value:totalsc});
                autodetail = true;
            }
        });

        //绑定半天假值变更事件
        WfForm.bindDetailFieldChangeEvent(WfForm.convertFieldNameToId("btj", "detail_1"),function(id,rowIndex,value){
            //alert('btj change');
            if (autodetail){
                autodetail = false;
                if (value === '0')
                    WfForm.changeFieldValue(WfForm.convertFieldNameToId("qtj", "detail_1")+"_"+rowIndex, {value:"1"});
                else
                    WfForm.changeFieldValue(WfForm.convertFieldNameToId("qtj", "detail_1")+"_"+rowIndex, {value:"0"});
                var totalsc = getTotalsc();
                WfForm.changeFieldValue(WfForm.convertFieldNameToId("qjsc"), {value:totalsc});
                autodetail = true;
            }
        });

        //绑定请假时长栏位值变更事件
        WfForm.bindDetailFieldChangeEvent(WfForm.convertFieldNameToId("qjsc", "detail_1"),function(id,rowIndex,value){
            //alert('qjsc change');
            if (autodetail){
                autodetail = false;
                var totalsc = getTotalsc();
                WfForm.changeFieldValue(WfForm.convertFieldNameToId("qjsc"), {value:totalsc});
                autodetail = true;
            }
        });
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("ksrq"),function(obj,id,value){
            console.log("WfForm.bindFieldChangeEvent--",obj,id,value);
            detailtTable();
        });
        WfForm.registerCheckEvent(WfForm.OPER_SAVE+","+WfForm.OPER_SUBMIT,function(callback){
            //alert('OPER_SUBMIT');
            let qjry = WfForm.getFieldValue(WfForm.convertFieldNameToId('qjry'));
            let jqlx = WfForm.getFieldValue(WfForm.convertFieldNameToId('jqlx'));
            if (jqlx == '' || jqlx == null || jqlx == undefined){
                return;
            }
            let mainTableData = {
                qjry:qjry,
                jqlx:jqlx
            }
            let detailTableData = [];
            let detailksrqField = WfForm.convertFieldNameToId('ksrq','detail_1');
            var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
            for(var i=0; i<rowArr.length; i++){
                var rowIndex = rowArr[i];
                if(rowIndex !== ""){
                    var fieldMark = detailksrqField+"_"+rowIndex;    //遍历明细行字段
                    detailTableData.push({
                        ksrq:WfForm.getFieldValue(fieldMark)
                    })
                }
            }

            let data = {
                mainTableData:JSON.stringify(mainTableData),
                detailTableData:JSON.stringify(detailTableData)
            }
            console.log(data);
            $.ajax({
                url:'/api/attendance/askforleave/getUesdHolidayItem',
                data:data,
                type:'GET',
                dataType:'json',
                success:function(res){
                    let mark1 = true;
                    console.log(res)
                    if (res.api_status){
                        let data = res.data
                        //实际标记项目
                        WfForm.changeFieldValue(WfForm.convertFieldNameToId("sjqjlx"), {
                            value: data.jqlx,
                            specialobj:[
                                {id:data.jqlx,name:data.mc},
                            ]
                        });
                        if (data.jqlx == undefined){
                            WfForm.changeFieldValue(WfForm.convertFieldNameToId("sjqjlx"), {
                                value: WfForm.getFieldValue(WfForm.convertFieldNameToId('jqlx')),
                                specialobj:[
                                    {id:WfForm.getFieldValue(WfForm.convertFieldNameToId('jqlx')),name:WfForm.getBrowserShowName(WfForm.convertFieldNameToId('jqlx'))},
                                ]
                            });
                        }
                        let hsdw = data.hsdw;

                        if (hsdw == '0'){ //天
                            let cxjqj = WfForm.getFieldValue(WfForm.convertFieldNameToId("cxjqj"));
                            if (cxjqj == '1' || cxjqj == '3'){
                                WfForm.changeFieldValue(WfForm.convertFieldNameToId("cxjqj"), {value:""});
                                WfForm.showMessage("假期核算单位为天只能选择半天或全天", 2, 10);
                                mark1 = false;
                            }
                        }
                        if (data.jcbyxsyqjb == '1'){
                            WfForm.showConfirm("优先使用"+data.mc+"项目的假期余额", function(){
                                if (mark1){
                                    callback();
                                }else {
                                    WfForm.showMessage("假期核算单位为天只能选择半天或全天", 2, 10);
                                }
                            },function (){
                                if (mark1){
                                    callback();
                                }else {
                                    WfForm.showMessage("假期核算单位为天只能选择半天或全天", 2, 10);
                                }
                            });
                        }else {
                            if (mark1){
                                callback();
                            }else {
                                WfForm.showMessage("假期核算单位为天只能选择半天或全天", 2, 10);
                            }
                        }
                    }else {
                        WfForm.showMessage(res.errormsg, 2, 10);
                    }
                }
            })
        });

    }catch (e) {
    }
  });

  /**
   *
   * @param pleavetype 请假方式：0：全天请假；1：按时间区间请假；2：半天；3：按时间长度请假
   */
  function resetAttr(pleavetype) {
      //alert('resetAttr');
      switch (pleavetype){
          case '1'://按时间区间请假
              WfForm.changeFieldValue(WfForm.convertFieldNameToId("scdw"),{ value: '1' });//请假时长单位为小时
              //请假开始时间可编辑
              WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 3);
              //请假结束时间可编辑
              WfForm.changeFieldAttr(WfForm.convertFieldNameToId("jssj"), 3);
              //请假时间长度不可编辑
              WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc"), 1);
              break;
          case '3'://按时间区间请假
              WfForm.changeFieldValue(WfForm.convertFieldNameToId("scdw"),{ value: '1' });//请假时长单位为小时
              //隐藏请假开始时间所在行（结束时间在同一行，不需要额外设置）
              WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 5);
              //请假时间长度可编辑
              WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc"), 3);
              //每天请假时长默认为1小时
              WfForm.changeFieldValue(WfForm.convertFieldNameToId("qjsc"),{ value: '1' });
              break;
          default:
              WfForm.changeFieldValue(WfForm.convertFieldNameToId("scdw"),{ value: '0' });//请假时长单位为小时
              //隐藏请假开始时间所在行（结束时间在同一行，不需要额外设置）
              WfForm.changeFieldAttr(WfForm.convertFieldNameToId("kssj"), 5);
              //请假时间长度不可编辑
              WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc"), 1);
              break;
      }
  }

  /**
   * 自动添加请假明细
   */
  function adddetail() {
      //alert('adddetail');
      //首先进行必填校验，不通过直接退出
      if(!WfForm.verifyFormRequired(false, true)){ return; }
      //获取请假时段类型：0：全天；1：指定时间区间；2：半天；3：指定时长长度
      let ccsd = WfForm.getFieldValue(WfForm.convertFieldNameToId("cxjqj"));
      //每天同时段请假，1:是，0：否
      let mttsdcc = WfForm.getFieldValue(WfForm.convertFieldNameToId("mtcfsdjq"));
      //开始日期
      var ksrq = new Date(WfForm.getFieldValue(WfForm.convertFieldNameToId("ksrq")));
      //结束日期
      var jsrq = new Date(WfForm.getFieldValue(WfForm.convertFieldNameToId("jsrq")));
      //开始时间
      var kssj = WfForm.getFieldValue(WfForm.convertFieldNameToId("kssj"));
      //结束时间
      let jssj = WfForm.getFieldValue(WfForm.convertFieldNameToId("jssj"));
      //请假时长
      var qjsc = WfForm.getFieldValue(WfForm.convertFieldNameToId("qjsc"));
      //实际请假类型
      var sjqjlx = WfForm.getFieldValue(WfForm.convertFieldNameToId("sjqjlx"));
      //实际请假类型
      var qjry = WfForm.getFieldValue(WfForm.convertFieldNameToId("qjry"));
      //清空第一明细所有记录
      WfForm.delDetailRow("detail_1", "all");
      //判断请假是否跨天
      let v_overzero = jssj < kssj ? true : false;
      //预置明细记录开始日期
      var v_tmpbdate = new Date(ksrq);
      //预置明细记录结束日期
      var v_tmpedate = new Date(v_tmpbdate);
      let param = {
          itemId:sjqjlx,
          userId:qjry,
          startDate:ksrq,
          endDate:jsrq
      }
      debugger;
      let dateList=undefined;
      $.ajax({
          url:"/api/attendance/askforleave/getRestDayInterval",
          type:"GET",
          data:param,
          dataType:"json",
          async:false,
          success:function(res){
              console.log(res)
              if (res.api_status){
                  dateList = res.data.data;
              }

          }
      })

      if (mttsdcc == '1') {
          //首次循环时，明细开始与结束日期均等于主表开始日期，而主表结束日期一定大于等于开始日期，所以至少添加一笔明细
          //当请假为跨天假时，每笔明细的结束日期会加一天
          while(v_tmpedate <= jsrq && v_tmpedate <= jsrq){
              //初始化明细记录
              var addObj = {};
              //添加开始日期字段信息
              let rqlx = "";
              let beginDate = v_tmpbdate.toString();
              if (dateList != undefined){
                  dateList.filter(item => {
                      if (item.rq == beginDate){
                          rqlx = item.rqlx;
                      }
                  });
              }
              if (rqlx == "1" || rqlx=="2" || rqlx=="3"){
                  //明细开始日期加一天
                  v_tmpbdate = v_tmpbdate.setDate(v_tmpbdate.getDate() + 1);
                  v_tmpbdate = new Date(v_tmpbdate);
                  //明细结束日期加一天
                  v_tmpedate = v_tmpedate.setDate(v_tmpedate.getDate() + 1);
                  v_tmpedate = new Date(v_tmpedate);
                  continue;
              }
              addObj[WfForm.convertFieldNameToId("ksrq", "detail_1")] = {value:v_tmpbdate};
              if (ccsd === '1'){
                  //按时间区间请假逻辑
                  if (v_overzero){
                      //跨天时，明细记录的结束日期等于开始日期加一天
                      v_tmpedate = v_tmpedate.setDate(v_tmpbdate.getDate() + 1);
                      v_tmpedate = new Date(v_tmpedate);
                  }
                  //添加结束日期字段信息
                  addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:v_tmpedate};
                  //添加开始时间字段信息
                  addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:kssj};
                  //添加结束时间字段信息
                  addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:jssj};
                  //todo 调用接口计算开始结束时间区间内的工作时长；
                  //暂时先不调用接口，直接使用开始结束时间区间间隔小时数
                  var v_hours = (new Date(v_tmpedate+" "+jssj).getTime() - new Date(v_tmpbdate+" "+kssj).getTime())/(1000 * 60 * 60);
                  //超过8小时，以8小时计
                  v_hours = Number(v_hours) > 8 ? 8 : Number(v_hours)
                  addObj[WfForm.convertFieldNameToId("qjsc", "detail_1")] = {value:v_hours};
              }else{
                  //按时间长度请假或者全天、半天请假逻辑，
                  //此三种情况系统只需要知道员工当天班次上是希望请假的小数数或者是全天还是半天请假即可，与结束日期，开始及结束时间没有关系，所以相应的值均设置为空
                  //添加结束日期字段信息
                  addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:''};
                  //添加开始时间字段信息
                  addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:''};
                  //添加结束时间字段信息
                  addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:''};
                  if (ccsd == '0'){
                      //全天请假时，全天的标记打开
                      addObj[WfForm.convertFieldNameToId("qtj", "detail_1")] = {value:'1'};
                  }else if (ccsd == '2') {
                      //半天请假时，半天的标记打开
                      addObj[WfForm.convertFieldNameToId("btj", "detail_1")] = {value:'1'};
                  }else if (ccsd == '3'){
                      //按小数数请假时，将主表上的总请假时长当成每天请假时长进行赋值
                      addObj[WfForm.convertFieldNameToId("qjsc", "detail_1")] = {value:qjsc};
                  }
              }
              //追加明细记录
              WfForm.addDetailRow("detail_1", addObj);
              //明细开始日期加一天
              v_tmpbdate = v_tmpbdate.setDate(v_tmpbdate.getDate() + 1);
              v_tmpbdate = new Date(v_tmpbdate);
              //明细结束日期加一天
              v_tmpedate = v_tmpedate.setDate(v_tmpedate.getDate() + 1);
              v_tmpedate = new Date(v_tmpedate);
          }
      }else{
          //非每天同时段请假方式请假
          //设置第一笔明细结束日期为请假开始日期加一天
          v_tmpedate = v_tmpedate.setDate(v_tmpedate.getDate() + 1);
          v_tmpedate = new Date(v_tmpedate);
          while (v_tmpedate <= jsrq) {
              var addObj = {};
              addObj[WfForm.convertFieldNameToId("ksrq", "detail_1")] = {value:v_tmpbdate};
              if (ccsd === '1'){
                  addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:v_tmpedate};
                  addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:kssj};
                  addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:"00:00"};
              }else{
                  addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:''};
                  addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:''};
                  addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:''};
                  if (ccsd == '0'){
                      addObj[WfForm.convertFieldNameToId("qtj", "detail_1")] = {value:'1'};
                      addObj[WfForm.convertFieldNameToId("btj", "detail_1")] = {value:'0'};
                  }else{
                      addObj[WfForm.convertFieldNameToId("qtj", "detail_1")] = {value:'0'};
                      addObj[WfForm.convertFieldNameToId("btj", "detail_1")] = {value:'1'};
                  }
              }
              //追加明细记录
              WfForm.addDetailRow("detail_1", addObj);
              v_tmpbdate = new Date(v_tmpedate);
              kssj = '00:00';
              //明细结束日期加一天
              v_tmpedate = v_tmpedate.setDate(v_tmpedate.getDate() + 1);
              v_tmpedate = new Date(v_tmpedate);
          }
          var addObj = {};
          addObj[WfForm.convertFieldNameToId("ksrq", "detail_1")] = {value:v_tmpbdate};
          if (ccsd === '1'){
              addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:jsrq};
              addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:kssj};
              addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:jssj};
          }else{
              addObj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:''};
              addObj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:''};
              addObj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:''};
              if (ccsd == '0')
                  addObj[WfForm.convertFieldNameToId("qtj", "detail_1")] = {value:'1'};
              else
                  addObj[WfForm.convertFieldNameToId("btj", "detail_1")] = {value:'1'};
          }
          //追加明细记录
          WfForm.addDetailRow("detail_1", addObj);
      }
      //添加完明细后，更新主表的总请假时长栏位信息
      var totalsc = getTotalsc();
      WfForm.changeFieldValue(WfForm.convertFieldNameToId("qjsc"), {value:totalsc});
      //控制明细显示属性
      var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
      for(var i=0; i<rowArr.length; i++){
          var rowIndex = rowArr[i];
          if(rowIndex !== ""){
              switch(ccsd){
                  case '1'://按时间区间请假
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc","detail_1")+"_"+rowIndex, 1);//请假时长栏位设置只读
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qtj","detail_1")+"_"+rowIndex, 1);//全天假栏位设置只读
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("btj","detail_1")+"_"+rowIndex, 1);//半天假栏位设置只读
                      break;
                  case '3'://按时间长度请假
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc","detail_1")+"_"+rowIndex, 3);//请假时长栏位设置必填
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qtj","detail_1")+"_"+rowIndex, 1);//全天假栏位设置只读
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("btj","detail_1")+"_"+rowIndex, 1);//半天假栏位设置只读
                      break;
                  default://其他全天或者半天请假
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qjsc","detail_1")+"_"+rowIndex, 1);//请假时长栏位设置只读
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("qtj","detail_1")+"_"+rowIndex, 2);//全天假栏位设置可编辑
                      WfForm.changeFieldAttr(WfForm.convertFieldNameToId("btj","detail_1")+"_"+rowIndex, 2);//半天假栏位设置可编辑
                      break;
              }
          }
      }
  }

  /**
   * 计算明细总请假长度
   */
  function getTotalsc(){
      //alert('getTotalsc');
      var ccsd = WfForm.getFieldValue(WfForm.convertFieldNameToId("cxjqj"));
      var totalsc = 0;
      var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
      for(var i=0; i<rowArr.length; i++){
          var rowIndex = rowArr[i];
          if(rowIndex !== ""){
              if (ccsd == '3' || ccsd == '1')//累计小时时长
                  totalsc = Number(totalsc) + Number(WfForm.getFieldValue(WfForm.convertFieldNameToId("qjsc", "detail_1")+"_"+rowIndex));
              else{
                  //累计天数时长
                  totalsc = Number(totalsc) +
                      Number(WfForm.getFieldValue(WfForm.convertFieldNameToId("qtj", "detail_1")+"_"+rowIndex)) +
                      Number(WfForm.getFieldValue(WfForm.convertFieldNameToId("btj", "detail_1")+"_"+rowIndex)) * 0.5;
              }
          }
      }
      return totalsc;
  }

  function detailtTable(){
      let qjry = WfForm.getFieldValue(WfForm.convertFieldNameToId('qjry'));
      let jqlx = WfForm.getFieldValue(WfForm.convertFieldNameToId('jqlx'));
      if (jqlx == '' || jqlx == null || jqlx == undefined){
          return;
      }
      let mainTableData = {
          qjry:qjry,
          jqlx:jqlx
      }
      let detailTableData = [];
      let detailksrqField = WfForm.convertFieldNameToId('ksrq','detail_1');
      var rowArr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
      for(var i=0; i<rowArr.length; i++){
          var rowIndex = rowArr[i];
          if(rowIndex !== ""){
              var fieldMark = detailksrqField+"_"+rowIndex;    //遍历明细行字段
              detailTableData.push({
                  ksrq:WfForm.getFieldValue(fieldMark)
              })
          }
      }

      let data = {
          mainTableData:JSON.stringify(mainTableData),
          detailTableData:JSON.stringify(detailTableData)
      }
      console.log(data);
      $.ajax({
          url:'/api/attendance/askforleave/getUesdHolidayItem',
          data:data,
          type:'GET',
          dataType:'json',
          async:false,
          success:function(res){
              console.log(res)
              if (res.api_status){
                  let data = res.data
                  //实际标记项目
                  WfForm.changeFieldValue(WfForm.convertFieldNameToId("sjqjlx"), {
                      value: data.jqlx,
                      specialobj:[
                          {id:data.jqlx,name:data.mc},
                      ]
                  });
                  if (data.jqlx == undefined){
                      WfForm.changeFieldValue(WfForm.convertFieldNameToId("sjqjlx"), {
                          value: WfForm.getFieldValue(WfForm.convertFieldNameToId('jqlx')),
                          specialobj:[
                              {id:WfForm.getFieldValue(WfForm.convertFieldNameToId('jqlx')),name:WfForm.getBrowserShowName(WfForm.convertFieldNameToId('jqlx'))},
                          ]
                      });
                  }
                  let hsdw = data.hsdw;

                  if (hsdw == '0'){ //天
                      let cxjqj = WfForm.getFieldValue(WfForm.convertFieldNameToId("cxjqj"));
                      if (cxjqj == '1' || cxjqj == '3'){
                          WfForm.changeFieldValue(WfForm.convertFieldNameToId("cxjqj"), {value:""});
                          WfForm.showMessage("假期核算单位为天只能选择半天或全天", 2, 10);
                      }
                  }
              }else {
                  WfForm.showMessage(res.errormsg, 2, 10);
              }
          }
      })
  }



</script>
