// // OrderViewModel.swift // ADHTuanCan // // Created by 敖德亨 on 2023/11/5. // import UIKit import RxCocoa import RxSwift class OrderViewModel: MCBaseViewModel { var shopType = OrderGeneraType.whiteOrder var orderType = OrderTypeEnumProtocol.willPay //MARK: - 获取订单列表 var getOrderListModel : GetOrderListModel = GetOrderListModel.init() var dataList : [OrderListModel]? var getOrderListRequset : MCDataRequest? func signalGetOrderList(_ isFirstPage: Bool) -> Observable? { if let _ = getOrderListRequset{ return nil } if isFirstPage{ self.getOrderListModel.current = 1 } if self.shopType == .whiteOrder{ self.getOrderListModel.isGeneral = "2" } if self.shopType == .generalOrder{ self.getOrderListModel.isGeneral = "1" } if self.orderType == .willPay{ self.getOrderListModel.status = "1" } if self.orderType == .takeOrdering{ self.getOrderListModel.status = "2" } if self.orderType == .delivery{ self.getOrderListModel.status = "3" } if self.orderType == .finish{ self.getOrderListModel.status = "4" } if self.orderType == .all{ self.getOrderListModel.status = nil } return Observable.create {(disposable) -> Disposable in self.getOrderListRequset = MCHttpUtil.request(self.getOrderListModel, responseClass: Array.self, success: {[unowned self] (data) in if isFirstPage{ self.dataList = [] } self.dataList?.append(contentsOf: data.data ?? []) self.getOrderListModel.current! = self.getOrderListModel.current! + 1 self.getOrderListRequset = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getOrderListRequset = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 获取订单详情 var getOrderDetailModel : GetOrderDetailModel = GetOrderDetailModel.init() var orderOutDataModel : OrderOutDetailModel? var getOrderDetailRequset : MCDataRequest? func signalGetOrderDetail() -> Observable? { if let _ = getOrderDetailRequset{ return nil } return Observable.create {(disposable) -> Disposable in self.getOrderDetailRequset = MCHttpUtil.request(self.getOrderDetailModel, responseClass: OrderOutDetailModel.self, success: {[unowned self] (data) in self.orderOutDataModel = data.data self.getOrderDetailRequset = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getOrderDetailRequset = 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 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 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() } } //MARK: - 取消订单 var cancelOrderModel : CancelOrderModel = CancelOrderModel.init() /// Request var cancelOrderRequest : MCDataRequest? /// 取消订单 /// - Returns: <#description#> func signalCancelOrder() -> Observable? { if let _ = cancelOrderRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.cancelOrderRequest = MCHttpUtil.request(self.cancelOrderModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in self.cancelOrderRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.cancelOrderRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 修改订单地址 var editOrderAddressModel : EditOrderAddressModel = EditOrderAddressModel.init() /// 修改订单地址Request var editOrderAddrRequest : MCDataRequest? /// 修改订单地址 /// - Returns: <#description#> func signalEditOrderAddress() -> Observable? { if let _ = editOrderAddrRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.editOrderAddrRequest = MCHttpUtil.request(self.editOrderAddressModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in self.editOrderAddrRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.editOrderAddrRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 确认收货 /// 确认收货MOdle var confirmReceiptModel : ConfirmReceiptModel = ConfirmReceiptModel.init() /// 确认收货Request var confirmReceiptRequest : MCDataRequest? /// 确认收货MOdle /// - Returns: <#description#> func signalConfirmReceipt() -> Observable? { if let _ = confirmReceiptRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.confirmReceiptRequest = MCHttpUtil.request(self.confirmReceiptModel, responseClass: MCBaseModel.self, success: {[unowned self] (data) in self.confirmReceiptRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.confirmReceiptRequest = nil disposable.onError(error) }) return Disposables.create() } } //MARK: - 获取客服电话 /// 获取客服电话MOdle var getServiceTelModel : GetServiceTelModel = GetServiceTelModel.init() /// 客服电话MOdle var serviceTelModel : ServiceTelModel? /// 获取客服电话Request var getServiceTelRequest : MCDataRequest? /// 获取客服电话 /// - Returns: <#description#> func signalGetServiceTell() -> Observable? { if let _ = getServiceTelRequest{ return nil } return Observable.create {(disposable) -> Disposable in self.getServiceTelRequest = MCHttpUtil.request(self.getServiceTelModel, responseClass: ServiceTelModel.self, success: {[unowned self] (data) in self.serviceTelModel = data.data self.getServiceTelRequest = nil disposable.onNext(data.responseData?.count ?? 0) disposable.onCompleted() }, error: {[weak self] (error) in self?.getServiceTelRequest = nil disposable.onError(error) }) return Disposables.create() } } }