// // ShoppingCarViewModel.swift // ADHTuanCan // // Created by 敖德亨 on 2023/10/30. // import UIKit import RxCocoa import RxSwift class ShoppingCarViewModel: MCBaseViewModel { //MARK: - 获取时间范围 var HomeTimeGetModel : HomeGetTimeRangRequestModel = HomeGetTimeRangRequestModel.init() var TimeRangDetail : HomeTimeRangModel? var HomeTimeRequset : MCDataRequest? func signalGetHomeTime() -> Observable? { if let _ = HomeTimeRequset{ return nil } return Observable.create {(disposable) -> Disposable in self.HomeTimeRequset = MCHttpUtil.request(self.HomeTimeGetModel, responseClass: HomeTimeRangModel.self, success: {[unowned self] (data) in self.TimeRangDetail = data.data self.HomeTimeRequset = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.HomeTimeRequset = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 获取购物车详情 var getShoppingCarMsgResultMeal : GetShoppingCarMsgResultMeal = GetShoppingCarMsgResultMeal.init() var ShopCarAllModelList : [ShopMealMsgModel]? var getShopCarResult : MCDataRequest? func signalgetShoppingCarMsg() -> Observable? { if let _ = getShopCarResult{ return nil } return Observable.create {(disposable) -> Disposable in self.getShopCarResult = MCHttpUtil.request(self.getShoppingCarMsgResultMeal, responseClass: Array.self, success: {[unowned self] (data) in self.ShopCarAllModelList = [] self.ShopCarAllModelList?.append(contentsOf: data.data ?? []) self.getShopCarResult = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getShopCarResult = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 获取购物车价格 var getShopCarPriceRModel : GetShoppingCarPriceRequestModel = GetShoppingCarPriceRequestModel.init() var shopCarPriceDetail : ShopCarPriceDetailModel? var getShopCarRequset : MCDataRequest? func signalGetShopCarPrice() -> Observable? { if let _ = getShopCarRequset{ return nil } return Observable.create {(disposable) -> Disposable in self.getShopCarRequset = MCHttpUtil.request(self.getShopCarPriceRModel, responseClass: ShopCarPriceDetailModel.self, success: {[unowned self] (data) in self.shopCarPriceDetail = data.data self.getShopCarRequset = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getShopCarRequset = 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: - 修改套餐 var editShoppingCarRequestModel : EditorShoppingCarRequestModel = EditorShoppingCarRequestModel.init() var editShoppingCarRequest : MCDataRequest? /// 修改套餐 /// - Returns: <#description#> func signalEditShopCar() -> Observable? { if let _ = editShoppingCarRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.editShoppingCarRequest = MCHttpUtil.request(self.editShoppingCarRequestModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in self.editShoppingCarRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.editShoppingCarRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 清空购物车 /// 清空购物车Model var cleanShopcarModel : CleanShopcarModel = CleanShopcarModel.init() var cleanShopcarRequest : MCDataRequest? /// 清空购物车Model /// - Returns: <#description#> func signalCleanShopCar() -> Observable? { if let _ = cleanShopcarRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.cleanShopcarRequest = MCHttpUtil.request(self.cleanShopcarModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in self.cleanShopcarRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.cleanShopcarRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 获取默认地址 var getDefualAddressModel : GetDefAddressRequestModel = GetDefAddressRequestModel.init() var defualAddressModel : AddressModel? var getDefualAddRequest : MCDataRequest? /// 获取默认地址 /// - Returns: <#description#> func signalGetDefualAdd() -> Observable? { if let _ = getDefualAddRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.editShoppingCarRequest = MCHttpUtil.request(self.getDefualAddressModel, responseClass: AddressModel.self, success: {[unowned self] (data) in self.defualAddressModel = data.data self.getDefualAddRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getDefualAddRequest = nil disposable.onError(error) }) return Disposables.create() } } /// 结算方式 var paySetModel : PaySettleTypeModel? /// 支付方式Model var payMentModel : PayMentTypeModel? //MARK: - 生成订单 var addOrderModel : AddOrderModel = AddOrderModel.init() var orderIdModel : OrderIDmModel? var addOrderRequest : MCDataRequest? /// 生成订单 /// - Returns: <#description#> func signalAddOrderRequest() -> Observable? { if let _ = addOrderRequest{ return nil } self.addOrderModel.settleId = self.paySetModel?.id self.addOrderModel.payTypeId = self.payMentModel?.id return Observable.create {(disposable) -> Disposable in self.addOrderRequest = MCHttpUtil.request(self.addOrderModel, responseClass: OrderIDmModel.self, success: {[unowned self] (data) in self.orderIdModel = data.data disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.addOrderRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 配置支付信息 var getPayConfigurationModel : GetPayConfiguration = GetPayConfiguration.init() var payConfiguration : PayConfigurationModel? var getPayConfigurationRequest : MCDataRequest? /// 配置支付信息 /// - Returns: <#description#> func signalGetPayConfiguration() -> Observable? { if let _ = getPayConfigurationRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.getPayConfigurationRequest = MCHttpUtil.request(self.getPayConfigurationModel, responseClass: PayConfigurationModel.self, success: {[unowned self] (data) in self.payConfiguration = data.data self.getPayConfigurationRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getPayConfigurationRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 根据支付方式获取价格 var getPriceWithTypeModel : GetPriceWithTypeModel = GetPriceWithTypeModel.init() var priceWithTypeModel : PriceWithTypeModel? var getPriceWithTypeRequest : MCDataRequest? /// 根据支付方式获取价格 /// - Returns: <#description#> func signalGetPriceWithTypeRequest() -> Observable? { self.getPriceWithTypeModel.settleId = self.paySetModel?.id if let _ = getPriceWithTypeRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.getPriceWithTypeRequest = MCHttpUtil.request(self.getPriceWithTypeModel, responseClass: PriceWithTypeModel.self, success: {[unowned self] (data) in self.priceWithTypeModel = data.data self.getPriceWithTypeRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getPriceWithTypeRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 获取结算方式 var getPaySettleTypeModel : GetPaySettleTypeModel = GetPaySettleTypeModel.init() /// 结算方式列表 var paySettleList : [PaySettleTypeModel]? var getPaySettleRequest : MCDataRequest? /// 获取结算方式 /// - Returns: <#description#> func signalGetPaySettleType() -> Observable? { if let _ = getPaySettleRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.getPaySettleRequest = MCHttpUtil.request(self.getPaySettleTypeModel, responseClass: Array.self, success: {[unowned self] (data) in self.paySettleList = [] self.paySettleList?.append(contentsOf: data.data ?? []) self.getPaySettleRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getPaySettleRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 获取支付方式 var getPayPayMentTypeModel : GetPayPaymentTypeModel = GetPayPaymentTypeModel.init() /// 结算方式列表 var payMentList : [PayMentTypeModel]? var getPayMentRequest : MCDataRequest? /// 获取支付方式 /// - Returns: <#description#> func signalGetPayMentType() -> Observable? { if let _ = getPayMentRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.getPayMentRequest = MCHttpUtil.request(self.getPayPayMentTypeModel, responseClass: Array.self, success: {[unowned self] (data) in self.payMentList = [] self.payMentList?.append(contentsOf: data.data ?? []) self.getPayMentRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getPayMentRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 获取是否密码支付or StripePay var getIsStripePayModel : GetIsStripePayModel = GetIsStripePayModel.init() /// 拉起支付密码支付 var isStripePayModel : IsStripePayModel? var getIsStripePayRequest : MCDataRequest? /// 获取是否密码支付or StripePay /// - Returns: <#description#> func signalGetIsStripePayRequest() -> Observable? { if let _ = getIsStripePayRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.getIsStripePayRequest = MCHttpUtil.request(self.getIsStripePayModel, responseClass: IsStripePayModel.self, success: {[unowned self] (data) in self.isStripePayModel = data.data self.getIsStripePayRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getIsStripePayRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 密码支付 var pswPayModel : PSWPayRequestModel = PSWPayRequestModel.init() var pswPayRequest : MCDataRequest? /// 密码支付 /// - Returns: <#description#> func signalPSWPay() -> Observable? { if let _ = pswPayRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.pswPayRequest = MCHttpUtil.request(self.pswPayModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in self.pswPayRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.pswPayRequest = nil disposable.onError(error) }) return Disposables.create() } } }