PhotoDetailViewController.swift 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. @IBOutlet weak var deptNmLabel: UILabel!{
  55. didSet{
  56. deptNmLabel.text = self.photo?.user?.deptNm
  57. }
  58. }
  59. @IBOutlet weak var treatClsKrLabel: UILabel!{
  60. didSet{
  61. treatClsKrLabel.text = self.photo?.user?.treatClsKr
  62. }
  63. }
  64. @IBOutlet weak var doctorNmLabel: UILabel!{
  65. didSet{
  66. doctorNmLabel.text = self.photo?.user?.doctorNm
  67. }
  68. }
  69. var image:UIImage?
  70. var photo:Photo?
  71. var callBack:(()->Void)?
  72. }
  73. extension PhotoDetailViewController:UIScrollViewDelegate{
  74. override func viewDidLoad() {
  75. super.viewDidLoad()
  76. self.navigationController?.isNavigationBarHidden = true
  77. if let img = self.image{
  78. self.imageView.image = img
  79. }
  80. }
  81. func closeAction(){
  82. self.navigationController?.popViewController(animated: true)
  83. self.callBack?()
  84. }
  85. func viewForZooming(in scrollView: UIScrollView) -> UIView? {
  86. return scrollView.subviews.first
  87. }
  88. func uploadAction(){
  89. guard let photo = self.photo else {
  90. return
  91. }
  92. self.uploadItem(photo)
  93. }
  94. func uploadItem(_ photo:Photo){
  95. var param = [String:Any]()
  96. param["hospitalCd"] = photo.user?.hospitalCD ?? ""
  97. param["userId"] = photo.user?.userId ?? ""
  98. param["patientId"] = photo.user?.patientId ?? ""
  99. param["deptCd"] = photo.user?.deptCd ?? ""
  100. param["doctorId"] = photo.user?.doctorId ?? ""
  101. param["searchCls"] = photo.user?.treatCls ?? ""
  102. param["thumbnail"] = ""
  103. param["excutionDtTm"] = Date().fromString(format: "yyyy-MM-dd hh:mm:ss")
  104. param["visitDt"] = photo.user?.visitDt ?? ""
  105. if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first {
  106. //원본 이미지 찾기
  107. let origin = dir.appendingPathComponent("kunkuk/\(photo.file ?? "")")
  108. if let data = try? Data(contentsOf: origin){
  109. param["image"] = String(data: data, encoding: .utf8)
  110. }
  111. }
  112. let url = "\(MCarePlusConstants.DOMAIN_NAME)/\(photo.user?.serviceUrl ?? "")"
  113. APIClient(url)
  114. .param(reqParam: param)
  115. .enType(.json)
  116. .connect { [weak self](result:[String:Any]) in
  117. guard let `result` = result["result"] as? [[String:Any]] else{ return }
  118. let returnCd = result.first?["returnCd"] as? String
  119. let returnMsg = result.first?["returnMsg"] as? String
  120. //성공일시
  121. if returnCd == "0000" {
  122. photo.isSended = true
  123. photo.update()
  124. self?.showAlert("전송 완료되었습니다.", "", "확인", nil, { action in
  125. self?.closeAction()
  126. })
  127. }else{
  128. self?.showAlert(returnMsg ?? "전송 실패하였습니다.", "", "확인", nil, { action in
  129. self?.closeAction()
  130. })
  131. }
  132. }
  133. }
  134. }