Commit aa2a3762 authored by Steven杜宇's avatar Steven杜宇

// alertView

parent aeaf07d5
......@@ -64,6 +64,7 @@
049A48A82B49417300D0C641 /* YHAboutUsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */; };
049A48AA2B49536000D0C641 /* YHAboutUsAdvantageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 049A48A92B49536000D0C641 /* YHAboutUsAdvantageCell.swift */; };
04A7BC8F2B6B2BC2000E8D47 /* YHFamilyRequestViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04A7BC8E2B6B2BC2000E8D47 /* YHFamilyRequestViewModel.swift */; };
04A7BC912B6B7B89000E8D47 /* YHTwoOptionAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04A7BC902B6B7B89000E8D47 /* YHTwoOptionAlertView.swift */; };
04AF58C42B4FC51C0066011A /* YHLocalizable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04AF58C32B4FC51C0066011A /* YHLocalizable.swift */; };
04D765732B6A173C0055ECBB /* YHSpouseInfoVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04D765722B6A173C0055ECBB /* YHSpouseInfoVC.swift */; };
6203A87EDC96313BBE789D9C /* Pods_galaxy.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 987C69D43AE8D85DC1930DCF /* Pods_galaxy.framework */; };
......@@ -271,6 +272,7 @@
049A48A72B49417300D0C641 /* YHAboutUsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAboutUsViewController.swift; sourceTree = "<group>"; };
049A48A92B49536000D0C641 /* YHAboutUsAdvantageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHAboutUsAdvantageCell.swift; sourceTree = "<group>"; };
04A7BC8E2B6B2BC2000E8D47 /* YHFamilyRequestViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHFamilyRequestViewModel.swift; sourceTree = "<group>"; };
04A7BC902B6B7B89000E8D47 /* YHTwoOptionAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHTwoOptionAlertView.swift; sourceTree = "<group>"; };
04AF58C32B4FC51C0066011A /* YHLocalizable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHLocalizable.swift; sourceTree = "<group>"; };
04D765722B6A173C0055ECBB /* YHSpouseInfoVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSpouseInfoVC.swift; sourceTree = "<group>"; };
58C2405158A4A6632D0E7460 /* Pods-galaxy.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-galaxy.debug.xcconfig"; path = "Target Support Files/Pods-galaxy/Pods-galaxy.debug.xcconfig"; sourceTree = "<group>"; };
......@@ -1025,6 +1027,7 @@
A5ACE9242B4564F7002C94D2 /* YHBouncesContentView.swift */,
A5ACE9252B4564F7002C94D2 /* YHBasicContentView.swift */,
A5ACE9262B4564F7002C94D2 /* YHNoDataTipView.swift */,
04A7BC902B6B7B89000E8D47 /* YHTwoOptionAlertView.swift */,
);
path = V;
sourceTree = "<group>";
......@@ -1433,6 +1436,7 @@
A5ACE9582B4564F7002C94D2 /* YHNoDataTipView.swift in Sources */,
042FBBBB2B62806D00F9DE23 /* YHCertificateViewController.swift in Sources */,
042FBBC72B64CFBF00F9DE23 /* YHChildInitialInfoVC.swift in Sources */,
04A7BC912B6B7B89000E8D47 /* YHTwoOptionAlertView.swift in Sources */,
0468D4792B68A08600CFB916 /* YHAddressViewController.swift in Sources */,
A5ACE9562B4564F7002C94D2 /* YHBouncesContentView.swift in Sources */,
042FBBCB2B65058000F9DE23 /* YHChildBasicInfoVC.swift in Sources */,
......
//
// YHTwoOptionAlertView.swift
// galaxy
//
// Created by edy on 2024/2/1.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHTwoOptionAlertView: UIView {
typealias Block = (Bool) -> ()
var block: Block?
var centerView: UIView!
var messageLabel: UILabel!
var rightButton: UIButton!
var leftButton: UIButton!
static func showAlertView(message:String?,leftBtnTitle:String? = "取消".local, rightBtnTitle:String? = "确认".local, callBack: @escaping Block) {
let view = YHTwoOptionAlertView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight))
view.messageLabel.text = message
view.leftButton.setTitle(leftBtnTitle, for: .normal)
view.rightButton.setTitle(rightBtnTitle, for: .normal)
view.block = callBack
let window = UIApplication.shared.yhKeyWindow()
window?.addSubview(view)
}
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(white: 0.5, alpha: 0.1)
let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
tap.delegate = self
addGestureRecognizer(tap)
setView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setView() {
backgroundColor = UIColor(hex: 0x0000, alpha: 0.5)
centerView = {
let view = UIView()
view.backgroundColor = .white
view.layer.cornerRadius = 12
return view
}()
addSubview(centerView)
messageLabel = {
let label = UILabel()
label.text = ""
label.font = kFont(size: 16)
label.textColor = UIColor(hex:0x222222)
label.textAlignment = .center
label.numberOfLines = 0
return label
}()
centerView.addSubview(messageLabel)
leftButton = {
let button = UIButton(type: .custom)
button.backgroundColor = UIColor(hex:0xffffff)
button.titleLabel?.font = kBoldFont(size: 14)
button.contentHorizontalAlignment = .center
button.setTitle("取消".local, for: .normal)
button.setTitleColor( UIColor(hex:0x3c86f8), for: .normal)
button.layer.cornerRadius = 8
button.layer.borderWidth = 1
button.layer.borderColor = UIColor(hex: 0x3c86f8).cgColor
button.addTarget(self, action: #selector(disagree), for: .touchUpInside)
return button
}()
centerView.addSubview(leftButton)
rightButton = {
let button = UIButton(type: .custom)
button.backgroundColor = UIColor(hex:0x3c86f8)
button.titleLabel?.font = kBoldFont(size: 14)
button.contentHorizontalAlignment = .center
button.setTitle("确认".local, for: .normal)
button.setTitleColor( UIColor(hex:0xffffff), for: .normal)
button.layer.cornerRadius = 8
button.addTarget(self, action: #selector(agree), for: .touchUpInside)
return button
}()
centerView.addSubview(rightButton)
centerView.snp.makeConstraints { make in
make.center.equalToSuperview()
make.width.equalTo(299)
}
messageLabel.snp.makeConstraints { make in
make.top.equalTo(40)
make.left.equalTo(22)
make.right.equalTo(-22)
}
leftButton.snp.makeConstraints { make in
make.top.equalTo(messageLabel.snp.bottom).offset(40)
make.left.equalTo(16)
make.bottom.equalToSuperview().offset(-16)
make.size.equalTo(CGSize(width: 128, height: 45))
}
rightButton.snp.makeConstraints { make in
make.right.equalTo(-16)
make.centerY.equalTo(leftButton)
make.size.equalTo(CGSize(width: 128, height: 45))
}
}
@objc func agree() {
block?(true)
dismiss()
}
@objc private func handleTap(_ sender: AnyObject?) {
print("处理点击手势")
dismiss()
}
@objc func disagree() {
block?(false)
dismiss()
}
func dismiss() {
removeFromSuperview()
}
}
extension YHTwoOptionAlertView: UIGestureRecognizerDelegate {
func gestureRecognizer(_ gestureRecognizer:UIGestureRecognizer, shouldReceive touch:UITouch) -> Bool {
if touch.view == self {
return true
}
return false
}
}
......@@ -16,6 +16,7 @@ enum YHFormTitleItemEditType:Int {
class YHFamilyMemberFormVC: YHBaseViewController {
var orderId:Int
let familyRequest:YHFamilyRequestViewModel = YHFamilyRequestViewModel()
var familyMemberInfo: YHFamilyMemberGroupInfo?
var isChildsEditMode: YHFormTitleItemEditType = .none
......@@ -63,6 +64,7 @@ class YHFamilyMemberFormVC: YHBaseViewController {
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.gk_navTitle = "家庭成员信息填写".local
......@@ -72,6 +74,15 @@ class YHFamilyMemberFormVC: YHBaseViewController {
}
init(orderId: Int) {
self.orderId = orderId
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func createUI() {
view.addSubview(tableView);
......@@ -152,24 +163,44 @@ class YHFamilyMemberFormVC: YHBaseViewController {
items.append(brotherArr)
let childCount = familyMemberInfo?.child?.count ?? 0
if isChildsEditMode == .none && childCount > 0 {
if childCount <= 0 {
isChildsEditMode = .none
} else {
if isChildsEditMode == .none {
isChildsEditMode = .canEdit
}
}
let brotherCount = familyMemberInfo?.brother?.count ?? 0
if isBrothersEditMode == .none && brotherCount > 0 {
if brotherCount <= 0 {
isBrothersEditMode = .none
} else {
if isBrothersEditMode == .none {
isBrothersEditMode = .canEdit
}
}
tableView.reloadData()
}
}
extension YHFamilyMemberFormVC {
// 请求家庭成员信息
func requestFamilyInfo() {
self.familyRequest.getFamilyInfo(params: ["orderId": self.orderId]) { [weak self] success, error in
guard let self = self else { return }
if success {
familyMemberInfo = self.familyRequest.familyInfo
}
loadFamilyMember()
}
}
// 添加兄弟姐妹子女
func addFamilyMember(_ type:YHFamilyMemberType) {
let dict:[String: Any] = ["orderId":"133971",
let dict:[String: Any] = ["orderId":self.orderId,
"relation":String(type.rawValue),
"step":0,
"next":false,
......@@ -185,16 +216,18 @@ extension YHFamilyMemberFormVC {
}
}
func requestFamilyInfo() {
// 添加兄弟姐妹子女
func deleteFamilyMember(orderId:Int, memberId:Int, callBack:((Bool)->Void)?) {
if orderId > 0 && memberId > 0 {
let dict = ["id":memberId, "orderId": orderId]
self.familyRequest.deleteFamilyMember(params: dict) { [weak self] success, error in
self.familyRequest.getFamilyInfo(params: ["orderId": 133971]) { [weak self] success, error in
guard let self = self else { return }
if success {
familyMemberInfo = self.familyRequest.familyInfo
if let callBack = callBack {
callBack(success)
}
}
loadFamilyMember()
}
}
}
......@@ -235,21 +268,23 @@ extension YHFamilyMemberFormVC : UITableViewDelegate, UITableViewDataSource {
// 右边按钮点击事件处理
cell.rightClickBlock = { [weak self] type in
guard let self = self else { return }
if formItem.type == .child {
if self?.isChildsEditMode == .canCancel {
self?.isChildsEditMode = .canEdit
} else if self?.isChildsEditMode == .canEdit {
self?.isChildsEditMode = .canCancel
if self.isChildsEditMode == .canCancel {
self.isChildsEditMode = .canEdit
} else if self.isChildsEditMode == .canEdit {
self.isChildsEditMode = .canCancel
}
}
if formItem.type == .brother {
if self?.isBrothersEditMode == .canCancel {
self?.isBrothersEditMode = .canEdit
} else if self?.isBrothersEditMode == .canEdit {
self?.isBrothersEditMode = .canCancel
if self.isBrothersEditMode == .canCancel {
self.isBrothersEditMode = .canEdit
} else if self.isBrothersEditMode == .canEdit {
self.isBrothersEditMode = .canCancel
}
}
self?.loadFamilyMember()
self.loadFamilyMember()
}
return cell
}
......@@ -274,25 +309,50 @@ extension YHFamilyMemberFormVC : UITableViewDelegate, UITableViewDataSource {
// 删除子女兄妹处理
cell.deleteBlock = { [weak self] in
guard let self = self else { return }
if detailItem.relationType == .child {
let childCount = self?.familyMemberInfo?.child?.count ?? 0
let childCount = self.familyMemberInfo?.child?.count ?? 0
// 因为子女兄妹section第一行都是标题所以row-1
if (indexPath.row-1 < childCount) {
self?.familyMemberInfo?.child?.remove(at: indexPath.row-1)
self?.isChildsEditMode = .none
self?.isBrothersEditMode = .none
if (indexPath.row-1 >= childCount) { return }
guard let child = self.familyMemberInfo?.child?[indexPath.row-1] else { return }
let msg = String(format: "确定要删除子女%d(%@)吗?".local, indexPath.row, "XXX")
YHTwoOptionAlertView.showAlertView(message:msg) { sure in
if !sure { return }
self.deleteFamilyMember(orderId: self.orderId, memberId:child.id) {
[weak self] success in
guard let self = self else { return }
self.isChildsEditMode = .none
self.isBrothersEditMode = .none
self.requestFamilyInfo()
}
}
} else if detailItem.relationType == .brother {
let brotherCount = self?.familyMemberInfo?.brother?.count ?? 0
let brotherCount = self.familyMemberInfo?.brother?.count ?? 0
// 因为子女兄妹section第一行都是标题所以row-1
if (indexPath.row-1 < brotherCount) {
self?.familyMemberInfo?.brother?.remove(at: indexPath.row-1)
self?.isChildsEditMode = .none
self?.isBrothersEditMode = .none
if (indexPath.row-1 >= brotherCount) { return }
guard let brother = self.familyMemberInfo?.brother?[indexPath.row-1] else { return }
let msg = String(format: "确定要删除兄弟%d(%@)吗?".local, indexPath.row, "XXX")
YHTwoOptionAlertView.showAlertView(message: msg) { sure in
if !sure { return }
self.deleteFamilyMember(orderId: self.orderId, memberId:brother.id) {
[weak self] success in
guard let self = self else { return }
self.isChildsEditMode = .none
self.isBrothersEditMode = .none
self.requestFamilyInfo()
}
}
}
self?.loadFamilyMember()
}
}
......
......@@ -127,8 +127,8 @@ extension YHMyViewController : UITableViewDelegate, UITableViewDataSource {
if (indexPath.row >= items.count) { return }
let vvc = YHFamilyMemberFormVC()
self.navigationController?.pushViewController(vvc)
let vc = YHFamilyMemberFormVC(orderId: 133971)
self.navigationController?.pushViewController(vc)
return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment