宽窄优行-由【嘉易行】项目成品而来
无故事王国
2023-05-25 dc1998fc1ac124f6b9a0e434ccf91103dd936409
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
//
//  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
    }
}