无故事王国
2023-09-26 c86ac49db2969495ec21fae2a27956cad9499752
WanPai/Root/Course/VC/CourseDetailVC.swift
@@ -16,12 +16,12 @@
    @IBOutlet weak var btn_local: QMUIButton!
    @IBOutlet weak var label_distance: UILabel!
    @IBOutlet weak var label_listenWeek: UILabel!
    @IBOutlet weak var label_listenTime: UILabel!
   @IBOutlet weak var view_listen: UIView!
   @IBOutlet weak var label_listenTime: UILabel!
    @IBOutlet weak var img_1: UIImageView!
    @IBOutlet weak var img_2: UIImageView!
    @IBOutlet weak var cons_img1Height: NSLayoutConstraint!
    @IBOutlet weak var cons_img2Height: NSLayoutConstraint!
   @IBOutlet weak var label_type: UILabel!
   @IBOutlet weak var label_courseType: UILabel!
   @IBOutlet weak var label_vaildTime: UILabel!
   @IBOutlet weak var view_vaildTime: UIView!
@@ -37,86 +37,92 @@
    private var id = 0
   private var signUpCourseModel:SignUpCourseItemDetailModel?
    private var detailModel:CourseDetailModel!{
    private var detailModel:CourseDetailModel?{
        didSet{
            img_cover.sd_setImage(with: URL(string: detailModel.coverDrawing))
            label_title.text = detailModel.name
            label_distance.text = String(format: "距离我%.2lfkm", detailModel.distance)
            btn_local.setTitle(detailModel.storeAddress, for: .normal)
            label_listenWeek.text = detailModel.weeks.joined(separator: "、")
         label_listenTime.text = detailModel.times.joined(separator: "|")
         label_vaildTime.text = detailModel.time
         label_courseType.text = detailModel.type.strTitle
         label_courseType.isHidden = detailModel.type == .none
         view_vaildTime.isHidden = detailModel.type == .normal
            img_1.sd_setImage(with: URL(string: detailModel.introduceDrawing)) { image, error, type, url in
                let radio = image!.size.width / image!.size.height
                self.cons_img1Height.constant = JQ_ScreenH * radio
         if let m = detailModel{
            img_cover.sd_setImage(with: URL(string: m.coverDrawing))
            label_title.text = m.name
            label_distance.text = String(format: "距离我%.2lfkm", m.distance)
            btn_local.setTitle(m.storeAddress, for: .normal)
            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 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()
            img_2.sd_setImage(with: URL(string: detailModel.detailDrawing)) { image, error, type, url in
                let radio = image!.size.width / image!.size.height
                self.cons_img2Height.constant = JQ_ScreenH * radio
            }
            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
            label_price.text = detailModel.list.first!.paymentPrice.currency()
            if let subM = detailModel.list.first {
                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)).delLine(color: UIColor(hexStr: "#3F3F3F").withAlphaComponent(0.58))
                    label_originPrice.attributedText = attribute.mutableAttributedString
                }
            img_2.sd_setImage(with: URL(string: m.detailDrawing)) { image, error, type, url in
               let radio = image!.size.width / image!.size.height
               self.cons_img2Height.constant = JQ_ScreenW / radio
            }
            label_price.text = m.list.first!.paymentPrice.currency()
            if let subM = m.list.first {
               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)).delLine(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 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
                }
            }
                  //会员价
               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
               }
            }
         if detailModel.type == .experience{
            label_courseType.text = "购买当天有效"
            label_price.text = (detailModel.list.first?.originalPrice ?? 0).currency()
            label_originPrice.isHidden = true
            label_vipPrice.isHidden = true
            if m.type == .experience{
               label_price.text = (m.list.first?.paymentPrice ?? 0).currency()
               label_originPrice.isHidden = true
               label_vipPrice.isHidden = true
               label_vaildTime.text = "购买当天有效"
               view_listen.isHidden = true
            }
               //体验课,假期课不展示
            if m.type != .normal && signUpCourseModel != nil{
               view_handle.isHidden = true
               cons_handleHei.constant = 0
            }
            if let m = signUpCourseModel{
               label_originPrice.isHidden = true
//               label_vipPrice.isHidden = true
               let coinAttribute = AttributedStringbuilder.build()
                  .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
                  .add(string: "\(m.wpGold)币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313"))
               label_coin.attributedText = coinAttribute.mutableAttributedString
               label_price.text = m.paymentPrice.currency()
               label_coin.alpha = m.wpGold == 0 ? 0:1
            }
         }
         //体验课,假期课不展示
         if detailModel.type != .normal && signUpCourseModel != nil{
            view_handle.isHidden = true
            cons_handleHei.constant = 0
         }
         if let m = signUpCourseModel{
            label_originPrice.isHidden = true
            label_vipPrice.isHidden = true
            let coinAttribute = AttributedStringbuilder.build()
               .add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#3F3F3F"))
               .add(string: "\(m.wpGold)币", withFont: UIFont.systemFont(ofSize: 14, weight: .semibold), withColor: UIColor(hexStr: "#F21313"))
            label_coin.attributedText = coinAttribute.mutableAttributedString
            label_price.text = m.amount.currency()
            label_coin.alpha = m.wpGold == 0 ? 0:1
         }
        }
    }
@@ -154,7 +160,6 @@
   override func viewDidLayoutSubviews() {
      super.viewDidLayoutSubviews()
      label_type.jq_addCorners(corner: [.topLeft,.bottomLeft], radius: 4, width: 58, height: 25)
   }
   @IBAction func applyAction(_ sender: UIButton) {
@@ -175,6 +180,8 @@
    
    
    @IBAction func localAction(_ sender: QMUIButton) {
        JQ_MapNavigationTool.startNav(CLLocationCoordinate2D(latitude: detailModel.lat.toDouble, longitude: detailModel.lon.toDouble), distanceName: detailModel.storeAddress, scheme: "weparklife")
      if let m = detailModel{
         JQ_MapNavigationTool.startNav(CLLocationCoordinate2D(latitude: m.lat.toDouble, longitude: m.lon.toDouble), distanceName: m.storeAddress, scheme: "weparklife")
      }
    }
}