QSLContactSendFailAlertView.swift 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // QSLContactSendFailAlertView.swift
  3. // QuickSearchLocation
  4. //
  5. // Created by Destiny on 2024/12/12.
  6. //
  7. import UIKit
  8. class QSLContactSendFailAlertView: UIView {
  9. var contactList: [String]?
  10. lazy var contentView: UIView = {
  11. let contentView = UIView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW - 60.rpx, height: 152.0.rpx))
  12. contentView.backgroundColor = .white
  13. contentView.addRadius(radius: 8.rpx)
  14. return contentView
  15. }()
  16. lazy var titleLabel: UILabel = {
  17. let label = UILabel()
  18. label.text("添加紧急联系人")
  19. label.mediumFont(17)
  20. label.textColor = QSLColor.Color_202020
  21. return label
  22. }()
  23. lazy var contentLabel: UILabel = {
  24. let label = UILabel()
  25. label.text("部分号码发送失败,请检查号码重试!")
  26. label.font(15)
  27. label.textColor = .hexStringColor(hexString: "#404040")
  28. return label
  29. }()
  30. lazy var infoView: UIView = {
  31. let view = UIView()
  32. view.addRadius(radius: 4.rpx)
  33. view.backgroundColor = QSLColor.backGroundColor
  34. view.addBorder(borderWidth: 1.rpx, borderColor: .hexStringColor(hexString: "#F2F2F2"))
  35. return view
  36. }()
  37. lazy var infoTableView: UITableView = {
  38. let tableView = UITableView(frame: .zero, style: .grouped)
  39. tableView.backgroundColor = QSLColor.backGroundColor
  40. tableView.separatorStyle = .none
  41. tableView.showsVerticalScrollIndicator = false
  42. tableView.delegate = self
  43. tableView.dataSource = self
  44. tableView.tableViewNeverAdjustContentInset()
  45. tableView.bounces = true
  46. tableView.isUserInteractionEnabled = true
  47. tableView.isScrollEnabled = true
  48. tableView.contentInsetAdjustmentBehavior = .never
  49. tableView.register(cellClass: QSLContactFailCell.self)
  50. return tableView
  51. }()
  52. lazy var oneButton: UIButton = {
  53. let btn = UIButton()
  54. btn.addRadius(radius: 20.rpx)
  55. btn.title("我知道了")
  56. btn.textColor(.white)
  57. btn.mediumFont(16)
  58. btn.gradientBackgroundColor(color1: .hexStringColor(hexString: "#15CBA1"), color2: .hexStringColor(hexString: "#1FE0BA"), width: 150.rpx, height: 40.rpx, direction: .horizontal)
  59. btn.addTarget(self, action: #selector(oneBtnAction), for: .touchUpInside)
  60. return btn
  61. }()
  62. lazy var closeButton: UIButton = {
  63. let btn = UIButton()
  64. btn.setBackgroundImage(UIImage(named: "public_btn_close_AAA"), for: .normal)
  65. btn.addTarget(self, action: #selector(removeView), for: .touchUpInside)
  66. return btn
  67. }()
  68. class func alert(view: UIView, contactList: [String]) {
  69. let window = QSLContactSendFailAlertView(frame: CGRect(x: 0, y: 0, width: QSLConst.qsl_kScreenW, height: QSLConst.qsl_kScreenH))
  70. window.contactList = contactList
  71. window.infoTableView.reloadData()
  72. let height = 20.rpx * contactList.count + 32.rpx + 10.rpx * (contactList.count - 1)
  73. window.infoView.snp.updateConstraints { make in
  74. make.height.equalTo(height)
  75. }
  76. window.contentView.snp.updateConstraints { make in
  77. make.height.equalTo(187.rpx + height)
  78. }
  79. view.addSubview(window)
  80. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) {
  81. window.backgroundColor = .hexStringColor(hexString: "#000000", alpha: 0.7)
  82. window.contentView.isHidden = false
  83. }
  84. }
  85. override init(frame: CGRect) {
  86. super.init(frame: frame)
  87. initUI()
  88. }
  89. required init?(coder: NSCoder) {
  90. fatalError("init(coder:) has not been implemented")
  91. }
  92. // 单按钮点击事件
  93. @objc func oneBtnAction() {
  94. removeView()
  95. }
  96. // 移除
  97. @objc func removeView() {
  98. UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.95, initialSpringVelocity: 0.05) { [weak self] in
  99. self?.backgroundColor = UIColor.init(white: 0, alpha: 0)
  100. self?.contentView.isHidden = true
  101. } completion: { [weak self] finished in
  102. self?.removeFromSuperview()
  103. }
  104. }
  105. }
  106. extension QSLContactSendFailAlertView: UITableViewDelegate, UITableViewDataSource {
  107. func numberOfSections(in tableView: UITableView) -> Int {
  108. return self.contactList?.count ?? 0
  109. }
  110. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  111. return 1
  112. }
  113. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  114. let cell = tableView.dequeueReusableCell(cellType: QSLContactFailCell.self, cellForRowAt: indexPath)
  115. cell.selectionStyle = .none
  116. if let phone = self.contactList?[indexPath.section] {
  117. cell.config(phone: phone)
  118. }
  119. return cell
  120. }
  121. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  122. return 20.rpx
  123. }
  124. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  125. return 0.0001
  126. }
  127. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  128. return 10.rpx
  129. }
  130. }
  131. extension QSLContactSendFailAlertView {
  132. func initUI() {
  133. addSubview(contentView)
  134. contentView.snp.makeConstraints { make in
  135. make.width.equalTo(QSLConst.qsl_kScreenW - 60.rpx)
  136. make.height.equalTo(203.0.rpx)
  137. make.center.equalToSuperview()
  138. }
  139. contentView.addSubview(titleLabel)
  140. titleLabel.snp.makeConstraints { make in
  141. make.centerX.equalToSuperview()
  142. make.top.equalTo(24.rpx)
  143. }
  144. contentView.addSubview(contentLabel)
  145. contentLabel.snp.makeConstraints { make in
  146. make.centerX.equalToSuperview()
  147. make.top.equalTo(titleLabel.snp.bottom).offset(16.rpx)
  148. }
  149. contentView.addSubview(infoView)
  150. infoView.snp.makeConstraints { make in
  151. make.left.equalTo(24.rpx)
  152. make.right.equalTo(-24.rpx)
  153. make.top.equalTo(contentLabel.snp.bottom).offset(8.rpx)
  154. make.height.equalTo(82.rpx)
  155. }
  156. infoView.addSubview(infoTableView)
  157. infoTableView.snp.makeConstraints { make in
  158. make.left.equalTo(0)
  159. make.right.equalTo(0)
  160. make.top.equalTo(16.rpx)
  161. make.bottom.equalTo(-16.rpx)
  162. }
  163. contentView.addSubview(oneButton)
  164. oneButton.snp.makeConstraints { make in
  165. make.size.equalTo(CGSize(width: 150.rpx, height: 40.rpx))
  166. make.centerX.equalToSuperview()
  167. make.bottom.equalTo(-24.rpx)
  168. }
  169. contentView.addSubview(closeButton)
  170. closeButton.snp.makeConstraints { make in
  171. make.size.equalTo(CGSize(width: 24.rpx, height: 24.rpx))
  172. make.top.equalTo(12.rpx)
  173. make.right.equalTo(-12.rpx)
  174. }
  175. }
  176. }