|
@@ -8,11 +8,20 @@
|
|
|
|
|
|
import UIKit
|
|
|
import RxSwift
|
|
|
+import SwiftyJSON
|
|
|
|
|
|
class OrderCommentController: BaseViewController {
|
|
|
|
|
|
- // 上传图片数组
|
|
|
- var goodsImageArr = Array<UIImage>()
|
|
|
+ var orderDetailModel: OrderModel? {
|
|
|
+ didSet {
|
|
|
+ self.productArr = self.orderDetailModel?.detail
|
|
|
+ self.tableView.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 商品数组
|
|
|
+ var productArr: Array<OrderModelDetailModel>?
|
|
|
+
|
|
|
// 提交评论参数Model
|
|
|
var paraMdl = OrderCommentParameterModel()
|
|
|
|
|
@@ -33,10 +42,7 @@ class OrderCommentController: BaseViewController {
|
|
|
commitButton.backgroundColor = kFFA42FColor
|
|
|
self.view.addSubview(commitButton)
|
|
|
commitButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
- print("点击了--提交评价")
|
|
|
- self?.uploadMultiImgUrl(imageArr: self!.goodsImageArr)
|
|
|
-// self?.uploadSingleImgUrl(imageArr: self!.goodsImageArr)
|
|
|
-
|
|
|
+ self?.commitProductComment()
|
|
|
}).disposed(by: disposeBag)
|
|
|
commitButton.snp.makeConstraints { (make) in
|
|
|
make.left.right.equalToSuperview()
|
|
@@ -79,23 +85,32 @@ class OrderCommentController: BaseViewController {
|
|
|
extension OrderCommentController : UITableViewDelegate, UITableViewDataSource {
|
|
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
- return 1
|
|
|
+ return productArr?.count ?? 0
|
|
|
}
|
|
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
let commentCell = OrderCommentTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
- commentCell.goodsImageArr = self.goodsImageArr
|
|
|
+ commentCell.orderModelDetailModel = productArr![indexPath.row]
|
|
|
+ commentCell.goodsImageArr = productArr![indexPath.row].imageArr
|
|
|
commentCell.frame = tableView.bounds
|
|
|
commentCell.layoutIfNeeded()
|
|
|
commentCell.reloadData()
|
|
|
+ commentCell.startChangedBlock = {
|
|
|
+ [weak self] (starValue) in
|
|
|
+ self?.productArr![indexPath.row].starValue = starValue!
|
|
|
+ }
|
|
|
+ commentCell.commentTextViewClosure = {
|
|
|
+ [weak self] (text) in
|
|
|
+ self?.productArr![indexPath.row].comment = text
|
|
|
+ }
|
|
|
commentCell.choosePicBlock = {
|
|
|
[weak self] in
|
|
|
// 添加图片
|
|
|
UIAlertController.showConfirmActionSheet(camera: { (action) in
|
|
|
PhotoAndCameraManager.shared().authorizeCamera()
|
|
|
PhotoAndCameraManager.shared().photoAndCameraManagerImageBlock = { [weak self] (image) in
|
|
|
- if self?.goodsImageArr.count ?? 0 < 6 {
|
|
|
- self?.goodsImageArr.append(image)
|
|
|
+ if self?.productArr![indexPath.row].imageArr.count ?? 0 < 6 {
|
|
|
+ self?.productArr![indexPath.row].imageArr.append(image)
|
|
|
self?.tableView.reloadData()
|
|
|
} else {
|
|
|
print("------超过最大数量")
|
|
@@ -105,8 +120,8 @@ extension OrderCommentController : UITableViewDelegate, UITableViewDataSource {
|
|
|
}) { (action) in
|
|
|
PhotoAndCameraManager.shared().authorizePhoto()
|
|
|
PhotoAndCameraManager.shared().photoAndCameraManagerImageBlock = { [weak self] (image) in
|
|
|
- if self?.goodsImageArr.count ?? 0 < 6 {
|
|
|
- self?.goodsImageArr.append(image)
|
|
|
+ if self?.productArr![indexPath.row].imageArr.count ?? 0 < 6 {
|
|
|
+ self?.productArr![indexPath.row].imageArr.append(image)
|
|
|
self?.tableView.reloadData()
|
|
|
} else {
|
|
|
print("------超过最大数量")
|
|
@@ -116,7 +131,7 @@ extension OrderCommentController : UITableViewDelegate, UITableViewDataSource {
|
|
|
}
|
|
|
commentCell.delPicTransBlock = {
|
|
|
[weak self] (idxRow) in
|
|
|
- self?.goodsImageArr.remove(at: idxRow!)
|
|
|
+ self?.productArr![idxRow!].imageArr.remove(at: idxRow!)
|
|
|
self?.tableView.reloadData()
|
|
|
}
|
|
|
return commentCell
|
|
@@ -148,43 +163,44 @@ extension OrderCommentController : UITableViewDelegate, UITableViewDataSource {
|
|
|
|
|
|
//MARK: - 逻辑处理
|
|
|
extension OrderCommentController {
|
|
|
-
|
|
|
- /// 单图上传
|
|
|
- ///
|
|
|
- /// - Parameter goodsImageArr: 图片数组
|
|
|
- func uploadSingleImgUrl(imageArr:[UIImage]) -> Void {
|
|
|
+ // 提交评价
|
|
|
+ func commitProductComment() {
|
|
|
|
|
|
- SwiftMoyaNetWorkServiceConfig.shared().configUploadSingleImgApi(imageArray: imageArr) { [weak self] (data) -> (Void) in
|
|
|
- print(data)
|
|
|
+ for productMdl in productArr! {
|
|
|
+ if productMdl.starValue == 0 {
|
|
|
+ SwiftProgressHUD.shared().showText("请给予商品评分")
|
|
|
+ return
|
|
|
+ }
|
|
|
+// if productMdl.comment == "" {
|
|
|
+// SwiftProgressHUD.shared().showText("请填写商品评价")
|
|
|
+// return
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
+ // 上传全部商品图片
|
|
|
+ for (idx, productMdl) in (productArr?.enumerated())! {
|
|
|
+ let curImageArr = productArr![idx].imageArr
|
|
|
+
|
|
|
+ if curImageArr.isEmpty {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ let sema = DispatchSemaphore(value: 0)
|
|
|
+ // 多图上传Api
|
|
|
+ SwiftMoyaNetWorkServiceConfig.shared().configUploadMultiImgApi(imageArray: curImageArr) { (imgUrlArr) -> (Void) in
|
|
|
+ let imgJsonStr = JSON(imgUrlArr).description
|
|
|
+ productMdl.imageArrUrlStr = imgJsonStr
|
|
|
+ sema.signal()
|
|
|
+ }
|
|
|
+ //异步调用返回前,就会一直阻塞在这
|
|
|
+ sema.wait()
|
|
|
+ }
|
|
|
|
|
|
-// SwiftMoyaNetWorkService.shared.commonUploadpicSingleApi(imageArray:goodsImageArr) { [weak self] (data) -> (Void) in
|
|
|
-//
|
|
|
-// SwiftMoyaNetWorkService.shared.minePersonalUploadFaceUrlApi(faceUrl: data as! String , completion: { [weak self] (data) -> (Void) in
|
|
|
-// self?.personalPortraitView.isReloadData = true
|
|
|
-// NotificationCenter.default.post(name: kMineUserQueryModelTokenModelChangeNotificationName, object: nil,userInfo: nil)
|
|
|
-// })
|
|
|
-// }
|
|
|
+ self.productAddCommentApi()
|
|
|
}
|
|
|
|
|
|
- /// 多图上传
|
|
|
- ///
|
|
|
- /// - Parameter goodsImageArr: 图片数组
|
|
|
- func uploadMultiImgUrl(imageArr:[UIImage]) -> Void {
|
|
|
-
|
|
|
- SwiftMoyaNetWorkServiceConfig.shared().configUploadMultiImgApi(imageArray: imageArr) { [weak self] (data) -> (Void) in
|
|
|
- print(data)
|
|
|
- }
|
|
|
-
|
|
|
+ func productAddCommentApi() {
|
|
|
|
|
|
- // SwiftMoyaNetWorkService.shared.commonUploadpicSingleApi(imageArray:goodsImageArr) { [weak self] (data) -> (Void) in
|
|
|
- //
|
|
|
- // SwiftMoyaNetWorkService.shared.minePersonalUploadFaceUrlApi(faceUrl: data as! String , completion: { [weak self] (data) -> (Void) in
|
|
|
- // self?.personalPortraitView.isReloadData = true
|
|
|
- // NotificationCenter.default.post(name: kMineUserQueryModelTokenModelChangeNotificationName, object: nil,userInfo: nil)
|
|
|
- // })
|
|
|
- // }
|
|
|
}
|
|
|
|
|
|
}
|