Commit 250f8732 authored by Steven杜宇's avatar Steven杜宇

原则批

parent de28f7d5
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
import UIKit import UIKit
import SmartCodable import SmartCodable
import AttributedString import AttributedString
import IQKeyboardManagerSwift
class YHPrincipleUploadListVC: YHBaseViewController { class YHPrincipleUploadListVC: YHBaseViewController {
...@@ -66,6 +67,11 @@ class YHPrincipleUploadListVC: YHBaseViewController { ...@@ -66,6 +67,11 @@ class YHPrincipleUploadListVC: YHBaseViewController {
requestData() requestData()
} }
lazy var previewFileTool:YHFilePreviewTool = {
let tool = YHFilePreviewTool(targetVC: UIViewController.current)
return tool
}()
func createUI() { func createUI() {
view.addSubview(bgView) view.addSubview(bgView)
view.addSubview(tableView) view.addSubview(tableView)
...@@ -170,6 +176,55 @@ extension YHPrincipleUploadListVC { ...@@ -170,6 +176,55 @@ extension YHPrincipleUploadListVC {
@objc func didUploadBtnClicked() { @objc func didUploadBtnClicked() {
} }
func showFileOperationAlertView(_ model: YHPrincipleContentUrlModel, itemModel:YHPrincipleAgreementModel) {
var arr = [YHCertificateEditItem(type:.rename, title:"重命名"),
YHCertificateEditItem(type:.preview, title:"预览"),
YHCertificateEditItem(type:.delete, title:"删除"),
YHCertificateEditItem(type:.cancel, title:"取消")]
YHCertificateEditSheetView.sheetView(items:arr) {
[weak self] editType in
guard let self = self else { return }
print("editType:\(editType.rawValue)")
if editType == .rename { // 重命名
IQKeyboardManager.shared.enable = false
// var name = contentItem.getFileNameWithoutSuffix()
// if name.count > 30 {
// name = name[safe: ..<30]!
// }
// renameInputView.textField.text = name
// renameInputView.textField.becomeFirstResponder()
} else if editType == .delete { // 删除
let msg = "您确定要删除文档\(model.name)吗?"
YHTwoOptionAlertView.showAlertView(message:msg) { sure in
if !sure { return }
// 删除
var targetIndex:Int = -1
for (index, m) in itemModel.content_url.enumerated() {
if m.url == model.url {
targetIndex = index
break
}
}
itemModel.content_url.remove(at: targetIndex)
self.tableView.reloadData()
}
} else if editType == .preview { // 预览
print(model.url)
self.viewModel.getPublicImageUrl(model.url) { success, error in
if let success = success {
self.previewFileTool.openXLSXRemoteFile(urlString: success, fileName:model.name)
}
}
}
}.show()
}
} }
extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource { extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource {
...@@ -224,6 +279,12 @@ extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource { ...@@ -224,6 +279,12 @@ extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource {
model.isUnfold = isUnfold model.isUnfold = isUnfold
self.tableView.reloadData() self.tableView.reloadData()
} }
// 文件操作
cell.fileEditBlock = {
[weak self] fileModel in
guard let self = self else { return }
self.showFileOperationAlertView(fileModel, itemModel: model)
}
return cell return cell
} }
} }
......
...@@ -66,6 +66,19 @@ class YHPrincipleContentUrlModel: SmartCodable { ...@@ -66,6 +66,19 @@ class YHPrincipleContentUrlModel: SmartCodable {
var fileUrl: String = "" var fileUrl: String = ""
var updated_at: String = "" var updated_at: String = ""
// 获取文件后缀名 eg:123.pdf -> pdf
func getFileSuffixName()->String {
let res1 = name.pathExtension.lowercased()
if !res1.isEmpty {
return res1
}
let res2 = url.pathExtension.lowercased()
if !res2.isEmpty {
return res2
}
return ""
}
required init() { required init() {
} }
......
...@@ -11,12 +11,20 @@ import UIKit ...@@ -11,12 +11,20 @@ import UIKit
class YHPrincipleUploadFileCell: UITableViewCell { class YHPrincipleUploadFileCell: UITableViewCell {
static let cellReuseIdentifier = "YHPrincipleUploadFileCell" static let cellReuseIdentifier = "YHPrincipleUploadFileCell"
static let height = 55.0 static let height = 55.0
var fileModel = YHPrincipleContentUrlModel()
var iconImgV: UIImageView! var iconImgV: UIImageView!
var titleLabel: UILabel! var titleLabel: UILabel!
var timeLabel: UILabel! var timeLabel: UILabel!
var editBtn: UIButton! var editBtn: UIButton!
var editBlock: ((YHPrincipleContentUrlModel)->())?
var isShowEditBtn: Bool = false {
didSet {
editBtn.isHidden = !isShowEditBtn
}
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
...@@ -27,32 +35,71 @@ class YHPrincipleUploadFileCell: UITableViewCell { ...@@ -27,32 +35,71 @@ class YHPrincipleUploadFileCell: UITableViewCell {
super.init(coder: coder) super.init(coder: coder)
} }
@objc func didEditBtnClicked() {
editBlock?(fileModel)
}
func updateModel(_ model: YHPrincipleContentUrlModel) { func updateModel(_ model: YHPrincipleContentUrlModel) {
fileModel = model
titleLabel.text = model.name titleLabel.text = model.name
timeLabel.text = model.updated_at timeLabel.text = "上传于" + model.updated_at
let suffix = model.getFileSuffixName()
var iconImgName = ""
if suffix == "jpeg" {
iconImgName = "my_cer_type_jpg"
} else if suffix == "jpg" {
iconImgName = "my_cer_type_jpg"
} else if suffix == "png" {
iconImgName = "my_cer_type_png"
} else if suffix == "pdf" {
iconImgName = "my_cer_type_pdf"
} else if suffix == "doc" || suffix == "docx" {
iconImgName = "my_cer_type_word"
} else if suffix == "ppt" || suffix == "pptx" {
iconImgName = "my_cer_type_ppt"
} else if suffix == "bmp" {
iconImgName = "my_cer_type_bmp"
} else if suffix == "tiff" {
iconImgName = "my_cer_type_tiff"
}
iconImgV.image = UIImage(named: iconImgName)
} }
func setupUI() { func setupUI() {
self.selectionStyle = .none self.selectionStyle = .none
iconImgV = UIImageView(image: UIImage(named: "my_cer_type_pdf")) iconImgV = UIImageView(image: UIImage(named: "my_cer_type_pdf"))
self.addSubview(iconImgV) contentView.addSubview(iconImgV)
titleLabel = UILabel() titleLabel = UILabel()
titleLabel.font = UIFont.PFSC_M(ofSize: 14) titleLabel.font = UIFont.PFSC_M(ofSize: 14)
titleLabel.textColor = UIColor.mainTextColor titleLabel.textColor = UIColor.mainTextColor
titleLabel.text = "文件名称" titleLabel.text = "文件名称"
self.addSubview(titleLabel) contentView.addSubview(titleLabel)
timeLabel = UILabel() timeLabel = UILabel()
timeLabel.font = UIFont.PFSC_R(ofSize: 11) timeLabel.font = UIFont.PFSC_R(ofSize: 11)
timeLabel.textColor = UIColor.labelTextColor2 timeLabel.textColor = UIColor.labelTextColor2
timeLabel.text = "上传于0000.00.00" timeLabel.text = "上传于0000.00.00"
self.addSubview(timeLabel) contentView.addSubview(timeLabel)
editBtn = UIButton() editBtn = UIButton()
editBtn.isHidden = true
editBtn.setImage(UIImage(named: "my_cer_btn_edit"), for: .normal) editBtn.setImage(UIImage(named: "my_cer_btn_edit"), for: .normal)
self.addSubview(editBtn) editBtn.YH_clickEdgeInsets = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
editBtn.addTarget(self, action: #selector(didEditBtnClicked), for: .touchUpInside)
contentView.addSubview(editBtn)
iconImgV.snp.makeConstraints { make in iconImgV.snp.makeConstraints { make in
make.left.equalTo(16) make.left.equalTo(16)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
import UIKit import UIKit
import AttributedString import AttributedString
import IQKeyboardManagerSwift
enum YHPrincipleUploadStatus : Int { enum YHPrincipleUploadStatus : Int {
// 审核中 // 审核中
...@@ -29,8 +30,10 @@ class YHPrincipleUploadStatusCell: UITableViewCell { ...@@ -29,8 +30,10 @@ class YHPrincipleUploadStatusCell: UITableViewCell {
var itemModel:YHPrincipleAgreementModel? var itemModel:YHPrincipleAgreementModel?
var items: [YHPrincipleContentUrlModel] = [] var items: [YHPrincipleContentUrlModel] = []
var expandClick:((Bool)->())? var expandClick:((Bool)->())?
var fileEditBlock:((YHPrincipleContentUrlModel) -> ())?
var status: YHPrincipleUploadStatus = .preUpload // var status: YHPrincipleUploadStatus = .preUpload
let viewModel = YHPrincleViewModel()
lazy var whiteView: UIView = { lazy var whiteView: UIView = {
let view = UIView() let view = UIView()
...@@ -425,10 +428,22 @@ extension YHPrincipleUploadStatusCell: UITableViewDataSource, UITableViewDelegat ...@@ -425,10 +428,22 @@ extension YHPrincipleUploadStatusCell: UITableViewDataSource, UITableViewDelegat
} }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: YHPrincipleUploadFileCell.cellReuseIdentifier, for: indexPath) as! YHPrincipleUploadFileCell let cell = tableView.dequeueReusableCell(withIdentifier: YHPrincipleUploadFileCell.cellReuseIdentifier, for: indexPath) as! YHPrincipleUploadFileCell
if 0 <= indexPath.row, indexPath.row < items.count { if 0 <= indexPath.row, indexPath.row < items.count {
let model: YHPrincipleContentUrlModel = items[indexPath.row] let model: YHPrincipleContentUrlModel = items[indexPath.row]
cell.updateModel(model) cell.updateModel(model)
if let itemModel = self.itemModel {
cell.isShowEditBtn = (itemModel.check_status == YHPrincipleUploadStatus.preUpload.rawValue ||
itemModel.check_status == YHPrincipleUploadStatus.rejected.rawValue)
} else {
cell.isShowEditBtn = false
}
cell.editBlock = {
[weak self] model in
guard let self = self else { return }
self.fileEditBlock?(model)
}
} }
return cell return cell
} }
...@@ -457,3 +472,9 @@ extension YHPrincipleUploadStatusCell: UITableViewDataSource, UITableViewDelegat ...@@ -457,3 +472,9 @@ extension YHPrincipleUploadStatusCell: UITableViewDataSource, UITableViewDelegat
return UIView() return UIView()
} }
} }
extension YHPrincipleUploadStatusCell {
}
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