MachineManagerViewController.swift 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // SelectBankViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/3/30.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class MachineManagerViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate {
  10. @IBOutlet weak var viewMenu1: UIView!
  11. @IBOutlet weak var viewMenu2: UIView!
  12. @IBOutlet weak var viewMenu3: UIView!
  13. @IBOutlet weak var viewMenu4: UIView!
  14. @IBOutlet weak var lblCount3: UILabel!
  15. @IBOutlet weak var lblCount2: UILabel!
  16. @IBOutlet weak var lblCount1: UILabel!
  17. @IBOutlet weak var viewRemark: UIView!
  18. @IBOutlet weak var tableView: UITableView!
  19. @IBOutlet weak var imgBackgroud: UIImageView!
  20. @IBOutlet weak var txtCode: UITextField!
  21. @IBOutlet weak var viewMenu: UIView!
  22. @IBOutlet weak var lblRemark: UILabel!
  23. var mid = ""
  24. var provinceId = ""
  25. var cityId = ""
  26. var shopEntity: ShopOpenEntity!
  27. var bankName = ""
  28. ///0:代理 1:商户
  29. var type = 0
  30. override func viewDidLoad() {
  31. super.viewDidLoad()
  32. let strTitle = "终端"
  33. let viewNav = (CommonViewUntils.getViewForXIB(xibName: "NavView") as! NavView)
  34. viewNav.initView(title: "我的\(strTitle)") {[weak self] (index, _) in
  35. if index == 0 {
  36. self!.handleBack()
  37. }
  38. }
  39. self.view.addSubview(viewNav)
  40. viewNav.marginTop(top: 0)
  41. self.view.addSubview(viewNav)
  42. viewNav.marginTop(top: 0)
  43. viewMenu.marginTop(top: viewNav.bottom())
  44. txtCode.setCornerRadius(size: 4)
  45. txtCode.setContentMarginLeft(leftWidth: 15)
  46. txtCode.setContentMarginRight(rightWidth: 30)
  47. imgBackgroud.setSizeHeight(height: viewMenu.bottom())
  48. viewRemark.marginTop(top: 0, view: imgBackgroud)
  49. tableView.marginTop(top: 1, view: viewRemark)
  50. tableView.setSizeHeight(height: ScreenHeight - imgBackgroud.height() - 49 - 26)
  51. tableView.register(UINib(nibName: "MachineManagerTableViewCell", bundle: nil), forCellReuseIdentifier: "MachineManagerTableViewCell")
  52. tableView.delegate = self
  53. tableView.dataSource = self
  54. tableView.separatorStyle = .none
  55. tableView.showsVerticalScrollIndicator = false
  56. tableView.estimatedRowHeight = 100
  57. tableView.keyboardDismissMode = .onDrag
  58. txtCode.delegate = self
  59. txtCode.returnKeyType = .search
  60. tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
  61. self!.currentPage = 1
  62. self!.loadData()
  63. })
  64. tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell"
  65. tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in
  66. self!.currentPage += 1
  67. self!.loadData()
  68. })
  69. loadInfo()
  70. CommonViewUntils.setViewAverage(arrView: [viewMenu1, viewMenu2, viewMenu3])
  71. //CommonViewUntils.getAttributedString(str: "直属\(strTitle)(3人)", left: [5,strTitle.length() + 2,strTitle.length() + 4], color: [UIColor])
  72. // lblRemark.text = "直属\(strTitle)(3人)"
  73. }
  74. override func KeyboardHidden(gestureRecognizer: UIGestureRecognizer) {
  75. txtCode.resignFirstResponder()
  76. }
  77. @IBAction func btnQuery(_ sender: Any) {
  78. self.currentPage = 1
  79. loadData()
  80. }
  81. func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  82. self.currentPage = 1
  83. loadData()
  84. return true
  85. }
  86. // MARK: =============加载数据===============
  87. func loadData() //str:String
  88. {
  89. let url = RequestURL.myMachineList
  90. let params = NSMutableDictionary()
  91. params.setValue(CommonValue.getUserId(), forKey: "userId")
  92. params.setValue(txtCode.text!, forKey: "snCode")
  93. loadDataList(url: url, params: params, tableView: tableView, tag: 1001)
  94. }
  95. func loadInfo() {
  96. let url = RequestURL.myMachineInfo
  97. let params = NSMutableDictionary()
  98. loadDataInfo(url: url, params: params, tag: 1002)
  99. }
  100. override func returnData(tag: Int) {
  101. if tag == 1001 {
  102. tableView.reloadData()
  103. } else if tag == 1002 {
  104. lblCount1.text = "\(getIntValue(key: "total"))"
  105. lblCount2.text = "\(getIntValue(key: "status1"))"
  106. lblCount3.text = "\(getIntValue(key: "status2"))"
  107. }
  108. }
  109. override func returnError(tag: Int, type: String) {
  110. }
  111. // MARK: TABLEVLEW 实现
  112. func numberOfSections(in tableView: UITableView) -> Int {
  113. return 1
  114. }
  115. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  116. return self.arrData.count
  117. }
  118. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  119. return 82
  120. }
  121. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  122. let cell = tableView.dequeueReusableCell(withIdentifier: "MachineManagerTableViewCell", for: indexPath as IndexPath) as! MachineManagerTableViewCell
  123. if getString(current: indexPath.row, key: "productTypeCN") != "" {
  124. cell.lblName.text = "\(getString(current: indexPath.row, key: "machineTypeCN"))(\(getString(current: indexPath.row, key: "productTypeCN")))"
  125. } else {
  126. cell.lblName.text = "\(getString(current: indexPath.row, key: "machineTypeCN"))"
  127. }
  128. cell.lblDate.text = "\(getString(current: indexPath.row, key: "sn_code"))"
  129. let state = getIntValue(current: indexPath.row, key: "status")
  130. if state == 0 {
  131. cell.lblRemark.text = "未绑定"
  132. cell.lblRemark.textColor = UIColor.red
  133. } else if state == 1 {
  134. cell.lblRemark.text = "已绑定"
  135. cell.lblRemark.textColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x666666, alpha: 1.0)
  136. } else {
  137. cell.lblRemark.text = "已激活"
  138. cell.lblRemark.textColor = CommonUntils.getUIColorFromRGB(rgbValue: 0x666666, alpha: 1.0)
  139. }
  140. return cell
  141. }
  142. var selectedIndex = -1
  143. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  144. if indexPath.row >= arrData.count {
  145. return
  146. }
  147. let vc = MachineDetailViewController()
  148. vc.id = getString(current: indexPath.row, key: "id")
  149. toViewController(viewController: vc)
  150. }
  151. override func viewWillAppear(_ animated: Bool) {
  152. super.viewWillAppear(animated)
  153. appDelegate.setNavigationBarHidden(isHidden: true)
  154. self.currentPage = 1
  155. loadData()
  156. }
  157. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  158. super.init(nibName: "MachineManagerViewController", bundle: nil)
  159. }
  160. required init?(coder aDecoder: NSCoder) {
  161. fatalError("init(coder:) has not been implemented")
  162. }
  163. }