//
|
// MinePublishSaleDetailVC.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2022/5/7.
|
// Copyright © 2022 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import WebKit
|
import QMUIKit
|
import AVKit
|
import Lantern
|
|
class MinePublishSaleDetailVC: YYViewController {
|
|
@IBOutlet weak var scrollView: UIScrollView!
|
@IBOutlet weak var contanerBannerView: UIView!
|
@IBOutlet weak var titleL: UILabel!
|
@IBOutlet weak var priceL: UILabel!
|
@IBOutlet weak var infoL: UILabel!
|
@IBOutlet weak var moreBtn: QMUIButton!
|
@IBOutlet weak var authBtn: QMUIButton!
|
@IBOutlet weak var firmL: UILabel! //所属厂商
|
@IBOutlet weak var mileageL: UILabel! //表里程
|
@IBOutlet weak var displacementL: UILabel! //排量
|
@IBOutlet weak var transmissionCaseL: UILabel! //变速箱
|
@IBOutlet weak var locationOfLicensePlateL: UILabel! //牌照地
|
@IBOutlet weak var transferTimesL: UILabel! //过户次数
|
@IBOutlet weak var levelL: UILabel! //级别
|
@IBOutlet weak var licensingTimeL: UILabel! //上牌时间
|
@IBOutlet weak var contactsNameL: UILabel! //联系人
|
@IBOutlet weak var addressL: UILabel! //联系地址
|
@IBOutlet weak var callBtn: UIButton!
|
@IBOutlet weak var imgCollectionView: UICollectionView!
|
@IBOutlet weak var imgHeiCons: NSLayoutConstraint!
|
@IBOutlet weak var descL: UILabel!
|
|
@IBOutlet weak var webView: WKWebView!
|
@IBOutlet weak var webViewHeiCons: NSLayoutConstraint!
|
@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!
|
|
private var videoImg:UIImage?
|
|
let cellW:Double = (SCREEN_WIDTH - 27)
|
let cellH:Double = (SCREEN_WIDTH - 27) * 0.497
|
|
var bannerView:BannerView!
|
var carSellModel:SellCarReqModel?
|
|
private let agreementViewModel = AgreementViewModel()
|
|
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
|
}
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
navigationItem.title = "车辆详情"
|
scrollView.contentInset = UIEdgeInsets(top: -navH, left: 0, bottom: 0, right: 0)
|
setReject(text: "")
|
imgCollectionView.delegate = self
|
imgCollectionView.dataSource = self
|
imgCollectionView.register(UINib(nibName: "Common_FullImg_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_FullImg_CCell")
|
|
if let m = carSellModel{
|
|
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
|
}
|
|
switch m.status {
|
case .reject:setReject(text: m.authRemark!)
|
default:setReject(text:"")
|
}
|
|
titleL.text = m.title
|
// if m.transferPrice! > 10000{
|
priceL.text = String(format: "%.2lf万", Double(m.transferPrice!) / 10000.0)
|
// }else{
|
// priceL.text = String(format: "%.2lf",m.transferPrice!)
|
// }
|
|
var temp = [String]()
|
|
// if m.newCarPrice! > 10000{
|
temp.append(String(format: "%.2lf万", Double(m.newCarPrice!) / 10000.0))
|
// }else{
|
// temp.append(String(format: "%.2lf",m.newCarPrice!))
|
// }
|
|
if m.includingTransferFee == 1{
|
temp.append("包含过户费")
|
}else{
|
temp.append("不包含过户费")
|
}
|
infoL.text = String(format: "新车含税价格:%@", temp.joined(separator: "/"))
|
firmL.text = m.brandName
|
mileageL.text = String(format: "%@万公里", m.mileage?.ld_formatFloat ?? "0")
|
displacementL.text = m.displacement!.contains("L") ? m.displacement! : "\(m.displacement!)L"
|
transmissionCaseL.text = m.transmissionCase
|
locationOfLicensePlateL.text = m.locationOfLicensePlate
|
transferTimesL.text = "\(m.transferTimes!.string())次"
|
levelL.text = m.level
|
licensingTimeL.text = m.licensingTime
|
contactsNameL.text = m.contactsName
|
authBtn.isHidden = m.userType != .business
|
addressL.text = String(format: "联系地址:%@%@%@", m.provinceName!,m.cityName!,m.addres!)
|
bannerView.setImages(images: m.imgUrl!.components(separatedBy: ","), type: .URL) { index in
|
|
}
|
|
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()
|
|
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:
|
//73793 【我发布的售卖车辆】拒绝状态的详情页面,底部应只有一个编辑按钮 ,目前显示了2个编辑按钮
|
setReject(text: m.authRemark ?? "")
|
opt1Btn.setTitle("编辑", for: .normal)
|
opt1Btn.backgroundColor = UIColor(hexString: "#DCDCDC")
|
opt1Btn.setTitleColor(UIColor(hexString: "#393939"), for: .normal)
|
opt2Btn.isHidden = true
|
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
|
}
|
}
|
|
agreementViewModel.type.accept(.question)
|
agreementViewModel.agreement()
|
|
}
|
|
override func setupViews() {
|
super.setupViews()
|
|
moreBtn.imagePosition = .right
|
moreBtn.spacingBetweenImageAndTitle = 7
|
authBtn.imagePosition = .left
|
authBtn.spacingBetweenImageAndTitle = 4
|
|
bannerView = BannerView()
|
contanerBannerView.maskToBounds = true
|
contanerBannerView.addSubview(bannerView)
|
contanerBannerView.sendSubviewToBack(bannerView)
|
bannerView.frame = CGRect(x: 0, y: 0, width: ScreenWidth, height: ScreenWidth * 0.8)
|
|
bannerView.changeAtIndex { [weak self] current, totalNum in
|
if current <= -1{
|
self?.bannerNum.text = "\(totalNum)/\(totalNum)"
|
}else{
|
self?.bannerNum.text = "\(current + 1)/\(totalNum)"
|
}
|
}
|
|
}
|
|
override func defineLayouts() {
|
super.defineLayouts()
|
|
}
|
|
override func bindRx() {
|
agreementViewModel.requestSubject.subscribe(onNext: {state in
|
switch state {
|
case .success(let model):
|
guard let data: SwitchCityModel = model as? SwitchCityModel else {return}
|
self.webView.loadHTMLString(data.content.ld_warpHtml, baseURL: nil)
|
default:break
|
}
|
|
}).disposed(by: disposeBag)
|
|
self.webView.scrollView.rx.observe(CGSize.self, "contentSize").map { (size) -> CGFloat? in
|
if let size = size{
|
return size.height
|
}
|
return nil
|
}.subscribe(onNext: { [unowned self](height) in
|
if let height = height{
|
self.webViewHeiCons.constant = height
|
}
|
}).disposed(by: disposeBag)
|
}
|
|
//设置拒绝
|
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
|
}
|
}
|
|
private func calHei(){
|
let count = carSellModel?.describeImgUrl?.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
|
imgHeiCons.constant = Double(count) * cellH + 8 * Double(count)
|
imgCollectionView.reloadData()
|
}
|
|
@IBAction func moreInfoAction(_ sender: QMUIButton) {
|
let vc = MinePublishSaleDetailMoreVC()
|
vc.sellCarReqModel = carSellModel
|
yy_push(vc: vc)
|
}
|
|
@IBAction func opt1Action(_ sender: UIButton) {
|
guard let m = carSellModel else { return }
|
|
if sender.titleLabel?.text == "编辑"{
|
let vc = PublishSaleCarVC(carSellModel!, 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: 2)).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: 2)).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: {
|
|
}
|
}
|
}
|
|
@IBAction func callAction(_ sender: UIButton) {
|
if let phone = carSellModel?.contactsPhone{
|
UIApplication.shared.open(URL(string: "telprompt://\(phone)")!, options: [:], completionHandler: nil)
|
}
|
}
|
|
override var preferredStatusBarStyle: UIStatusBarStyle{
|
return .lightContent
|
}
|
|
}
|
|
extension MinePublishSaleDetailVC:UICollectionViewDelegate{
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
let count = carSellModel?.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 MinePublishSaleDetailVC:UICollectionViewDataSource{
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
let count = carSellModel?.describeImgUrl?.components(separatedBy: ",").filter({!$0.isEmpty}).count ?? 0
|
return count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let imgUrl = carSellModel!.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 MinePublishSaleDetailVC :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)
|
}
|
}
|