//
|
// ReasonforTravelVC.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2023/4/14.
|
// Copyright © 2023 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import QMUIKit
|
|
class ReasonforTravelVC: YYViewController {
|
|
class PassengerInfo{
|
var name = ""
|
var phone:String?
|
|
convenience init(name:String,phone:String? = nil){
|
self.init()
|
self.name = name
|
self.phone = phone
|
}
|
}
|
|
@IBOutlet weak var scrollButtomCons: NSLayoutConstraint!
|
@IBOutlet weak var tableView: UITableView!
|
@IBOutlet weak var tableViewHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var collectViewHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var collectionView: UICollectionView!
|
@IBOutlet weak var btn_cost: QMUIButton!
|
@IBOutlet weak var btn_companyCost: QMUIButton!
|
@IBOutlet weak var textView: QMUITextView!
|
@IBOutlet weak var label_limit: UILabel!
|
@IBOutlet weak var tf_passenger: UITextField!
|
@IBOutlet weak var tf_passengerPhone: UITextField!
|
@IBOutlet weak var view_addPassenger: UIView!
|
var passengers = [PassengerInfo]()
|
|
var selectIndex = 0
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
btn_cost.spacingBetweenImageAndTitle = 7
|
btn_companyCost.spacingBetweenImageAndTitle = 7
|
tableView.delegate = self
|
tableView.dataSource = self
|
tableView.separatorStyle = .none
|
tableView.register(UINib(nibName: "Reason_Content_TCell", bundle: nil), forCellReuseIdentifier: "_Reason_Content_TCell")
|
collectionView.delegate = self
|
collectionView.dataSource = self
|
collectionView.contentInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
|
collectionView.register(UINib(nibName: "Common_SingleText_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_SingleText_CCell")
|
scrollButtomCons.constant = app.window?.safeAreaInsets.bottom ?? 0
|
let h = ceil(8 / 4.0) * 30.0 + floor(8 / 4.0) * 10.0
|
collectViewHeiCons.constant = h
|
|
passengers.append(PassengerInfo(name: "杨锴", phone: "18111223301"))
|
tableViewHeiCons.constant = 40 * Double(passengers.count)
|
}
|
|
override func bindRx() {
|
super.bindRx()
|
textView.rx.text.changed.subscribe(onNext: {text in
|
self.label_limit.text = "\(text?.count ?? 0)/50"
|
|
}).disposed(by: disposeBag)
|
}
|
|
|
@IBAction func paymentTypeAction(_ sender: UIButton) {
|
btn_cost.isSelected = btn_cost.tag == sender.tag
|
btn_companyCost.isSelected = btn_companyCost.tag == sender.tag
|
}
|
|
@IBAction func addPassengerAction(_ sender: UIButton) {
|
guard !tf_passenger.isEmpty else {
|
alert(text: "请输入或选择出行人");return
|
}
|
|
guard !tf_passengerPhone.isEmpty else {
|
alert(text: "请输入或选择出行人的电话号码");return
|
}
|
|
guard passengers.filter({$0.name == tf_passenger.text && $0.phone == tf_passengerPhone.text}).count == 0 else {
|
alert(text: "重复出行人");return
|
}
|
|
passengers.append(PassengerInfo(name: tf_passenger.text!, phone: tf_passengerPhone.text!))
|
tableViewHeiCons.constant = 40 * Double(passengers.count)
|
tableView.reloadData()
|
view_addPassenger.isHidden = passengers.count >= 4
|
}
|
|
@IBAction func closeAction(_ sender: Any) {
|
self.removeViewAndControllerFromParentViewController()
|
}
|
}
|
|
extension ReasonforTravelVC:UITableViewDelegate{
|
|
}
|
|
extension ReasonforTravelVC:UITableViewDataSource{
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_Reason_Content_TCell") as! Reason_Content_TCell
|
cell.index = indexPath
|
cell.label_name.text = passengers[indexPath.row].name
|
cell.tf_phone.text = passengers[indexPath.row].phone
|
|
cell.tf_phone.rx.text.changed.subscribe(onNext: { [weak self] text in
|
self?.passengers[indexPath.row].phone = text
|
}).disposed(by: disposeBag)
|
|
cell.deleteComplete { [weak self] index in
|
guard let weakSelf = self else { return }
|
weakSelf.passengers.remove(at: index.row)
|
weakSelf.tableView.reloadData()
|
weakSelf.view_addPassenger.isHidden = weakSelf.passengers.count >= 4
|
}
|
return cell
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return passengers.count
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
return 40
|
}
|
}
|
|
extension ReasonforTravelVC:UICollectionViewDelegate{
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
selectIndex = indexPath.row
|
collectionView.reloadData()
|
}
|
}
|
|
extension ReasonforTravelVC:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_SingleText_CCell", for: indexPath) as! Common_SingleText_CCell
|
cell.titleL.text = "测试"
|
cell.titleL.borderWidth = 1
|
cell.titleL.cornerRadius = 2
|
cell.titleL.backgroundColor = .white
|
cell.titleL.font = UIFont.systemFont(ofSize: 12, weight: .medium)
|
if selectIndex == indexPath.row{
|
cell.titleL.borderColor = UIColor(hexString: "#FF884D")!
|
cell.titleL.textColor = UIColor(hexString: "#FF884D")!
|
}else{
|
cell.titleL.borderColor = UIColor(hexString: "#90A1B1")!
|
cell.titleL.textColor = UIColor(hexString: "#90A1B1")!
|
}
|
return cell
|
}
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return 8
|
}
|
}
|
|
extension ReasonforTravelVC:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 10
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 10
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
return CGSizeMake(70, 30)
|
}
|
}
|