//
//  YHTravelDocsPreparationViewModel.swift
//  galaxy
//
//  Created by davidhuangA on 2024/8/26.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHTravelDocsPreparationViewModel: YHBaseViewModel {
    //列表信息
    var arrTravelDocs : [YHTravelDocsPreparationListModel?] = []
    
}

extension YHTravelDocsPreparationViewModel {
    
    //获取上传列表
    func getTravelDocsList(param : [String:Any],callBackBlock:@escaping (_ success: Bool,_ err:YHErrorModel?)->()) {
        let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.TravelDocsPreparation.getTravelDocsListApi
        let _ = YHNetRequest.getRequest(url: strUrl,params:param) { [weak self] json, code in
            //1. json字符串 转 对象
            guard let self = self else { return }
            printLog("model 是 ==> \(json)")
            
            if json.code == 200 {
                let dic = json.data
                guard let list = [YHTravelDocsPreparationListModel].deserialize(array: dic as? [Any]) else {
                    let err = YHErrorModel(errorCode: YHErrorCode.dictParseError.rawValue, errorMsg: YHErrorCode.dictParseError.description())
                    self.arrTravelDocs = []
                    callBackBlock(false, err)
                    return
                }
                self.arrTravelDocs = list
                callBackBlock(true, nil)
                
            } else {
                let err = YHErrorModel(errorCode: Int32(json.code), errorMsg: json.msg.isEmpty ? "" : json.msg)
                callBackBlock(false,err)
            }
        } failBlock: { err in
            callBackBlock(false,err)
        }
    }
}
