From 5a590aaf3fd9ed5f9cfd2d54e72c904ce4918e7f Mon Sep 17 00:00:00 2001 From: younger_times <841720330@qq.com> Date: 星期三, 12 七月 2023 18:56:43 +0800 Subject: [PATCH] 完善“课程详情” --- WanPai/Root/Course/VC/CourseDetailApplyVC.swift | 151 ++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 133 insertions(+), 18 deletions(-) diff --git a/WanPai/Root/Course/VC/CourseDetailApplyVC.swift b/WanPai/Root/Course/VC/CourseDetailApplyVC.swift index 9c08359..7b27517 100644 --- a/WanPai/Root/Course/VC/CourseDetailApplyVC.swift +++ b/WanPai/Root/Course/VC/CourseDetailApplyVC.swift @@ -1,9 +1,9 @@ -// -// CourseDetailApplyVC.swift -// WanPai -// -// Created by 杨锴 on 2023/6/9. -// + // + // CourseDetailApplyVC.swift + // WanPai + // + // Created by 杨锴 on 2023/6/9. + // import UIKit import JQTools @@ -15,20 +15,58 @@ @IBOutlet weak var cons_collectHei: NSLayoutConstraint! @IBOutlet weak var btn_addStudent: QMUIButton! @IBOutlet weak var tableView: UITableView! + @IBOutlet weak var cons_collHei: NSLayoutConstraint! @IBOutlet weak var cons_tableHei: NSLayoutConstraint! @IBOutlet weak var btn_coupon: TapBtn! - + + @IBOutlet weak var img_cover: UIImageView! + @IBOutlet weak var label_title: UILabel! + @IBOutlet weak var label_listenWeek: UILabel! + @IBOutlet weak var label_listenTime: UILabel! + @IBOutlet weak var label_store: UILabel! + @IBOutlet weak var label_address: UILabel! + + @IBOutlet weak var label_price: UILabel! + @IBOutlet weak var label_originPrice: UILabel! + @IBOutlet weak var label_vipPrice: UILabel! + @IBOutlet weak var label_coin: UILabel! + @IBOutlet weak var btn_hasCoupon: TapBtn! + @IBOutlet weak var studentTableView: UITableView! - var CellW:Double! - var CellH:Double! + + private var detailModel:CourseDetailModel? + private var selectClassIndex:Int = 0 + private var CellW:Double! + private var CellH:Double! + private var studentModels = [CourseDetailStudentModel]() + private var couponModels = [CouponInfoModel]() override func viewDidLoad() { super.viewDidLoad() title = "课程详情" + + if let m = detailModel{ + img_cover.sd_setImage(with: URL(string: m.coverDrawing)) + label_title.text = m.name + label_listenWeek.text = m.weeks.joined(separator: "、") + label_listenTime.text = m.times + label_store.text = m.storeName + label_address.text = m.storeAddress + + changePrice(selectClassIndex) + if let stu = m.student{studentModels.append(stu)} + + cons_collHei.constant = ceil(Double(m.list.count) / 3.0) * CellH + floor(Double(m.list.count) / 3.0) * 21.0 + collectionView.reloadData() + + cons_tableHei.constant = CGFloat(studentModels.count * 87) + tableView.reloadData() + } } override func setUI() { - + + btn_hasCoupon.isHidden = true CellW = (JQ_ScreenW - 155) / 3.0 CellH = CellW * 0.439 @@ -44,8 +82,22 @@ btn_addStudent.imagePosition = .right btn_addStudent.spacingBetweenImageAndTitle = 3 } - + + init(detailModel:CourseDetailModel) { + super.init(nibName: nil, bundle: nil) + self.detailModel = detailModel + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + @IBAction func couponAction(_ sender: TapBtn) { + guard couponModels.count != 0 else { + alertError(msg: "暂无优惠券");return + } + CouponChooseView.show() } @@ -56,7 +108,6 @@ let vc = AddStudentVC() self?.push(vc: vc) } - } @IBAction func paymentAction(_ sender: UIButton) { @@ -67,21 +118,85 @@ self.present(vc, animated: true) } } + + private func changePrice(_ index:Int){ + if let subM = detailModel?.list[index]{ + label_price.text = subM.paymentPrice.currency() + label_originPrice.isHidden = subM.originalPrice == nil + label_coin.isHidden = subM.playPaiCoin == nil + label_vipPrice.isHidden = subM.vipPrice == nil + + + //原价 + if let originPrice = subM.originalPrice{ + let attribute = AttributedStringbuilder.build().add(string: originPrice.currency(), withFont: UIFont.systemFont(ofSize: 16, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58)).underLine(color: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58)) + label_originPrice.attributedText = attribute.mutableAttributedString + } + + + //玩湃币 + if let paiCoin = subM.playPaiCoin{ + let coinAttribute = AttributedStringbuilder.build() + .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F")) + .add(string: "\(paiCoin)币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")) + label_coin.attributedText = coinAttribute.mutableAttributedString + } + + //会员价 + if let vipPrice = subM.vipPrice{ + let vipAttribute = AttributedStringbuilder.build() + .add(string: "会员价:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F")) + .add(string: vipPrice.currency(), withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")) + label_vipPrice.attributedText = vipAttribute.mutableAttributedString + } + } + + queryCouponInfo() + } + + private func queryCouponInfo(){ + if let subM = detailModel?.list[selectClassIndex]{ + + var price:Double? + switch subM.payType{ + case .cash: + price = subM.originalPrice == nil ? subM.vipPrice : subM.originalPrice + case .coin: + if let coin = subM.playPaiCoin{price = Double(coin)} + } + + guard price != nil else { + LogError("会员优惠价格出现问题:nil");return + } + + Services.queryAvaiableCopons(id: subM.id, price: price!).subscribe(onNext: { [weak self] data in + self?.btn_hasCoupon.isHidden = (data.data?.count ?? 0) == 0 + self?.couponModels = data.data ?? [] + }).disposed(by: disposeBag) + } + } } extension CourseDetailApplyVC:UICollectionViewDelegate{ - + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + selectClassIndex = indexPath.row + collectionView.reloadData() + changePrice(selectClassIndex) + } } extension CourseDetailApplyVC:UICollectionViewDataSource{ func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_1_CCell", for: indexPath) as! Common_1_CCell - + let m = detailModel!.list[indexPath.row] + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_Common_1_CCell", for: indexPath) as! Common_1_CCell + cell.isSelected = indexPath.row == selectClassIndex + cell.courseDetailListModel = m + return cell } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 3 + return detailModel?.list.count ?? 0 } } @@ -102,12 +217,12 @@ extension CourseDetailApplyVC:UITableViewDataSource{ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return 1 + return studentModels.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfoTCell") as! StudentInfoTCell - + cell.studentModel = studentModels[indexPath.row] return cell } -- Gitblit v1.7.1