OOLinkManViewModel.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // OOLinkManViewModel.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/11/23.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. //定义简易类型
  10. typealias OOPersonCellModel = (title:String,value:String,actionIconName:String?,actionURL:String?)
  11. class OOLinkManViewModel: NSObject {
  12. private let contactAPI = OOMoyaProvider<OOContactAPI>()
  13. var currentPerson:OOPersonModel?{
  14. didSet {
  15. personInfoData.append((title:"姓名",value:(currentPerson?.name)!,nil,nil))
  16. personInfoData.append((title:"员工号",value:(currentPerson?.employee)!,nil,nil))
  17. personInfoData.append((title:"唯一编码",value:(currentPerson?.unique)!,nil,nil))
  18. personInfoData.append((title:"联系电话",value:(currentPerson?.mobile)!,"Shape","tel:\((currentPerson?.mobile)!)"))
  19. personInfoData.append((title:"电子邮件",value:(currentPerson?.mail)!,"icon_email","mailto:\((currentPerson?.mail)!)"))
  20. var dept:[String] = []
  21. currentPerson?.woIdentityList?.forEach({ (iModel) in
  22. dept.append(iModel.unitName!)
  23. })
  24. personInfoData.append((title:"部门",value:dept.joined(separator: ","),nil,nil))
  25. }
  26. }
  27. private var personInfoData:[OOPersonCellModel] = []
  28. // MARK: - 获取icon
  29. func getIconOfPerson(_ person:OOPersonModel,compeletionBlock:@escaping (_ image:UIImage?,_ errMsg:String?) -> Void) {
  30. contactAPI.request(.iconByPerson(person.id!)) { (result) in
  31. if let err = result.error {
  32. compeletionBlock(#imageLiteral(resourceName: "icon_?"),err.errorDescription)
  33. }else{
  34. let data = result.value?.data
  35. guard let image = UIImage(data: data!) else {
  36. compeletionBlock(#imageLiteral(resourceName: "icon_?"),"image transform error")
  37. return
  38. }
  39. compeletionBlock(image,nil)
  40. }
  41. }
  42. }
  43. }
  44. extension OOLinkManViewModel{
  45. func numberOfSections() -> Int {
  46. return 1
  47. }
  48. func numberOfRowsInSection(_ section: Int) -> Int {
  49. return personInfoData.count
  50. }
  51. func nodeForIndexPath(_ indexPath:IndexPath) -> OOPersonCellModel? {
  52. return personInfoData[indexPath.row]
  53. }
  54. func headerHeightOfSection(_ section:Int) -> CGFloat {
  55. return 10.0
  56. }
  57. func footerHeightOfSection(_ section:Int) -> CGFloat {
  58. return 10.0
  59. }
  60. func tableHeaderView() -> UIView{
  61. let headerView = Bundle.main.loadNibNamed("OOLinkManInfoHeader", owner: self, options: nil)![0] as! OOLinkManInfoHeader
  62. headerView.configHeaderOfPerson(self,currentPerson!)
  63. return headerView
  64. }
  65. func headerTypeOfSection(_ section:Int) -> UIView {
  66. return UIView()
  67. }
  68. }