1
0

3 Ревизии a2a52a10c5 ... 493b86ed0b

Автор SHA1 Съобщение Дата
  lintong 493b86ed0b 修复账户详情现价显示 преди 1 седмица
  lintong 4ee3ff6dbb Merge branch '推广版' of http://156.254.127.134:3000/tomy/JD_iOS into 推广版 преди 1 седмица
  lintong 8e9e34f6e0 修复交易画面持仓列表现价 преди 1 седмица

+ 14 - 7
Koala/Koala/Modular/Deal/V/Deal/DealListCell.swift

@@ -143,7 +143,6 @@ class DealListCell: BaseTableViewCell {
 
         cancelStatusLabel.showAnimatedGradientSkeleton(usingGradient: gradient, transition: .crossDissolve(0.25))
         holdView.layoutIfNeeded()
-        print("骨架图:Cell显示")
     }
     
     func hidenAnimated() {
@@ -174,7 +173,6 @@ class DealListCell: BaseTableViewCell {
 //        profitLabel.hideSkeleton()
 //        cancelStatusLabel.hideSkeleton()
 //        guadanjiageLabel.hideSkeleton()
-        print("骨架图:隐藏")
     }
 
     
@@ -358,20 +356,29 @@ class DealListCell: BaseTableViewCell {
         self.shoushuLabel.attributedText = self.setAttributesForLots(title: switchLanguage("手数"), text: precisionString(with: model.volume, precision: "2"))
         
         var price = model.close_price
-        let prd = BaseProductList.shareInstance.productList[model.productBean.symbol]
-        if prd != nil && model.productBean.inTrading() {
-            let bid = prd!.bid
-            let ask = prd!.ask
+        if let prd = BaseProductList.shareInstance.productList[model.productBean.symbol] {
+            let bid = prd.bid
+            let ask = prd.ask
             price = bid
             if model.cmd == 1 || model.cmd == 3 || model.cmd == 5 {
                 price = ask
             }
         }
+//        let prd = self.productList![model.productBean.symbol]
+//        if prd != nil && model.productBean.inTrading() {
+//            let bid = prd!.bid
+//            let ask = prd!.ask
+//            price = bid
+//            if model.cmd == 1 || model.cmd == 3 || model.cmd == 5 {
+//                price = ask
+//            }
+//        }
         
         var xianjiaColor = color(242, 64, 64, 1)
-        if Double(price ?? "0") ?? 0 < Double(model.open_price ?? "0") ?? 0 {
+        if model.cmd == 1 || model.cmd == 3 || model.cmd == 5 {
             xianjiaColor = color(83, 185, 73, 1)
         }
+        self.xianjiaLabel.textColor = xianjiaColor
         
         if model.productBean.digits.length > 0 {
             self.xianjiaLabel.text = precisionString(with: price ?? "0", precision: model.productBean.digits, isRound: true)

+ 2 - 1
Koala/Koala/Modular/Deal/V/Deal/DealView.swift

@@ -973,8 +973,9 @@ class DealView: BaseView {
         
         self.VM?.getDealProductActionBlock = { [weak self] in
             guard let self = self else { return }
+            self.tabHeaderView.VM = self.VM
             self.tableView.reloadData()
-            self.tabHeaderView.liteInfoView.submitView.bidNotSupport = self.VM?.selectSymbolModel.enable == "0"
+            
         }
         
         var issignalSymbol = true

+ 38 - 54
Koala/Koala/Modular/Deal/VM/DealViewModel.swift

@@ -1442,57 +1442,18 @@ extension DealViewModel {
                     }
                     PriceCalibrator.shareCalibrator.updateLastPriceTime()
                     print("symbol的值:\(symbol)")
-                    var isReload = false
-                    if self.selectIndex == 0 {
-                        if let positionModel = self.positionListDict[symbol] {
-                            positionModel.isUpdate = true
-                            positionModel.SymbolModel.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            positionModel.SymbolModel.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            
-//                            let ask = Double(positionModel.SymbolModel.ask) ?? 0.0
-//                            let bid = Double(positionModel.SymbolModel.bid) ?? 0.0
-//                            positionModel.close_price = positionModel.SymbolModel.close
-                            let promd = BaseProductList.shareInstance.productList[symbol]
-                            
-                            let promdc = self.productList[symbol]
-                            promd?.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            promd?.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            promdc?.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            promdc?.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            isReload = true
-                        }
-                    } else if self.selectIndex == 1 {
-                        if let positionModel = self.entrustListDict[symbol] {
-                            positionModel.SymbolModel.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            positionModel.SymbolModel.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            let promd = BaseProductList.shareInstance.productList[symbol]
-                            
-                            let promdc = self.productList[symbol]
-                            promd?.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            promd?.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            promdc?.ask = String(format: "%@", currentSocket["ask"] as! CVarArg)
-                            promdc?.bid = String(format: "%@", currentSocket["bid"] as! CVarArg)
-                            isReload = true
-                        }
-                    }
                     
                     let model = self.selectSymbolModel
                     if model.symbol == symbol {
-                        isReload = false
                         model.newPrice = "\(currentSocket["ask"] ?? "0")"
                         let np = conerData(model.newPrice, .MyDouble).2! - conerData(model.open, .MyDouble).2!
                         model.increase = "\(np / conerData(model.open, .MyDouble).2! * 100)"
-                        model.ask = "\(currentSocket["bid"] ?? "0")"
-                        model.bid = "\(currentSocket["ask"] ?? "0")"
+                        let bid = "\(currentSocket["bid"] ?? "0")"
+                        let ask = "\(currentSocket["ask"] ?? "0")"
                         
-                        let curPrice = ((Double(model.ask) ?? 0) + (Double(model.bid) ?? 0)) / 2
+                        let curPrice = ((Double(ask) ?? 0) + (Double(bid) ?? 0)) / 2
                         self.price = "\(curPrice)"
                         
-                        if self.productList[symbol] != nil {
-                            self.productList[symbol]!.ask = "\(currentSocket["ask"] ?? "0")"
-                            self.productList[symbol]!.bid = "\(currentSocket["bid"] ?? "0")"
-                        }
-                        
                         self.observeSymbol.send(value: true)
                         
                         guard let _ = currentSocket["time"] as? Int64 else {
@@ -1503,7 +1464,6 @@ extension DealViewModel {
                     
                         var period = KLinePeriod.minuteFor(kPeriod: KLinePeriod.getDefaultKLinePeriod())
                         period = period * 60
-                        isReload = true
                         if let firstModel = self.priceList.first {
                             let firstTime = conerData(firstModel.datetime as Any, .MyCLong).3! + period
                             
@@ -1535,18 +1495,9 @@ extension DealViewModel {
                             model.low = newPrice
                             self.priceList.insert(model, at: 0)
                         }
-                        if isReload {
-                            self.signalPriceBlock?()
-                            //                        self.observePrice.send(value: true)
-                            //                        if(self.refreshBlock != nil){
-                            //                            self.refreshBlock!()
-                            //                        }
-                        }
+                        self.signalPriceBlock?()
                     } else {
-                        if isReload {
-                            self.signalPositionBlock?()
-                            //                        self.observePosition.send(value: true)
-                        }
+                        self.signalPositionBlock?()
                     }
                 } else if currentType == "depth" {
                     guard let symbol = currentSocket["symbol"] as? String else {
@@ -1561,6 +1512,39 @@ extension DealViewModel {
                             self.getPriceDepthActionBlock?()
                         }
                     }
+                    
+                    if let marketDepthModel = MarketDepthModel.deserialize(from: currentSocket) {
+                        if self.selectIndex == 0 {
+                            if let positionModel = self.positionListDict[symbol] {
+                                positionModel.isUpdate = true
+                                positionModel.SymbolModel.ask = marketDepthModel.asks[0].price
+                                positionModel.SymbolModel.bid = marketDepthModel.bids[0].price
+                                
+                                let promd = BaseProductList.shareInstance.productList[symbol]
+                                let promdc = self.productList[symbol]
+                                
+                                promd?.ask = marketDepthModel.asks[0].price
+                                promd?.bid = marketDepthModel.bids[0].price
+                                promdc?.ask = marketDepthModel.asks[0].price
+                                promdc?.bid = marketDepthModel.bids[0].price
+                            }
+                        } else if self.selectIndex == 1 {
+                            if let positionModel = self.entrustListDict[symbol] {
+                                positionModel.SymbolModel.ask = marketDepthModel.asks[0].price
+                                positionModel.SymbolModel.bid = marketDepthModel.bids[0].price
+                                let promd = BaseProductList.shareInstance.productList[symbol]
+                                
+                                let promdc = self.productList[symbol]
+                                promd?.ask = marketDepthModel.asks[0].price
+                                promd?.bid = marketDepthModel.bids[0].price
+                                promdc?.ask = marketDepthModel.asks[0].price
+                                promdc?.bid = marketDepthModel.bids[0].price
+                            }
+                        }
+                        
+                        self.signalPositionBlock?()
+                    }
+                    
                 }
             } else if type == 1 {
                 guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else { return }

+ 18 - 21
Koala/Koala/Modular/JDTrade/VC/JDNewTradeAccountDetailViewController.swift

@@ -246,13 +246,15 @@ class JDNewTradeAccountDetailViewController: BaseViewController {
                 guard let cell = tableView.cellForRow(at: indexPath) as? DealListCell else { continue }
                 guard indexPath.row < (viewModel.positionList.count) else {return}
                 cell.updatePositionCellWith(model: self.viewModel.positionList[indexPath.row])
+                cell.layoutIfNeeded()
             }
         }
-        else if sectionView.segmentedControl.selectedSegmentIndex == 0 {
+        else if sectionView.segmentedControl.selectedSegmentIndex == 1 {
             for indexPath in visibleRows {
                 guard let cell = tableView.cellForRow(at: indexPath) as? DealListCell else { continue }
                 guard indexPath.row < (viewModel.entrustList.count) else {return}
                 cell.updateEntrustCellWith(model: self.viewModel.entrustList[indexPath.row])
+                cell.layoutIfNeeded()
             }
         }
     }
@@ -428,9 +430,7 @@ class JDNewTradeAccountDetailViewController: BaseViewController {
             if !self.isScrolling.value {
                 self.skeletonCount = 0
                 self.tableView.hideSkeleton()
-                print("骨架图:隐藏")
                 self.tableView.reloadData()
-                print("刷新列表")
             }
             /// ===>推广版本修改
             var isCu = self.isCurrencyOptions
@@ -546,7 +546,6 @@ extension JDNewTradeAccountDetailViewController: UITableViewDelegate, SkeletonTa
         let cell: DealListCell = tableView.dequeueReusableCell(withIdentifier: "DealListCell") as! DealListCell
         skeletonCount = 0
         cell.hidenAnimated()
-        print("骨架图:隐藏")
         if self.sectionView.segmentedControl.selectedSegmentIndex == 2 {
             cell.cellType = .Hold // 持仓
             guard indexPath.row < self.viewModel.closeOrderList.count else{
@@ -1177,18 +1176,17 @@ extension JDNewTradeAccountDetailViewController {
                                   guard let self else {return false}
                                   return !self.isScrolling.value
                               })
-                              .startWithValues { [weak self] indexPath in
+                              .startWithValues { [weak self] indexPaths in
                                   guard let self = self,
-                                        self.sectionView.segmentedControl.selectedSegmentIndex == 0,
-                                        indexPath.row < self.viewModel.positionList.count else {return}
-                                  
-                                  guard self.tableView.indexPathsForVisibleRows?.contains(indexPath) == true else {return}
-                                  guard let cell = self.tableView.cellForRow(at: indexPath) as? DealListCell else {return}
-                                  if self.skeletonCount > 0 {
-                                      self.skeletonCount = 0
-                                      self.tableView.hideSkeleton()
-                                  }
-                                  cell.updatePositionCellWith(model: self.viewModel.positionList[indexPath.row])
+                                        self.sectionView.segmentedControl.selectedSegmentIndex == 0 else {return}
+                                 
+//                                  if self.skeletonCount > 0 {
+//                                      self.skeletonCount = 0
+//                                      self.tableView.hideSkeleton()
+//                                  }
+//                                  
+//                                  self.tableView.reloadRows(at: indexPaths, with: .none)
+                                  self.updateVisibleRows()
                               }
         
         
@@ -1199,18 +1197,17 @@ extension JDNewTradeAccountDetailViewController {
                                   guard let self else {return false}
                                   return !self.isScrolling.value
                               })
-                              .startWithValues { [weak self] indexPath in
+                              .startWithValues { [weak self] indexPaths in
                                   guard let self = self,
-                                        self.sectionView.segmentedControl.selectedSegmentIndex == 1,
-                                        indexPath.row < self.viewModel.entrustList.count else {return}
+                                        self.sectionView.segmentedControl.selectedSegmentIndex == 1
+                                        else {return}
                                   
-                                  guard self.tableView.indexPathsForVisibleRows?.contains(indexPath) == true else {return}
-                                  guard let cell = self.tableView.cellForRow(at: indexPath) as? DealListCell else {return}
                                   if self.skeletonCount > 0 {
                                       self.skeletonCount = 0
                                       self.tableView.hideSkeleton()
                                   }
-                                  cell.updateEntrustCellWith(model: self.viewModel.entrustList[indexPath.row])
+                                  
+                                  self.tableView.reloadRows(at: indexPaths, with: .none)
                               }
        
     }

+ 76 - 5
Koala/Koala/Modular/JDTrade/VM/JDNewTradeAccountDetailViewModel.swift

@@ -72,9 +72,9 @@ class JDNewTradeAccountDetailViewModel {
     var lastUpdate: TimeInterval = Date().timeIntervalSince1970
     
     // 持仓列表待更新的列表项
-    let holdUpdatedIndexPath = MutableProperty<IndexPath?>(nil)
+    let holdUpdatedIndexPath = MutableProperty<Array<IndexPath>?>(nil)
     // 挂单列表待更新的列表项
-    let hangUpdatedIndexPath = MutableProperty<IndexPath?>(nil)
+    let hangUpdatedIndexPath = MutableProperty<Array<IndexPath>?>(nil)
     
 
     init(accountModel: JDTradeAccountModel) {
@@ -410,7 +410,14 @@ extension JDNewTradeAccountDetailViewModel {
             guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else {return}
             guard let symbol = currentSocket["symbol"] as? String else {return}
             if type == 0 {
-                updatePrice(symbol: currentSocket)
+                guard let currentSocket = dict.object(forKey: "currentSocket") as? NSDictionary else { return }
+                guard let currentType = currentSocket["type"] as? String else { return }
+                
+                if(currentType == "depth"){
+                    updateDepth(symbol: currentSocket)
+                }else if(currentType == "price"){
+                    updatePrice(symbol: currentSocket)
+                }
             }
             else if type == 1 {
                 let isUpdateHold =  positionList.contains {$0.symbol == symbol}
@@ -421,6 +428,50 @@ extension JDNewTradeAccountDetailViewModel {
             }
         }
     }
+    
+    func updateDepth(symbol: NSDictionary){
+        guard let symbol_str = symbol["symbol"] as? String else {
+            return
+        }
+        if symbol_str.count == 0 {
+            return
+        }
+        
+        if let marketDepthModel = MarketDepthModel.deserialize(from: symbol) {
+            
+            guard let model = self.productList[symbol_str] else {
+                return
+            }
+            
+            model.ask = marketDepthModel.asks[0].price
+            model.bid = marketDepthModel.bids[0].price
+            BaseProductList.shareInstance.updateProductInfo(model: model)
+            if self.current_select_index == 0 {
+                let indices = self.positionList.enumerated().compactMap { (index, item) -> Int? in
+                    if(item.symbol == symbol_str){
+                        item.productBean.ask = model.ask
+                        item.productBean.bid = model.bid
+                        item.SymbolModel.ask = model.ask
+                        item.SymbolModel.bid = model.bid
+                        return index
+                    }
+                    return nil
+                }
+                // 将索引集合转换为 IndexPath 集合
+                let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
+                
+                self.holdUpdatedIndexPath.value = indexPaths
+            }else if(self.current_select_index == 1){
+                let indices = self.entrustList.enumerated().compactMap { (index, item) -> Int? in
+                    return item.symbol == symbol_str ? index : nil
+                }
+                // 将索引集合转换为 IndexPath 集合
+                let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
+                
+                self.hangUpdatedIndexPath.value = indexPaths
+            }
+        }
+    }
 
     func updatePrice(symbol: NSDictionary) {
         guard let symbol_str = symbol["symbol"] as? String else {
@@ -461,11 +512,31 @@ extension JDNewTradeAccountDetailViewModel {
             positionModel.productBean.ask = model.ask
             positionModel.productBean.bid = model.bid
             
-            self.holdUpdatedIndexPath.value = IndexPath.init(row: row, section: 0)
+            let indices = self.positionList.enumerated().compactMap { (index, item) -> Int? in
+                if(item.symbol == symbol_str){
+                    item.productBean.ask = model.ask
+                    item.productBean.bid = model.bid
+                    item.SymbolModel.ask = model.ask
+                    item.SymbolModel.bid = model.bid
+                    return index
+                }
+                return nil
+            }
+            // 将索引集合转换为 IndexPath 集合
+            let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
+            
+            self.holdUpdatedIndexPath.value = indexPaths
         }
         else if self.current_select_index == 1 {
             guard let row = self.entrustList.firstIndex(where: {$0.symbol == symbol_str}) else {return}
-            self.hangUpdatedIndexPath.value = IndexPath.init(row: row, section: 0)
+            
+            let indices = self.entrustList.enumerated().compactMap { (index, item) -> Int? in
+                return item.symbol == symbol_str ? index : nil
+            }
+            // 将索引集合转换为 IndexPath 集合
+            let indexPaths = indices.map { IndexPath(row: $0, section: 0) }
+            
+            self.hangUpdatedIndexPath.value = indexPaths
         }
         
     }