MyDelegateDetailViewController.swift 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // MyDelegateDetailViewController.swift
  3. // xingchuangke
  4. //
  5. // Created by Virgil on 2019/4/21.
  6. // Copyright © 2019 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. import BetterSegmentedControl
  10. class MyDelegateDetailViewController: BaseViewController, UITableViewDelegate, UITableViewDataSource {
  11. @IBOutlet var control2: BetterSegmentedControl!
  12. @IBOutlet weak var lblAmountMoney: UILabel!
  13. @IBOutlet weak var lblShopCount: UILabel!
  14. @IBOutlet weak var tableView: UITableView!
  15. @IBOutlet weak var lblDate: UILabel!
  16. @IBOutlet weak var lblNo: UILabel!
  17. @IBOutlet weak var lblName: UILabel!
  18. @IBOutlet weak var imgIcon: UIImageView!
  19. var id = ""
  20. override func viewDidLoad() {
  21. super.viewDidLoad()
  22. self.title = "代理详情"
  23. initNavLeftBackButton()
  24. lblName.text = getString(key: "realName")
  25. lblNo.text = "推荐码:\(getString(key: "recCode"))"
  26. let isAuth = getIntValue(key: "isAuthentication")
  27. if isAuth == 2 {
  28. lblDate.text = "认证时间:\(getString(key: "auditTime"))"
  29. } else {
  30. lblDate.text = "认证时间:未认证"
  31. }
  32. imgIcon.loadImage(imgUrl: getString(key: "headPortrait"), defaultImage: "ion_index_01")
  33. imgIcon.setCornerRadius()
  34. tableView.register(UINib(nibName: "MyDelegateDetailTableViewCell", bundle: nil), forCellReuseIdentifier: "MyDelegateDetailTableViewCell")
  35. tableView.delegate = self
  36. tableView.dataSource = self
  37. tableView.separatorStyle = .none
  38. tableView.showsVerticalScrollIndicator = false
  39. tableView.estimatedRowHeight = 100
  40. tableView.mj_header = MJRefreshNormalHeader(refreshingBlock: {[weak self] in
  41. self!.currentPage = 1
  42. self!.loadData()
  43. })
  44. tableView.mj_header?.lastUpdatedTimeKey = "ShowTableViewCell"
  45. tableView.mj_footer = MJRefreshBackNormalFooter(refreshingBlock: {[weak self] in
  46. self!.currentPage += 1
  47. self!.loadData()
  48. })
  49. control2.segments = LabelSegment.segments(withTitles: ["代理", "伙伴"],
  50. normalTextColor: .gray,
  51. selectedTextColor: .white)
  52. let userType = getIntValue(key: "userType")
  53. control2.index = userType == 1 ? 1 : 0
  54. let dicUser = CommonValue.getLoginUserInfo()
  55. var userTypeUser = dicUser!.getInt(key: "userType")
  56. control2.isHidden = userTypeUser == 1 ? true : false
  57. loadDataInfo()
  58. }
  59. // MARK: =============加载数据===============
  60. func loadData() {
  61. let url = RequestURL.sumTransactionListPage
  62. let params = NSMutableDictionary()
  63. params.setValue(id, forKey: "userId")
  64. loadDataList(url: url, params: params, tableView: tableView, tag: 1001)
  65. }
  66. func loadDataInfo() {
  67. let url = RequestURL.agentXMInfo
  68. let params = NSMutableDictionary()
  69. params.setValue(id, forKey: "userId")
  70. params.setValue(id, forKey: "id")
  71. loadDataInfo(url: url, params: params, tag: 1002)
  72. }
  73. override func returnData(tag: Int) {
  74. if tag == 1001 {
  75. tableView.reloadData()
  76. } else if tag == 1002 {
  77. lblShopCount.text = "\(getIntValue(key: "num"))"
  78. lblAmountMoney.text = "¥\(getDoubleValue(key: "total", defaultValue: 0.00))"
  79. tableView.mj_header?.beginRefreshing()
  80. }else if tag == 1003 {
  81. let userType = getIntValue(key: "userType")
  82. control2.index = userType == 1 ? 1 : 0
  83. SVProgressHUD.showSuccess(withStatus: "操作成功")
  84. tableView.reloadData()
  85. }
  86. }
  87. override func returnError(tag: Int, type: String) {
  88. if tag == 1002 {
  89. tableView.mj_header?.beginRefreshing()
  90. }
  91. }
  92. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  93. return 8
  94. }
  95. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  96. let view = UIView(frame: CGRect(x: 0, y: 0, width: ScreenWidth, height: 8))
  97. view.backgroundColor = CommonUntils.getUIColorFromRGB(rgbValue: 0xf0f0f2, alpha: 1.0)
  98. return view
  99. }
  100. // MARK: TABLEVLEW 实现
  101. func numberOfSections(in tableView: UITableView) -> Int {
  102. return 1
  103. }
  104. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  105. return self.arrData.count
  106. }
  107. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  108. return 45
  109. }
  110. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  111. let cell = tableView.dequeueReusableCell(withIdentifier: "MyDelegateDetailTableViewCell", for: indexPath as IndexPath) as! MyDelegateDetailTableViewCell
  112. //cell.lblTitle.text = getString(indexPath.row, key: "Name")
  113. cell.lblLeft.text = getString(current: indexPath.row, key: "sum_month")
  114. let str = "交易额\(getDoubleValue(current: indexPath.row, key: "amount", defaultValue: 0.00))"
  115. cell.lblRight.attributedText = CommonViewUntils.getAttributedStringForFont(str: str, rangs: [NSRange.init(location: 0, length: 3), NSRange.init(location: 3, length: str.length() - 3)], fonts: [UIFont.systemFont(ofSize: 10), UIFont.systemFont(ofSize: 14)])
  116. return cell
  117. }
  118. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  119. // let view = UIViewController()
  120. // view.oneGoId = self.arrData[indexPath.row]["ItemId"] as! Int
  121. // self.navigationController?.pushViewController(view, animated: true)
  122. }
  123. override func viewWillAppear(_ animated: Bool) {
  124. super.viewWillAppear(animated)
  125. }
  126. override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  127. super.init(nibName: "MyDelegateDetailViewController", bundle: nil)
  128. }
  129. required init?(coder aDecoder: NSCoder) {
  130. fatalError("init(coder:) has not been implemented")
  131. }
  132. @IBAction func segmentedControl1ValueChanged(_ sender: BetterSegmentedControl) {
  133. print("The selected index is \(sender.index)")
  134. let url = RequestURL.editUserType
  135. let params = NSMutableDictionary()
  136. params.setValue(id, forKey: "userId")
  137. params.setValue(sender.index, forKey: "userType")
  138. loadDataInfo(url: url, params: params, tag: 1003)
  139. }
  140. }