Commit 2c18f7ce authored by David黄金龙's avatar David黄金龙

上传过关证件

parent 1be88d79
......@@ -17,12 +17,23 @@ enum UploadCertificateDetailType : Int {
class YHUploadCertificateDetailVC: YHBaseViewController {
lazy var viewModel: YHUploadCertificateViewModel = {
let vm = YHUploadCertificateViewModel()
return vm
}()
var dataModel : YHUploadCertificateModel = YHUploadCertificateModel() {
didSet {
}
}
var detailType : UploadCertificateDetailType = .SmallWhiteNote
var canEditFlag : Bool = true //已上传状态也可以重新传
lazy var uploadImageVM: YHBaseViewModel = {
let vm = YHBaseViewModel()
return vm
}()
var detailType : UploadCertificateDetailType = .SmallWhiteNote
lazy var topImgView: UIImageView = {
let view = UIImageView(image: UIImage(named: "xbt_tips")) // 343 90
view.layer.cornerRadius = kCornerRadius6
......@@ -30,7 +41,6 @@ class YHUploadCertificateDetailVC: YHBaseViewController {
return view
}()
lazy var whiteContentView: UIView = {
let view = UIView()
view.backgroundColor = .white
......@@ -110,6 +120,11 @@ class YHUploadCertificateDetailVC: YHBaseViewController {
}()
private var startDateStr : String = ""
private var endDateStr : String = ""
private var uploadImageUrl : String = ""
lazy var lineView2 : UIView = {
let view = UIView()
view.backgroundColor = .separatorColor
......@@ -121,18 +136,140 @@ class YHUploadCertificateDetailVC: YHBaseViewController {
return view
}()
lazy var bottomView : YHFileListBottomView = {
let view = YHFileListBottomView()
view.updateBtnTitle(title: "确认,保存")
view.block = { tag in
self.submitInfo()
}
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
loadData()
}
}
// MARK: - 私有方法
private extension YHUploadCertificateDetailVC {
func isAllInfoOK() -> Bool {
if uploadImageUrl.isEmpty {
var txt = ""
if detailType == .SmallWhiteNote {
txt = "上传小白条"
} else {
txt = "上传香港身份证"
}
YHHUD.flash(message: txt)
return false
}
if detailType == .SmallWhiteNote {
if startDateStr.isEmpty {
YHHUD.flash(message: "选择入境日期")
return false
}
if endDateStr.isEmpty {
YHHUD.flash(message: "选择逗留截止日期")
return false
}
}
return true
}
func submitInfo() {
if isAllInfoOK() {
if detailType == .SmallWhiteNote {
submitSmallWhiteBarInfo()
} else {
submitHKIDCarInfo()
}
}
}
func submitSmallWhiteBarInfo() {
let params : [String : Any] = [
"idcard_url":uploadImageUrl,
"small_white_note_validity_start":startDateStr,
"small_white_note_validity_end":endDateStr,
"user_id": dataModel.user_id,
"order_id":dataModel.order_id,
"user_type":dataModel.user_type,
]
viewModel.submitSmallWhiteBar(params) { success, error in
if success {
YHHUD.flash(message: "保存成功")
} else {
let msg = error?.errorMsg ?? "保存失败,请重试"
YHHUD.flash(message: msg)
}
}
}
func submitHKIDCarInfo() {
let params : [String : Any] = [
"idcard_url":uploadImageUrl,
"user_id": dataModel.user_id,
"order_id":dataModel.order_id,
"user_type":dataModel.user_type,
]
viewModel.submitSmallWhiteBar(params) { success, error in
if success {
YHHUD.flash(message: "保存成功")
} else {
let msg = error?.errorMsg ?? "保存失败,请重试"
YHHUD.flash(message: msg)
}
}
}
@objc func tapItem(gestureRecognizer:UITapGestureRecognizer) {
var title = ""
var defaultDate = ""
if gestureRecognizer.view == startDateItem {
title = "选择入境日期"
defaultDate = startDateStr
} else {
title = "选择逗留截止日期"
defaultDate = endDateStr
}
YHDatePickView.show(type: .yyyymmdd, title:title, lastIsTaday: true, currentDay: defaultDate) { [weak self] dateStr in
guard let self = self else { return }
if gestureRecognizer.view == startDateItem {
startDateStr = dateStr
startDateItem.updateDate(date: dateStr)
} else {
endDateStr = dateStr
endDateItem.updateDate(date: dateStr)
}
}
}
@objc func clickDelImageBtn() {
cardButton.setContent("card_upload", "点击上传")
cardButton.setBackgroundImage(UIImage(named: "service_cn_card_front"), for: .normal)
delImageButton.isHidden = true
self.uploadImageUrl = ""
}
@objc func tapExampleMudel() {
......@@ -146,39 +283,76 @@ private extension YHUploadCertificateDetailVC {
}
@objc func clickCardButton() {
YHImagePickerView.show() {[weak self] image in
guard let self = self else { return }
self.cardButton.setContent("card_loading", "上传中")
self.cardButton.startRotationAnimation()
self.uploadImageVM.uploadImage(image) {[weak self] success, error in
if uploadImageUrl.isEmpty {
//选择图片
YHImagePickerView.show() {[weak self] image in
guard let self = self else { return }
self.cardButton.setContent("card_loading", "上传中")
self.cardButton.startRotationAnimation()
self.uploadImageVM.uploadImage(image) {[weak self] success, error in
guard let self = self else { return }
self.cardButton.stopRotationAnimation()
self.cardButton.setContent("", "")
self.delImageButton.isHidden = false
guard let url = success else { return }
print(url)
self.uploadImageUrl = url
self.cardButton.setBackgroundImage(image, for: .normal)
self.cardButton.isHidden = false
}
}
} else {
showBigImage()
}
}
func showBigImage() {
if !self.uploadImageUrl.isEmpty {
let vc = YHImageViewController()
vc.imgString = self.uploadImageUrl
UIViewController.current?.navigationController?.pushViewController(vc)
}
}
func loadData() {
let params = [
"cert_type": (detailType == .SmallWhiteNote) ? 1 : 2, //证件类型 1-小白条 2-身份证
"user_id": dataModel.user_id,
"order_id":dataModel.order_id,
"user_type":dataModel.user_type,
] as [String : Any]
viewModel.getCertificateDetailInfo(params) { success, error in
if success {
self.updateUI()
}
}
}
//获取数据后进行更新
func updateUI() {
if let url = viewModel.certificateDetail?.image_url,!url.isYHEmpty() {
uploadImageUrl = url
self.viewModel.getPublicImageUrl(url) {[weak self] success, error in
guard let self = self else { return }
self.cardButton.stopRotationAnimation()
self.cardButton.setContent("", "")
self.delImageButton.isHidden = false
guard let url = success else { return }
// self.viewModel.updateModel(self.type, isFront: true, url: url)
print(url)
self.cardButton.setBackgroundImage(image, for: .normal)
self.cardButton.isHidden = false
// self.viewModel.getPublicImageUrl(url) {[weak self] success, error in
// guard let self = self else { return }
// guard let url = success else { return }
//
// if self.type == .identity {
// self.viewModel.requestCnIDCardMessage(url, isBack: 0) {[weak self] success, error in
// guard self != nil else { return }
// }
// } else {
// self.viewModel.requestHkIDCardMessage(url, isBack: 0) {[weak self] success, error in
// guard self != nil else { return }
// }
// }
// }
self.cardButton.kf.setBackgroundImage(with: URL(string: url), for: .normal, completionHandler: { _ in
self.delImageButton.isHidden = false
})
self.cardButton.setContent("", "")
}
}
if detailType == .SmallWhiteNote {
startDateStr = viewModel.certificateDetail?.start_time ?? ""
endDateStr = viewModel.certificateDetail?.end_time ?? ""
startDateItem.updateDate(date: startDateStr)
endDateItem.updateDate(date: endDateStr)
}
}
func setupUI() {
......@@ -225,11 +399,6 @@ private extension YHUploadCertificateDetailVC {
}
}
titleTextView.attributed.text = """
\("*", .foreground(UIColor.failColor), .font(UIFont.PFSC_M(ofSize: 17)))\(" 张三的第一次赴港激活小白条 ", .foreground(UIColor.mainTextColor), .font(UIFont.PFSC_M(ofSize: 17)))\(.view(customLabel, .original(.center)))
"""
whiteContentView.addSubview(titleTextView)
titleTextView.snp.makeConstraints { make in
......@@ -257,15 +426,11 @@ private extension YHUploadCertificateDetailVC {
if detailType == .SmallWhiteNote {
whiteContentView.addSubview(cardButton)
cardButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(18)
make.top.equalTo(cardLabel.snp.bottom).offset(9)
make.height.equalTo(99)
make.width.equalTo(160)
make.bottom.equalToSuperview().offset(-kMargin)
}
} else if detailType == .HongKongCard {
titleTextView.attributed.text = """
\("*", .foreground(UIColor.failColor), .font(UIFont.PFSC_M(ofSize: 17)))\(" \(dataModel.apply_name)的第一次赴港激活小白条 ", .foreground(UIColor.mainTextColor), .font(UIFont.PFSC_M(ofSize: 17)))\(.view(customLabel, .original(.center)))
"""
whiteContentView.addSubview(cardButton)
cardButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(18)
......@@ -306,10 +471,32 @@ private extension YHUploadCertificateDetailVC {
}
endDateItem.update(title: "逗留截止")
let tap = UITapGestureRecognizer(target: self, action: #selector(tapItem(gestureRecognizer:)))
startDateItem.addGestureRecognizer(tap)
let tap2 = UITapGestureRecognizer(target: self, action: #selector(tapItem(gestureRecognizer:)))
endDateItem.addGestureRecognizer(tap2)
} else if detailType == .HongKongCard {
titleTextView.attributed.text = """
\("*", .foreground(UIColor.failColor), .font(UIFont.PFSC_M(ofSize: 17)))\(" \(dataModel.apply_name)的香港身份 ", .foreground(UIColor.mainTextColor), .font(UIFont.PFSC_M(ofSize: 17)))\(.view(customLabel, .original(.center)))
"""
whiteContentView.addSubview(cardButton)
cardButton.snp.makeConstraints { make in
make.left.equalToSuperview().offset(18)
make.top.equalTo(cardLabel.snp.bottom).offset(9)
make.height.equalTo(99)
make.width.equalTo(160)
make.bottom.equalToSuperview().offset(-kMargin)
}
}
//可编辑
whiteContentView.addSubview(delImageButton)
delImageButton.snp.makeConstraints { make in
make.centerX.equalTo(cardButton.snp.right)
......@@ -318,5 +505,12 @@ private extension YHUploadCertificateDetailVC {
make.width.equalTo(21)
}
view.addSubview(bottomView)
bottomView.snp.makeConstraints { make in
make.left.equalToSuperview()
make.right.equalToSuperview()
make.bottom.equalToSuperview()
make.height.equalTo(YHFileListBottomView.viewH)
}
}
}
......@@ -9,8 +9,6 @@
import UIKit
class YHUploadCertificateVC: YHBaseViewController {
var items: [String] = ["1", "1"]
lazy var viewModel: YHUploadCertificateViewModel = {
let vm = YHUploadCertificateViewModel()
......@@ -71,7 +69,7 @@ class YHUploadCertificateVC: YHBaseViewController {
setupUI()
orderId = 150661 //for test hjl
// orderId = 150661 //for test hjl
loadData()
}
}
......@@ -149,48 +147,43 @@ extension YHUploadCertificateVC: UITableViewDelegate, UITableViewDataSource {
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if 0 <= indexPath.section && indexPath.section < items.count {
if indexPath.row == 0 {
let warningCell = tableView.dequeueReusableCell(withIdentifier: YHUploadCertificateTitleCell.cellReuseIdentifier, for: indexPath) as! YHUploadCertificateTitleCell
var title = ""
if indexPath.section == 0 {
title = "小白条"
} else {
title = "香港身份证"
}
warningCell.updateTitle(title)
return warningCell
if indexPath.row == 0 {
let warningCell = tableView.dequeueReusableCell(withIdentifier: YHUploadCertificateTitleCell.cellReuseIdentifier, for: indexPath) as! YHUploadCertificateTitleCell
var title = ""
if indexPath.section == 0 {
title = "小白条"
} else {
let approveCell = tableView.dequeueReusableCell(withIdentifier: YHUploadCertificateDetailCell.cellReuseIdentifier, for: indexPath) as! YHUploadCertificateDetailCell
if let model = viewModel.uploadCertificateDataListModel {
if indexPath.section == 0 {
let tmp = model.small_whites[indexPath.row - 1]
approveCell.dataModel = tmp
if indexPath.row == model.small_whites.count {
approveCell.isLastCell = true
} else {
approveCell.isLastCell = false
}
} else if indexPath.section == 1 {
let tmp = model.id_cards[indexPath.row - 1]
approveCell.dataModel = tmp
if indexPath.row == model.id_cards.count {
approveCell.isLastCell = true
} else {
approveCell.isLastCell = false
}
title = "香港身份证"
}
warningCell.updateTitle(title)
return warningCell
} else {
let approveCell = tableView.dequeueReusableCell(withIdentifier: YHUploadCertificateDetailCell.cellReuseIdentifier, for: indexPath) as! YHUploadCertificateDetailCell
if let model = viewModel.uploadCertificateDataListModel {
if indexPath.section == 0 {
let tmp = model.small_whites[indexPath.row - 1]
approveCell.dataModel = tmp
if indexPath.row == model.small_whites.count {
approveCell.isLastCell = true
} else {
approveCell.isLastCell = false
}
} else if indexPath.section == 1 {
let tmp = model.id_cards[indexPath.row - 1]
approveCell.dataModel = tmp
if indexPath.row == model.id_cards.count {
approveCell.isLastCell = true
} else {
approveCell.isLastCell = false
}
}
return approveCell
}
return approveCell
}
let approveCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
return approveCell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
......@@ -201,14 +194,22 @@ extension YHUploadCertificateVC: UITableViewDelegate, UITableViewDataSource {
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = YHUploadCertificateDetailVC()
//
if 0 <= indexPath.section && indexPath.section < items.count {
let vc = YHUploadCertificateDetailVC()
vc.detailType = .SmallWhiteNote
self.navigationController?.pushViewController(vc)
if let model = viewModel.uploadCertificateDataListModel {
var tmp : YHUploadCertificateModel?
if indexPath.section == 0 {
tmp = model.small_whites[indexPath.row - 1]
vc.detailType = .SmallWhiteNote
} else if indexPath.section == 1 {
tmp = model.id_cards[indexPath.row - 1]
vc.detailType = .HongKongCard
}
if let tmp = tmp {
vc.dataModel = tmp
self.navigationController?.pushViewController(vc)
}
}
}
......
......@@ -99,5 +99,9 @@ extension YHUploadCertificateDateItem {
cardLabel.attributed.text = b
}
}
func updateDate(date : String) {
dateTextField.text = date
}
}
......@@ -130,9 +130,7 @@ private extension YHVisaPaymentVC {
self.orderID = (id as? Int) ?? 0
}
}
// orderID = 133874//for test hjl
view.addSubview(tableView)
view.addSubview(bottomView)
bottomView.snp.makeConstraints { make in
......@@ -155,6 +153,7 @@ private extension YHVisaPaymentVC {
if self.viewModel.isAllMemberPay() {
//跳转
let vc = YHUploadCertificateVC()
vc.orderId = orderID
self.navigationController?.push(vc, removeClass: YHVisaPaymentVC.self)
} else {
postPaymentResult()
......
......@@ -39,6 +39,7 @@ private extension YHFileListBottomView {
button.layer.cornerRadius = kCornerRadius3
button.clipsToBounds = true
button.addTarget(self, action: #selector(submit), for: .touchUpInside)
button.backgroundColor = UIColor.brandMainColor
return button
}()
addSubview(nextButton)
......@@ -49,14 +50,16 @@ private extension YHFileListBottomView {
make.left.equalTo(kMargin)
}
nextButton.layoutIfNeeded()
nextButton.addYinHeGradualLayer()
}
@objc func save() {
block?(0)
}
@objc func submit() {
block?(1)
}
}
extension YHFileListBottomView {
func updateBtnTitle(title : String) {
nextButton.setTitle(title, for: .normal)
}
}
......@@ -142,16 +142,6 @@ class YHMyViewController: YHBaseViewController, ConstraintRelatableTarget {
vc.myDefaultNavItemIndex = 2
self.navigationController?.pushViewController(vc)
print("最近浏览")
// let view = YHRangeDatePickerSheetView.sheetView()
// view.block = { (startDate,endDate) in
// print("选择的日期是:")
// print(startDate)
// print(endDate)
// }
// view.show() //for test hjl
}
return view
}()
......
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