OOLinkManViewModel.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. switch result {
  32. case .success(let res):
  33. guard let image = UIImage(data: res.data) else {
  34. compeletionBlock(#imageLiteral(resourceName: "icon_?"),"image transform error")
  35. return
  36. }
  37. compeletionBlock(image,nil)
  38. break
  39. case .failure(let err):
  40. compeletionBlock(#imageLiteral(resourceName: "icon_?"),err.errorDescription)
  41. break
  42. }
  43. }
  44. }
  45. }
  46. extension OOLinkManViewModel{
  47. func numberOfSections() -> Int {
  48. return 1
  49. }
  50. func numberOfRowsInSection(_ section: Int) -> Int {
  51. return personInfoData.count
  52. }
  53. func nodeForIndexPath(_ indexPath:IndexPath) -> OOPersonCellModel? {
  54. return personInfoData[indexPath.row]
  55. }
  56. func headerHeightOfSection(_ section:Int) -> CGFloat {
  57. return 10.0
  58. }
  59. func footerHeightOfSection(_ section:Int) -> CGFloat {
  60. return 10.0
  61. }
  62. func tableHeaderView() -> UIView{
  63. let headerView = Bundle.main.loadNibNamed("OOLinkManInfoHeader", owner: self, options: nil)![0] as! OOLinkManInfoHeader
  64. headerView.configHeaderOfPerson(self,currentPerson!)
  65. return headerView
  66. }
  67. func headerTypeOfSection(_ section:Int) -> UIView {
  68. return UIView()
  69. }
  70. }