BusinessViewController.swift 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // BusinessViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/22.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class BusinessViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, BusinessHeaderViewDelegate {
  10. @IBOutlet weak var tableView: UITableView!
  11. var headerView: BusinessHeaderView!
  12. var machineType: NSString = "2"
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. tableView.register(UINib(nibName: "BusinessTableViewCell", bundle: nil), forCellReuseIdentifier: "BusinessTableViewCell")
  16. tableView.delegate = self
  17. tableView.dataSource = self
  18. tableView.separatorStyle = .none
  19. tableView.showsVerticalScrollIndicator = false
  20. tableView.estimatedRowHeight = 100
  21. tableView.setSizeHeight(height: ScreenHeight - common_nav_status_height - common_bottom_height - 48)
  22. tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
  23. self!.currentPage = 1
  24. self!.loadData()
  25. })
  26. tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell"
  27. tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in
  28. self!.currentPage += 1
  29. self!.loadData()
  30. })
  31. headerView = (CommonViewUntils.getViewForXIB(xibName: "BusinessHeaderView") as! BusinessHeaderView)
  32. headerView.delegate = self
  33. headerView.initView()
  34. tableView.tableHeaderView = headerView
  35. tableView.reloadData()
  36. headerTop = headerView.viewContent2.topm()
  37. loadData()
  38. // Do any additional setup after loading the view.
  39. }
  40. // MARK: =============加载数据===============
  41. func loadData() {
  42. let url = RequestURL.transactionListPage
  43. let params = NSMutableDictionary()
  44. // params.setValue("", forKey: "machineTypeId")
  45. params.setValue(self.machineType, forKey: "machineTypeId")
  46. params.setValue("", forKey: "timeStart")
  47. params.setValue("", forKey: "timeEnd")
  48. params.setValue("", forKey: "cardType")
  49. params.setValue("", forKey: "transactionType")
  50. params.setValue("desc", forKey: "sortType")
  51. loadDataList(url: url, params: params, tableView: tableView, tag: 1001)
  52. }
  53. override func returnData(tag: Int) {
  54. if tag == 1001 {
  55. tableView.reloadData()
  56. }
  57. }
  58. override func returnError(tag: Int, type: String) {
  59. }
  60. // MARK: TABLEVLEW 实现
  61. func numberOfSections(in tableView: UITableView) -> Int {
  62. return 1
  63. }
  64. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  65. return self.arrData.count;//
  66. }
  67. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  68. return 57
  69. }
  70. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  71. let cell = tableView.dequeueReusableCell(withIdentifier: "BusinessTableViewCell", for: indexPath as IndexPath) as! BusinessTableViewCell
  72. //cell.lblTitle.text = getString(indexPath.row, key: "Name")
  73. cell.lblName.text = getString(current: indexPath.row, key: "shopName")
  74. cell.lblDate.text = getString(current: indexPath.row, key: "tradeDate")
  75. cell.lblPayName.text = getString(current: indexPath.row, key: "machineTypeCN")
  76. cell.lblMoney.text = "¥\(getString(current: indexPath.row, key: "tradeAmount") )"
  77. let depositTrade = getString(current: indexPath.row, key: "depositTrade") == "19" ? "押金" : "消费"
  78. cell.lblType.text = "(\(depositTrade))"
  79. cell.lblType.isHidden = true
  80. return cell
  81. }
  82. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  83. }
  84. var headerIsTop = false
  85. var headerTop: CGFloat = 258; //view距顶部的距离
  86. func scrollViewDidScroll(_ scrollView: UIScrollView) {
  87. if scrollView.contentOffset.y >= headerTop {
  88. if !headerIsTop {
  89. headerView.viewContent2.removeFromSuperview()
  90. self.view.addSubview(headerView.viewContent2)
  91. headerView.viewContent2.marginTop(top: 0)
  92. headerIsTop = true
  93. }
  94. } else {
  95. if headerIsTop {
  96. headerView.viewContent2.removeFromSuperview()
  97. headerView.addSubview(headerView.viewContent2)
  98. headerView.viewContent2.marginTop(top: 258)
  99. headerIsTop = false
  100. }
  101. }
  102. }
  103. func segmentDidClickedWithIndex(index: NSInteger) {
  104. if index == 0 {
  105. self.machineType = "2"
  106. } else if index == 1 {
  107. self.machineType = "300595e17ed94b5f8c2b3f437ce26116"
  108. } else if index == 2 {
  109. self.machineType = "f391406346e04510ab6b3be081b2e4aa"
  110. } else if index == 3 {
  111. self.machineType = "4"
  112. }
  113. self.currentPage = 1
  114. loadData()
  115. }
  116. override func viewWillAppear(_ animated: Bool) {
  117. super.viewWillAppear(animated)
  118. appDelegate.setNavigationBarHidden(isHidden: false)
  119. self.tabBarController?.title = "我的业务"
  120. }
  121. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  122. super.init(nibName: "BusinessViewController", bundle: nil)
  123. }
  124. required init?(coder aDecoder: NSCoder) {
  125. fatalError("init(coder:) has not been implemented")
  126. }
  127. }