PhotoDetailViewController.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // PhotoDetailViewController.swift
  3. // MCPlus
  4. //
  5. // Created by seo ha on 07/02/2019.
  6. // Copyright © 2019 KangSH. All rights reserved.
  7. //
  8. import UIKit
  9. class PhotoDetailViewController: UIViewController {
  10. @IBOutlet weak var closeButton: UIImageView!{
  11. didSet{
  12. closeButton.addTapGestureRecognizer(action: self.closeAction)
  13. }
  14. }
  15. @IBOutlet weak var scrollView: UIScrollView!{
  16. didSet{
  17. scrollView.delegate = self
  18. }
  19. }
  20. @IBOutlet weak var imageView: UIImageView!
  21. @IBOutlet weak var patientIdLabel :UILabel!{
  22. didSet{
  23. patientIdLabel.text = self.photo?.user?.patientId
  24. }
  25. }
  26. @IBOutlet weak var patientNmLabel :UILabel!{
  27. didSet{
  28. patientNmLabel.text = self.photo?.user?.patientNm
  29. }
  30. }
  31. @IBOutlet weak var ageGenderLabel :UILabel!{
  32. didSet{
  33. ageGenderLabel.text = "\(self.photo?.user?.age ?? "") / \(self.photo?.user?.gender ?? "")"
  34. }
  35. }
  36. @IBOutlet weak var titleLabel: UILabel!{
  37. didSet{
  38. titleLabel.text = self.photo?.key
  39. }
  40. }
  41. @IBOutlet weak var exitButton: UIButton!{
  42. didSet{
  43. exitButton.addTapGestureRecognizer(action: self.closeAction)
  44. }
  45. }
  46. @IBOutlet weak var uploadButton: UIButton!{
  47. didSet{
  48. if self.photo?.isSended == true{
  49. uploadButton.isHidden = true
  50. }
  51. uploadButton.addTapGestureRecognizer(action: self.uploadAction)
  52. }
  53. }
  54. var image:UIImage?
  55. var photo:Photo?
  56. var callBack:(()->Void)?
  57. }
  58. extension PhotoDetailViewController:UIScrollViewDelegate{
  59. override func viewDidLoad() {
  60. super.viewDidLoad()
  61. self.navigationController?.isNavigationBarHidden = true
  62. if let img = self.image{
  63. self.imageView.image = img
  64. }
  65. }
  66. func closeAction(){
  67. self.navigationController?.popViewController(animated: true)
  68. self.callBack?()
  69. }
  70. func viewForZooming(in scrollView: UIScrollView) -> UIView? {
  71. return scrollView.subviews.first
  72. }
  73. func uploadAction(){
  74. guard let photo = self.photo else {
  75. return
  76. }
  77. self.uploadItem(photo)
  78. }
  79. func uploadItem(_ photo:Photo){
  80. var param = [String:Any]()
  81. param["hospitalCd"] = photo.user?.hospitalCD ?? ""
  82. param["userId"] = photo.user?.userId ?? ""
  83. param["patientId"] = photo.user?.patientId ?? ""
  84. param["deptCd"] = photo.user?.deptCd ?? ""
  85. param["doctorId"] = photo.user?.doctorId ?? ""
  86. param["searchCls"] = photo.user?.treatCls ?? ""
  87. param["thumbnail"] = ""
  88. param["excutionDtTm"] = Date().fromString(format: "yyyy-MM-dd hh:mm:ss")
  89. param["excutionDtTm"] = photo.user?.visitDt ?? ""
  90. if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
  91. //원본 이미지 찾기
  92. let origin = dir.appendingPathComponent("kunkuk/\(photo.file ?? "")")
  93. if let data = try? Data(contentsOf: origin){
  94. param["image"] = data.base64EncodedString()
  95. }
  96. }
  97. let url = "\(MCarePlusConstants.DOMAIN_NAME)/\(photo.user?.serviceUrl ?? "")"
  98. APIClient(url)
  99. .param(reqParam: param)
  100. .enType(.json)
  101. .connect { [weak self](result:[String:Any]) in
  102. //성공일시
  103. if result["returnCd"] as? String == "0000"{
  104. photo.isSended = true
  105. photo.update()
  106. self?.showAlert("서버에 업로드 되었습니다.", "", "확인", nil, { action in
  107. self?.closeAction()
  108. })
  109. }else{
  110. self?.showAlert("서버업로드에 실패하였습니다. 관리자에게 문의하여 주세요.", "", "확인", nil, { action in
  111. self?.closeAction()
  112. })
  113. }
  114. }
  115. }
  116. }