123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // ContactPersonInfoController.swift
- // O2Platform
- //
- // Created by 刘振兴 on 16/7/15.
- // Copyright © 2016年 zoneland. All rights reserved.
- //
- import UIKit
- import Alamofire
- import AlamofireImage
- import AlamofireObjectMapper
- import SwiftyJSON
- import ObjectMapper
- import Eureka
- import CocoaLumberjack
- class ContactPersonInfoController: FormViewController {
-
-
- var myPersonURL:String?
-
- var identity:IdentityV2? {
- didSet {
- self.myPersonURL = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personInfoByNameQuery, parameter: ["##name##":identity!.person! as AnyObject])
- }
- }
-
- var isLoadPerson:Bool = true
-
- var contact:PersonV2? {
- didSet {
- isLoadPerson = false
- }
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- ImageRow.defaultCellUpdate = { cell, row in
- cell.accessoryView?.layer.cornerRadius = 17
- cell.accessoryView?.frame = CGRect(x: 0, y: 0, width: 34, height: 34)
- cell.textLabel?.font = UIFont(name: "PingFangSC-Light", size: 12.0)
- cell.textLabel?.textColor = RGB(155, g: 155, b: 155)
- }
-
- LabelRow.defaultCellUpdate = {
- cell,row in
- cell.textLabel?.font = UIFont(name: "PingFangSC-Light", size: 12.0)
- cell.textLabel?.textColor = RGB(155, g: 155, b: 155)
- cell.accessoryType = .disclosureIndicator
- }
- EmailRow.defaultCellUpdate = {
- cell,row in
- cell.textLabel?.font = UIFont(name: "PingFangSC-Light", size: 12.0)
- cell.textLabel?.textColor = RGB(155, g: 155, b: 155)
- cell.accessoryType = .disclosureIndicator
-
- }
-
- PhoneRow.defaultCellUpdate = {
- cell,row in
- cell.textLabel?.font = UIFont(name: "PingFangSC-Light", size: 12.0)
- cell.textLabel?.textColor = RGB(155, g: 155, b: 155)
- cell.accessoryType = .disclosureIndicator
- }
-
- isLoadPerson==true ?loadPersonInfo(nil):loadDataCell()
-
- }
-
- func loadPersonInfo(_ sender: AnyObject?){
- self.showLoading()
- AF.request(myPersonURL!).responseJSON {
- response in
- switch response.result {
- case .success( let val):
- let json = JSON(val)["data"]
- self.contact = Mapper<PersonV2>().map(JSONString:json.description)!
- self.loadDataCell()
- self.hideLoading()
- case .failure(let err):
- DDLogError(err.localizedDescription)
- self.showError(title: L10n.errorWithMsg(err.localizedDescription))
- }
-
- }
- }
-
- func loadDataCell(){
-
- form +++ Section()
- <<< ImageRow("icon"){ row in
- row.title = "头像"
- let urlstr = AppDelegate.o2Collect.generateURLWithAppContextKey(ContactContext.contactsContextKeyV2, query: ContactContext.personIconByNameQueryV2, parameter: ["##name##":contact?.unique as AnyObject])
- let url = URL(string: urlstr!)
- //从网络获取数据流
- if let data = try? Data(contentsOf: url!){
- row.value = UIImage(data: data)
- }else{
- row.value = UIImage(named: "personDefaultIcon")
- }
-
- row.disabled = true
- }
- <<< LabelRow("employee"){
- $0.title = "工号"
- $0.value = contact!.employee
- }
- <<< LabelRow("display"){
- $0.title = "名字"
- $0.value = contact!.name
- }
- <<< LabelRow("genderType"){
- $0.title = "性别"
- $0.value = contact!.genderType == "f" ? "女":"男"
- }
-
- +++ Section()
- <<< LabelRow("mail"){
- $0.title = "Email"
- $0.value = contact!.mail
- }
- <<< LabelRow("mobile"){
- $0.title = "手机"
- $0.value = contact!.mobile
- }.onCellSelection({ (cell, row) in
- if let phone = row.value {
- let alertController = UIAlertController(title: "", message: "呼叫联系人?", preferredStyle: .alert)
- let smsAction = UIAlertAction(title: "发短信", style: .default, handler: { _ in
- let smsURL = URL(string: "sms://\(phone)")
- if UIApplication.shared.canOpenURL(smsURL!) {
- UIApplication.shared.openURL(smsURL!)
- }else{
- self.showError(title: "发短信失败")
- }
- })
- let phoneAction = UIAlertAction(title: "打电话", style: .default, handler: { _ in
- let phoneURL = URL(string: "tel://\(phone)")
- if UIApplication.shared.canOpenURL(phoneURL!) {
- UIApplication.shared.openURL(phoneURL!)
- }else{
- self.showError(title: "打电话失败")
- }
- })
- let cancelAction = UIAlertAction(title: "取消", style: .cancel, handler: nil)
- alertController.addAction(phoneAction)
- alertController.addAction(smsAction)
- alertController.addAction(cancelAction)
- self.present(alertController, animated: true, completion: nil)
- }
- })
- <<< LabelRow("weixin"){
- $0.title = "微信"
- $0.value = contact!.weixin
- }
- <<< LabelRow("qq"){
- $0.title = "QQ"
- $0.value = contact!.qq
- }
- <<< LabelRow("weibo"){
- $0.title = "微博"
- $0.value = ""
- }
- }
-
-
-
-
- }
|