123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //
- // SetMealViewModel.swift
- // ADHTuanCan
- //
- // Created by 敖德亨 on 2023/10/26.
- //
- import UIKit
- import RxCocoa
- import RxSwift
- class SetMealViewModel: MCBaseViewModel {
- //MARK: - 获取套餐详情
- var getSMDetailRequestModel : GetSetMealDetailRequestModel = GetSetMealDetailRequestModel.init()
- var SMDetailModel : SetMealDetailModel?//详情数据
- var GetSMDRequest : MCDataRequest?
-
- /// 获取套餐详情
- /// - Returns: <#description#>
- func signalGetSetMealDetail() -> Observable<Int>? {
-
- if let _ = GetSMDRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.GetSMDRequest = MCHttpUtil.request(self.getSMDetailRequestModel, responseClass: SetMealDetailModel.self, success: {[unowned self] (data) in
- self.SMDetailModel = data.data
- self.GetSMDRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.GetSMDRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
-
- //MARK: - 获取配送时段
- var getTimeRequestModel : GetDeliveryTimeRequestModel = GetDeliveryTimeRequestModel.init()
- var deliveryTimeList : [DeliveryTimeModel]?//详情数据
- var getDeliveryTimeRequest : MCDataRequest?
-
- /// 获取配送时段
- /// - Returns: <#description#>
- func signalGetDeliveryTime() -> Observable<Int>? {
-
- if let _ = getDeliveryTimeRequest{
- return nil
- }
-
- return Observable.create {(disposable) -> Disposable in
- self.getDeliveryTimeRequest = MCHttpUtil.request(self.getTimeRequestModel, responseClass: Array<DeliveryTimeModel>.self, success: {[unowned self] (data) in
- self.deliveryTimeList = []
- self.deliveryTimeList?.append(contentsOf: data.data ?? [])
- self.getDeliveryTimeRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getDeliveryTimeRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
-
- //MARK: - 加入购物车
- let addShoppingRequestModel : AddToshoppingCartModel = AddToshoppingCartModel.init()
- var addShoppingRequest : MCDataRequest?
-
- /// 加入购物车
- /// - Returns: <#description#>
- func signalAddShopping() -> Observable<Int>? {
-
- if let _ = addShoppingRequest{
- return nil
- }
- return Observable.create {(disposable) -> Disposable in
- self.addShoppingRequest = MCHttpUtil.request(self.addShoppingRequestModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in
-
- self.addShoppingRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.addShoppingRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
-
-
- //MARK: - 获取可替换菜品
- let getReplaceFoodRequestModel : GetReplaceFoodRequestModel = GetReplaceFoodRequestModel.init()
- var replaceFoodModels : [MealFoodMsgModel]?//详情数据
- var getReplaceFoodRequest : MCDataRequest?
-
- /// 加入购物车
- /// - Returns: <#description#>
- func signalGetReplaceFood() -> Observable<Int>? {
-
- if let _ = getReplaceFoodRequest{
- return nil
- }
- return Observable.create {(disposable) -> Disposable in
- self.getReplaceFoodRequest = MCHttpUtil.request(self.getReplaceFoodRequestModel, responseClass: Array<MealFoodMsgModel>.self, success: {[unowned self] (data) in
- self.replaceFoodModels = []
- self.replaceFoodModels?.append(contentsOf: data.data ?? [])
- self.getReplaceFoodRequest = nil
- disposable.onNext(data.responseData?.count ?? 0)
- disposable.onCompleted()
- }, error: {[weak self] (error) in
- self?.getReplaceFoodRequest = nil
- disposable.onError(error)
- })
- return Disposables.create()
- }
- }
- }
|