Commit 1c86fe9f authored by Steven杜宇's avatar Steven杜宇

// 高才

parent c203aae2
//
// YHGCEducationDetailVC.swift
// galaxy
//
// Created by Dufet on 2024/12/19.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import SwifterSwift
//import Toast_Swift
class YHGCEducationDetailVC: YHBaseViewController {
//【WARNING!】新添加 传orderId 已有信息传detailId和orderId
// 订单ID
var orderId: Int = 0
// 学历ID
var detailId: Int = 0
// 是否显示未填写错误提示
var isNeedShowError = false
let educationRequest:YHEducationRequestViewModel = YHEducationRequestViewModel()
var detailInfo: YHEducationDetailInfo = YHEducationDetailInfo()
var items:[[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(YHFormItemTitleCell.self, forCellReuseIdentifier: YHFormItemTitleCell.cellReuseIdentifier)
tableView.register(YHFormItemAddCell.self, forCellReuseIdentifier: YHFormItemAddCell.cellReuseIdentifier)
tableView.register(YHFormItemInputTextCell.self, forCellReuseIdentifier: YHFormItemInputTextCell.cellReuseIdentifier)
tableView.register(YHFormItemSelectSheetCell.self, forCellReuseIdentifier: YHFormItemSelectSheetCell.cellReuseIdentifier)
tableView.register(YHEducationCertificateConfirmCell.self, forCellReuseIdentifier: YHEducationCertificateConfirmCell.cellReuseIdentifier)
return tableView
}()
var bottomView: YHSaveAndSubmitView = {
let view = YHSaveAndSubmitView.createView()
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.gk_navTitle = "学历".local
self.gk_navigationBar.backgroundColor = .white
view.backgroundColor = UIColor(hexString:"#F8F8F8")
createUI()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
func createUI() {
view.addSubview(tableView);
view.addSubview(bottomView)
bottomView.saveBlock = {
[weak self] in
guard let self = self else { return }
saveDetailInfo(isSubmit:false, isNeedPop: true, isShowToast: true)
}
bottomView.submitBlock = {
[weak self] in
guard let self = self else { return }
submitInfo()
}
bottomView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.bottom.equalToSuperview()
make.height.equalTo(YHSaveAndSubmitView.height)
}
tableView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(k_Height_NavigationtBarAndStatuBar)
make.bottom.equalTo(bottomView.snp.top)
make.left.equalToSuperview().offset(16)
make.right.equalToSuperview().offset(-16)
}
loadInfo()
if self.detailId != 0 { // 有学历ID则该学历已存在
getDetailInfo()
}
}
func loadInfo() {
items.removeAll()
let title0 = YHFormTitleItem(type: .mainApplicantEducation)
let item00 = YHFormDetailItem(type: .universityFullName)
if detailInfo.degree.contains("学士学位") {
item00.tips = "请输入学校全称".local
item00.placeHolder = "请输入学校全称,例:清华,需填全称“清华大学”".local
} else {
item00.tips = "请选择学校".local
item00.placeHolder = "请选择学校"
}
item00.value = detailInfo.college
let item01 = YHFormDetailItem(type: .educationStyle)
item01.tips = "请选择授课形式".local
item01.placeHolder = "请选择授课形式"
item01.value = detailInfo.teachingFormat
let item02 = YHFormDetailItem(type: .educationTime)
item02.tips = "请选择年月".local
item02.placeHolder = "请选择年月".local
item02.value = detailInfo.admissionTime
let item03 = YHFormDetailItem(type: .graduateTime)
item03.tips = "请选择年月".local
item03.placeHolder = "请选择年月".local
item03.value = detailInfo.graduateTime
let item04 = YHFormDetailItem(type: .educationMajor)
item04.tips = "请选择专业".local
item04.placeHolder = "请选择专业".local
item04.value = detailInfo.major
let item05 = YHFormDetailItem(type: .educationDegree)
item05.tips = "请选择学位".local
item05.placeHolder = "请选择学位".local
item05.value = detailInfo.degree
let item06 = YHFormDetailItem(type: .degreeType)
item06.tips = "请选择学位类型".local
item06.value = detailInfo.degreeType
let item07 = YHFormDetailItem(type: .educationCountry)
item07.tips = "请选择国家及地区".local
item07.placeHolder = "请选择国家及地区".local
item07.value = detailInfo.schoolAddress.country
let item08 = YHFormDetailItem(type: .educationCity)
if detailInfo.isSchoolInAboard() {
item08.value = detailInfo.schoolAddress.foreign
item08.tips = "请输入城市".local
} else {
item08.value = detailInfo.schoolAddress.area.joined(separator: ",")
item08.tips = "请选择城市".local
}
let arr0:[YHFormItemProtocol] = [title0, item05, item00, item01, item02, item03, item04, item07]
items.append(arr0)
let item10 = YHFormDetailItem(type: .cerConfirm)
let arr1:[YHFormItemProtocol] = [item10]
items.append(arr1)
self.tableView.reloadData()
}
}
extension YHGCEducationDetailVC : 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 formItem = item as! YHFormTitleItem
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemTitleCell.cellReuseIdentifier, for: indexPath) as! YHFormItemTitleCell
cell.setTitleAndSubTitle(title:formItem.getTitle())
return cell
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
let cellType = getCellType(detailItem)
if cellType == .inputText {
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemInputTextCell.cellReuseIdentifier, for: indexPath) as! YHFormItemInputTextCell
var isValueValid = false
if let value = detailItem.value, !value.isEmpty {
isValueValid = true
}
cell.setTips(detailItem.tips, isShow: (isNeedShowError && !isValueValid))
cell.placeHolder = detailItem.placeHolder
cell.isMust = detailItem.isNeed
cell.title = detailItem.getTitle()
cell.text = detailItem.value
cell.textInputCondtion = {
textField in
var max = -1
if detailItem.type == .educationMajor {
max = 50
} else if detailItem.type == .educationCity {
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 == .educationCity {
if let text = text, !text.isEmpty {
detailInfo.schoolAddress.foreign = text
} else {
detailInfo.schoolAddress.foreign = ""
}
} else if detailItem.type == .educationMajor {
if let text = text, !text.isEmpty {
detailInfo.major = text
} else {
detailInfo.major = ""
}
} else if detailItem.type == .universityFullName {
if let text = text, !text.isEmpty {
detailInfo.college = text
} else {
detailInfo.college = ""
}
}
if isEditEnd {
loadInfo()
saveInfoSilent()
}
}
return cell
} else if cellType == .selectSheet {
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemSelectSheetCell.cellReuseIdentifier, for: indexPath) as! YHFormItemSelectSheetCell
cell.isShowTipsButton = (detailItem.type == .degreeType)
cell.tipsBtnClickBlock = {
YHWholeScreenTipsView.show(type: .degreeType, targetView: cell.tipsButton)
}
cell.placeHolder = detailItem.placeHolder
cell.isMust = detailItem.isNeed
cell.title = detailItem.getTitle()
cell.detail = detailItem.value
var isValueValid = false
if let value = detailItem.value, !value.isEmpty {
isValueValid = true
}
cell.setTips(detailItem.tips, isShow: (isNeedShowError && !isValueValid))
return cell
} else if cellType == .cerConfirm {
let cell = tableView.dequeueReusableCell(withIdentifier: YHEducationCertificateConfirmCell.cellReuseIdentifier, for: indexPath) as! YHEducationCertificateConfirmCell
cell.isCheck = isNeedShowError
var isSelectTrue = false
var isSelectFalse = false
let isCerConfirm = detailInfo.certConfirm
if isCerConfirm == 1 {
isSelectTrue = true
isSelectFalse = false
} else if isCerConfirm == 2 {
isSelectFalse = true
isSelectTrue = false
}
let answers = [YHFormChoiceItem(title: "是".local, isSelect: isSelectTrue),
YHFormChoiceItem(title: "否".local, isSelect: isSelectFalse)]
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)
detailInfo.certConfirm = option ? 1 : 2
self.tableView.reloadData()
}
return cell
}
}
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return cell
}
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 tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
private func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat {
return 14.0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let arr = items[indexPath.section]
let item:YHFormItemProtocol = arr[indexPath.row]
// 标题
if item is YHFormTitleItem {
return
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if detailItem.type == .universityFullName { // 选择大学名称
if detailInfo.degree.contains("学士学位") {
// 此时学位是输入
return
}
let vc = YHCollegeSearchViewController()
vc.orderId = self.orderId
vc.searchCollegeName = detailInfo.college
vc.selectBlock = {
[weak self] text in
guard let self = self else { return }
if let text = text, !text.isEmpty {
detailInfo.college = text
} else {
detailInfo.college = ""
}
loadInfo()
saveInfoSilent()
}
self.navigationController?.pushViewController(vc)
} else if detailItem.type == .educationStyle { // 授课形式
YHSheetPickerView.show(type:.educationStyle, selectTitle:detailInfo.teachingFormat) {
[weak self] item in
guard let self = self else { return }
detailInfo.teachingFormat = item.title
loadInfo()
saveInfoSilent()
}
} else if detailItem.type == .educationTime || detailItem.type == .graduateTime { // 入学及毕业年月
var title = ""
var dateStr = ""
if detailItem.type == .educationTime {
title = "选择入学日期"
dateStr = detailInfo.admissionTime
} else if detailItem.type == .graduateTime {
title = "选择毕业日期"
dateStr = detailInfo.graduateTime
}
YHDatePickView.show(type: .yyyymm, title: title, lastIsTaday: true, currentDay: dateStr) {
[weak self] dateStr in
guard let self = self else { return }
let format = DateFormatter()
format.dateFormat = "yyyy-MM"
if let selectDate = format.date(from:dateStr) {
let selectTimeInterval = selectDate.timeIntervalSince1970
let currentTimeInterval = Date().timeIntervalSince1970
if detailItem.type == .educationTime { // 选择入学日期
// 入学日期须早于当前日期
if selectTimeInterval > currentTimeInterval {
YHHUD.flash(message: "入学日期不能晚于当前日期")
return
}
if !detailInfo.graduateTime.isEmpty, let endDate = format.date(from:detailInfo.graduateTime) {
let endTimeInterval = endDate.timeIntervalSince1970
if selectTimeInterval > endTimeInterval {
YHHUD.flash(message: "入学日期不能晚于毕业日期")
return
}
}
detailInfo.admissionTime = dateStr
}
if detailItem.type == .graduateTime { // 选择毕业日期
if !detailInfo.admissionTime.isEmpty, let startDate = format.date(from:detailInfo.admissionTime) {
let startTimeInterval = startDate.timeIntervalSince1970
if selectTimeInterval < startTimeInterval {
YHHUD.flash(message: "毕业日期不能早于入学日期")
return
}
}
detailInfo.graduateTime = dateStr
}
}
loadInfo()
saveInfoSilent()
}
} else if detailItem.type == .educationDegree { // 学位
YHSheetPickerView.show(type:.degree, selectTitle:detailInfo.degree) {
[weak self] item in
guard let self = self else { return }
detailInfo.degree = item.title
loadInfo()
saveInfoSilent()
}
} else if detailItem.type == .degreeType { // 学位类型
YHSheetPickerView.show(type: .degreeCategory, selectTitle:"工程学") {
[weak self] selectItem in
guard let self = self else { return }
detailInfo.degreeType = selectItem.title
loadInfo()
saveInfoSilent()
}
} else if detailItem.type == .educationCountry { // 上课国家/地区
let vc = YHSelectCountryViewController()
vc.backLocationStringController = {
[weak self] country in
guard let self = self else { return }
detailInfo.schoolAddress.country = country
detailInfo.isAboardSchool = detailInfo.isSchoolInAboard()
loadInfo()
saveInfoSilent()
}
self.navigationController?.pushViewController(vc)
} else if detailItem.type == .educationCity { // 上课城市
if detailInfo.isSchoolInAboard() { return }
let vc = YHAddressViewController()
vc.backLocationStringController = {
[weak self] (string1, string2, string3, string4) in
guard let self = self else { return }
var citys:[String] = []
if !isEmptyString(string2) {
citys.append(string2)
}
if !isEmptyString(string3) {
citys.append(string3)
}
detailInfo.schoolAddress.area = citys
loadInfo()
saveInfoSilent()
}
self.present(vc, animated: true)
} else if detailItem.type == .educationMajor { // 专业
let vc = YHMajorSearchViewController()
vc.orderId = self.orderId
vc.searchMajorName = detailInfo.major
vc.selectBlock = {
[weak self] text in
guard let self = self else { return }
if let text = text, !text.isEmpty {
detailInfo.major = text
} else {
detailInfo.major = ""
}
loadInfo()
saveInfoSilent()
}
self.navigationController?.pushViewController(vc)
}
}
}
func createDefaultCell(_ indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return cell
}
func createCorner(cell:UITableViewCell, arr:Array<Any>, indexPath:IndexPath) {
// 设置每块section圆角
if indexPath.row == 0, indexPath.row == arr.count-1 {
let corner = UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue |
UIRectCorner.topRight.rawValue |
UIRectCorner.bottomLeft.rawValue |
UIRectCorner.bottomRight.rawValue)
cell.createCorner(CGSizeMake(12.0, 12.0), corner)
return
}
if (indexPath.row == 0) {
let corner = UIRectCorner(rawValue: UIRectCorner.topLeft.rawValue | UIRectCorner.topRight.rawValue)
cell.createCorner(CGSizeMake(12.0, 12.0), corner)
return
}
if (indexPath.row == arr.count-1) {
let corner = UIRectCorner(rawValue: UIRectCorner.bottomLeft.rawValue | UIRectCorner.bottomRight.rawValue)
cell.createCorner(CGSizeMake(12.0, 12.0), corner)
return
}
cell.layer.mask = nil
}
func getCellType(_ item: Any) ->HKFormItemCellType {
if item is YHFormTitleItem {
return .title
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if detailItem.type == .cerConfirm {
return .cerConfirm
}
// 学位选择:学士学位,
// 学习全称:直接输入学校名称,不需要进入搜索页面
//
// 学位选择:硕士学位/博士学位,
// 学习全称:需要进入名校库搜索页面,模糊搜索名校,若搜不到直接输入
if detailItem.type == .universityFullName { // 学校全称
if detailInfo.degree.contains("学士学位") {
return .inputText
}
return .selectSheet
}
if detailItem.type == .educationCity {
if detailInfo.isSchoolInAboard() {
return .inputText
}
return .selectSheet
}
if detailItem.type == .educationMajor
|| detailItem.type == .educationStyle
|| detailItem.type == .educationTime
|| detailItem.type == .graduateTime
|| detailItem.type == .educationDegree
|| detailItem.type == .degreeType
|| detailItem.type == .educationCountry
{
return .selectSheet
}
}
return .defaultType
}
}
extension YHGCEducationDetailVC {
func getDetailInfo() {
self.educationRequest.getEducationDetailInfo(params: ["id": self.detailId]) {
[weak self] success, error in
guard let self = self else { return }
if success {
if let educationDetailInfo = self.educationRequest.educationDetailInfo {
detailInfo = educationDetailInfo
}
loadInfo()
}
}
}
func submitInfo() {
let isChecked = checkIntegrity()
isNeedShowError = !isChecked
self.tableView .reloadData()
if !isChecked {
YHHUD.flash(message: "资料还未填完")
return
}
saveDetailInfo(isSubmit:true, isNeedPop: true, isShowToast: true)
}
// 检查填写信息完整性
func checkIntegrity() -> Bool {
if detailInfo.college.isEmpty
|| detailInfo.teachingFormat.isEmpty
|| detailInfo.admissionTime.isEmpty
|| detailInfo.graduateTime.isEmpty
|| detailInfo.major.isEmpty
|| detailInfo.degree.isEmpty
|| detailInfo.schoolAddress.country.isEmpty
{
return false
}
if detailInfo.certConfirm == 0 { // 证件提供确认
return false
}
// if detailInfo.isSchoolInAboard(), detailInfo.schoolAddress.foreign.isEmpty {
// return false
// }
// if !detailInfo.isSchoolInAboard(), detailInfo.schoolAddress.area.count <= 0 {
// return false
// }
return true
}
func saveInfoSilent() {
if detailId != 0 {
saveDetailInfo(isSubmit:false, isNeedPop: false, isShowToast: false)
}
}
// 保存信息 isNeedPop:保存成功后是否退出该页面
func saveDetailInfo(isSubmit:Bool, isNeedPop:Bool, isShowToast:Bool) {
guard var dict:[String:Any] = detailInfo.toDictionary() else { return }
dict["order_id"] = self.orderId
dict["is_aboard_school"] = detailInfo.isSchoolInAboard()
self.educationRequest.saveEducationInfo(params: dict, isSilent: !isShowToast) {
[weak self] success, error in
guard let self = self else { return }
if success {
if isShowToast {
YHHUD.flash(message: isSubmit ? "提交成功":"保存成功" )
}
if isNeedPop {
self.navigationController?.popViewController(animated: true)
}
} else {
if isShowToast {
var errorMsg = isSubmit ? "提交失败" : "保存失败"
if let errMsg = error?.errorMsg, errMsg.count > 0 {
errorMsg = errMsg
}
YHHUD.flash(message: errorMsg)
}
}
}
}
}
//
// YHGCEducationInfoListVC.swift
// galaxy
//
// Created by Dufet on 2024/12/19.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHGCEducationInfoListVC: YHBaseViewController {
var orderId:Int = 0
let educationRequest:YHEducationRequestViewModel = YHEducationRequestViewModel()
var familyMemberInfo: YHFamilyMemberGroupInfo?
// 学历编辑模式
var isDegreeEditMode: YHFormTitleItemEditType = .none
// 专业编辑模式
var isQualificationEditMode: YHFormTitleItemEditType = .none
var educationInfo: YHEducationListInfo?
var items:[[YHFormItemProtocol]] = []
// 是否显示未填写错误提示
var isNeedShowError = false
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(YHEducationInfoCell.self, forCellReuseIdentifier: YHEducationInfoCell.cellReuseIdentifier)
tableView.register(YHFormItemTitleCell.self, forCellReuseIdentifier: YHFormItemTitleCell.cellReuseIdentifier)
tableView.register(YHFormItemAddCell.self, forCellReuseIdentifier: YHFormItemAddCell.cellReuseIdentifier)
tableView.register(YHFormItemEnterDetailCell.self, forCellReuseIdentifier: YHFormItemEnterDetailCell.cellReuseIdentifier)
tableView.register(YHFormItemAddCell.self, forCellReuseIdentifier: YHFormItemAddCell.cellReuseIdentifier)
tableView.register(YHFormItemQuestionsCell.self, forCellReuseIdentifier: YHFormItemQuestionsCell.cellReuseIdentifier)
return tableView
}()
var bottomView: YHSaveAndSubmitView = {
let view = YHSaveAndSubmitView.createView()
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.gk_navTitle = "学历/专业资格填写".local
self.gk_navigationBar.backgroundColor = .white
view.backgroundColor = UIColor(hexString:"#F8F8F8")
createUI()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
requestEducationInfo()
}
func createUI() {
view.addSubview(tableView);
view.addSubview(bottomView)
bottomView.saveBlock = {
[weak self] in
guard let self = self else { return }
saveInfo(isSubmit: false)
self.navigationController?.popViewController(animated: true)
}
bottomView.submitBlock = {
[weak self] in
guard let self = self else { return }
submitInfo()
}
bottomView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.bottom.equalToSuperview()
make.height.equalTo(YHSaveAndSubmitView.height)
}
tableView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(k_Height_NavigationtBarAndStatuBar)
make.bottom.equalTo(bottomView.snp.top)
make.left.equalToSuperview().offset(16)
make.right.equalToSuperview().offset(-16)
}
loadInfo()
}
func loadInfo() {
guard let educationInfo = educationInfo else { return }
items.removeAll()
// 主申请人学历
let title0 = YHFormTitleItem(type: .mainApplicantEducation)
var arr0:[YHFormItemProtocol] = [title0]
if let eduList = educationInfo.eduList {
for (index, eduInfo) in eduList.enumerated() {
let item = YHFormDetailItem(type: .educationInfo)
arr0.append(item)
}
// 多学历可编辑删除状态
if eduList.count <= 1 {
isDegreeEditMode = .none
} else {
if isDegreeEditMode == .none {
isDegreeEditMode = .canEdit
}
}
} else {
isDegreeEditMode = .none
}
// 新增学历信息
arr0.append(YHFormAddItem(type: .addEducation))
items.append(arr0)
// 主申请人专业资格及会员资格
let title1 = YHFormTitleItem(type: .mainApplicantProfessionalQualification)
var arr1:[YHFormItemProtocol] = [title1]
if let quaList = educationInfo.quaList {
for (index, quaInfo) in quaList.enumerated() {
let item = YHFormDetailItem(type: .certificateInfo)
arr1.append(item)
}
// 多专业可编辑删除状态
if quaList.count <= 0 {
isQualificationEditMode = .none
} else {
if isQualificationEditMode == .none {
isQualificationEditMode = .canEdit
}
}
} else {
isQualificationEditMode = .none
}
// 新增学历信息
arr1.append(YHFormAddItem(type: .addCertificateInfo))
items.append(arr1)
// 学历证书姓名及出生日期正确性
let title2 = YHFormTitleItem(type: .edutionalCertificateNameAndBirthday)
var arr2:[YHFormItemProtocol] = [title2]
// 问题集合
let questions = YHQuestionInfo.getEducationQuestion(eduList: educationInfo)
for questionInfo in questions {
if questionInfo.key == "qualification" {
questionInfo.answer = educationInfo.isNameSame
arr2.append(questionInfo)
} else if questionInfo.key == "graduate" {
questionInfo.answer = educationInfo.isSpouseNameSame
}
}
items.append(arr2)
self.tableView.reloadData()
}
}
extension YHGCEducationInfoListVC : 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 formItem = item as! YHFormTitleItem
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemTitleCell.cellReuseIdentifier, for: indexPath) as! YHFormItemTitleCell
let isNeedWrap = (formItem.type == .mainApplicantProfessionalQualification)
cell.setTitleAndSubTitle(title:formItem.getTitle(), subTitle:formItem.getSubTitle(), isNeedWrap:isNeedWrap)
// 决定右边按钮显示样式
cell.showEditType(type: .none)
if formItem.type == .mainApplicantEducation { // 学历
cell.showEditType(type: isDegreeEditMode)
} else if formItem.type == .mainApplicantProfessionalQualification { // 专业
cell.showEditType(type: isQualificationEditMode)
}
// 右边按钮点击事件处理
cell.rightClickBlock = {
[weak self] type in
guard let self = self else { return }
if formItem.type == .mainApplicantEducation { // 学历
if self.isDegreeEditMode == .canCancel {
self.isDegreeEditMode = .canEdit
} else if self.isDegreeEditMode == .canEdit {
self.isDegreeEditMode = .canCancel
}
}
if formItem.type == .mainApplicantProfessionalQualification { // 专业
if self.isQualificationEditMode == .canCancel {
self.isQualificationEditMode = .canEdit
} else if self.isQualificationEditMode == .canEdit {
self.isQualificationEditMode = .canCancel
}
}
loadInfo()
}
return cell
}
if item is YHFormAddItem {
let detailItem = item as! YHFormAddItem
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemAddCell.cellReuseIdentifier, for: indexPath) as! YHFormItemAddCell
if detailItem.type == .addEducation {
cell.title = "新增学历信息"
} else if detailItem.type == .addCertificateInfo {
cell.title = "新增证书信息"
} else {
cell.title = ""
}
cell.clickBlock = {
[weak self] in
guard let self = self else { return }
if detailItem.type == .addEducation { // 学历
let vc = YHEducationDetailVC()
vc.orderId = self.orderId
self.navigationController?.pushViewController(vc)
} else if detailItem.type == .addCertificateInfo { // 证书
let vc = YHQualificationDetailVC()
vc.orderId = self.orderId
self.navigationController?.pushViewController(vc)
}
return
}
return cell
}
if item is YHQuestionInfo {
let detailItem = item as! YHQuestionInfo
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemQuestionsCell.cellReuseIdentifier, for: indexPath) as! YHFormItemQuestionsCell
cell.isMust = true
cell.title = String(format: "%d、\(detailItem.question)", indexPath.row)
var select0 = false
var select1 = false
if let answer = detailItem.answer {
select0 = answer
select1 = !answer
}
let answers = [YHFormChoiceItem(title: "是".local, isSelect: select0),YHFormChoiceItem(title: "否".local, isSelect: select1)]
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.key == "qualification" {
self.educationInfo?.isNameSame = option
} else if detailItem.key == "graduate" {
self.educationInfo?.isSpouseNameSame = option
}
loadInfo()
}
return cell
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if detailItem.type == .educationInfo {
if let eduList = educationInfo?.eduList, eduList.count > 0 {
// 第一行是标题
let eduInfo:YHEducationInfo = eduList[indexPath.row-1]
if eduInfo.vacantNum > 0 { // 有未填项
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemEnterDetailCell.cellReuseIdentifier, for: indexPath) as! YHFormItemEnterDetailCell
if let college = eduInfo.college, !college.isEmpty {
cell.title = eduInfo.college
} else {
cell.title = "学历标题".local
}
let tips = String(format: "有%d项未填", eduInfo.vacantNum)
cell.detailLabel.text = tips
cell.isShowDeleteBtn = (isDegreeEditMode == .canCancel && eduList.count > 1)
cell.setTips(tips, isShow:(isNeedShowError && eduInfo.vacantNum > 0))
cell.deleteBlock = {
var title = "确定删除该学历吗?"
if let collegeName = eduInfo.college, !collegeName.isEmpty {
title = "确定删除学历\(collegeName)吗"
}
YHTwoOptionAlertView.showAlertView(message:title) {
[weak self] sure in
guard let self = self else { return }
if !sure { return }
isDegreeEditMode = .none
deleteEducationInfo(id:eduInfo.id)
}
}
return cell
} else { // 数据已填满
let cell = tableView.dequeueReusableCell(withIdentifier: YHEducationInfoCell.cellReuseIdentifier, for: indexPath) as! YHEducationInfoCell
cell.titleLabel.text = eduInfo.college
cell.subTitleLabel.text = ""
if let major = eduInfo.major, let degree = eduInfo.degree {
cell.subTitleLabel.text = String("\(degree)-\(major)")
}
cell.timeLabel.text = ""
if let admissionTime = eduInfo.admissionTime, let graduateTime = eduInfo.graduateTime {
cell.timeLabel.text = String("\(admissionTime) ~ \(graduateTime)")
}
cell.isShowDeleteBtn = (isDegreeEditMode == .canCancel)
cell.deleteBlock = {
var title = "确定删除该学历吗?"
if let collegeName = eduInfo.college, !collegeName.isEmpty {
title = "确定删除学历\(collegeName)吗"
}
YHTwoOptionAlertView.showAlertView(message:title) {
[weak self] sure in
guard let self = self else { return }
if !sure { return }
isDegreeEditMode = .none
deleteEducationInfo(id:eduInfo.id)
}
}
return cell
}
}
}
if detailItem.type == .certificateInfo {
if let quaList = educationInfo?.quaList, quaList.count > 0 {
// 第一行是标题
let quaInfo:YHQualificationInfo = quaList[indexPath.row-1]
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemEnterDetailCell.cellReuseIdentifier, for: indexPath) as! YHFormItemEnterDetailCell
cell.title = "证书标题"
if let qualification = quaInfo.qualification, !qualification.isEmpty {
cell.title = qualification
}
var tips = ""
if quaInfo.vacantNum > 0 {
tips = String(format: "有%d项未填", quaInfo.vacantNum)
cell.detailLabel.text = tips
} else {
cell.detailLabel.text = "已填完".local
}
cell.setTips(tips, isShow:(isNeedShowError && quaInfo.vacantNum > 0))
cell.isShowDeleteBtn = (isQualificationEditMode == .canCancel)
cell.deleteBlock = {
var title = "确定要删除该证书吗?"
if let qualification = quaInfo.qualification, !qualification.isEmpty {
title = "确定删除证书\(qualification)吗"
}
YHTwoOptionAlertView.showAlertView(message:title) {
[weak self] sure in
guard let self = self else { return }
if !sure { return }
isQualificationEditMode = .none
deleteQualificationInfo(id:quaInfo.id)
}
}
return cell
}
}
}
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return cell
}
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 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) {
let arr = items[indexPath.section]
let item:YHFormItemProtocol = arr[indexPath.row]
// 标题
if item is YHFormTitleItem {
return
}
if item is YHFormAddItem {
return
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if detailItem.type == .educationInfo { // 学历
let vc = YHEducationDetailVC()
if let eduList = educationInfo?.eduList, indexPath.row-1 < eduList.count {
let eduInfo = eduList[indexPath.row-1]
vc.detailId = eduInfo.id
vc.orderId = self.orderId
}
self.navigationController?.pushViewController(vc)
return
}
if detailItem.type == .certificateInfo { // 证书
let vc = YHQualificationDetailVC()
if let quaList = educationInfo?.quaList, indexPath.row-1 < quaList.count {
let quaInfo = quaList[indexPath.row-1]
vc.detailId = quaInfo.id
vc.orderId = self.orderId
}
self.navigationController?.pushViewController(vc)
return
}
}
}
func createDefaultCell(_ indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return cell
}
func createCorner(cell:UITableViewCell, arr:Array<Any>, indexPath:IndexPath) {
// 设置每块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
}
}
}
extension YHGCEducationInfoListVC {
// 请求家庭成员信息
func requestEducationInfo() {
self.educationRequest.requestEducationInfoList(params: ["order_id": self.orderId]) {
[weak self] success, error in
guard let self = self else { return }
if success {
educationInfo = self.educationRequest.listInfo
loadInfo()
}
}
}
// 删除学历信息
func deleteEducationInfo(id:Int) {
self.educationRequest.deleteEducationInfo(id: id) {
[weak self] success, error in
guard let self = self else { return }
if success {
YHHUD.flash(message: "删除成功")
requestEducationInfo()
} else {
var errorMsg = "删除失败"
if let errMsg = error?.errorMsg, errMsg.count > 0 {
errorMsg = errMsg
}
YHHUD.flash(message: errorMsg)
}
}
}
// 删除证书信息
func deleteQualificationInfo(id:Int) {
self.educationRequest.deleteQualificationInfo(id: id) {
[weak self] success, error in
guard let self = self else { return }
if success {
YHHUD.flash(message: "删除成功")
requestEducationInfo()
} else {
var errorMsg = "删除失败"
if let errMsg = error?.errorMsg, errMsg.count > 0 {
errorMsg = errMsg
}
YHHUD.flash(message: errorMsg)
}
}
}
// 保存
func saveInfo(isSubmit:Bool) {
guard let educationInfo = educationInfo else { return }
let params:[String : Any] = [ "order_id": self.orderId,
"goNextFlow": isSubmit,
"isSpouseNameSame": educationInfo.isSpouseNameSame ?? false,
"isNameSame": educationInfo.isNameSame ?? false]
self.educationRequest.saveAllEducationInfo(params: params) {
[weak self] success, error in
guard let self = self else { return }
if success {
requestEducationInfo()
self.navigationController?.popViewController()
} else {
var errorMsg = isSubmit ? "提交失败" : "保存失败"
if let errMsg = error?.errorMsg, errMsg.count > 0 {
errorMsg = errMsg
}
YHHUD.flash(message: errorMsg)
}
}
}
func submitInfo() {
let isChecked = checkIntegrity()
isNeedShowError = !isChecked
self.tableView .reloadData()
if !isChecked {
YHHUD.flash(message: "资料还未填完")
return
}
saveInfo(isSubmit: true)
}
// 检查填写信息完整性
func checkIntegrity() -> Bool {
guard let educationInfo = educationInfo else { return false }
// 检查所有学历信息是否有未填项
if let eduList = educationInfo.eduList, eduList.count > 0 {
for eduInfo in eduList {
if eduInfo.vacantNum > 0 {
return false
}
}
}
// 检查所有证书信息是否有未填项
if let quaList = educationInfo.quaList, quaList.count > 0 {
for quaInfo in quaList {
if quaInfo.vacantNum > 0 {
return false
}
}
}
// 检查所有问题是否有未答项
if educationInfo.isNameSame == nil {
return false
}
return true
}
}
//
// YHGCQualificationDetailVC.swift
// galaxy
//
// Created by Dufet on 2024/12/19.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHGCQualificationDetailVC: YHBaseViewController {
//【WARNING!】新添加 传orderId 已有信息传detailId和orderId
// 订单ID
var orderId:Int = 0
// 专业ID
var detailId: Int = 0
let educationRequest:YHEducationRequestViewModel = YHEducationRequestViewModel()
// 专业详情信息
var detailInfo = YHQualificationDetailInfo()
var isChildsEditMode: YHFormTitleItemEditType = .none
var isBrothersEditMode: YHFormTitleItemEditType = .none
// 是否显示未填写错误提示
var isNeedShowError = false
var items:[[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(YHFormItemTitleCell.self, forCellReuseIdentifier: YHFormItemTitleCell.cellReuseIdentifier)
tableView.register(YHFormItemAddCell.self, forCellReuseIdentifier: YHFormItemAddCell.cellReuseIdentifier)
tableView.register(YHFormItemInputTextCell.self, forCellReuseIdentifier: YHFormItemInputTextCell.cellReuseIdentifier)
tableView.register(YHFormItemSelectSheetCell.self, forCellReuseIdentifier: YHFormItemSelectSheetCell.cellReuseIdentifier)
return tableView
}()
var bottomView: YHSaveAndSubmitView = {
let view = YHSaveAndSubmitView.createView()
view.changeRightBtnTitle("下一步".local)
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.gk_navTitle = "专业资格及会员资格".local
self.gk_navigationBar.backgroundColor = .white
view.backgroundColor = UIColor(hexString:"#F8F8F8")
createUI()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
func createUI() {
view.addSubview(tableView);
view.addSubview(bottomView)
bottomView.saveBlock = {
[weak self] in
guard let self = self else { return }
saveDetailInfo(isSubmit:false, isNeedPop: true, isShowToast: true)
}
bottomView.submitBlock = {
[weak self] in
guard let self = self else { return }
submitInfo()
}
bottomView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.bottom.equalToSuperview()
make.height.equalTo(YHSaveAndSubmitView.height)
}
tableView.snp.makeConstraints { make in
make.top.equalToSuperview().offset(k_Height_NavigationtBarAndStatuBar)
make.bottom.equalTo(bottomView.snp.top)
make.left.equalToSuperview().offset(16)
make.right.equalToSuperview().offset(-16)
}
loadInfo()
if self.detailId != 0 { // 有专业ID则该专业已存在
reqeustDetailInfo()
}
}
func loadInfo() {
items.removeAll()
let title0 = YHFormTitleItem(type: .mainApplicantProfessionalQualification)
let item00 = YHFormDetailItem(type: .qualificationCertificateName)
item00.tips = "请选择资格证书名称".local
item00.value = detailInfo.certName
let item01 = YHFormDetailItem(type: .conferAgencyFullName)
item01.tips = "请输入颁授机构".local
item01.value = detailInfo.issuingAgent
let item02 = YHFormDetailItem(type: .conferTime)
item02.tips = "请选择颁授年份".local
if detailInfo.issuingYear > 0 {
item02.value = String(detailInfo.issuingYear)
}
let item03 = YHFormDetailItem(type: .conferCountry)
item03.tips = "请选择颁授国家/地区".local
item03.value = detailInfo.issuingAddr.country
let item04 = YHFormDetailItem(type: .conferCity)
if detailInfo.isCollegeInAboard() {
item04.tips = "请输入颁授城市".local
item04.value = detailInfo.issuingAddr.foreign
} else {
item04.tips = "请选择颁授城市".local
item04.value = detailInfo.issuingAddr.area.joined(separator: ",")
}
let arr0:[YHFormItemProtocol] = [title0, item00, item01, item02, item03, item04]
items.append(arr0)
self.tableView.reloadData()
}
}
extension YHGCQualificationDetailVC : 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 formItem = item as! YHFormTitleItem
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemTitleCell.cellReuseIdentifier, for: indexPath) as! YHFormItemTitleCell
cell.setTitleAndSubTitle(title:formItem.getTitle())
return cell
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
let cellType = getCellType(detailItem)
if cellType == .inputText {
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemInputTextCell.cellReuseIdentifier, for: indexPath) as! YHFormItemInputTextCell
var isValueValid = false
if let value = detailItem.value, !value.isEmpty {
isValueValid = true
}
cell.setTips(detailItem.tips, isShow: (isNeedShowError && !isValueValid))
cell.placeHolder = detailItem.placeHolder
cell.isMust = detailItem.isNeed
cell.title = detailItem.getTitle()
cell.text = detailItem.value
cell.textInputCondtion = {
textField in
var max = -1
if detailItem.type == .conferAgencyFullName ||
detailItem.type == .conferCity {
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 == .conferCity {
if let text = text, !text.isEmpty {
detailInfo.issuingAddr.foreign = text
} else {
detailInfo.issuingAddr.foreign = ""
}
} else if detailItem.type == .conferAgencyFullName {
if let text = text, !text.isEmpty {
detailInfo.issuingAgent = text
} else {
detailInfo.issuingAgent = ""
}
}
if isEditEnd {
loadInfo()
saveInfoSilent()
}
}
return cell
} else if cellType == .selectSheet {
let cell = tableView.dequeueReusableCell(withIdentifier: YHFormItemSelectSheetCell.cellReuseIdentifier, for: indexPath) as! YHFormItemSelectSheetCell
cell.placeHolder = detailItem.placeHolder
var isValueValid = false
if let value = detailItem.value, !value.isEmpty {
isValueValid = true
}
cell.setTips(detailItem.tips, isShow: (isNeedShowError && !isValueValid))
cell.isMust = detailItem.isNeed
cell.title = detailItem.getTitle()
cell.detail = detailItem.value
return cell
}
}
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return cell
}
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 tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
private func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat {
return 14.0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let arr = items[indexPath.section]
let item:YHFormItemProtocol = arr[indexPath.row]
// 标题
if item is YHFormTitleItem {
return
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if detailItem.type == .qualificationCertificateName { // 资格证书名称
YHSheetPickerView.show(type: .professionCertificate, selectTitle:detailInfo.certName) {
[weak self] selectItem in
guard let self = self else { return }
detailInfo.certName = selectItem.title
loadInfo()
saveInfoSilent()
}
} else if detailItem.type == .conferTime { // 授权年份
YHDatePickView.show(type: .yyyy, title:"选择授权年份".local, lastIsTaday: true, currentDay: "\(detailInfo.issuingYear)") {
[weak self] dateStr in
guard let self = self else { return }
let format = DateFormatter()
format.dateFormat = "yyyy"
if let selectDate = format.date(from:dateStr) {
let selectTimeInterval = selectDate.timeIntervalSince1970
let currentTimeInterval = Date().timeIntervalSince1970
// 出生日期须早于当前日期
if selectTimeInterval > currentTimeInterval {
YHHUD.flash(message: "授权年份不能晚于当前年份".local)
return
}
}
detailInfo.issuingYear = Int(dateStr) ?? 2024
loadInfo()
saveInfoSilent()
}
} else if detailItem.type == .conferCountry { // 授权国家/地区
let vc = YHSelectCountryViewController()
vc.backLocationStringController = {
[weak self] country in
guard let self = self else { return }
detailInfo.issuingAddr.country = country
detailInfo.isAboardAddr = detailInfo.isCollegeInAboard()
loadInfo()
saveInfoSilent()
}
self.navigationController?.pushViewController(vc)
} else if detailItem.type == .conferCity { // 授权城市
if detailInfo.isCollegeInAboard() { return }
let vc = YHAddressViewController()
vc.backLocationStringController = {
[weak self] (string1, string2, string3, string4) in
guard let self = self else { return }
var citys:[String] = []
if !isEmptyString(string2) {
citys.append(string2)
}
if !isEmptyString(string3) {
citys.append(string3)
}
detailInfo.issuingAddr.area = citys
loadInfo()
saveInfoSilent()
}
self.present(vc, animated: true)
}
}
}
func createDefaultCell(_ indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)
return cell
}
func createCorner(cell:UITableViewCell, arr:Array<Any>, indexPath:IndexPath) {
// 设置每块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 getCellType(_ item: Any) ->HKFormItemCellType {
if item is YHFormTitleItem {
return .title
}
if item is YHFormDetailItem {
let detailItem = item as! YHFormDetailItem
if detailItem.type == .conferCity {
if detailInfo.isCollegeInAboard() {
return .inputText
}
return .selectSheet
}
if detailItem.type == .conferAgencyFullName {
return .inputText
}
if detailItem.type == .conferTime
|| detailItem.type == .conferCountry
|| detailItem.type == .conferCity
|| detailItem.type == .qualificationCertificateName{
return .selectSheet
}
}
return .defaultType
}
}
extension YHGCQualificationDetailVC {
func reqeustDetailInfo() {
self.educationRequest.getQualificationDetailInfo(id:self.detailId) {
[weak self] success, error in
guard let self = self else { return }
if success {
if let qualificationDetailInfo = self.educationRequest.qualificationDetailInfo {
detailInfo = qualificationDetailInfo
}
loadInfo()
}
}
}
func saveInfoSilent() {
if detailId != 0 {
saveDetailInfo(isSubmit:false, isNeedPop: false, isShowToast: false)
}
}
// 保存数据
// @param isNeedPop:保存成功后是否需要退出该页面
// @param isShowToast: 请求完成后是否弹Toast
func saveDetailInfo(isSubmit:Bool, isNeedPop:Bool, isShowToast:Bool) {
var dict:[String : Any] = ["orderId":self.orderId]
detailInfo.isAboardAddr = detailInfo.isCollegeInAboard()
let quaDict:[String : Any] = detailInfo.toDictionary() ?? [:]
dict["qua_data"] = quaDict
print(dict)
self.educationRequest.saveQualificationInfo(params: dict, isSilent:!isShowToast) {
[weak self] success, error in
guard let self = self else { return }
if success {
if isShowToast {
YHHUD.flash(message: isSubmit ? "提交成功":"保存成功" )
}
if isNeedPop {
self.navigationController?.popViewController(animated: true)
}
} else {
if isShowToast {
var errorMsg = isSubmit ? "提交失败" : "保存失败"
if let errMsg = error?.errorMsg, errMsg.count > 0 {
errorMsg = errMsg
}
YHHUD.flash(message: errorMsg)
}
}
}
}
func submitInfo() {
let isChecked = checkIntegrity()
isNeedShowError = !isChecked
self.tableView .reloadData()
if !isChecked {
YHHUD.flash(message: "资料还未填完")
return
}
saveDetailInfo(isSubmit:true, isNeedPop: true, isShowToast: true)
}
// 检查填写信息完整性
func checkIntegrity() -> Bool {
if detailInfo.certName.isEmpty
|| detailInfo.issuingAgent.isEmpty
|| detailInfo.issuingYear <= 0
|| detailInfo.issuingAddr.country.isEmpty
{
return false
}
if detailInfo.isCollegeInAboard(), detailInfo.issuingAddr.foreign.isEmpty {
return false
}
if !detailInfo.isCollegeInAboard(), detailInfo.issuingAddr.area.count <= 0 {
return false
}
return true
}
}
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