//
|
// MinePublishHireDetailVC.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2022/5/6.
|
// Copyright © 2022 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import WebKit
|
import Lantern
|
|
class MinePublishHireDetailVC: YYViewController {
|
@IBOutlet weak var scrollView: UIScrollView!
|
@IBOutlet weak var contanerBannerView: UIView!
|
@IBOutlet weak var titleL: UILabel!
|
@IBOutlet weak var rentMoneyL: UILabel! //租金
|
@IBOutlet weak var cashPledgeL: UILabel! //押金
|
@IBOutlet weak var carBrandL: UILabel! //车辆品牌
|
@IBOutlet weak var seatL: UILabel! // 座位
|
@IBOutlet weak var displacementL: UILabel! //排量
|
@IBOutlet weak var gearsL: UILabel! //档位
|
@IBOutlet weak var takeCarIdType: UILabel! //取车证件
|
@IBOutlet weak var contanctL: UILabel! //联系人
|
@IBOutlet weak var contanctAddressL: UILabel! //联系人地址
|
@IBOutlet weak var opt1Btn: UIButton!
|
@IBOutlet weak var opt2Btn: UIButton!
|
@IBOutlet weak var rejectView: UIView!
|
@IBOutlet weak var rejectL: UILabel! //拒绝原因
|
@IBOutlet weak var rejectHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var carTypeL: UILabel! //车辆类型
|
@IBOutlet weak var bannerNum: UILabel!
|
@IBOutlet weak var imgCollectionView: UICollectionView!
|
@IBOutlet weak var imgHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var descL: UILabel!
|
|
lazy var bannarView : HQFlowView = {
|
let bannar = HQFlowView()
|
bannar.delegate = self
|
bannar.dataSource = self
|
bannar.minimumPageAlpha = 0.1
|
bannar.leftRightMargin = 0
|
bannar.topBottomMargin = 0
|
bannar.autoTime = 5
|
bannar.isOpenAutoScroll = true
|
bannar.orientation = HQFlowViewOrientationHorizontal
|
return bannar
|
}()
|
|
// var bannerView:BannerView!
|
var rentalModel:RentCarReqModel?
|
private var videoImg:UIImage?
|
|
let cellW:Double = (SCREEN_WIDTH - 27)
|
let cellH:Double = (SCREEN_WIDTH - 27) * 0.497
|
|
override func viewWillAppear(_ animated: Bool) {
|
super.viewWillAppear(animated)
|
yy_nav_back_img = UIImage.init(named: "icon_back_white")!
|
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white,NSAttributedString.Key.font: UIFont.init(name: Medium, size: 18) ?? UIFont.systemFont(ofSize: 18)]
|
let image = UIImage(named: "LD_Rectangle")
|
self.navigationController?.navigationBar.setBackgroundImage(image, for: .default)
|
self.navigationController?.navigationBar.isTranslucent = true
|
}
|
|
override func viewWillDisappear(_ animated: Bool) {
|
super.viewWillDisappear(animated)
|
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.color(light: UIColor.color(hexString: "#000000"), dark: UIColor.color(hexString: "#FFFFFF")),NSAttributedString.Key.font: UIFont.init(name: Medium, size: 18) ?? UIFont.systemFont(ofSize: 18)]
|
self.navigationController?.navigationBar.barTintColor = UIColor.color(light: UIColor.color(hexString: "#FFFFFF"), dark: UIColor.color(hexString: "#191919"))
|
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
|
self.navigationController?.navigationBar.isTranslucent = false
|
}
|
|
init(_ m:RentCarReqModel) {
|
super.init(nibName: nil, bundle: nil)
|
self.rentalModel = m
|
}
|
|
required init?(coder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
navigationItem.title = "车辆详情"
|
scrollView.contentInset = UIEdgeInsets(top: -navH, left: 0, bottom: 0, right: 0)
|
|
contanerBannerView.addSubview(bannarView)
|
bannarView.backgroundColor = .gray
|
contanerBannerView.maskToBounds = true
|
bannarView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: 260)
|
contanerBannerView.sendSubviewToBack(bannarView)
|
|
setReject(text: "")
|
|
imgCollectionView.delegate = self
|
imgCollectionView.dataSource = self
|
imgCollectionView.register(UINib(nibName: "Common_FullImg_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_FullImg_CCell")
|
|
if let m = rentalModel{
|
|
bannarView.isOpenAutoScroll = m.videoUrl!.isEmpty
|
|
titleL.text = m.title
|
rentMoneyL.text = String(format: "%.2lf元/天", m.rentMoney ?? 0)
|
cashPledgeL.text = "\(m.deposit ?? 0)元"
|
|
let defaultFront = UIFont.systemFont(ofSize: 14, weight: .medium)
|
let titleColor = UIColor(hexString: "#696969")!.withAlphaComponent(0.8)
|
|
carBrandL.attributedText = AttributedStringbuilder.build().add(string: "车辆品牌:", withFont: defaultFront, withColor: titleColor).add(string: m.brandName ?? "", withFont: defaultFront, withColor: .black).mutableAttributedString
|
|
seatL.attributedText = AttributedStringbuilder.build().add(string: "座位:", withFont: defaultFront, withColor: titleColor).add(string: m.seat ?? "", withFont: defaultFront, withColor: .black).mutableAttributedString
|
|
displacementL.attributedText = AttributedStringbuilder.build().add(string: "排量:", withFont: defaultFront, withColor: titleColor).add(string: m.displacement ?? "", withFont: defaultFront, withColor: .black).mutableAttributedString
|
|
gearsL.attributedText = AttributedStringbuilder.build().add(string: "档位:", withFont: defaultFront, withColor: titleColor).add(string: m.gear ?? "", withFont: defaultFront, withColor: .black).mutableAttributedString
|
|
takeCarIdType.attributedText = AttributedStringbuilder.build().add(string: "取车证件:", withFont: defaultFront, withColor: titleColor).add(string: m.pickUpCarCarCertificates ?? "", withFont: defaultFront, withColor: .black).mutableAttributedString
|
|
contanctAddressL.attributedText = AttributedStringbuilder.build().add(string: "联系地址:", withFont: defaultFront, withColor: titleColor).add(string: m.addres ?? "", withFont: defaultFront, withColor: .black).mutableAttributedString
|
|
contanctL.attributedText = AttributedStringbuilder.build().add(string: "联系人:", withFont: defaultFront, withColor: titleColor).add(string: m.contactsName ?? "", withFont: defaultFront, withColor: .black).mutableAttributedString
|
|
switch m.userType {
|
case .business:
|
carTypeL.text = "企业车辆"
|
// carTypeL.backgroundColor = UIColor(hexString: "#FF8A3D")?.withAlphaComponent(0.79)
|
case .user:
|
carTypeL.text = "个人车辆"
|
// carTypeL.backgroundColor = UIColor(hexString: "#00BF30")?.withAlphaComponent(0.79)
|
default:break
|
}
|
|
var tempCount = m.imgUrl?.components(separatedBy: ",").count ?? 0
|
if !(m.videoUrl?.isEmpty ?? true){
|
tempCount+=1
|
}
|
|
bannerNum.text = "1/\(tempCount)"
|
bannarView.reloadData()
|
|
// bannerView.setImages(images: m.imgUrl!.components(separatedBy: ","), type: .URL) { index in
|
//
|
// }
|
|
switch m.status {
|
case .review:
|
opt1Btn.isEnabled = false
|
opt1Btn.setTitle("审核中", for: .normal)
|
opt1Btn.backgroundColor = UIColor(hexString: "#DCDCDC")
|
opt1Btn.setTitleColor(UIColor(hexString: "#393939"), for: .normal)
|
opt2Btn.isHidden = true
|
case .onShelf:
|
opt1Btn.setTitle("下架", for: .normal)
|
opt1Btn.backgroundColor = UIColor(hexString: "#00BF30")
|
opt1Btn.setTitleColor(.white, for: .normal)
|
opt2Btn.isHidden = true
|
case .waitOnShelf:
|
opt1Btn.setTitle("编辑", for: .normal)
|
opt1Btn.backgroundColor = UIColor(hexString: "#DCDCDC")
|
opt1Btn.setTitleColor(UIColor(hexString: "#393939"), for: .normal)
|
opt2Btn.setTitle("上架", for: .normal)
|
opt2Btn.backgroundColor = UIColor(hexString: "#00BF30")
|
opt2Btn.setTitleColor(.white, for: .normal)
|
case .reject:
|
setReject(text: m.authRemark ?? "")
|
opt1Btn.setTitle("编辑", for: .normal)
|
opt1Btn.backgroundColor = UIColor(hexString: "#DCDCDC")
|
opt1Btn.setTitleColor(UIColor(hexString: "#393939"), for: .normal)
|
opt2Btn.setTitle("上架", for: .normal)
|
opt2Btn.backgroundColor = UIColor(hexString: "#00BF30")
|
opt2Btn.setTitleColor(.white, for: .normal)
|
case .takeDown:
|
opt1Btn.setTitle("编辑", for: .normal)
|
opt1Btn.backgroundColor = UIColor(hexString: "#DCDCDC")
|
opt1Btn.setTitleColor(UIColor(hexString: "#393939"), for: .normal)
|
opt2Btn.setTitle("上架", for: .normal)
|
opt2Btn.backgroundColor = UIColor(hexString: "#00BF30")
|
opt2Btn.setTitleColor(.white, for: .normal)
|
default:
|
opt1Btn.isHidden = true
|
opt2Btn.isHidden = true
|
}
|
|
if !m.videoUrl!.isEmpty{
|
let asset = AVURLAsset(url: URL(string: m.videoUrl!)!)
|
let gen = AVAssetImageGenerator(asset: asset)
|
gen.appliesPreferredTrackTransform = true
|
let time = CMTimeMakeWithSeconds(0.0, preferredTimescale: 1)
|
var actualTime : CMTime = CMTimeMakeWithSeconds(0, preferredTimescale: 0)
|
do {
|
let image = try gen.copyCGImage(at: time, actualTime: &actualTime)
|
self.videoImg = UIImage(cgImage: image)
|
calHei()
|
} catch {
|
print("错误")
|
}
|
}
|
|
let attribute = AttributedStringbuilder.build()
|
self.descL.attributedText = attribute.add(string: m.describe!, withFont: UIFont.systemFont(ofSize: 14, weight: .medium), withColor: UIColor(hexString: "#696969")!.withAlphaComponent(0.8), lineSpace: 3).mutableAttributedString
|
|
calHei()
|
}
|
}
|
|
override func setupViews() {
|
super.setupViews()
|
}
|
|
private func calHei(){
|
let count = rentalModel?.describeImgUrl?.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
|
imgHeiCons.constant = Double(count) * cellH + 8 * Double(count)
|
imgCollectionView.reloadData()
|
}
|
|
override func defineLayouts() {
|
super.defineLayouts()
|
}
|
|
//设置拒绝
|
private func setReject(text:String){
|
rejectView.isHidden = text.isEmpty
|
rejectL.text = text
|
if text.isEmpty{
|
rejectHeiCons.constant = 7
|
}else{
|
let h = text.height(12, wight: ScreenWidth - 28)
|
rejectHeiCons.constant = h + 20
|
}
|
}
|
|
@IBAction func opt1Action(_ sender: UIButton) {
|
guard let m = rentalModel else { return }
|
|
if sender.titleLabel?.text == "编辑"{
|
let vc = MinePublishHireEditVC(m, isEdit: true,saveEdit: false)
|
yy_push(vc: vc)
|
}else if sender.titleLabel?.text == "上架"{
|
alert(popup: .double, title: nil, text: "是否对该商品进行上架?", submitTitle: "确定", cancelTitle: "取消") {[weak self] () in
|
guard let weakSelf = self else { return }
|
weakSelf.show()
|
APIManager.shared.provider.rx.request(.putOnTheShelf(id: m.id!.int!, type: 1)).map(YYModel<Nothing>.self).subscribe(onSuccess: {data in
|
//74083 【我发布的-售卖车辆 + 出租车辆】 下架的车辆,点击上架后,页面底部应显示为 下架按钮,不应是 审核中 按钮
|
weakSelf.hide()
|
weakSelf.opt1Btn.setTitle("下架", for: .normal)
|
weakSelf.opt1Btn.backgroundColor = UIColor(hexString: "#00BF30")
|
weakSelf.opt1Btn.setTitleColor(.white, for: .normal)
|
weakSelf.opt2Btn.isHidden = true
|
}) { error in
|
weakSelf.hide()
|
}.disposed(by: weakSelf.disposeBag)
|
} cancelClick: {
|
|
}
|
}else if sender.titleLabel?.text == "下架"{
|
alert(popup: .double, title: nil, text: "是否对该商品进行上架?", submitTitle: "确定", cancelTitle: "取消") {[weak self] () in
|
guard let weakSelf = self else { return }
|
weakSelf.show()
|
APIManager.shared.provider.rx.request(.offTheShelf(id: m.id!.int!, type: 1)).map(YYModel<Nothing>.self).subscribe(onSuccess: {data in
|
weakSelf.hide()
|
weakSelf.opt1Btn.setTitle("编辑", for: .normal)
|
weakSelf.opt1Btn.backgroundColor = UIColor(hexString: "#DCDCDC")
|
weakSelf.opt1Btn.setTitleColor(UIColor(hexString: "#393939"), for: .normal)
|
weakSelf.opt2Btn.setTitle("上架", for: .normal)
|
weakSelf.opt2Btn.backgroundColor = UIColor(hexString: "#00BF30")
|
weakSelf.opt2Btn.setTitleColor(.white, for: .normal)
|
weakSelf.opt1Btn.isHidden = false
|
weakSelf.opt2Btn.isHidden = false
|
}) { error in
|
weakSelf.hide()
|
}.disposed(by: weakSelf.disposeBag)
|
} cancelClick: {
|
|
}
|
}
|
}
|
|
override func viewDidLayoutSubviews() {
|
super.viewDidLayoutSubviews()
|
bannarView.adjustCenterSubview()
|
}
|
|
deinit {
|
AVPlayerSingleManager.shared.clear()
|
}
|
|
override var preferredStatusBarStyle: UIStatusBarStyle{
|
return .lightContent
|
}
|
}
|
|
|
extension MinePublishHireDetailVC:UICollectionViewDelegate{
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
let count = rentalModel?.describeImgUrl?.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
|
let lantern = Lantern()
|
lantern.numberOfItems = {return count}
|
|
lantern.cellClassAtIndex = { _ in LanternImageCell.self}
|
|
lantern.transitionAnimator = LanternZoomAnimator(previousView: { index -> UIView? in
|
let cell = collectionView.cellForItem(at: IndexPath(item: index, section: indexPath.section)) as! Common_FullImg_CCell
|
return cell.img
|
})
|
|
// UIPageIndicator样式的页码指示器
|
lantern.pageIndicator = LanternDefaultPageIndicator()
|
|
lantern.pageIndex = indexPath.item
|
|
lantern.reloadCellAtIndex = { context in
|
let lanternCell = context.cell as? LanternImageCell
|
let cell = collectionView.cellForItem(at: IndexPath(item:context.index, section: indexPath.section)) as! Common_FullImg_CCell
|
lanternCell?.imageView.image = cell.img.image
|
}
|
//不要使用push
|
lantern.show()
|
}
|
}
|
|
extension MinePublishHireDetailVC:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
let count = rentalModel?.describeImgUrl?.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
|
return count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let imgUrl = rentalModel!.describeImgUrl!.components(separatedBy: ",").filter({!$0.isEmpty})
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_FullImg_CCell", for: indexPath) as! Common_FullImg_CCell
|
cell.closeBtn.isHidden = true
|
cell.img.load(url: imgUrl[indexPath.row])
|
return cell
|
}
|
}
|
|
extension MinePublishHireDetailVC :UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 8
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
return CGSize(width: cellW, height: cellH)
|
}
|
}
|
|
extension MinePublishHireDetailVC:HQFlowViewDelegate,HQFlowViewDataSource{
|
func sizeForPage(in flowView: HQFlowView!) -> CGSize {
|
return CGSize(width: screenW, height: 260)
|
}
|
func numberOfPages(in flowView: HQFlowView!) -> Int {
|
let count = rentalModel?.imgUrl?.components(separatedBy: ",").count ?? 0
|
if rentalModel?.videoUrl?.isEmpty == false{
|
return count + 1
|
}
|
return count
|
}
|
func didSelectCell(_ subView: HQIndexBannerSubview!, withSubViewIndex subIndex: Int) {
|
|
}
|
func didScroll(toPage pageNumber: Int, in flowView: HQFlowView!) {
|
var totalNum = rentalModel?.imgUrl?.components(separatedBy: ",").count ?? 0
|
if rentalModel?.videoUrl?.isEmpty == false{
|
totalNum += 1
|
}
|
bannerNum.text = "\(pageNumber + 1)/\(totalNum)"
|
AVPlayerSingleManager.shared.pause()
|
}
|
func flowView(_ flowView: HQFlowView!, cellForPageAt index: Int) -> HQIndexBannerSubview! {
|
var mutiurl = rentalModel?.imgUrl?.components(separatedBy: ",") ?? []
|
|
if rentalModel?.videoUrl?.isEmpty == false{
|
mutiurl.insert(rentalModel!.videoUrl!, at: 0)
|
}
|
|
let url = mutiurl[index]
|
|
var cell = flowView.dequeueReusableCell()
|
if mutiurl.count > 0 && mutiurl[index] == rentalModel?.videoUrl {
|
//视频
|
if cell == nil {
|
cell = StoreGoodsVideoView.loadViewFromNib()
|
cell?.frame = CGRect(x: 0, y: 0, width: screenW, height: 260)
|
}
|
(cell as? StoreGoodsVideoView)?.setupData(url)
|
} else {
|
//图片
|
cell = HQIndexBannerSubview(frame: CGRect(x: 0, y: 0, width: screenW, height: 260))
|
cell?.backgroundColor = .white
|
cell?.mainImageView.contentMode = .scaleAspectFill
|
cell?.mainImageView.load(url: url)
|
}
|
return cell
|
}
|
}
|