JCVerificationDetailViewController.swift 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // JCVerificationDetailViewController.swift
  3. // JChat
  4. //
  5. // Created by deng on 2017/5/25.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. import UIKit
  9. class JCVerificationDetailViewController: UIViewController {
  10. var verificationInfo: JCVerificationInfo!
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. _init()
  14. }
  15. fileprivate lazy var tableview: UITableView = UITableView(frame: .zero, style: .grouped)
  16. fileprivate var user: JMSGUser?
  17. //MARK: - private func
  18. private func _init() {
  19. self.title = "详细信息"
  20. automaticallyAdjustsScrollViewInsets = false
  21. tableview.delegate = self
  22. tableview.dataSource = self
  23. tableview.register(JCUserAvatorCell.self, forCellReuseIdentifier: "JCUserAvatorCell")
  24. tableview.register(JCUserInfoCell.self, forCellReuseIdentifier: "JCUserInfoCell")
  25. tableview.register(JCResaonCell.self, forCellReuseIdentifier: "JCResaonCell")
  26. tableview.register(JCDoubleButtonCell.self, forCellReuseIdentifier: "JCDoubleButtonCell")
  27. tableview.separatorStyle = .none
  28. tableview.backgroundColor = UIColor(netHex: 0xe8edf3)
  29. tableview.frame = CGRect(x: 0, y: 64, width: view.width, height: view.height - 64)
  30. view.addSubview(tableview)
  31. _getUserInfo()
  32. }
  33. private func _getUserInfo() {
  34. JMSGUser.userInfoArray(withUsernameArray: [verificationInfo.username]) { (result, error) in
  35. if error == nil {
  36. let users = result as! [JMSGUser]
  37. self.user = users.first
  38. self.tableview.reloadData()
  39. }
  40. }
  41. }
  42. }
  43. //MARK: - UITableViewDataSource & UITableViewDelegate
  44. extension JCVerificationDetailViewController: UITableViewDataSource, UITableViewDelegate {
  45. func numberOfSections(in tableView: UITableView) -> Int {
  46. if user != nil {
  47. return 2
  48. }
  49. return 0
  50. }
  51. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  52. if section == 1 {
  53. return 1
  54. }
  55. return 5
  56. }
  57. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  58. if indexPath.section == 0 && indexPath.row == 0 {
  59. return 175
  60. }
  61. if indexPath.section == 1 {
  62. return 40
  63. }
  64. return 45
  65. }
  66. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  67. if section == 0 {
  68. return 15
  69. }
  70. return 0.0001
  71. }
  72. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  73. return 0.0001
  74. }
  75. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  76. if indexPath.section == 0 && indexPath.row == 0 {
  77. return tableView.dequeueReusableCell(withIdentifier: "JCUserAvatorCell", for: indexPath)
  78. }
  79. if indexPath.section == 0 && indexPath.row == 1 {
  80. return tableView.dequeueReusableCell(withIdentifier: "JCResaonCell", for: indexPath)
  81. }
  82. if indexPath.section == 1 {
  83. return tableView.dequeueReusableCell(withIdentifier: "JCDoubleButtonCell", for: indexPath)
  84. }
  85. return tableView.dequeueReusableCell(withIdentifier: "JCUserInfoCell", for: indexPath)
  86. }
  87. func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
  88. cell.selectionStyle = .none
  89. if indexPath.section == 0 && indexPath.row == 0 {
  90. guard let cell = cell as? JCUserAvatorCell else {
  91. return
  92. }
  93. cell.delegate = self
  94. cell.bindData(user: user!)
  95. }
  96. if indexPath.section == 0 && indexPath.row == 1 {
  97. guard let cell = cell as? JCResaonCell else {
  98. return
  99. }
  100. if verificationInfo.resaon.isEmpty {
  101. cell.resaon = "附加消息:无"
  102. } else {
  103. cell.resaon = "附加消息:\(verificationInfo.resaon)"
  104. }
  105. }
  106. if indexPath.section == 1 {
  107. guard let cell = cell as? JCDoubleButtonCell else {
  108. return
  109. }
  110. cell.leftButtonTitle = "拒绝"
  111. cell.rightButtonTitle = "同意"
  112. cell.delegate = self
  113. }
  114. if indexPath.section == 0 {
  115. guard let cell = cell as? JCUserInfoCell else {
  116. return
  117. }
  118. switch indexPath.row {
  119. case 2:
  120. cell.title = "用户名"
  121. cell.detail = user?.username
  122. cell.icon = UIImage.loadImage("com_icon_username")
  123. case 3:
  124. cell.title = "性别"
  125. cell.icon = UIImage.loadImage("com_icon_gender")
  126. if user?.gender == .male {
  127. cell.detail = "男"
  128. } else if user?.gender == .female {
  129. cell.detail = "女"
  130. } else {
  131. cell.detail = "保密"
  132. }
  133. case 4:
  134. cell.title = "生日"
  135. cell.icon = UIImage.loadImage("com_icon_birthday")
  136. cell.detail = user?.birthday
  137. case 5:
  138. cell.title = "地区"
  139. cell.icon = UIImage.loadImage("com_icon_region")
  140. cell.detail = user?.region
  141. default:
  142. break
  143. }
  144. }
  145. }
  146. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  147. }
  148. }
  149. extension JCVerificationDetailViewController: JCDoubleButtonCellDelegate {
  150. func doubleButtonCell(clickLeftButton button: UIButton) {
  151. JMSGFriendManager.rejectInvitation(withUsername: verificationInfo.username, appKey: verificationInfo.appkey, reason: "") { (result, error) in
  152. if error == nil {
  153. self.verificationInfo.state = JCVerificationType.reject.rawValue
  154. JCVerificationInfoDB.shareInstance.updateData(self.verificationInfo)
  155. NotificationCenter.default.post(name: Notification.Name(rawValue: kUpdateVerification), object: nil)
  156. self.navigationController?.popViewController(animated: true)
  157. }
  158. }
  159. }
  160. func doubleButtonCell(clickRightButton button: UIButton) {
  161. JMSGFriendManager.acceptInvitation(withUsername: verificationInfo.username, appKey: verificationInfo.appkey) { (result, error) in
  162. if error == nil {
  163. self.verificationInfo.state = JCVerificationType.accept.rawValue
  164. JCVerificationInfoDB.shareInstance.updateData(self.verificationInfo)
  165. NotificationCenter.default.post(name: Notification.Name(rawValue: kUpdateVerification), object: nil)
  166. NotificationCenter.default.post(name: Notification.Name(rawValue: kUpdateFriendList), object: nil)
  167. self.navigationController?.popViewController(animated: true)
  168. }
  169. }
  170. }
  171. }
  172. extension JCVerificationDetailViewController: JCUserAvatorCellDelegate {
  173. func tapAvator(_ image: UIImage?) {
  174. guard let image = image else {
  175. return
  176. }
  177. let browserImageVC = JCImageBrowserViewController()
  178. browserImageVC.imageArr = [image]
  179. browserImageVC.imgCurrentIndex = 0
  180. present(browserImageVC, animated: true) {
  181. }
  182. }
  183. }