Commit 0c96cdb8 authored by Alex朱枝文's avatar Alex朱枝文

编辑在港记录增加时间判断

parent 7bc0d6ff
......@@ -391,20 +391,33 @@ extension YHHKRecordsEditContentVC: UITableViewDelegate, UITableViewDataSource {
let row = sectionArr[indexPath.row]
if case let .selectTime(title, detail, placeholder, timeType) = row {
YHDatePickView.show(type: .yyyymmdd, title:title, lastIsTaday: false, currentDay: detail ?? "") { [weak self] dateStr in
guard let self = self else { return }
guard let self = self, dateStr.count > 0 else { return }
if timeType == .fromTime {
if self.editModel.end_date.count > 0, self.compareDateStrings(dateStr, self.editModel.end_date) == .orderedDescending {
YHHUD.flash(message: "入境时间不能晚于离境时间")
} else {
var sections = self.datas[indexPath.section]
sections[indexPath.row] = .selectTime(title, dateStr, placeholder, timeType)
self.datas[indexPath.section] = sections
if timeType == .fromTime {
self.editModel.start_date = dateStr
tableView.reloadRows(at: [indexPath], with: .automatic)
}
} else {
if self.editModel.start_date.count > 0, self.compareDateStrings(self.editModel.start_date, dateStr) == .orderedDescending {
YHHUD.flash(message: "离境时间不能早于入境时间")
} else {
var sections = self.datas[indexPath.section]
sections[indexPath.row] = .selectTime(title, dateStr, placeholder, timeType)
self.datas[indexPath.section] = sections
self.editModel.end_date = dateStr
}
tableView.reloadRows(at: [indexPath], with: .automatic)
}
}
}
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
guard datas.count > indexPath.section else {
......@@ -452,4 +465,15 @@ extension YHHKRecordsEditContentVC {
attStr.setAttributes([.foregroundColor: UIColor.brandMainColor], range: NSRange(location: normalTextFirst.count, length: attText.count))
return attStr
}
private func compareDateStrings(_ date1: String, _ date2: String) -> ComparisonResult? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd" // 根据你的日期字符串格式调整
guard let firstDate = dateFormatter.date(from: date1),
let secondDate = dateFormatter.date(from: date2) else {
YHHUD.flash(message:"日期字符串格式无效")
return nil
}
return firstDate.compare(secondDate)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment