Commit 52e2dd2a authored by David黄金龙's avatar David黄金龙

Merge branch 'develop' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS into develop

* 'develop' of http://gitlab.galaxy-immi.com/mobile-group/galaxy-iOS:
  文书逻辑重新调整,以及接口调试
  续签补件逻辑补充
parents 274e08b7 1f2e9216
......@@ -446,7 +446,6 @@ extension YHServiceOrderListView : UITableViewDelegate,UITableViewDataSource {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let model = self.arrDataForSeviceCenterProgress[indexPath.row]
if model.status == 1 || model.status == 4 {
YHServiceOrderListView.jumpToMessageController(type: model.type, orderId: orderID, stepID)
return
} else {
YHServiceOrderListView.jumpToMessageController(type: model.type, orderId: orderID, stepID)
......
......@@ -63,7 +63,7 @@ class YHFilePreviewTool: NSObject {
}
DispatchQueue.main.async { [weak self] in
guard let self = self, let presentingVC = self.targetVC else {
guard let self = self, self.targetVC != nil else {
printLog("Target view controller is not available")
return
}
......
......@@ -28,6 +28,12 @@ class YHResignDocumentDetailViewController: YHBaseViewController {
case uploadAction(_ uploadName: String, _ isUploadButtonEnable: Bool = false, _ isSureButtonEnable: Bool = false, _ topMargin: CGFloat = 16)
}
enum ActionType {
case upload
case reupload
case delete
}
private var datas: [[RowType]] = []
private lazy var viewModel = YHResignDocumentViewModel()
private var detailModel: YHResignDocumentCompleteModel?
......@@ -37,7 +43,10 @@ class YHResignDocumentDetailViewController: YHBaseViewController {
private let docId: Int
private var name: String
private let uploadMaxCount = 10
private var isEditUploadFiles: Bool = false // 跟踪编辑状态 上传 预览 删除等
private var isEditUploadFilesDidDisappear: Bool = false // 跟踪编辑状态 上传 预览 删除等时是否页面消失
init(_ docId: Int, _ name: String = "") {
self.docId = docId
self.name = name
......@@ -121,7 +130,20 @@ class YHResignDocumentDetailViewController: YHBaseViewController {
super.viewWillAppear(animated)
let needLoading = isNeedShowLoading
isNeedShowLoading = false
requestData(isNeedLoading: needLoading)
if isEditUploadFilesDidDisappear {
isEditUploadFiles = false
isEditUploadFilesDidDisappear = false
} else {
isEditUploadFiles = false
requestData(isNeedLoading: needLoading)
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
if isEditUploadFiles {
isEditUploadFilesDidDisappear = true
}
}
deinit {
......@@ -278,15 +300,32 @@ extension YHResignDocumentDetailViewController: UITableViewDelegate, UITableView
cell.setupCellInfo(title, cellType: cellType)
cell.editButtonClickEvent = { [weak self] in
guard let self = self else { return }
self.isEditUploadFiles = true
let items: [YHCertificateEditItem] = editTypes.map {
YHCertificateEditItem(type: $0, title: $0.editName())
}
YHCertificateEditSheetView.sheetView(items:items) { [weak self] editType in
guard let self = self else { return }
if editType == .reupload {
//
let sheetView = YHDocumentUploadView.sheetView()
sheetView.maxSelectCount = 1
sheetView.uploadFilesBlock = { [weak self] fileUrl in
guard let self = self else { return }
printLog(fileUrl)
self.uploadFile(fileUrl, actionType: .reupload, oldUrl: urlStr)
}
sheetView.uploadImageBlock = { [weak self] imgArr in
guard let self = self else { return }
self.uploadImages(imgArr: imgArr, actionType: .reupload, oldUrl: urlStr)
}
sheetView.show()
} else if editType == .delete { // 删除
//
if let index = self.detailModel?.signedDocument.firstIndex(where: { model in
model.url == urlStr
}) {
self.detailModel?.signedDocument.remove(at: index)
self.updateUploadFilesSection()
}
} else if editType == .preview { // 预览
guard URL(string: urlStr) != nil else {
return
......@@ -314,6 +353,7 @@ extension YHResignDocumentDetailViewController: UITableViewDelegate, UITableView
guard let detailModel = self.detailModel else {
return
}
self.isEditUploadFiles = true
let count = detailModel.signedDocument.count
if count >= 10 {
YHHUD.flash(message: "最多上传10个图片或文件")
......@@ -325,11 +365,11 @@ extension YHResignDocumentDetailViewController: UITableViewDelegate, UITableView
sheetView.uploadFilesBlock = { [weak self] fileUrl in
guard let self = self else { return }
printLog(fileUrl)
self.uploadFile(fileUrl)
self.uploadFile(fileUrl, actionType: .upload, oldUrl: nil)
}
sheetView.uploadImageBlock = { [weak self] imgArr in
guard let self = self else { return }
self.uploadImages(imgArr: imgArr)
self.uploadImages(imgArr: imgArr, actionType: .upload, oldUrl: nil)
}
sheetView.show()
}
......@@ -493,12 +533,24 @@ extension YHResignDocumentDetailViewController {
}
}
private func getFileExtenion(_ fileUrl: String) -> String {
var extenion = ""
if let url = URL(string: fileUrl) {
extenion = "." + url.pathExtension
}
return extenion
}
private func getUploadSection(status: YHResignDocumentStatus, model: YHResignDocumentCompleteModel) -> [RowType] {
var uploadSection: [RowType] = []
if status == .pendingConfirmation {
if status == .pendingConfirmation || status == .awaitingSignature {
uploadSection.append(.uploadHeader("上传已签署件"))
model.signedDocument.forEach {
uploadSection.append(.uploadFile($0.fileName, $0.url, [.preview, .reupload, .delete, .cancel]))
model.signedDocument.enumerated().forEach { [weak self] index, file in
guard let self = self else {
return
}
let extenionName = self.getFileExtenion(file.url)
uploadSection.append(.uploadFile(self.name + "\(index + 1)" + extenionName, file.url, [.preview, .reupload, .delete, .cancel]))
}
var name = "上传已签署件"
var isUploadEnable = true
......@@ -514,14 +566,55 @@ extension YHResignDocumentDetailViewController {
} else {
if model.signedDocument.count > 0 {
uploadSection.append(.uploadHeader("上传已签署件"))
model.signedDocument.forEach {
uploadSection.append(.uploadFile($0.fileName, $0.url, [.preview, .cancel]))
model.signedDocument.enumerated().forEach { [weak self] index, file in
guard let self = self else {
return
}
let extenionName = self.getFileExtenion(file.url)
uploadSection.append(.uploadFile(self.name + "\(index + 1)" + extenionName, file.url, [.preview, .cancel]))
}
}
}
return uploadSection
}
private func updateUploadFilesSection() {
guard let model = detailModel else {
return
}
var uploadSection: [RowType] = []
uploadSection.append(.uploadHeader("上传已签署件"))
model.signedDocument.enumerated().forEach { [weak self] index, file in
guard let self = self else { return }
let extenionName = self.getFileExtenion(file.url)
uploadSection.append(.uploadFile(self.name + "\(index + 1)" + extenionName, file.url, [.preview, .reupload, .delete, .cancel]))
}
var name = "上传已签署件"
var isUploadEnable = true
let totalCount = model.signedDocument.count
let isSureButtonEnable = totalCount > 0
if totalCount >= uploadMaxCount {
name = "继续上传"
isUploadEnable = false
} else if totalCount > 0 {
name = "继续上传"
isUploadEnable = true
}
uploadSection.append(.uploadAction(name, isUploadEnable, isSureButtonEnable, isSureButtonEnable ? 4 : 16))
if let index = datas.firstIndex(where: { sectionArr in
return sectionArr.contains { rowType in
if case.uploadHeader = rowType {
return true
}
return false
}
}) {
datas[index] = uploadSection
}
tableView.reloadData()
}
private func getStatusButtonsConfig(docType: YHResignDocumentType, status: YHResignDocumentStatus, model: YHResignDocumentCompleteModel) -> YHResignDocumentStatusCell.ButtonsConfig {
var config = YHResignDocumentStatusCell.ButtonsConfig()
var actions: [(() -> Void)] = []
......@@ -612,7 +705,7 @@ extension YHResignDocumentDetailViewController {
}
extension YHResignDocumentDetailViewController {
private func uploadFile(_ fileUrl: URL) {
private func uploadFile(_ fileUrl: URL, actionType: ActionType, oldUrl: String?) {
if let fileData = try? Data(contentsOf: fileUrl) {
// 将文件数据上传到服务器
let size = String(format: "%.2fM", Double(fileData.count) / (1024.0 * 1024.0))
......@@ -624,22 +717,21 @@ extension YHResignDocumentDetailViewController {
YHHUD.hide()
// 再调用业务接口
if let successUrl = successUrl, !successUrl.isEmpty {
let uploadModel = YHResignDocumentUploadSignedDocument()
uploadModel.name = fileUrl.lastPathComponent
let uploadModel = YHResignSignedDocumentModel()
uploadModel.url = successUrl
self.viewModel.uploadSignedDoc(self.docId, type: .upload, [uploadModel]) { [weak self] success, error in
guard let self = self else { return }
if success {
YHHUD.flash(message: "上传成功")
} else {
var msg = "上传失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message: msg)
let extenionName = self.getFileExtenion(successUrl)
uploadModel.fileName = self.name + "\((self.detailModel?.signedDocument.count ?? 0) + 1)" + extenionName
if actionType == .upload {
self.detailModel?.signedDocument.append(uploadModel)
} else if actionType == .reupload {
if let index = self.detailModel?.signedDocument.firstIndex(where: {
$0.url == oldUrl && oldUrl != nil
}) {
self.detailModel?.signedDocument[index] = uploadModel
}
self.requestData(isNeedLoading: true)
}
self.updateUploadFilesSection()
return
}
var msg = "上传文件失败"
......@@ -653,19 +745,18 @@ extension YHResignDocumentDetailViewController {
}
}
private func uploadImages(imgArr: [YHSelectImageItem]) {
private func uploadImages(imgArr: [YHSelectImageItem], actionType: ActionType, oldUrl: String?) {
let group = DispatchGroup()
var successArr: [YHResignDocumentUploadSignedDocument] = []
var successArr: [YHResignSignedDocumentModel] = []
var failArr: [YHSelectImageItem] = []
YHHUD.show(.progress(message: "上传中..."))
for item in imgArr {
if let image = item.data {
group.enter()
self.uploadImage(image, imageName: item.name) { success, url in
self.uploadImage(image) { success, url in
if success {
let doc = YHResignDocumentUploadSignedDocument()
doc.name = item.name
let doc = YHResignSignedDocumentModel()
doc.url = url
successArr.append(doc)
} else {
......@@ -686,15 +777,30 @@ extension YHResignDocumentDetailViewController {
} else {
YHHUD.flash(message: "\(successArr.count)张照片上传成功\n\(failArr.count)张照片上传失败")
}
self.viewModel.uploadSignedDoc(self.docId, type: .upload, successArr) { [weak self] success, error in
guard let self = self else { return }
self.requestData(isNeedLoading: true)
if actionType == .upload {
let count = self.detailModel?.signedDocument.count ?? 0
successArr.enumerated().forEach { [weak self] index, file in
guard let self = self else { return }
let extenionName = self.getFileExtenion(file.url)
file.fileName = self.name + "\(count + 1 + index)" + extenionName
}
self.detailModel?.signedDocument.append(contentsOf: successArr)
} else if actionType == .reupload {
if let index = self.detailModel?.signedDocument.firstIndex(where: {
$0.url == oldUrl && oldUrl != nil
}) {
if let file = self.detailModel?.signedDocument[index], let newUrl = successArr.first?.url {
let extenionName = self.getFileExtenion(newUrl)
self.detailModel?.signedDocument[index].url = newUrl
self.detailModel?.signedDocument[index].fileName = self.name + "\(index)" + extenionName
}
}
}
self.updateUploadFilesSection()
}
}
private func uploadImage(_ img: UIImage, imageName: String, callBack: @escaping (Bool, String) -> Void) {
private func uploadImage(_ img: UIImage, callBack: @escaping (Bool, String) -> Void) {
// 先OSS上传得到URL
self.viewModel.uploadImage(img) { [weak self] url, error in
guard self != nil else { return }
......
......@@ -52,6 +52,8 @@ class YHResignUploadDocDetailViewController: YHBaseViewController {
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}
tableView.estimatedSectionHeaderHeight = 0.01
tableView.estimatedSectionFooterHeight = 0.01
tableView.showsVerticalScrollIndicator = false
tableView.backgroundColor = .white
tableView.separatorStyle = .none
......@@ -113,8 +115,21 @@ class YHResignUploadDocDetailViewController: YHBaseViewController {
}
@objc func didClickUploadBtn() {
if self.materialModel.unavailable_reason.count != 0 {
self.viewModel.postUploadDocFillUnavailableReason(id: id, reason: self.materialModel.unavailable_reason) {[weak self] success, err in
guard let self = self else { return }
if success {
self.navigationController?.popViewController(animated: true)
}
}
} else {
self.viewModel.postUploadDocUpload(id: id, file: self.items) { [weak self] success, err in
guard let self = self else { return }
if success {
self.navigationController?.popViewController(animated: true)
}
}
}
}
func createUI() {
......@@ -365,7 +380,7 @@ extension YHResignUploadDocDetailViewController: UITableViewDelegate, UITableVie
let model = YHResignUploadDetailFileListModel()
model.url = item
model.name = "\(UInt64(timestamp))" + ".jpg"
// model.uploadedAt = formattedDate
model.updated_at = formattedDate
self.items.append(model)
}
self.tableView.reloadData()
......@@ -393,10 +408,10 @@ extension YHResignUploadDocDetailViewController: UITableViewDelegate, UITableVie
return 77.0
}
if indexPath.section == 2 {
return 61
return 57
}
if indexPath.section == 3 {
return 45
return 41
}
return 55.0
}
......@@ -408,7 +423,7 @@ extension YHResignUploadDocDetailViewController: UITableViewDelegate, UITableVie
if section == 1 {
return UITableView.automaticDimension
}
return 0.01
return 1
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
......@@ -486,10 +501,7 @@ extension YHResignUploadDocDetailViewController: UITableViewDelegate, UITableVie
if section == 0 {
return UITableView.automaticDimension
}
// if section == 1 {
// return 60.0
// }
return 0.01
return 1
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
......@@ -626,6 +638,7 @@ extension YHResignUploadDocDetailViewController: UITableViewDelegate, UITableVie
}
return view
}
view.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: 0.01)
return view
}
......
......@@ -191,7 +191,7 @@ class YHResignUploadDocItemView: UIView {
addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.left.top.bottom.equalToSuperview()
make.right.equalTo(-50)
make.right.equalTo(-70)
}
explainLabel = {
......
......@@ -39,6 +39,47 @@ extension YHResignUploadDetailViewModel {
}
}
func postUploadDocFillUnavailableReason(id: Int, reason: String, callBackBlock:@escaping (_ success: Bool,_ err:YHErrorModel?)->()) {
let params: [String : Any] = ["id": id, "unavailable_reason": reason]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.ResignUploadDoc.reason
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(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)
}
}
func postUploadDocUpload(id: Int, file: [YHResignUploadDetailFileListModel], callBackBlock:@escaping (_ success: Bool,_ err:YHErrorModel?)->()) {
var urls: [Any] = []
for item in file {
let file = ["name": item.name, "url": item.url, "upload_date": item.updated_at]
urls.append(file)
}
let params: [String : Any] = ["id": id, "file_list": urls]
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.ResignUploadDoc.upload
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(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)
}
}
}
......@@ -598,6 +598,9 @@ class YHAllApiName {
static let progress = "super-app/renewal/supplement/progress"
static let list = "super-app/renewal/supplement/list"
static let detail = "super-app/renewal/supplement/upload/detail"
static let reason = "super-app/renewal/supplement/fill-unavailable-reason"
static let upload = "super-app/renewal/supplement/confirm-upload"
}
// 续签-电子签证缴费
struct ResignVisa {
......
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