Browse Source

订单支付列表fix && 获取默认快递Info

Chris 6 years ago
parent
commit
a11e2d9f43

+ 3 - 2
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCart/View/ShoppingCartView.swift

@@ -152,9 +152,10 @@ extension ShoppingCartView : UITableViewDelegate, UITableViewDataSource {
                         let cartAmountMdl = amountData as? CartAmountModel
                         let amount = cartAmountMdl?.amount
                         self?.cartListModelArr![indexPath.section].productList![indexPath.row].amount = amount
-                        // 2.刷新cell
+                        // 2.刷新cell及合计View
                         let indexPath = IndexPath(item: indexPath.row, section: indexPath.section)
                         self?.tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
+                        self?.refreshAccountView()
                     })
                 }
                 return cell
@@ -288,7 +289,7 @@ extension ShoppingCartView {
             var subTag: Int = 0
             for (rowIdx, productMdl) in cartProListMdl.productList!.enumerated() {
                 if productMdl.isSelect == 1 {
-                    totalPrice += productMdl.skuPrice ?? 0
+                    totalPrice += productMdl.skuPrice! * productMdl.amount!
                     totalNum += 1
                     
                 } else {

+ 22 - 31
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/ShoppingCartOrderPayView.swift

@@ -128,7 +128,7 @@ extension ShoppingCartOrderPayView : UITableViewDelegate, UITableViewDataSource
         if section == 0 {
             return nil
         } else {
-            let headerView = ShoppingCartListTableViewHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 58))
+            let headerView = ShoppingCartPayOrderHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 58))
             headerView.shopName = proListModelArr![section-1].shopName
             return headerView
             
@@ -148,6 +148,18 @@ extension ShoppingCartOrderPayView : UITableViewDelegate, UITableViewDataSource
             return nil
         } else {
             let footerView = ShoppingCartPayOrderFooter(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 88))
+            
+            let cartProListMdl: CartProductListModel = proListModelArr![section-1]
+            let secNum: Int = cartProListMdl.productList!.count
+            
+            footerView.tPrice = self.calculateSectionPrice(section-1)
+            footerView.tNumber = secNum
+            
+            footerView.buyerNoteBlock = { [weak self]
+                (buyerNotes) in
+                self?.proListModelArr![section-1].buyerNotes = buyerNotes
+            }
+            
             return footerView
         }
     }
@@ -157,36 +169,15 @@ extension ShoppingCartOrderPayView : UITableViewDelegate, UITableViewDataSource
 // 购物车计算
 extension ShoppingCartOrderPayView {
     
-    // 计算结算数据,刷新结算View
-    func refreshAccountView() {
-//        totalPrice = 0
-//        totalNum = 0
-//        selModelArr = []
-//
-//        // 深拷贝数组
-//        for listModel in cartListModelArr! {
-//            let copyListMdl: CartProductListModel = listModel.copy() as! CartProductListModel
-//            selModelArr.append(copyListMdl)
-//        }
-//
-//        for (secIdx, cartProListMdl) in (cartListModelArr?.enumerated())! {
-//            var subTag: Int = 0
-//            for (rowIdx, productMdl) in cartProListMdl.productList!.enumerated() {
-//                if productMdl.isSelect == 1 {
-//                    totalPrice += productMdl.skuPrice ?? 0
-//                    totalNum += 1
-//
-//                } else {
-//                    if !cartListModelArr![secIdx].productList!.isEmpty {
-//                        selModelArr[secIdx].productList!.remove(at: rowIdx-subTag)
-//                        subTag += 1
-//                    }
-//                }
-//            }
-//        }
-//
-//        self.accountView.tPrice = totalPrice
-//        self.accountView.tNumber = totalNum
+    // 计算Section数据,刷新结算View
+    func calculateSectionPrice(_ section: Int) -> Int {
+        var totalPrice: Int = 0
+        
+        let cartProListMdl: CartProductListModel = proListModelArr![section]
+        for productMdl in cartProListMdl.productList! {
+            totalPrice += productMdl.skuPrice! * productMdl.amount!
+        }
+        return totalPrice
     }
     
 }

+ 27 - 6
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/View/ShoppingCartPayOrderFooter.swift

@@ -12,6 +12,27 @@ import RxCocoa
 
 class ShoppingCartPayOrderFooter: BaseView {
     
+    typealias BuyerNoteBlock = (_ note: String) -> Void
+    var buyerNoteBlock : BuyerNoteBlock?
+    
+    var tPrice: Int? {
+        didSet {
+            let originStr = "合计 ¥\(tPrice ?? 0)"
+            let attrStr = NSMutableAttributedString(string:originStr)
+            attrStr.changeForegroundColor(kfe352bColor, range: NSRange(location: 2, length: originStr.count-2))
+            priceLabel.attributedText = attrStr
+        }
+    }
+    
+    var tNumber: Int? {
+        didSet {
+            let originStr = "共\(tNumber ?? 0)件商品,"
+            let attrStr = NSMutableAttributedString(string:originStr)
+            attrStr.changeForegroundColor(k333333Color, range: NSRange(location: 1, length: originStr.count-5))
+            numberLabel.attributedText = attrStr
+        }
+    }
+    
     override var frame: CGRect {
         get {
             return super.frame
@@ -78,17 +99,18 @@ class ShoppingCartPayOrderFooter: BaseView {
         msgTextField.sizeToFit()
         msgTextField.tintColor = kFFA42FColor
         
-        msgTextField.rx.text.changed.subscribe(onNext: { [weak self] (text) in
-//            self?.msgTextField.text = String(text?.prefix(11) ?? "") as String
-//            self?.phoneNumber = self?.msgTextField.text ?? ""
-//            self?.observableString()
+        msgTextField.rx.text.orEmpty.changed.subscribe(onNext: { [weak self] (text) in
+            self?.msgTextField.text = String(text.prefix(4)) as String
+            if let buyerNoteBlock = self?.buyerNoteBlock {
+                buyerNoteBlock(self?.msgTextField.text ?? "")
+            }
+            
         }).disposed(by: disposeBag)
         return msgTextField
     }()
     
     private lazy var priceLabel: UILabel = {
         let priceLabel = UILabel()
-        priceLabel.text = "合计"
         priceLabel.textColor = k999999Color
         priceLabel.font = kRegularFont14
         priceLabel.textAlignment = .right
@@ -97,7 +119,6 @@ class ShoppingCartPayOrderFooter: BaseView {
     
     private lazy var numberLabel: UILabel = {
         let numberLabel = UILabel()
-        numberLabel.text = "共x件商品,"
         numberLabel.textColor = k999999Color
         numberLabel.font = kRegularFont14
         numberLabel.textAlignment = .right

+ 17 - 1
RainbowPlanet/RainbowPlanet/Modules/ShoppingCartModule/ShoppingCartPayOrder/ViewController/ShoppingCartPayOrderController.swift

@@ -33,7 +33,16 @@ class ShoppingCartPayOrderController: BaseViewController {
     }
     
     override func setupData() {
-        
+        let deliverType = DeliveryMethodTypeModel.shared().getModel()?.deliveryMethodType
+        switch deliverType {
+        case "1":
+            print("")
+        case "2":
+            // 获取默认快递信息
+            self.userDefaultExpressApi()
+        default:
+            break
+        }
     }
     
     /// 添加view
@@ -59,4 +68,11 @@ class ShoppingCartPayOrderController: BaseViewController {
         return orderPayView
     }()
     
+    /// 获取默认快递信息
+    func userDefaultExpressApi() {
+        SwiftMoyaNetWorkServiceUser.shared().userDefaultExpressApi { [weak self] (expressAddresModel) -> (Void) in
+            print(expressAddresModel)
+        }
+    }
+    
 }

+ 1 - 0
RainbowPlanet/RainbowPlanet/Service/Model/ProductModel/ProductCartListModel.swift

@@ -45,6 +45,7 @@ class CartProductListModel : NSObject, Mappable, NSCopying, NSMutableCopying{
     var productList : [ProductModel]?
     var shopId : Int?
     var shopName : String?
+    var buyerNotes : String?
     
     
     class func newInstance(map: Map) -> Mappable?{

+ 15 - 0
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceUser/SwiftMoyaNetWorkServiceUser.swift

@@ -364,6 +364,7 @@ public class SwiftMoyaNetWorkServiceUser: NSObject {
             completion("")
         }
     }
+    
     // MARK: - 自提点收货人列表
     /// 自提点收货人列表
     ///
@@ -381,6 +382,20 @@ public class SwiftMoyaNetWorkServiceUser: NSObject {
         }
     }
     
+    // MARK: - 获取默认快递信息
+    /// 获取默认快递信息
+    ///
+    /// - Parameter completion: 成功回调
+    func userDefaultExpressApi(completion: @escaping apiCallBack) {
+        let parameters = Dictionary<String,Any>()
+        SwiftProgressHUD.shared().showWait()
+        SwiftMoyaNetWorkManager.shared().request(target: MultiTarget(SwiftMoyaServiceUserApi.userDefaultExpress(parameters: parameters))) {(expressAddresModel) in
+            let expressAddresModel = expressAddresModel as! ExpressAddresModel
+            SwiftProgressHUD.shared().hide()
+            completion(expressAddresModel)
+        }
+    }
+    
     
     // MARK: - 新增、编辑 自提地址收货人信息
     /// 新增、编辑 自提地址收货人信息

+ 12 - 0
RainbowPlanet/RainbowPlanet/Service/SwiftMoyaService/SwiftMoyaServiceApi/SwiftMoyaServiceUser/SwiftMoyaServiceUserApi.swift

@@ -69,6 +69,10 @@ public let kUserAddressDeleteApi = "/user/addressDelete"
 /// 自提点收货人列表
 public let kUserExpreesContactsListApi = "/user/expreesContactsList"
 
+// MARK: - 获取默认快递信息
+/// 获取默认快递信息
+public let kUserDefaultExpressApi = "/user/getDefault"
+
 // MARK: - 新增、编辑 自提地址收货人信息
 /// 新增、编辑 自提地址收货人信息
 public let kUserSaveExpreesContactsApi = "/user/saveExpreesContacts"
@@ -106,6 +110,7 @@ public let kUserSetDeliverTypeApi = "/user/setDeliverType"
 /// - userAddressIsDefault: 设置默认(自提/快递)地址
 /// - userAddressDelete: 删除(自提/快递)地址
 /// - userExpreesContactsList: 自提点收货人列表
+/// - userDefaultExpress: 获取默认快递信息
 /// - userSaveExpreesContacts: 新增、编辑 自提地址收货人信息
 /// - userDelExpreesContacts: 删除自提点收货人信息
 /// - userSetExpreesContactsDefault: 自提点收货人信息,设置默认
@@ -127,6 +132,7 @@ public enum SwiftMoyaServiceUserApi {
     case userAddressIsDefault(parameters:Dictionary<String, Any>)
     case userAddressDelete(parameters:Dictionary<String, Any>)
     case userExpreesContactsList(parameters:Dictionary<String, Any>)
+    case userDefaultExpress(parameters:Dictionary<String, Any>)
     case userSaveExpreesContacts(parameters:Dictionary<String, Any>)
     case userDelExpreesContacts(parameters:Dictionary<String, Any>)
     case userSetExpreesContactsDefault(parameters:Dictionary<String, Any>)
@@ -154,6 +160,7 @@ extension SwiftMoyaServiceUserApi: TargetType {
              .userAddressIsDefault,
              .userAddressDelete,
              .userExpreesContactsList,
+             .userDefaultExpress,
              .userSaveExpreesContacts,
              .userDelExpreesContacts,
              .userSetExpreesContactsDefault,
@@ -196,6 +203,8 @@ extension SwiftMoyaServiceUserApi: TargetType {
             return kUserAddressDeleteApi
         case .userExpreesContactsList:
             return kUserExpreesContactsListApi
+        case .userDefaultExpress:
+            return kUserDefaultExpressApi
         case .userSaveExpreesContacts:
             return kUserSaveExpreesContactsApi
         case .userDelExpreesContacts:
@@ -226,6 +235,7 @@ extension SwiftMoyaServiceUserApi: TargetType {
              .userAddressIsDefault,
              .userAddressDelete,
              .userExpreesContactsList,
+             .userDefaultExpress,
              .userSaveExpreesContacts,
              .userDelExpreesContacts,
              .userSetExpreesContactsDefault,
@@ -256,6 +266,7 @@ extension SwiftMoyaServiceUserApi: TargetType {
              .userAddressIsDefault(var parameters),
              .userAddressDelete(var parameters),
              .userExpreesContactsList(var parameters),
+             .userDefaultExpress(var parameters),
              .userSaveExpreesContacts(var parameters),
              .userDelExpreesContacts(var parameters),
              .userSetExpreesContactsDefault(var parameters),
@@ -298,6 +309,7 @@ extension SwiftMoyaServiceUserApi: TargetType {
              .userAddressIsDefault,
              .userAddressDelete,
              .userExpreesContactsList,
+             .userDefaultExpress,
              .userSaveExpreesContacts,
              .userDelExpreesContacts,
              .userSetExpreesContactsDefault,