Commit a6f2fd26 authored by pete谢兆麟's avatar pete谢兆麟

修改代码

parent d42d44ba
......@@ -15,7 +15,7 @@ class YHActivityDetailViewController: YHBaseViewController {
let vm = YHActivityViewModel()
return vm
}()
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
tableView.showsVerticalScrollIndicator = false
......@@ -25,40 +25,41 @@ class YHActivityDetailViewController: YHBaseViewController {
tableView.backgroundColor = UIColor.clear
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell")
tableView.register(YHActivityDetailCell.self, forCellReuseIdentifier: YHActivityDetailCell.cellReuseIdentifier)
tableView.register(YHActivityDetailCell0.self, forCellReuseIdentifier: YHActivityDetailCell0.cellReuseIdentifier)
tableView.register(YHActivityDetailCell1.self, forCellReuseIdentifier: YHActivityDetailCell1.cellReuseIdentifier)
tableView.register(YHActivityDetailCell2.self, forCellReuseIdentifier: YHActivityDetailCell2.cellReuseIdentifier)
// tableView.register(YHActivityDetailInfoCell.self, forCellReuseIdentifier: YHActivityDetailInfoCell.cellReuseIdentifier)
tableView.tableHeaderView = nil
tableView.tableHeaderView = nil
tableView.tableFooterView = nil
tableView.estimatedSectionHeaderHeight = 0
tableView.estimatedSectionFooterHeight = 0
return tableView
}()
lazy var topView: UIImageView = {
let view = UIImageView()
view.contentMode = .scaleAspectFill
view.image = UIImage(named: "activity_detail_top_bkg")
return view
}()
lazy var bottomView: YHActivityDetailBottomView = {
let view = YHActivityDetailBottomView()
return view
}()
// MARK: - 生命周期方法
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
loadData()
......@@ -67,10 +68,10 @@ class YHActivityDetailViewController: YHBaseViewController {
extension YHActivityDetailViewController {
func gotoTheRightVcForStatus() {
guard let model = self.viewModel.activityDetailModel else {
guard let model = viewModel.activityDetailModel else {
return
}
if let status = YHActivityStatus(rawValue: model.status.int ?? 0) {
switch status {
case .notApply:
......@@ -91,37 +92,35 @@ extension YHActivityDetailViewController {
printLog("")
}
}
}
func gotoActivityTravelVC() {
if let nav = self.navigationController {
if let nav = navigationController {
let rrr = nav.viewControllers.contains { $0.isKind(of: YHActivityTravelViewController.self) }
if rrr {
var targetVc: UIViewController?
for(_, value) in nav.viewControllers.enumerated() {
var targetVc: UIViewController?
for (_, value) in nav.viewControllers.enumerated() {
if value.isKind(of: YHActivityTravelViewController.self) {
targetVc = value
break
}
}
if let vc = targetVc {
navigationController?.popToViewController(vc, animated: true)
}
return
}
}
// 行程单详情
let vc = YHActivityTravelViewController()
vc.travelId = viewModel.activityDetailModel?.checkId ?? ""
navigationController?.pushViewController(vc)
}
func showApplyUI() {
YHApplyActivityAlert.showApplyActivityAlertView(name: self.viewModel.activityDetailModel?.businessCardName ?? "") { (tag, name, number, phone) in
YHApplyActivityAlert.showApplyActivityAlertView(name: viewModel.activityDetailModel?.businessCardName ?? "") { tag, name, number, phone in
if tag {
printLog(tag)
printLog(name)
......@@ -137,52 +136,53 @@ extension YHActivityDetailViewController {
}
}
}
func setupUI() {
gk_navigationBar.isHidden = false
gk_navigationBar.backgroundColor = .clear
gk_backImage = UIImage(named: "activity_nav_back")
view.backgroundColor = .white
// 1.
view.addSubview(tableView)
view.addSubview(bottomView)
view.addSubview(topView)
// 2.
tableView.contentInsetAdjustmentBehavior = .never
tableView.snp.makeConstraints { make in
make.left.right.top.equalToSuperview()
make.bottom.equalTo(bottomView.snp.top)
}
// 3.
bottomView.snp.makeConstraints { make in
make.left.right.bottom.equalToSuperview()
make.height.equalTo(YHActivityDetailBottomView.viewH)
}
bottomView.block = { [weak self] _ in
// 判断是否登录成功
if YHLoginManager.shared.isLogin() {
self?.gotoTheRightVcForStatus()
} else {
YHOneKeyLoginManager.shared.oneKeyLogin()
YHLoginManager.shared.loginSuccessActionBlock = {[weak self] in
YHLoginManager.shared.loginSuccessActionBlock = { [weak self] in
guard self != nil else { return }
self?.loadData()
YHLoginManager.shared.loginSuccessActionBlock = nil
}
}
}
// 4.
topView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.height.equalTo(114)
}
}
func loadData() {
if !activityId.isEmpty {
viewModel.getActivityDetailData(activityID: activityId) { success, error in
......@@ -195,7 +195,7 @@ extension YHActivityDetailViewController {
YHHUD.flash(message: msg)
self.navigationController?.popViewController()
}
// tableView
self.tableView.reloadData()
}
......@@ -204,9 +204,9 @@ extension YHActivityDetailViewController {
navigationController?.popViewController()
}
}
func requestImages() {
guard let detailModel = self.viewModel.activityDetailModel else {
guard let detailModel = viewModel.activityDetailModel else {
return
}
let ossGroup = DispatchGroup()
......@@ -214,13 +214,13 @@ extension YHActivityDetailViewController {
ossGroup.enter()
item.imgView.kf.setImage(with: URL(string: item.url)) { result in
switch result {
case .success(let value):
case let .success(value):
let size = value.image.size
let scale = size.width > 0 ? Double(size.height / size.width) : 0.0
if scale > 0 {
item.height = scale * item.width
}
case .failure(let error):
case let .failure(error):
print("Job failed: \(error.localizedDescription)")
}
ossGroup.leave()
......@@ -230,9 +230,8 @@ extension YHActivityDetailViewController {
self.tableView.reloadData()
}
}
func applyActivity(param: [String: Any]) {
viewModel.applyActivity(param: param) { success, error in
if success {
YHHUD.flash(message: "报名成功")
......@@ -264,41 +263,37 @@ extension YHActivityDetailViewController: UITableViewDelegate, UITableViewDataSo
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel.arrActivityDetail.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: YHActivityDetailCell.cellReuseIdentifier, for: indexPath) as! YHActivityDetailCell
cell.dataModel = viewModel.activityDetailModel
if indexPath.row < viewModel.arrActivityDetail.count {
let model = viewModel.arrActivityDetail[indexPath.row]
if model.type == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: YHActivityDetailCell0.cellReuseIdentifier, for: indexPath) as! YHActivityDetailCell0
cell.dataModel = model.activityDetailModel ?? YHActivityDetailModel()
return cell
} else if model.type == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: YHActivityDetailCell1.cellReuseIdentifier, for: indexPath) as! YHActivityDetailCell1
cell.dataModel = model.activityDetailModel ?? YHActivityDetailModel()
return cell
} else if model.type == 2 {
let cell = tableView.dequeueReusableCell(withIdentifier: YHActivityDetailCell2.cellReuseIdentifier, for: indexPath) as! YHActivityDetailCell2
cell.dataModel = model.activityDetailModel ?? YHActivityDetailModel()
return cell
}
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
......
......@@ -6,20 +6,19 @@
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import JXSegmentedView
import UIKit
enum YHActivityStatus: Int {
// 活动的状态 1:立即报名 2:已报名 3:活动结束 4:已取消报名
case unknow = 0 // 未知
case notApply = 1 // 立即报名
case applied = 2 // 已报名
case end = 3 // 活动结束
case canceled = 4 // 已取消报名
case soldout = 5 // 活动下架
var titleForList: String {
switch self {
case .notApply:
......@@ -36,7 +35,7 @@ enum YHActivityStatus: Int {
return ""
}
}
var titleForMyApplyList: String {
switch self {
case .notApply:
......@@ -53,7 +52,7 @@ enum YHActivityStatus: Int {
return ""
}
}
var titleForDetail: String {
switch self {
case .notApply:
......@@ -70,7 +69,7 @@ enum YHActivityStatus: Int {
return ""
}
}
var activityColor: UIColor {
switch self {
case .notApply:
......@@ -87,7 +86,7 @@ enum YHActivityStatus: Int {
return UIColor.clear
}
}
var activityColorForMyApplyList: UIColor {
switch self {
case .notApply:
......@@ -110,14 +109,13 @@ enum YHActivityStatus: Int {
活动列表 或 我的报名活动
*/
class YHActivityListViewController: YHBaseViewController {
var type: Int = 0 // 0-活动列表 1-我的报名活动
lazy var viewModel: YHActivityViewModel = {
let vm = YHActivityViewModel()
return vm
}()
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.showsVerticalScrollIndicator = false
......@@ -130,29 +128,30 @@ class YHActivityListViewController: YHBaseViewController {
tableView.backgroundView = self.emptyDataTipsView
return tableView
}()
lazy var emptyDataTipsView: YHEmptyDataView = {
let view = YHEmptyDataView.createView("暂无活动", kEmptyCommonBgName)
view.topMargin = 222
view.isHidden = true
return view
}()
// MARK: - 生命周期方法
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
gk_navigationBar.isHidden = true
gk_navigationBar.backgroundColor = .white
view.addSubview(tableView)
if type == 1 {
gk_navTitle = "我的活动"
gk_navigationBar.isHidden = false
gk_navigationBar.backgroundColor = .clear
tableView.snp.makeConstraints { make in
make.left.equalTo(20)
make.right.equalTo(-20)
......@@ -167,7 +166,7 @@ class YHActivityListViewController: YHBaseViewController {
make.top.equalToSuperview()
}
}
tableView.es.addYHPullToRefresh {
self.loadFirstData()
}
......@@ -175,11 +174,10 @@ class YHActivityListViewController: YHBaseViewController {
tableView.es.addInfiniteScrolling {
self.loadMoreData()
}
emptyDataTipsView.isHidden = viewModel.arrActivityListData.count > 0 ? true : false
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
loadFirstData()
......@@ -188,29 +186,29 @@ class YHActivityListViewController: YHBaseViewController {
extension YHActivityListViewController {
func loadMoreData() {
self.viewModel.getActivityList(firstFlag: false, type: type) {[weak self] _, _ in
viewModel.getActivityList(firstFlag: false, type: type) { [weak self] _, _ in
guard let self = self else { return }
self.tableView.reloadData()
self.emptyDataTipsView.isHidden = self.viewModel.arrActivityListData.count > 0 ? true : false
// DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.35, execute: {
self.tableView.es.stopLoadingMore()
if self.viewModel.hasMoreForActivityList == false {
self.tableView.es.noticeNoMoreData()
self.tableView.footer?.alpha = 1
}
self.tableView.es.stopLoadingMore()
if self.viewModel.hasMoreForActivityList == false {
self.tableView.es.noticeNoMoreData()
self.tableView.footer?.alpha = 1
}
// })
self.tableView.reloadData()
}
}
func loadFirstData() {
self.viewModel.getActivityList(firstFlag: true, type: type) {[weak self] _, _ in
viewModel.getActivityList(firstFlag: true, type: type) { [weak self] _, _ in
guard let self = self else { return }
self.tableView.es.stopPullToRefresh()
self.tableView.reloadData()
self.emptyDataTipsView.isHidden = self.viewModel.arrActivityListData.count > 0 ? true : false
self.tableView.es.stopPullToRefresh()
......@@ -229,37 +227,36 @@ extension YHActivityListViewController {
}
extension YHActivityListViewController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
if viewModel.arrActivityListData.count > 0 {
return viewModel.arrActivityListData.count
}
return 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: YHActivityListCell.cellReuseIdentifier, for: indexPath) as! YHActivityListCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: YHActivityListCell.cellReuseIdentifier, for: indexPath) as? YHActivityListCell else { return UITableViewCell() }
cell.sessionIndex = indexPath.section
cell.type = type
if indexPath.section < viewModel.arrActivityListData.count {
cell.dataModel = viewModel.arrActivityListData[indexPath.section]
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 185.0
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section < viewModel.arrActivityListData.count {
let model = viewModel.arrActivityListData[indexPath.section]
if type == 1 {
if model.status.int == 2 {
gotoActivityTravelVC(checkId: model.checkId)
......@@ -269,40 +266,39 @@ extension YHActivityListViewController: UITableViewDelegate, UITableViewDataSour
return
}
}
let vc = YHActivityDetailViewController()
vc.activityId = String(model.id)
vc.activityId = String(model.id)
vc.activityName = model.name
navigationController?.pushViewController(vc)
}
}
func gotoActivityTravelVC(checkId: String = "") {
if let nav = self.navigationController {
if let nav = navigationController {
let rrr = nav.viewControllers.contains { $0.isKind(of: YHActivityTravelViewController.self) }
if rrr {
var targetVc: UIViewController?
for(_, value) in nav.viewControllers.enumerated() {
var targetVc: UIViewController?
for (_, value) in nav.viewControllers.enumerated() {
if value.isKind(of: YHActivityTravelViewController.self) {
targetVc = value
break
}
}
if let vc = targetVc {
navigationController?.popToViewController(vc, animated: true)
}
return
}
}
// 行程单详情
let vc = YHActivityTravelViewController()
vc.travelId = checkId
navigationController?.pushViewController(vc)
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
var height: CGFloat = 16.0
if section != 0 {
......@@ -310,25 +306,24 @@ extension YHActivityListViewController: UITableViewDelegate, UITableViewDataSour
}
return height
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
var height: CGFloat = 16.0
if section != 0 {
height = 20.0
}
let view = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth-16.0*2, height: height))
let view = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth - 16.0 * 2, height: height))
view.backgroundColor = .clear
return view
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let view = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth-16.0*2, height: 0.001))
let view = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth - 16.0 * 2, height: 0.001))
view.backgroundColor = .clear
return view
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.001
}
......
......@@ -233,7 +233,8 @@ extension YHActivityTravelViewController: UITableViewDelegate, UITableViewDataSo
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: YHActivityTravelCell.cellReuseIdentifier, for: indexPath) as! YHActivityTravelCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: YHActivityTravelCell.cellReuseIdentifier, for: indexPath) as? YHActivityTravelCell else { return UITableViewCell() }
cell.dataModel = viewModel.activityTravelModel
cell.block = {[weak self] in
self?.clickBottomButton()
......
......@@ -88,7 +88,8 @@ extension YHMyGoodFriendsVC: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: YHAddFriendCardCell.cellReuseIdentifier, for: indexPath) as! YHAddFriendCardCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: YHAddFriendCardCell.cellReuseIdentifier, for: indexPath) as? YHAddFriendCardCell else { return UITableViewCell() }
cell.cardCount = self.friendRequestArr.count
if self.friendRequestArr.count > 0 {
cell.friendModel = self.friendRequestArr[0]
......@@ -118,7 +119,7 @@ extension YHMyGoodFriendsVC: UITableViewDelegate, UITableViewDataSource {
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: YHMyFriendsCell.cellReuseIdentifier, for: indexPath) as! YHMyFriendsCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: YHMyFriendsCell.cellReuseIdentifier, for: indexPath) as? YHMyFriendsCell else { return UITableViewCell() }
if 0 <= indexPath.row && indexPath.row < friendsArr.count {
let friend = self.friendsArr[indexPath.row]
cell.friendModel = friend
......
......@@ -127,7 +127,7 @@ extension YHNameCardViewController: UITableViewDelegate, UITableViewDataSource {
let cardInfo = self.cardInfoArr[indexPath.section]
if cardInfo.type == .avatar {
let cell = tableView.dequeueReusableCell(withIdentifier: YHMyNameCardAvatarInfoCell.cellReuseIdentifier, for: indexPath) as! YHMyNameCardAvatarInfoCell
guard let cell = tableView.dequeueReusableCell(withIdentifier: YHMyNameCardAvatarInfoCell.cellReuseIdentifier, for: indexPath) as? YHMyNameCardAvatarInfoCell else { return UITableViewCell() }
cell.userModel = cardInfo
cell.editBlock = { [weak self] in
guard let self = self else { return }
......@@ -139,7 +139,8 @@ extension YHNameCardViewController: UITableViewDelegate, UITableViewDataSource {
}
if cardInfo.type == .honor || cardInfo.type == .introduce {
let introCell = tableView.dequeueReusableCell(withIdentifier: YHMyIntroductionCell.cellReuseIdentifier, for: indexPath) as! YHMyIntroductionCell
guard let introCell = tableView.dequeueReusableCell(withIdentifier: YHMyIntroductionCell.cellReuseIdentifier, for: indexPath) as? YHMyIntroductionCell else { return UITableViewCell() }
introCell.userModel = cardInfo
introCell.editBlock = { [weak self] in
guard let self = self else { return }
......@@ -157,7 +158,7 @@ extension YHNameCardViewController: UITableViewDelegate, UITableViewDataSource {
}
if cardInfo.type == .education {
let eduCell = tableView.dequeueReusableCell(withIdentifier: YHMyEducationCell.cellReuseIdentifier, for: indexPath) as! YHMyEducationCell
guard let eduCell = tableView.dequeueReusableCell(withIdentifier: YHMyEducationCell.cellReuseIdentifier, for: indexPath) as? YHMyEducationCell else { return UITableViewCell() }
eduCell.userModel = cardInfo
eduCell.hiddenBtnBlock = {
[weak self] in
......@@ -174,7 +175,7 @@ extension YHNameCardViewController: UITableViewDelegate, UITableViewDataSource {
}
if cardInfo.type == .workExperience {
let workCell = tableView.dequeueReusableCell(withIdentifier: YHMyWorkExperienceCell.cellReuseIdentifier, for: indexPath) as! YHMyWorkExperienceCell
guard let workCell = tableView.dequeueReusableCell(withIdentifier: YHMyWorkExperienceCell.cellReuseIdentifier, for: indexPath) as? YHMyWorkExperienceCell else { return UITableViewCell() }
workCell.userModel = cardInfo
workCell.hiddenBtnBlock = {
[weak self] in
......@@ -191,7 +192,7 @@ extension YHNameCardViewController: UITableViewDelegate, UITableViewDataSource {
}
if cardInfo.type == .topics {
let topicCell = tableView.dequeueReusableCell(withIdentifier: YHMyInterestTopicCell.cellReuseIdentifier, for: indexPath) as! YHMyInterestTopicCell
guard let topicCell = tableView.dequeueReusableCell(withIdentifier: YHMyInterestTopicCell.cellReuseIdentifier, for: indexPath) as? YHMyInterestTopicCell else { return UITableViewCell() }
topicCell.userModel = cardInfo
topicCell.editBlock = { [weak self] in
guard let self = self else { return }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment