宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//
//  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)
    }
}