OrderCommentController.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //
  2. // OrderCommentController.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/5/17.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 订单--评价Vc
  8. import UIKit
  9. import RxSwift
  10. import SwiftyJSON
  11. class OrderCommentController: BaseViewController {
  12. var orderDetailModel: OrderModel? {
  13. didSet {
  14. self.productArr = self.orderDetailModel?.detail
  15. self.tableView.reloadData()
  16. }
  17. }
  18. // 商品数组
  19. var productArr: Array<OrderModelDetailModel>?
  20. // 提交评论参数Model
  21. var paraMdl = OrderCommentParameterModel()
  22. override func viewDidLoad() {
  23. super.viewDidLoad()
  24. setupViews()
  25. setupData()
  26. }
  27. override func setupViews() {
  28. navigationBar.title = "评价"
  29. let commitButton = UIButton(type: UIButton.ButtonType.custom)
  30. commitButton.setTitle("提交", for: .normal)
  31. commitButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
  32. commitButton.titleLabel?.font = kRegularFont16
  33. commitButton.backgroundColor = kFFA42FColor
  34. self.view.addSubview(commitButton)
  35. commitButton.rx.tap.subscribe(onNext: { [weak self] (data) in
  36. self?.commitProductComment()
  37. }).disposed(by: disposeBag)
  38. commitButton.snp.makeConstraints { (make) in
  39. make.left.right.equalToSuperview()
  40. make.bottom.equalToSuperview().offset(-kSafeTabBarHeight)
  41. make.height.equalTo(50)
  42. }
  43. self.view.addSubview(tableView)
  44. let emptyView = EmptyView.shared.diyCustomEmptyViewStyle2(iconStr: "page04", titleStr: "当前暂无数据")
  45. emptyView.contentViewY = kScaleValue(value: 182)
  46. tableView.ly_emptyView = emptyView
  47. tableView.ly_startLoading()
  48. tableView.snp.makeConstraints { (make) in
  49. make.top.equalToSuperview().offset(kSafeStatusBarHeight+40)
  50. make.bottom.equalTo(commitButton.snp_top)
  51. make.left.right.equalToSuperview()
  52. }
  53. }
  54. override func setupData() {
  55. }
  56. lazy var tableView: UITableView = {
  57. let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
  58. tableView.separatorStyle = .none
  59. tableView.backgroundColor = kffffffColor
  60. tableView.dataSource = self
  61. tableView.delegate = self
  62. tableView.estimatedRowHeight = 0.000001
  63. tableView.estimatedSectionFooterHeight = 0.000001
  64. tableView.estimatedSectionHeaderHeight = 0.000001
  65. return tableView
  66. }()
  67. }
  68. // MARK: - tableView dataSource && delegate
  69. extension OrderCommentController : UITableViewDelegate, UITableViewDataSource {
  70. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  71. return productArr?.count ?? 0
  72. }
  73. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  74. let commentCell = OrderCommentTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
  75. commentCell.orderModelDetailModel = productArr![indexPath.row]
  76. commentCell.goodsImageArr = productArr![indexPath.row].imageArr
  77. commentCell.frame = tableView.bounds
  78. commentCell.layoutIfNeeded()
  79. commentCell.reloadData()
  80. commentCell.startChangedBlock = {
  81. [weak self] (starValue) in
  82. self?.productArr![indexPath.row].starValue = starValue!
  83. }
  84. commentCell.commentTextViewClosure = {
  85. [weak self] (text) in
  86. self?.productArr![indexPath.row].comment = text
  87. }
  88. commentCell.choosePicBlock = {
  89. [weak self] in
  90. // 添加图片
  91. UIAlertController.showConfirmActionSheet(camera: { (action) in
  92. PhotoAndCameraManager.shared().authorizeCamera()
  93. PhotoAndCameraManager.shared().photoAndCameraManagerImageBlock = { [weak self] (image) in
  94. if self?.productArr![indexPath.row].imageArr.count ?? 0 < 6 {
  95. self?.productArr![indexPath.row].imageArr.append(image)
  96. self?.tableView.reloadData()
  97. } else {
  98. print("------超过最大数量")
  99. }
  100. }
  101. }) { (action) in
  102. PhotoAndCameraManager.shared().authorizePhoto()
  103. PhotoAndCameraManager.shared().photoAndCameraManagerImageBlock = { [weak self] (image) in
  104. if self?.productArr![indexPath.row].imageArr.count ?? 0 < 6 {
  105. self?.productArr![indexPath.row].imageArr.append(image)
  106. self?.tableView.reloadData()
  107. } else {
  108. print("------超过最大数量")
  109. }
  110. }
  111. }
  112. }
  113. commentCell.delPicTransBlock = {
  114. [weak self] (idxRow) in
  115. self?.productArr![idxRow!].imageArr.remove(at: idxRow!)
  116. self?.tableView.reloadData()
  117. }
  118. return commentCell
  119. }
  120. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  121. return UITableView.automaticDimension
  122. }
  123. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  124. return 10
  125. }
  126. func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
  127. let headerSepView = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 10))
  128. headerSepView.backgroundColor = kf7f8faColor
  129. return headerSepView
  130. }
  131. func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
  132. return 0.000001
  133. }
  134. func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
  135. return nil
  136. }
  137. }
  138. //MARK: - 逻辑处理
  139. extension OrderCommentController {
  140. // 提交评价
  141. func commitProductComment() {
  142. for productMdl in productArr! {
  143. if productMdl.starValue == 0 {
  144. SwiftProgressHUD.shared().showText("请给予商品评分")
  145. return
  146. }
  147. // if productMdl.comment == "" {
  148. // SwiftProgressHUD.shared().showText("请填写商品评价")
  149. // return
  150. // }
  151. }
  152. // 上传全部商品图片
  153. for (idx, productMdl) in (productArr?.enumerated())! {
  154. let curImageArr = productArr![idx].imageArr
  155. if curImageArr.isEmpty {
  156. continue
  157. }
  158. let sema = DispatchSemaphore(value: 0)
  159. // 多图上传Api
  160. SwiftMoyaNetWorkServiceConfig.shared().configUploadMultiImgApi(imageArray: curImageArr) { (imgUrlArr) -> (Void) in
  161. let imgJsonStr = JSON(imgUrlArr).description
  162. productMdl.imageArrUrlStr = imgJsonStr
  163. sema.signal()
  164. }
  165. //异步调用返回前,就会一直阻塞在这
  166. sema.wait()
  167. }
  168. self.productAddCommentApi()
  169. }
  170. func productAddCommentApi() {
  171. }
  172. }