| | |
| | | @IBOutlet weak var collectionView: UICollectionView! |
| | | @IBOutlet weak var cons_collectionHei: NSLayoutConstraint! |
| | | @IBOutlet weak var label_needNum: UILabel! |
| | | |
| | | @IBOutlet weak var hei_cons: NSLayoutConstraint! |
| | | |
| | | private var courseId:Int! |
| | | private var experienceCourseModel:ExperienceCourseModel? |
| | | private var cellW:Double = 0 |
| | |
| | | override func viewDidLoad() { |
| | | super.viewDidLoad() |
| | | title = "体验购课" |
| | | cellW = ((view.width - 28.0) - 11.0 * 3) / 4 |
| | | cellW = ((view.width - 40.0) - 11.0 * 3) / 4 |
| | | cellH = cellW * 0.439 |
| | | |
| | | collectionView.delegate = self |
| | | collectionView.dataSource = self |
| | | collectionView.isScrollEnabled = false |
| | | collectionView.register(UINib(nibName: "Common_1_CCell", bundle: nil), forCellWithReuseIdentifier: "_Common_1_CCell") |
| | | collectionView.contentInset = UIEdgeInsets(top: 0, left: 14, bottom: 0, right: 14) |
| | | |
| | |
| | | if let model = data.data{ |
| | | self?.label_name.text = model.name |
| | | self?.label_num.text = "\(model.num)课时" |
| | | self?.label_week.text = model.week |
| | | self?.label_week.text = "每" + model.week |
| | | self?.label_times.text = model.time.joined(separator: "|") |
| | | self?.experienceCourseModel = model |
| | | self?.collectionView.reloadData() |
| | |
| | | } |
| | | |
| | | @IBAction func paymenAction(_ sender: UIButton) { |
| | | guard selectIndexs.count > 0 else {alert(msg: "请选择上课时间");return} |
| | | let n = (experienceCourseModel?.num ?? 0) * (experienceCourseModel?.time.count ?? 0) * selectIndexs.count |
| | | if let storeId = UserDefaults.standard.value(forKey: "Current_StoreID") as? Int{ |
| | | PaymentCourseView.show(storeId: storeId, number: n) {[weak self] s in |
| | | guard let weakSelf = self else { return } |
| | | if let storeStr = UserDefaults.standard.object(forKey: "CurrentStore") as? String{ |
| | | if let deserModel = HomeStoreModel.deserialize(from: storeStr){ |
| | | PaymentCourseView.show(storeId: deserModel.storeId, number: n) {[weak self] s in |
| | | guard let weakSelf = self else { return } |
| | | |
| | | var t = [String]() |
| | | for selectIndex in weakSelf.selectIndexs { |
| | | t.append(weakSelf.experienceCourseModel!.day[selectIndex]) |
| | | var t = [String]() |
| | | for selectIndex in weakSelf.selectIndexs { |
| | | t.append(weakSelf.experienceCourseModel!.day[selectIndex]) |
| | | } |
| | | Services.payCourse(courseId: weakSelf.courseId, num: n, oldCourseId: s, time: t).subscribe(onNext: {data in |
| | | alertSuccess(msg: "购买成功") |
| | | }) { error in |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | } |
| | | Services.payCourse(courseId: weakSelf.courseId, num: n, oldCourseId: s, time: t).subscribe(onNext: {data in |
| | | alertSuccess(msg: "购买成功") |
| | | }) { error in |
| | | |
| | | }.disposed(by: weakSelf.disposeBag) |
| | | } |
| | | } |
| | | } |
| | |
| | | extension ExperienceCourseVC:UICollectionViewDelegate{ |
| | | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { |
| | | if selectIndexs.contains(indexPath.row){ |
| | | selectIndexs.remove(indexPath.row) |
| | | if indexPath.row == 0 || (indexPath.row == (experienceCourseModel!.day.count - 1)){ |
| | | selectIndexs.remove(indexPath.row) |
| | | }else if selectIndexs.contains(indexPath.row + 1) && selectIndexs.contains(indexPath.row - 1){ |
| | | alert(msg: "必须连续选择") |
| | | }else{ |
| | | selectIndexs.remove(indexPath.row) |
| | | } |
| | | }else{ |
| | | selectIndexs.insert(indexPath.row) |
| | | if selectIndexs.count != 0{ |
| | | if selectIndexs.contains(indexPath.row - 1) || selectIndexs.contains(indexPath.row + 1){ |
| | | selectIndexs.insert(indexPath.row) |
| | | }else{ |
| | | alert(msg: "必须连续选择") |
| | | } |
| | | }else{ |
| | | selectIndexs.insert(indexPath.row) |
| | | } |
| | | } |
| | | let n = (experienceCourseModel?.num ?? 0) * (experienceCourseModel?.time.count ?? 0) * selectIndexs.count |
| | | label_needNum.text = "\(n)" |
| | |
| | | cell.label_content.backgroundColor = isSelected ? Def_ThemeColor : .white |
| | | cell.label_content.textColor = isSelected ? .white : UIColor(hexStr: "#898989") |
| | | cell.label_content.borderWidth = isSelected ? 0:1 |
| | | cell.label_content.borderColor = UIColor(hexStr: "#F2E9E9") |
| | | return cell |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { |
| | | return 11 |
| | | return 13 |
| | | } |
| | | |
| | | func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { |