UnitPickerTableViewCell.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //
  2. // UnitPickerTableViewCell.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/8/13.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. protocol UnitPickerNextBtnDelegate {
  10. func next(unitName: String?, unitDistinguishedName: String?)
  11. }
  12. class UnitPickerTableViewCell: UITableViewCell {
  13. var delegate: UnitPickerNextBtnDelegate?
  14. lazy public var trueImage: UIImage = {
  15. return UIImage(named: "selected")!
  16. }()
  17. lazy public var falseImage: UIImage = {
  18. return UIImage(named: "unselected")!
  19. }()
  20. @IBAction func clickNextBtn(_ sender: UIButton) {
  21. if delegate != nil {
  22. delegate?.next(unitName: unitInfo?.name, unitDistinguishedName: unitInfo?.distinguishedName)
  23. }
  24. }
  25. @IBOutlet weak var nextLevelBtn: UIButton!
  26. @IBOutlet weak var unitIconLabel: UILabel!
  27. @IBOutlet weak var unitNameLabel: UILabel!
  28. @IBOutlet weak var checkImageView: UIImageView!
  29. @IBOutlet weak var unitIconBgImageView: UIImageView!
  30. private var unitInfo: OOUnitModel?
  31. override func awakeFromNib() {
  32. super.awakeFromNib()
  33. self.checkImageView.image = falseImage
  34. self.unitIconBgImageView.image = O2ThemeManager.image(for: "Icon.pic_oval")
  35. }
  36. override func setSelected(_ selected: Bool, animated: Bool) {
  37. super.setSelected(selected, animated: animated)
  38. }
  39. func loadUnitInfo(info: OOUnitModel, checked: Bool) {
  40. self.unitInfo = info
  41. if let name = info.name {
  42. unitIconLabel.text = NSString(string: name).substring(to: 1)
  43. }
  44. self.unitIconLabel.isHidden = false
  45. self.checkImageView.isHidden = false
  46. self.nextLevelBtn.isHidden = false
  47. self.unitIconBgImageView.layer.masksToBounds = true
  48. self.unitIconBgImageView.layer.cornerRadius = self.unitIconBgImageView.width / 2.0
  49. self.unitIconBgImageView.image = O2ThemeManager.image(for: "Icon.pic_oval")
  50. self.unitNameLabel.text = info.name
  51. if checked {
  52. self.checkImageView.image = trueImage
  53. }else {
  54. self.checkImageView.image = falseImage
  55. }
  56. }
  57. func loadUnitNotCheck(info: OOUnitModel) {
  58. self.unitInfo = info
  59. if let name = info.name {
  60. unitIconLabel.text = NSString(string: name).substring(to: 1)
  61. }
  62. self.unitIconBgImageView.layer.masksToBounds = true
  63. self.unitIconBgImageView.layer.cornerRadius = self.unitIconBgImageView.width / 2.0
  64. self.unitIconBgImageView.image = O2ThemeManager.image(for: "Icon.pic_oval")
  65. self.unitNameLabel.text = info.name
  66. self.checkImageView.isHidden = true
  67. self.unitIconLabel.isHidden = false
  68. self.nextLevelBtn.isHidden = false
  69. }
  70. func loadIdentity(identity: OOIdentityModel, checked: Bool) {
  71. self.checkImageView.isHidden = false
  72. self.unitIconLabel.isHidden = true
  73. self.nextLevelBtn.isHidden = true
  74. self.unitNameLabel.text = identity.name
  75. self.unitIconBgImageView.layer.masksToBounds = true
  76. self.unitIconBgImageView.layer.cornerRadius = self.unitIconBgImageView.width / 2.0
  77. let urlstr = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personIconByNameQueryV2, parameter: ["##name##":identity.person as AnyObject], generateTime: false)
  78. let url = URL(string: urlstr!)
  79. self.unitIconBgImageView.hnk_setImageFromURL(url!)
  80. if checked {
  81. self.checkImageView.image = trueImage
  82. }else {
  83. self.checkImageView.image = falseImage
  84. }
  85. }
  86. }