杨锴
2024-10-09 1f08239dd60c05f1eb6eb9b3122aa23cd700348b
WanPai/Root/Course/VC/CourseDetailVC.swift
@@ -11,218 +11,218 @@
class CourseDetailVC: BaseVC {
   @IBOutlet weak var view_banner: CommonBannerView!
    @IBOutlet weak var label_title: UILabel!
    @IBOutlet weak var label_local: UILabel!
    @IBOutlet weak var label_distance: UILabel!
    @IBOutlet weak var label_listenWeek: UILabel!
   @IBOutlet weak var view_listen: UIView!
   @IBOutlet weak var label_listenTime: UILabel!
    @IBOutlet weak var img_1: UIImageView!
    @IBOutlet weak var cons_img1Height: NSLayoutConstraint!
   @IBOutlet weak var label_courseType: UILabel!
   @IBOutlet weak var label_vaildTime: UILabel!
   @IBOutlet weak var view_vaildTime: UIView!
   @IBOutlet weak var view_handle: UIView!
    @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 cons_handleHei: NSLayoutConstraint!
   @IBOutlet weak var btn_enroll: UIButton!
   @IBOutlet weak var view_tag: UIView!
    private var id = 0
            @IBOutlet weak var view_banner: CommonBannerView!
            @IBOutlet weak var label_title: UILabel!
            @IBOutlet weak var label_local: UILabel!
            @IBOutlet weak var label_distance: UILabel!
            @IBOutlet weak var label_listenWeek: UILabel!
            @IBOutlet weak var view_listen: UIView!
            @IBOutlet weak var label_listenTime: UILabel!
            @IBOutlet weak var img_1: UIImageView!
            @IBOutlet weak var cons_img1Height: NSLayoutConstraint!
            @IBOutlet weak var label_courseType: UILabel!
            @IBOutlet weak var label_vaildTime: UILabel!
            @IBOutlet weak var view_vaildTime: UIView!
            @IBOutlet weak var view_handle: UIView!
   private var signUpCourseModel:SignUpCourseItemDetailModel?
    private var detailModel:CourseDetailModel?{
        didSet{
            @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 cons_handleHei: NSLayoutConstraint!
            @IBOutlet weak var btn_enroll: UIButton!
            @IBOutlet weak var view_tag: UIView!
         if let m = detailModel{
            label_title.text = m.name
            label_distance.text = String(format: "距离我%.2lfkm", m.distance)
            label_local.text = String(format: "%@(%@)", m.storeName,m.storeAddress)
            label_listenWeek.text = "每" + m.weeks.joined(separator: "、")
            label_listenTime.text = m.times.joined(separator: "|")
            label_vaildTime.text = m.time
            label_courseType.text = m.type.strTitle
            label_courseType.isHidden = m.type == .none
            view_vaildTime.isHidden = m.type == .normal
            private var id = 0
            let w = String.jq_getWidth(text: m.type.strTitle, height: 25, font: 14)
            label_courseType.jq_cornerPartWithNib(byRoundingCorners: [.topLeft,.bottomLeft], radii: 8, size: CGSize(width: w, height: 25))
            label_courseType.layoutIfNeeded()
            private var signUpCourseModel:SignUpCourseItemDetailModel?
            private var detailModel:CourseDetailModel?{
                        didSet{
            img_1.sd_setImage(with: URL(string: m.introduceDrawing)) { image, error, type, url in
               let radio = image!.size.width / image!.size.height
               self.cons_img1Height.constant = JQ_ScreenW / radio
            }
                                    if let m = detailModel{
                                                label_title.text = m.name
                                                label_distance.text = String(format: "距离我%.2lfkm", m.distance)
                                                label_local.text = String(format: "%@(%@)", m.storeName,m.storeAddress)
                                                label_listenWeek.text = "每" + m.weeks.joined(separator: "、")
                                                label_listenTime.text = m.times.joined(separator: "|")
                                                label_vaildTime.text = m.time
                                                label_courseType.text = m.type.strTitle
                                                label_courseType.isHidden = m.type == .none
                                                view_vaildTime.isHidden = m.type == .normal
            let imgs = m.detailDrawing.components(separatedBy: ",")
            var items = [CommonBannerModel]()
            for (index,img) in imgs.enumerated(){
               items.append(CommonBannerModel(index: index,resource: img,mediaType: .imageUrl))
            }
            view_banner.setItems(items: items)
                                                let w = String.jq_getWidth(text: m.type.strTitle, height: 25, font: 14)
                                                label_courseType.jq_cornerPartWithNib(byRoundingCorners: [.topLeft,.bottomLeft], radii: 8, size: CGSize(width: w, height: 25))
                                                label_courseType.layoutIfNeeded()
            var tempSub = m.list.first
            if signUpCourseModel?.chooseHours != nil{
               for v in m.list{
                  if v.classHours == signUpCourseModel?.chooseHours{
                     tempSub = v;break
                  }
               }
            }
                                                img_1.sd_setImage(with: URL(string: m.introduceDrawing)) { image, error, type, url in
                                                            let radio = image!.size.width / image!.size.height
                                                            self.cons_img1Height.constant = JQ_ScreenW / radio
                                                }
            if let subM = tempSub {
               switch subM.payType {
                  case .coin:
                     label_price.text = ""
                     label_price.isHidden = true
                     label_originPrice.isHidden = true
                     label_vipPrice.isHidden = true
                     label_coin.isHidden = false
                     //玩湃币
                     label_coin.attributedText = AttributedStringbuilder.build()
                        .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                        .add(string: "\(subM.playPaiCoin )币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")).mutableAttributedString
                                                let imgs = m.detailDrawing.components(separatedBy: ",")
                                                var items = [CommonBannerModel]()
                                                for (index,img) in imgs.enumerated(){
                                                            items.append(CommonBannerModel(index: index,resource: img,mediaType: .imageUrl))
                                                }
                                                view_banner.setItems(items: items)
                  case .cash:
                     fallthrough
                  case .cashCoin:
                     if subM.originalPrice == 0 || subM.originalPrice == subM.paymentPrice{
                        label_originPrice.isHidden = true
                     }else{
                        label_originPrice.isHidden = false
                     }
                     label_coin.isHidden = subM.payType == .cash
                        //玩湃币
                     label_coin.attributedText = AttributedStringbuilder.build()
                        .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                        .add(string: "\(subM.playPaiCoin )币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")).mutableAttributedString
                                                var tempSub = m.list.first
                                                if signUpCourseModel?.chooseHours != nil{
                                                            for v in m.list{
                                                                        if v.classHours == signUpCourseModel?.chooseHours{
                                                                                    tempSub = v;break
                                                                        }
                                                            }
                                                }
                        //原价
                     let attribute = AttributedStringbuilder.build().add(string: subM.originalPrice.currency(), withFont: UIFont.systemFont(ofSize: 16, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58)).delLine(color: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58))
                     label_originPrice.attributedText = attribute.mutableAttributedString
                                                if let subM = tempSub {
                                                            switch subM.payType {
                                                                        case .coin:
                                                                                    label_price.text = ""
                                                                                    label_price.isHidden = true
                                                                                    label_originPrice.isHidden = true
                                                                                    label_vipPrice.isHidden = true
                                                                                    label_coin.isHidden = false
                                                                                    //玩湃币
                                                                                    label_coin.attributedText = AttributedStringbuilder.build()
                                                                                                .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                                                                                                .add(string: "\(subM.playPaiCoin )币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")).mutableAttributedString
                     if UserInfoModel.get()?.isVip == 1{
                        if subM.payType != .coin{
                              //会员
                           label_vipPrice.isHidden = true
                              //优惠价比会员价更优惠
                           if subM.paymentPrice < subM.vipPrice && subM.paymentPrice != 0{
                              label_price.text = subM.paymentPrice.currency()
                           }
                              //会员价比优惠价更优惠
                           else if subM.vipPrice < subM.paymentPrice && subM.vipPrice != 0{
                              label_price.text = subM.vipPrice.currency()
                           }else if subM.vipPrice != 0 && subM.paymentPrice != 0{
                                 //会员价和优惠价一样
                              label_price.text = min(subM.vipPrice,subM.paymentPrice).currency()
                           }else{
                              label_price.text = subM.paymentPrice.currency()
                           }
                                                                        case .cash:
                                                                                    fallthrough
                                                                        case .cashCoin:
                                                                                    if subM.originalPrice == 0 || subM.originalPrice == subM.paymentPrice{
                                                                                                label_originPrice.isHidden = true
                                                                                    }else{
                                                                                                label_originPrice.isHidden = false
                                                                                    }
                                                                                    label_coin.isHidden = subM.payType == .cash
                                                                                    //玩湃币
                                                                                    label_coin.attributedText = AttributedStringbuilder.build()
                                                                                                .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                                                                                                .add(string: "\(subM.playPaiCoin )币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313")).mutableAttributedString
                                                                                    //原价
                                                                                    let attribute = AttributedStringbuilder.build().add(string: subM.originalPrice.currency(), withFont: UIFont.systemFont(ofSize: 16, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58)).delLine(color: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58))
                                                                                    label_originPrice.attributedText = attribute.mutableAttributedString
                                                                                    if UserInfoModel.get()?.isVip == 1{
                                                                                                if subM.payType != .coin{
                                                                                                            //会员
                                                                                                            label_vipPrice.isHidden = true
                                                                                                            //优惠价比会员价更优惠
                                                                                                            if subM.paymentPrice < subM.vipPrice && subM.paymentPrice != 0{
                                                                                                                        label_price.text = subM.paymentPrice.currency()
                                                                                                            }
                                                                                                            //会员价比优惠价更优惠
                                                                                                            else if subM.vipPrice < subM.paymentPrice && subM.vipPrice != 0{
                                                                                                                        label_price.text = subM.vipPrice.currency()
                                                                                                            }else if subM.vipPrice != 0 && subM.paymentPrice != 0{
                                                                                                                        //会员价和优惠价一样
                                                                                                                        label_price.text = min(subM.vipPrice,subM.paymentPrice).currency()
                                                                                                            }else{
                                                                                                                        label_price.text = subM.paymentPrice.currency()
                                                                                                            }
                                                                                                }
                                                                                    }else{
                                                                                                if subM.payType != .coin{
                                                                                                            //非会员
                                                                                                            label_vipPrice.isHidden = subM.vipPrice == 0 || subM.vipPrice == subM.paymentPrice
                                                                                                            let vipAttribute = AttributedStringbuilder.build()
                                                                                                                        .add(string: "会员价:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                                                                                                                        .add(string: subM.vipPrice.currency(), withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313"))
                                                                                                            label_vipPrice.attributedText = vipAttribute.mutableAttributedString
                                                                                                            if subM.originalPrice != 0 && subM.paymentPrice == 0{
                                                                                                                        label_price.text = subM.originalPrice.currency()
                                                                                                            }else if subM.originalPrice == 0 && subM.paymentPrice != 0{
                                                                                                                        label_price.text = subM.paymentPrice.currency()
                                                                                                            }else if subM.originalPrice != 0 && subM.paymentPrice != 0{
                                                                                                                        label_price.text = min(subM.originalPrice,subM.paymentPrice).currency()
                                                                                                            }else{
                                                                                                                        label_price.text = subM.originalPrice.currency()
                                                                                                            }
                                                                                                }
                                                                                    }
                                                            }
                                                }
                                                if m.type == .experience{
                                                            if  m.list.first?.paymentPrice != 0{
                                                                        label_price.text = (m.list.first!.paymentPrice).currency()
                                                                        label_price.isHidden = false
                                                            }
                                                            label_vaildTime.text = "购买当天有效"
                                                            label_originPrice.isHidden = true
                                                            label_vipPrice.isHidden = true
                                                            view_listen.isHidden = true
                                                            //               label_price.isHidden = (m.list.first?.paymentPrice ?? 0) == 0
                                                }
                                                //体验课,假期课不展示
                                                if m.type != .normal && signUpCourseModel != nil{
                                                            view_handle.isHidden = true
                                                            cons_handleHei.constant = 0
                                                }
                                                //            if label_originPrice.isHidden && label_vipPrice.isHidden && label_coin.isHidden{
                                                //               label_coin.alpha = 0
                                                //            }
                                    }
                        }
                     }else{
                        if subM.payType != .coin{
                              //非会员
                           label_vipPrice.isHidden = subM.vipPrice == 0 || subM.vipPrice == subM.paymentPrice
                           let vipAttribute = AttributedStringbuilder.build()
                              .add(string: "会员价:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                              .add(string: subM.vipPrice.currency(), withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313"))
                           label_vipPrice.attributedText = vipAttribute.mutableAttributedString
            }
            required init(id:Int,signUpCourseModel:SignUpCourseItemDetailModel? = nil) {
                        super.init(nibName: nil, bundle: nil)
                        self.id = id
                        self.signUpCourseModel = signUpCourseModel
            }
                           if subM.originalPrice != 0 && subM.paymentPrice == 0{
                              label_price.text = subM.originalPrice.currency()
                           }else if subM.originalPrice == 0 && subM.paymentPrice != 0{
                              label_price.text = subM.paymentPrice.currency()
                           }else if subM.originalPrice != 0 && subM.paymentPrice != 0{
                              label_price.text = min(subM.originalPrice,subM.paymentPrice).currency()
                           }else{
                              label_price.text = subM.originalPrice.currency()
                           }
            required init?(coder: NSCoder) {
                        fatalError("init(coder:) has not been implemented")
            }
            override func viewDidLoad() {
                        super.viewDidLoad()
                        title = "运动营详情"
                        if signUpCourseModel?.payStatus == .unPayment{
                                    btn_enroll.setTitle("待支付", for: .normal)
                        }else if signUpCourseModel?.payStatus == .paymented{
                                    btn_enroll.setTitle("续课", for: .normal)
                        }
                     }
               }
                        Services.queryCourseInfo(id: id).subscribe(onNext: { data in
                                    if let m = data.data{
                                                self.detailModel = m
                                    }
                        }).disposed(by: disposeBag)
            }
            if m.type == .experience{
            override func setUI() {
               if  m.list.first?.paymentPrice != 0{
                  label_price.text = (m.list.first!.paymentPrice).currency()
                  label_price.isHidden = false
               }
               label_vaildTime.text = "购买当天有效"
               label_originPrice.isHidden = true
               label_vipPrice.isHidden = true
               view_listen.isHidden = true
//               label_price.isHidden = (m.list.first?.paymentPrice ?? 0) == 0
            }
               //体验课,假期课不展示
            if m.type != .normal && signUpCourseModel != nil{
               view_handle.isHidden = true
               cons_handleHei.constant = 0
            override func viewDidLayoutSubviews() {
                        super.viewDidLayoutSubviews()
                        let w = String.jq_getWidth(text: detailModel?.type.strTitle ?? "", height: 25, font: 14) + 16
                        view_tag.jq_addCorners(corner: [.topLeft,.bottomLeft], radius: 4, width: w, height: 25)
            }
//            if label_originPrice.isHidden && label_vipPrice.isHidden && label_coin.isHidden{
//               label_coin.alpha = 0
//            }
         }
        }
    }
            @IBAction func applyAction(_ sender: UIButton) {
                        if let m = detailModel{
                                    let vc = CourseDetailApplyVC(detailModel: m,signUpModel: signUpCourseModel)
                                    push(vc: vc)
                        }
            }
   required init(id:Int,signUpCourseModel:SignUpCourseItemDetailModel? = nil) {
        super.init(nibName: nil, bundle: nil)
        self.id = id
      self.signUpCourseModel = signUpCourseModel
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "运动营详情"
      if signUpCourseModel?.payStatus == .unPayment{
         btn_enroll.setTitle("待支付", for: .normal)
      }else if signUpCourseModel?.payStatus == .paymented{
         btn_enroll.setTitle("续课", for: .normal)
      }
        Services.queryCourseInfo(id: id).subscribe(onNext: { data in
            if let m = data.data{
                self.detailModel = m
            }
        }).disposed(by: disposeBag)
    }
    override func setUI() {
    }
   override func viewDidLayoutSubviews() {
      super.viewDidLayoutSubviews()
      let w = String.jq_getWidth(text: detailModel?.type.strTitle ?? "", height: 25, font: 14) + 16
      view_tag.jq_addCorners(corner: [.topLeft,.bottomLeft], radius: 4, width: w, height: 25)
   }
   @IBAction func applyAction(_ sender: UIButton) {
      if let m = detailModel{
         let vc = CourseDetailApplyVC(detailModel: m,signUpModel: signUpCourseModel)
           push(vc: vc)
        }
    }
    @IBAction func localAction(_ sender: UIButton) {
      if let m = detailModel{
         JQ_MapNavigationTool.startNav(CLLocationCoordinate2D(latitude: m.lat.toDouble, longitude: m.lon.toDouble), distanceName: m.storeAddress, scheme: "weparklife")
      }
    }
            @IBAction func localAction(_ sender: UIButton) {
                        if let m = detailModel{
                                    JQ_MapNavigationTool.startNav(CLLocationCoordinate2D(latitude: m.lat.toDouble, longitude: m.lon.toDouble), distanceName: m.storeAddress, scheme: "weparklife")
                        }
            }
}