Commit 14cd018e authored by Steven杜宇's avatar Steven杜宇

// 搜索学校

parent 39f0dcb5
......@@ -10,10 +10,12 @@ import UIKit
class YHCollegeSearchViewController: YHBaseViewController {
var orderId:Int = 0
var searchCollegeName:String?
var selectBlock:((String?)->Void)?
var colleges:[Any] = []
var colleges:[YHCollegeInfo] = []
let educationRequest:YHEducationRequestViewModel = YHEducationRequestViewModel()
lazy var searchBar: YHSearchBar = {
let bar = YHSearchBar.createBar()
return bar
......@@ -39,6 +41,7 @@ class YHCollegeSearchViewController: YHBaseViewController {
lazy var emptyDataTipsView:UIView = {
let view = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 124))
view.isHidden = true
let imgView = UIImageView(image: UIImage(named: "service_center_no_data"))
imgView.contentMode = .scaleAspectFill
......@@ -67,6 +70,9 @@ class YHCollegeSearchViewController: YHBaseViewController {
override func viewDidLoad() {
super.viewDidLoad()
createUI()
if searchCollegeName != nil {
searchCollege()
}
}
func createUI() {
......@@ -83,6 +89,8 @@ class YHCollegeSearchViewController: YHBaseViewController {
searchBar.textChange = {
[weak self] text in
guard let self = self else { return }
searchCollegeName = text
searchCollege()
}
searchBar.confirmBlock = {
[weak self] in
......@@ -105,6 +113,28 @@ class YHCollegeSearchViewController: YHBaseViewController {
make.left.right.bottom.equalToSuperview()
}
}
func searchCollege() {
let param:[String:Any] = ["order_id": orderId,
"name":searchCollegeName ?? "",
"page":1,
"page_size":15,
]
self.educationRequest.searchCollegeInfoList(params: param) {
[weak self] success, error in
guard let self = self else { return }
if success {
if let list = self.educationRequest.collegeList {
colleges = list
} else {
colleges = []
}
emptyDataTipsView.isHidden = colleges.count > 0
}
self.tableView.reloadData()
}
}
}
extension YHCollegeSearchViewController: UITableViewDelegate, UITableViewDataSource {
......@@ -114,19 +144,37 @@ extension YHCollegeSearchViewController: UITableViewDelegate, UITableViewDataSou
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 36.0
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: YHCollegeNameCell.cellReuseIdentifier, for: indexPath) as! YHCollegeNameCell
cell.titleLabel.text = "XXXXXXXXX"
if indexPath.row < colleges.count {
let college:YHCollegeInfo = colleges[indexPath.row]
var name = ""
if !isEmptyString(college.zhName) {
name += college.zhName
}
if !isEmptyString(college.zhName) && !isEmptyString(college.enName) {
name += "/"
}
if !isEmptyString(college.enName) {
name += college.enName
}
cell.titleLabel.text = name
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let selectBlock = selectBlock {
selectBlock("")
self.navigationController?.popViewController(animated: true)
if indexPath.row < colleges.count {
let college:YHCollegeInfo = colleges[indexPath.row]
selectBlock(college.getCollegeName())
self.navigationController?.popViewController(animated: true)
}
}
}
}
......@@ -299,8 +299,9 @@ extension YHEducationDetailVC : UITableViewDelegate, UITableViewDataSource {
if detailItem.type == .universityFullName { // 选择大学名称
let vc = YHCollegeSearchViewController()
vc.orderId = self.orderId
vc.searchCollegeName = detailInfo.college
vc.selectBlock = {
vc.selectBlock = {
[weak self] text in
guard let self = self else { return }
if let text = text, !text.isEmpty {
......
......@@ -162,5 +162,41 @@ class YHQualificationDetailInfo: SmartCodable {
}
}
class YHCollegeInfo: SmartCodable {
var id: Int = 0
var zhName: String = ""
var enName: String = ""
// 0-未知,1-中文主校,2-英文主校
var mainNameType: Int = 0
var schoolType: Int = 0
var assoProduct: [Int] = []
var color: String = ""
enum CodingKeys: String, CodingKey {
case id = "id"
case zhName = "zh_name"
case enName = "en_name"
case mainNameType = "main_name_type"
case schoolType = "school_type"
case assoProduct = "asso_product"
case color = "color"
}
func getCollegeName() -> String {
if mainNameType == 1 {
return zhName
} else if mainNameType == 2 {
return enName
}
return ""
}
required init() {
}
}
......@@ -15,6 +15,8 @@ class YHEducationRequestViewModel {
var educationDetailInfo: YHEducationDetailInfo?
// 专业详情信息
var qualificationDetailInfo: YHQualificationDetailInfo?
// 搜索学校数组
var collegeList: [YHCollegeInfo]?
// 请求学历和专业证书信息列表
func requestEducationInfoList(params:[String:Any], callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
......@@ -215,5 +217,32 @@ class YHEducationRequestViewModel {
}
}
// 搜索学校
func searchCollegeInfoList(params:[String:Any], callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
YHHUD.show(.progress(message: "数据加载中..."))
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Education.searchCollegeNameApi
let _ = YHNetRequest.getRequest(url: strUrl, params:params) {[weak self] json, code in
YHHUD.hide()
guard let self = self else { return }
printLog("model 是 ==> \(json)")
let dic = json.data as? [AnyHashable : Any]
guard let dic = dic, let list = dic["list"] as? [[String:Any]], let results = [YHCollegeInfo].deserialize(array: list) as? [YHCollegeInfo] else {
callBackBlock(false,nil)
return
}
collegeList = results
callBackBlock(true,nil)
} failBlock: { err in
callBackBlock(false,err)
}
}
}
......@@ -16,6 +16,7 @@ class YHCollegeNameCell: UITableViewCell {
let label = UILabel()
label.textColor = .mainTextColor
label.textAlignment = .left
label.numberOfLines = 0
label.font = UIFont.PFSC_B(ofSize: 14)
return label
}()
......@@ -37,7 +38,9 @@ class YHCollegeNameCell: UITableViewCell {
titleLabel.snp.makeConstraints { make in
make.left.equalToSuperview().offset(21)
make.right.equalToSuperview().offset(-21)
make.top.bottom.equalToSuperview()
make.top.equalToSuperview().offset(8)
make.bottom.equalToSuperview().offset(-8)
}
}
......
......@@ -50,6 +50,7 @@ class YHAllApiName {
static let familyInfoApi = "frontend/order/information/family"
// 删除家庭成员信息
static let familyMemberDeleteApi = "frontend/order/information/family/delete"
}
......@@ -71,6 +72,9 @@ class YHAllApiName {
// 保存所有信息
// static let saveAllEduAndQuaInfoApi = "frontend/education/save_all"
static let saveAllEduAndQuaInfoApi = "infoflow/submitEducert"
// 搜索大学名称
static let searchCollegeNameApi = "infoflow/getSchools"
}
......
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