ContactPersonInfoController.swift 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // ContactPersonInfoController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 16/7/15.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import Alamofire
  10. import AlamofireImage
  11. import AlamofireObjectMapper
  12. import SwiftyJSON
  13. import ObjectMapper
  14. import Eureka
  15. import CocoaLumberjack
  16. class ContactPersonInfoController: FormViewController {
  17. var myPersonURL:String?
  18. var identity:IdentityV2? {
  19. didSet {
  20. self.myPersonURL = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personInfoByNameQuery, parameter: ["##name##":identity!.person! as AnyObject])
  21. }
  22. }
  23. var isLoadPerson:Bool = true
  24. var contact:PersonV2? {
  25. didSet {
  26. isLoadPerson = false
  27. }
  28. }
  29. override func viewDidLoad() {
  30. super.viewDidLoad()
  31. ImageRow.defaultCellUpdate = { cell, row in
  32. cell.accessoryView?.layer.cornerRadius = 17
  33. cell.accessoryView?.frame = CGRect(x: 0, y: 0, width: 34, height: 34)
  34. cell.textLabel?.font = UIFont(name: "PingFangSC-Light", size: 12.0)
  35. cell.textLabel?.textColor = RGB(155, g: 155, b: 155)
  36. }
  37. LabelRow.defaultCellUpdate = {
  38. cell,row in
  39. cell.textLabel?.font = UIFont(name: "PingFangSC-Light", size: 12.0)
  40. cell.textLabel?.textColor = RGB(155, g: 155, b: 155)
  41. cell.accessoryType = .disclosureIndicator
  42. }
  43. EmailRow.defaultCellUpdate = {
  44. cell,row in
  45. cell.textLabel?.font = UIFont(name: "PingFangSC-Light", size: 12.0)
  46. cell.textLabel?.textColor = RGB(155, g: 155, b: 155)
  47. cell.accessoryType = .disclosureIndicator
  48. }
  49. PhoneRow.defaultCellUpdate = {
  50. cell,row in
  51. cell.textLabel?.font = UIFont(name: "PingFangSC-Light", size: 12.0)
  52. cell.textLabel?.textColor = RGB(155, g: 155, b: 155)
  53. cell.accessoryType = .disclosureIndicator
  54. }
  55. isLoadPerson==true ?loadPersonInfo(nil):loadDataCell()
  56. }
  57. func loadPersonInfo(_ sender: AnyObject?){
  58. self.showLoading()
  59. AF.request(myPersonURL!).responseJSON {
  60. response in
  61. switch response.result {
  62. case .success( let val):
  63. let json = JSON(val)["data"]
  64. self.contact = Mapper<PersonV2>().map(JSONString:json.description)!
  65. self.loadDataCell()
  66. self.hideLoading()
  67. case .failure(let err):
  68. DDLogError(err.localizedDescription)
  69. self.showError(title: L10n.errorWithMsg(err.localizedDescription))
  70. }
  71. }
  72. }
  73. func loadDataCell(){
  74. form +++ Section()
  75. <<< ImageRow("icon"){ row in
  76. row.title = "头像"
  77. let urlstr = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personIconByNameQueryV2, parameter: ["##name##":contact?.unique as AnyObject])
  78. let url = URL(string: urlstr!)
  79. //从网络获取数据流
  80. if let data = try? Data(contentsOf: url!){
  81. row.value = UIImage(data: data)
  82. }else{
  83. row.value = UIImage(named: "personDefaultIcon")
  84. }
  85. row.disabled = true
  86. }
  87. <<< LabelRow("employee"){
  88. $0.title = "工号"
  89. $0.value = contact!.employee
  90. }
  91. <<< LabelRow("display"){
  92. $0.title = "名字"
  93. $0.value = contact!.name
  94. }
  95. <<< LabelRow("genderType"){
  96. $0.title = "性别"
  97. $0.value = contact!.genderType == "f" ? "女":"男"
  98. }
  99. +++ Section()
  100. <<< LabelRow("mail"){
  101. $0.title = "Email"
  102. $0.value = contact!.mail
  103. }
  104. <<< LabelRow("mobile"){
  105. $0.title = "手机"
  106. $0.value = contact!.mobile
  107. }.onCellSelection({ (cell, row) in
  108. if let phone = row.value {
  109. let alertController = UIAlertController(title: "", message: "呼叫联系人?", preferredStyle: .alert)
  110. let smsAction = UIAlertAction(title: "发短信", style: .default, handler: { _ in
  111. let smsURL = URL(string: "sms://\(phone)")
  112. if UIApplication.shared.canOpenURL(smsURL!) {
  113. UIApplication.shared.openURL(smsURL!)
  114. }else{
  115. self.showError(title: "发短信失败")
  116. }
  117. })
  118. let phoneAction = UIAlertAction(title: "打电话", style: .default, handler: { _ in
  119. let phoneURL = URL(string: "tel://\(phone)")
  120. if UIApplication.shared.canOpenURL(phoneURL!) {
  121. UIApplication.shared.openURL(phoneURL!)
  122. }else{
  123. self.showError(title: "打电话失败")
  124. }
  125. })
  126. let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
  127. alertController.addAction(phoneAction)
  128. alertController.addAction(smsAction)
  129. alertController.addAction(cancelAction)
  130. self.present(alertController, animated: true, completion: nil)
  131. }
  132. })
  133. <<< LabelRow("weixin"){
  134. $0.title = "微信"
  135. $0.value = contact!.weixin
  136. }
  137. <<< LabelRow("qq"){
  138. $0.title = "QQ"
  139. $0.value = contact!.qq
  140. }
  141. <<< LabelRow("weibo"){
  142. $0.title = "微博"
  143. $0.value = ""
  144. }
  145. }
  146. }