无故事王国
2023-11-13 a64b39beb6ba6ed8208d70daef2ff8872bdf265a
WanPai/Root/Course/VC/CourseDetailApplyVC.swift
@@ -85,7 +85,11 @@
         cons_tableHei.constant = CGFloat(studentModels.count * 87)
         tableView.reloadData()
         changePrice(selectClassIndex)
         queryCouponInfo {[weak self] () in
            guard let weakSelf = self else { return }
            self?.changePrice(weakSelf.selectClassIndex)
         }
         let imgs = m.detailDrawing.components(separatedBy: ",")
         var items = [CommonBannerModel]()
@@ -256,6 +260,7 @@
        }
    }
   //计算价格
    private func changePrice(_ index:Int){
        if let subM = detailModel?.list[index]{
         
@@ -274,6 +279,9 @@
               label_originPrice.isHidden = true
               label_vipPrice.isHidden = true
               //纯玩湃币没有优惠券项
               btn_hasCoupon.isHidden = true
                  //玩湃币
               label_coin.attributedText = AttributedStringbuilder.build()
                  .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
@@ -282,8 +290,12 @@
            case .cash:
               label_coin.isHidden = true;fallthrough
            case .cashCoin:
               if subM.originalPrice == 0{label_originPrice.isHidden = true}
               label_originPrice.isHidden = (subM.paymentPrice == subM.originalPrice && subM.paymentPrice != 0 && subM.originalPrice != 0)
               if subM.originalPrice == 0 || subM.originalPrice == subM.paymentPrice{
                  label_originPrice.isHidden = true
               }else{
                  label_originPrice.isHidden = false
               }
//               label_originPrice.isHidden = (subM.paymentPrice == subM.originalPrice && subM.paymentPrice != 0 && subM.originalPrice != 0)
                  //玩湃币
               label_coin.attributedText = AttributedStringbuilder.build()
@@ -299,8 +311,11 @@
                  label_vipPrice.isHidden = true
                  if subM.paymentPrice < subM.vipPrice && subM.paymentPrice != 0{
                     label_price.text = (subM.paymentPrice * studentCount - (selectCouponModel?.favorable ?? 0)).currency()
                  }else if subM.vipPrice != 0{
                  }else if subM.vipPrice < subM.paymentPrice && subM.vipPrice != 0{
                     label_price.text = (subM.vipPrice * studentCount - (selectCouponModel?.favorable ?? 0)).currency()
                  }else if subM.vipPrice != 0 &&  subM.paymentPrice != 0{
                     let price = min(subM.vipPrice, subM.paymentPrice)
                     label_price.text = (price * studentCount - (selectCouponModel?.favorable ?? 0)).currency()
                  }else{
                     label_price.text = (subM.paymentPrice * studentCount - (selectCouponModel?.favorable ?? 0)).currency()
                  }
@@ -317,10 +332,12 @@
                     label_price.text = (subM.originalPrice * studentCount - (selectCouponModel?.favorable ?? 0)).currency()
                  }else if subM.originalPrice == 0 && subM.paymentPrice != 0{
                     label_price.text = (subM.paymentPrice * studentCount - (selectCouponModel?.favorable ?? 0)).currency()
                  }else{
                  }else if subM.originalPrice != 0 && subM.paymentPrice != 0{
                     var money = min(subM.originalPrice,subM.paymentPrice)
                     money = money - (selectCouponModel?.favorable ?? 0)
                     label_price.text = (money * studentCount).currency()
                  }else{
                     label_price.text = (subM.originalPrice * studentCount - (selectCouponModel?.favorable ?? 0)).currency()
                  }
               }
         }
@@ -331,12 +348,15 @@
            label_originPrice.isHidden = true
            label_vipPrice.isHidden = true
         }
        }
        queryCouponInfo()
         if label_originPrice.isHidden && label_vipPrice.isHidden && label_coin.isHidden{
            label_coin.alpha = 0
         }
        }
    }
    private func queryCouponInfo(){
   //查询优惠券
   private func queryCouponInfo(complete:(()->Void)? = nil){
        if let subM = detailModel?.list[selectClassIndex]{
            var price:Double?
@@ -352,8 +372,18 @@
            }
            Services.queryAvaiableCopons(id: detailModel!.id, price: price!).subscribe(onNext: { [weak self] data in
            guard let weakSelf = self else { return }
                self?.btn_hasCoupon.isHidden = (data.data?.count ?? 0) == 0
                self?.couponModels = data.data ?? []
            //重新获取优惠券,在切换套餐时触发
            if let selectCoupon = self?.selectCouponModel{
               if !weakSelf.couponModels.contains(where: {$0.id == selectCoupon.id}){
                  weakSelf.selectCouponModel = nil
                  weakSelf.btn_couponInfo.setTitle("去选择", for: .normal)
               }
            }
            complete?()
            }).disposed(by: disposeBag)
        }
    }
@@ -369,7 +399,9 @@
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        selectClassIndex = indexPath.row
        collectionView.reloadData()
        changePrice(selectClassIndex)
      queryCouponInfo {[weak self] () in
         self?.changePrice(indexPath.row)
      }
    }
}