Commit 547e1ea5 authored by pete谢兆麟's avatar pete谢兆麟

逻辑

parent 199c626f
......@@ -1171,6 +1171,7 @@
048D6AE32D6348F000BC6F4C /* YHMemberCenterCurrentPrivilegeCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048D6AE22D6348EF00BC6F4C /* YHMemberCenterCurrentPrivilegeCell.swift */; };
0497C7532D9BD21500A3E32A /* YHMakePlanViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0497C7522D9BD21500A3E32A /* YHMakePlanViewModel.swift */; };
0497C7552D9BD36700A3E32A /* YHMakePlanModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0497C7542D9BD36700A3E32A /* YHMakePlanModel.swift */; };
0497C7572D9D437B00A3E32A /* YHMakePlanScoreModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0497C7562D9D437B00A3E32A /* YHMakePlanScoreModel.swift */; };
04A750D02D925FD400974E5F /* YHCustomerInformationQuestionnaireVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04A750CF2D925FD400974E5F /* YHCustomerInformationQuestionnaireVC.swift */; };
04A750D22D93ABCE00974E5F /* YHSurveyTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04A750D12D93ABCE00974E5F /* YHSurveyTableViewCell.swift */; };
04A750D42D93DFED00974E5F /* YHSurveyQuestionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04A750D32D93DFED00974E5F /* YHSurveyQuestionType.swift */; };
......@@ -2475,6 +2476,7 @@
048D6AE22D6348EF00BC6F4C /* YHMemberCenterCurrentPrivilegeCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMemberCenterCurrentPrivilegeCell.swift; sourceTree = "<group>"; };
0497C7522D9BD21500A3E32A /* YHMakePlanViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMakePlanViewModel.swift; sourceTree = "<group>"; };
0497C7542D9BD36700A3E32A /* YHMakePlanModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMakePlanModel.swift; sourceTree = "<group>"; };
0497C7562D9D437B00A3E32A /* YHMakePlanScoreModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHMakePlanScoreModel.swift; sourceTree = "<group>"; };
04A750CF2D925FD400974E5F /* YHCustomerInformationQuestionnaireVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCustomerInformationQuestionnaireVC.swift; sourceTree = "<group>"; };
04A750D12D93ABCE00974E5F /* YHSurveyTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSurveyTableViewCell.swift; sourceTree = "<group>"; };
04A750D32D93DFED00974E5F /* YHSurveyQuestionType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSurveyQuestionType.swift; sourceTree = "<group>"; };
......@@ -6719,6 +6721,7 @@
isa = PBXGroup;
children = (
0497C7542D9BD36700A3E32A /* YHMakePlanModel.swift */,
0497C7562D9D437B00A3E32A /* YHMakePlanScoreModel.swift */,
);
path = M;
sourceTree = "<group>";
......@@ -7737,6 +7740,7 @@
045C119B2D12CA5F00BD2DC0 /* YHButlerServiceMessage.swift in Sources */,
045C119C2D12CA5F00BD2DC0 /* YHSubmitAllInfoCheckView.swift in Sources */,
045C119D2D12CA5F00BD2DC0 /* UIColor+Extension.swift in Sources */,
0497C7572D9D437B00A3E32A /* YHMakePlanScoreModel.swift in Sources */,
045C119E2D12CA5F00BD2DC0 /* YHCustomTextView.swift in Sources */,
04307BA52D1E54BD00ED8E8D /* YHGCInformationFillTipsAlertView.swift in Sources */,
045C119F2D12CA5F00BD2DC0 /* YHEditBaseUserInfoViewController.swift in Sources */,
......
......@@ -57,14 +57,6 @@ class YHMakePlanViewController: YHBaseViewController {
make.bottom.left.right.equalToSuperview()
make.height.equalTo(98)
}
// Configure with data
priceView.configure(price: "489800") {
print("Action button tapped!")
YHMakePlanPriceAlertView.show { _ in
}
}
self.view.addSubview(tableView)
tableView.snp.makeConstraints { make in
......@@ -82,6 +74,19 @@ class YHMakePlanViewController: YHBaseViewController {
requestData()
}
func updataPrice() {
let totalPrice = viewModel.makePlanModel.calculateTotalPrice()
priceView.configure(price: totalPrice, actionText: "去办理") {
YHMakePlanPriceAlertView.show(dataSource: self.viewModel.makePlanModel) { _ in
}
} nextHandler: {
YHMakePlanPriceAlertView.show(dataSource: self.viewModel.makePlanModel) { _ in
}
}
}
func addRightItems() {
let rightButtonItem = UIBarButtonItem(image: UIImage(named: "share_item")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(share))
gk_navRightBarButtonItem = rightButtonItem
......@@ -96,6 +101,14 @@ class YHMakePlanViewController: YHBaseViewController {
viewModel.getProductList {[weak self] _, _ in
guard let self = self else { return }
tableView.reloadData()
getScore()
}
}
func getScore() {
viewModel.getRate(model: viewModel.makePlanModel) {[weak self] _, _ in
guard let self = self else { return }
}
}
......@@ -126,6 +139,10 @@ extension YHMakePlanViewController: UITableViewDelegate, UITableViewDataSource {
dataSource = viewModel.makePlanModel.invest
}
cell.dataSource = dataSource
cell.actionHandler = { product in
self.viewModel.makePlanModel.toggleAddCartStatus(for: product)
self.updataPrice()
}
return cell
}
......
......@@ -14,6 +14,14 @@ struct YHMakePlanModel: SmartCodable {
var work: [YHMakePlanMainModel] = []
var live: [YHMakePlanMainModel] = []
var invest: [YHMakePlanMainModel] = []
// 修改所有子元素的 is_add_cart 值
mutating func updateAddCartStatus() {
basic = basic.map { $0.updatedModel() }
work = work.map { $0.updatedModel() }
live = live.map { $0.updatedModel() }
invest = invest.map { $0.updatedModel() }
}
}
struct YHMakePlanMainModel: SmartCodable {
......@@ -24,6 +32,29 @@ struct YHMakePlanMainModel: SmartCodable {
var price: String = ""
var is_add_cart: Bool = true
var sub_product: [YHMakePlanSubModel] = []
// 更新当前模型及其子模型的 is_add_cart 状态
func updatedModel() -> YHMakePlanMainModel {
var updatedModel = self
updatedModel.is_add_cart = true
// 处理子产品,找到最便宜的一个
if !sub_product.isEmpty {
// 找到最便宜的子产品
let cheapestSubProduct = sub_product
.sorted { ($0.price.toDouble() ?? 0) < ($1.price.toDouble() ?? 0) }
.first
// 更新所有子产品的 is_add_cart 状态
updatedModel.sub_product = sub_product.map {
var sub = $0
sub.is_add_cart = ($0.product_id == cheapestSubProduct?.product_id)
return sub
}
}
return updatedModel
}
}
struct YHMakePlanSubModel: SmartCodable {
......@@ -34,3 +65,127 @@ struct YHMakePlanSubModel: SmartCodable {
var price: String = ""
var is_add_cart: Bool = true
}
// 扩展 String 用于价格转换
extension String {
func toDouble() -> Double? {
// 移除可能存在的货币符号、千位分隔符等
let numericString = self
.replacingOccurrences(of: "$", with: "")
.replacingOccurrences(of: ",", with: "")
.trimmingCharacters(in: .whitespacesAndNewlines)
return Double(numericString)
}
}
extension YHMakePlanModel {
mutating func toggleAddCartStatus(for productId: Int) {
// Search and toggle in basic array
for i in 0..<basic.count {
if basic[i].product_id == productId {
basic[i].is_add_cart = !basic[i].is_add_cart
// If enabling, set all sub products to false except the first one
if basic[i].is_add_cart {
for j in 0..<basic[i].sub_product.count {
basic[i].sub_product[j].is_add_cart = (j == 0)
}
}
return
} else {
// Search in sub products
for j in 0..<basic[i].sub_product.count {
if basic[i].sub_product[j].product_id == productId {
basic[i].sub_product[j].is_add_cart = !basic[i].sub_product[j].is_add_cart
// When a sub product is selected, set its parent to true
if basic[i].sub_product[j].is_add_cart {
basic[i].is_add_cart = true
}
return
}
}
}
}
// Repeat the same logic for work, live, and invest arrays
toggleInArray(&work, productId: productId)
toggleInArray(&live, productId: productId)
toggleInArray(&invest, productId: productId)
}
private func toggleInArray(_ array: inout [YHMakePlanMainModel], productId: Int) {
for i in 0..<array.count {
if array[i].product_id == productId {
array[i].is_add_cart = !array[i].is_add_cart
// If enabling, set all sub products to false except the first one
if array[i].is_add_cart {
for j in 0..<array[i].sub_product.count {
array[i].sub_product[j].is_add_cart = (j == 0)
}
}
return
} else {
// Search in sub products
for j in 0..<array[i].sub_product.count {
if array[i].sub_product[j].product_id == productId {
array[i].sub_product[j].is_add_cart = !array[i].sub_product[j].is_add_cart
// When a sub product is selected, set its parent to true
if array[i].sub_product[j].is_add_cart {
array[i].is_add_cart = true
}
return
}
}
}
}
}
func calculateTotalPrice() -> String {
let allCategories = [basic, work, live, invest]
var total: Double = 0
for category in allCategories {
for mainModel in category {
// Check main product
if mainModel.is_add_cart, let price = Double(mainModel.price) {
total += price
}
// Check sub products
for subModel in mainModel.sub_product {
if subModel.is_add_cart, let price = Double(subModel.price) {
total += price
}
}
}
}
return "\(total)"
}
}
extension YHMakePlanMainModel {
/// Returns a filtered version of the model, keeping only `is_add_cart == true` for itself and its sub-products.
func filteredByCartStatus() -> YHMakePlanMainModel? {
guard is_add_cart else { return nil }
var filteredModel = self
filteredModel.sub_product = sub_product.filter { $0.is_add_cart }
return filteredModel
}
}
extension Array where Element == YHMakePlanMainModel {
/// Filters out models where `is_add_cart == false` and also filters their sub-products.
func filteredByCartStatus() -> [YHMakePlanMainModel] {
self.compactMap { $0.filteredByCartStatus() }
}
}
extension Array where Element == YHMakePlanSubModel {
/// Filters out sub-models where `is_add_cart == false`.
func filteredByCartStatus() -> [YHMakePlanSubModel] {
self.filter { $0.is_add_cart }
}
}
//
// YHMakePlanScoreModel.swift
// galaxy
//
// Created by EDY on 2025/4/2.
// Copyright © 2025 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
import SmartCodable
struct YHMakePlanScoreModel: SmartCodable {
var year: Int = -1
var pass_rate: String = ""
var url: String = ""
}
......@@ -33,6 +33,7 @@ class YHMakePlanBottomView: UIView {
button.titleLabel?.font = UIFont.PFSC_M(ofSize: 16)
button.layer.cornerRadius = 2
button.backgroundColor = UIColor.mainTextColor
button.addTarget(self, action: #selector(nextAction), for: .touchUpInside)
return button
}()
......@@ -47,7 +48,8 @@ class YHMakePlanBottomView: UIView {
}
var actionHandler: (() -> Void)?
var nextHandler: (() -> Void)?
// MARK: - Initialization
override init(frame: CGRect) {
......@@ -96,13 +98,17 @@ class YHMakePlanBottomView: UIView {
actionHandler?()
}
@objc private func nextAction() {
nextHandler?()
}
// MARK: - Configuration
func configure(price: String, actionText: String? = nil, actionHandler: (() -> Void)? = nil) {
func configure(price: String, actionText: String? = nil, actionHandler: (() -> Void)? = nil, nextHandler: (() -> Void)? = nil) {
self.price = price
if let actionText = actionText {
actionButton.setTitle(actionText, for: .normal)
}
self.actionHandler = actionHandler
self.nextHandler = nextHandler
}
}
......@@ -10,8 +10,10 @@ import UIKit
import AttributedString
class YHMakePlanCardView: UIView {
var actionHandler: ((Int) -> Void)?
// MARK: - UI Elements
var data: YHMakePlanMainModel?
private lazy var containerView: UIView = {
let view = UIView()
......@@ -45,7 +47,7 @@ class YHMakePlanCardView: UIView {
let button = YHImageTextButton(title: "星企航(7年)", image: UIImage(named: "make_plan_down"))
button.layer.cornerRadius = 2
button.backgroundColor = UIColor(hex: 0xf5f6f8)
// button.addTarget(self, action: #selector(handleAction), for: .touchUpInside)
button.addTarget(self, action: #selector(selectAction), for: .touchUpInside)
return button
}()
......@@ -62,7 +64,7 @@ class YHMakePlanCardView: UIView {
button.setImage(UIImage(named: "make_plan_select"), for: .selected)
button.setImage(UIImage(named: "make_plan_normal"), for: .normal)
// button.addTarget(self, action: #selector(handleAction), for: .touchUpInside)
button.addTarget(self, action: #selector(handleAction), for: .touchUpInside)
return button
}()
......@@ -134,15 +136,42 @@ class YHMakePlanCardView: UIView {
}
@objc func selectAction() {
YHMakePlanSelectAlertView.show(dataSource: data ?? YHMakePlanMainModel()) { tag in
self.actionHandler?(tag)
self.selectButton.isSelected = true
let count = self.data?.sub_product.count ?? 0
for i in 0 ..< count {
if tag == self.data?.sub_product[i].product_id {
self.data?.sub_product[i].is_add_cart = true
}
}
self.configure(with: self.data ?? YHMakePlanMainModel())
}
}
@objc func handleAction() {
selectButton.isSelected = !selectButton.isSelected
self.actionHandler?(self.data?.product_id ?? 0)
}
// MARK: - Configuration
func configure(with data: YHMakePlanMainModel) {
self.data = data
titleLabel.text = data.product_name
subtitleLabel.text = data.product_desc
priceTagView.text = data.price
if data.price == "" {
storeButton.isHidden = false
let subModel = data.sub_product[0]
let count = self.data?.sub_product.count ?? 0
var index = 0
for i in 0 ..< count {
let flag = self.data?.sub_product[i].is_add_cart ?? false
if flag {
index = i
}
}
let subModel = data.sub_product[index]
priceTagView.text = subModel.price
storeButton.setTitle(subModel.product_name, for: .normal)
} else {
......@@ -151,6 +180,25 @@ class YHMakePlanCardView: UIView {
if let url = URL(string: data.cover_img) {
companyImageView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
}
if data.is_add_cart {
selectButton.isSelected = true
} else {
selectButton.isSelected = false
}
storeButton.updateContent()
}
func configureSub(with data: YHMakePlanSubModel) {
titleLabel.text = data.product_name
subtitleLabel.text = data.product_desc
priceTagView.text = data.price
selectButton.isHidden = true
storeButton.isHidden = true
if let url = URL(string: data.cover_img) {
companyImageView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
}
storeButton.updateContent()
}
}
......
......@@ -9,7 +9,7 @@
import UIKit
class YHMakePlanCell: UITableViewCell {
// typealias InformationBlock = (_ model: YHItemModel) -> Void
var actionHandler: ((Int) -> Void)?
var centerView: UIView!
var titleLabel: UILabel!
var mainItemView: UIView!
......@@ -94,6 +94,9 @@ class YHMakePlanCell: UITableViewCell {
}
var h = 121
let itemView = YHMakePlanCardView()
itemView.actionHandler = { product in
self.actionHandler?(product)
}
itemView.configure(with: dataSource?[i] ?? YHMakePlanMainModel())
mainItemView.addSubview(itemView)
itemView.snp.makeConstraints { make in
......
......@@ -25,6 +25,8 @@ class YHMakePlanPriceAlertView: UIView {
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 50
tableView.showsVerticalScrollIndicator = false
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
......@@ -34,9 +36,16 @@ class YHMakePlanPriceAlertView: UIView {
return tableView
}()
static func show(callBack: @escaping ((Int) -> Void)) {
var dataSource: YHMakePlanModel = YHMakePlanModel() {
didSet {
tableView.reloadData()
}
}
static func show(dataSource: YHMakePlanModel, callBack: @escaping ((Int) -> Void)) {
let view = YHMakePlanPriceAlertView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight))
view.block = callBack
view.dataSource = dataSource
let window = UIApplication.shared.yhKeyWindow()
window?.addSubview(view)
}
......@@ -118,10 +127,10 @@ class YHMakePlanPriceAlertView: UIView {
make.height.equalTo(98)
}
// Configure with data
priceView.configure(price: "489800") {
print("Action button tapped!")
// Handle the "去办理" action here
priceView.configure(price: "489800", actionText: "去办理") {
self.dismiss()
} nextHandler: {
self.block?(1)
}
centerView.addSubview(tableView)
......@@ -174,12 +183,22 @@ extension YHMakePlanPriceAlertView: UITableViewDelegate, UITableViewDataSource {
guard let cell = tableView.dequeueReusableCell(withClass: YHMakePlanLabelCell.self) as? YHMakePlanLabelCell else {
return UITableViewCell()
}
// cell.dataSource = [CompanyPackageData(title: "香港身份申请至永居删除", subtitle: "香港高才入境计划申请到永居全流程", companyName: "", priceTag: "", price: "¥20000.00", showCheckmark: true)]
var data: [YHMakePlanMainModel] = []
if indexPath.row == 0 {
data = dataSource.basic
} else if indexPath.row == 1 {
data = dataSource.work
} else if indexPath.row == 2 {
data = dataSource.live
} else if indexPath.row == 3 {
data = dataSource.invest
}
cell.dataSource = data
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 96
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
......@@ -293,40 +312,50 @@ class YHMakePlanLabelCell: UITableViewCell {
func updateAllViews() {
titleLabel.text = "基础身份续签"
mainItemView.removeSubviews()
var y = 0
for i in 0 ..< (dataSource?.count ?? 0) {
y += 12
var h = 20
let titleLabel = {
let label = UILabel()
label.font = UIFont.PFSC_M(ofSize: 14)
label.textColor = UIColor.mainTextColor
label.text = "香港身份申请至永居"
return label
}()
let filteredModel = dataSource?.filteredByCartStatus() ?? []
var lastView: UIView?
for (i, model) in filteredModel.enumerated() {
let titleLabel = UILabel()
titleLabel.font = UIFont.PFSC_M(ofSize: 14)
titleLabel.textColor = UIColor.mainTextColor
titleLabel.text = model.product_name
titleLabel.numberOfLines = 0
mainItemView.addSubview(titleLabel)
let price = model.sub_product.first?.price ?? model.price
let valueLabel = UILabel()
valueLabel.font = UIFont.PFSC_M(ofSize: 14)
valueLabel.textColor = UIColor.mainTextColor
valueLabel.textAlignment = .right
valueLabel.text = price
mainItemView.addSubview(valueLabel)
titleLabel.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(y)
make.height.equalTo(h)
make.left.equalToSuperview()
make.right.equalTo(valueLabel.snp.left).offset(-8)
if let lastView = lastView {
make.top.equalTo(lastView.snp.bottom).offset(12)
} else {
make.top.equalToSuperview().offset(12)
}
}
let valueLabel = {
let label = UILabel()
label.font = UIFont.PFSC_M(ofSize: 14)
label.textColor = UIColor.mainTextColor
label.textAlignment = .right
label.text = "¥58999"
return label
}()
mainItemView.addSubview(valueLabel)
valueLabel.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(y)
make.height.equalTo(h)
make.right.equalToSuperview()
make.width.equalTo(100)
make.top.equalTo(titleLabel)
}
y += h
lastView = titleLabel
// 如果是最后一个元素,连接到底部
if i == filteredModel.count - 1 {
titleLabel.snp.makeConstraints { make in
make.bottom.equalToSuperview().offset(-12)
}
}
}
}
}
......@@ -18,6 +18,12 @@ class YHMakePlanSelectAlertView: UIView {
var hasSelectLabel: UILabel!
var cardView: YHMakePlanCardView!
var lineView: UIView!
var selectIndex: Int = 0
var dataSource: YHMakePlanMainModel? {
didSet {
updata()
}
}
lazy var tableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
......@@ -39,8 +45,9 @@ class YHMakePlanSelectAlertView: UIView {
return tableView
}()
static func show(callBack: @escaping ((Int) -> Void)) {
static func show(dataSource: YHMakePlanMainModel, callBack: @escaping ((Int) -> Void)) {
let view = YHMakePlanSelectAlertView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: KScreenHeight))
view.dataSource = dataSource
view.block = callBack
let window = UIApplication.shared.yhKeyWindow()
window?.addSubview(view)
......@@ -162,7 +169,7 @@ class YHMakePlanSelectAlertView: UIView {
button.setTitleColor(UIColor(hex: 0xffffff), for: .normal)
button.setTitle("确认", for: .normal)
button.layer.cornerRadius = 4
button.addTarget(self, action: #selector(dismiss), for: .touchUpInside)
button.addTarget(self, action: #selector(orderButtonClick), for: .touchUpInside)
return button
}()
centerView.addSubview(sureButton)
......@@ -181,6 +188,17 @@ class YHMakePlanSelectAlertView: UIView {
}
}
func updata() {
guard let data = dataSource else { return }
for i in 0 ..< data.sub_product.count {
if data.sub_product[i].is_add_cart == true {
selectIndex = i
}
}
cardView.configureSub(with: data.sub_product[selectIndex])
tableView.reloadData()
}
@objc private func handleTap(_ sender: AnyObject?) {
dismiss()
}
......@@ -191,17 +209,11 @@ class YHMakePlanSelectAlertView: UIView {
@objc func orderButtonClick() {
if let block = block {
block(1)
block(dataSource?.sub_product[selectIndex].product_id ?? 0)
}
dismiss()
}
@objc func guideButtonClick() {
if let block = block {
block(2)
}
dismiss()
}
}
extension YHMakePlanSelectAlertView: UIGestureRecognizerDelegate {
......@@ -216,14 +228,15 @@ extension YHMakePlanSelectAlertView: UIGestureRecognizerDelegate {
extension YHMakePlanSelectAlertView: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// return items.count
return 4
return dataSource?.sub_product.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withClass: YHMakePlanCardCell.self) as? YHMakePlanCardCell else {
return UITableViewCell()
}
cell.configure(with: ServiceModel(title: "星企航7年服务", price: 18900))
guard let model = dataSource?.sub_product[indexPath.row] else { return UITableViewCell()}
cell.configure(with: model)
return cell
}
......@@ -232,7 +245,18 @@ extension YHMakePlanSelectAlertView: UITableViewDelegate, UITableViewDataSource
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectIndex = indexPath.row
let count = dataSource?.sub_product.count ?? 0
for i in 0 ..< count {
if i == indexPath.row {
dataSource?.sub_product[i].is_add_cart = true
guard let model = dataSource?.sub_product[i] else { return }
cardView.configureSub(with: model)
} else {
dataSource?.sub_product[i].is_add_cart = false
}
}
tableView.reloadData()
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
......@@ -339,14 +363,16 @@ class YHMakePlanCardCell: UITableViewCell {
}
// MARK: - Configuration
func configure(with service: ServiceModel) {
titleLabel.text = service.title
priceLabel.text = "¥\(service.price)"
func configure(with service: YHMakePlanSubModel) {
titleLabel.text = service.product_name
priceLabel.text = service.price
if service.is_add_cart {
containerView.layer.borderWidth = 1
} else {
containerView.layer.borderWidth = 0
}
if let url = URL(string: service.cover_img) {
bgImageView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
}
}
}
// Example model for configuration
struct ServiceModel {
let title: String
let price: Int
}
......@@ -10,7 +10,7 @@ import UIKit
class YHMakePlanViewModel: YHBaseViewModel {
var makePlanModel: YHMakePlanModel = YHMakePlanModel()
var score: YHMakePlanScoreModel = YHMakePlanScoreModel()
// 请求产品列表
func getProductList(callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.ResignPlan.productListApi
......@@ -23,6 +23,7 @@ class YHMakePlanViewModel: YHBaseViewModel {
return
}
self?.makePlanModel = result
self?.makePlanModel.updateAddCartStatus()
callBackBlock(true, nil)
} else {
let error: YHErrorModel = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.count > 0 ? json.msg : "数据错误")
......@@ -33,4 +34,93 @@ class YHMakePlanViewModel: YHBaseViewModel {
}
}
// 请求产品列表
func getRate(model: YHMakePlanModel, callBackBlock: @escaping (_ success: Bool, _ error: YHErrorModel?) -> Void) {
var basic: [Int] = []
var work: [Int] = []
var live: [Int] = []
var invest: [Int] = []
let basicArray = makePlanModel.basic
let workArray = makePlanModel.work
let liveArray = makePlanModel.live
let investArray = makePlanModel.invest
for item in basicArray {
if item.is_add_cart == true {
if item.sub_product.count > 0 {
for subItem in item.sub_product {
if subItem.is_add_cart == true {
basic.append(subItem.product_id)
}
}
} else {
basic.append(item.product_id)
}
}
}
for item in workArray {
if item.is_add_cart == true {
if item.sub_product.count > 0 {
for subItem in item.sub_product {
if subItem.is_add_cart == true {
work.append(subItem.product_id)
}
}
} else {
work.append(item.product_id)
}
}
}
for item in liveArray {
if item.is_add_cart == true {
if item.sub_product.count > 0 {
for subItem in item.sub_product {
if subItem.is_add_cart == true {
live.append(subItem.product_id)
}
}
} else {
live.append(item.product_id)
}
}
}
for item in investArray {
if item.is_add_cart == true {
if item.sub_product.count > 0 {
for subItem in item.sub_product {
if subItem.is_add_cart == true {
invest.append(subItem.product_id)
}
}
} else {
invest.append(item.product_id)
}
}
}
var params: [String: Any] = ["work_product_ids": work,
"live_product_ids": live,
"invest_product_ids": invest,
"basic_product_ids": basic]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.ResignPlan.getRate
_ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, _ in
// 1. json字符串 转 对象
guard self != nil else { return }
if json.code == 200 {
guard let dic = json.data?.peel as? [String: Any], let result = YHMakePlanScoreModel.deserialize(from: dic) else {
callBackBlock(false, nil)
return
}
self?.score = result
callBackBlock(true, nil)
} else {
let error: YHErrorModel = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.count > 0 ? json.msg : "数据错误")
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
}
......@@ -756,6 +756,7 @@ class YHAllApiName {
struct ResignPlan {
static let planlistApi = "super-app/renewal/advice/get-renewal-plan"
static let productListApi = "super-app/renewal/advice/get-renewal-product-list"
static let getRate = "super-app/renewal/advice/get-year-and-pass-rate"
}
// 问卷
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment