AddEvaluateViewController.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // AddEvaluateViewController.swift
  3. // ADHTuanCan
  4. //
  5. // Created by 敖德亨 on 2023/11/10.
  6. //
  7. import UIKit
  8. import RxCocoa
  9. import RxSwift
  10. import TZImagePickerController
  11. class AddEvaluateViewController: ADHBaseVC {
  12. @IBOutlet weak var tableView: UITableView!
  13. @IBOutlet weak var topContent: NSLayoutConstraint!
  14. /// 订单ID
  15. var orderId : NSNumber?{
  16. didSet{
  17. self.viewModel.getNeedEvaluateListModel.id = orderId
  18. self.viewModel.upEvaluateListModel.orderId = orderId
  19. }
  20. }
  21. let viewModel : EvaluateViewModel = EvaluateViewModel.init()
  22. let diposableBag = DisposeBag()
  23. var dataSource : [NeedEvaluateListModel]?
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. let navStyle = MCNavBarStyle()
  27. navStyle.styleForBackImage = UIImage.init(named: "黑色返回")!
  28. navStyle.styleForTitleColor = UIColor.black
  29. self.navBar = MCNavBarView.init(title: LanguagesUtil.createTextBy(Ctext: "发表评价", Etext: "Comment"), subTitle: nil,style: navStyle)
  30. self.topContent.constant = kNavAndStatuHeight + 1
  31. self.navBar?.backgroundColor = UIColor.white
  32. tableView.register(withType: AddEvaluateCell.self)
  33. self.getDataList()
  34. }
  35. // MARK: - 获取列表
  36. func getDataList(){
  37. self.hud.showLoading()
  38. self.viewModel.signalGetNeedEvaluateList()?.on(success: { dd in
  39. self.dataSource = self.viewModel.needEvaluateList
  40. self.tableView.reloadData()
  41. self.hud.hidden()
  42. }, error: { error in
  43. self.hud.showFailure(error.msg ?? LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
  44. })
  45. }
  46. func addUploadImg(model : NeedEvaluateListModel , reindexPath : IndexPath){
  47. let num = 4 - (model.links?.count ?? 0)
  48. let imagePickerVC = TZImagePickerController(maxImagesCount: num, delegate: self)
  49. imagePickerVC?.allowTakeVideo = false
  50. imagePickerVC?.allowPickingOriginalPhoto = true
  51. // imagePickerVC?.photoPreviewPageUIConfigBlock?.previewViewBgColor = UIColor.black
  52. imagePickerVC?.navigationBar.barTintColor = UIColor.white
  53. imagePickerVC?.navigationBar.tintColor = UIColor.black
  54. // imagePickerVC?.navigationItem.backAction = UIColor.black
  55. imagePickerVC?.didFinishPickingPhotosHandle = {[weak self] photos , assset, iskkk in
  56. NSLog("\(photos?.count ?? 0)")
  57. var imgDatas : [Data]? = []
  58. for item in photos!{
  59. guard let jpegData = item.jpegData(compressionQuality: 0.5)else {return}
  60. imgDatas?.append(jpegData)
  61. }
  62. self?.hud.showLoading()
  63. MCHttpUtil.uploadImg(imageDates: imgDatas!, url: "/blade-resource/oss/endpoint/put-file-attach") { models in
  64. self?.hud.hidden()
  65. // var links : [String]? = []
  66. for item in models{
  67. let sss : PhotoUrlModel = item
  68. model.links?.append(sss.link ?? "")
  69. }
  70. // model.links?.append(contentsOf: links ?? [])
  71. self?.tableView.reloadRows(at: [reindexPath], with: .none)
  72. } error: { errorMsg in
  73. self?.hud.showFailure("\(errorMsg)")
  74. }
  75. }
  76. self.present(imagePickerVC!, animated: true)
  77. }
  78. @IBAction func saveAction(_ sender: UIButton) {
  79. self.hud.showLoading()
  80. self.viewModel.upEvaluateListModel.orderMealReviews = []
  81. for item in self.viewModel.needEvaluateList! {
  82. let model : NeedEvaluateListModel = item
  83. self.viewModel.upEvaluateListModel.orderMealReviews?.append(model)
  84. }
  85. self.viewModel.signalUpEvaluate()?.on(success: { dd in
  86. NotificationCenter.default.post(name: NSNotification.Name("刷新订单列表"), object: self, userInfo:nil)
  87. self.hud.showSuccess()
  88. self.navigationController?.popViewController(animated: true)
  89. }, error: { error in
  90. self.hud.showFailure(error.msg ?? LanguagesUtil.createTextBy(Ctext: "网络错误", Etext: "network error"))
  91. })
  92. }
  93. }
  94. extension AddEvaluateViewController : UITableViewDelegate,UITableViewDataSource{
  95. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  96. return self.dataSource?.count ?? 0
  97. }
  98. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  99. let cell = tableView.dequeueReusableCell(withIdentifier: "AddEvaluateCell") as! AddEvaluateCell;
  100. let model : NeedEvaluateListModel = self.dataSource![indexPath.row]
  101. cell.configModel(model: model)
  102. cell.reloadBlock = {[weak self] in
  103. let reindexPath = IndexPath(item: indexPath.row, section: 0)
  104. self?.tableView.reloadRows(at: [reindexPath], with: .none)
  105. }
  106. cell.addImgBlock = {[weak self] in
  107. let reindexPath = IndexPath(item: indexPath.row, section: 0)
  108. self?.addUploadImg(model: model, reindexPath: reindexPath)
  109. }
  110. return cell
  111. }
  112. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  113. return 0.01
  114. }
  115. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  116. return 0.01
  117. }
  118. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  119. }
  120. }
  121. extension AddEvaluateViewController : TZImagePickerControllerDelegate{
  122. // func setdeid
  123. }