From b932f704f6c04adc7d7b4104a06cbc09c8d49cb5 Mon Sep 17 00:00:00 2001 From: younger_times <841720330@qq.com> Date: 星期五, 14 七月 2023 15:50:47 +0800 Subject: [PATCH] 报名课程流程完成 --- WanPai/Root/Course/VC/CourseDetailApplyVC.swift | 97 +++++++++++++++++++++++++++++++++++++----------- 1 files changed, 74 insertions(+), 23 deletions(-) diff --git a/WanPai/Root/Course/VC/CourseDetailApplyVC.swift b/WanPai/Root/Course/VC/CourseDetailApplyVC.swift index ddb2d31..0f09c71 100644 --- a/WanPai/Root/Course/VC/CourseDetailApplyVC.swift +++ b/WanPai/Root/Course/VC/CourseDetailApplyVC.swift @@ -31,6 +31,7 @@ @IBOutlet weak var label_vipPrice: UILabel! @IBOutlet weak var label_coin: UILabel! @IBOutlet weak var btn_hasCoupon: TapBtn! + @IBOutlet weak var btn_couponInfo: UIButton! @IBOutlet weak var studentTableView: UITableView! @@ -40,6 +41,7 @@ private var CellH:Double! private var studentModels = [CourseDetailStudentModel]() private var couponModels = [CouponInfoModel]() + private var selectCouponModel:CouponInfoModel? override func viewDidLoad() { super.viewDidLoad() @@ -53,7 +55,6 @@ 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 @@ -61,6 +62,7 @@ cons_tableHei.constant = CGFloat(studentModels.count * 87) tableView.reloadData() + changePrice(selectClassIndex) } } @@ -94,16 +96,22 @@ @IBAction func couponAction(_ sender: TapBtn) { - guard couponModels.count != 0 else { - alertError(msg: "暂无优惠券");return + CouponChooseView.show(couponModels,defaultModel: selectCouponModel) { m in + self.selectCouponModel = m + guard m != nil else { + self.btn_couponInfo.setTitle("去选择", for: .normal);return + } + self.btn_couponInfo.setTitle("-\(m!.favorable)", for: .normal) } - - CouponChooseView.show() } @IBAction func studentAction(_ sender: QMUIButton) { - StudentChooseView.show(itemType:.course,defaultStu: detailModel?.student) { - + StudentChooseView.show(itemType: .course, defaultStu: studentModels) { [weak self] studs in + guard let weakSelf = self else { return } + weakSelf.studentModels = studs + weakSelf.tableView.reloadData() + weakSelf.cons_tableHei.constant = CGFloat((weakSelf.studentModels.count) * 87) + weakSelf.changePrice(weakSelf.selectClassIndex) } needAddClouse: { [weak self] () in let vc = AddStudentVC() self?.push(vc: vc) @@ -111,34 +119,67 @@ } @IBAction func paymentAction(_ sender: UIButton) { - PaymentView.show { status in - let paymentState:PaymentResultVC.PaymentResult = status ? .success:.fail - let vc = PaymentResultVC(result: paymentState, objType: .courseApply) - vc.modalPresentationStyle = .fullScreen - self.present(vc, animated: true) + guard detailModel != nil else {return} + guard studentModels.count != 0 else {alertError(msg: "请选择学员");return} + StoresInfoView.show(detailModel!) { [weak self] status in + guard let weakSelf = self else { return } + if status{ + if let model = weakSelf.detailModel?.list[weakSelf.selectClassIndex]{ + let price = model.vipPrice == nil ? model.originalPrice : model.vipPrice + let coin = model.playPaiCoin + PaymentView.show(money: (ali:price,wx:price,coin:coin,course:nil)) { [weak self] payType in + guard let weakSelf = self else { return } + Services.courcePayment(conponId: weakSelf.selectCouponModel?.id, courseConfigId: model.id, id: weakSelf.detailModel!.id, price: model.paymentPrice, payType: payType, stuId: weakSelf.studentModels.map({$0.id})).subscribe(onNext: { data in + if let m = data.data{ + switch payType { + case .aliPay: + YYPaymentManager.shared.sendPaymentRequest(YYAlipayRequest(orderString: m.orderString)) { [weak self] result in + switch result { + case .success: + let vc = PaymentResultVC(result: .success, objType: .courseApply) + self?.present(vc, animated: true) + case .cancel: + let vc = PaymentResultVC(result: .fail, objType: .courseApply) + self?.present(vc, animated: true) + case .failure(let error): + let vc = PaymentResultVC(result: .fail, objType: .courseApply) + self?.present(vc, animated: true) + } + } + case .wechat:break + case .coin:break + case .courseNum:break + } + }else{ + alertError(msg: data.msg) + } + }).disposed(by: weakSelf.disposeBag) + } + } + }else{ + self?.navigationController?.popToRootViewController(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 - + label_price.text = (subM.paymentPrice * Double(studentModels.count)).currency() + label_originPrice.isHidden = subM.originalPrice == nil || subM.originalPrice == 0 + label_coin.isHidden = subM.playPaiCoin == nil || subM.playPaiCoin == 0 + label_vipPrice.isHidden = subM.vipPrice == nil || subM.vipPrice == 0 //原价 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)) + let attribute = AttributedStringbuilder.build().add(string: (originPrice * Double(studentModels.count)).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")) + .add(string: "\(paiCoin * studentModels.count)币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")) label_coin.attributedText = coinAttribute.mutableAttributedString } @@ -146,7 +187,7 @@ 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")) + .add(string: (vipPrice * Double(studentModels.count)).currency(), withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")) label_vipPrice.attributedText = vipAttribute.mutableAttributedString } } @@ -169,7 +210,7 @@ LogError("会员优惠价格出现问题:nil");return } - Services.queryAvaiableCopons(id: subM.id, price: price!).subscribe(onNext: { [weak self] data in + Services.queryAvaiableCopons(id: detailModel!.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) @@ -222,8 +263,18 @@ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "_StudentInfoTCell") as! StudentInfoTCell + cell.indexPath = indexPath cell.studentModel = studentModels[indexPath.row] + cell.deleClouse = { [weak self] index in + guard let weakSelf = self else { return } + tableView.beginUpdates() + weakSelf.studentModels.remove(at: index) + tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .right) + tableView.endUpdates() + weakSelf.cons_tableHei.constant = CGFloat((weakSelf.studentModels.count) * 87) + tableView.reloadData() + weakSelf.changePrice(weakSelf.selectClassIndex) + } return cell } - } -- Gitblit v1.7.1