From 2834569133090d46dd3f28a30100fa74661ef1e1 Mon Sep 17 00:00:00 2001 From: 无故事王国 <841720330@qq.com> Date: 星期三, 20 九月 2023 18:41:27 +0800 Subject: [PATCH] 完善 --- WanPai/Root/Course/VC/CourseInfoVC.swift | 166 +++++++++++++++++++++++++++++++------------------------ 1 files changed, 93 insertions(+), 73 deletions(-) diff --git a/WanPai/Root/Course/VC/CourseInfoVC.swift b/WanPai/Root/Course/VC/CourseInfoVC.swift index ac57a2c..fa746ee 100644 --- a/WanPai/Root/Course/VC/CourseInfoVC.swift +++ b/WanPai/Root/Course/VC/CourseInfoVC.swift @@ -41,7 +41,7 @@ var startClouseHomeModel:StartClouseHomeModel? - var weeklyCourseModels = [WeeklyCourseModel]() + var weeklyCourseModel:WeeklyCourseModel? private var currentDate = Date() private var unDispatchNum:Int? private var mentals = [StudentMedalModel]() @@ -298,10 +298,11 @@ private func getSelectDayData(){ if let model = startClouseHomeModel{ - Services.weeksOfCourseDetails(stuId: model.stuId, time: currentDate).subscribe(onNext: {[weak self] data in - if let models = data.data{ - self?.weeklyCourseModels = models - self?.cons_tableHei.constant = Double(models.flatMap({$0.courses}).count) * 70 + 58 * Double(models.count) + let currentStoreId = UserDefaults.standard.value(forKey: "Current_StoreID") + Services.weeksOfCourseDetails(stuId: model.stuId, time: currentDate,storeId: currentStoreId as! Int).subscribe(onNext: {[weak self] data in + if let model = data.data{ + self?.weeklyCourseModel = model + self?.cons_tableHei.constant = 58 + 70 * Double(model.data.count) UIView.animate(withDuration: 0.3) { self?.view.layoutIfNeeded() self?.viewDidLayoutSubviews() @@ -323,13 +324,18 @@ @objc func localDetailAction(btn:UIButton){ let index = btn.tag - 10 - let model = weeklyCourseModels[index] - JQ_MapNavigationTool.startNav(CLLocationCoordinate2D(latitude: model.lat, longitude: model.lon), distanceName: model.areaName, scheme: "weparklife") + if let model = weeklyCourseModel?.data[index]{ + JQ_MapNavigationTool.startNav(CLLocationCoordinate2D(latitude: weeklyCourseModel!.lat, longitude: weeklyCourseModel!.lon), distanceName: weeklyCourseModel!.name, scheme: "weparklife") + } } } extension CourseInfoVC:UITableViewDelegate{ - + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let m = weeklyCourseModel?.data[indexPath.row] + let vc = SignUpCourseVC() + push(vc: vc) + } } extension CourseInfoVC:UITableViewDataSource{ @@ -337,100 +343,114 @@ let cell = tableView.dequeueReusableCell(withIdentifier: "_CourseBookingTCell") as! CourseBookingTCell cell.contentView.backgroundColor = UIColor(hexStr: "#F2F6F9") - if indexPath.row == 0 && weeklyCourseModels[indexPath.section].courses.count == 1{ + + + if indexPath.row == 0 && weeklyCourseModel?.data.count == 1{ cell.contentView.jq_addCorners(corner: [.allCorners], radius: 16,width: JQ_ScreenW - 48,height: 70) - }else if indexPath.row == 0 && weeklyCourseModels[indexPath.section].courses.count != 1{ + }else if indexPath.row == 0 && weeklyCourseModel?.data.count != 1{ cell.contentView.jq_addCorners(corner: [.topLeft,.topRight], radius: 16,width: JQ_ScreenW - 48,height: 70) - }else if indexPath.row == weeklyCourseModels[indexPath.section].courses.count - 1{ + }else if indexPath.row == (weeklyCourseModel?.data.count ?? 0) - 1{ cell.contentView.jq_addCorners(corner: [.bottomLeft,.bottomRight], radius: 16,width: JQ_ScreenW - 48,height: 70) }else{ cell.contentView.jq_addCorners(corner: [.allCorners], radius: 0,width: JQ_ScreenW - 48,height: 70) } - cell.weeklyCourseItemModel = weeklyCourseModels[indexPath.section].courses[indexPath.row] + cell.weeklyCourseItemModel = weeklyCourseModel?.data[indexPath.row] cell.clickClouse = {[weak self] m in guard let weakSelf = self else { return } if let stuId = weakSelf.startClouseHomeModel?.stuId{ - Services.startCourceRreverse(courseId: m.courseID, time: weakSelf.currentDate.jq_format("yyyy-MM-dd"), stuId: stuId).subscribe(onNext: { data in - alertSuccess(msg: "预约成功") - tableView.beginUpdates() - weakSelf.weeklyCourseModels[indexPath.section].courses.remove(at: indexPath.row) - tableView.deleteRows(at: [indexPath], with: .automatic) - tableView.endUpdates() - weakSelf.cons_tableHei.constant = Double(weakSelf.weeklyCourseModels.flatMap({$0.courses}).count) * 70 + 58 * Double(weakSelf.weeklyCourseModels.count) - UIView.animate(withDuration: 0.3) { - weakSelf.view.layoutIfNeeded() - weakSelf.viewDidLayoutSubviews() - } - }).disposed(by: weakSelf.disposeBag) + //请假 + if m.type == 1{ + Services.startCourceRreverse(courseId: m.id, time: weakSelf.currentDate.jq_format("yyyy-MM-dd"), stuId: stuId).subscribe(onNext: { data in + alertSuccess(msg: "请假成功") + tableView.beginUpdates() + weakSelf.weeklyCourseModel?.data.remove(at: indexPath.row) + tableView.deleteRows(at: [indexPath], with: .automatic) + tableView.endUpdates() + weakSelf.cons_tableHei.constant = 58 + 70 * Double(weakSelf.weeklyCourseModel?.data.count ?? 0) + UIView.animate(withDuration: 0.3) { + weakSelf.view.layoutIfNeeded() + weakSelf.viewDidLayoutSubviews() + } + }).disposed(by: weakSelf.disposeBag) + } + + //购课 + if m.type == 2{ + let vc = ExperienceCourseVC(courseId: m.id) + weakSelf.push(vc: vc) + } + } } return cell } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return weeklyCourseModels[section].courses.count + return weeklyCourseModel?.data.count ?? 0 } func numberOfSections(in tableView: UITableView) -> Int { - return weeklyCourseModels.count + return 1 } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 70 } - func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - let m = weeklyCourseModels[section] - var headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header") - if headerView == nil{ - headerView = UITableViewHeaderFooterView(reuseIdentifier: "header") + func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + if let m = weeklyCourseModel{ + var headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header") + if headerView == nil{ + headerView = UITableViewHeaderFooterView(reuseIdentifier: "header") - let contentView = UIView() - contentView.borderColor = UIColor(hexStr: "#E7E3E3") - contentView.borderWidth = 1 - contentView.cornerRadius = 11 - headerView?.contentView.addSubview(contentView) - contentView.snp.makeConstraints { make in - make.center.equalToSuperview() - make.left.right.equalToSuperview() - make.height.equalTo(22) - } + let contentView = UIView() + contentView.borderColor = UIColor(hexStr: "#E7E3E3") + contentView.borderWidth = 1 + contentView.cornerRadius = 11 + headerView?.contentView.addSubview(contentView) + contentView.snp.makeConstraints { make in + make.center.equalToSuperview() + make.left.right.equalToSuperview() + make.height.equalTo(22) + } - let label_address = UILabel() - label_address.tag = 1000 - label_address.text = "成都非遗玩湃全科体育公园 0.0km" - label_address.font = UIFont.systemFont(ofSize: 10, weight: .medium) - label_address.textColor = UIColor(hexStr: "#AFB4BC") - contentView.addSubview(label_address) - label_address.snp.makeConstraints { make in - make.left.equalToSuperview().offset(12) - make.centerY.equalToSuperview() - make.right.equalTo(-50) - } + let label_address = UILabel() + label_address.tag = 1000 + label_address.text = "成都非遗玩湃全科体育公园 0.0km" + label_address.font = UIFont.systemFont(ofSize: 10, weight: .medium) + label_address.textColor = UIColor(hexStr: "#AFB4BC") + contentView.addSubview(label_address) + label_address.snp.makeConstraints { make in + make.left.equalToSuperview().offset(12) + make.centerY.equalToSuperview() + make.right.equalTo(-50) + } - let btn_detial = QMUIButton(type: .custom) - btn_detial.setTitle("位置详情", for: .normal) - btn_detial.tag = 10 + section - btn_detial.addTarget(self, action: #selector(localDetailAction(btn:)), for: .touchUpInside) - btn_detial.titleLabel?.font = UIFont.systemFont(ofSize: 10) - btn_detial.setTitleColor(UIColor(hexStr: "#AFB4BC"), for: .normal) - btn_detial.setImage(UIImage(named: "icon_pop"), for: .normal) - btn_detial.imagePosition = .left - btn_detial.spacingBetweenImageAndTitle = 3 - contentView.addSubview(btn_detial) - btn_detial.snp.makeConstraints { make in - make.right.equalTo(-10) - make.centerY.equalToSuperview() - } - } + let btn_detial = QMUIButton(type: .custom) + btn_detial.setTitle("位置详情", for: .normal) + btn_detial.tag = 10 + section + btn_detial.addTarget(self, action: #selector(localDetailAction(btn:)), for: .touchUpInside) + btn_detial.titleLabel?.font = UIFont.systemFont(ofSize: 10) + btn_detial.setTitleColor(UIColor(hexStr: "#AFB4BC"), for: .normal) + btn_detial.setImage(UIImage(named: "icon_pop"), for: .normal) + btn_detial.imagePosition = .left + btn_detial.spacingBetweenImageAndTitle = 3 + contentView.addSubview(btn_detial) + btn_detial.snp.makeConstraints { make in + make.right.equalTo(-10) + make.centerY.equalToSuperview() + } + } - if let label = headerView?.contentView.viewWithTag(1000) as? UILabel{ - label.text = String(format: "%@ %.1lfkm", m.areaName,m.siteDistance) - } + if let label = headerView?.contentView.viewWithTag(1000) as? UILabel{ + label.text = String(format: "%@ %.1lfkm", m.name,m.distance) + } - headerView?.contentView.backgroundColor = .white - return headerView - } + headerView?.contentView.backgroundColor = .white + return headerView + } + return nil + } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 58 -- Gitblit v1.7.1