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

原则批

parent de28f7d5
......@@ -9,6 +9,7 @@
import UIKit
import SmartCodable
import AttributedString
import IQKeyboardManagerSwift
class YHPrincipleUploadListVC: YHBaseViewController {
......@@ -66,6 +67,11 @@ class YHPrincipleUploadListVC: YHBaseViewController {
requestData()
}
lazy var previewFileTool:YHFilePreviewTool = {
let tool = YHFilePreviewTool(targetVC: UIViewController.current)
return tool
}()
func createUI() {
view.addSubview(bgView)
view.addSubview(tableView)
......@@ -170,6 +176,55 @@ extension YHPrincipleUploadListVC {
@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 {
......@@ -224,6 +279,12 @@ extension YHPrincipleUploadListVC: UITableViewDelegate, UITableViewDataSource {
model.isUnfold = isUnfold
self.tableView.reloadData()
}
// 文件操作
cell.fileEditBlock = {
[weak self] fileModel in
guard let self = self else { return }
self.showFileOperationAlertView(fileModel, itemModel: model)
}
return cell
}
}
......
......@@ -66,6 +66,19 @@ class YHPrincipleContentUrlModel: SmartCodable {
var fileUrl: 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() {
}
......
......@@ -11,12 +11,20 @@ import UIKit
class YHPrincipleUploadFileCell: UITableViewCell {
static let cellReuseIdentifier = "YHPrincipleUploadFileCell"
static let height = 55.0
var fileModel = YHPrincipleContentUrlModel()
var iconImgV: UIImageView!
var titleLabel: UILabel!
var timeLabel: UILabel!
var editBtn: UIButton!
var editBlock: ((YHPrincipleContentUrlModel)->())?
var isShowEditBtn: Bool = false {
didSet {
editBtn.isHidden = !isShowEditBtn
}
}
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
......@@ -27,32 +35,71 @@ class YHPrincipleUploadFileCell: UITableViewCell {
super.init(coder: coder)
}
@objc func didEditBtnClicked() {
editBlock?(fileModel)
}
func updateModel(_ model: YHPrincipleContentUrlModel) {
fileModel = model
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() {
self.selectionStyle = .none
iconImgV = UIImageView(image: UIImage(named: "my_cer_type_pdf"))
self.addSubview(iconImgV)
contentView.addSubview(iconImgV)
titleLabel = UILabel()
titleLabel.font = UIFont.PFSC_M(ofSize: 14)
titleLabel.textColor = UIColor.mainTextColor
titleLabel.text = "文件名称"
self.addSubview(titleLabel)
contentView.addSubview(titleLabel)
timeLabel = UILabel()
timeLabel.font = UIFont.PFSC_R(ofSize: 11)
timeLabel.textColor = UIColor.labelTextColor2
timeLabel.text = "上传于0000.00.00"
self.addSubview(timeLabel)
contentView.addSubview(timeLabel)
editBtn = UIButton()
editBtn.isHidden = true
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
make.left.equalTo(16)
......
......@@ -8,6 +8,7 @@
import UIKit
import AttributedString
import IQKeyboardManagerSwift
enum YHPrincipleUploadStatus : Int {
// 审核中
......@@ -29,8 +30,10 @@ class YHPrincipleUploadStatusCell: UITableViewCell {
var itemModel:YHPrincipleAgreementModel?
var items: [YHPrincipleContentUrlModel] = []
var expandClick:((Bool)->())?
var fileEditBlock:((YHPrincipleContentUrlModel) -> ())?
var status: YHPrincipleUploadStatus = .preUpload
// var status: YHPrincipleUploadStatus = .preUpload
let viewModel = YHPrincleViewModel()
lazy var whiteView: UIView = {
let view = UIView()
......@@ -425,10 +428,22 @@ extension YHPrincipleUploadStatusCell: UITableViewDataSource, UITableViewDelegat
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: YHPrincipleUploadFileCell.cellReuseIdentifier, for: indexPath) as! YHPrincipleUploadFileCell
if 0 <= indexPath.row, indexPath.row < items.count {
let model: YHPrincipleContentUrlModel = items[indexPath.row]
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
}
......@@ -457,3 +472,9 @@ extension YHPrincipleUploadStatusCell: UITableViewDataSource, UITableViewDelegat
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