// // 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? { 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? { if let _ = getDeliveryTimeRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.getDeliveryTimeRequest = MCHttpUtil.request(self.getTimeRequestModel, responseClass: Array.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? { 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? { if let _ = getReplaceFoodRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.getReplaceFoodRequest = MCHttpUtil.request(self.getReplaceFoodRequestModel, responseClass: Array.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() } } }