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

首页直播优化需求开发

parent baab3eee
......@@ -31,6 +31,7 @@
0411CF122D1C065300644D35 /* YHGCSignatureAddViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0411CF112D1C065300644D35 /* YHGCSignatureAddViewModel.swift */; };
0411CF142D1C0B0700644D35 /* YHGCSignatureAddModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0411CF132D1C0B0700644D35 /* YHGCSignatureAddModel.swift */; };
0411CF162D1C0D0C00644D35 /* YHGCSignatureAddTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0411CF152D1C0D0C00644D35 /* YHGCSignatureAddTableViewCell.swift */; };
0411CF182D1D502D00644D35 /* YHlifeCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0411CF172D1D502D00644D35 /* YHlifeCollectionReusableView.swift */; };
04307B662D1942F500ED8E8D /* YHDynamicSheetPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307B652D1942F500ED8E8D /* YHDynamicSheetPickerView.swift */; };
04307B682D19911800ED8E8D /* YHIncomeInfoEditCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307B672D19911800ED8E8D /* YHIncomeInfoEditCell.swift */; };
04307B6A2D1A4C6500ED8E8D /* YHIncomeInfoSelectCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04307B692D1A4C6500ED8E8D /* YHIncomeInfoSelectCell.swift */; };
......@@ -1232,6 +1233,7 @@
0411CF112D1C065300644D35 /* YHGCSignatureAddViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHGCSignatureAddViewModel.swift; sourceTree = "<group>"; };
0411CF132D1C0B0700644D35 /* YHGCSignatureAddModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHGCSignatureAddModel.swift; sourceTree = "<group>"; };
0411CF152D1C0D0C00644D35 /* YHGCSignatureAddTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHGCSignatureAddTableViewCell.swift; sourceTree = "<group>"; };
0411CF172D1D502D00644D35 /* YHlifeCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHlifeCollectionReusableView.swift; sourceTree = "<group>"; };
04307B652D1942F500ED8E8D /* YHDynamicSheetPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHDynamicSheetPickerView.swift; sourceTree = "<group>"; };
04307B672D19911800ED8E8D /* YHIncomeInfoEditCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHIncomeInfoEditCell.swift; sourceTree = "<group>"; };
04307B692D1A4C6500ED8E8D /* YHIncomeInfoSelectCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHIncomeInfoSelectCell.swift; sourceTree = "<group>"; };
......@@ -3041,6 +3043,7 @@
045C0ACB2D12CA5E00BD2DC0 /* YHLifeHeadView.swift */,
045C0ACC2D12CA5E00BD2DC0 /* YHLifeItemTableViewCell.swift */,
045C0ACD2D12CA5E00BD2DC0 /* YHLifeSectionView.swift */,
0411CF172D1D502D00644D35 /* YHlifeCollectionReusableView.swift */,
);
path = V;
sourceTree = "<group>";
......@@ -7135,6 +7138,7 @@
045C111D2D12CA5F00BD2DC0 /* YHResignInfoValidTimeItemView.swift in Sources */,
045C111E2D12CA5F00BD2DC0 /* YHPreviewAcademicAndProfessionalQualificationViewController.swift in Sources */,
045C111F2D12CA5F00BD2DC0 /* YHWorkExperienceTableViewCell.swift in Sources */,
0411CF182D1D502D00644D35 /* YHlifeCollectionReusableView.swift in Sources */,
045C11202D12CA5F00BD2DC0 /* UITextField+Extension.swift in Sources */,
045C11212D12CA5F00BD2DC0 /* YHPlayer.swift in Sources */,
045C11222D12CA5F00BD2DC0 /* YHAddAdoptersViewController.swift in Sources */,
......
......@@ -32,6 +32,7 @@ class YHLifeViewController: YHBaseViewController {
collectinoView.backgroundColor = .white
// collectinoView.contentInset = UIEdgeInsets(top: 16, left: 20, bottom: 0, right: 20)
collectinoView.register(YHLookCollectionViewCell.self, forCellWithReuseIdentifier:YHLookCollectionViewCell.cellReuseIdentifier)
collectinoView.register(YHlifeCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: YHlifeCollectionReusableView.reuseIdentifier)
collectinoView.delegate = self
collectinoView.dataSource = self
collectinoView.translatesAutoresizingMaskIntoConstraints = false
......@@ -97,6 +98,10 @@ extension YHLifeViewController {
}
}
self.viewModel.getSchedulLiveList {[weak self] success, error in
guard let self = self else { return }
self.myCollectView.reloadData()
}
}
func getDetailImages() {
......@@ -272,7 +277,7 @@ extension YHLifeViewController: JXSegmentedListContainerViewListDelegate {
}
}
extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSource {
extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.viewModel.liveArr.count
......@@ -298,6 +303,24 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo
let playbackInfo = YHPlayerManager.PlaybackInfo(id: item.id, url: nil, title: item.live_title, roomId: item.room_id.count > 0 ? item.room_id : nil, uid: nil, isLive: true, scene: .fullscreen)
YHPlayerManager.shared.enterLive(from: nil, playbackInfo: playbackInfo)
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionView.elementKindSectionFooter {
let footerView = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: YHlifeCollectionReusableView.reuseIdentifier, for: indexPath) as! YHlifeCollectionReusableView
// 配置 footerView
footerView.dataSource = self.viewModel.schedulLiveArr
return footerView
}
return UICollectionReusableView()
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
if self.viewModel.schedulLiveArr.count != 0 {
let height = 50.0 + 104.0 * Double(self.viewModel.schedulLiveArr.count)
return CGSize(width: KScreenWidth, height: height) // 根据需要设置高度
}
return CGSize(width: KScreenWidth, height: 0) // 根据需要设置高度
}
}
class YHLookCollectionViewCell: UICollectionViewCell {
......
//
// YHlifeCollectionReusableView.swift
// galaxy
//
// Created by EDY on 2024/12/26.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHlifeCollectionReusableView: UICollectionReusableView {
static let reuseIdentifier = "YHlifeCollectionReusableView"
var tableView: UITableView!
var sectionView: YHlifeCollectionReusableViewHeadView!
var dataSource: [YHLiveListModel]? {
didSet {
self.tableView.reloadData()
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}
private func setupView() {
sectionView = {
let view = YHlifeCollectionReusableViewHeadView()
view.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: 50)
return view
}()
tableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.contentInsetAdjustmentBehavior = .never
tableView.backgroundColor = .white
tableView.separatorStyle = .none
tableView.showsHorizontalScrollIndicator = false
tableView.showsVerticalScrollIndicator = false
tableView.dataSource = self
tableView.delegate = self
tableView.tableHeaderView = sectionView
tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 0.01))
tableView.register(cellWithClass: YHlifeCollectionReusableViewTableViewCell.self)
return tableView
}()
addSubview(tableView)
tableView.snp.makeConstraints { make in
make.top.bottom.left.right.equalToSuperview()
}
}
}
extension YHlifeCollectionReusableView: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withClass: YHlifeCollectionReusableViewTableViewCell.self)
cell.dataSource = dataSource?[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 104
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0.01
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.01
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
}
class YHlifeCollectionReusableViewHeadView: UIView {
var lineView: UIView!
var flagView: UIView!
var titleLabel: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .white
setUpView()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setUpView() {
backgroundColor = .white
lineView = {
let view = UIView()
view.backgroundColor = UIColor.separatorColor
return view
}()
addSubview(lineView)
lineView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalToSuperview()
make.height.equalTo(1)
}
flagView = {
let view = UIView()
view.backgroundColor = UIColor.brandMainColor
return view
}()
addSubview(flagView)
flagView.snp.makeConstraints { make in
make.left.equalToSuperview()
make.top.equalTo(23)
make.height.equalTo(11)
make.width.equalTo(3)
}
titleLabel = {
let label = UILabel()
label.text = "即将开播"
label.font = UIFont.PFSC_R(ofSize: 14)
label.textColor = UIColor.mainTextColor
return label
}()
addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalTo(7)
make.centerY.equalTo(flagView.snp.centerY)
make.height.equalTo(17)
make.right.equalToSuperview()
}
}
}
class YHlifeCollectionReusableViewTableViewCell: UITableViewCell {
var centerImageView: UIImageView!
var titleLabel: UILabel!
var subTitleLabel: UILabel!
var headImageView: UIImageView!
var flagLabel: UILabel!
var timelabel: UILabel!
var actionButton: UIButton!
var dataSource: YHLiveListModel? {
didSet {
guard let dataSource = dataSource else { return }
self.titleLabel.text = dataSource.title
self.subTitleLabel.text = dataSource.account
self.timelabel.text = dataSource.start_time
flagLabel.isHidden = false
actionButton.isSelected = dataSource.is_schedule_live
guard let url = URL(string: dataSource.image) else { return }
self.centerImageView.kf.setImage(with: url)
guard let url = URL(string: dataSource.avatarurl) else { return }
self.headImageView.kf.setImage(with: url)
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
selectionStyle = .none
setupUI()
}
func setupUI() {
self.backgroundColor = .white
let bgview = {
let view = UIView()
view.layer.borderWidth = 1
view.layer.borderColor = UIColor.separatorColor.cgColor
return view
}()
contentView.addSubview(bgview)
bgview.snp.makeConstraints { make in
make.top.equalTo(6)
make.bottom.equalTo(-6)
make.left.right.equalToSuperview()
}
centerImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "global_default_image")
return imageView
}()
contentView.addSubview(centerImageView)
centerImageView.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalToSuperview()
make.height.width.equalTo(92)
}
titleLabel = {
let view = UILabel()
view.text = "高才A香港企明星(7)"
view.font = UIFont.PFSC_M(ofSize: 14)
view.textColor = UIColor.mainTextColor
view.numberOfLines = 2
return view
}()
contentView.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.equalTo(centerImageView.snp.right).offset(12)
make.right.equalToSuperview()
make.top.equalTo(centerImageView.snp.top)
make.height.equalTo(22)
}
subTitleLabel = {
let view = UILabel()
view.text = "高才专家社"
view.font = UIFont.PFSC_M(ofSize: 12)
view.textColor = UIColor(hex: 0x6d788a)
view.numberOfLines = 2
return view
}()
contentView.addSubview(subTitleLabel)
subTitleLabel.snp.makeConstraints { make in
make.left.equalTo(centerImageView.snp.right).offset(34)
make.right.equalTo(-20)
make.bottom.equalTo(-16.5)
make.height.equalTo(20)
}
flagLabel = {
let label = UILabel()
label.text = "预告"
label.textAlignment = .center
label.textColor = .white
label.backgroundColor = .brandMainColor
label.font = UIFont.PFSC_R(ofSize: 10)
return label
}()
centerImageView.addSubview(flagLabel)
flagLabel.snp.makeConstraints { make in
make.left.top.equalToSuperview()
make.width.equalTo(28)
make.height.equalTo(16)
}
timelabel = {
let view = UILabel()
view.text = "12月19日 09:00~11:00"
view.font = UIFont.PFSC_M(ofSize: 12)
view.textColor = UIColor.brandMainColor
return view
}()
contentView.addSubview(timelabel)
timelabel.snp.makeConstraints { make in
make.left.equalTo(centerImageView.snp.right).offset(12)
make.right.equalTo(-20)
make.top.equalTo(centerImageView.snp.top).offset(26)
make.height.equalTo(18)
}
headImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "global_default_image")
imageView.layer.cornerRadius = 10
imageView.layer.masksToBounds = true
return imageView
}()
contentView.addSubview(headImageView)
headImageView.snp.makeConstraints { make in
make.bottom.equalTo(-15)
make.left.equalTo(centerImageView.snp.right).offset(12)
make.height.width.equalTo(20)
}
actionButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 12)
button.contentHorizontalAlignment = .center
button.setTitle("预约", for: .normal)
button.setTitle("已预约", for: .selected)
button.setTitleColor(UIColor(hex: 0xb3c8e9), for: .selected)
button.setTitleColor(UIColor.brandMainColor, for: .normal)
button.setBackgroundColor(color: UIColor(hex:0xebf0f9), forState: .normal)
button.addTarget(self, action: #selector(actionClick), for: .touchUpInside)
button.layer.cornerRadius = 3
return button
}()
contentView.addSubview(actionButton)
actionButton.snp.makeConstraints { make in
make.bottom.right.equalTo(-12)
make.width.equalTo(60)
make.height.equalTo(28)
}
}
@objc func actionClick() {
actionButton.isSelected = true
}
}
......@@ -22,3 +22,22 @@ class YHLiveModel: SmartCodable {
}
}
class YHLiveListModel: SmartCodable {
var live_id: Int = 0
var title: String = ""
var avatarurl: String = ""
var status: Int = 0
var start_time: String = ""
var account: String = ""
var image: String = ""
var is_schedule_live: Bool = false
required init() {
}
}
class YHLiveListDataModel: SmartCodable {
var live_list: [YHLiveListModel] = []
required init() {
}
}
......@@ -20,6 +20,7 @@ class YHHomePageViewModel : YHBaseViewModel {
var categoryArr:[YHHomeLifeCategoryModel?] = []
var detailModel: YHHomeLifeCategoryDetailModel = YHHomeLifeCategoryDetailModel()
var liveArr: [YHLiveModel] = []
var schedulLiveArr: [YHLiveListModel] = []
var liveInfo: YHHomeLiveInfoModel?
//首页相关参数
private var curPageIndex : Int = 1
......@@ -576,6 +577,30 @@ extension YHHomePageViewModel {
}
}
func getSchedulLiveList(callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.schedulLiveList
let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
guard let self = self else { return }
//1. json字符串 转 对象
if json.code == 200 {
guard let dic = json.data?.peel as? [String : Any], let resultModel = YHLiveListDataModel.deserialize(from: dic) else {
self.schedulLiveArr = []
callBackBlock(false,nil)
return
}
self.schedulLiveArr = resultModel.live_list
callBackBlock(true, nil)
} else {
self.schedulLiveArr = []
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
self.schedulLiveArr = []
callBackBlock(false, err)
}
}
//获取首页浮动小窗
func getHomeFloatingLive(callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Home.homeFloatingLive
......
......@@ -16,6 +16,8 @@ class YHSelectViewController: YHBaseViewController {
var headView: YHSelectLookHeadView!
var viewModel: YHSelectViewModel = YHSelectViewModel()
var selectItem: Int = 0
var buttonItem: Int = 0
var selectMenuView: YHSelectMenuView!
var canShowMenu: Bool = true
var hideFlag: Bool = false
......@@ -52,8 +54,13 @@ extension YHSelectViewController {
func loadData() {
self.viewModel.getCategoryList {[weak self] success, error in
guard let self = self else { return }
var dataSource: [String] = []
for item in self.viewModel.categoryArray {
dataSource.append(item.name)
}
self.headView.items = dataSource
}
self.viewModel.getGoodsList(categoryID: "0") {[weak self] success, error in
self.viewModel.getGoodsList(categoryID: "0", sortType: 0) {[weak self] success, error in
guard let self = self else { return }
self.tableView.reloadData()
if self.viewModel.goodsArray.count == 0 {
......@@ -76,7 +83,7 @@ extension YHSelectViewController {
func updataData() {
if selectItem < self.viewModel.categoryArray.count {
let model = self.viewModel.categoryArray[selectItem]
self.viewModel.getGoodsList(categoryID: model.id) {[weak self] success, error in
self.viewModel.getGoodsList(categoryID: model.id, sortType: buttonItem) {[weak self] success, error in
guard let self = self else { return }
self.tableView.reloadData()
if self.viewModel.goodsArray.count == 0 {
......@@ -112,27 +119,14 @@ extension YHSelectViewController {
sectionView.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: 92)
headView = {
let head = YHSelectLookHeadView()
head.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: 46)
head.block = {
self.tableView.setContentOffset(CGPoint(x: 0, y: 92), animated: true)
var dataSource: [String] = []
for item in self.viewModel.categoryArray {
dataSource.append(item.name)
}
if self.canShowMenu {
self.canShowMenu = false
self.selectMenuView = YHSelectMenuView()
var top: CGFloat = k_Height_NavigationtBarAndStatuBar + 46
if self.hideFlag {
top = k_Height_safeAreaInsetsTop() + 6 + 36 + 46 + 46
}
self.selectMenuView.show(top: top, selectItem: self.selectItem, dataSource: dataSource) { item in
self.selectItem = item
self.updataData()
self.canShowMenu = true
self.headView.itemButton.isSelected = false
}
}
head.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: 66)
head.block = { index in
self.selectItem = index
self.updataData()
}
head.buttonBlock = { index in
self.buttonItem = index
self.updataData()
}
return head
}()
......@@ -192,15 +186,15 @@ extension YHSelectViewController: UITableViewDelegate, UITableViewDataSource {
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 46
return 66
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
if selectItem < self.viewModel.categoryArray.count {
let model = self.viewModel.categoryArray[selectItem]
headView.itemButton.setTitle(model.name, for: .normal)
headView.itemButton.iconInRight(with: 0.5)
}
// if selectItem < self.viewModel.categoryArray.count {
// let model = self.viewModel.categoryArray[selectItem]
// headView.itemButton.setTitle(model.name, for: .normal)
// headView.itemButton.iconInRight(with: 0.5)
// }
return headView
}
......@@ -249,10 +243,10 @@ extension YHSelectViewController: JXSegmentedListContainerViewListDelegate {
}
func listWillDisappear() {
self.headView.itemButton.isSelected = false
if (self.selectMenuView != nil) {
self.selectMenuView.removeFromSuperview()
}
// self.headView.itemButton.isSelected = false
// if (self.selectMenuView != nil) {
// self.selectMenuView.removeFromSuperview()
// }
}
}
......
......@@ -9,9 +9,40 @@
import UIKit
class YHSelectLookHeadView: UIView {
typealias Block = () -> ()
typealias Block = (Int) -> ()
var block: Block?
var itemButton: UIButton!
var buttonBlock: Block?
var normalButton: UIButton!
var hotButton: UIButton!
var priceButton: UIButton!
var buttonIndex = 0
var items: [String] = [] {
didSet {
self.myCollectView.reloadData()
}
}
lazy var myCollectView = {
// 设置布局方向
let flowLayout = UICollectionViewFlowLayout()
// flowLayout.itemSize = CGSize(width: 60, height: 76)
flowLayout.minimumInteritemSpacing = 12.0
flowLayout.minimumLineSpacing = 12.0
flowLayout.scrollDirection = .horizontal
let collectinoView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
collectinoView.backgroundColor = .white
collectinoView.contentInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
collectinoView.register(YHSelectLookHeadViewCollectionViewCell.self, forCellWithReuseIdentifier:YHSelectLookHeadViewCollectionViewCell.cellReuseIdentifier)
collectinoView.delegate = self
collectinoView.dataSource = self
collectinoView.translatesAutoresizingMaskIntoConstraints = false
collectinoView.alwaysBounceVertical = true
collectinoView.bounces = false
collectinoView.showsHorizontalScrollIndicator = false
collectinoView.showsVerticalScrollIndicator = false
return collectinoView
}()
var selectIndex = 0 {
didSet {
......@@ -30,35 +61,204 @@ class YHSelectLookHeadView: UIView {
func setUpView() {
backgroundColor = .white
itemButton = {
addSubview(myCollectView)
myCollectView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.height.equalTo(46)
}
normalButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 12)
button.contentHorizontalAlignment = .center
button.setTitle("默认", for: .normal)
// button.setImage(UIImage(named: "home_select_icon"), for: .normal)
button.setTitleColor(UIColor(hex: 0x8993a2), for: .normal)
button.setTitleColor(UIColor.brandMainColor, for: .selected)
// button.setImage(UIImage(named: "home_select_icon_select"), for: .selected)
button.addTarget(self, action: #selector(normalClick), for: .touchUpInside)
return button
}()
addSubview(normalButton)
normalButton.snp.makeConstraints { make in
make.left.equalTo(20)
make.bottom.equalToSuperview()
make.height.equalTo(16)
make.width.equalTo(24)
}
hotButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 12)
button.contentHorizontalAlignment = .center
button.setTitle("热门", for: .normal)
// button.setImage(UIImage(named: "home_select_icon"), for: .normal)
button.setTitleColor(UIColor(hex: 0x8993a2), for: .normal)
button.setTitleColor(UIColor.brandMainColor, for: .selected)
// button.setImage(UIImage(named: "home_select_icon_select"), for: .selected)
button.addTarget(self, action: #selector(hotClick), for: .touchUpInside)
return button
}()
addSubview(hotButton)
hotButton.snp.makeConstraints { make in
make.left.equalTo(normalButton.snp.right).offset(20)
make.bottom.equalToSuperview()
make.height.equalTo(16)
make.width.equalTo(24)
}
priceButton = {
let button = UIButton(type: .custom)
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 12)
button.contentHorizontalAlignment = .center
button.setTitle("全部产品", for: .normal)
button.setTitle("价格", for: .normal)
button.setImage(UIImage(named: "home_select_icon"), for: .normal)
button.setTitleColor(UIColor(hex: 0x6d788a), for: .normal)
button.setTitleColor(UIColor(hex: 0x8993a2), for: .normal)
button.setTitleColor(UIColor.brandMainColor, for: .selected)
button.setImage(UIImage(named: "home_select_icon_select"), for: .selected)
button.setBackgroundColor(color: UIColor.contentBkgColor, forState: .normal)
button.setBackgroundColor(color: UIColor(hex: 0xebf0f9), forState: .selected)
button.addTarget(self, action: #selector(itemClick), for: .touchUpInside)
button.contentEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
button.addTarget(self, action: #selector(priceClick), for: .touchUpInside)
return button
}()
addSubview(itemButton)
itemButton.snp.makeConstraints { make in
make.left.equalTo(20)
make.top.equalTo(12)
make.height.equalTo(26)
// make.width.equalTo(92)
addSubview(priceButton)
priceButton.snp.makeConstraints { make in
make.left.equalTo(hotButton.snp.right).offset(20)
make.bottom.equalToSuperview()
make.height.equalTo(16)
make.width.equalTo(40)
}
itemButton.iconInRight(with: 0.5)
priceButton.iconInRight(with: 0.5)
}
@objc func itemClick() {
itemButton.isSelected = true
if let block = self.block {
block()
@objc func normalClick() {
normalButton.isSelected = true
hotButton.isSelected = false
priceButton.isSelected = false
if let block = self.buttonBlock {
block(0)
}
buttonIndex = 0
}
@objc func hotClick() {
normalButton.isSelected = false
hotButton.isSelected = true
priceButton.isSelected = false
if let block = self.buttonBlock {
block(1)
}
buttonIndex = 1
}
@objc func priceClick() {
normalButton.isSelected = false
hotButton.isSelected = false
priceButton.isSelected = true
if buttonIndex != 2 {
if let block = self.buttonBlock {
block(2)
}
buttonIndex = 2
priceButton.setImage(UIImage(named: "home_select_icon_select"), for: .selected)
} else {
if let block = self.buttonBlock {
block(3)
}
buttonIndex = 3
priceButton.setImage(UIImage(named: "home_select_icon_select_two"), for: .selected)
}
}
}
extension YHSelectLookHeadView: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHSelectLookHeadViewCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHSelectLookHeadViewCollectionViewCell
cell.dataSource = items[indexPath.row]
if indexPath.row == selectIndex {
cell.setSelectedStyle()
} else {
cell.setDeSelectedStyle()
}
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
selectIndex = indexPath.row
collectionView.reloadData()
if let block = block {
block(indexPath.row)
}
print("index is \(indexPath.row)")
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// 根据数据内容计算单元格的大小
let text = items[indexPath.row] // 要显示的文本内容
let font = UIFont.PFSC_R(ofSize: 13) // 字体大小
let maxHeight = 26.0 // 最大宽度限制
// 创建NSAttributedString对象并设置属性
let attributes = [NSAttributedString.Key.font : font] as [NSAttributedString.Key : Any]
_ = NSMutableAttributedString(string: text, attributes: attributes)
// 根据指定的最大宽度和字体大小计算文本的高度
let size = (text as NSString).boundingRect(with: CGSize(width: .greatestFiniteMagnitude, height: maxHeight), options: .usesLineFragmentOrigin, attributes: attributes, context: nil).size
let itemWidth = size.width + 20.0 // 计算单元格宽度的逻辑
let itemHeight = 26.0 // 计算单元格高度的逻辑
return CGSize(width: itemWidth, height: itemHeight)
}
}
class YHSelectLookHeadViewCollectionViewCell: UICollectionViewCell {
static let cellReuseIdentifier = "YHLifeSectionCollectionViewCell"
func setSelectedStyle() {
descripeLable.textColor = UIColor.brandMainColor
descripeLable.backgroundColor = UIColor(hex: 0xebf0f9)
}
func setDeSelectedStyle() {
descripeLable.textColor = UIColor(hex: 0x435163)
descripeLable.backgroundColor = UIColor(hex: 0xf8f9fb)
}
var dataSource: String? {
didSet {
updataAllSubViews()
}
}
lazy var descripeLable:UILabel = {
let label = UILabel()
label.text = "赴港"
label.textColor = UIColor(hex: 0x94a3bb)
label.font = UIFont.PFSC_R(ofSize: 13)
label.textAlignment = .center
return label
}()
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
private func setupUI() {
contentView.addSubview(descripeLable)
descripeLable.snp.makeConstraints { make in
make.top.left.right.bottom.equalToSuperview()
}
}
func updataAllSubViews() {
guard let dataSource = dataSource else { return }
descripeLable.text = dataSource
}
}
......@@ -41,8 +41,8 @@ extension YHSelectViewModel {
}
}
func getGoodsList(categoryID: String, callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let params:[String : Any] = ["goods_category_id": categoryID, "page":1, "page_size": 100]
func getGoodsList(categoryID: String, sortType: Int,callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
let params:[String : Any] = ["goods_category_id": categoryID, "page":1, "page_size": 100, "sort_type": sortType]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.LiveSales.goodsList
let _ = YHNetRequest.getRequest(url: strUrl, params: params) { [weak self] json, code in
guard let self = self else { return }
......
......@@ -721,6 +721,7 @@ class YHAllApiName {
static let createOrder = "super-app/presale/app/order/create"
// APP直播间人数
static let livePeople = "super-app/live/live-people"
static let schedulLiveList = "super-app/live/schedule-live-list"
}
struct AIChat {
......
......@@ -5,12 +5,12 @@
"scale" : "1x"
},
{
"filename" : "home_select_icon@2x.png",
"filename" : "20pt@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "home_select_icon@3x.png",
"filename" : "20pt@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
......
......@@ -5,12 +5,12 @@
"scale" : "1x"
},
{
"filename" : "home_select_icon_select@2x.png",
"filename" : "20pt@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "home_select_icon_select@3x.png",
"filename" : "20pt@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "home_select_icon_select_two@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "home_select_icon_select_two@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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