SetMealViewModel.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // SetMealViewModel.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/10/26.
  6. //
  7. import UIKit
  8. import RxCocoa
  9. import RxSwift
  10. class SetMealViewModel: MCBaseViewModel {
  11. //MARK: - 获取套餐详情
  12. var getSMDetailRequestModel : GetSetMealDetailRequestModel = GetSetMealDetailRequestModel.init()
  13. var SMDetailModel : SetMealDetailModel?//详情数据
  14. var GetSMDRequest : MCDataRequest?
  15. /// 获取套餐详情
  16. /// - Returns: <#description#>
  17. func signalGetSetMealDetail() -> Observable<Int>? {
  18. if let _ = GetSMDRequest{
  19. return nil
  20. }
  21. return Observable.create {(disposable) -> Disposable in
  22. self.GetSMDRequest = MCHttpUtil.request(self.getSMDetailRequestModel, responseClass: SetMealDetailModel.self, success: {[unowned self] (data) in
  23. self.SMDetailModel = data.data
  24. self.GetSMDRequest = nil
  25. disposable.onNext(data.responseData?.count ?? 0)
  26. disposable.onCompleted()
  27. }, error: {[weak self] (error) in
  28. self?.GetSMDRequest = nil
  29. disposable.onError(error)
  30. })
  31. return Disposables.create()
  32. }
  33. }
  34. //MARK: - 获取配送时段
  35. var getTimeRequestModel : GetDeliveryTimeRequestModel = GetDeliveryTimeRequestModel.init()
  36. var deliveryTimeList : [DeliveryTimeModel]?//详情数据
  37. var getDeliveryTimeRequest : MCDataRequest?
  38. /// 获取配送时段
  39. /// - Returns: <#description#>
  40. func signalGetDeliveryTime() -> Observable<Int>? {
  41. if let _ = getDeliveryTimeRequest{
  42. return nil
  43. }
  44. return Observable.create {(disposable) -> Disposable in
  45. self.getDeliveryTimeRequest = MCHttpUtil.request(self.getTimeRequestModel, responseClass: Array<DeliveryTimeModel>.self, success: {[unowned self] (data) in
  46. self.deliveryTimeList = []
  47. self.deliveryTimeList?.append(contentsOf: data.data ?? [])
  48. self.getDeliveryTimeRequest = nil
  49. disposable.onNext(data.responseData?.count ?? 0)
  50. disposable.onCompleted()
  51. }, error: {[weak self] (error) in
  52. self?.getDeliveryTimeRequest = nil
  53. disposable.onError(error)
  54. })
  55. return Disposables.create()
  56. }
  57. }
  58. //MARK: - 加入购物车
  59. let addShoppingRequestModel : AddToshoppingCartModel = AddToshoppingCartModel.init()
  60. var addShoppingRequest : MCDataRequest?
  61. /// 加入购物车
  62. /// - Returns: <#description#>
  63. func signalAddShopping() -> Observable<Int>? {
  64. if let _ = addShoppingRequest{
  65. return nil
  66. }
  67. return Observable.create {(disposable) -> Disposable in
  68. self.addShoppingRequest = MCHttpUtil.request(self.addShoppingRequestModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
  69. self.addShoppingRequest = nil
  70. disposable.onNext(data.responseData?.count ?? 0)
  71. disposable.onCompleted()
  72. }, error: {[weak self] (error) in
  73. self?.addShoppingRequest = nil
  74. disposable.onError(error)
  75. })
  76. return Disposables.create()
  77. }
  78. }
  79. //MARK: - 获取可替换菜品
  80. let getReplaceFoodRequestModel : GetReplaceFoodRequestModel = GetReplaceFoodRequestModel.init()
  81. var replaceFoodModels : [MealFoodMsgModel]?//详情数据
  82. var getReplaceFoodRequest : MCDataRequest?
  83. /// 加入购物车
  84. /// - Returns: <#description#>
  85. func signalGetReplaceFood() -> Observable<Int>? {
  86. if let _ = getReplaceFoodRequest{
  87. return nil
  88. }
  89. return Observable.create {(disposable) -> Disposable in
  90. self.getReplaceFoodRequest = MCHttpUtil.request(self.getReplaceFoodRequestModel, responseClass: Array<MealFoodMsgModel>.self, success: {[unowned self] (data) in
  91. self.replaceFoodModels = []
  92. self.replaceFoodModels?.append(contentsOf: data.data ?? [])
  93. self.getReplaceFoodRequest = nil
  94. disposable.onNext(data.responseData?.count ?? 0)
  95. disposable.onCompleted()
  96. }, error: {[weak self] (error) in
  97. self?.getReplaceFoodRequest = nil
  98. disposable.onError(error)
  99. })
  100. return Disposables.create()
  101. }
  102. }
  103. }