如何使用JQuery从开始日期,天,周末和假日计算结束日期

时间:2020-11-12 09:11:12

标签: jquery jquery-ui-datepicker

我正在使用Laravel-5.8和JQuery-ui datepicker开发应用程序HR应用程序。

我使用JSON将国定假日从Controller传递到视图,并且运行良好:

我有以下三个字段:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="commencement_date" class="form-control commencement_date" placeholder="dd/mm/yyyy" readonly autocomplete="off" name="commencement_date">
<input type="text" id="leave_days" name="no_of_days" class="form-control no_of_days" placeholder="e.g. 10" maxlength="3" onkeyup="checkScore(this.value)">
<input type="text" id="resumption_date" class="form-control resumption_date" placeholder="dd/mm/yyyy" readonly autocomplete="off" name="resumption_date">

< script type = "text/javascript" >
  var holidayDays = [];
$(document).ready(function() {
  $(document).on('change', '#leave_type', function() {
    var air_id = $(this).val();

    var a = $(this).parent();
    var op = "";

    $.ajax({
      type: 'get',
      url: '{{ route('
      get.leavecounts.all ') }}',
      data: {
        'id': air_id
      },
      dataType: 'json', //return data will be json
      // console.log("Its Change !");
      success: function(data) {
        holidayDays = data.nationalholidays;
      },
      error: function() {

      }
    });
  });
}); <
/script>

#leave_type onchange加载国家节日。在控制台中,国定假日采用以下格式:

(7) ["2020-11-12", "2020-11-16", "2020-11-19", "2020-11-30", "2020-12-14", "2020-12-01", "2020-12-10"]
0: "2020-11-12"
1: "2020-11-16"
2: "2020-11-19"
3: "2020-11-30"
4: "2020-12-14"
5: "2020-12-01"
6: "2020-12-10"
length: 7
__proto__: Array(0)

使用下面的代码,在#leave_days键上,我已经能够从开始日期+休假天数计算恢复日期。但这并不能照顾国定假日和周末。

< script type = "text/javascript" >
  $(document).ready(function() {
    $("#leave_days").on('keyup blur', function(e) {
      var periodval = parseInt($("#leave_days").val());
      holidayDays = holidayDays;
      console.log(holidayDays);;
      var startDate = $('.commencement_date');
      var endDate = $('.resumption_date');

      var dte = startDate.datepicker("getDate");

    });

    $('.commencement_date').datepicker({
      dateFormat: 'dd-mm-yy',
      changeMonth: true,
      changeYear: true,
      showAnim: 'slideDown',
      duration: 'fast',
      minDate: +1,
      setDate: new Date(),
      beforeShowDay: $.datepicker.noWeekends,
      yearRange: new Date().getFullYear() + ':' + new Date().getFullYear(),
    }).datepicker('setDate', '1');

    $('.resumption_date').datepicker({
      dateFormat: 'dd-mm-yy',
      changeMonth: true,
      changeYear: true,
      showAnim: 'slideDown',
      duration: 'fast',
      minDate: +1,
      beforeShowDay: $.datepicker.noWeekends,
      yearRange: new Date().getFullYear() + ':' + new Date().getFullYear(),
      enableOnReadonly: true,
      beforeShow: function(i) {
        if ($(i).attr('readonly')) {
          return false;
        }
      }
    });
  }); <
/script>

现在的问题是,如何在#leave_days keyup上从开始日期,休假日,国家节假日和周末计算恢复日期?

谢谢

0 个答案:

没有答案