Просмотр исходного кода

评价:多图上传 --> 单图循环上传

Chris лет назад: 5
Родитель
Сommit
84e68d5b1c

+ 69 - 31
RainbowPlanet/RainbowPlanet/Modules/OrderModule/OrderComment/ViewController/OrderCommentController.swift

@@ -175,45 +175,83 @@ extension OrderCommentController : UITableViewDelegate, UITableViewDataSource {
 extension OrderCommentController {
     // 提交评价
     func commitProductComment() {
-        
-//        // test data
-//        let testMdl: OrderModelDetailModel = (productArr?[0])!
-//        productArr?.append(testMdl)
-//        productArr?.append(testMdl)
-//        productArr?.append(testMdl)
         print("\n0----开始上传流程")
-        var times: Int = productArr?.count ?? 0
+        uploadAllImages(totalTimes: 0)
+        
+//        var times: Int = productArr?.count ?? 0
         // 上传全部商品图片
-        for (idx, productMdl) in (productArr?.enumerated())! {
-            let curImageArr = productArr![idx].imageArr
-            
-            if curImageArr.isEmpty {
-                times -= 1
-                productMdl.imageArrUrl = []
-                if times == 0 {
-                    self.productAddCommentApi()
-                    return
-                } else {
-                    continue
-                }
-            }
+//        for (idx, productMdl) in (productArr?.enumerated())! {
+//            let curImageArr = productArr![idx].imageArr
+//
+//            if curImageArr.isEmpty {
+//                times -= 1
+//                productMdl.imageArrUrl = []
+//                if times == 0 {
+//                    self.productAddCommentApi()
+//                    return
+//                } else {
+//                    continue
+//                }
+//            }
+//
+//            uploadSectionImages(productMdl: productMdl, curImageArr: curImageArr, totalTimes: 0)
+        
             
-            print("\n1----准备请求\(idx)")
             
             // 多图上传Api
-            SwiftMoyaNetWorkServiceConfig.shared().configUploadMultiImgApi(imageArray: curImageArr) { (imgUrlArr) -> (Void) in
-                productMdl.imageArrUrl = imgUrlArr as! Array<String>
-                NXLLog("\n2----请求返回\(idx)")
-                
-                // 需待最后一次请求返回后,再调用评价API
-                times -= 1
-                if times == 0 {
-                    self.productAddCommentApi()
+//            SwiftMoyaNetWorkServiceConfig.shared().configUploadMultiImgApi(imageArray: curImageArr) { (imgUrlArr) -> (Void) in
+//                productMdl.imageArrUrl = imgUrlArr as! Array<String>
+//                NXLLog("\n2----请求返回\(idx)")
+//
+//                // 需待最后一次请求返回后,再调用评价API
+//                times -= 1
+//                if times == 0 {
+//                    self.productAddCommentApi()
+//                }
+//            }
+            
+//        }
+        
+    }
+    
+    func uploadAllImages(totalTimes: Int) {
+        var curTimes: Int = totalTimes
+        
+        let productMdl = productArr![curTimes]
+        let curImageArr = productArr![curTimes].imageArr
+        
+        if curImageArr.isEmpty {
+            productMdl.imageArrUrl = []
+            if curTimes == productArr!.count - 1 {
+                self.productAddCommentApi()
+            } else {
+                curTimes += 1
+                uploadAllImages(totalTimes: curTimes)
+            }
+        } else {
+            uploadSectionImages(productMdl: productMdl, curImageArr: curImageArr, totalTimes: curTimes, secTimes: 0)
+        }
+    }
+    
+    func uploadSectionImages(productMdl: OrderModelDetailModel, curImageArr: Array<UIImage>, totalTimes: Int, secTimes: Int) {
+        var curTimes: Int = secTimes
+        print("-----StartUpload,secTimes == \(totalTimes),rowTimes == \(curTimes)")
+        SwiftMoyaNetWorkServiceConfig.shared().configUploadSingleImgApi(imageArray: [curImageArr[curTimes]]) {
+            [weak self] (imgUrl) -> (Void) in
+            let urlStr: String = imgUrl as! String
+            productMdl.imageArrUrl.append(urlStr)
+            print("-----FinishUpload,secTimes == \(totalTimes),rowTimes == \(curTimes)")
+            curTimes += 1
+            if curTimes < curImageArr.count {
+                self?.uploadSectionImages(productMdl: productMdl, curImageArr: curImageArr, totalTimes: totalTimes, secTimes: curTimes)
+            } else {
+                if totalTimes == (self?.productArr!.count)! - 1 {
+                    self?.productAddCommentApi()
+                } else {
+                    self?.uploadAllImages(totalTimes: totalTimes+1)
                 }
             }
         }
-        
-        
     }
     
     func uploadImages() {

+ 2 - 1
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceConfig/SwiftMoyaNetWorkServiceConfig.swift

@@ -97,8 +97,9 @@ class SwiftMoyaNetWorkServiceConfig: NSObject {
             multipartData.append(formData)
         }
         SwiftProgressHUD.shared().showWait()
-        SwiftMoyaNetWorkManager.shared.requestAny(target: MultiTarget(SwiftMoyaServiceConfigApi.configUploadSingleImg(parameters: parameters, dataArray: multipartData))) { (data) in
+        SwiftMoyaNetWorkManager.shared.requestAny(target: MultiTarget(SwiftMoyaServiceConfigApi.configUploadSingleImg(parameters: parameters, dataArray: multipartData))) { (imgUrl) in
             SwiftProgressHUD.shared().hide()
+            completion(imgUrl)
         }
     }