Commit 3d22ba06 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 27a5c433 ef0351c4
......@@ -128,14 +128,14 @@ extension YHCertificateResourceUploadVC: UITableViewDelegate, UITableViewDataSou
let item = items[indexPath.section]
if item.checkStatus == YHCertificateUploadStatus.preUpload { // 待上传
showUploadSheetView(item.templateInfo)
showUploadSheetView(item)
return
}
// 非待上传的进入详情
let vc = YHUploadContentVC()
vc.orderId = orderId
vc.categoryInfo = categoryInfo
vc.uploadInfo = item
vc.supplementInfo = item
self.navigationController?.pushViewController(vc)
}
}
......@@ -223,29 +223,92 @@ extension YHCertificateResourceUploadVC {
}
}
func showUploadSheetView(_ template: YHTemplateInfo) {
func uploadImage(_ img: UIImage, supplementInfo:YHSupplementInfo) {
// 先OSS上传得到URL
YHHUD.show(.progress(message: "上传中..."))
self.viewModel.uploadImage(img) {
[weak self] url, error in
guard let self = self else { return }
YHHUD.hide()
if let url = url, !url.isEmpty {
let imgName = url.lastPathComponent
var suffix = "jpg"
let suffixName = url.pathExtension.lowercased()
if !suffixName.isEmpty {
suffix = suffixName
}
// 再调用业务接口
let model = YHContentUrl()
model.name = imgName
model.url = url
model.suffix = suffix
self.viewModel.updateCertificateItem(supplementId:supplementInfo.id, urlModel:model, operation: "add", rename: "") {
self.requestList(status: self.status)
}
return
}
//
var msg = "上传图片失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message: msg)
}
}
func uploadFile(_ fileUrl:URL, supplementInfo:YHSupplementInfo) {
if let fileData = try? Data(contentsOf: fileUrl) {
// 将文件数据上传到服务器
let size = String(format: "%.2fM", Double(fileData.count)/(1024.0 * 1024.0))
print("\(size)")
// 先OSS上传得到URL
self.viewModel.uploadFile(fileUrl.absoluteString) {
[weak self] successUrl, error in
guard let self = self else { return }
// 再调用业务接口
if let successUrl = successUrl, !successUrl.isEmpty {
let fileName = successUrl.lastPathComponent
let suffixName = successUrl.pathExtension.lowercased()
let model = YHContentUrl()
model.name = fileName
model.url = successUrl
model.suffix = suffixName
self.viewModel.updateCertificateItem(supplementId:supplementInfo.id, urlModel:model, operation: "add", rename: "") {
self.requestList(status:self.status)
}
return
}
var msg = "上传图片失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message: msg)
}
} else {
YHHUD.flash(message: "识别文件失败")
}
}
func showUploadSheetView(_ supplementInfo: YHSupplementInfo) {
let sheetView = YHCertificateUploadSheetView.sheetView
sheetView.templateInfo = template
sheetView.templateInfo = supplementInfo.templateInfo
sheetView.uploadFilesBlock = {
[weak self] fileUrl in
guard let self = self else { return }
print(fileUrl)
if let fileData = try? Data(contentsOf: fileUrl) {
// 将文件数据上传到服务器
let size = String(format: "%.2fM", Double(fileData.count)/(1024.0 * 1024.0))
print("\(size)")
self.viewModel.uploadFile(fileUrl.absoluteString) {[weak self] success, error in
guard let self = self else { return }
}
}
}
sheetView.uploadImageBlock = {
[weak self] image in
guard let self = self else { return }
// uploadImage(image)
}
sheetView.show()
[weak self] fileUrl in
guard let self = self else { return }
print(fileUrl)
uploadFile(fileUrl, supplementInfo: supplementInfo)
}
sheetView.uploadImageBlock = {
[weak self] image in
guard let self = self else { return }
uploadImage(image, supplementInfo: supplementInfo)
}
sheetView.show()
}
}
......@@ -13,10 +13,10 @@ class YHUploadContentVC: YHBaseViewController {
var orderId : Int!
var categoryInfo: YHCategoryData!
var uploadInfo: YHSupplementInfo! {
var supplementInfo: YHSupplementInfo! {
didSet {
templateArr.removeAll()
if let uploadInfo = uploadInfo {
if let uploadInfo = supplementInfo {
if uploadInfo.templateInfo.materialPath.count > 0 {
templateArr.append(uploadInfo.templateInfo.materialPath[0])
}
......@@ -88,7 +88,7 @@ class YHUploadContentVC: YHBaseViewController {
createUI()
items.removeAll()
items.append(contentsOf: uploadInfo.contentUrl)
items.append(contentsOf: supplementInfo.contentUrl)
tableView.reloadData()
requestList()
......@@ -97,7 +97,9 @@ class YHUploadContentVC: YHBaseViewController {
[weak self] text in
guard let self = self else { return }
if let selectEditItem = selectEditItem, let text = text {
self.updateCertificateItem(selectEditItem, operation: "rename", rename: text)
self.viewModel.updateCertificateItem(supplementId:supplementInfo.id, urlModel:selectEditItem, operation: "rename", rename: text) {
self.requestList()
}
}
}
}
......@@ -108,20 +110,12 @@ class YHUploadContentVC: YHBaseViewController {
@objc func didClickUploadBtn() {
let sheetView = YHCertificateUploadSheetView.sheetView
sheetView.templateInfo = uploadInfo.templateInfo
sheetView.templateInfo = supplementInfo.templateInfo
sheetView.uploadFilesBlock = {
[weak self] fileUrl in
guard let self = self else { return }
print(fileUrl)
if let fileData = try? Data(contentsOf: fileUrl) {
// 将文件数据上传到服务器
let size = String(format: "%.2fM", Double(fileData.count)/(1024.0 * 1024.0))
print("\(size)")
self.viewModel.uploadFile(fileUrl.absoluteString) {[weak self] success, error in
guard let self = self else { return }
}
}
uploadFile(fileUrl)
}
sheetView.uploadImageBlock = {
[weak self] image in
......@@ -140,7 +134,7 @@ class YHUploadContentVC: YHBaseViewController {
tableView.snp.makeConstraints { make in
make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
make.left.right.equalTo(view)
if uploadInfo.checkStatus == YHCertificateUploadStatus.finish.rawValue {
if supplementInfo.checkStatus == YHCertificateUploadStatus.finish.rawValue {
make.bottom.equalToSuperview()
} else {
make.bottom.equalTo(uploadBtn.snp.top).offset(-34)
......@@ -205,7 +199,7 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
YHCertificateEditItem(type:.delete, title:"删除"),
YHCertificateEditItem(type:.cancel, title:"取消")]
if uploadInfo.checkStatus == YHCertificateUploadStatus.finish.rawValue {
if supplementInfo.checkStatus == YHCertificateUploadStatus.finish.rawValue {
items = [YHCertificateEditItem(type:.preview, title:"预览"),
YHCertificateEditItem(type:.cancel, title:"取消")]
}
......@@ -225,7 +219,9 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
let msg = "您确定要删除文档\(contentItem.name)吗"
YHTwoOptionAlertView.showAlertView(message:msg) { sure in
if !sure { return }
self.updateCertificateItem(contentItem, operation: "del", rename: "")
self.viewModel.updateCertificateItem(supplementId:self.supplementInfo.id, urlModel:contentItem, operation: "del", rename:"") {
self.requestList()
}
}
} else if editType == .preview { // 预览
......@@ -247,7 +243,7 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
private func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat {
if section == 0 {
if uploadInfo.templateInfo.isNeedShowTemplate() {
if supplementInfo.templateInfo.isNeedShowTemplate() {
return UITableView.automaticDimension
}
return 0.0
......@@ -260,7 +256,7 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
let view = UIView()
if section == 0 { // 证件示例模版
if !uploadInfo.templateInfo.isNeedShowTemplate() {
if !supplementInfo.templateInfo.isNeedShowTemplate() {
return view
}
......@@ -268,7 +264,7 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
titlelabel.textColor = UIColor.mainTextColor
titlelabel.textAlignment = .left
titlelabel.font = UIFont.PFSC_M(ofSize:17)
titlelabel.text = "\(uploadInfo.name)示例模版"
titlelabel.text = "\(supplementInfo.name)示例模版"
titlelabel.numberOfLines = 0
view.addSubview(titlelabel)
......@@ -283,8 +279,8 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
tipsLabel.textAlignment = .left
tipsLabel.font = UIFont.PFSC_R(ofSize:14)
tipsLabel.numberOfLines = 0
if !uploadInfo.templateInfo.description.isEmpty {
tipsLabel.text = "注意事项:\(uploadInfo.templateInfo.description)"
if !supplementInfo.templateInfo.description.isEmpty {
tipsLabel.text = "注意事项:\(supplementInfo.templateInfo.description)"
}
view.addSubview(tipsLabel)
......@@ -302,7 +298,7 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
titlelabel.textColor = UIColor.mainTextColor
titlelabel.textAlignment = .left
titlelabel.font = UIFont.PFSC_M(ofSize:17)
titlelabel.text = uploadInfo.name
titlelabel.text = supplementInfo.name
titlelabel.numberOfLines = 0
view.addSubview(titlelabel)
......@@ -316,21 +312,21 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
var text = ""
var textColor:UIColor = .clear
var bgColor:UIColor = .clear
if uploadInfo.checkStatus == YHCertificateUploadStatus.review.rawValue {
if supplementInfo.checkStatus == YHCertificateUploadStatus.review.rawValue {
text = "审核中".local
textColor = UIColor(hexString: "#FF9900")
bgColor = UIColor(hexString: "#FF9900", 0.08)
} else if uploadInfo.checkStatus == YHCertificateUploadStatus.preUpload.rawValue {
} else if supplementInfo.checkStatus == YHCertificateUploadStatus.preUpload.rawValue {
text = "待上传".local
textColor = UIColor(hexString: "#2F7EF6")
bgColor = UIColor(hexString: "#2F7EF6", 0.08)
} else if uploadInfo.checkStatus == YHCertificateUploadStatus.finish.rawValue {
} else if supplementInfo.checkStatus == YHCertificateUploadStatus.finish.rawValue {
text = "已通过".local
textColor = UIColor(hexString: "#49D2B1")
bgColor = UIColor(hexString: "#49D2B1", 0.08)
} else if uploadInfo.checkStatus == YHCertificateUploadStatus.rejected.rawValue {
} else if supplementInfo.checkStatus == YHCertificateUploadStatus.rejected.rawValue {
text = "已驳回".local
textColor = UIColor(hexString: "#F81D22")
bgColor = UIColor(hexString: "#F81D22", 0.08)
......@@ -344,7 +340,7 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
tipsLabel.font = UIFont.PFSC_R(ofSize:12)
tipsLabel.textAlignment = .left
tipsLabel.numberOfLines = 0
tipsLabel.text = uploadInfo.auditContent
tipsLabel.text = supplementInfo.auditContent
view.addSubview(tipsLabel)
titlelabel.snp.makeConstraints { make in
......@@ -394,7 +390,14 @@ extension YHUploadContentVC: UITableViewDelegate, UITableViewDataSource {
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 { // 模版列表
if 0 <= indexPath.row && indexPath.row < templateArr.count {
let path = templateArr[indexPath.row]
}
} else if indexPath.section == 1 { // 证件列表
}
}
@objc func dismissed() {
......@@ -446,7 +449,7 @@ extension YHUploadContentVC {
"node": "1",
"state": "1",
"category_id": categoryInfo.categoryId,
"supplement_ids": uploadInfo.id]
"supplement_ids": supplementInfo.id]
print(params)
viewModel.getCertificateList(params: params) {
......@@ -458,6 +461,9 @@ extension YHUploadContentVC {
if let listInfo = listInfo {
categoryInfo = listInfo.categoryData
let arr = listInfo.supplementList
if arr.count > 0 {
supplementInfo = arr[0]
}
for item in arr {
items.append(contentsOf: item.contentUrl)
}
......@@ -470,73 +476,7 @@ extension YHUploadContentVC {
}
}
// 更改证件
// operation参数必填,必须是:add(上传)、del(删除)、rename(重命名)
func updateCertificateItem(_ model: YHContentUrl, operation:String, rename:String) {
var name = model.name
if operation == "rename" {
name = rename
}
let dic:[String : Any] = [
"id" : uploadInfo.id,
"content_url": [
"name": name,
"url": model.url,
"suffix": model.suffix]]
let params: [String: Any] = [
"file_info" : [dic],
"operation" : operation,
]
self.viewModel.updateCertificates(params: params) {
[weak self] success, error in
guard let self = self else { return }
if operation == "del" {
if success {
YHHUD.flash(message: "删除成功")
} else {
var msg = "删除失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message:msg)
}
requestList()
return
}
if operation == "rename" {
if success {
YHHUD.flash(message: "重命名成功")
} else {
var msg = "重命名失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message:msg)
}
requestList()
return
}
if operation == "add" {
if success {
YHHUD.flash(message: "添加成功")
} else {
var msg = "添加失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message:msg)
}
requestList()
return
}
}
}
func uploadImage(_ img: UIImage) {
......@@ -559,7 +499,9 @@ extension YHUploadContentVC {
model.name = imgName
model.url = url
model.suffix = suffix
updateCertificateItem(model, operation: "add", rename: "")
self.viewModel.updateCertificateItem(supplementId:supplementInfo.id, urlModel:model, operation: "add", rename: "") {
self.requestList()
}
return
}
//
......@@ -570,5 +512,40 @@ extension YHUploadContentVC {
YHHUD.flash(message: msg)
}
}
func uploadFile(_ fileUrl:URL) {
if let fileData = try? Data(contentsOf: fileUrl) {
// 将文件数据上传到服务器
let size = String(format: "%.2fM", Double(fileData.count)/(1024.0 * 1024.0))
print("\(size)")
// 先OSS上传得到URL
self.viewModel.uploadFile(fileUrl.absoluteString) {
[weak self] successUrl, error in
guard let self = self else { return }
// 再调用业务接口
if let successUrl = successUrl, !successUrl.isEmpty {
let fileName = successUrl.lastPathComponent
let suffixName = successUrl.pathExtension.lowercased()
let model = YHContentUrl()
model.name = fileName
model.url = successUrl
model.suffix = suffixName
self.viewModel.updateCertificateItem(supplementId:supplementInfo.id, urlModel:model, operation: "add", rename: "") {
self.requestList()
}
return
}
var msg = "上传图片失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message: msg)
}
} else {
YHHUD.flash(message: "识别文件失败")
}
}
}
......@@ -239,6 +239,12 @@ extension YHCertificateTemplateSheetView: UITableViewDelegate, UITableViewDataSo
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if 0 <= indexPath.row && indexPath.row < templateArr.count {
let path = templateArr[indexPath.row]
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 82.0
}
......
......@@ -253,6 +253,33 @@ extension YHCertificateUploadSheetView: UITableViewDelegate, UITableViewDataSour
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 { // 模版列表
if 0 <= indexPath.row && indexPath.row < templateArr.count {
let path = templateArr[indexPath.row]
}
} else if indexPath.section == 1 { // 操作列表
if 0 <= indexPath.row && indexPath.row < uploadTypeArr.count {
let operationItem = uploadTypeArr[indexPath.row]
if operationItem.type == .cancel {
dismiss()
} else if operationItem.type == .photo {
selectPhoto()
} else if operationItem.type == .camera {
takePhoto()
} else if operationItem.type == .phoneFile {
selectFile()
}
}
}
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0 {
return 82.0
......@@ -364,6 +391,7 @@ extension YHCertificateUploadSheetView: (UIImagePickerControllerDelegate & UINav
} else {
printLog("pick image wrong")
self.dismiss()
}
// 收回图库选择界面
picker.dismiss(animated: true, completion: nil)
......
......@@ -198,4 +198,76 @@ class YHCertificateViewModel: YHBaseViewModel {
callBack(false, err)
}
}
// 更改证件
// operation参数必填,必须是:add(上传)、del(删除)、rename(重命名)
func updateCertificateItem(supplementId:Int, urlModel: YHContentUrl, operation:String, rename:String, callBack:(()->())?) {
var name = urlModel.name
if operation == "rename" {
name = rename
}
let dic:[String : Any] = [
"id" : supplementId,
"content_url": [
"name": name,
"url": urlModel.url,
"suffix": urlModel.suffix]]
let params: [String: Any] = [
"file_info" : [dic],
"operation" : operation,
]
YHHUD.show(.progress(message: "数据加载中..."))
self.updateCertificates(params: params) {
[weak self] success, error in
YHHUD.hide()
guard let self = self else { return }
if operation == "del" {
if success {
YHHUD.flash(message: "删除成功")
} else {
var msg = "删除失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message:msg)
}
callBack?()
return
}
if operation == "rename" {
if success {
YHHUD.flash(message: "重命名成功")
} else {
var msg = "重命名失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message:msg)
}
callBack?()
return
}
if operation == "add" {
if success {
YHHUD.flash(message: "添加成功")
} else {
var msg = "添加失败"
if let errorMsg = error?.errorMsg, !errorMsg.isEmpty {
msg = errorMsg
}
YHHUD.flash(message:msg)
}
callBack?()
return
}
}
}
}
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