SearchAplikasiVC.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // SearchAplikasiVC.swift
  3. // Sirani
  4. //
  5. // Created by Hendi on 21/06/23.
  6. // Copyright © 2026 PT. Mitra Sinerji Teknoindo. All rights reserved.
  7. //
  8. import UIKit
  9. protocol SearchAplikasiDelegate {
  10. func onSearch(search: String, status: String, jenisLabel: String)
  11. }
  12. class SearchAplikasiVC: UIViewController {
  13. // Outlets / Views
  14. @IBOutlet weak var inputSearch: RoundTextField!
  15. @IBOutlet weak var optionsLayoutTV: UITableView!
  16. @IBOutlet weak var optionsLayout: UIView!
  17. @IBOutlet weak var optionsBg: UIView!
  18. @IBOutlet weak var btnStatusOptions: UIButton!
  19. // Initialize
  20. var delegate: SearchAplikasiDelegate?
  21. // constants vallue data
  22. private let jenisSertifikatOptionItems = [
  23. OptionItem(label: "Semua", value: "apl_all"),
  24. OptionItem(label: "Draft Customer", value: "apl_draft_cust"),
  25. OptionItem(label: "Pemeriksaan Dokumen", value: "apl_pemeriksaan_dok"),
  26. OptionItem(label: "Tunggu Disposisi", value: "apl_tunggu_disposisi"),
  27. OptionItem(label: "Evaluasi Dokumen", value: "apl_eval_dok"),
  28. OptionItem(label: "Rekomendasi Aplikasi", value: "apl_rekomendasi_apl"),
  29. OptionItem(label: "Persetujuan Aplikasi", value: "apl_persetujuan_apl"),
  30. // OptionItem(label: "Persetujuan Penerbitan", value: ""),
  31. OptionItem(label: "Proses Sertifikasi", value: "apl_proses_sertifikasi"),
  32. OptionItem(label: "Pembayaran SP2", value: "apl_pembayaran_sp2"),
  33. OptionItem(label: "Sertifikat Dicetak", value: "apl_sertifikat_dicetak"),
  34. OptionItem(label: "Permohonan Tidak Lengkap", value: "apl_permohonan_tidak_lengkap"),
  35. OptionItem(label: "Draft Ditolak", value: "apl_draft_ditolak"),
  36. OptionItem(label: "SP2 Kadaluarsa", value: "apl_sp2_kadaluarsa"),
  37. OptionItem(label: "Batal", value: "apl_batal")
  38. ]
  39. private let OPTION_JENIS_SERTIFIKAT_ID = 1
  40. // Others
  41. private var selectedOptions = 0
  42. private var selectedOptionItems = [OptionItem]()
  43. private var optionsShown = false
  44. // Result Values
  45. private var search = ""
  46. private var status = ""
  47. private var jenisLabel = "Semua"
  48. // View Lifecycles
  49. override var preferredStatusBarStyle: UIStatusBarStyle {
  50. return .lightContent
  51. }
  52. override func viewWillAppear(_ animated: Bool) {
  53. btnStatusOptions.layer.masksToBounds = false
  54. btnStatusOptions.layer.shadowColor = #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1)
  55. btnStatusOptions.layer.shadowOpacity = 0.5
  56. btnStatusOptions.layer.shadowOffset = CGSize(width: 1, height: 1)
  57. btnStatusOptions.layer.shadowRadius = 1
  58. status = jenisSertifikatOptionItems[0].value as! String
  59. jenisLabel = jenisSertifikatOptionItems[0].label
  60. btnStatusOptions.setTitle(jenisLabel, for: .normal)
  61. hideOptions()
  62. optionsLayoutTV.bringSubviewToFront(optionsBg)
  63. let onOptionsBgTapped = UITapGestureRecognizer(target: self, action: #selector(hideOptions))
  64. optionsBg.addGestureRecognizer(onOptionsBgTapped)
  65. }
  66. override func viewDidLoad() {
  67. super.viewDidLoad()
  68. optionsLayoutTV.delegate = self
  69. optionsLayoutTV.dataSource = self
  70. optionsLayoutTV.tableFooterView = UIView()
  71. }
  72. @IBAction func onInputSearchKeyTap(_ sender: Any) {
  73. view.endEditing(true)
  74. }
  75. @IBAction func unwindToAplikasi(_ sender: Any) {
  76. if optionsShown {
  77. hideOptions()
  78. } else {
  79. performSegue(withIdentifier: "unwindSearchToAplikasiSegueId", sender: self)
  80. }
  81. }
  82. @IBAction func onJenisSertifikatOptionsTapped(_ sender: Any) {
  83. selectedOptions = OPTION_JENIS_SERTIFIKAT_ID
  84. selectedOptionItems.removeAll()
  85. selectedOptionItems += jenisSertifikatOptionItems
  86. optionsLayoutTV.reloadData()
  87. showOptions()
  88. }
  89. @IBAction func onResetTapped(_ sender: Any) {
  90. search = ""
  91. status = ""
  92. jenisLabel = "Semua"
  93. inputSearch.text = ""
  94. btnStatusOptions.setTitle(jenisLabel, for: .normal)
  95. }
  96. @IBAction func onSearchTapped(_ sender: Any) {
  97. if let searchText = inputSearch.getText() {
  98. search = searchText
  99. }
  100. self.delegate?.onSearch(search: search, status: status, jenisLabel: jenisLabel)
  101. performSegue(withIdentifier: "unwindSearchToAplikasiSegueId", sender: self)
  102. }
  103. private func showOptions() {
  104. optionsLayout.show()
  105. optionsShown = true
  106. }
  107. @objc private func hideOptions() {
  108. optionsLayout.hide()
  109. optionsShown = false
  110. }
  111. }
  112. extension SearchAplikasiVC: UITableViewDelegate, UITableViewDataSource {
  113. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  114. return selectedOptionItems.count
  115. }
  116. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  117. if let cell = tableView.dequeueReusableCell(withIdentifier: "searchAplikasiCell", for: indexPath) as? OptionsCell {
  118. let optionItem = selectedOptionItems[indexPath.row]
  119. cell.updateViews(item: optionItem)
  120. return cell
  121. } else {
  122. return OptionsCell()
  123. }
  124. }
  125. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  126. if selectedOptions == OPTION_JENIS_SERTIFIKAT_ID {
  127. status = selectedOptionItems[indexPath.row].value as! String
  128. jenisLabel = selectedOptionItems[indexPath.row].label
  129. btnStatusOptions.setTitle(jenisLabel, for: .normal)
  130. }
  131. hideOptions()
  132. }
  133. }