OutInQueryViewController.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. //
  2. // OutInQueryViewController.swift
  3. // MTP2_iOS
  4. //
  5. // Created by zhongyuan on 2018/3/20.
  6. // Copyright © 2018年 zhongyuan.All rights reserved.
  7. //
  8. import UIKit
  9. class OutInQueryViewController: BaseTableViewController<MoMoneyOutIn>, UITextFieldDelegate {
  10. @IBOutlet weak var startTimeTextField: UITextField!
  11. @IBOutlet weak var endTimeTextField: UITextField!
  12. @IBOutlet weak var queryButton: UIButton!
  13. @IBOutlet weak var tableView: UITableView!
  14. //MARK: TAG值
  15. private static let STARTTIMETEXTFIELDTAG = 100
  16. private static let ENDTIMETEXTFIELDTAG = 101
  17. private lazy var datePickerPopupView = Bundle.main.loadNibNamed("DatePicker", owner: nil, options: nil)?.first as! DatePickerPopupView
  18. /// 开始时间
  19. var startTime: Date?
  20. /// 结束时间
  21. var endTime: Date?
  22. /// 当前页面索引
  23. var pageIndex: Int?
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. addLoadingView()
  27. buildView()
  28. reloadData()
  29. }
  30. private func buildView() {
  31. /// 添加loading组件
  32. addLoadingView()
  33. /// cell重用标识
  34. cellReuseIdentifier = "OutInMoneyTableViewCellID"
  35. setupTextField(textField: startTimeTextField)
  36. setupTextField(textField: endTimeTextField)
  37. }
  38. /// 查询
  39. ///
  40. /// - Parameter sender: queryButton
  41. @IBAction func onClickQueryButton(_ sender: UIButton) {
  42. if !checkValue() { return }
  43. queryOutInMoney(startTime: startTimeTextField.text!, endTime: endTimeTextField.text!)
  44. }
  45. func checkValue() -> Bool {
  46. if let startTime = self.startTimeTextField.text, let endTime = self.endTimeTextField.text {
  47. if startTime.compare(endTime) == .orderedDescending {
  48. self.showHintController(title: "提示", message: "开始日期不能大于结束日期")
  49. return false
  50. }else if self.startTime?.getString(formatter: "yyyy-MM-dd").compare(DateUtils.getLastDate(self.endTime!).getString(formatter: "yyyy-MM-dd")) == .orderedAscending {
  51. self.showHintController(title: "提示", message: "查询间隔不能超过一个月")
  52. return false
  53. }else {
  54. return true
  55. }
  56. }else {
  57. self.showHintController(title: "提示", message: "日期不能为空")
  58. return false
  59. }
  60. }
  61. func setupTextField(textField: UITextField) {
  62. let formatter = DateFormatter()
  63. formatter.dateFormat = "yyyy-MM-dd"
  64. let startTime = formatter.string(from: DateUtils.getLastDate())
  65. let endTime = formatter.string(from: Date())
  66. /// 设置开始和结束时间
  67. self.startTime = DateUtils.getLastDate()
  68. self.endTime = Date()
  69. switch textField.tag {
  70. case OutInQueryViewController.STARTTIMETEXTFIELDTAG:
  71. startTimeTextField.text = startTime
  72. case OutInQueryViewController.ENDTIMETEXTFIELDTAG:
  73. endTimeTextField.text = endTime
  74. default:
  75. break
  76. }
  77. }
  78. func reloadData() {
  79. queryOutInMoney(startTime: startTime!.toDateZero().getString(), endTime: endTime!.toDateNext().getString())
  80. }
  81. private func queryOutInMoney(startTime: String, endTime: String) {
  82. /// 异常
  83. guard let bankManager = MTP2BusinessCore.shared.bankManager,
  84. let accountManager = MTP2BusinessCore.shared.accountManager,
  85. let accountId = accountManager.getCurrentTAAccountInfo()?.accountId else { return }
  86. if tableView.contentOffset.y == 0 {
  87. _anim?.startAnimating()
  88. }
  89. if !noDataButton.isHidden {
  90. noDataButton.isHidden = true
  91. }
  92. bankManager.searchClientMoneyOutIn(accountId: accountId, beginDate: startTime, endDate: endTime){ (isSuccess, errorInfo, results) in
  93. DispatchQueue.main.async {
  94. if self.tableView.contentOffset.y == 0 {
  95. self._anim?.stopAnimating()
  96. }
  97. if isSuccess {
  98. /// 查询成功
  99. self.tableCellModels = results ?? []
  100. if self.tableCellModels.count == 0 {
  101. self.noDataButton.isHidden = false
  102. }else {
  103. self.noDataButton.isHidden = true
  104. }
  105. self.tableView.reloadData()
  106. }else {
  107. /// 查询失败
  108. }
  109. }
  110. }
  111. }
  112. // MARK: - UITextFieldDelegate
  113. func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
  114. datePickerPopupView.delegate = self
  115. datePickerPopupView.datePicker.tag = textField.tag
  116. textField.tag == OutInQueryViewController.STARTTIMETEXTFIELDTAG ? datePickerPopupView.showInView(self.view, currentDate: startTime!) : datePickerPopupView.showInView(self.view, currentDate: endTime!)
  117. return false
  118. }
  119. }
  120. // MARK: - DatePickerPopupViewDelegate
  121. extension OutInQueryViewController: DatePickerPopupViewDelegate {
  122. func datePickerPopupView(_ sender: DatePickerPopupView, selectedDate date: Date, selectedDateString value: String) {
  123. switch sender.datePicker.tag {
  124. case OutInQueryViewController.STARTTIMETEXTFIELDTAG:
  125. startTimeTextField.text = value
  126. startTime = date
  127. case OutInQueryViewController.ENDTIMETEXTFIELDTAG:
  128. endTimeTextField.text = value
  129. endTime = date
  130. default:
  131. break
  132. }
  133. sender.hidePopupView()
  134. }
  135. }
  136. // MARK: - PageChangeDelegate
  137. extension OutInQueryViewController: PageChangeDelegate {
  138. func didShow() {
  139. reloadData()
  140. }
  141. func didHide() {
  142. //do something
  143. }
  144. }