Commit fd9eb38b authored by pete谢兆麟's avatar pete谢兆麟

上传接口

parent 7872c88c
......@@ -9,7 +9,6 @@
import UIKit
class YHMainApplicantInformationViewController: YHBaseViewController {
var stepView: YHStepView!
var bottomView: YHBottomNextView!
var tableView: UITableView!
......@@ -135,8 +134,12 @@ extension YHMainApplicantInformationViewController: UITableViewDelegate, UITable
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if stepView.currentIndex == 1 {
let cell = tableView.dequeueReusableCell(withClass: YHMainInformationCardTableViewCell.self)
cell.dataSource = dataSource?[indexPath.row]
cell.type = YHCardType(rawValue: indexPath.row)
cell.type = YHCardType(rawValue: indexPath.row) ?? .identity
cell.viewModel = viewModel
cell.informationBlock = {[weak self] type, image, isLeft in
guard let self = self else { return }
}
return cell
} else {
let cell = tableView.dequeueReusableCell(withClass: YHMainInformationTableViewCell.self)
......
......@@ -207,7 +207,10 @@ extension YHImagePickerView: UINavigationControllerDelegate, UIImagePickerContro
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
uploadImage(image: image)
self.dismiss()
if let block = backImage {
block(image)
self.dismiss()
}
} else {
printLog("pick image wrong")
}
......
......@@ -15,7 +15,8 @@ enum YHCardType: Int {
}
class YHMainInformationCardTableViewCell: UITableViewCell {
typealias InformationBlock = (_ type: YHCardType, _ image: UIImage, _ isleft: Bool) -> ()
var informationBlock: InformationBlock?
var centerView: UIView!
var titleLabel: UILabel!
var exampleButton: UIButton!
......@@ -23,9 +24,9 @@ class YHMainInformationCardTableViewCell: UITableViewCell {
var backSurfaceLabel: UILabel!
var frontImageButton: UIButton!
var backSurfaceImageButton: UIButton!
var type: YHCardType? {
var viewModel: YHMainApplicantInformationViewModel!
var type: YHCardType = .identity {
didSet {
guard let type = type else { return }
switch type {
case .identity:
titleLabel.text = "中国身份证(选填)"
......@@ -39,12 +40,7 @@ class YHMainInformationCardTableViewCell: UITableViewCell {
}
}
}
var dataSource: YHSectionItemModel?{
didSet {
updataData()
}
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
......@@ -197,14 +193,40 @@ class YHMainInformationCardTableViewCell: UITableViewCell {
}
@objc func frontImageClick() {
YHImagePickerView.show() { image in
YHImagePickerView.show() {[weak self] image in
guard let self = self else { return }
self.frontImageButton.setBackgroundImage(image, for: .normal)
self.viewModel.uploadImage(image) {[weak self] success, error in
guard let self = self else { return }
guard let url = success else { return }
self.viewModel.updateModel(self.type, isFront: true, url: url)
self.viewModel.getPublicImageUrl(url) {[weak self] success, error in
guard let self = self else { return }
}
}
// if let block = self.informationBlock {
// block(self.type, image, false)
// }
}
}
@objc func backSurfaceImageClick() {
YHImagePickerView.show() { image in
YHImagePickerView.show() {[weak self] image in
guard let self = self else { return }
self.backSurfaceImageButton.setBackgroundImage(image, for: .normal)
self.viewModel.uploadImage(image) {[weak self] success, error in
guard let self = self else { return }
guard let url = success else { return }
self.viewModel.updateModel(self.type, isFront: false, url: url)
self.viewModel.getPublicImageUrl(url) {[weak self] success, error in
guard let self = self else { return }
}
}
// if let block = self.informationBlock {
// block(self.type, image, true)
// }
}
}
......
......@@ -8,6 +8,7 @@
import UIKit
import SmartCodable
import Alamofire
enum YHSaveType: Int {
case save = 0
......@@ -205,9 +206,24 @@ class YHMainApplicantInformationViewModel: YHBaseViewModel {
}
}
func updateModel(_ type: YHCardType, isFront: Bool, url: String) {
switch type {
case .identity:
if isFront {
mainModel.certificates.cn_identity_card.img_front = url
} else {
mainModel.certificates.cn_identity_card.img_back = url
}
case .passport:
if isFront {
mainModel.certificates.hk_macao_pass.img_front = url
} else {
mainModel.certificates.hk_macao_pass.img_back = url
}
}
}
func requestMainInformation(_ orderID: String, callBackBlock:@escaping (_ success: YHMainInformationModel?, _ error:YHErrorModel?)->()) {
// /infoflow/order-information/get_information?order_id=9402
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.OrderInformation.getInformation + "?order_id=\(orderID)"
// let strUrl = "http://192.168.25.48:18088/" + YHAllApiName.OrderInformation.getInformation + "?order_id=\(orderID)"
// let params: [String : Any] = ["order_id": orderID]
......@@ -301,6 +317,78 @@ class YHMainApplicantInformationViewModel: YHBaseViewModel {
}
}
// 上传方法
func uploadImage(_ image: UIImage, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
let strUrl = "https://test-comserver.galaxy-immi.com/oss/upload/storage"
let boundary = UUID().uuidString
let headers: HTTPHeaders = [
"Content-type": "multipart/form-data; boundary=\(boundary)",
"businessCode": "4001001"
]
let _ = YHNetRequest.uplaodRequest(url: strUrl, headers: headers, image: image) { [weak self] json, code in
guard let self = self else { return }
if json.code == 200 {
callBackBlock(json.data as? String, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(nil, error)
}
} failBlock: { err in
callBackBlock(nil, err)
}
}
func getPublicImageUrl(_ url: String, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
let strUrl = "https://test-comserver.galaxy-immi.com/oss/storage/convertToPublicURL" + "?fileUrl=\(url)"
let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else { return }
if json.code == 200 {
callBackBlock(json.data as? String, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(nil, error)
}
} failBlock: { err in
callBackBlock(nil,err)
}
}
func requestCnIDCardMessage(_ url: String, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.OrderInformation.cnIdCard
let params: [String : Any] = ["url": url]
let _ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else { return }
if json.code == 200 {
// callBackBlock(json.data as? String, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(nil, error)
}
} failBlock: { err in
callBackBlock(nil,err)
}
}
func requestHkIDCardMessage(_ url: String, callBackBlock:@escaping (_ success: String?, _ error:YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.OrderInformation.hkIdCard
let params: [String : Any] = ["url": url]
let _ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else { return }
if json.code == 200 {
// callBackBlock(json.data as? String, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(nil, error)
}
} failBlock: { err in
callBackBlock(nil,err)
}
}
func isCanNext(_ step: Int) -> Bool {
if step == 0 {
let nationality = mainModel.nationality
......
......@@ -115,6 +115,10 @@ class YHAllApiName {
static let updateInformation = "infoflow/order-information/update_information"
// 主申请人国家信息
static let countryInformation = "infoflow/country"
// 主申请人中国
static let cnIdCard = "infoflow/order-information/get_id_card"
// 主申请人港澳通行证
static let hkIdCard = "infoflow/order-information/get_hk_macao_pass"
}
struct WorkExperience {
......
......@@ -174,13 +174,13 @@ class YHNetRequest: NSObject {
return httpRequest
}
guard let imageData = image.jpegData(compressionQuality: 1) else { return httpRequest }
var multipartFormData = MultipartFormData()
let multipartFormData = MultipartFormData()
// 将图片添加到multipartFormData中
multipartFormData.append(imageData, withName: "file", fileName: "image.jpg", mimeType: "image/jpeg")
// 发送POST请求
let uploadRequest = AF.upload(multipartFormData: multipartFormData, to: "https://test-comserver.galaxy-immi.com/oss/upload/storage", headers: headers)
let uploadRequest = AF.upload(multipartFormData: multipartFormData, to: self.url!, headers: headers)
uploadRequest.responseString(completionHandler: { string in
#if DEBUG
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment