| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- //
- // OutInQueryViewController.swift
- // MTP2_iOS
- //
- // Created by zhongyuan on 2018/3/20.
- // Copyright © 2018年 zhongyuan.All rights reserved.
- //
- import UIKit
- class OutInQueryViewController: BaseTableViewController<MoMoneyOutIn>, UITextFieldDelegate {
-
- @IBOutlet weak var startTimeTextField: UITextField!
- @IBOutlet weak var endTimeTextField: UITextField!
- @IBOutlet weak var queryButton: UIButton!
- @IBOutlet weak var tableView: UITableView!
-
- //MARK: TAG值
- private static let STARTTIMETEXTFIELDTAG = 100
- private static let ENDTIMETEXTFIELDTAG = 101
-
- private lazy var datePickerPopupView = Bundle.main.loadNibNamed("DatePicker", owner: nil, options: nil)?.first as! DatePickerPopupView
-
- /// 开始时间
- var startTime: Date?
- /// 结束时间
- var endTime: Date?
- /// 当前页面索引
- var pageIndex: Int?
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- addLoadingView()
- buildView()
- reloadData()
- }
-
- private func buildView() {
- /// 添加loading组件
- addLoadingView()
- /// cell重用标识
- cellReuseIdentifier = "OutInMoneyTableViewCellID"
-
- setupTextField(textField: startTimeTextField)
- setupTextField(textField: endTimeTextField)
- }
-
- /// 查询
- ///
- /// - Parameter sender: queryButton
- @IBAction func onClickQueryButton(_ sender: UIButton) {
- if !checkValue() { return }
-
- queryOutInMoney(startTime: startTimeTextField.text!, endTime: endTimeTextField.text!)
- }
-
- func checkValue() -> Bool {
- if let startTime = self.startTimeTextField.text, let endTime = self.endTimeTextField.text {
- if startTime.compare(endTime) == .orderedDescending {
- self.showHintController(title: "提示", message: "开始日期不能大于结束日期")
- return false
- }else if self.startTime?.getString(formatter: "yyyy-MM-dd").compare(DateUtils.getLastDate(self.endTime!).getString(formatter: "yyyy-MM-dd")) == .orderedAscending {
- self.showHintController(title: "提示", message: "查询间隔不能超过一个月")
- return false
- }else {
- return true
- }
- }else {
- self.showHintController(title: "提示", message: "日期不能为空")
- return false
- }
- }
-
- func setupTextField(textField: UITextField) {
- let formatter = DateFormatter()
- formatter.dateFormat = "yyyy-MM-dd"
- let startTime = formatter.string(from: DateUtils.getLastDate())
- let endTime = formatter.string(from: Date())
- /// 设置开始和结束时间
- self.startTime = DateUtils.getLastDate()
- self.endTime = Date()
- switch textField.tag {
- case OutInQueryViewController.STARTTIMETEXTFIELDTAG:
- startTimeTextField.text = startTime
- case OutInQueryViewController.ENDTIMETEXTFIELDTAG:
- endTimeTextField.text = endTime
- default:
- break
- }
- }
-
- func reloadData() {
- queryOutInMoney(startTime: startTime!.toDateZero().getString(), endTime: endTime!.toDateNext().getString())
- }
-
- private func queryOutInMoney(startTime: String, endTime: String) {
- /// 异常
- guard let bankManager = MTP2BusinessCore.shared.bankManager,
- let accountManager = MTP2BusinessCore.shared.accountManager,
- let accountId = accountManager.getCurrentTAAccountInfo()?.accountId else { return }
-
- if tableView.contentOffset.y == 0 {
- _anim?.startAnimating()
- }
- if !noDataButton.isHidden {
- noDataButton.isHidden = true
- }
-
- bankManager.searchClientMoneyOutIn(accountId: accountId, beginDate: startTime, endDate: endTime){ (isSuccess, errorInfo, results) in
-
- DispatchQueue.main.async {
- if self.tableView.contentOffset.y == 0 {
- self._anim?.stopAnimating()
- }
- if isSuccess {
- /// 查询成功
- self.tableCellModels = results ?? []
-
- if self.tableCellModels.count == 0 {
- self.noDataButton.isHidden = false
- }else {
- self.noDataButton.isHidden = true
- }
- self.tableView.reloadData()
- }else {
- /// 查询失败
- }
- }
- }
- }
-
- // MARK: - UITextFieldDelegate
- func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
- datePickerPopupView.delegate = self
- datePickerPopupView.datePicker.tag = textField.tag
- textField.tag == OutInQueryViewController.STARTTIMETEXTFIELDTAG ? datePickerPopupView.showInView(self.view, currentDate: startTime!) : datePickerPopupView.showInView(self.view, currentDate: endTime!)
- return false
- }
- }
- // MARK: - DatePickerPopupViewDelegate
- extension OutInQueryViewController: DatePickerPopupViewDelegate {
- func datePickerPopupView(_ sender: DatePickerPopupView, selectedDate date: Date, selectedDateString value: String) {
- switch sender.datePicker.tag {
- case OutInQueryViewController.STARTTIMETEXTFIELDTAG:
- startTimeTextField.text = value
- startTime = date
- case OutInQueryViewController.ENDTIMETEXTFIELDTAG:
- endTimeTextField.text = value
- endTime = date
- default:
- break
- }
- sender.hidePopupView()
- }
- }
- // MARK: - PageChangeDelegate
- extension OutInQueryViewController: PageChangeDelegate {
- func didShow() {
- reloadData()
- }
-
- func didHide() {
- //do something
- }
- }
|