//
|
// PointsViewModel.swift
|
// OKProject
|
//
|
// Created by Sweet on 2020/12/25.
|
// Copyright © 2020 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
import RxSwift
|
import RxCocoa
|
import HandyJSON
|
class PointsViewModel: NSObject {
|
/// 获取积分列表
|
/// - Returns: <#description#>
|
func getPoinstData(page:Int) -> Observable<Result<[PoinstModel]?,Error>>{
|
return APIManager.shared.provider.rx
|
.request(.integralGoodsData(pageNum: page, size: 20))
|
.mapThenValidate([PoinstModel].self)
|
.catchError { Single.just(.failure($0)) }
|
.asObservable()
|
}
|
|
/// 获取详情
|
/// - Parameter id: <#id description#>
|
/// - Returns: <#description#>
|
func getDetail(id:Int)-> Observable<Result<PoinstModel?,Error>>{
|
return APIManager.shared.provider.rx
|
.request(.queryGoodsInfoUsing(id: id))
|
.mapThenValidate(PoinstModel.self)
|
.catchError { Single.just(.failure($0)) }
|
.asObservable()
|
}
|
|
/// 提交兑换
|
/// - Parameters:
|
/// - consigneeAddress: <#consigneeAddress description#>
|
/// - consigneeName: <#consigneeName description#>
|
/// - consigneePhone: <#consigneePhone description#>
|
/// - goodsId: <#goodsId description#>
|
/// - remark: <#remark description#>
|
/// - Returns: <#description#>
|
func commitChange(consigneeAddress:String,consigneeName:String,consigneePhone:String,goodsId:Int,remark:String)-> Observable<Result<Nothing?,Error>>{
|
return APIManager.shared.provider.rx
|
.request(.changeGoods(consigneeAddress: consigneeAddress, consigneeName: consigneeName, consigneePhone: consigneePhone, goodsId: goodsId, remark: remark))
|
.mapThenValidate(Nothing.self)
|
.catchError { Single.just(.failure($0)) }
|
.asObservable()
|
}
|
}
|
|
class PointsListViewModel: YYRefreshViewModel<PoinstModel> {
|
override func api() -> API! {
|
return .queryConvertHistory(page: currentPage)
|
}
|
}
|