2020-06-01 14:09:28 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2020-07-05 00:06:34 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-06-01 14:09:28 +08:00
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
|
|
|
|
namespace AntDesign
|
|
|
|
|
{
|
|
|
|
|
public partial class RangePicker : DatePickerBase<DateTime[]>
|
|
|
|
|
{
|
|
|
|
|
public RangePicker()
|
|
|
|
|
{
|
|
|
|
|
IsRange = true;
|
|
|
|
|
|
|
|
|
|
Value = new DateTime[2];
|
|
|
|
|
|
|
|
|
|
DisabledDate = (date) =>
|
|
|
|
|
{
|
|
|
|
|
if (_pickerStatus[0]._hadSelectValue && _inputEnd.IsOnFocused)
|
|
|
|
|
{
|
2020-07-05 00:06:34 +08:00
|
|
|
|
return DateHelper.FormatDateByPicker(date.Date, Picker) < DateHelper.FormatDateByPicker(Value[0].Date, Picker);
|
2020-06-01 14:09:28 +08:00
|
|
|
|
}
|
|
|
|
|
if (_pickerStatus[1]._hadSelectValue && _inputStart.IsOnFocused)
|
|
|
|
|
{
|
2020-07-05 00:06:34 +08:00
|
|
|
|
return DateHelper.FormatDateByPicker(date.Date, Picker) > DateHelper.FormatDateByPicker(Value[1].Date, Picker);
|
2020-06-01 14:09:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void OnInput(ChangeEventArgs args, int index = 0)
|
|
|
|
|
{
|
|
|
|
|
if (args == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DateTime.TryParse(args.Value.ToString(), out DateTime changeValue))
|
|
|
|
|
{
|
|
|
|
|
Value[index] = changeValue;
|
|
|
|
|
_pickerValues[index] = changeValue;
|
|
|
|
|
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UpdateCurrentValueAsString(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get value by picker index
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="index"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override DateTime? GetIndexValue(int index)
|
|
|
|
|
{
|
|
|
|
|
if (_pickerStatus[index]._hadSelectValue)
|
|
|
|
|
{
|
|
|
|
|
return Value[index];
|
|
|
|
|
}
|
|
|
|
|
else if (_defaultValues[index] != null)
|
|
|
|
|
{
|
|
|
|
|
return (DateTime)_defaultValues[index];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ChangeValue(DateTime value, int index = 0)
|
|
|
|
|
{
|
|
|
|
|
Value[index] = value;
|
|
|
|
|
|
|
|
|
|
_pickerStatus[index]._hadSelectValue = true;
|
|
|
|
|
|
|
|
|
|
UpdateCurrentValueAsString(index);
|
|
|
|
|
|
|
|
|
|
if (IsRange && !IsShowTime && Picker != DatePickerType.Time)
|
|
|
|
|
{
|
|
|
|
|
if (_pickerStatus[0]._hadSelectValue && _pickerStatus[1]._hadSelectValue)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!IsShowTime && Picker != DatePickerType.Time)
|
|
|
|
|
{
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-05 00:06:34 +08:00
|
|
|
|
|
|
|
|
|
private async Task OnInputClick(int index)
|
|
|
|
|
{
|
|
|
|
|
await _dropDown.Show();
|
|
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
|
{
|
|
|
|
|
// change start picker value
|
|
|
|
|
if (!_inputStart.IsOnFocused && _pickerStatus[index]._hadSelectValue)
|
|
|
|
|
{
|
|
|
|
|
ChangePickerValue(Value[index], index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChangeFocusTarget(true, false);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// change end picker value
|
|
|
|
|
if (!_inputEnd.IsOnFocused && _pickerStatus[index]._hadSelectValue)
|
|
|
|
|
{
|
|
|
|
|
ChangePickerValue(Value[index], index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChangeFocusTarget(false, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-06 19:09:01 +08:00
|
|
|
|
|
|
|
|
|
public override void ClearValue(int index = 0)
|
|
|
|
|
{
|
|
|
|
|
_isSetPicker = false;
|
|
|
|
|
_pickerStatus[0]._hadSelectValue = false;
|
|
|
|
|
_pickerStatus[1]._hadSelectValue = false;
|
|
|
|
|
UpdateCurrentValueAsString();
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-01 14:09:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|