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

配偶

parent c29d095a
...@@ -8,23 +8,758 @@ ...@@ -8,23 +8,758 @@
import UIKit import UIKit
class YHGCSpouseBasicInfoVC: YHBaseViewController { class YHGCSpouseBasicInfoVC: YHBaseViewController, YHFamilyMemberProtol {
var spouse:YHFamilyMember?
weak var delegate:YHSpouseInfoVCProtocol?
// 是否显示未填写错误提示
var isNeedShowError = false
var items:[[YHFormItemProtocol]] = [[YHFormItemProtocol]]()
lazy var tableView: UITableView = {
let tableView = UITableView(frame:.zero, style:.grouped)
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}
tableView.estimatedSectionHeaderHeight = 14.0
tableView.estimatedSectionFooterHeight = 1.0
tableView.showsVerticalScrollIndicator = false
tableView.backgroundColor = UIColor(hexString:"#F8F8F8")
tableView.separatorStyle = .none
tableView.delegate = self
tableView.dataSource = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell")
tableView.register(YHFormItemDoubleChoiceCell.self, forCellReuseIdentifier: YHFormItemDoubleChoiceCell.cellReuseIdentifier)
tableView.register(YHFormItemInputTextCell.self, forCellReuseIdentifier: YHFormItemInputTextCell.cellReuseIdentifier)
tableView.register(YHFormItemEnterDetailCell.self, forCellReuseIdentifier: YHFormItemEnterDetailCell.cellReuseIdentifier)
tableView.register(YHFormItemTitleCell.self, forCellReuseIdentifier: YHFormItemTitleCell.cellReuseIdentifier)
tableView.register(YHFormItemAddCell.self, forCellReuseIdentifier: YHFormItemAddCell.cellReuseIdentifier)
tableView.register(YHFormItemSelectSheetCell.self, forCellReuseIdentifier: YHFormItemSelectSheetCell.cellReuseIdentifier)
tableView.register(YHFormItemDegreeInfoCell.self, forCellReuseIdentifier: YHFormItemDegreeInfoCell.cellReuseIdentifier)
return tableView
}()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
gk_navigationBar.isHidden = true
// Do any additional setup after loading the view. view.backgroundColor = UIColor(hexString:"#F8F8F8")
createUI()
loadInfo()
} }
func createUI() {
view.addSubview(tableView);
let topHeight = k_Height_NavigationtBarAndStatuBar+YHStepView.height
let bottomHeight = YHSaveAndSubmitView.height
tableView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.left.equalToSuperview().offset(16)
make.right.equalToSuperview().offset(-16)
make.height.equalTo(KScreenHeight-topHeight-bottomHeight)
}
}
func loadInfo() {
guard let spouse = spouse else { return }
items.removeAll()
// 配偶信息
let title0 = YHFormTitleItem(type: .spouseInfo)
let item00 = YHFormDetailItem(type: .spouseName)
item00.placeHolder = "请输入".local
item00.value = spouse.subsetName
item00.tips = "请输入配偶姓名".local
let item01 = YHFormDetailItem(type: .everName, isNeed: false)
item01.placeHolder = "选填".local
item01.value = spouse.usedName
let item02 = YHFormDetailItem(type: .befourMarryFirstName, isNeed: false)
item02.placeHolder = "如有则填写,仅支持输入字".local
item02.value = spouse.surname
let item03 = YHFormDetailItem(type: .birthday)
item03.placeHolder = "请选择".local
item03.value = spouse.birthday
item03.tips = "请选择出生日期".local
let item04 = YHFormDetailItem(type: .birthNation)
item04.value = String(spouse.isBirthOverSeas())
let item05 = YHFormDetailItem(type: .birthCity)
if spouse.isBirthOverSeas() {
item05.value = spouse.birthPlace.foreign
item05.placeHolder = "请输入".local
item05.tips = "请输入出生城市".local
} else {
item05.value = spouse.birthPlace.area.joined(separator: ",")
item05.placeHolder = "请选择".local
item05.tips = "请选择出生城市".local
}
let arr0:[YHFormItemProtocol] = [title0, item00, item01, item02, item03, item04, item05]
// 职业信息
let title1 = YHFormTitleItem(type: .occupationInfo)
let item10 = YHFormDetailItem(type: .occupation)
item10.value = spouse.occupation
item10.placeHolder = "请选择".local
item10.tips = "请选择职业".local
var arr1:[YHFormItemProtocol] = [title1, item10]
if spouse.isNowHaveJob() {
let item11 = YHFormDetailItem(type: .occupationName)
item11.value = spouse.occupationName
item11.placeHolder = "请输入".local
item11.tips = "请输入职业名称".local
arr1.append(item11)
}
// 学位信息
let title2 = YHFormTitleItem(type: .degreeInfo)
let item20 = YHFormDetailItem(type: .ownDegree)
item20.placeHolder = "请选择".local
item20.value = spouse.hasDegreeName()
item20.tips = "请选择是否拥有学位".local
var arr2:[YHFormItemProtocol] = [title2, item20]
if spouse.isHaveDegree() { // 选择了有学位
if !spouse.hasDegreeJson.isEmpty {
for degreeInfo in spouse.hasDegreeJson {
let item = YHFormDetailItem(type: .degreeDetailInfo)
arr2.append(item)
}
} else { // 学位数组为空则添加一个
let item = YHFormDetailItem(type: .degreeDetailInfo)
let newDegree = YHHasDegreeJson()
spouse.hasDegreeJson = [newDegree]
arr2.append(item)
}
// 添加一行增加学历学位信息
let item = YHFormAddItem(type: .addDegree)
arr2.append(item)
}
items.append(contentsOf: [arr0, arr1, arr2])
if spouse.isFollow() {
// 在港信息
let title3 = YHFormTitleItem(type: .inHongKongInfo)
let item30 = YHFormDetailItem(type: .isNowInHK)
item30.value = String(spouse.isNowInHK())
var arr3:[YHFormItemProtocol] = [title3, item30]
if spouse.isNowInHK() { // 目前在港才显示 逗留期限和在港身份
let item31 = YHFormDetailItem(type: .stayHKDate)
item31.placeHolder = "请选择".local
item31.value = spouse.childInHk.info
item31.tips = "请选择".local
let item32 = YHFormDetailItem(type: .roleInHK)
item32.placeHolder = "请选择".local
item32.value = spouse.hkIdentity
item32.tips = "请选择".local
arr3.append(contentsOf: [item31, item32])
}
items.append(arr3)
}
/* // 香港身份证
// MARK: - Navigation let title4 = YHFormTitleItem(type: .hkIdentityCardInfo)
let item40 = YHFormDetailItem(type: .isHaveHkIdentityCard)
item40.value = String(spouse.isHaveHKIdentityCard())
var arr4:[YHFormItemProtocol] = [title4, item40]
// In a storyboard-based application, you will often want to do a little preparation before navigation if spouse.isHaveHKIdentityCard() { // 办理过香港身份证才显示证号
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { let item41 = YHFormDetailItem(type: .hkIdentityCardNumber)
// Get the new view controller using segue.destination. item41.value = spouse.hkIdentityCard
// Pass the selected object to the new view controller. let tips = isEmptyString(spouse.hkIdentityCard) ? "请输入香港身份证号码".local : "请输入正确的香港身份证号码".local
item41.tips = tips
arr4.append(item41)
}
items.append(arr4)
tableView.reloadData()
}
// 检查填写信息完整性
func checkIntegrity() -> Bool {
guard let spouse = spouse else { return false}
if isEmptyString(spouse.subsetName) {
return false
}
if isEmptyString(spouse.birthday) {
return false
}
if spouse.isBirthOverSeas() {
if isEmptyString(spouse.birthPlace.foreign) {
return false
}
} else {
if isEmptyArray(spouse.birthPlace.area) {
return false
}
}
if isEmptyString(spouse.occupation) {
return false
}
if spouse.isNowHaveJob(), isEmptyString(spouse.occupationName) {
return false
}
if spouse.hasDegree.isEmpty {
return false
}
if spouse.isHaveDegree() { // 选择了有学位
if !spouse.hasDegreeJson.isEmpty {
for degreeInfo in spouse.hasDegreeJson {
if isEmptyString(degreeInfo.degree) || isEmptyString(degreeInfo.address) {
return false
}
}
}
}
if spouse.isFollow() {
if spouse.isNowInHK() {
if isEmptyString(spouse.childInHk.info) || isEmptyString(spouse.hkIdentity) {
return false
}
}
}
if spouse.isHaveHKIdentityCard() {
if isEmptyString(spouse.hkIdentityCard) {
return false
}
}
return true
}
func nextStep()->Bool {
guard let spouse = spouse else { return false }
let isChecked = checkIntegrity()
isNeedShowError = !isChecked
loadInfo()
if !isChecked {
YHHUD.flash(message: "资料还未填完")
return false
}
if spouse.isHaveHKIdentityCard(), let hkIdentityCard = spouse.hkIdentityCard, !hkIdentityCard.isHKIdentityCardNumber() {
isNeedShowError = true
loadInfo()
YHHUD.flash(message: "请输入正确的香港身份证号码")
return false
}
return true
}
func getCellType(_ item: Any) ->HKFormItemCellType {
if item is YHFormTitleItem {
return .title
}
if item is YHFormAddItem {
return .addItem
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if detailItem.type == .birthCity {
var isBirthOverSeas = false
if let spouse = spouse {
isBirthOverSeas = spouse.isBirthOverSeas()
}
if isBirthOverSeas {
return .inputText
} else {
return .selectSheet
}
}
if detailItem.type == .spouseName
|| detailItem.type == .everName
|| detailItem.type == .befourMarryFirstName
|| detailItem.type == .occupationName
|| detailItem.type == .hkIdentityCardNumber
{
return .inputText
}
if detailItem.type == .birthday
|| detailItem.type == .occupation
|| detailItem.type == .stayHKDate
|| detailItem.type == .roleInHK
|| detailItem.type == .ownDegree
{
return .selectSheet
}
if detailItem.type == .birthNation
|| detailItem.type == .isNowInHK
|| detailItem.type == .isHaveHkIdentityCard
{
return .twoChoice
}
if detailItem.type == .degreeDetailInfo
{
return .degreeDetailInfo
}
}
return .defaultType
}
}
extension YHGCSpouseBasicInfoVC : UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return items.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section >= items.count { return 0 }
let arr = items[section]
return arr.count
} }
*/
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section >= items.count { return createDefaultCell(indexPath) }
let arr:[YHFormItemProtocol] = items[indexPath.section]
if indexPath.row >= arr.count { return createDefaultCell(indexPath) }
let item:YHFormItemProtocol = arr[indexPath.row]
let cellType = getCellType(item)
if cellType == .title { // 标题
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemTitleCell.cellReuseIdentifier, for: indexPath) as! YHFormItemTitleCell
cell.setTitleAndSubTitle(title:item.getTitle())
return cell
}
if cellType == .addItem { // 新增item cell
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemAddCell.cellReuseIdentifier, for: indexPath) as! YHFormItemAddCell
cell.title = item.getTitle()
cell.clickBlock = {
[weak self] in
guard let self = self else { return }
let newDegree = YHHasDegreeJson()
self.spouse?.hasDegreeJson.append(newDegree)
self.loadInfo()
}
return cell
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if cellType == .inputText { // 输入文字cell
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemInputTextCell.cellReuseIdentifier, for: indexPath) as! YHFormItemInputTextCell
cell.isMust = detailItem.isNeed
cell.placeHolder = detailItem.placeHolder
cell.title = detailItem.getTitle()
cell.text = detailItem.value
if detailItem.type == .hkIdentityCardNumber { // 输入香港身份证号码
let isEmptyValue = isEmptyString(detailItem.value)
var isUnvalidFormat = true
if let value = detailItem.value, value.isHKIdentityCardNumber() {
isUnvalidFormat = false
}
let isNeedShowTips = isEmptyValue || isUnvalidFormat
cell.setTips(detailItem.tips, isShow: isNeedShowError && isNeedShowTips)
} else {
cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips)
}
if detailItem.type == .befourMarryFirstName {
cell.textField.keyboardType = .asciiCapable // 英文键盘
} else {
cell.textField.keyboardType = .default
}
cell.textInputCondtion = {
textField in
if detailItem.type == .befourMarryFirstName { // 仅支持输入最多30个大写字母
let regex = "[^A-Za-z]+"
textField.limitInputWithPattern(pattern:regex, 30)
return true
}
var max = -1
if detailItem.type == .spouseName ||
detailItem.type == .everName {
max = 30
} else if detailItem.type == .occupationName {
max = 50
} else if detailItem.type == .birthCity {
max = 100
}
if max > 0 {
if let textStr = textField.text {
textField.text = (textStr.count > max ? textStr[safe: ..<max] : textStr)
}
}
return true
}
cell.textChange = {
[weak self] (text, isEditEnd) in
guard let self = self else { return }
if detailItem.type == .spouseName {
self.spouse?.subsetName = text ?? ""
} else if detailItem.type == .everName {
self.spouse?.usedName = text ?? ""
} else if detailItem.type == .befourMarryFirstName {
let tt = text?.uppercased()
self.spouse?.surname = tt ?? ""
cell.textField.text = tt
} else if detailItem.type == .birthCity {
self.spouse?.birthPlace.foreign = text ?? ""
} else if detailItem.type == .occupationName {
self.spouse?.occupationName = text ?? ""
} else if detailItem.type == .hkIdentityCardNumber {
self.spouse?.hkIdentityCard = text
}
if isEditEnd {
self.loadInfo()
if detailItem.type == .hkIdentityCardNumber {
if let text = text, !text.isEmpty, !text.isHKIdentityCardNumber() {
YHHUD.flash(message: "请输入正确的香港身份证号格式")
return
}
}
save()
}
}
return cell
}
if cellType == .selectSheet { // 点击选择列表cell
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemSelectSheetCell.cellReuseIdentifier, for: indexPath) as! YHFormItemSelectSheetCell
cell.isMust = detailItem.isNeed
cell.placeHolder = detailItem.placeHolder
cell.title = detailItem.getTitle()
cell.detail = detailItem.value
cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips)
return cell
}
if cellType == .twoChoice { // 双项选择cell
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemDoubleChoiceCell.cellReuseIdentifier, for: indexPath) as! YHFormItemDoubleChoiceCell
cell.isMust = detailItem.isNeed
cell.title = item.getTitle()
cell.answerArr = nil
if detailItem.type == .birthNation { // 出生国家
var select = false
if let value = detailItem.value {
select = Bool(value)!
}
let answers = [YHFormChoiceItem(title: "国内".local, isSelect: !select),
YHFormChoiceItem(title: "国外".local, isSelect: select)]
cell.answerArr = answers
cell.answerBlock = {
[weak self] (answers, index) in
guard let self = self else { return }
let selectItem = answers[index]
self.spouse?.setBirthOverSeas(selectItem.title == "国外".local)
self.loadInfo()
save()
}
} else if detailItem.type == .isHaveHkIdentityCard || detailItem.type == .isNowInHK { // 是否办理过香港身份证 是否在岗
var select = false
if let value = detailItem.value {
select = Bool(value)!
}
let answers = [YHFormChoiceItem(title: "是".local, isSelect: select),
YHFormChoiceItem(title: "否".local, isSelect: !select)]
cell.answerArr = answers
cell.answerBlock = {
[weak self] (answers, index) in
guard let self = self else { return }
let selectItem = answers[index]
if detailItem.type == .isNowInHK {
self.spouse?.setNowIsInHK(selectItem.title == "是".local)
} else if detailItem.type == .isHaveHkIdentityCard {
let isHaveIdCard = selectItem.title == "是".local
self.spouse?.setHaveHKIdentityCard(isHaveIdCard)
if !isHaveIdCard {
self.spouse?.hkIdentityCard = ""
}
}
self.loadInfo()
save()
}
}
return cell
}
if cellType == .degreeDetailInfo { // 学位cell
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemDegreeInfoCell.cellReuseIdentifier, for: indexPath) as! YHFormItemDegreeInfoCell
if let degreeArr = self.spouse?.hasDegreeJson {
if indexPath.row-2 < degreeArr.count {
let degreeInfo = degreeArr[indexPath.row-2]
cell.title = String(format: "%@%d", "学位信息".local, indexPath.row-1)
// 前两行是 学历学位信息标题 和 是否拥有学位
cell.showDeleteBtn(indexPath.row > 2)
// 学位
var degreeDesc = ""
if let degreeInt = Int(degreeInfo.degree), let item = YHSheetPickerView.getItem(type:.degree, index:degreeInt)
{
degreeDesc = item.title
}
cell.degree = degreeDesc
// 颁发地区
var degreeAreaDesc = ""
if let areaInt = Int(degreeInfo.address), let item = YHSheetPickerView.getItem(type:.degreeLocation, index: areaInt)
{
degreeAreaDesc = item.title
}
cell.degreePlace = degreeAreaDesc
let isNeedShowDegreeTips = isNeedShowError && isEmptyString(degreeDesc)
let isNeedShowPlaceTips = isNeedShowError && isEmptyString(degreeAreaDesc)
cell.showTips(isShowDegreeTips:isNeedShowDegreeTips, isShowPlaceTips:isNeedShowPlaceTips)
cell.degreeClickBlock = {
YHSheetPickerView.show(type: .degree, selectTitle:degreeDesc) {
[weak self] selectItem in
guard let self = self else { return }
degreeInfo.degree = String(selectItem.index)
loadInfo()
save()
}
}
cell.areaClickBlock = {
YHSheetPickerView.show(type: .degreeLocation, selectTitle: degreeAreaDesc) {
[weak self] selectType in
guard let self = self else { return }
degreeInfo.address = String(selectType.index)
loadInfo()
save()
}
}
cell.deleteBlock = {
[weak self] in
guard let self = self else { return }
var msg = "确定删除学位信息\(indexPath.row-1)吗"
YHTwoOptionAlertView.showAlertView(message:msg) { sure in
if !sure { return }
self.spouse?.hasDegreeJson.remove(at: indexPath.row-2)
self.loadInfo()
self.save()
}
}
}
}
return cell
}
}
return createDefaultCell(indexPath)
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.section >= items.count { return }
let arr:[YHFormItemProtocol] = items[indexPath.section]
if indexPath.row >= arr.count { return }
createCorner(cell: cell, arr: arr, indexPath: indexPath)
}
func createDefaultCell(_ indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
private func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat {
return 14.0
}
private func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> CGFloat {
if section == items.count-1 {
return 14.0
}
return 1.0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if !(0..<items.count).contains(indexPath.section) { return }
let arr:[YHFormItemProtocol] = items[indexPath.section]
if !(0..<arr.count).contains(indexPath.row) { return }
let item = arr[indexPath.row]
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if detailItem.type == .birthday || detailItem.type == .stayHKDate { // 出生日期/获准滞留至
var title = ""
if detailItem.type == .birthday {
title = "选择出生日期"
} else if detailItem.type == .stayHKDate {
title = "选择逗留日期"
}
YHDatePickView.show(type: .yyyymmdd, title:title, lastIsTaday: true, currentDay: spouse?.birthday ?? "") { [weak self] dateStr in
guard let self = self else { return }
if detailItem.type == .birthday {
let format = DateFormatter()
format.dateFormat = "yyyy-MM-dd"
if let selectDate = format.date(from:dateStr) {
let selectTimeInterval = selectDate.timeIntervalSince1970
let currentTimeInterval = Date().timeIntervalSince1970
// 出生日期须早于当前日期
if selectTimeInterval > currentTimeInterval {
YHHUD.flash(message: "出生日期不能晚于当前日期".local)
return
}
}
self.spouse?.birthday = dateStr
} else if detailItem.type == .stayHKDate {
self.spouse?.childInHk.info = dateStr
}
loadInfo()
save()
}
} else if detailItem.type == .birthCity { // 出生城市
var isBirthOverSeas = false
if let spouse = spouse {
isBirthOverSeas = spouse.isBirthOverSeas()
}
// 出生国外时 出生城市是输入框
if isBirthOverSeas { return }
let vc = YHAddressViewController()
vc.backLocationStringController = {
[weak self] (string1, string2, string3, string4) in
guard let self = self else { return }
print("\(string1)\n\(string2)\n\(string3)\n\(string4)")
var citys:[String] = []
if !isEmptyString(string2) {
citys.append(string2)
}
if !isEmptyString(string3) {
citys.append(string3)
}
self.spouse?.birthPlace.area = citys
loadInfo()
save()
}
self.present(vc, animated: true)
} else if detailItem.type == .roleInHK { // 在港身份
let identity = self.spouse?.hkIdentity ?? ""
YHSheetPickerView.show(type:.identity, selectTitle:identity) {
[weak self] selectItem in
guard let self = self else { return }
self.spouse?.hkIdentity = selectItem.title
loadInfo()
save()
}
} else if detailItem.type == .occupation {
let occupation = self.spouse?.occupation ?? ""
YHSheetPickerView.show(type: .occupation, selectTitle:occupation) {
[weak self] selectItem in
guard let self = self else { return }
self.spouse?.occupation = selectItem.title
loadInfo()
save()
}
} else if detailItem.type == .ownDegree {
YHSheetPickerView.show(type: .ownDegree, selectTitle:self.spouse?.hasDegreeName()) {
[weak self] selectItem in
guard let self = self else { return }
let hasDegree = selectItem.index == 1
self.spouse?.setHaveDegree(hasDegree)
self.loadInfo()
save()
}
}
}
}
func createCorner(cell:UITableViewCell, arr:Array<Any>, indexPath:IndexPath) {
// 复用时需清理
cell.layer.mask = nil
// 设置每块section圆角
if (indexPath.row == 0) {
let corner = UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue)
cell.createCorner(CGSizeMake(12.0, 12.0), corner)
} else if (indexPath.row == arr.count-1) {
let corner = UIRectCorner(rawValue: UIRectCorner.bottomLeft.rawValue | UIRectCorner.bottomRight.rawValue)
cell.createCorner(CGSizeMake(12.0, 12.0), corner)
} else {
cell.layer.mask = nil
}
}
func save() {
if let delegate = delegate, delegate.responds(to: #selector(YHSpouseInfoVCProtocol.saveInfoSilent)) {
delegate.saveInfoSilent()
}
}
} }
...@@ -8,23 +8,296 @@ ...@@ -8,23 +8,296 @@
import UIKit import UIKit
class YHGCSpouseInfoContainerVC: YHBaseViewController {
override func viewDidLoad() { class YHGCSpouseInfoContainerVC: YHBaseViewController, YHSpouseInfoVCProtocol {
super.viewDidLoad()
// Do any additional setup after loading the view. let familyRequest:YHFamilyRequestViewModel = YHFamilyRequestViewModel()
var stepVCs:[YHFaimilyStepItem] = []
var orderId:Int = 0
var spouse:YHFamilyMember? {
didSet {
if let spouse = spouse {
primaryInfoVC.spouse = spouse
uploadVC.familyMember = spouse
certificateVC.familyMember = spouse
basicInfoVC.spouse = spouse
}
}
}
var _currentStep = 0
var currentStep:Int {
get {
return _currentStep
}
set {
if let spouse = spouse, !spouse.isFollow(), newValue > 0 {
_currentStep = 3
} else {
_currentStep = newValue
}
let index = getArrayIndexOfCurrentStep()
if let index = index {
stepView.currentIndex = index
bottomView.changeRightBtnTitle(index == stepVCs.count-1 ? "提交".local : "下一步".local)
}
for vcItem in stepVCs {
vcItem.vc.view.isHidden = (vcItem.step != currentStep)
if vcItem.step == currentStep {
// 刷新
if vcItem.vc.responds(to: #selector(YHFamilyMemberProtol.loadInfo)) {
vcItem.vc.loadInfo()
}
}
}
}
} }
var stepView:YHStepView = {
let stepV = YHStepView()
return stepV
}()
var bottomView: YHSaveAndSubmitView = {
let view = YHSaveAndSubmitView.createView()
view.changeRightBtnTitle("下一步")
return view
}()
let primaryInfoVC = YHGCSpousePrimaryInfoVC()
let uploadVC = YHGCCertificateUploadVC()
let certificateVC = YHGCCertificateInfoController()
let basicInfoVC = YHGCSpouseBasicInfoVC()
/* override func viewDidLoad() {
// MARK: - Navigation super.viewDidLoad()
gk_navTitle = "配偶信息填写".local
gk_navigationBar.backgroundColor = .white
view.backgroundColor = UIColor(hexString:"#F8F8F8")
createUI()
}
func createUI() {
guard let spouse = spouse else { return }
primaryInfoVC.delegate = self
uploadVC.delegate = self
certificateVC.delegate = self
basicInfoVC.delegate = self
view.addSubview(stepView)
view.addSubview(bottomView)
updateStepView()
print("step:\(spouse.step)")
currentStep = spouse.step
stepView.maxIndex = getArrayIndexOfCurrentStep() ?? stepVCs.count-1
bottomView.submitBlock = {
[weak self] in
guard let self = self else { return }
submit()
}
bottomView.saveBlock = {
[weak self] in
guard let self = self else { return }
saveInfo(isSubmit: false, isShowSubmitMsg:false, isLoading: true, callBack: nil)
}
stepView.snp.makeConstraints { make in
make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
make.left.right.equalTo(view)
make.height.equalTo(YHStepView.height)
}
bottomView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.bottom.equalToSuperview()
make.height.equalTo(YHSaveAndSubmitView.height)
}
}
func updateStepView() {
guard let spouse = spouse else { return }
for vc in self.children {
vc.willMove(toParent: nil)
vc.removeFromParent()
vc.view.removeFromSuperview()
}
print(self.children)
if spouse.isFollow() {
stepVCs = [ YHFaimilyStepItem(title:"初始信息".local, vc:primaryInfoVC, step:0),
YHFaimilyStepItem(title:"证件上传".local, vc:uploadVC, step:1),
YHFaimilyStepItem(title:"证件信息".local, vc:certificateVC, step:2),
YHFaimilyStepItem(title:"基本信息".local, vc:basicInfoVC, step:3)]
} else {
stepVCs = [ YHFaimilyStepItem(title:"初始信息".local, vc:primaryInfoVC, step:0),
YHFaimilyStepItem(title:"基本信息".local, vc:basicInfoVC, step:3)]
}
var titles:[String] = []
for vcItem in stepVCs {
let topHeight = k_Height_NavigationtBarAndStatuBar+YHStepView.height
let bottomHeight = YHSaveAndSubmitView.height
vcItem.vc.view.frame = CGRectMake(0, topHeight, KScreenWidth, KScreenHeight-topHeight-bottomHeight)
self.addChild(vcItem.vc)
self.view.addSubview(vcItem.vc.view)
titles.append(vcItem.title)
}
stepView.dataSource = titles
// 数据源可能会变,所以需要重新设置step
let step = currentStep
currentStep = step
stepView.block = {
[weak self] index in
guard let self = self else { return }
if let targetStep = getStepForArrayIndex(index) {
currentStep = targetStep
}
requestDetail()
print("index:\(index)")
}
self.view.bringSubviewToFront(stepView)
self.view.bringSubviewToFront(bottomView)
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
} }
*/ }
extension YHGCSpouseInfoContainerVC {
// isSubmit:是否为提交 false为保存 true为提交
func saveInfo(isSubmit:Bool, isShowSubmitMsg:Bool, isLoading:Bool, callBack:((Bool)->Void)?) {
guard let spouse = spouse else { return }
guard let info = spouse.toDictionary() else { return }
let dict:[String: Any] = ["order_id":orderId,
"relation":spouse.relation,
"step":currentStep,
"next":isSubmit,
"info":info]
self.familyRequest.addOrSaveFamilyMember(params:dict, isShowLoading: isLoading) {
success, error in
if isLoading {
if success {
YHHUD.flash(message:isSubmit && isShowSubmitMsg ? "提交成功" : "保存成功")
} else {
var msg = isSubmit && isShowSubmitMsg ? "提交失败" : "保存失败"
if let errorMsg = error?.errorMsg, errorMsg.count > 0 {
msg = errorMsg
}
YHHUD.flash(message:msg)
}
}
if let callBack = callBack {
callBack(success)
}
}
}
func saveInfoSilent() {
saveInfo(isSubmit: false,isShowSubmitMsg:false, isLoading: false) {
[weak self] success in
}
}
func submit() {
if let targetVC = getCurrentStepViewController() {
if targetVC.nextStep() {
var isShowSubmitMsg = false
let index = getArrayIndexOfCurrentStep()
if let index = index, index == stepVCs.count-1 {
// 最后一步
isShowSubmitMsg = true
}
saveInfo(isSubmit: true, isShowSubmitMsg:isShowSubmitMsg, isLoading: true) {
[weak self] success in
guard let self = self else { return }
if success {
// 当前步骤已是最后一步
if let vc = stepVCs.last, vc.step == currentStep {
self.navigationController?.popViewController()
return
}
requestDetail()
if let cur = getArrayIndexOfCurrentStep(), let item = stepVCs[safe:cur+1] {
currentStep = item.step
if cur+1 > stepView.maxIndex {
stepView.maxIndex = cur+1
}
}
print("currentIndex:\(currentStep)")
}
}
}
}
}
func requestDetail() {
if orderId <= 0 {
print("订单号不存在")
return
}
self.familyRequest.requestFamilyMemberDetailInfo(memberType:.spouse, orderId:orderId) {
[weak self] detail in
guard let self = self else { return }
if let detail = detail {
self.spouse = detail
for vcItem in stepVCs {
vcItem.vc.loadInfo()
}
}
}
}
// 【WARNING!】步骤step和在数组中的下标有时候并不是一一对应
func getArrayIndexOfCurrentStep() ->Int? {
for (i, item) in stepVCs.enumerated() {
if item.step == currentStep {
return i
}
}
return nil
}
// 【WARNING!】步骤step和在数组中的下标有时候并不是一一对应
func getStepForArrayIndex(_ index:Int) -> Int? {
if let targetVCItem = stepVCs[safe: index] {
return targetVCItem.step
}
return nil
}
func getCurrentStepViewController() -> (UIViewController & YHFamilyMemberProtol)? {
for vcItem in stepVCs {
if vcItem.step == currentStep {
return vcItem.vc
}
}
return nil
}
} }
...@@ -7,24 +7,458 @@ ...@@ -7,24 +7,458 @@
// //
import UIKit import UIKit
import SmartCodable
import SwifterSwift
class YHGCSpousePrimaryInfoVC: YHBaseViewController { class YHGCSpousePrimaryInfoVC: YHBaseViewController, YHFamilyMemberProtol {
var spouse:YHFamilyMember?
weak var delegate:YHSpouseInfoVCProtocol?
// 是否显示未填写错误提示
var isNeedShowError = false
lazy var items:[[YHFormItemProtocol]] = [[YHFormItemProtocol]]()
lazy var tableView: UITableView = {
let tableView = UITableView(frame:.zero, style:.grouped)
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 52.0
tableView.estimatedSectionHeaderHeight = 14.0
tableView.estimatedSectionFooterHeight = 1.0
tableView.showsVerticalScrollIndicator = false
tableView.backgroundColor = UIColor(hexString:"#F8F8F8")
tableView.separatorStyle = .none
tableView.delegate = self
tableView.dataSource = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell")
tableView.register(YHFormItemDoubleChoiceCell.self, forCellReuseIdentifier: YHFormItemDoubleChoiceCell.cellReuseIdentifier)
tableView.register(YHFormItemInputTextCell.self, forCellReuseIdentifier: YHFormItemInputTextCell.cellReuseIdentifier)
tableView.register(YHFormItemSelectSheetCell.self, forCellReuseIdentifier: YHFormItemSelectSheetCell.cellReuseIdentifier)
tableView.register(YHFormItemTitleCell.self, forCellReuseIdentifier: YHFormItemTitleCell.cellReuseIdentifier)
tableView.register(YHFormItemAddCell.self, forCellReuseIdentifier: YHFormItemAddCell.cellReuseIdentifier)
return tableView
}()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
gk_navigationBar.isHidden = true
view.backgroundColor = UIColor(hexString:"#F8F8F8")
createUI()
loadInfo()
}
func loadInfo() {
guard let spouse = spouse else { return }
items.removeAll()
// 随行
let title0 = YHFormTitleItem(type: .accompany)
let item0 = YHFormDetailItem(type: .isAccompanyToHK)
item0.value = String(spouse.isFollow())
let arr0:[YHFormItemProtocol] = [title0, item0]
items.append(arr0)
if spouse.isFollow() { // 随行才加后面的信息
// 国籍
let title1 = YHFormTitleItem(type: .nationality)
let item10 = YHFormDetailItem(type:.nationOrArea, value:spouse.nationality, placeHolder:"请选择".local, tips:"请选择国籍".local)
let arr1:[YHFormItemProtocol] = [title1, item10]
// 居住信息
var arr2 = [YHFormItemProtocol]()
let title2 = YHFormTitleItem(type: .liveInfo)
let item20 = YHFormDetailItem(type:.isLiveTother, value:String(spouse.isLiveTother()))
arr2.append(title2)
arr2.append(item20)
if !spouse.isLiveTother() { // 不同住 才需填写国家/地区
let item21 = YHFormDetailItem(type:.nationOrArea, value:spouse.address.country, placeHolder:"请选择".local, tips:"请选择国家/地区".local)
arr2.append(item21)
// 国家/地区已填写 才显示现居住城市和详细地址两行
if !spouse.address.country.isEmpty {
// 居住信息中选择中国才会显示现居住城市
let isLiveInChina = spouse.address.country.contains("中国".local)
if isLiveInChina {
var value:String? = ""
if !spouse.address.area.isEmpty {
value = spouse.address.area.joined(separator: ",")
}
let item22 = YHFormDetailItem(type:.liveCity, value:value, tips:"请选择省市地区".local)
arr2.append(item22)
}
let placeHolder = (isLiveInChina ? "请填写小区、楼栋、单元室等".local : "请填写国外居住地".local)
let tips = (isLiveInChina ? "请填写小区、楼栋、单元室等".local : "请填写国外居住地".local)
let detailAddress = isLiveInChina ? spouse.address.details : spouse.address.foreign
let item23 = YHFormDetailItem(type:.detailAddress, value:detailAddress, placeHolder:placeHolder, tips:tips)
arr2.append(item23)
if !isLiveInChina {// 在国外
// 是否在海外居住满1年及以上
let item24 = YHFormDetailItem(type: .isLiveOverSeasMore1Year)
item24.value = String(spouse.isOverSeasOver1Year())
arr2.append(item24)
}
}
}
// 港澳通信证
var isShowHKPassportItem = false
if spouse.nationality.contains("中国") { // 中国国籍 居住在国内或居住国外不满一年
let isLiveInChina = spouse.address.country.contains("中国".local)
if isLiveInChina || (!isLiveInChina && !spouse.isOverSeasOver1Year()) {
isShowHKPassportItem = true
}
} else { // 外国国籍
isShowHKPassportItem = false
}
let title3 = YHFormTitleItem(type: .hkAndMacaoPassport)
let item30 = YHFormDetailItem(type: .isHandleHKPassPort)
item30.value = String(spouse.isNeedHandleHKPassPort())
let arr3:[YHFormItemProtocol] = [title3, item30]
items.append(contentsOf:[arr1, arr2])
if isShowHKPassportItem {
items.append(arr3)
}
}
tableView.reloadData()
}
func createUI() {
view.addSubview(tableView);
let topHeight = k_Height_NavigationtBarAndStatuBar+YHStepView.height
let bottomHeight = YHSaveAndSubmitView.height
tableView.snp.makeConstraints { make in
make.top.equalToSuperview()
make.left.equalToSuperview().offset(16)
make.right.equalToSuperview().offset(-16)
make.height.equalTo(KScreenHeight-topHeight-bottomHeight)
}
}
}
// Do any additional setup after loading the view.
extension YHGCSpousePrimaryInfoVC : UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return items.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section >= items.count { return 0 }
let arr = items[section]
return arr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section >= items.count { return createDefaultCell(indexPath) }
let arr:[YHFormItemProtocol] = items[indexPath.section]
if indexPath.row >= arr.count { return createDefaultCell(indexPath) }
let item:YHFormItemProtocol = arr[indexPath.row]
if item is YHFormTitleItem { // 标题
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemTitleCell.cellReuseIdentifier, for: indexPath) as! YHFormItemTitleCell
cell.setTitleAndSubTitle(title:item.getTitle())
return cell
} else if item is YHFormDetailItem { // 具体信息
let detailItem = item as! YHFormDetailItem
// 是否随行到香港 / 是否办理港澳通行证 / // 是否与主申请人同住 均用双项按钮cell
if detailItem.type == .isAccompanyToHK || detailItem.type == .isHandleHKPassPort || detailItem.type == .isLiveTother || detailItem.type == .isLiveOverSeasMore1Year {
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemDoubleChoiceCell.cellReuseIdentifier, for: indexPath) as! YHFormItemDoubleChoiceCell
cell.isMust = detailItem.isNeed
cell.title = detailItem.getTitle()
cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips)
var select = false
if let value = detailItem.value {
select = Bool(value)!
}
let answers = [YHFormChoiceItem(title: "是".local, isSelect: select),YHFormChoiceItem(title: "否".local, isSelect: !select)]
cell.answerArr = answers
cell.answerBlock = {
[weak self] (arr, selectIndex) in
guard let self = self else { return }
let selectItem:YHFormChoiceItem = arr[selectIndex]
let option = (selectItem.title == "是".local ? true : false)
if detailItem.type == .isAccompanyToHK { // 是否随行
self.spouse?.setFollow(option)
self.loadInfo()
if let delegate = delegate, delegate.responds(to: #selector(YHSpouseInfoVCProtocol.updateStepView)) {
delegate.updateStepView()
}
} else if detailItem.type == .isHandleHKPassPort { // 是否办理港澳通行证
self.spouse?.setNeedHandleHKPassPort(option)
self.loadInfo()
} else if detailItem.type == .isLiveTother { // 是否与主申请人同住
self.spouse?.setLiveTother(option)
if option {
self.spouse?.address.clearAddress()
}
self.loadInfo()
} else if detailItem.type == .isLiveOverSeasMore1Year { // 是否在海外居住满1年及以上
self.spouse?.setOverSearsOver1Year(option)
self.loadInfo()
} else if detailItem.type == .isLiveOverSeasMore1Year { // 是否在海外居住满1年及以上
self.spouse?.setOverSearsOver1Year(option)
self.loadInfo()
}
save()
}
return cell
}
if detailItem.type == .nationOrArea || detailItem.type == .liveCity {
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemSelectSheetCell.cellReuseIdentifier, for: indexPath) as! YHFormItemSelectSheetCell
cell.isMust = detailItem.isNeed
cell.title = detailItem.getTitle()
cell.placeHolder = detailItem.placeHolder
cell.detail = detailItem.value
cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips)
return cell
}
if detailItem.type == .detailAddress {
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemInputTextCell.cellReuseIdentifier, for: indexPath) as! YHFormItemInputTextCell
cell.isMust = detailItem.isNeed
cell.title = detailItem.getTitle()
cell.text = detailItem.value
cell.placeHolder = detailItem.placeHolder
cell.setTips(detailItem.tips, isShow: isNeedShowError && detailItem.isShowTips)
cell.textInputCondtion = {
textField in
if let textStr = textField.text {
let max = 100
textField.text = textStr.count > max ? textStr[safe: ..<max] : textStr
}
return true
}
cell.textChange = {
[weak self] (text, isEditEnd) in
guard let self = self else { return }
guard let spouse = spouse else { return }
if detailItem.type == .detailAddress {
if spouse.isLiveInChina() {
spouse.address.details = text ?? ""
} else {
spouse.address.foreign = text ?? ""
}
}
if isEditEnd {
self.loadInfo()
save()
}
}
return cell
}
}
return createDefaultCell(indexPath)
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.section >= items.count { return }
let arr:[YHFormItemProtocol] = items[indexPath.section]
if indexPath.row >= arr.count { return }
createCorner(cell: cell, arr: arr, indexPath: indexPath)
}
func createDefaultCell(_ indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
private func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat {
return 14.0
}
private func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> CGFloat {
if section == items.count-1 {
return 14.0
}
return 1.0
} }
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if !(0..<items.count).contains(indexPath.section) { return }
let arr:[YHFormItemProtocol] = items[indexPath.section]
if !(0..<arr.count).contains(indexPath.row) { return }
let item = arr[indexPath.row]
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
// 选国籍/现居住城市/详细地址
if detailItem.type == .nationOrArea {
let vc = YHSelectCountryViewController()
vc.backLocationStringController = {
[weak self] country in
guard let self = self else { return }
let title = arr[0] as! YHFormTitleItem
if title.type == .nationality { // 选国籍
self.spouse?.nationality = country
/* } else if title.type == .liveInfo {// 居住信息选国家地区
// MARK: - Navigation self.spouse?.address.country = country
// 选择国家地区后需清空城市
self.spouse?.address.area = []
// In a storyboard-based application, you will often want to do a little preparation before navigation }
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { self.loadInfo()
// Get the new view controller using segue.destination. save()
// Pass the selected object to the new view controller. }
self.navigationController?.pushViewController(vc)
} else if detailItem.type == .liveCity {
var provice = ""
if let country = self.spouse?.address.country {
if country.contains("台湾") {
provice = "台湾省"
}
if country.contains("香港") {
provice = "香港特别行政区"
}
if country.contains("澳门") {
provice = "澳门特别行政区"
}
}
let addressPicker = YHAddressViewController(selectProvince: provice)
addressPicker.backLocationStringController = {
[weak self] (address,province,city,area) in
guard let self = self else { return }
print("\(address)\n\(province)\n\(city)\n\(area)")
var citys:[String] = []
if !isEmptyString(province) {
citys.append(province)
}
if !isEmptyString(city) {
citys.append(city)
}
self.spouse?.address.area = citys
self.loadInfo()
save()
}
UIViewController.current?.present(addressPicker, animated: true, completion: nil)
}
}
}
func createCorner(cell:UITableViewCell, arr:Array<Any>, indexPath:IndexPath) {
// 复用时需清理
cell.layer.mask = nil
// 设置每块section圆角
if (indexPath.row == 0) {
let corner = UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue)
cell.createCorner(CGSizeMake(12.0, 12.0), corner)
} else if (indexPath.row == arr.count-1) {
let corner = UIRectCorner(rawValue: UIRectCorner.bottomLeft.rawValue | UIRectCorner.bottomRight.rawValue)
cell.createCorner(CGSizeMake(12.0, 12.0), corner)
} else {
cell.layer.mask = nil
}
}
// 检查填写信息完整性
func checkIntegrity() -> Bool {
guard let spouse = spouse else { return false}
if !spouse.isFollow() {
return true
}
if isEmptyString(spouse.nationality) {
return false
}
if !spouse.isLiveTother() { // 没有与主申请人同住
if isEmptyString(spouse.address.country) {
return false
}
if spouse.isLiveInChina() {
if isEmptyArray(spouse.address.area) {
return false
}
if isEmptyString(spouse.address.details) {
return false
}
} else { // 住在国外
if isEmptyString(spouse.address.foreign) {
return false
}
}
}
return true
}
func nextStep() -> Bool {
let isChecked = checkIntegrity()
isNeedShowError = !isChecked
loadInfo()
if !isChecked {
YHHUD.flash(message: "资料还未填完")
return false
}
return true
}
func save() {
if let delegate = delegate, delegate.responds(to: #selector(YHSpouseInfoVCProtocol.saveInfoSilent)) {
delegate.saveInfoSilent()
}
} }
*/
} }
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