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

发送到邮箱逻辑添加

parent f9c2ba62
......@@ -8,6 +8,7 @@
import UIKit
import SafariServices
import IQKeyboardManagerSwift
class YHMyDocumentsDetailViewController: YHBaseViewController {
......@@ -20,6 +21,20 @@ class YHMyDocumentsDetailViewController: YHBaseViewController {
var id: Int = 0
var oldUrl: String?
lazy var blackMaskView: UIView = {
let view = UIView(frame:UIScreen.main.bounds)
view.backgroundColor = UIColor(hex: 0x0F1214, alpha: 0.5)
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissed))
view.addGestureRecognizer(tap)
view.isHidden = true
return view
}()
lazy var emailInputView: YHEmailInputAlertView = {
let view = YHEmailInputAlertView.emailInputView(defalutText: "请输入邮箱")
return view
}()
lazy var previewFileTool:YHFilePreviewTool = {
let tool = YHFilePreviewTool(targetVC: self)
return tool
......@@ -77,6 +92,7 @@ class YHMyDocumentsDetailViewController: YHBaseViewController {
}
func setView() {
addKeyBoardNotify()
view.backgroundColor = .contentBkgColor
stepView = {
let step = YHStepView()
......@@ -143,10 +159,47 @@ class YHMyDocumentsDetailViewController: YHBaseViewController {
make.left.equalTo(16)
}
view.addSubview(blackMaskView)
view.addSubview(emailInputView)
emailInputView.snp.makeConstraints { make in
make.left.right.equalTo(view)
make.height.equalTo(YHEmailInputAlertView.height)
make.bottom.equalToSuperview().offset(YHEmailInputAlertView.height)
}
emailInputView.editBlock = {
[weak self] text in
guard let self = self else { return }
if let text = text {
YHCheckEamilAlertView.show(nil,text, "取消", "确认") {
//进行
//发送接口
if let orderID = UserDefaults.standard.value(forKey: "orderIdForPreview") {
let params = ["order_id":orderID,"ids":[self.id],"email":text]
self.viewModel?.sendEmailForDocs(params, callBackBlock: { success, error in
if success {
YHHUD.flash(message: "发送成功")
} else {
let msg = error?.errorMsg ?? "发送失败"
YHHUD.flash(message: msg)
}
})
} else {
YHHUD.flash(message: "订单ID 为空")
}
}
}
}
bottomButton.layoutIfNeeded()
bottomButton.addYinHeGradualLayer()
}
@objc func dismissed() {
emailInputView.textField.resignFirstResponder()
}
@objc func submit() {
viewModel.requestSignConfirm("\(self.viewModel.mainModel?.writing_document.doc_sign.id ?? 0)") {[weak self] success, error in
guard let self = self else { return }
......@@ -256,6 +309,10 @@ class YHMyDocumentsDetailViewController: YHBaseViewController {
callBack?(false)
}
}
deinit {
removeNotify()
}
}
extension YHMyDocumentsDetailViewController: UITableViewDelegate, UITableViewDataSource {
......@@ -371,10 +428,19 @@ extension YHMyDocumentsDetailViewController: UITableViewDelegate, UITableViewDat
}
if type == .downLoad {
self.viewModel.requestSignatureDownload("\(self.viewModel.mainModel?.writing_document.doc_sign.id ?? 0)") { [weak self] success, error in
//弹窗 选择发送邮箱
let items = [YHCertificateEditItem(type:.sendEmail, title:"发送至邮箱"),
YHCertificateEditItem(type:.cancel, title:"取消")]
YHCertificateEditSheetView.sheetView(items:items) {
[weak self] editType in
guard let self = self else { return }
//获取到下载链接发送到邮箱
}
IQKeyboardManager.shared.enable = false
if editType == .sendEmail {
emailInputView.textField.text = ""
emailInputView.textField.becomeFirstResponder()
}
}.show()
}
}
return cell
......@@ -519,7 +585,7 @@ extension YHMyDocumentsDetailViewController: UITableViewDelegate, UITableViewDat
return 180
} else {
guard let count = self.viewModel.mainModel?.writing_document.doc_sign.doc_return_manual.count else { return CGFloat(221) }
return CGFloat(221 + count * 52)
return CGFloat(221 + count * 71)
}
}
}
......@@ -564,3 +630,39 @@ extension YHMyDocumentsDetailViewController: SFSafariViewControllerDelegate {
print(#function)
}
}
extension YHMyDocumentsDetailViewController {
func addKeyBoardNotify() {
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
func removeNotify() {
NotificationCenter.default.removeObserver(self)
}
@objc func handleKeyboardNotification(_ notification: Notification) {
if notification.userInfo != nil {
guard let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue else {return }
let isKeyboardShow = notification.name == UIResponder.keyboardWillShowNotification
self.blackMaskView.isHidden = !isKeyboardShow
let bottomMargin = (isKeyboardShow ? -keyboardFrame.height : YHFileRenameInputView.height)
if !isKeyboardShow {
IQKeyboardManager.shared.enable = true
}
self.emailInputView.snp.updateConstraints { make in
make.bottom.equalToSuperview().offset(bottomMargin)
}
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
}
}
}
......@@ -141,7 +141,7 @@ class YHDocumentUploadTableViewCell: UITableViewCell {
}
y = y + 1
let data = dataSource.writing_document.doc_sign.doc_return_manual[i]
let h = 51
let h = 70
let itemView = YHDocumentFileItemView()
itemView.index = i
itemView.docType = dataSource.writing_document.doc_sign.doc_type
......
......@@ -253,4 +253,23 @@ class YHMyDocumentsDetailViewModel: YHBaseViewModel {
callBackBlock(false, err)
}
}
func sendEmailForDocs(_ params : [String : Any], callBackBlock:@escaping (_ success: Bool, _ error: YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Signature.sendMail
let _ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else {
callBackBlock(false, nil)
return
}
if json.code == 200 {
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
}
......@@ -39,7 +39,7 @@ class YHMyDocumentsListViewModel: YHBaseViewModel {
//发送邮箱
func sendEmailForDocs(_ params : [String : Any], callBackBlock:@escaping (_ success: Bool, _ error: YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Signature.sendMail
let _ = YHNetRequest.getRequest(url: strUrl, params: params) { [weak self] json, code in
let _ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else {
callBackBlock(false, nil)
......
......@@ -8,6 +8,7 @@
import UIKit
import SafariServices
import IQKeyboardManagerSwift
class YHMySignatureDetailViewController: YHBaseViewController {
var bottomView: UIView!
......@@ -23,6 +24,20 @@ class YHMySignatureDetailViewController: YHBaseViewController {
return tool
}()
lazy var blackMaskView: UIView = {
let view = UIView(frame:UIScreen.main.bounds)
view.backgroundColor = UIColor(hex: 0x0F1214, alpha: 0.5)
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissed))
view.addGestureRecognizer(tap)
view.isHidden = true
return view
}()
lazy var emailInputView: YHEmailInputAlertView = {
let view = YHEmailInputAlertView.emailInputView(defalutText: "请输入邮箱")
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
viewModel = YHMySignatureDetailViewModel()
......@@ -60,6 +75,8 @@ class YHMySignatureDetailViewController: YHBaseViewController {
}
func setView() {
addKeyBoardNotify()
view.backgroundColor = .contentBkgColor
tableView = {
let tableView = UITableView(frame:.zero, style:.grouped)
......@@ -111,11 +128,46 @@ class YHMySignatureDetailViewController: YHBaseViewController {
make.height.equalTo(48)
make.left.equalTo(16)
}
view.addSubview(blackMaskView)
view.addSubview(emailInputView)
emailInputView.snp.makeConstraints { make in
make.left.right.equalTo(view)
make.height.equalTo(YHEmailInputAlertView.height)
make.bottom.equalToSuperview().offset(YHEmailInputAlertView.height)
}
emailInputView.editBlock = {
[weak self] text in
guard let self = self else { return }
if let text = text {
YHCheckEamilAlertView.show(nil,text, "取消", "确认") {
//进行
//发送接口
if let orderID = UserDefaults.standard.value(forKey: "orderIdForPreview") {
let params = ["order_id":orderID,"ids":[self.id],"email":text]
self.viewModel?.sendEmailForDocs(params, callBackBlock: { success, error in
if success {
YHHUD.flash(message: "发送成功")
} else {
let msg = error?.errorMsg ?? "发送失败"
YHHUD.flash(message: msg)
}
})
} else {
YHHUD.flash(message: "订单ID 为空")
}
}
}
}
bottomButton.layoutIfNeeded()
bottomButton.addYinHeGradualLayer()
}
@objc func dismissed() {
emailInputView.textField.resignFirstResponder()
}
@objc func submit() {
viewModel.requestSignConfirm("\(self.id)") {[weak self] success, error in
guard let self = self else { return }
......@@ -213,6 +265,10 @@ class YHMySignatureDetailViewController: YHBaseViewController {
callBack?(false)
}
}
deinit {
removeNotify()
}
}
extension YHMySignatureDetailViewController: UITableViewDelegate, UITableViewDataSource {
......@@ -277,10 +333,19 @@ extension YHMySignatureDetailViewController: UITableViewDelegate, UITableViewDat
}
if type == .downLoad {
self.viewModel.requestSignatureDownload("\(self.id)") { [weak self] success, error in
//弹窗 选择发送邮箱
let items = [YHCertificateEditItem(type:.sendEmail, title:"发送至邮箱"),
YHCertificateEditItem(type:.cancel, title:"取消")]
YHCertificateEditSheetView.sheetView(items:items) {
[weak self] editType in
guard let self = self else { return }
//获取到下载链接发送到邮箱
}
IQKeyboardManager.shared.enable = false
if editType == .sendEmail {
emailInputView.textField.text = ""
emailInputView.textField.becomeFirstResponder()
}
}.show()
}
}
return cell
......@@ -421,7 +486,7 @@ extension YHMySignatureDetailViewController: UITableViewDelegate, UITableViewDat
return 180
} else {
guard let count = self.viewModel.mainModel?.doc_return_manual.count else { return CGFloat(221) }
return CGFloat(221 + count * 52)
return CGFloat(221 + count * 71)
}
}
......@@ -465,3 +530,40 @@ extension YHMySignatureDetailViewController: SFSafariViewControllerDelegate {
print(#function)
}
}
extension YHMySignatureDetailViewController {
func addKeyBoardNotify() {
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleKeyboardNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
func removeNotify() {
NotificationCenter.default.removeObserver(self)
}
@objc func handleKeyboardNotification(_ notification: Notification) {
if notification.userInfo != nil {
guard let keyboardFrame = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as AnyObject).cgRectValue else {return }
let isKeyboardShow = notification.name == UIResponder.keyboardWillShowNotification
self.blackMaskView.isHidden = !isKeyboardShow
let bottomMargin = (isKeyboardShow ? -keyboardFrame.height : YHFileRenameInputView.height)
if !isKeyboardShow {
IQKeyboardManager.shared.enable = true
}
self.emailInputView.snp.updateConstraints { make in
make.bottom.equalToSuperview().offset(bottomMargin)
}
self.view.setNeedsLayout()
self.view.layoutIfNeeded()
}
}
}
......@@ -141,7 +141,7 @@ class YHSignatureUploadTableViewCell: UITableViewCell {
}
y = y + 1
let data = dataSource.doc_return_manual[i]
let h = 51
let h = 70
let itemView = YHDocumentFileItemView()
itemView.index = i
itemView.docType = dataSource.doc_type
......
......@@ -191,4 +191,23 @@ class YHMySignatureDetailViewModel: YHBaseViewModel {
callBackBlock(false, err)
}
}
func sendEmailForDocs(_ params : [String : Any], callBackBlock:@escaping (_ success: Bool, _ error: YHErrorModel?)->()) {
let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Signature.sendMail
let _ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, code in
//1. json字符串 转 对象
guard let self = self else {
callBackBlock(false, nil)
return
}
if json.code == 200 {
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
} failBlock: { err in
callBackBlock(false, err)
}
}
}
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