<%@ 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{


        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("xjr"),function(obj,id,value){
            console.log("WfForm.bindFieldChangeEvent--",obj,id,value);
            detailtTable();
        });
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("qjlx"),function(obj,id,value){
            console.log("WfForm.bindFieldChangeEvent--",obj,id,value);
            detailtTable();
        });
        WfForm.bindFieldChangeEvent(WfForm.convertFieldNameToId("cxqj"),function(obj,id,value){
            console.log("WfForm.bindFieldChangeEvent--",obj,id,value);
            detailtTable();
        });

    }catch (e) {
    }
  });
  function detailtTable(){
      let qjlx = WfForm.getFieldValue(WfForm.convertFieldNameToId('qjlx'));
      let xcr = WfForm.getFieldValue(WfForm.convertFieldNameToId('xjr'));
      let cxqj = WfForm.getFieldValue(WfForm.convertFieldNameToId('cxqj'));
      let startDate="";
      let endDate="";
      let nowYear = new Date().getFullYear();
      let nowMonth =new Date().getMonth()+1;
      let month = 1;
      let fullDay = 30;
      if (cxqj == "0"){
          //上月
          month = nowMonth-1;
          if (month == 0){
              month =12;
          }
          fullDay = new Date(nowYear,month,0).getDate();
          if (month < 10){
              month = "0"+month;
          }
      }else if (cxqj == "1"){
          //本月
          month = nowMonth;
          fullDay = new Date(nowYear,month,0).getDate();
          if (month < 10){
              month = "0"+month;
          }

      }else if (cxqj == "2"){
          //下月
          month = nowMonth+1;
          if (month > 12){
              month = month-12;
              nowYear = nowYear+1;
          }
          fullDay = new Date(nowYear,month,0).getDate();
          if (month < 10){
              month = "0"+month;
          }

      }else if (cxqj == "3"){
          //下下月
          month = nowMonth+2;
          if (month > 12){
              month = month-12;
              nowYear = nowYear+1;
          }
          fullDay = new Date(nowYear,month,0).getDate();
          if (month < 10){
              month = "0"+month;
          }
      }
      startDate = nowYear+"-"+month+"-01";
      endDate = nowYear+"-"+month+"-"+fullDay;
      let data = {
          targetUserId:xcr,
          businessTripsType:qjlx,
          startDate:startDate,
          endDate:endDate
      }

      $.ajax({
          url:'/api/attendance/askforleave/getAskForLeaveRecordList',
          data:data,
          type:'GET',
          dataType:'json',
          success:function(res){
              console.log(res)
              let data = res.data.result;
              WfForm.delDetailRow("detail_1", "all");
              if (data != undefined){
                  data.filter(item => {
                      var obj = {};
                      //撤销
                      obj[WfForm.convertFieldNameToId("cx", "detail_1")] = {value:item.cxqj};
                      //开始日期
                      obj[WfForm.convertFieldNameToId("ksrq", "detail_1")] = {value:item.ksrq};
                      //开始时间
                      obj[WfForm.convertFieldNameToId("kssj", "detail_1")] = {value:item.kssj};
                      //结束日期
                      obj[WfForm.convertFieldNameToId("jsrq", "detail_1")] = {value:item.jsrq};
                      //结束时间
                      obj[WfForm.convertFieldNameToId("jssj", "detail_1")] = {value:item.jssj};
                      //出差时长
                      obj[WfForm.convertFieldNameToId("qjsc", "detail_1")] = {value:item.qjsc};
                      //全天
                      obj[WfForm.convertFieldNameToId("qt", "detail_1")] = {value:item.qtj};
                      //半天
                      obj[WfForm.convertFieldNameToId("bt", "detail_1")] = {value:item.btj};
                      //撤销id
                      obj[WfForm.convertFieldNameToId("cxlyid", "detail_1")] = {value:item.id};

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

</script>
