OOContactSearchCell.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //
  2. // OOContactSearchCell.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/11/28.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. class OOContactSearchCell: UITableViewCell,Configurable {
  10. @IBOutlet weak var iconImageView: UIImageView!
  11. @IBOutlet weak var titleLabel: UILabel!
  12. @IBOutlet weak var subTitleLabel: UILabel!
  13. open var viewModel:OOContactSearchViewModel?
  14. override func awakeFromNib() {
  15. super.awakeFromNib()
  16. // Initialization code
  17. }
  18. override func setSelected(_ selected: Bool, animated: Bool) {
  19. super.setSelected(selected, animated: animated)
  20. // Configure the view for the selected state
  21. }
  22. func config(withItem item: Any?) {
  23. let model = item as! NSObject
  24. if model.isKind(of: OOUnitModel.self) {
  25. let uModel = item as! OOUnitModel
  26. let first = uModel.name![0..<1]
  27. if let iconImage = firstWordImage(first) {
  28. self.iconImageView.image = iconImage
  29. }
  30. let number = uModel.subDirectUnitCount ?? 0
  31. if number > 0 {
  32. self.titleLabel.text = "\(uModel.name!)(\(number.description))"
  33. }else{
  34. self.titleLabel.text = uModel.name!
  35. }
  36. if let desc = uModel.desc {
  37. self.subTitleLabel.text = desc.count > 0 ? desc : "此组织没有描述信息"
  38. }else{
  39. self.subTitleLabel.text = "此组织没有描述信息"
  40. }
  41. }else if(model.isKind(of: OOGroupModel.self)){
  42. let gModel = item as! OOGroupModel
  43. let number = gModel.groupList?.count ?? 0
  44. //title
  45. if number > 0 {
  46. self.titleLabel.text = "\(gModel.name!)(\(number.description))"
  47. }else{
  48. self.titleLabel.text = gModel.name!
  49. }
  50. //subtitle
  51. if let desc = gModel.desc {
  52. self.subTitleLabel.text = desc.count > 0 ? desc : "此群组没有描述信息"
  53. }else{
  54. self.subTitleLabel.text = "此群组没有描述信息"
  55. }
  56. }else if(model.isKind(of: OOPersonModel.self)){
  57. let pModel = model as! OOPersonModel
  58. // self.iconImageView.sd_setIndicatorStyle(.gray)
  59. // self.iconImageView.sd_setShowActivityIndicatorView(true)
  60. viewModel?.getIconOfPerson(pModel, compeletionBlock: { (iconImage, errMSg) in
  61. //self.iconImageView.sd_setShowActivityIndicatorView(false)
  62. self.iconImageView.image = iconImage
  63. })
  64. self.titleLabel.text = pModel.name
  65. self.subTitleLabel.text = pModel.mobile
  66. }
  67. }
  68. private func firstWordImage(_ word:String) -> UIImage? {
  69. let size = CGSize(width: 40, height: 40)
  70. let textColor = UIColor.white
  71. let backColor = O2ThemeManager.color(for: "Base.base_color")!
  72. let font = UIFont(name: "PingFangSC-Regular", size: 18)
  73. return word.getTextImage(size, textColor: textColor, backColor: backColor, textFont: font!)
  74. }
  75. }